v1.3
This commit is contained in:
parent
9044377b64
commit
d627358851
133
admin/dashboard.php
Normal file
133
admin/dashboard.php
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
require_once '../db/config.php'; // Adjusted path for db/config.php
|
||||||
|
|
||||||
|
// Security check: Ensure user is logged in and is an admin
|
||||||
|
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'admin') {
|
||||||
|
// If not an admin, redirect to the login page with an error message
|
||||||
|
$_SESSION['message'] = "You must be an administrator to access this page.";
|
||||||
|
$_SESSION['alert_type'] = 'danger';
|
||||||
|
header("Location: ../login.php");
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch all users from the database
|
||||||
|
$pdo = db_connect();
|
||||||
|
$users = [];
|
||||||
|
if ($pdo) {
|
||||||
|
try {
|
||||||
|
$stmt = $pdo->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.";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Admin Dashboard - MyMech</title>
|
||||||
|
<meta name="robots" content="noindex, nofollow"> <!-- Prevent search engines from indexing the admin page -->
|
||||||
|
|
||||||
|
<!-- Bootstrap 5 CDN -->
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
|
||||||
|
<!-- Google Fonts (Poppins) -->
|
||||||
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||||
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap" rel="stylesheet">
|
||||||
|
|
||||||
|
<!-- Custom CSS -->
|
||||||
|
<link rel="stylesheet" href="../assets/css/custom.css?v=<?php echo time(); ?>">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<!-- Navbar -->
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-dark bg-navy-blue-darker">
|
||||||
|
<div class="container">
|
||||||
|
<a class="navbar-brand" href="../index.php"><span class="golden-text">MyMech</span></a>
|
||||||
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||||
|
<span class="navbar-toggler-icon"></span>
|
||||||
|
</button>
|
||||||
|
<div class="collapse navbar-collapse" id="navbarNav">
|
||||||
|
<ul class="navbar-nav ms-auto align-items-center">
|
||||||
|
<li class="nav-item">
|
||||||
|
<span class="navbar-text text-white me-3">Welcome, Admin!</span>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="btn btn-outline-golden px-3" href="../logout.php">Logout</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<!-- Admin Dashboard Section -->
|
||||||
|
<section class="admin-dashboard-section">
|
||||||
|
<div class="container-fluid"> <!-- Use fluid container for more space -->
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="dashboard-container">
|
||||||
|
<h2 class="text-center golden-text mb-4">Administrator Dashboard</h2>
|
||||||
|
<p class="text-center mb-5">Manage all registered users in the system.</p>
|
||||||
|
|
||||||
|
<?php if (isset($user_list_error)): ?>
|
||||||
|
<div class="alert alert-danger"><?php echo htmlspecialchars($user_list_error); ?></div>
|
||||||
|
<?php elseif (empty($users)): ?>
|
||||||
|
<div class="alert alert-info">No users have registered yet.</div>
|
||||||
|
<?php else: ?>
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-dark table-striped table-hover">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>Role</th>
|
||||||
|
<th>Full Name</th>
|
||||||
|
<th>ID Number</th>
|
||||||
|
<th>Phone</th>
|
||||||
|
<th>Garage/Shop</th>
|
||||||
|
<th>Location</th>
|
||||||
|
<th>Registered On</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php foreach ($users as $user): ?>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo htmlspecialchars($user['id']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars(ucfirst(str_replace('_', ' ', $user['user_role']))); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($user['full_name']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($user['id_number']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($user['phone_number']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($user['garage_name'] ?? 'N/A'); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($user['location']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars(date("M d, Y H:i", strtotime($user['created_at']))); ?></td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- Footer -->
|
||||||
|
<footer class="footer text-center">
|
||||||
|
<div class="container">
|
||||||
|
<p>© <?php echo date("Y"); ?> MyMech. All Rights Reserved.</p>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<!-- Bootstrap 5 JS Bundle -->
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
<!-- Custom JS -->
|
||||||
|
<script src="../assets/js/main.js?v=<?php echo time(); ?>"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@ -149,6 +149,45 @@ body {
|
|||||||
color: var(--golden-yellow);
|
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 */
|
/* Responsive Adjustments */
|
||||||
@media (max-width: 991.98px) {
|
@media (max-width: 991.98px) {
|
||||||
|
|||||||
@ -1,5 +1,30 @@
|
|||||||
// Custom JavaScript for MyMech
|
// Custom JavaScript for MyMech
|
||||||
document.addEventListener('DOMContentLoaded', function () {
|
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");
|
console.log("MyMech JS loaded");
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,17 +1,47 @@
|
|||||||
<?php
|
<?php
|
||||||
// Generated by setup_mariadb_project.sh — edit as needed.
|
// db/config.php
|
||||||
define('DB_HOST', '127.0.0.1');
|
|
||||||
define('DB_NAME', 'app_34233');
|
|
||||||
define('DB_USER', 'app_34233');
|
|
||||||
define('DB_PASS', 'b3b671b9-a1a3-4bff-aa00-682f316d944e');
|
|
||||||
|
|
||||||
function db() {
|
// --- Database Credentials ---
|
||||||
static $pdo;
|
// Replace with your actual database credentials
|
||||||
if (!$pdo) {
|
define('DB_HOST', '127.0.0.1');
|
||||||
$pdo = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8mb4', DB_USER, DB_PASS, [
|
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_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
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;
|
return $pdo;
|
||||||
}
|
}
|
||||||
|
?>
|
||||||
16
index.php
16
index.php
@ -36,10 +36,10 @@
|
|||||||
<div class="collapse navbar-collapse" id="navbarNav">
|
<div class="collapse navbar-collapse" id="navbarNav">
|
||||||
<ul class="navbar-nav ms-auto align-items-center">
|
<ul class="navbar-nav ms-auto align-items-center">
|
||||||
<li class="nav-item mb-2 mb-lg-0 me-lg-2">
|
<li class="nav-item mb-2 mb-lg-0 me-lg-2">
|
||||||
<a class="btn btn-outline-golden px-3" href="#">Login</a>
|
<a class="btn btn-outline-golden px-3" href="login.php">Login</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="btn btn-golden px-3" href="#">Register</a>
|
<a class="btn btn-golden px-3" href="register.php">Register</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
@ -52,8 +52,8 @@
|
|||||||
<h1 class="display-3">Your Trusted Mechanic, <span class="golden-text">Just a Click Away.</span></h1>
|
<h1 class="display-3">Your Trusted Mechanic, <span class="golden-text">Just a Click Away.</span></h1>
|
||||||
<p class="lead">Find reliable mechanics and genuine spare parts instantly. Get back on the road faster.</p>
|
<p class="lead">Find reliable mechanics and genuine spare parts instantly. Get back on the road faster.</p>
|
||||||
<div class="d-grid gap-2 d-sm-flex justify-content-sm-center">
|
<div class="d-grid gap-2 d-sm-flex justify-content-sm-center">
|
||||||
<a href="#" class="btn btn-golden btn-lg px-4 gap-3">Find a Mechanic</a>
|
<a href="search.php" class="btn btn-golden btn-lg px-4 gap-3">Find a Mechanic</a>
|
||||||
<a href="#" class="btn btn-outline-light btn-lg px-4">Find Spare Parts</a>
|
<a href="search.php" class="btn btn-outline-light btn-lg px-4">Find Spare Parts</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
@ -71,7 +71,7 @@
|
|||||||
<h3>For Drivers</h3>
|
<h3>For Drivers</h3>
|
||||||
<p>Get fast, reliable help from trusted mechanics near you. Search for specific services and parts to get exactly what you need.</p>
|
<p>Get fast, reliable help from trusted mechanics near you. Search for specific services and parts to get exactly what you need.</p>
|
||||||
</div>
|
</div>
|
||||||
<a href="#" class="btn btn-golden mt-3">Sign Up as a Driver</a>
|
<a href="register.php" class="btn btn-golden mt-3">Sign Up as a Driver</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- For Mechanics -->
|
<!-- For Mechanics -->
|
||||||
@ -82,7 +82,7 @@
|
|||||||
<h3>For Mechanics</h3>
|
<h3>For Mechanics</h3>
|
||||||
<p>Grow your business by connecting with car owners in your area. List your services and showcase your expertise.</p>
|
<p>Grow your business by connecting with car owners in your area. List your services and showcase your expertise.</p>
|
||||||
</div>
|
</div>
|
||||||
<a href="#" class="btn btn-golden mt-3">Register Your Garage</a>
|
<a href="register.php" class="btn btn-golden mt-3">Register Your Garage</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- For Shops -->
|
<!-- For Shops -->
|
||||||
@ -93,7 +93,7 @@
|
|||||||
<h3>For Part Shops</h3>
|
<h3>For Part Shops</h3>
|
||||||
<p>List your inventory and reach a larger audience. Help drivers find the genuine parts they need quickly and easily.</p>
|
<p>List your inventory and reach a larger audience. Help drivers find the genuine parts they need quickly and easily.</p>
|
||||||
</div>
|
</div>
|
||||||
<a href="#" class="btn btn-golden mt-3">List Your Parts</a>
|
<a href="register.php" class="btn btn-golden mt-3">List Your Parts</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -105,7 +105,7 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<p>© <?php echo date("Y"); ?> MyMech. All Rights Reserved.</p>
|
<p>© <?php echo date("Y"); ?> MyMech. All Rights Reserved.</p>
|
||||||
<p>
|
<p>
|
||||||
<a href="#">Privacy Policy</a> | <a href="#">Terms of Service</a>
|
<a href="privacy.php">Privacy Policy</a> | <a href="terms.php">Terms of Service</a>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
|
|||||||
132
login.php
Normal file
132
login.php
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
require_once 'db/config.php';
|
||||||
|
|
||||||
|
// Handle login form submission
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
$login_identifier = $_POST['login_identifier'] ?? '';
|
||||||
|
$password = $_POST['password'] ?? '';
|
||||||
|
$error = '';
|
||||||
|
|
||||||
|
if (empty($login_identifier) || empty($password)) {
|
||||||
|
$error = "Please enter both your identifier and password.";
|
||||||
|
} else {
|
||||||
|
$pdo = db_connect();
|
||||||
|
if ($pdo) {
|
||||||
|
// Check if the identifier is a phone number or an ID number
|
||||||
|
$sql = "SELECT id, full_name, user_role, password_hash FROM users WHERE phone_number = :identifier OR id_number = :identifier";
|
||||||
|
$stmt = $pdo->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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Login - MyMech</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-dark bg-navy-blue-darker">
|
||||||
|
<div class="container">
|
||||||
|
<a class="navbar-brand" href="index.php"><span class="golden-text">MyMech</span></a>
|
||||||
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||||
|
<span class="navbar-toggler-icon"></span>
|
||||||
|
</button>
|
||||||
|
<div class="collapse navbar-collapse" id="navbarNav">
|
||||||
|
<ul class="navbar-nav ms-auto align-items-center">
|
||||||
|
<li class="nav-item mb-2 mb-lg-0 me-lg-2">
|
||||||
|
<a class="btn btn-outline-golden px-3" href="login.php">Login</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="btn btn-golden px-3" href="register.php">Register</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<main class="container py-5">
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-lg-6 col-md-8">
|
||||||
|
<div class="form-container">
|
||||||
|
<h2 class="text-center golden-text mb-4">Login to Your Account</h2>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
// Display messages if any (e.g., from registration or login errors)
|
||||||
|
if (isset($_SESSION['message'])) {
|
||||||
|
$message = $_SESSION['message'];
|
||||||
|
$alert_type = $_SESSION['alert_type'];
|
||||||
|
echo "<div class='alert alert-{$alert_type} alert-dismissible fade show' role='alert'>";
|
||||||
|
echo htmlspecialchars($message);
|
||||||
|
echo '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>';
|
||||||
|
echo "</div>";
|
||||||
|
// Unset the session variables so they don't persist
|
||||||
|
unset($_SESSION['message']);
|
||||||
|
unset($_SESSION['alert_type']);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<form action="login.php" method="POST">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="login_identifier" class="form-label">Phone Number or National ID</label>
|
||||||
|
<input type="text" class="form-control" id="login_identifier" name="login_identifier" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="password" class="form-label">Password</label>
|
||||||
|
<input type="password" class="form-control" id="password" name="password" required>
|
||||||
|
</div>
|
||||||
|
<div class="d-grid">
|
||||||
|
<button type="submit" class="btn btn-golden btn-lg">Login</button>
|
||||||
|
</div>
|
||||||
|
<p class="text-center mt-4">Don't have an account? <a href="register.php">Register here</a>.</p>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer class="footer text-center">
|
||||||
|
<div class="container">
|
||||||
|
<p>© <?php echo date("Y"); ?> MyMech. All Rights Reserved.</p>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
7
logout.php
Normal file
7
logout.php
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
session_unset();
|
||||||
|
session_destroy();
|
||||||
|
header("Location: login.php");
|
||||||
|
exit();
|
||||||
|
?>
|
||||||
34
privacy.php
Normal file
34
privacy.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Privacy Policy - MyMech</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
||||||
|
<div class="container">
|
||||||
|
<a class="navbar-brand" href="index.php"><span class="golden-text">MyMech</span></a>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<main class="container py-5">
|
||||||
|
<h2 class="golden-text">Privacy Policy</h2>
|
||||||
|
<p>This page is under construction. Our Privacy Policy will be detailed here.</p>
|
||||||
|
<div class="text-center mt-4">
|
||||||
|
<a href="index.php" class="btn btn-golden">Go Back to Home</a>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer class="footer text-center">
|
||||||
|
<div class="container">
|
||||||
|
<p>© <?php echo date("Y"); ?> MyMech. All Rights Reserved.</p>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
232
register.php
Normal file
232
register.php
Normal file
@ -0,0 +1,232 @@
|
|||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Register - MyMech</title>
|
||||||
|
<meta name="description" content="Join MyMech to find reliable mechanics and genuine spare parts.">
|
||||||
|
|
||||||
|
<!-- Bootstrap 5 CDN -->
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
|
||||||
|
<!-- Google Fonts (Poppins) -->
|
||||||
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||||
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap" rel="stylesheet">
|
||||||
|
|
||||||
|
<!-- Custom CSS -->
|
||||||
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<!-- Navbar -->
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-dark bg-navy-blue-darker">
|
||||||
|
<div class="container">
|
||||||
|
<a class="navbar-brand" href="index.php"><span class="golden-text">MyMech</span></a>
|
||||||
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||||
|
<span class="navbar-toggler-icon"></span>
|
||||||
|
</button>
|
||||||
|
<div class="collapse navbar-collapse" id="navbarNav">
|
||||||
|
<ul class="navbar-nav ms-auto align-items-center">
|
||||||
|
<li class="nav-item mb-2 mb-lg-0 me-lg-2">
|
||||||
|
<a class="btn btn-outline-golden px-3" href="login.php">Login</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="btn btn-golden px-3" href="register.php">Register</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<!-- Registration Form Section -->
|
||||||
|
<section class="form-section">
|
||||||
|
<div class="container">
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-lg-7 col-md-9">
|
||||||
|
<div class="form-container">
|
||||||
|
<h2 class="text-center golden-text mb-4">Create Your Account</h2>
|
||||||
|
<p class="text-center mb-5">Join our community of drivers, mechanics, and part suppliers.</p>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
session_start(); // Start the session to store messages
|
||||||
|
|
||||||
|
// Display messages if any
|
||||||
|
if (isset($_SESSION['message'])) {
|
||||||
|
$message = $_SESSION['message'];
|
||||||
|
$alert_type = $_SESSION['alert_type'];
|
||||||
|
echo "<div class='alert alert-{$alert_type} alert-dismissible fade show' role='alert'>";
|
||||||
|
echo $message;
|
||||||
|
echo '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>';
|
||||||
|
echo "</div>";
|
||||||
|
// 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<form action="register.php" method="POST" id="registrationForm">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="user_role" class="form-label">I am a...</label>
|
||||||
|
<select class="form-select" id="user_role" name="user_role" required>
|
||||||
|
<option value="driver" selected>Car Owner / Driver</option>
|
||||||
|
<option value="mechanic">Mechanic</option>
|
||||||
|
<option value="shop_owner">Spare Part Shop Owner</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="full_name" class="form-label">Full Names (as on National ID)</label>
|
||||||
|
<input type="text" class="form-control" id="full_name" name="full_name" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="id_number" class="form-label">National ID Number</label>
|
||||||
|
<input type="text" class="form-control" id="id_number" name="id_number" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="phone_number" class="form-label">Phone Number</label>
|
||||||
|
<input type="tel" class="form-control" id="phone_number" name="phone_number" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3" id="garage_name_field" style="display: none;">
|
||||||
|
<label for="garage_name" class="form-label">Garage/Shop Name</label>
|
||||||
|
<input type="text" class="form-control" id="garage_name" name="garage_name">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="location" class="form-label">Location / Address</label>
|
||||||
|
<input type="text" class="form-control" id="location" name="location" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6 mb-3">
|
||||||
|
<label for="password" class="form-label">Password</label>
|
||||||
|
<input type="password" class="form-control" id="password" name="password" required>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6 mb-3">
|
||||||
|
<label for="confirm_password" class="form-label">Confirm Password</label>
|
||||||
|
<input type="password" class="form-control" id="confirm_password" name="confirm_password" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="d-grid">
|
||||||
|
<button type="submit" class="btn btn-golden btn-lg">Register</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- Footer -->
|
||||||
|
<footer class="footer text-center">
|
||||||
|
<div class="container">
|
||||||
|
<p>© <?php echo date("Y"); ?> MyMech. All Rights Reserved.</p>
|
||||||
|
<p>
|
||||||
|
<a href="privacy.php">Privacy Policy</a> | <a href="terms.php">Terms of Service</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<!-- Bootstrap 5 JS Bundle -->
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
<!-- Custom JS -->
|
||||||
|
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
34
search.php
Normal file
34
search.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Search - MyMech</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
||||||
|
<div class="container">
|
||||||
|
<a class="navbar-brand" href="index.php"><span class="golden-text">MyMech</span></a>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<main class="container py-5 text-center">
|
||||||
|
<h2 class="golden-text">Search</h2>
|
||||||
|
<p>This page is under construction. The search functionality for mechanics and spare parts will be available here soon.</p>
|
||||||
|
<div class="text-center mt-4">
|
||||||
|
<a href="index.php" class="btn btn-golden">Go Back to Home</a>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer class="footer text-center">
|
||||||
|
<div class="container">
|
||||||
|
<p>© <?php echo date("Y"); ?> MyMech. All Rights Reserved.</p>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
34
terms.php
Normal file
34
terms.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Terms of Service - MyMech</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
||||||
|
<div class="container">
|
||||||
|
<a class="navbar-brand" href="index.php"><span class="golden-text">MyMech</span></a>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<main class="container py-5">
|
||||||
|
<h2 class="golden-text">Terms of Service</h2>
|
||||||
|
<p>This page is under construction. Our Terms of Service will be detailed here.</p>
|
||||||
|
<div class="text-center mt-4">
|
||||||
|
<a href="index.php" class="btn btn-golden">Go Back to Home</a>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer class="footer text-center">
|
||||||
|
<div class="container">
|
||||||
|
<p>© <?php echo date("Y"); ?> MyMech. All Rights Reserved.</p>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
x
Reference in New Issue
Block a user