From d627358851370e4ad0a8a1b7106cb685547263e5 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Tue, 23 Sep 2025 16:15:21 +0000 Subject: [PATCH] v1.3 --- admin/dashboard.php | 133 ++++++++++++++++++++++++ assets/css/custom.css | 39 +++++++ assets/js/main.js | 27 ++++- db/config.php | 58 ++++++++--- index.php | 16 +-- login.php | 132 ++++++++++++++++++++++++ logout.php | 7 ++ privacy.php | 34 +++++++ register.php | 232 ++++++++++++++++++++++++++++++++++++++++++ search.php | 34 +++++++ terms.php | 34 +++++++ 11 files changed, 723 insertions(+), 23 deletions(-) create mode 100644 admin/dashboard.php create mode 100644 login.php create mode 100644 logout.php create mode 100644 privacy.php create mode 100644 register.php create mode 100644 search.php create mode 100644 terms.php diff --git a/admin/dashboard.php b/admin/dashboard.php new file mode 100644 index 0000000..5e7c359 --- /dev/null +++ b/admin/dashboard.php @@ -0,0 +1,133 @@ +query("SELECT id, user_role, full_name, id_number, phone_number, garage_name, location, created_at FROM users ORDER BY created_at DESC"); + $users = $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + // In a real app, you would log this error, not display it. + $user_list_error = "Error fetching users: " . $e->getMessage(); + } +} else { + $user_list_error = "Database connection failed."; +} +?> + + + + + + Admin Dashboard - MyMech + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+

Administrator Dashboard

+

Manage all registered users in the system.

+ + +
+ +
No users have registered yet.
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
IDRoleFull NameID NumberPhoneGarage/ShopLocationRegistered On
+
+ +
+
+
+
+
+ + + + + + + + + + \ No newline at end of file diff --git a/assets/css/custom.css b/assets/css/custom.css index 788225d..cb9e7d8 100644 --- a/assets/css/custom.css +++ b/assets/css/custom.css @@ -149,6 +149,45 @@ body { color: var(--golden-yellow); } +/* Form Styles */ +.form-section { + padding: 5rem 0; +} + +.form-container { + background-color: var(--card-bg); + padding: 3rem; + border-radius: 8px; + border: 1px solid #003b73; +} + +.form-label { + color: var(--off-white); + font-weight: 600; +} + +.form-control, .form-select { + background-color: #003b73; + border: 1px solid #004a8a; + color: var(--off-white); + padding: 0.75rem 1rem; +} + +.form-control:focus, .form-select:focus { + background-color: #004a8a; + border-color: var(--golden-yellow); + box-shadow: 0 0 0 0.25rem rgba(255, 215, 0, 0.25); + color: var(--off-white); +} + +.form-control::placeholder { + color: #aab; +} + +.bg-navy-blue-darker { + background-color: var(--navy-blue-darker) !important; +} + /* Responsive Adjustments */ @media (max-width: 991.98px) { diff --git a/assets/js/main.js b/assets/js/main.js index bcf4642..51533bb 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -1,5 +1,30 @@ // Custom JavaScript for MyMech document.addEventListener('DOMContentLoaded', function () { - // Future interactivity can be added here. + + // Registration form logic + const registrationForm = document.getElementById('registrationForm'); + if (registrationForm) { + const userRole = document.getElementById('user_role'); + const garageNameField = document.getElementById('garage_name_field'); + const garageNameInput = document.getElementById('garage_name'); + + function toggleGarageNameField() { + const selectedRole = userRole.value; + if (selectedRole === 'mechanic' || selectedRole === 'shop_owner') { + garageNameField.style.display = 'block'; + garageNameInput.required = true; + } else { + garageNameField.style.display = 'none'; + garageNameInput.required = false; + } + } + + // Initial check + toggleGarageNameField(); + + // Listen for changes + userRole.addEventListener('change', toggleGarageNameField); + } + console.log("MyMech JS loaded"); }); diff --git a/db/config.php b/db/config.php index a0e6a07..17c24ed 100644 --- a/db/config.php +++ b/db/config.php @@ -1,17 +1,47 @@ PDO::ERRMODE_EXCEPTION, - PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, - ]); - } - return $pdo; +// --- Database Credentials --- +// Replace with your actual database credentials +define('DB_HOST', '127.0.0.1'); +define('DB_NAME', 'mymecha'); // Changed from 'default_db' +define('DB_USER', 'root'); // Changed from 'user' +define('DB_PASS', ''); // Assuming empty password for local dev + +// --- PDO Connection Function --- +/** + * Creates a PDO database connection. + * + * @return PDO|null A PDO connection object on success, or null on failure. + */ +function db_connect() { + static $pdo = null; // Static variable to hold the connection + + if ($pdo === null) { + $dsn = 'mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=utf8mb4'; + $options = [ + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, + PDO::ATTR_EMULATE_PREPARES => false, + ]; + + try { + // Create the database if it doesn't exist + $temp_pdo = new PDO('mysql:host=' . DB_HOST, DB_USER, DB_PASS, $options); + $temp_pdo->exec("CREATE DATABASE IF NOT EXISTS " . DB_NAME); + + // Now connect to the specific database + $pdo = new PDO($dsn, DB_USER, DB_PASS, $options); + + } catch (PDOException $e) { + // In a real application, you would log this error, not display it + // For development, it's useful to see the error + error_log('Database Connection Error: ' . $e->getMessage()); + // Return null or handle the error as appropriate for your application + return null; + } + } + + return $pdo; } +?> \ No newline at end of file diff --git a/index.php b/index.php index daa451a..1a53acb 100644 --- a/index.php +++ b/index.php @@ -36,10 +36,10 @@ @@ -52,8 +52,8 @@

Your Trusted Mechanic, Just a Click Away.

Find reliable mechanics and genuine spare parts instantly. Get back on the road faster.

- Find a Mechanic - Find Spare Parts + Find a Mechanic + Find Spare Parts
@@ -71,7 +71,7 @@

For Drivers

Get fast, reliable help from trusted mechanics near you. Search for specific services and parts to get exactly what you need.

- Sign Up as a Driver + Sign Up as a Driver @@ -82,7 +82,7 @@

For Mechanics

Grow your business by connecting with car owners in your area. List your services and showcase your expertise.

- Register Your Garage + Register Your Garage @@ -93,7 +93,7 @@

For Part Shops

List your inventory and reach a larger audience. Help drivers find the genuine parts they need quickly and easily.

- List Your Parts + List Your Parts @@ -105,7 +105,7 @@

© MyMech. All Rights Reserved.

- Privacy Policy | Terms of Service + Privacy Policy | Terms of Service

diff --git a/login.php b/login.php new file mode 100644 index 0000000..63a82ca --- /dev/null +++ b/login.php @@ -0,0 +1,132 @@ +prepare($sql); + $stmt->execute(['identifier' => $login_identifier]); + $user = $stmt->fetch(PDO::FETCH_ASSOC); + + if ($user && password_verify($password, $user['password_hash'])) { + // Password is correct, set session variables + $_SESSION['user_id'] = $user['id']; + $_SESSION['full_name'] = $user['full_name']; + $_SESSION['user_role'] = $user['user_role']; + + // Redirect based on user role + if ($user['user_role'] === 'admin') { + header("Location: admin/dashboard.php"); + } else { + // For other users, redirect to the main page or a user-specific dashboard + header("Location: index.php"); + } + exit(); + } else { + // Invalid credentials + $error = "Invalid login credentials. Please try again."; + } + } else { + $error = "Database connection failed. Please try again later."; + } + } + + // If there was an error, store it in the session to display it + if ($error) { + $_SESSION['message'] = $error; + $_SESSION['alert_type'] = 'danger'; + header("Location: login.php"); + exit(); + } +} +?> + + + + + + Login - MyMech + + + + + + + +
+
+
+
+

Login to Your Account

+ + "; + echo htmlspecialchars($message); + echo ''; + echo "
"; + // Unset the session variables so they don't persist + unset($_SESSION['message']); + unset($_SESSION['alert_type']); + } + ?> + +
+
+ + +
+
+ + +
+
+ +
+

Don't have an account? Register here.

+
+
+
+ +
+ + + + + + \ No newline at end of file diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..248c535 --- /dev/null +++ b/logout.php @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/privacy.php b/privacy.php new file mode 100644 index 0000000..d0fdba7 --- /dev/null +++ b/privacy.php @@ -0,0 +1,34 @@ + + + + + + Privacy Policy - MyMech + + + + + + + +
+

Privacy Policy

+

This page is under construction. Our Privacy Policy will be detailed here.

+ +
+ + + + + + \ No newline at end of file diff --git a/register.php b/register.php new file mode 100644 index 0000000..6d801e1 --- /dev/null +++ b/register.php @@ -0,0 +1,232 @@ + + + + + + + Register - MyMech + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+

Create Your Account

+

Join our community of drivers, mechanics, and part suppliers.

+ + "; + echo $message; + echo ''; + echo "
"; + // Unset the session variables so they don't persist + unset($_SESSION['message']); + unset($_SESSION['alert_type']); + } + + if ($_SERVER["REQUEST_METHOD"] == "POST") { + require_once 'db/config.php'; + + $pdo = db_connect(); + $message = ''; + $error = false; + + if (!$pdo) { + $message = "Database connection failed."; + $error = true; + } else { + // Create table if it doesn't exist + try { + $pdo->exec("CREATE TABLE IF NOT EXISTS users ( + id INT AUTO_INCREMENT PRIMARY KEY, + user_role VARCHAR(50) NOT NULL, + full_name VARCHAR(255) NOT NULL, + id_number VARCHAR(50) NOT NULL UNIQUE, + phone_number VARCHAR(50) NOT NULL UNIQUE, + garage_name VARCHAR(255), + location VARCHAR(255) NOT NULL, + password_hash VARCHAR(255) NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"); + } catch (PDOException $e) { + $message = "Error creating table: " . $e->getMessage(); + $error = true; + } + + if (!$error) { + // --- Form Data --- + $user_role = $_POST['user_role'] ?? ''; + $full_name = $_POST['full_name'] ?? ''; + $id_number = $_POST['id_number'] ?? ''; + $phone_number = $_POST['phone_number'] ?? ''; + $garage_name = ($user_role === 'mechanic' || $user_role === 'shop_owner') ? ($_POST['garage_name'] ?? '') : null; + $location = $_POST['location'] ?? ''; + $password = $_POST['password'] ?? ''; + $confirm_password = $_POST['confirm_password'] ?? ''; + + // --- Validation --- + if (empty($user_role) || empty($full_name) || empty($id_number) || empty($phone_number) || empty($location) || empty($password)) { + $message = "Please fill in all required fields."; + $error = true; + } elseif ($password !== $confirm_password) { + $message = "Passwords do not match."; + $error = true; + } else { + // Check for existing user (ID number or phone) + $stmt = $pdo->prepare("SELECT id FROM users WHERE id_number = ? OR phone_number = ?"); + $stmt->execute([$id_number, $phone_number]); + if ($stmt->fetch()) { + $message = "A user with this ID number or phone number already exists."; + $error = true; + } + } + + // --- Insertion --- + if (!$error) { + $password_hash = password_hash($password, PASSWORD_DEFAULT); + + $sql = "INSERT INTO users (user_role, full_name, id_number, phone_number, garage_name, location, password_hash) VALUES (?, ?, ?, ?, ?, ?, ?)"; + $stmt = $pdo->prepare($sql); + + try { + $stmt->execute([$user_role, $full_name, $id_number, $phone_number, $garage_name, $location, $password_hash]); + $_SESSION['message'] = "Registration successful! You can now log in."; + $_SESSION['alert_type'] = 'success'; + header("Location: login.php"); // Redirect to login page on success + exit(); + } catch (PDOException $e) { + // Check for duplicate entry specifically + if ($e->errorInfo[1] == 1062) { + $_SESSION['message'] = "A user with this ID number or phone number already exists."; + } else { + $_SESSION['message'] = "An error occurred during registration. Please try again."; + } + $_SESSION['alert_type'] = 'danger'; + header("Location: register.php"); + exit(); + } + } + } + } + if ($error) { + $_SESSION['message'] = $message; + $_SESSION['alert_type'] = 'danger'; + header("Location: register.php"); + exit(); + } + } + ?> + +
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + + +
+ + +
+ +
+
+ + +
+
+ + +
+
+ +
+ +
+
+
+
+
+ +
+ + + + + + + + + + diff --git a/search.php b/search.php new file mode 100644 index 0000000..afd05aa --- /dev/null +++ b/search.php @@ -0,0 +1,34 @@ + + + + + + Search - MyMech + + + + + + + +
+

Search

+

This page is under construction. The search functionality for mechanics and spare parts will be available here soon.

+ +
+ + + + + + \ No newline at end of file diff --git a/terms.php b/terms.php new file mode 100644 index 0000000..f41fd70 --- /dev/null +++ b/terms.php @@ -0,0 +1,34 @@ + + + + + + Terms of Service - MyMech + + + + + + + +
+

Terms of Service

+

This page is under construction. Our Terms of Service will be detailed here.

+ +
+ + + + + + \ No newline at end of file