From ef79b062217d6a6c5560045066907c42d90cc471 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Sun, 12 Oct 2025 16:00:27 +0000 Subject: [PATCH] v1.pata --- db/config.php | 18 ++ db/migrations/001_create_users_table.sql | 7 + index.php | 275 +++++++++++------------ users.php | 192 ++++++++++++++++ 4 files changed, 349 insertions(+), 143 deletions(-) create mode 100644 db/migrations/001_create_users_table.sql create mode 100644 users.php diff --git a/db/config.php b/db/config.php index bb98f7d..5d11ebb 100644 --- a/db/config.php +++ b/db/config.php @@ -12,6 +12,24 @@ function db() { PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, ]); + run_migrations($pdo); } return $pdo; } + +function run_migrations($pdo) { + $migrations_dir = __DIR__ . '/migrations'; + if (!is_dir($migrations_dir)) { + mkdir($migrations_dir, 0775, true); + } + $migration_files = glob($migrations_dir . '/*.sql'); + foreach ($migration_files as $file) { + try { + $sql = file_get_contents($file); + $pdo->exec($sql); + } catch (PDOException $e) { + // Log error or handle it as needed + error_log("Migration failed for file: $file. Error: " . $e->getMessage()); + } + } +} diff --git a/db/migrations/001_create_users_table.sql b/db/migrations/001_create_users_table.sql new file mode 100644 index 0000000..c683825 --- /dev/null +++ b/db/migrations/001_create_users_table.sql @@ -0,0 +1,7 @@ +CREATE TABLE IF NOT EXISTS users ( + id INT AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(255) NOT NULL, + email VARCHAR(255) NOT NULL UNIQUE, + role VARCHAR(50) NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); diff --git a/index.php b/index.php index 7205f3d..272b82a 100644 --- a/index.php +++ b/index.php @@ -1,150 +1,139 @@ - - + - - - New Style - - - - - - - - - - - - - - - - - - - + + + Motoris Field Sales System + + + + + + + + + + + + + + -
-
-

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

+ +
- + + +
+
+

Streamline Your Field Sales Operations

+

The all-in-one app for your sales team to track visits, manage orders, and boost performance.

+ Get Started +
+header> + +
+
+

Core Features

+
+
+ +

Visit & GPS Tracking

+

Record client visits with notes, photos, and precise GPS location.

+
+
+ +

Order & Stock Management

+

Input orders, check vehicle stock, and manage payments on the go.

+
+
+ +

Performance Dashboards

+

View daily performance, track sales history, and get insights.

+
+
+
+
+ +
+
+

© Motoris Field Sales. All Rights Reserved.

+

Built with Flatlogic

+
+
+ + diff --git a/users.php b/users.php new file mode 100644 index 0000000..ecf191d --- /dev/null +++ b/users.php @@ -0,0 +1,192 @@ +prepare($sql); + $stmt->execute(['name' => $name, 'email' => $email, 'role' => $role]); + $success_message = "User added successfully!"; + } catch (PDOException $e) { + // Check for duplicate entry + if ($e->getCode() == 23000) { + $error_message = "Email already exists."; + } else { + $error_message = "Database error: " . $e->getMessage(); + } + } + } +} + +// Fetch all users +try { + $pdo = db(); + $stmt = $pdo->query("SELECT id, name, email, role, created_at FROM users ORDER BY created_at DESC"); + $users = $stmt->fetchAll(PDO::FETCH_ASSOC); +} catch (PDOException $e) { + $users = []; + $error_message = "Could not fetch users: " . $e->getMessage(); +} + +?> + + + + + + User Management - Motoris Field Sales + + + + + + + + + + + +
+
+
+
+
+
Add New User
+
+
+ + +
+
+ + +
+
+ + +
+ +
+
+
+
+
+
+
+
Current Users
+ +
+ + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
NameEmailRoleCreated At
No users found.
+
+
+
+
+
+
+ + + +