26
This commit is contained in:
parent
1b310520c9
commit
f054121ef2
104
admin/bookings.php
Normal file
104
admin/bookings.php
Normal file
@ -0,0 +1,104 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'admin') {
|
||||
header("Location: ../login.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
require_once '../db/config.php';
|
||||
|
||||
$pdo = db();
|
||||
|
||||
// Handle booking status change
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$bookingId = $_POST['booking_id'];
|
||||
$carId = $_POST['car_id'];
|
||||
|
||||
if (isset($_POST['approve'])) {
|
||||
$pdo->prepare("UPDATE bookings SET status = 'approved' WHERE id = ?")->execute([$bookingId]);
|
||||
$pdo->prepare("UPDATE cars SET status = 'sold' WHERE id = ?")->execute([$carId]);
|
||||
} elseif (isset($_POST['cancel'])) {
|
||||
$pdo->prepare("UPDATE bookings SET status = 'canceled' WHERE id = ?")->execute([$bookingId]);
|
||||
$pdo->prepare("UPDATE cars SET status = 'for_sale' WHERE id = ?")->execute([$carId]);
|
||||
}
|
||||
header("Location: bookings.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
$bookings = $pdo->query("
|
||||
SELECT b.id, b.status, b.booking_date, u.username, c.make, c.model, c.id as car_id
|
||||
FROM bookings b
|
||||
JOIN users u ON b.user_id = u.id
|
||||
JOIN cars c ON b.car_id = c.id
|
||||
ORDER BY b.booking_date DESC
|
||||
")->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$projectName = 'Manage Bookings';
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><?= htmlspecialchars($projectName) ?></title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css">
|
||||
<link rel="stylesheet" href="../assets/css/custom.css?v=<?= time() ?>">
|
||||
</head>
|
||||
<body class="admin-dashboard">
|
||||
<?php include __DIR__ . '/../partials/navbar.php'; ?>
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<nav id="sidebar" class="col-md-3 col-lg-2 d-md-block bg-light sidebar collapse">
|
||||
<div class="position-sticky pt-3">
|
||||
<ul class="nav flex-column">
|
||||
<li class="nav-item"><a class="nav-link" href="index.php"><i class="bi bi-house-door"></i> Dashboard</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="users.php"><i class="bi bi-people"></i> Manage Users</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="cars.php"><i class="bi bi-car-front"></i> Manage Cars</a></li>
|
||||
<li class="nav-item"><a class="nav-link active" aria-current="page" href="bookings.php"><i class="bi bi-calendar-check"></i> Manage Bookings</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="reviews.php"><i class="bi bi-star-fill"></i> Manage Reviews</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
<main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
|
||||
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
||||
<h1 class="h2">Manage Bookings</h1>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped">
|
||||
<thead class="table-dark">
|
||||
<tr><th>User</th><th>Car</th><th>Date</th><th>Status</th><th>Actions</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($bookings as $booking): ?>
|
||||
<tr>
|
||||
<td><?= htmlspecialchars($booking['username']) ?></td>
|
||||
<td><?= htmlspecialchars($booking['make'] . ' ' . $booking['model']) ?></td>
|
||||
<td><?= date("M d, Y", strtotime($booking['booking_date'])) ?></td>
|
||||
<td><span class="badge bg-info"><?= htmlspecialchars($booking['status']) ?></span></td>
|
||||
<td>
|
||||
<?php if ($booking['status'] === 'pending'): ?>
|
||||
<form method="POST" class="d-inline">
|
||||
<input type="hidden" name="booking_id" value="<?= $booking['id'] ?>">
|
||||
<input type="hidden" name="car_id" value="<?= $booking['car_id'] ?>">
|
||||
<button type="submit" name="approve" class="btn btn-sm btn-success">Approve</button>
|
||||
<button type="submit" name="cancel" class="btn btn-sm btn-danger">Cancel</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
200
admin/cars.php
Normal file
200
admin/cars.php
Normal file
@ -0,0 +1,200 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'admin') {
|
||||
header("Location: ../login.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
require_once '../db/config.php';
|
||||
|
||||
$pdo = db();
|
||||
|
||||
// Handle Add/Edit/Delete
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
// Delete
|
||||
if (isset($_POST['delete_car'])) {
|
||||
$carId = $_POST['car_id'];
|
||||
$stmt = $pdo->prepare("DELETE FROM cars WHERE id = ?");
|
||||
$stmt->execute([$carId]);
|
||||
header("Location: cars.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
// Add/Edit
|
||||
$carId = $_POST['car_id'] ?? null;
|
||||
$make = $_POST['make'];
|
||||
$model = $_POST['model'];
|
||||
$year = $_POST['year'];
|
||||
$price = $_POST['price'];
|
||||
$status = $_POST['status'];
|
||||
$description = $_POST['description'];
|
||||
$imageUrl = $_POST['existing_image']; // Keep existing image by default
|
||||
|
||||
if (isset($_FILES['image']) && $_FILES['image']['error'] == 0) {
|
||||
$targetDir = "../assets/images/cars/";
|
||||
if (!is_dir($targetDir)) mkdir($targetDir, 0755, true);
|
||||
$fileName = uniqid() . '-' . basename($_FILES["image"]["name"]);
|
||||
$targetFilePath = $targetDir . $fileName;
|
||||
if (move_uploaded_file($_FILES["image"]["tmp_name"], $targetFilePath)) {
|
||||
$imageUrl = 'assets/images/cars/' . $fileName;
|
||||
}
|
||||
}
|
||||
|
||||
if ($carId) { // Update
|
||||
$sql = "UPDATE cars SET make=?, model=?, year=?, price=?, status=?, description=?, image_url=? WHERE id=?";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$make, $model, $year, $price, $status, $description, $imageUrl, $carId]);
|
||||
} else { // Insert
|
||||
$sql = "INSERT INTO cars (make, model, year, price, status, description, image_url) VALUES (?, ?, ?, ?, ?, ?, ?)";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$make, $model, $year, $price, $status, $description, $imageUrl]);
|
||||
}
|
||||
header("Location: cars.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
$search = $_GET['search'] ?? '';
|
||||
$filter_status = $_GET['status'] ?? 'all';
|
||||
|
||||
$sql = "SELECT * FROM cars";
|
||||
$params = [];
|
||||
if (!empty($search)) {
|
||||
$sql .= " WHERE (make LIKE ? OR model LIKE ?)";
|
||||
$params[] = "%$search%";
|
||||
$params[] = "%$search%";
|
||||
}
|
||||
if ($filter_status !== 'all') {
|
||||
$sql .= (strpos($sql, 'WHERE') === false ? " WHERE" : " AND") . " status = ?";
|
||||
$params[] = $filter_status;
|
||||
}
|
||||
$sql .= " ORDER BY created_at DESC";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$cars = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$projectName = 'Manage Cars';
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><?php echo htmlspecialchars($projectName); ?></title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="../assets/css/custom.css?v=<?php echo time(); ?>">
|
||||
</head>
|
||||
<body class="admin-dashboard">
|
||||
<?php include __DIR__ . '/../partials/navbar.php'; ?>
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<nav id="sidebar" class="col-md-3 col-lg-2 d-md-block bg-light sidebar collapse">
|
||||
<div class="position-sticky pt-3">
|
||||
<ul class="nav flex-column">
|
||||
<li class="nav-item"><a class="nav-link" href="index.php"><i class="bi bi-house-door"></i> Dashboard</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="users.php"><i class="bi bi-people"></i> Manage Users</a></li>
|
||||
<li class="nav-item"><a class="nav-link active" aria-current="page" href="cars.php"><i class="bi bi-car-front"></i> Manage Cars</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="bookings.php"><i class="bi bi-calendar-check"></i> Manage Bookings</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="reviews.php"><i class="bi bi-star-fill"></i> Manage Reviews</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
<main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
|
||||
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
||||
<h1 class="h2">Manage Cars</h1>
|
||||
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#carModal"><i class="bi bi-plus-circle"></i> Add New Car</button>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<form method="GET" action="cars.php" class="row g-3">
|
||||
<div class="col-md-4"><input type="text" name="search" class="form-control" placeholder="Search by make or model..." value="<?= htmlspecialchars($search) ?>"></div>
|
||||
<div class="col-md-3">
|
||||
<select name="status" class="form-select">
|
||||
<option value="all">All Statuses</option>
|
||||
<option value="for_sale" <?= $filter_status == 'for_sale' ? 'selected' : '' ?>>For Sale</option>
|
||||
<option value="reserved" <?= $filter_status == 'reserved' ? 'selected' : '' ?>>Reserved</option>
|
||||
<option value="sold" <?= $filter_status == 'sold' ? 'selected' : '' ?>>Sold</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-2"><button type="submit" class="btn btn-primary">Filter</button></div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped">
|
||||
<thead class="table-dark">
|
||||
<tr><th>Image</th><th>Make/Model</th><th>Year</th><th>Price</th><th>Status</th><th>Actions</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($cars as $car): ?>
|
||||
<tr>
|
||||
<td><img src="../<?= htmlspecialchars($car['image_url']) ?>" height="50" alt="<?= htmlspecialchars($car['make']) ?>"></td>
|
||||
<td><?= htmlspecialchars($car['make'] . ' ' . $car['model']) ?></td>
|
||||
<td><?= htmlspecialchars($car['year']) ?></td>
|
||||
<td>$<?= number_format($car['price']) ?></td>
|
||||
<td><span class="badge bg-info"><?= htmlspecialchars($car['status']) ?></span></td>
|
||||
<td>
|
||||
<button type="button" class="btn btn-sm btn-outline-primary edit-btn" data-bs-toggle="modal" data-bs-target="#carModal" data-car='<?= json_encode($car) ?>'><i class="bi bi-pencil-square"></i></button>
|
||||
<form method="POST" class="d-inline" onsubmit="return confirm('Delete this car?');">
|
||||
<input type="hidden" name="car_id" value="<?= $car['id'] ?>">
|
||||
<button type="submit" name="delete_car" class="btn btn-sm btn-outline-danger"><i class="bi bi-trash"></i></button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Car Modal -->
|
||||
<div class="modal fade" id="carModal" tabindex="-1">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<form method="POST" enctype="multipart/form-data">
|
||||
<input type="hidden" name="car_id" id="car_id">
|
||||
<input type="hidden" name="existing_image" id="existing_image">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="modalTitle">Add Car</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3"><label>Make</label><input type="text" name="make" id="make" class="form-control" required></div>
|
||||
<div class="col-md-6 mb-3"><label>Model</label><input type="text" name="model" id="model" class="form-control" required></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3"><label>Year</label><input type="number" name="year" id="year" class="form-control" required></div>
|
||||
<div class="col-md-6 mb-3"><label>Price</label><input type="number" name="price" id="price" class="form-control" step="0.01" required></div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label>Status</label>
|
||||
<select name="status" id="status" class="form-select">
|
||||
<option value="for_sale">For Sale</option>
|
||||
<option value="reserved">Reserved</option>
|
||||
<option value="sold">Sold</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3"><label>Description</label><textarea name="description" id="description" class="form-control" rows="3"></textarea></div>
|
||||
<div class="mb-3"><label>Image</label><input type="file" name="image" class="form-control"></div>
|
||||
<img id="image_preview" src="" class="img-fluid rounded" style="max-height: 150px;">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
||||
<button type="submit" class="btn btn-primary">Save Car</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
120
admin/index.php
Normal file
120
admin/index.php
Normal file
@ -0,0 +1,120 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'admin') {
|
||||
header("Location: ../login.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
require_once '../db/config.php';
|
||||
|
||||
$pdo = db();
|
||||
|
||||
// Stats
|
||||
$stats = [
|
||||
'users' => $pdo->query("SELECT COUNT(*) FROM users")->fetchColumn(),
|
||||
'cars' => $pdo->query("SELECT COUNT(*) FROM cars")->fetchColumn(),
|
||||
'bookings' => $pdo->query("SELECT COUNT(*) FROM bookings")->fetchColumn(),
|
||||
'reviews' => $pdo->query("SELECT COUNT(*) FROM reviews")->fetchColumn(),
|
||||
];
|
||||
|
||||
// Chart Data
|
||||
$sales_data = $pdo->query("SELECT DATE(booking_date) as date, COUNT(*) as count FROM bookings WHERE status = 'approved' GROUP BY DATE(booking_date) ORDER BY date ASC")->fetchAll(PDO::FETCH_ASSOC);
|
||||
$bookings_status_data = $pdo->query("SELECT status, COUNT(*) as count FROM bookings GROUP BY status")->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// Top Cars
|
||||
$top_selling_cars = $pdo->query("
|
||||
SELECT c.make, c.model, COUNT(b.id) as sales
|
||||
FROM cars c
|
||||
JOIN bookings b ON c.id = b.car_id
|
||||
WHERE b.status = 'approved'
|
||||
GROUP BY c.id
|
||||
ORDER BY sales DESC
|
||||
LIMIT 5
|
||||
")->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$most_popular_cars = $pdo->query("
|
||||
SELECT c.make, c.model, COUNT(r.id) as review_count
|
||||
FROM cars c
|
||||
LEFT JOIN reviews r ON c.id = r.car_id
|
||||
GROUP BY c.id
|
||||
ORDER BY review_count DESC
|
||||
LIMIT 5
|
||||
")->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$projectName = 'Admin Dashboard';
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><?= htmlspecialchars($projectName) ?></title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css">
|
||||
<link rel="stylesheet" href="../assets/css/custom.css?v=<?= time() ?>">
|
||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||
</head>
|
||||
<body class="admin-dashboard">
|
||||
<?php include __DIR__ . '/../partials/navbar.php'; ?>
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<nav id="sidebar" class="col-md-3 col-lg-2 d-md-block bg-light sidebar collapse">
|
||||
<div class="position-sticky pt-3">
|
||||
<ul class="nav flex-column">
|
||||
<li class="nav-item"><a class="nav-link active" aria-current="page" href="index.php"><i class="bi bi-house-door"></i> Dashboard</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="users.php"><i class="bi bi-people"></i> Manage Users</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="cars.php"><i class="bi bi-car-front"></i> Manage Cars</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="bookings.php"><i class="bi bi-calendar-check"></i> Manage Bookings</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="reviews.php"><i class="bi bi-star-fill"></i> Manage Reviews</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
<main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
|
||||
<h1 class="h2 pt-3 pb-2 mb-3 border-bottom">Dashboard</h1>
|
||||
<div class="row g-4">
|
||||
<!-- Stat Cards -->
|
||||
<div class="col-6 col-lg-3"><div class="card bg-primary text-white"><div class="card-body"><h5>Users</h5><p class="fs-2"><?= $stats['users'] ?></p></div></div></div>
|
||||
<div class="col-6 col-lg-3"><div class="card bg-success text-white"><div class="card-body"><h5>Cars</h5><p class="fs-2"><?= $stats['cars'] ?></p></div></div></div>
|
||||
<div class="col-6 col-lg-3"><div class="card bg-info text-white"><div class="card-body"><h5>Bookings</h5><p class="fs-2"><?= $stats['bookings'] ?></p></div></div></div>
|
||||
<div class="col-6 col-lg-3"><div class="card bg-warning text-white"><div class="card-body"><h5>Reviews</h5><p class="fs-2"><?= $stats['reviews'] ?></p></div></div></div>
|
||||
|
||||
<!-- Charts -->
|
||||
<div class="col-md-8"><div class="card"><div class="card-header">Sales Over Time</div><div class="card-body"><canvas id="salesChart"></canvas></div></div></div>
|
||||
<div class="col-md-4"><div class="card"><div class="card-header">Bookings Status</div><div class="card-body"><canvas id="bookingsChart"></canvas></div></div></div>
|
||||
|
||||
<!-- Top Lists -->
|
||||
<div class="col-md-6"><div class="card"><div class="card-header">Top Selling Cars</div><div class="card-body"><ul class="list-group list-group-flush"><?php foreach($top_selling_cars as $c) echo "<li class='list-group-item'>{$c['make']} {$c['model']} <span class='badge bg-success float-end'>{$c['sales']} sales</span></li>"; ?></ul></div></div></div>
|
||||
<div class="col-md-6"><div class="card"><div class="card-header">Most Popular Cars (by Reviews)</div><div class="card-body"><ul class="list-group list-group-flush"><?php foreach($most_popular_cars as $c) echo "<li class='list-group-item'>{$c['make']} {$c['model']} <span class='badge bg-warning float-end'>{$c['review_count']} reviews</span></li>"; ?></ul></div></div></div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
const salesChart = new Chart(document.getElementById('salesChart'), {
|
||||
type: 'line',
|
||||
data: {
|
||||
labels: <?= json_encode(array_column($sales_data, 'date')) ?>,
|
||||
datasets: [{
|
||||
label: 'Sales',
|
||||
data: <?= json_encode(array_column($sales_data, 'count')) ?>,
|
||||
borderColor: 'rgba(75, 192, 192, 1)',
|
||||
tension: 0.1
|
||||
}]
|
||||
}
|
||||
});
|
||||
|
||||
const bookingsChart = new Chart(document.getElementById('bookingsChart'), {
|
||||
type: 'doughnut',
|
||||
data: {
|
||||
labels: <?= json_encode(array_column($bookings_status_data, 'status')) ?>,
|
||||
datasets: [{
|
||||
data: <?= json_encode(array_column($bookings_status_data, 'count')) ?>,
|
||||
backgroundColor: ['#0d6efd', '#198754', '#dc3545']
|
||||
}]
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
102
admin/reviews.php
Normal file
102
admin/reviews.php
Normal file
@ -0,0 +1,102 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'admin') {
|
||||
header("Location: ../login.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
require_once '../db/config.php';
|
||||
|
||||
$pdo = db();
|
||||
|
||||
// Handle review status change
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$reviewId = $_POST['review_id'];
|
||||
|
||||
if (isset($_POST['approve'])) {
|
||||
$pdo->prepare("UPDATE reviews SET status = 'approved' WHERE id = ?")->execute([$reviewId]);
|
||||
} elseif (isset($_POST['delete'])) {
|
||||
$pdo->prepare("DELETE FROM reviews WHERE id = ?")->execute([$reviewId]);
|
||||
}
|
||||
header("Location: reviews.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
$reviews = $pdo->query("
|
||||
SELECT r.id, r.rating, r.review, r.status, r.created_at, u.username, c.make, c.model
|
||||
FROM reviews r
|
||||
JOIN users u ON r.user_id = u.id
|
||||
JOIN cars c ON r.car_id = c.id
|
||||
ORDER BY r.created_at DESC
|
||||
")->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$projectName = 'Manage Reviews';
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><?= htmlspecialchars($projectName) ?></title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css">
|
||||
<link rel="stylesheet" href="../assets/css/custom.css?v=<?= time() ?>">
|
||||
</head>
|
||||
<body class="admin-dashboard">
|
||||
<?php include __DIR__ . '/../partials/navbar.php'; ?>
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<nav id="sidebar" class="col-md-3 col-lg-2 d-md-block bg-light sidebar collapse">
|
||||
<div class="position-sticky pt-3">
|
||||
<ul class="nav flex-column">
|
||||
<li class="nav-item"><a class="nav-link" href="index.php"><i class="bi bi-house-door"></i> Dashboard</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="users.php"><i class="bi bi-people"></i> Manage Users</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="cars.php"><i class="bi bi-car-front"></i> Manage Cars</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="bookings.php"><i class="bi bi-calendar-check"></i> Manage Bookings</a></li>
|
||||
<li class="nav-item"><a class="nav-link active" aria-current="page" href="reviews.php"><i class="bi bi-star-fill"></i> Manage Reviews</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
<main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
|
||||
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
||||
<h1 class="h2">Manage Reviews</h1>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped">
|
||||
<thead class="table-dark">
|
||||
<tr><th>User</th><th>Car</th><th>Rating</th><th>Review</th><th>Date</th><th>Status</th><th>Actions</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($reviews as $review): ?>
|
||||
<tr>
|
||||
<td><?= htmlspecialchars($review['username']) ?></td>
|
||||
<td><?= htmlspecialchars($review['make'] . ' ' . $review['model']) ?></td>
|
||||
<td><?= str_repeat('★', $review['rating']) ?></td>
|
||||
<td><?= htmlspecialchars($review['review']) ?></td>
|
||||
<td><?= date("M d, Y", strtotime($review['created_at'])) ?></td>
|
||||
<td><span class="badge bg-info"><?= htmlspecialchars($review['status']) ?></span></td>
|
||||
<td>
|
||||
<form method="POST" class="d-inline">
|
||||
<input type="hidden" name="review_id" value="<?= $review['id'] ?>">
|
||||
<?php if ($review['status'] === 'pending'): ?>
|
||||
<button type="submit" name="approve" class="btn btn-sm btn-success">Approve</button>
|
||||
<?php endif; ?>
|
||||
<button type="submit" name="delete" class="btn btn-sm btn-danger">Delete</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
159
admin/users.php
Normal file
159
admin/users.php
Normal file
@ -0,0 +1,159 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'admin') {
|
||||
header("Location: ../login.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
require_once '../db/config.php';
|
||||
|
||||
// Handle user actions (delete, toggle status)
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$pdo = db();
|
||||
if (isset($_POST['delete_user'])) {
|
||||
$userId = $_POST['user_id'];
|
||||
$stmt = $pdo->prepare("DELETE FROM users WHERE id = ?");
|
||||
$stmt->execute([$userId]);
|
||||
} elseif (isset($_POST['toggle_status'])) {
|
||||
$userId = $_POST['user_id'];
|
||||
$stmt = $pdo->prepare("UPDATE users SET status = CASE WHEN status = 'active' THEN 'disabled' ELSE 'active' END WHERE id = ?");
|
||||
$stmt->execute([$userId]);
|
||||
}
|
||||
header("Location: users.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
$search = $_GET['search'] ?? '';
|
||||
$filter = $_GET['filter'] ?? 'all';
|
||||
|
||||
try {
|
||||
$pdo = db();
|
||||
$sql = "SELECT id, username, email, role, created_at, status FROM users";
|
||||
$params = [];
|
||||
|
||||
if (!empty($search)) {
|
||||
$sql .= " WHERE (username LIKE ? OR email LIKE ?)";
|
||||
$params[] = "%$search%";
|
||||
$params[] = "%$search%";
|
||||
}
|
||||
|
||||
if ($filter !== 'all') {
|
||||
$sql .= (strpos($sql, 'WHERE') === false ? " WHERE" : " AND") . " status = ?";
|
||||
$params[] = $filter;
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY created_at DESC";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$users = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $e) {
|
||||
error_log("Admin Users Page Error: " . $e->getMessage());
|
||||
$users = [];
|
||||
}
|
||||
|
||||
$projectName = 'Manage Users';
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><?php echo htmlspecialchars($projectName); ?></title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="../assets/css/custom.css?v=<?php echo time(); ?>">
|
||||
</head>
|
||||
<body class="admin-dashboard">
|
||||
|
||||
<?php include __DIR__ . '/../partials/navbar.php'; ?>
|
||||
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<nav id="sidebar" class="col-md-3 col-lg-2 d-md-block bg-light sidebar collapse">
|
||||
<div class="position-sticky pt-3">
|
||||
<ul class="nav flex-column">
|
||||
<li class="nav-item"><a class="nav-link" href="index.php"><i class="bi bi-house-door"></i> Dashboard</a></li>
|
||||
<li class="nav-item"><a class="nav-link active" aria-current="page" href="users.php"><i class="bi bi-people"></i> Manage Users</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="cars.php"><i class="bi bi-car-front"></i> Manage Cars</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="bookings.php"><i class="bi bi-calendar-check"></i> Manage Bookings</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="reviews.php"><i class="bi bi-star-fill"></i> Manage Reviews</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
|
||||
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
||||
<h1 class="h2">Manage Users</h1>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<form method="GET" action="users.php" class="row g-3 align-items-center">
|
||||
<div class="col-auto">
|
||||
<input type="text" name="search" class="form-control" placeholder="Search by name or email..." value="<?php echo htmlspecialchars($search); ?>">
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<select name="filter" class="form-select">
|
||||
<option value="all" <?php if ($filter === 'all') echo 'selected'; ?>>All Statuses</option>
|
||||
<option value="active" <?php if ($filter === 'active') echo 'selected'; ?>>Active</option>
|
||||
<option value="disabled" <?php if ($filter === 'disabled') echo 'selected'; ?>>Disabled</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<button type="submit" class="btn btn-primary">Filter</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-hover">
|
||||
<thead class="table-dark">
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Username</th>
|
||||
<th>Email</th>
|
||||
<th>Role</th>
|
||||
<th>Status</th>
|
||||
<th>Joined On</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($users as $user): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($user['id']); ?></td>
|
||||
<td><?php echo htmlspecialchars($user['username']); ?></td>
|
||||
<td><?php echo htmlspecialchars($user['email']); ?></td>
|
||||
<td><span class="badge bg-<?php echo $user['role'] === 'admin' ? 'success' : 'info'; ?>"><?php echo htmlspecialchars($user['role']); ?></span></td>
|
||||
<td><span class="badge bg-<?php echo $user['status'] === 'active' ? 'success' : 'warning'; ?>"><?php echo htmlspecialchars($user['status']); ?></span></td>
|
||||
<td><?php echo date("M d, Y", strtotime($user['created_at'])); ?></td>
|
||||
<td>
|
||||
<form method="POST" action="users.php" class="d-inline">
|
||||
<input type="hidden" name="user_id" value="<?php echo $user['id']; ?>">
|
||||
<button type="submit" name="toggle_status" class="btn btn-sm btn-outline-secondary">
|
||||
<i class="bi bi-person-fill-<?php echo $user['status'] === 'active' ? 'slash' : 'check'; ?>"></i>
|
||||
</button>
|
||||
<button type="submit" name="delete_user" class="btn btn-sm btn-outline-danger" onclick="return confirm('Are you sure?');">
|
||||
<i class="bi bi-trash"></i>
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php if (empty($users)): ?>
|
||||
<tr><td colspan="7" class="text-center">No users found.</td></tr>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@ -1,346 +1,195 @@
|
||||
:root {
|
||||
--color-bg: #ffffff;
|
||||
--color-text: #1a1a1a;
|
||||
--color-primary: #2563EB; /* Vibrant Blue */
|
||||
--color-secondary: #000000;
|
||||
--color-accent: #A3E635; /* Lime Green */
|
||||
--color-surface: #f8f9fa;
|
||||
--font-heading: 'Space Grotesk', sans-serif;
|
||||
--font-body: 'Inter', sans-serif;
|
||||
--border-width: 2px;
|
||||
--shadow-hard: 5px 5px 0px #000;
|
||||
--shadow-hover: 8px 8px 0px #000;
|
||||
--radius-pill: 50rem;
|
||||
--radius-card: 1rem;
|
||||
--primary-color: #0f172a;
|
||||
--accent-color: #ea580c;
|
||||
--bg-color: #f8fafc;
|
||||
--surface-color: #ffffff;
|
||||
--text-color: #1e293b;
|
||||
--text-muted: #64748b;
|
||||
--border-color: #e2e8f0;
|
||||
--card-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
|
||||
}
|
||||
|
||||
body.dark-mode {
|
||||
--primary-color: #f8fafc;
|
||||
--accent-color: #f97316;
|
||||
--bg-color: #0f172a;
|
||||
--surface-color: #1e293b;
|
||||
--text-color: #f1f5f9;
|
||||
--text-muted: #94a3b8;
|
||||
--border-color: #334155;
|
||||
--card-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.5);
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: var(--font-body);
|
||||
background-color: var(--color-bg);
|
||||
color: var(--color-text);
|
||||
overflow-x: hidden;
|
||||
font-family: 'Inter', system-ui, -apple-system, sans-serif;
|
||||
background-color: var(--bg-color);
|
||||
color: var(--text-color);
|
||||
transition: background-color 0.3s ease, color 0.3s ease;
|
||||
}
|
||||
|
||||
h1, h2, h3, h4, h5, h6, .navbar-brand {
|
||||
font-family: var(--font-heading);
|
||||
letter-spacing: -0.03em;
|
||||
}
|
||||
|
||||
/* Utilities */
|
||||
.text-primary { color: var(--color-primary) !important; }
|
||||
.bg-black { background-color: #000 !important; }
|
||||
.text-white { color: #fff !important; }
|
||||
.shadow-hard { box-shadow: var(--shadow-hard); }
|
||||
.border-2-black { border: var(--border-width) solid #000; }
|
||||
.py-section { padding-top: 5rem; padding-bottom: 5rem; }
|
||||
|
||||
/* Navbar */
|
||||
.navbar {
|
||||
background: rgba(255, 255, 255, 0.9);
|
||||
background-color: rgba(255, 255, 255, 0.95);
|
||||
backdrop-filter: blur(10px);
|
||||
border-bottom: var(--border-width) solid transparent;
|
||||
transition: all 0.3s;
|
||||
padding-top: 1rem;
|
||||
padding-bottom: 1rem;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.navbar.scrolled {
|
||||
border-bottom-color: #000;
|
||||
padding-top: 0.5rem;
|
||||
padding-bottom: 0.5rem;
|
||||
body.dark-mode .navbar {
|
||||
background-color: rgba(15, 23, 42, 0.95);
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.brand-text {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 800;
|
||||
.navbar-brand {
|
||||
font-weight: 700;
|
||||
color: var(--text-color) !important;
|
||||
}
|
||||
|
||||
.nav-link {
|
||||
color: var(--text-muted) !important;
|
||||
font-weight: 500;
|
||||
color: var(--color-text);
|
||||
margin-left: 1rem;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.nav-link:hover, .nav-link.active {
|
||||
color: var(--color-primary);
|
||||
color: var(--accent-color) !important;
|
||||
}
|
||||
|
||||
/* Buttons */
|
||||
.btn {
|
||||
font-weight: 700;
|
||||
font-family: var(--font-heading);
|
||||
padding: 0.8rem 2rem;
|
||||
border-radius: var(--radius-pill);
|
||||
border: var(--border-width) solid #000;
|
||||
transition: all 0.2s cubic-bezier(0.25, 1, 0.5, 1);
|
||||
box-shadow: var(--shadow-hard);
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
transform: translate(-2px, -2px);
|
||||
box-shadow: var(--shadow-hover);
|
||||
}
|
||||
|
||||
.btn:active {
|
||||
transform: translate(2px, 2px);
|
||||
box-shadow: 0 0 0 #000;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background-color: var(--color-primary);
|
||||
border-color: #000;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
background-color: #1d4ed8;
|
||||
border-color: #000;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.btn-outline-dark {
|
||||
background-color: #fff;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.btn-cta {
|
||||
background-color: var(--color-accent);
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.btn-cta:hover {
|
||||
background-color: #8cc629;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
/* Hero Section */
|
||||
.hero-section {
|
||||
min-height: 100vh;
|
||||
padding-top: 80px;
|
||||
position: relative;
|
||||
padding: 8rem 0 6rem;
|
||||
background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
|
||||
color: white;
|
||||
border-radius: 0 0 2rem 2rem;
|
||||
margin-bottom: 4rem;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.background-blob {
|
||||
.hero-bg-overlay {
|
||||
position: absolute;
|
||||
border-radius: 50%;
|
||||
filter: blur(80px);
|
||||
opacity: 0.6;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-image: url('https://images.pexels.com/photos/120049/pexels-photo-120049.jpeg?auto=compress&cs=tinysrgb&w=1600');
|
||||
background-size: cover;
|
||||
background-position: center;
|
||||
opacity: 0.2;
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
.hero-content {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.blob-1 {
|
||||
top: -10%;
|
||||
right: -10%;
|
||||
width: 600px;
|
||||
height: 600px;
|
||||
background: radial-gradient(circle, var(--color-accent), transparent);
|
||||
.search-card {
|
||||
background-color: var(--surface-color);
|
||||
border-radius: 1rem;
|
||||
padding: 1.5rem;
|
||||
box-shadow: 0 10px 25px -5px rgb(0 0 0 / 0.1);
|
||||
margin-top: 2rem;
|
||||
border: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.blob-2 {
|
||||
bottom: 10%;
|
||||
left: -10%;
|
||||
width: 500px;
|
||||
height: 500px;
|
||||
background: radial-gradient(circle, var(--color-primary), transparent);
|
||||
}
|
||||
|
||||
.highlight-text {
|
||||
background: linear-gradient(120deg, transparent 0%, transparent 40%, var(--color-accent) 40%, var(--color-accent) 100%);
|
||||
background-repeat: no-repeat;
|
||||
background-size: 100% 40%;
|
||||
background-position: 0 88%;
|
||||
padding: 0 5px;
|
||||
}
|
||||
|
||||
.dot { color: var(--color-primary); }
|
||||
|
||||
.badge-pill {
|
||||
display: inline-block;
|
||||
padding: 0.5rem 1rem;
|
||||
border: 2px solid #000;
|
||||
border-radius: 50px;
|
||||
font-weight: 700;
|
||||
background: #fff;
|
||||
box-shadow: 4px 4px 0 #000;
|
||||
font-family: var(--font-heading);
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
/* Marquee */
|
||||
.marquee-container {
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
border-top: 2px solid #000;
|
||||
border-bottom: 2px solid #000;
|
||||
}
|
||||
|
||||
.rotate-divider {
|
||||
transform: rotate(-2deg) scale(1.05);
|
||||
z-index: 10;
|
||||
position: relative;
|
||||
margin-top: -50px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.marquee-content {
|
||||
display: inline-block;
|
||||
animation: marquee 20s linear infinite;
|
||||
font-family: var(--font-heading);
|
||||
font-weight: 700;
|
||||
font-size: 1.5rem;
|
||||
letter-spacing: 2px;
|
||||
}
|
||||
|
||||
@keyframes marquee {
|
||||
0% { transform: translateX(0); }
|
||||
100% { transform: translateX(-50%); }
|
||||
}
|
||||
|
||||
/* Portfolio Cards */
|
||||
.project-card {
|
||||
border: 2px solid #000;
|
||||
border-radius: var(--radius-card);
|
||||
overflow: hidden;
|
||||
background: #fff;
|
||||
transition: transform 0.3s ease;
|
||||
box-shadow: var(--shadow-hard);
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.project-card:hover {
|
||||
transform: translateY(-10px);
|
||||
box-shadow: 8px 8px 0 #000;
|
||||
}
|
||||
|
||||
.card-img-holder {
|
||||
height: 250px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-bottom: 2px solid #000;
|
||||
position: relative;
|
||||
font-size: 4rem;
|
||||
}
|
||||
|
||||
.placeholder-art {
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.project-card:hover .placeholder-art {
|
||||
transform: scale(1.2) rotate(10deg);
|
||||
}
|
||||
|
||||
.bg-soft-blue { background-color: #e0f2fe; }
|
||||
.bg-soft-green { background-color: #dcfce7; }
|
||||
.bg-soft-purple { background-color: #f3e8ff; }
|
||||
.bg-soft-yellow { background-color: #fef9c3; }
|
||||
|
||||
.category-tag {
|
||||
position: absolute;
|
||||
top: 15px;
|
||||
right: 15px;
|
||||
background: #000;
|
||||
color: #fff;
|
||||
padding: 5px 12px;
|
||||
border-radius: 20px;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.card-body { padding: 1.5rem; }
|
||||
|
||||
.link-arrow {
|
||||
text-decoration: none;
|
||||
color: #000;
|
||||
font-weight: 700;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
margin-top: auto;
|
||||
}
|
||||
|
||||
.link-arrow i { transition: transform 0.2s; margin-left: 5px; }
|
||||
.link-arrow:hover i { transform: translateX(5px); }
|
||||
|
||||
/* About */
|
||||
.about-image-stack {
|
||||
position: relative;
|
||||
height: 400px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.stack-card {
|
||||
position: absolute;
|
||||
width: 80%;
|
||||
height: 100%;
|
||||
border-radius: var(--radius-card);
|
||||
border: 2px solid #000;
|
||||
box-shadow: var(--shadow-hard);
|
||||
left: 10%;
|
||||
transform: rotate(-3deg);
|
||||
background-size: cover;
|
||||
}
|
||||
|
||||
/* Forms */
|
||||
.form-control {
|
||||
border: 2px solid #000;
|
||||
.form-control, .form-select {
|
||||
background-color: var(--bg-color);
|
||||
border: 1px solid var(--border-color);
|
||||
color: var(--text-color);
|
||||
padding: 0.75rem 1rem;
|
||||
border-radius: 0.5rem;
|
||||
padding: 1rem;
|
||||
font-weight: 500;
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.form-control:focus {
|
||||
box-shadow: 4px 4px 0 var(--color-primary);
|
||||
border-color: #000;
|
||||
background: #fff;
|
||||
.form-control:focus, .form-select:focus {
|
||||
background-color: var(--bg-color);
|
||||
border-color: var(--accent-color);
|
||||
color: var(--text-color);
|
||||
box-shadow: 0 0 0 2px rgba(234, 88, 12, 0.2);
|
||||
}
|
||||
|
||||
/* Animations */
|
||||
.animate-up {
|
||||
opacity: 0;
|
||||
transform: translateY(30px);
|
||||
animation: fadeUp 0.8s ease forwards;
|
||||
.btn-primary {
|
||||
background-color: var(--accent-color);
|
||||
border-color: var(--accent-color);
|
||||
padding: 0.75rem 1.5rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.delay-100 { animation-delay: 0.1s; }
|
||||
.delay-200 { animation-delay: 0.2s; }
|
||||
|
||||
@keyframes fadeUp {
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
.btn-primary:hover {
|
||||
background-color: #c2410c;
|
||||
border-color: #c2410c;
|
||||
}
|
||||
|
||||
/* Social */
|
||||
.social-links a {
|
||||
transition: transform 0.2s;
|
||||
.section-title {
|
||||
font-weight: 700;
|
||||
margin-bottom: 2rem;
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
}
|
||||
.social-links a:hover {
|
||||
transform: scale(1.2) rotate(10deg);
|
||||
color: var(--color-accent) !important;
|
||||
|
||||
.section-title::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 0;
|
||||
bottom: -10px;
|
||||
width: 60px;
|
||||
height: 4px;
|
||||
background-color: var(--accent-color);
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
/* Responsive */
|
||||
@media (max-width: 991px) {
|
||||
.rotate-divider {
|
||||
transform: rotate(0);
|
||||
margin-top: 0;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.hero-section {
|
||||
padding-top: 120px;
|
||||
text-align: center;
|
||||
min-height: auto;
|
||||
padding-bottom: 100px;
|
||||
}
|
||||
|
||||
.display-1 { font-size: 3.5rem; }
|
||||
|
||||
.blob-1 { width: 300px; height: 300px; right: -20%; }
|
||||
.blob-2 { width: 300px; height: 300px; left: -20%; }
|
||||
.car-card {
|
||||
background-color: var(--surface-color);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 1rem;
|
||||
overflow: hidden;
|
||||
transition: transform 0.3s ease, box-shadow 0.3s ease;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.car-card:hover {
|
||||
transform: translateY(-5px);
|
||||
box-shadow: var(--card-shadow);
|
||||
}
|
||||
|
||||
.car-img-top {
|
||||
height: 220px;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.car-card-body {
|
||||
padding: 1.5rem;
|
||||
}
|
||||
|
||||
.price-tag {
|
||||
color: var(--accent-color);
|
||||
font-weight: 700;
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
|
||||
.spec-item {
|
||||
color: var(--text-muted);
|
||||
font-size: 0.9rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.spec-item i {
|
||||
color: var(--accent-color);
|
||||
}
|
||||
|
||||
.footer {
|
||||
background-color: var(--surface-color);
|
||||
border-top: 1px solid var(--border-color);
|
||||
padding: 4rem 0 2rem;
|
||||
margin-top: 4rem;
|
||||
}
|
||||
|
||||
/* Dark mode toggler */
|
||||
.theme-toggle {
|
||||
cursor: pointer;
|
||||
padding: 0.5rem;
|
||||
border-radius: 50%;
|
||||
transition: background-color 0.2s;
|
||||
}
|
||||
|
||||
.theme-toggle:hover {
|
||||
background-color: rgba(128, 128, 128, 0.1);
|
||||
}
|
||||
@ -1,73 +1,27 @@
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
// Smooth scrolling for navigation links
|
||||
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
|
||||
anchor.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
const targetId = this.getAttribute('href');
|
||||
if (targetId === '#') return;
|
||||
|
||||
const targetElement = document.querySelector(targetId);
|
||||
if (targetElement) {
|
||||
// Close mobile menu if open
|
||||
const navbarToggler = document.querySelector('.navbar-toggler');
|
||||
const navbarCollapse = document.querySelector('.navbar-collapse');
|
||||
if (navbarCollapse.classList.contains('show')) {
|
||||
navbarToggler.click();
|
||||
}
|
||||
const themeToggleBtn = document.getElementById('theme-toggle');
|
||||
const body = document.body;
|
||||
const icon = themeToggleBtn.querySelector('i');
|
||||
|
||||
// Scroll with offset
|
||||
const offset = 80;
|
||||
const elementPosition = targetElement.getBoundingClientRect().top;
|
||||
const offsetPosition = elementPosition + window.pageYOffset - offset;
|
||||
// Check local storage
|
||||
const currentTheme = localStorage.getItem('theme');
|
||||
if (currentTheme === 'dark') {
|
||||
body.classList.add('dark-mode');
|
||||
icon.classList.remove('bi-moon-fill');
|
||||
icon.classList.add('bi-sun-fill');
|
||||
}
|
||||
|
||||
window.scrollTo({
|
||||
top: offsetPosition,
|
||||
behavior: "smooth"
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Navbar scroll effect
|
||||
const navbar = document.querySelector('.navbar');
|
||||
window.addEventListener('scroll', () => {
|
||||
if (window.scrollY > 50) {
|
||||
navbar.classList.add('scrolled', 'shadow-sm', 'bg-white');
|
||||
navbar.classList.remove('bg-transparent');
|
||||
themeToggleBtn.addEventListener('click', () => {
|
||||
body.classList.toggle('dark-mode');
|
||||
|
||||
if (body.classList.contains('dark-mode')) {
|
||||
localStorage.setItem('theme', 'dark');
|
||||
icon.classList.remove('bi-moon-fill');
|
||||
icon.classList.add('bi-sun-fill');
|
||||
} else {
|
||||
navbar.classList.remove('scrolled', 'shadow-sm', 'bg-white');
|
||||
navbar.classList.add('bg-transparent');
|
||||
localStorage.setItem('theme', 'light');
|
||||
icon.classList.remove('bi-sun-fill');
|
||||
icon.classList.add('bi-moon-fill');
|
||||
}
|
||||
});
|
||||
|
||||
// Intersection Observer for fade-up animations
|
||||
const observerOptions = {
|
||||
threshold: 0.1,
|
||||
rootMargin: "0px 0px -50px 0px"
|
||||
};
|
||||
|
||||
const observer = new IntersectionObserver((entries) => {
|
||||
entries.forEach(entry => {
|
||||
if (entry.isIntersecting) {
|
||||
entry.target.classList.add('animate-up');
|
||||
entry.target.style.opacity = "1";
|
||||
observer.unobserve(entry.target); // Only animate once
|
||||
}
|
||||
});
|
||||
}, observerOptions);
|
||||
|
||||
// Select elements to animate (add a class 'reveal' to them in HTML if not already handled by CSS animation)
|
||||
// For now, let's just make sure the hero animations run.
|
||||
// If we want scroll animations, we'd add opacity: 0 to elements in CSS and reveal them here.
|
||||
// Given the request, the CSS animation I added runs on load for Hero.
|
||||
// Let's make the project cards animate in.
|
||||
|
||||
const projectCards = document.querySelectorAll('.project-card');
|
||||
projectCards.forEach((card, index) => {
|
||||
card.style.opacity = "0";
|
||||
card.style.animationDelay = `${index * 0.1}s`;
|
||||
observer.observe(card);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
150
car_detail.php
Normal file
150
car_detail.php
Normal file
@ -0,0 +1,150 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'db/config.php';
|
||||
|
||||
if (!isset($_GET['id'])) {
|
||||
header("Location: car_list.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
$carId = $_GET['id'];
|
||||
$pdo = db();
|
||||
|
||||
// Handle Booking
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['book_now'])) {
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header("Location: login.php");
|
||||
exit();
|
||||
}
|
||||
$userId = $_SESSION['user_id'];
|
||||
$stmt = $pdo->prepare("INSERT INTO bookings (user_id, car_id) VALUES (?, ?)");
|
||||
$stmt->execute([$userId, $carId]);
|
||||
$stmt = $pdo->prepare("UPDATE cars SET status = 'reserved' WHERE id = ?");
|
||||
$stmt->execute([$carId]);
|
||||
$booking_success = "Your booking request has been sent!";
|
||||
}
|
||||
|
||||
// Handle Review
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['submit_review'])) {
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header("Location: login.php");
|
||||
exit();
|
||||
}
|
||||
$userId = $_SESSION['user_id'];
|
||||
$rating = $_POST['rating'];
|
||||
$review = $_POST['review'];
|
||||
|
||||
$stmt = $pdo->prepare("INSERT INTO reviews (car_id, user_id, rating, review) VALUES (?, ?, ?, ?)");
|
||||
$stmt->execute([$carId, $userId, $rating, $review]);
|
||||
$review_success = "Your review has been submitted for approval!";
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare("SELECT * FROM cars WHERE id = ?");
|
||||
$stmt->execute([$carId]);
|
||||
$car = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$car) {
|
||||
header("Location: car_list.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
// Fetch Reviews
|
||||
$stmt = $pdo->prepare("SELECT r.*, u.username FROM reviews r JOIN users u ON r.user_id = u.id WHERE r.car_id = ? AND r.status = 'approved' ORDER BY r.created_at DESC");
|
||||
$stmt->execute([$carId]);
|
||||
$reviews = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$projectName = htmlspecialchars($car['make'] . ' ' . $car['model']);
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><?= $projectName ?></title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/custom.css?v=<?= time() ?>">
|
||||
</head>
|
||||
<body>
|
||||
<?php include 'partials/navbar.php'; ?>
|
||||
|
||||
<div class="container mt-5">
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<img src="<?= htmlspecialchars($car['image_url']) ?>" class="img-fluid rounded" alt="<?= $projectName ?>">
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<h1><?= $projectName ?></h1>
|
||||
<p class="lead"><?= htmlspecialchars($car['description']) ?></p>
|
||||
<p><strong>Year:</strong> <?= htmlspecialchars($car['year']) ?></p>
|
||||
<p><strong>Price:</strong> $<?= number_format($car['price']) ?></p>
|
||||
<p><strong>Status:</strong> <span class="badge bg-info"><?= htmlspecialchars($car['status']) ?></span></p>
|
||||
|
||||
<?php if (isset($booking_success)): ?>
|
||||
<div class="alert alert-success"><?= $booking_success ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($car['status'] === 'for_sale'): ?>
|
||||
<form method="POST">
|
||||
<button type="submit" name="book_now" class="btn btn-success btn-lg">Book Now</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr class="my-5">
|
||||
|
||||
<!-- Reviews Section -->
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<h2>Reviews</h2>
|
||||
<?php if (isset($review_success)): ?>
|
||||
<div class="alert alert-success"><?= $review_success ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (isset($_SESSION['user_id'])): ?>
|
||||
<div class="card mb-4">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Leave a Review</h5>
|
||||
<form method="POST">
|
||||
<div class="mb-3">
|
||||
<label for="rating" class="form-label">Rating</label>
|
||||
<select name="rating" id="rating" class="form-select" required>
|
||||
<option value="5">5 Stars</option>
|
||||
<option value="4">4 Stars</option>
|
||||
<option value="3">3 Stars</option>
|
||||
<option value="2">2 Stars</option>
|
||||
<option value="1">1 Star</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="review" class="form-label">Review</label>
|
||||
<textarea name="review" id="review" class="form-control" rows="3" required></textarea>
|
||||
</div>
|
||||
<button type="submit" name="submit_review" class="btn btn-primary">Submit Review</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<p><a href="login.php">Log in</a> to leave a review.</p>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php foreach ($reviews as $review): ?>
|
||||
<div class="card mb-3">
|
||||
<div class="card-body">
|
||||
<h6 class="card-subtitle mb-2 text-muted"><strong><?= htmlspecialchars($review['username']) ?></strong> - <?= date("M d, Y", strtotime($review['created_at'])) ?></h6>
|
||||
<p class="card-text">Rating: <?= str_repeat('★', $review['rating']) ?></p>
|
||||
<p class="card-text"><?= htmlspecialchars($review['review']) ?></p>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php if (empty($reviews)): ?>
|
||||
<p>No reviews yet.</p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include 'partials/footer.php'; ?>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
70
car_list.php
Normal file
70
car_list.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'db/config.php';
|
||||
|
||||
$pdo = db();
|
||||
$search = $_GET['search'] ?? '';
|
||||
|
||||
$sql = "SELECT * FROM cars WHERE status = 'for_sale'";
|
||||
$params = [];
|
||||
if (!empty($search)) {
|
||||
$sql .= " AND (make LIKE ? OR model LIKE ?)";
|
||||
$params[] = "%$search%";
|
||||
$params[] = "%$search%";
|
||||
}
|
||||
$sql .= " ORDER BY created_at DESC";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$cars = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$projectName = 'Available Cars';
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><?= htmlspecialchars($projectName) ?></title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/custom.css?v=<?= time() ?>">
|
||||
</head>
|
||||
<body>
|
||||
<?php include 'partials/navbar.php'; ?>
|
||||
|
||||
<div class="container mt-5">
|
||||
<h1 class="text-center mb-4"><?= htmlspecialchars($projectName) ?></h1>
|
||||
<form method="GET" class="row g-3 mb-4 justify-content-center">
|
||||
<div class="col-md-6">
|
||||
<input type="text" name="search" class="form-control" placeholder="Search by make or model..." value="<?= htmlspecialchars($search) ?>">
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<button type="submit" class="btn btn-primary">Search</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="row">
|
||||
<?php foreach ($cars as $car): ?>
|
||||
<div class="col-md-4 mb-4">
|
||||
<div class="card h-100">
|
||||
<img src="<?= htmlspecialchars($car['image_url']) ?>" class="card-img-top" alt="<?= htmlspecialchars($car['make'] . ' ' . $car['model']) ?>">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title"><?= htmlspecialchars($car['make'] . ' ' . $car['model']) ?></h5>
|
||||
<p class="card-text"><?= htmlspecialchars($car['description']) ?></p>
|
||||
<p class="card-text"><strong>Price:</strong> $<?= number_format($car['price']) ?></p>
|
||||
<a href="car_detail.php?id=<?= $car['id'] ?>" class="btn btn-primary">View Details</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php if (empty($cars)): ?>
|
||||
<div class="col-12">
|
||||
<p class="text-center">No cars found.</p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include 'partials/footer.php'; ?>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
102
dashboard.php
Normal file
102
dashboard.php
Normal file
@ -0,0 +1,102 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
// Check if the user is logged in
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header("Location: login.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
require_once 'db/config.php';
|
||||
|
||||
$user = null;
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare("SELECT * FROM users WHERE id = :id");
|
||||
$stmt->execute(['id' => $_SESSION['user_id']]);
|
||||
$user = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $e) {
|
||||
error_log("Dashboard Page Error: " . $e->getMessage());
|
||||
}
|
||||
|
||||
// If for some reason user is not found in DB, destroy session and redirect
|
||||
if (!$user) {
|
||||
session_destroy();
|
||||
header("Location: login.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
$projectName = 'User Dashboard';
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><?php echo htmlspecialchars($projectName); ?></title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<?php include 'partials/navbar.php'; ?>
|
||||
|
||||
<main class="container my-5">
|
||||
<div class="row">
|
||||
<!-- Sidebar -->
|
||||
<div class="col-md-4">
|
||||
<div class="card">
|
||||
<div class="card-body text-center">
|
||||
<i class="bi bi-person-circle display-3 text-primary"></i>
|
||||
<h5 class="card-title mt-3"><?php echo htmlspecialchars($user['username']); ?></h5>
|
||||
<p class="card-text text-muted"><?php echo htmlspecialchars($user['email']); ?></p>
|
||||
<span class="badge bg-secondary"><?php echo ucfirst(htmlspecialchars($user['role'])); ?></span>
|
||||
</div>
|
||||
<div class="list-group list-group-flush">
|
||||
<a href="dashboard.php" class="list-group-item list-group-item-action active" aria-current="true">
|
||||
<i class="bi bi-person-fill-gear me-2"></i>Profile
|
||||
</a>
|
||||
<a href="#" class="list-group-item list-group-item-action"><i class="bi bi-journal-text me-2"></i>My Bookings</a>
|
||||
<a href="#" class="list-group-item list-group-item-action"><i class="bi bi-car-front-fill me-2"></i>My Cars for Sale</a>
|
||||
<a href="logout.php" class="list-group-item list-group-item-action text-danger"><i class="bi bi-box-arrow-left me-2"></i>Logout</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Main Content -->
|
||||
<div class="col-md-8">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h4 class="mb-0">Welcome to your Dashboard</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Your Profile Information</h5>
|
||||
<form>
|
||||
<div class="mb-3">
|
||||
<label for="username" class="form-label">Username</label>
|
||||
<input type="text" class="form-control" id="username" value="<?php echo htmlspecialchars($user['username']); ?>" readonly>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="email" class="form-label">Email address</label>
|
||||
<input type="email" class="form-control" id="email" value="<?php echo htmlspecialchars($user['email']); ?>" readonly>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="memberSince" class="form-label">Member Since</label>
|
||||
<input type="text" class="form-control" id="memberSince" value="<?php echo date("F j, Y", strtotime($user['created_at'])); ?>" readonly>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Edit Profile (Coming Soon)</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<?php include 'partials/footer.php'; ?>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
||||
</body>
|
||||
</html>
|
||||
28
db/migrate.php
Normal file
28
db/migrate.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
require_once 'config.php';
|
||||
|
||||
try {
|
||||
$pdo = db();
|
||||
|
||||
// Create migrations table if it doesn't exist
|
||||
$pdo->exec("CREATE TABLE IF NOT EXISTS migrations (migration VARCHAR(255) PRIMARY KEY)");
|
||||
|
||||
// Get executed migrations
|
||||
$executed_migrations = $pdo->query("SELECT migration FROM migrations")->fetchAll(PDO::FETCH_COLUMN);
|
||||
|
||||
$migration_files = glob(__DIR__ . '/migrations/*.sql');
|
||||
foreach ($migration_files as $file) {
|
||||
$migration_name = basename($file);
|
||||
if (!in_array($migration_name, $executed_migrations)) {
|
||||
$sql = file_get_contents($file);
|
||||
$pdo->exec($sql);
|
||||
|
||||
$stmt = $pdo->prepare("INSERT INTO migrations (migration) VALUES (?)");
|
||||
$stmt->execute([$migration_name]);
|
||||
|
||||
echo "Applied migration: " . $migration_name . "\n";
|
||||
}
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
die("Migration failed: " . $e->getMessage());
|
||||
}
|
||||
1
db/migrations/000_create_migrations_table.sql
Normal file
1
db/migrations/000_create_migrations_table.sql
Normal file
@ -0,0 +1 @@
|
||||
CREATE TABLE IF NOT EXISTS migrations (migration VARCHAR(255) PRIMARY KEY);
|
||||
1
db/migrations/001_add_status_to_users.sql
Normal file
1
db/migrations/001_add_status_to_users.sql
Normal file
@ -0,0 +1 @@
|
||||
ALTER TABLE users ADD COLUMN IF NOT EXISTS status VARCHAR(50) NOT NULL DEFAULT 'active';
|
||||
1
db/migrations/002_add_status_and_description_to_cars.sql
Normal file
1
db/migrations/002_add_status_and_description_to_cars.sql
Normal file
@ -0,0 +1 @@
|
||||
ALTER TABLE cars ADD COLUMN IF NOT EXISTS status VARCHAR(50) NOT NULL DEFAULT 'for_sale', ADD COLUMN IF NOT EXISTS description TEXT;
|
||||
9
db/migrations/003_create_bookings_table.sql
Normal file
9
db/migrations/003_create_bookings_table.sql
Normal file
@ -0,0 +1,9 @@
|
||||
CREATE TABLE IF NOT EXISTS bookings (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
user_id INT NOT NULL,
|
||||
car_id INT NOT NULL,
|
||||
booking_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
status VARCHAR(50) NOT NULL DEFAULT 'pending', -- pending, approved, canceled
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (car_id) REFERENCES cars(id) ON DELETE CASCADE
|
||||
);
|
||||
11
db/migrations/004_create_reviews_table.sql
Normal file
11
db/migrations/004_create_reviews_table.sql
Normal file
@ -0,0 +1,11 @@
|
||||
CREATE TABLE IF NOT EXISTS reviews (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
car_id INT NOT NULL,
|
||||
user_id INT NOT NULL,
|
||||
rating INT NOT NULL CHECK (rating >= 1 AND rating <= 5),
|
||||
review TEXT,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
status VARCHAR(50) NOT NULL DEFAULT 'pending', -- pending, approved
|
||||
FOREIGN KEY (car_id) REFERENCES cars(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
);
|
||||
78
db/setup_cars.php
Normal file
78
db/setup_cars.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/config.php';
|
||||
|
||||
try {
|
||||
$pdo = db();
|
||||
|
||||
// Create cars table
|
||||
$sql = "CREATE TABLE IF NOT EXISTS cars (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
make VARCHAR(50) NOT NULL,
|
||||
model VARCHAR(50) NOT NULL,
|
||||
year INT NOT NULL,
|
||||
price DECIMAL(10, 2) NOT NULL,
|
||||
mileage INT DEFAULT 0,
|
||||
image_url VARCHAR(255),
|
||||
description TEXT,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)";
|
||||
$pdo->exec($sql);
|
||||
echo "Table 'cars' created or already exists.<br>";
|
||||
|
||||
// Check if empty
|
||||
$stmt = $pdo->query("SELECT COUNT(*) FROM cars");
|
||||
if ($stmt->fetchColumn() == 0) {
|
||||
// Seed data
|
||||
$cars = [
|
||||
[
|
||||
'make' => 'Toyota',
|
||||
'model' => 'Corolla',
|
||||
'year' => 2015,
|
||||
'price' => 12500.00,
|
||||
'mileage' => 45000,
|
||||
'image_url' => 'https://images.pexels.com/photos/170811/pexels-photo-170811.jpeg?auto=compress&cs=tinysrgb&w=800',
|
||||
'description' => 'Reliable white Corolla, excellent condition. Kabul plate.'
|
||||
],
|
||||
[
|
||||
'make' => 'Toyota',
|
||||
'model' => 'Land Cruiser',
|
||||
'year' => 2018,
|
||||
'price' => 45000.00,
|
||||
'mileage' => 32000,
|
||||
'image_url' => 'https://images.pexels.com/photos/116675/pexels-photo-116675.jpeg?auto=compress&cs=tinysrgb&w=800',
|
||||
'description' => 'Black Land Cruiser V8. Powerful and luxurious. Ready for any road.'
|
||||
],
|
||||
[
|
||||
'make' => 'Mercedes-Benz',
|
||||
'model' => 'C-Class',
|
||||
'year' => 2012,
|
||||
'price' => 18000.00,
|
||||
'mileage' => 60000,
|
||||
'image_url' => 'https://images.pexels.com/photos/112460/pexels-photo-112460.jpeg?auto=compress&cs=tinysrgb&w=800',
|
||||
'description' => 'Silver C-Class. Imported from Germany. Clean interior.'
|
||||
],
|
||||
[
|
||||
'make' => 'Toyota',
|
||||
'model' => 'Hilux',
|
||||
'year' => 2020,
|
||||
'price' => 28000.00,
|
||||
'mileage' => 15000,
|
||||
'image_url' => 'https://images.pexels.com/photos/119435/pexels-photo-119435.jpeg?auto=compress&cs=tinysrgb&w=800',
|
||||
'description' => 'Double cabin Hilux. Strong engine, barely used.'
|
||||
]
|
||||
];
|
||||
|
||||
$insertSql = "INSERT INTO cars (make, model, year, price, mileage, image_url, description) VALUES (:make, :model, :year, :price, :mileage, :image_url, :description)";
|
||||
$stmt = $pdo->prepare($insertSql);
|
||||
|
||||
foreach ($cars as $car) {
|
||||
$stmt->execute($car);
|
||||
}
|
||||
echo "Seeded " . count($cars) . " cars.<br>";
|
||||
} else {
|
||||
echo "Table 'cars' already has data.<br>";
|
||||
}
|
||||
|
||||
} catch (PDOException $e) {
|
||||
echo "Error: " . $e->getMessage();
|
||||
}
|
||||
46
db/setup_users.php
Normal file
46
db/setup_users.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
require_once 'config.php';
|
||||
|
||||
try {
|
||||
$pdo = db();
|
||||
$sql = "
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
username VARCHAR(255) NOT NULL UNIQUE,
|
||||
email VARCHAR(255) NOT NULL UNIQUE,
|
||||
password_hash VARCHAR(255) NOT NULL,
|
||||
role ENUM('user', 'admin') NOT NULL DEFAULT 'user',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
";
|
||||
$pdo->exec($sql);
|
||||
echo "Table 'users' created successfully." . PHP_EOL;
|
||||
|
||||
// Add a default admin user if one doesn't exist
|
||||
$stmt = $pdo->prepare("SELECT COUNT(*) FROM users WHERE email = :email");
|
||||
$stmt->execute(['email' => 'admin@example.com']);
|
||||
if ($stmt->fetchColumn() == 0) {
|
||||
$username = 'admin';
|
||||
$email = 'admin@example.com';
|
||||
$password = 'password'; // In a real app, use a stronger password and handle this securely
|
||||
$password_hash = password_hash($password, PASSWORD_DEFAULT);
|
||||
$role = 'admin';
|
||||
|
||||
$insert_sql = "
|
||||
INSERT INTO users (username, email, password_hash, role)
|
||||
VALUES (:username, :email, :password_hash, :role);
|
||||
";
|
||||
$insert_stmt = $pdo->prepare($insert_sql);
|
||||
$insert_stmt->execute([
|
||||
':username' => $username,
|
||||
':email' => $email,
|
||||
':password_hash' => $password_hash,
|
||||
':role' => $role
|
||||
]);
|
||||
echo "Default admin user created (admin@example.com / password)." . PHP_EOL;
|
||||
}
|
||||
|
||||
|
||||
} catch (PDOException $e) {
|
||||
die("DB ERROR: " . $e->getMessage());
|
||||
}
|
||||
270
index.php
270
index.php
@ -1,150 +1,136 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
@ini_set('display_errors', '1');
|
||||
@error_reporting(E_ALL);
|
||||
@date_default_timezone_set('UTC');
|
||||
session_start();
|
||||
require_once __DIR__ . '/db/config.php';
|
||||
|
||||
$phpVersion = PHP_VERSION;
|
||||
$now = date('Y-m-d H:i:s');
|
||||
// Fetch Featured Cars
|
||||
$cars = [];
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->query("SELECT * FROM cars ORDER BY created_at DESC LIMIT 4");
|
||||
$cars = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
} catch (Exception $e) {
|
||||
// Graceful fallback if DB fails (shouldn't happen given the setup step)
|
||||
error_log($e->getMessage());
|
||||
}
|
||||
|
||||
// Meta variables
|
||||
$projectName = getenv('PROJECT_NAME') ?: 'Car Sells in Afghanistan';
|
||||
$projectDesc = getenv('PROJECT_DESCRIPTION') ?: 'The best marketplace for buying and selling cars in Afghanistan.';
|
||||
$projectImage = getenv('PROJECT_IMAGE_URL') ?: 'https://images.pexels.com/photos/120049/pexels-photo-120049.jpeg?auto=compress&cs=tinysrgb&w=1200';
|
||||
?>
|
||||
<!doctype html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>New Style</title>
|
||||
<?php
|
||||
// Read project preview data from environment
|
||||
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
|
||||
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
|
||||
?>
|
||||
<?php if ($projectDescription): ?>
|
||||
<!-- Meta description -->
|
||||
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
|
||||
<!-- Open Graph meta tags -->
|
||||
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<!-- Twitter meta tags -->
|
||||
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<?php endif; ?>
|
||||
<?php if ($projectImageUrl): ?>
|
||||
<!-- Open Graph image -->
|
||||
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<!-- Twitter image -->
|
||||
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<?php endif; ?>
|
||||
<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=Inter:wght@400;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
:root {
|
||||
--bg-color-start: #6a11cb;
|
||||
--bg-color-end: #2575fc;
|
||||
--text-color: #ffffff;
|
||||
--card-bg-color: rgba(255, 255, 255, 0.01);
|
||||
--card-border-color: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: 'Inter', sans-serif;
|
||||
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
|
||||
color: var(--text-color);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
body::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
|
||||
animation: bg-pan 20s linear infinite;
|
||||
z-index: -1;
|
||||
}
|
||||
@keyframes bg-pan {
|
||||
0% { background-position: 0% 0%; }
|
||||
100% { background-position: 100% 100%; }
|
||||
}
|
||||
main {
|
||||
padding: 2rem;
|
||||
}
|
||||
.card {
|
||||
background: var(--card-bg-color);
|
||||
border: 1px solid var(--card-border-color);
|
||||
border-radius: 16px;
|
||||
padding: 2rem;
|
||||
backdrop-filter: blur(20px);
|
||||
-webkit-backdrop-filter: blur(20px);
|
||||
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.loader {
|
||||
margin: 1.25rem auto 1.25rem;
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border: 3px solid rgba(255, 255, 255, 0.25);
|
||||
border-top-color: #fff;
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
@keyframes spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
.hint {
|
||||
opacity: 0.9;
|
||||
}
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px; height: 1px;
|
||||
padding: 0; margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap; border: 0;
|
||||
}
|
||||
h1 {
|
||||
font-size: 3rem;
|
||||
font-weight: 700;
|
||||
margin: 0 0 1rem;
|
||||
letter-spacing: -1px;
|
||||
}
|
||||
p {
|
||||
margin: 0.5rem 0;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
code {
|
||||
background: rgba(0,0,0,0.2);
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
}
|
||||
footer {
|
||||
position: absolute;
|
||||
bottom: 1rem;
|
||||
font-size: 0.8rem;
|
||||
opacity: 0.7;
|
||||
}
|
||||
</style>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><?php echo htmlspecialchars($projectName); ?></title>
|
||||
<meta name="description" content="<?php echo htmlspecialchars($projectDesc); ?>">
|
||||
|
||||
<!-- Open Graph -->
|
||||
<meta property="og:title" content="<?php echo htmlspecialchars($projectName); ?>">
|
||||
<meta property="og:description" content="<?php echo htmlspecialchars($projectDesc); ?>">
|
||||
<meta property="og:image" content="<?php echo htmlspecialchars($projectImage); ?>">
|
||||
|
||||
<!-- Bootstrap 5 -->
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<!-- Bootstrap Icons -->
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css">
|
||||
<!-- Google Fonts: Inter -->
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
|
||||
|
||||
<!-- Custom CSS -->
|
||||
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<div class="card">
|
||||
<h1>Analyzing your requirements and generating your website…</h1>
|
||||
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
|
||||
<span class="sr-only">Loading…</span>
|
||||
</div>
|
||||
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p>
|
||||
<p class="hint">This page will update automatically as the plan is implemented.</p>
|
||||
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
|
||||
</div>
|
||||
</main>
|
||||
<footer>
|
||||
Page updated: <?= htmlspecialchars($now) ?> (UTC)
|
||||
</footer>
|
||||
|
||||
<?php include 'partials/navbar.php'; ?>
|
||||
|
||||
<!-- Hero Section -->
|
||||
<section class="hero-section text-center">
|
||||
<div class="hero-bg-overlay"></div>
|
||||
<div class="container hero-content">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-lg-8">
|
||||
<h1 class="display-4 fw-bold mb-3">Find Your Dream Car</h1>
|
||||
<p class="lead mb-5 text-light opacity-75">The most trusted marketplace for buying and selling cars in Afghanistan.</p>
|
||||
|
||||
<div class="search-card text-start">
|
||||
<form action="#" method="GET" class="row g-3">
|
||||
<div class="col-md-4">
|
||||
<label class="form-label small text-muted">Make</label>
|
||||
<select class="form-select border-0 bg-light">
|
||||
<option selected>All Makes</option>
|
||||
<option>Toyota</option>
|
||||
<option>Mercedes</option>
|
||||
<option>Honda</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label small text-muted">Model</label>
|
||||
<select class="form-select border-0 bg-light">
|
||||
<option selected>Any Model</option>
|
||||
<option>Corolla</option>
|
||||
<option>Camry</option>
|
||||
<option>Land Cruiser</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label small text-muted d-block"> </label>
|
||||
<button type="submit" class="btn btn-primary w-100">Search Cars</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Featured Cars -->
|
||||
<section class="container mb-5">
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<h2 class="section-title h3 mb-0">Featured Cars</h2>
|
||||
<a href="#" class="text-decoration-none fw-semibold">View All <i class="bi bi-arrow-right"></i></a>
|
||||
</div>
|
||||
|
||||
<div class="row g-4">
|
||||
<?php if (!empty($cars)): ?>
|
||||
<?php foreach ($cars as $car): ?>
|
||||
<div class="col-md-6 col-lg-3">
|
||||
<div class="car-card h-100">
|
||||
<div class="position-relative">
|
||||
<img src="<?php echo htmlspecialchars($car['image_url']); ?>" class="card-img-top car-img-top" alt="<?php echo htmlspecialchars($car['make'] . ' ' . $car['model']); ?>">
|
||||
<span class="position-absolute top-0 end-0 m-3 badge bg-dark opacity-75"><?php echo $car['year']; ?></span>
|
||||
</div>
|
||||
<div class="car-card-body d-flex flex-column">
|
||||
<h5 class="card-title fw-bold mb-1"><?php echo htmlspecialchars($car['make'] . ' ' . $car['model']); ?></h5>
|
||||
<p class="text-muted small mb-3 text-truncate"><?php echo htmlspecialchars($car['description']); ?></p>
|
||||
|
||||
<div class="mt-auto">
|
||||
<div class="d-flex justify-content-between mb-3">
|
||||
<div class="spec-item"><i class="bi bi-speedometer2"></i> <?php echo number_format($car['mileage']); ?> km</div>
|
||||
<div class="spec-item"><i class="bi bi-fuel-pump"></i> Petrol</div>
|
||||
</div>
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<span class="price-tag">$<?php echo number_format($car['price']); ?></span>
|
||||
<a href="#" class="btn btn-outline-secondary btn-sm rounded-pill">Details</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php else: ?>
|
||||
<div class="col-12 text-center py-5">
|
||||
<p class="text-muted">No cars available at the moment. Please check back later.</p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<?php include 'partials/footer.php'; ?>
|
||||
|
||||
<!-- Scripts -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
93
login.php
Normal file
93
login.php
Normal file
@ -0,0 +1,93 @@
|
||||
<?php
|
||||
require_once 'db/config.php';
|
||||
|
||||
session_start();
|
||||
|
||||
if (isset($_SESSION['user_id'])) {
|
||||
header("Location: index.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
$errors = [];
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$email = trim($_POST['email']);
|
||||
$password = $_POST['password'];
|
||||
|
||||
if (empty($email)) {
|
||||
$errors[] = 'Email is required';
|
||||
}
|
||||
if (empty($password)) {
|
||||
$errors[] = 'Password is required';
|
||||
}
|
||||
|
||||
if (empty($errors)) {
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare("SELECT * FROM users WHERE email = :email");
|
||||
$stmt->execute(['email' => $email]);
|
||||
$user = $stmt->fetch();
|
||||
|
||||
if ($user && password_verify($password, $user['password_hash'])) {
|
||||
$_SESSION['user_id'] = $user['id'];
|
||||
$_SESSION['username'] = $user['username'];
|
||||
$_SESSION['role'] = $user['role'];
|
||||
header("Location: index.php");
|
||||
exit();
|
||||
} else {
|
||||
$errors[] = 'Invalid email or password';
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
$errors[] = "Database error: " . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Login - Car Sells in Afghanistan</title>
|
||||
<link href="https://rsms.me/inter/inter.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||
</head>
|
||||
<body class="bg-slate-50 dark:bg-slate-900 text-slate-800 dark:text-slate-200">
|
||||
|
||||
<?php include 'partials/navbar.php'; ?>
|
||||
|
||||
<main class="container mx-auto px-4 py-8">
|
||||
<div class="max-w-md mx-auto bg-white dark:bg-slate-800 rounded-lg shadow-md p-8">
|
||||
<h1 class="text-2xl font-bold text-center mb-6">Login to Your Account</h1>
|
||||
|
||||
<?php if (!empty($errors)): ?>
|
||||
<div class="bg-red-100 dark:bg-red-900 border border-red-400 text-red-700 dark:text-red-200 px-4 py-3 rounded relative mb-4" role="alert">
|
||||
<ul>
|
||||
<?php foreach ($errors as $error): ?>
|
||||
<li><?php echo htmlspecialchars($error); ?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form action="login.php" method="POST">
|
||||
<div class="mb-4">
|
||||
<label for="email" class="block text-sm font-medium mb-2">Email Address</label>
|
||||
<input type="email" id="email" name="email" class="w-full px-3 py-2 bg-slate-100 dark:bg-slate-700 rounded-md focus:outline-none focus:ring-2 focus:ring-orange-500" required>
|
||||
</div>
|
||||
<div class="mb-6">
|
||||
<label for="password" class="block text-sm font-medium mb-2">Password</label>
|
||||
<input type="password" id="password" name="password" class="w-full px-3 py-2 bg-slate-100 dark:bg-slate-700 rounded-md focus:outline-none focus:ring-2 focus:ring-orange-500" required>
|
||||
</div>
|
||||
<button type="submit" class="w-full bg-orange-600 hover:bg-orange-700 text-white font-bold py-2 px-4 rounded-md transition duration-300">Login</button>
|
||||
</form>
|
||||
<p class="text-center text-sm mt-6">
|
||||
Don't have an account? <a href="register.php" class="text-orange-500 hover:underline">Register here</a>.
|
||||
</p>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<?php include 'partials/footer.php'; ?>
|
||||
|
||||
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
||||
</body>
|
||||
</html>
|
||||
6
logout.php
Normal file
6
logout.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
session_start();
|
||||
session_unset();
|
||||
session_destroy();
|
||||
header("Location: index.php");
|
||||
exit();
|
||||
13
partials/footer.php
Normal file
13
partials/footer.php
Normal file
@ -0,0 +1,13 @@
|
||||
<footer class="footer text-center">
|
||||
<div class="container">
|
||||
<div class="row justify-content-center mb-4">
|
||||
<div class="col-md-6">
|
||||
<h5 class="fw-bold mb-3">Car Sells AF</h5>
|
||||
<p class="text-muted small">The easiest way to buy and sell cars in Afghanistan. Secure, fast, and reliable.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="border-top pt-4">
|
||||
<p class="text-muted small mb-0">© <?php echo date('Y'); ?> Car Sells in Afghanistan. All rights reserved.</p>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
51
partials/navbar.php
Normal file
51
partials/navbar.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
?>
|
||||
<nav class="navbar navbar-expand-lg sticky-top">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="index.php">
|
||||
<i class="bi bi-car-front-fill text-primary me-2"></i>Car Sells AF
|
||||
</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
|
||||
<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"><a class="nav-link" href="index.php">Home</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="car_list.php">Cars</a></li>
|
||||
|
||||
<?php if (isset($_SESSION['user_id'])): ?>
|
||||
<li class="nav-item"><a class="nav-link" href="#">Sell Your Car</a></li>
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="bi bi-person-circle"></i> <?php echo htmlspecialchars($_SESSION['username']); ?>
|
||||
</a>
|
||||
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
|
||||
<li><a class="dropdown-item" href="dashboard.php">Dashboard</a></li>
|
||||
<?php if ($_SESSION['role'] === 'admin'): ?>
|
||||
<li><a class="dropdown-item" href="admin/index.php">Admin Panel</a></li>
|
||||
<?php endif; ?>
|
||||
<li><hr class="dropdown-divider"></li>
|
||||
<li><a class="dropdown-item" href="logout.php">Logout</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<?php else: ?>
|
||||
<li class="nav-item ms-lg-3">
|
||||
<a href="login.php" class="btn btn-primary btn-sm rounded-pill px-4">Login</a>
|
||||
</li>
|
||||
<li class="nav-item ms-2">
|
||||
<a href="register.php" class="btn btn-outline-secondary btn-sm rounded-pill px-4">Register</a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
|
||||
<li class="nav-item ms-3">
|
||||
<button id="theme-toggle" class="btn btn-link text-muted p-0 border-0">
|
||||
<i class="bi bi-moon-fill fs-5"></i>
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
109
register.php
Normal file
109
register.php
Normal file
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
require_once 'db/config.php';
|
||||
|
||||
session_start();
|
||||
|
||||
if (isset($_SESSION['user_id'])) {
|
||||
header("Location: index.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
$errors = [];
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$username = trim($_POST['username']);
|
||||
$email = trim($_POST['email']);
|
||||
$password = $_POST['password'];
|
||||
|
||||
if (empty($username)) {
|
||||
$errors[] = 'Username is required';
|
||||
}
|
||||
if (empty($email)) {
|
||||
$errors[] = 'Email is required';
|
||||
} else if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
$errors[] = 'Invalid email format';
|
||||
}
|
||||
if (empty($password)) {
|
||||
$errors[] = 'Password is required';
|
||||
}
|
||||
|
||||
if (empty($errors)) {
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare("SELECT COUNT(*) FROM users WHERE email = :email OR username = :username");
|
||||
$stmt->execute(['email' => $email, 'username' => $username]);
|
||||
if ($stmt->fetchColumn() > 0) {
|
||||
$errors[] = 'Username or email already exists';
|
||||
} else {
|
||||
$password_hash = password_hash($password, PASSWORD_DEFAULT);
|
||||
$insert_stmt = $pdo->prepare("INSERT INTO users (username, email, password_hash) VALUES (:username, :email, :password_hash)");
|
||||
$insert_stmt->execute([
|
||||
':username' => $username,
|
||||
':email' => $email,
|
||||
':password_hash' => $password_hash
|
||||
]);
|
||||
$_SESSION['user_id'] = $pdo->lastInsertId();
|
||||
$_SESSION['username'] = $username;
|
||||
$_SESSION['role'] = 'user';
|
||||
header("Location: index.php");
|
||||
exit();
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
$errors[] = "Database error: " . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Register - Car Sells in Afghanistan</title>
|
||||
<link href="https://rsms.me/inter/inter.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||
</head>
|
||||
<body class="bg-slate-50 dark:bg-slate-900 text-slate-800 dark:text-slate-200">
|
||||
|
||||
<?php include 'partials/navbar.php'; ?>
|
||||
|
||||
<main class="container mx-auto px-4 py-8">
|
||||
<div class="max-w-md mx-auto bg-white dark:bg-slate-800 rounded-lg shadow-md p-8">
|
||||
<h1 class="text-2xl font-bold text-center mb-6">Create an Account</h1>
|
||||
|
||||
<?php if (!empty($errors)): ?>
|
||||
<div class="bg-red-100 dark:bg-red-900 border border-red-400 text-red-700 dark:text-red-200 px-4 py-3 rounded relative mb-4" role="alert">
|
||||
<ul>
|
||||
<?php foreach ($errors as $error): ?>
|
||||
<li><?php echo htmlspecialchars($error); ?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form action="register.php" method="POST">
|
||||
<div class="mb-4">
|
||||
<label for="username" class="block text-sm font-medium mb-2">Username</label>
|
||||
<input type="text" id="username" name="username" class="w-full px-3 py-2 bg-slate-100 dark:bg-slate-700 rounded-md focus:outline-none focus:ring-2 focus:ring-orange-500" required>
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
<label for="email" class="block text-sm font-medium mb-2">Email Address</label>
|
||||
<input type="email" id="email" name="email" class="w-full px-3 py-2 bg-slate-100 dark:bg-slate-700 rounded-md focus:outline-none focus:ring-2 focus:ring-orange-500" required>
|
||||
</div>
|
||||
<div class="mb-6">
|
||||
<label for="password" class="block text-sm font-medium mb-2">Password</label>
|
||||
<input type="password" id="password" name="password" class="w-full px-3 py-2 bg-slate-100 dark:bg-slate-700 rounded-md focus:outline-none focus:ring-2 focus:ring-orange-500" required>
|
||||
</div>
|
||||
<button type="submit" class="w-full bg-orange-600 hover:bg-orange-700 text-white font-bold py-2 px-4 rounded-md transition duration-300">Register</button>
|
||||
</form>
|
||||
<p class="text-center text-sm mt-6">
|
||||
Already have an account? <a href="login.php" class="text-orange-500 hover:underline">Login here</a>.
|
||||
</p>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<?php include 'partials/footer.php'; ?>
|
||||
|
||||
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
x
Reference in New Issue
Block a user