From 53eb27812c32f5daf85d36472c00637913f23984 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Wed, 5 Nov 2025 22:08:13 +0000 Subject: [PATCH] v1.1 --- add-asset.php | 161 +++++++++++ add-user.php | 130 +++++++++ assets/css/custom.css | 125 +++++++++ assets/js/main.js | 17 ++ auth-check.php | 8 + db/migrations/001_create_assets_table.sql | 27 ++ db/migrations/002_create_users_table.sql | 14 + delete-asset.php | 28 ++ delete-user.php | 34 +++ edit-asset.php | 185 +++++++++++++ edit-user.php | 160 +++++++++++ index.php | 320 ++++++++++++---------- login.php | 87 ++++++ logout.php | 7 + users.php | 159 +++++++++++ 15 files changed, 1320 insertions(+), 142 deletions(-) create mode 100644 add-asset.php create mode 100644 add-user.php create mode 100644 assets/css/custom.css create mode 100644 assets/js/main.js create mode 100644 auth-check.php create mode 100644 db/migrations/001_create_assets_table.sql create mode 100644 db/migrations/002_create_users_table.sql create mode 100644 delete-asset.php create mode 100644 delete-user.php create mode 100644 edit-asset.php create mode 100644 edit-user.php create mode 100644 login.php create mode 100644 logout.php create mode 100644 users.php diff --git a/add-asset.php b/add-asset.php new file mode 100644 index 0000000..0e8f787 --- /dev/null +++ b/add-asset.php @@ -0,0 +1,161 @@ +prepare($sql); + $stmt->execute([$name, $asset_tag, $status, $location, $manufacturer, $model, $purchase_date]); + + header("Location: index.php?success=asset_added"); + exit; + + } catch (PDOException $e) { + $error_message = 'Database error: ' . $e->getMessage(); + } + } +} +?> + + + + + + Add New Asset - IC-Inventory + + + + + + + + + + +
+ + +
+
+

Add New Asset

+
+ +
+
+ +
+ +
+ + +
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+ + +
+ + + Cancel +
+
+
+
+ + + + + + diff --git a/add-user.php b/add-user.php new file mode 100644 index 0000000..418eea4 --- /dev/null +++ b/add-user.php @@ -0,0 +1,130 @@ +prepare("SELECT id FROM users WHERE email = ?"); + $stmt->execute([$email]); + if ($stmt->fetch()) { + $error_message = 'Email already exists.'; + } else { + $hashed_password = password_hash($password, PASSWORD_DEFAULT); + + $sql = "INSERT INTO users (name, email, password, role) VALUES (?, ?, ?, ?)"; + $stmt = $pdo->prepare($sql); + $stmt->execute([$name, $email, $hashed_password, $role]); + + header("Location: users.php?success=user_added"); + exit; + } + } catch (PDOException $e) { + $error_message = 'Database error: ' . $e->getMessage(); + } + } +} +?> + + + + + + Add New User - IC-Inventory + + + + + + + + + +
+ + +
+
+

Add New User

+
+
+ +
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ + + Cancel +
+
+
+
+ + + + + + diff --git a/assets/css/custom.css b/assets/css/custom.css new file mode 100644 index 0000000..1ae6f93 --- /dev/null +++ b/assets/css/custom.css @@ -0,0 +1,125 @@ +/* General Styles */ +:root { + --primary-color: #4A90E2; + --secondary-color: #50E3C2; + --light-bg: #F7F9FC; + --light-surface: #FFFFFF; + --light-text: #333333; + --dark-bg: #121212; + --dark-surface: #1E1E1E; + --dark-text: #E0E0E0; + --border-radius: 8px; +} + +body { + font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; + transition: background-color 0.3s, color 0.3s; +} + +/* Light Mode */ +body { + background-color: var(--light-bg); + color: var(--light-text); +} + +/* Dark Mode */ +body.dark-mode { + background-color: var(--dark-bg); + color: var(--dark-text); +} + +.surface { + background-color: var(--light-surface); + border-radius: var(--border-radius); + box-shadow: 0 4px 6px rgba(0,0,0,0.1); + transition: background-color 0.3s; +} + +body.dark-mode .surface { + background-color: var(--dark-surface); + box-shadow: 0 4px 6px rgba(0,0,0,0.2); +} + +/* Layout */ +.wrapper { + display: flex; + min-height: 100vh; +} + +#sidebar { + width: 250px; + background-color: var(--light-surface); + transition: background-color 0.3s; + padding: 20px; + box-shadow: 2px 0 5px rgba(0,0,0,0.1); +} + +body.dark-mode #sidebar { + background-color: var(--dark-surface); + box-shadow: 2px 0 5px rgba(0,0,0,0.2); +} + +#content { + flex-grow: 1; + padding: 2rem; +} + +/* Header */ +.header { + display: flex; + justify-content: space-between; + align-items: center; + margin-bottom: 2rem; +} + +/* Theme Switcher */ +.theme-switcher { + cursor: pointer; +} + +/* Asset Table */ +.asset-table { + width: 100%; + border-collapse: collapse; +} + +.asset-table th, .asset-table td { + padding: 12px 15px; + text-align: left; + border-bottom: 1px solid #ddd; +} + +body.dark-mode .asset-table th, body.dark-mode .asset-table td { + border-bottom: 1px solid #444; +} + +.asset-table th { + background-color: var(--light-bg); +} + +body.dark-mode .asset-table th { + background-color: var(--dark-bg); +} + +.status { + padding: 5px 10px; + border-radius: 20px; + font-size: 0.8rem; + font-weight: bold; +} + +.status-in-service { background-color: #d4edda; color: #155724; } +.status-under-repair { background-color: #fff3cd; color: #856404; } +.status-retired { background-color: #f8d7da; color: #721c24; } + +/* Sidebar */ +#sidebar .nav-link { + color: var(--light-text); +} +body.dark-mode #sidebar .nav-link { + color: var(--dark-text); +} +#sidebar .nav-link.active { + color: var(--primary-color); + font-weight: bold; +} \ No newline at end of file diff --git a/assets/js/main.js b/assets/js/main.js new file mode 100644 index 0000000..1a70b8e --- /dev/null +++ b/assets/js/main.js @@ -0,0 +1,17 @@ +document.addEventListener('DOMContentLoaded', () => { + const themeSwitcher = document.getElementById('theme-switcher'); + const currentTheme = localStorage.getItem('theme'); + + if (currentTheme === 'dark') { + document.body.classList.add('dark-mode'); + } + + themeSwitcher.addEventListener('click', () => { + document.body.classList.toggle('dark-mode'); + let theme = 'light'; + if (document.body.classList.contains('dark-mode')) { + theme = 'dark'; + } + localStorage.setItem('theme', theme); + }); +}); \ No newline at end of file diff --git a/auth-check.php b/auth-check.php new file mode 100644 index 0000000..0fc84f4 --- /dev/null +++ b/auth-check.php @@ -0,0 +1,8 @@ + diff --git a/db/migrations/001_create_assets_table.sql b/db/migrations/001_create_assets_table.sql new file mode 100644 index 0000000..18fee06 --- /dev/null +++ b/db/migrations/001_create_assets_table.sql @@ -0,0 +1,27 @@ +CREATE TABLE IF NOT EXISTS `assets` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `name` VARCHAR(255) NOT NULL, + `asset_tag` VARCHAR(255) UNIQUE NOT NULL, + `serial_number` VARCHAR(255), + `model` VARCHAR(255), + `manufacturer` VARCHAR(255), + `category` VARCHAR(255), + `status` VARCHAR(50) NOT NULL, + `location` VARCHAR(255), + `purchase_date` DATE, + `purchase_cost` DECIMAL(10, 2), + `warranty_end` DATE, + `vendor` VARCHAR(255), + `assigned_to` INT, + `notes` TEXT, + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP +); + +-- Seed data +INSERT INTO `assets` (`name`, `asset_tag`, `status`, `location`, `purchase_date`, `assigned_to`, `manufacturer`, `model`) VALUES +('Laptop', 'ASSET-001', 'In Service', 'Office A', '2023-01-15', 1, 'Dell', 'XPS 15'), +('Monitor', 'ASSET-002', 'In Service', 'Office A', '2023-01-15', 1, 'Dell', 'UltraSharp 27'), +('Keyboard', 'ASSET-003', 'In Service', 'Office B', '2023-02-20', 2, 'Logitech', 'MX Keys'), +('Mouse', 'ASSET-004', 'Under Repair', 'IT Department', '2023-02-20', NULL, 'Logitech', 'MX Master 3'), +('Projector', 'ASSET-005', 'Retired', 'Storage', '2020-05-10', NULL, 'Epson', 'PowerLite 1781W'); \ No newline at end of file diff --git a/db/migrations/002_create_users_table.sql b/db/migrations/002_create_users_table.sql new file mode 100644 index 0000000..124b984 --- /dev/null +++ b/db/migrations/002_create_users_table.sql @@ -0,0 +1,14 @@ +CREATE TABLE IF NOT EXISTS `users` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL, + `email` varchar(255) NOT NULL, + `password` varchar(255) NOT NULL, + `role` enum('Admin','Asset Manager','IT Technician','Employee') NOT NULL DEFAULT 'Employee', + `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + UNIQUE KEY `email` (`email`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- Seed with a default admin user +INSERT INTO `users` (`name`, `email`, `password`, `role`) VALUES +('Admin User', 'admin@example.com', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'Admin'); -- password is 'password' diff --git a/delete-asset.php b/delete-asset.php new file mode 100644 index 0000000..eb49404 --- /dev/null +++ b/delete-asset.php @@ -0,0 +1,28 @@ +prepare("DELETE FROM assets WHERE id = ?"); + $stmt->execute([$asset_id]); + + header("Location: index.php?success=asset_deleted"); + exit; + +} catch (PDOException $e) { + header("Location: index.php?error=db_error"); + exit; +} +?> diff --git a/delete-user.php b/delete-user.php new file mode 100644 index 0000000..c1d5a72 --- /dev/null +++ b/delete-user.php @@ -0,0 +1,34 @@ +prepare("DELETE FROM users WHERE id = ?"); + $stmt->execute([$user_id]); + + header("Location: users.php?success=user_deleted"); + exit; + +} catch (PDOException $e) { + header("Location: users.php?error=db_error"); + exit; +} +?> diff --git a/edit-asset.php b/edit-asset.php new file mode 100644 index 0000000..049744e --- /dev/null +++ b/edit-asset.php @@ -0,0 +1,185 @@ +prepare("SELECT * FROM assets WHERE id = ?"); + $stmt->execute([$asset_id]); + $asset = $stmt->fetch(PDO::FETCH_ASSOC); + + if (!$asset) { + header("Location: index.php?error=not_found"); + exit; + } +} catch (PDOException $e) { + $error_message = 'Database error: ' . $e->getMessage(); +} + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $name = $_POST['name'] ?? ''; + $asset_tag = $_POST['asset_tag'] ?? ''; + $status = $_POST['status'] ?? 'In Service'; + $location = $_POST['location'] ?? ''; + $manufacturer = $_POST['manufacturer'] ?? ''; + $model = $_POST['model'] ?? ''; + $purchase_date = $_POST['purchase_date'] ?? ''; + + if (empty($name) || empty($asset_tag) || empty($purchase_date)) { + $error_message = 'Please fill in all required fields: Name, Asset Tag, and Purchase Date.'; + } else { + try { + $pdo = db(); + $sql = "UPDATE assets SET name = ?, asset_tag = ?, status = ?, location = ?, manufacturer = ?, model = ?, purchase_date = ? WHERE id = ?"; + $stmt = $pdo->prepare($sql); + $stmt->execute([$name, $asset_tag, $status, $location, $manufacturer, $model, $purchase_date, $asset_id]); + + header("Location: index.php?success=asset_updated"); + exit; + + } catch (PDOException $e) { + $error_message = 'Database error: ' . $e->getMessage(); + } + } +} +?> + + + + + + Edit Asset - IC-Inventory + + + + + + + + + + +
+ + +
+
+

Edit Asset

+
+ +
+
+ +
+ +
+ + + +
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+ + +
+ + + Cancel +
+ +
+
+
+ + + + + + diff --git a/edit-user.php b/edit-user.php new file mode 100644 index 0000000..f53d2b4 --- /dev/null +++ b/edit-user.php @@ -0,0 +1,160 @@ +prepare("SELECT id, name, email, role FROM users WHERE id = ?"); + $stmt->execute([$user_id]); + $user = $stmt->fetch(PDO::FETCH_ASSOC); + + if (!$user) { + header("Location: users.php?error=not_found"); + exit; + } +} catch (PDOException $e) { + $error_message = 'Database error: ' . $e->getMessage(); +} + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $name = $_POST['name'] ?? ''; + $email = $_POST['email'] ?? ''; + $role = $_POST['role'] ?? 'Employee'; + $password = $_POST['password'] ?? ''; + + if (empty($name) || empty($email)) { + $error_message = 'Name and Email are required.'; + } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { + $error_message = 'Invalid email format.'; + } else { + try { + $pdo = db(); + + // Check if email already exists for another user + $stmt = $pdo->prepare("SELECT id FROM users WHERE email = ? AND id != ?"); + $stmt->execute([$email, $user_id]); + if ($stmt->fetch()) { + $error_message = 'Email already exists for another user.'; + } else { + if (!empty($password)) { + $hashed_password = password_hash($password, PASSWORD_DEFAULT); + $sql = "UPDATE users SET name = ?, email = ?, role = ?, password = ? WHERE id = ?"; + $stmt = $pdo->prepare($sql); + $stmt->execute([$name, $email, $role, $hashed_password, $user_id]); + } else { + $sql = "UPDATE users SET name = ?, email = ?, role = ? WHERE id = ?"; + $stmt = $pdo->prepare($sql); + $stmt->execute([$name, $email, $role, $user_id]); + } + + header("Location: users.php?success=user_updated"); + exit; + } + } catch (PDOException $e) { + $error_message = 'Database error: ' . $e->getMessage(); + } + } +} +?> + + + + + + Edit User - IC-Inventory + + + + + + + + + +
+ + +
+
+

Edit User

+
+
+ +
+ +
+ + + +
+
+ + +
+
+ + +
+
+ + +
Leave blank to keep the current password.
+
+
+ + +
+ + + Cancel +
+ +
+
+
+ + + + + + diff --git a/index.php b/index.php index 7205f3d..3780a84 100644 --- a/index.php +++ b/index.php @@ -1,150 +1,186 @@ query("SHOW TABLES LIKE 'assets'"); + if ($result->rowCount() == 0) { + $sql = file_get_contents('db/migrations/001_create_assets_table.sql'); + $pdo->exec($sql); + } + + $stmt = $pdo->query('SELECT * FROM assets ORDER BY created_at DESC'); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + // In a real app, you'd log this error and show a user-friendly message. + // For this initial setup, we'll just display the error. + return ['error' => 'Database error: ' . $e->getMessage()]; + } +} + +$assets = get_assets(); + +function getStatusClass($status) { + switch (strtolower($status)) { + case 'in service': + return 'status-in-service'; + case 'under repair': + return 'status-under-repair'; + case 'retired': + return 'status-retired'; + default: + return ''; + } +} ?> - + - - - New Style - - - - - - - - - - - - - - - - - - - + + + IC-Inventory + + + + + + + + + + + + + + -
-
-

Analyzing your requirements and generating your website…

-
- Loading… -
-

AI is collecting your requirements and applying the first changes.

-

This page will update automatically as the plan is implemented.

-

Runtime: PHP — UTC

-
-
- + +
+ + +
+
+

Asset Dashboard

+
+ Add New Asset +
+ +
+
+
+ + +
Asset successfully added!
+ +
Asset successfully updated!
+ +
Asset successfully deleted!
+ +
You do not have permission to access that page.
+ + +
+ +
+ +
+ +
+

No assets found.

+

Get started by adding your first company asset.

+ Add Asset +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameAsset TagStatusLocationManufacturerModelPurchase DateActions
+ Edit + + Delete + +
+
+ +
+
+
+ + + + - + \ No newline at end of file diff --git a/login.php b/login.php new file mode 100644 index 0000000..41f2972 --- /dev/null +++ b/login.php @@ -0,0 +1,87 @@ +prepare("SELECT * FROM users WHERE email = ?"); + $stmt->execute([$email]); + $user = $stmt->fetch(PDO::FETCH_ASSOC); + + if ($user && password_verify($password, $user['password'])) { + $_SESSION['user_id'] = $user['id']; + $_SESSION['user_name'] = $user['name']; + $_SESSION['user_role'] = $user['role']; + header("Location: index.php"); + exit; + } else { + $error_message = 'Invalid email or password.'; + } + } catch (PDOException $e) { + $error_message = 'Database error: ' . $e->getMessage(); + } + } +} +?> + + + + + + Login - IC-Inventory + + + + + + +
+
+

IC-Inventory

+ +
+ +
+
+ + +
+
+ + +
+ +
+
+
+ + + + diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..ea82c68 --- /dev/null +++ b/logout.php @@ -0,0 +1,7 @@ + diff --git a/users.php b/users.php new file mode 100644 index 0000000..1162c03 --- /dev/null +++ b/users.php @@ -0,0 +1,159 @@ +query("SHOW TABLES LIKE 'users'"); + if ($result->rowCount() == 0) { + $sql = file_get_contents('db/migrations/002_create_users_table.sql'); + $pdo->exec($sql); + } + + $stmt = $pdo->query('SELECT id, name, email, role, created_at FROM users ORDER BY created_at DESC'); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + return ['error' => 'Database error: ' . $e->getMessage()]; + } +} + +$users = get_users(); +?> + + + + + + User Management - IC-Inventory + + + + + + + + + + +
+ + +
+
+

User Management

+
+ Add New User +
+ +
+
+
+ +
+ +
User successfully added!
+ +
User successfully updated!
+ +
User successfully deleted!
+ +
The default admin user cannot be deleted.
+ + +
+ +
+ +
+

No users found.

+

Get started by adding your first user.

+ Add User +
+ +
+ + + + + + + + + + + + + + + + + + + + + +
NameEmailRoleCreated AtActions
+ Edit + Delete +
+
+ +
+
+
+ + + + + +