sadiq
This commit is contained in:
parent
5e1b7e7c43
commit
980e61a17b
@ -91,4 +91,11 @@ $branches = $pdo->query("SELECT * FROM branches ORDER BY created_at DESC")->fetc
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Auto-open modal if action=add
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
if (urlParams.get('action') === 'add') {
|
||||
document.getElementById('addBranchModal').style.display = 'block';
|
||||
}
|
||||
</script>
|
||||
<?php require_once 'includes/footer.php'; ?>
|
||||
|
||||
@ -16,12 +16,29 @@ if (isset($_POST['delete_car'])) {
|
||||
// Handle Add (Basic Implementation)
|
||||
if (isset($_POST['add_car'])) {
|
||||
try {
|
||||
$stmt = $pdo->prepare("INSERT INTO cars (vin, brand, model, year, price, mileage, transmission, fuel_type, status, branch_id, dealer_id, installment_available) VALUES (?, ?, ?, ?, ?, ?, ?, ?, 'Available', ?, ?, ?)");
|
||||
$image_url = 'assets/images/cars/default.jpg'; // Default
|
||||
|
||||
// Handle Image Upload
|
||||
if (isset($_FILES['image']) && $_FILES['image']['error'] === UPLOAD_ERR_OK) {
|
||||
$uploadDir = __DIR__ . '/../assets/images/cars/';
|
||||
if (!is_dir($uploadDir)) mkdir($uploadDir, 0777, true);
|
||||
|
||||
$ext = pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION);
|
||||
$filename = uniqid('car_') . '.' . $ext;
|
||||
$targetPath = $uploadDir . $filename;
|
||||
|
||||
if (move_uploaded_file($_FILES['image']['tmp_name'], $targetPath)) {
|
||||
$image_url = 'assets/images/cars/' . $filename;
|
||||
}
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare("INSERT INTO cars (vin, brand, model, year, price, mileage, transmission, fuel_type, status, branch_id, dealer_id, installment_available, image_url) VALUES (?, ?, ?, ?, ?, ?, ?, ?, 'Available', ?, ?, ?, ?)");
|
||||
$stmt->execute([
|
||||
$_POST['vin'], $_POST['brand'], $_POST['model'], $_POST['year'],
|
||||
$_POST['price'], $_POST['mileage'], $_POST['transmission'],
|
||||
$_POST['fuel_type'], $_POST['branch_id'], $_POST['dealer_id'] ?: null,
|
||||
isset($_POST['installment_available']) ? 1 : 0
|
||||
isset($_POST['installment_available']) ? 1 : 0,
|
||||
$image_url
|
||||
]);
|
||||
|
||||
// Log activity
|
||||
@ -83,9 +100,13 @@ $cars = $stmt->fetchAll();
|
||||
|
||||
<!-- Simple Add Car Modal -->
|
||||
<div id="addCarModal" style="display:none; position:fixed; top:0; left:0; width:100%; height:100%; background:rgba(0,0,0,0.8); z-index:2000; align-items:center; justify-content:center; display:none;">
|
||||
<div style="background:var(--card-bg); margin:5% auto; padding:2rem; width:90%; max-width:500px; border-radius:12px; border:1px solid var(--border-color); position: relative;">
|
||||
<div style="background:var(--card-bg); margin:5% auto; padding:2rem; width:90%; max-width:500px; border-radius:12px; border:1px solid var(--border-color); position: relative; max-height: 90vh; overflow-y: auto;">
|
||||
<h2 style="margin-bottom:1.5rem; text-align:center;">Add New Car</h2>
|
||||
<form method="POST">
|
||||
<form method="POST" enctype="multipart/form-data">
|
||||
<div style="margin-bottom:1rem;">
|
||||
<label style="display:block; margin-bottom:0.5rem;">Vehicle Image</label>
|
||||
<input type="file" name="image" accept="image/*" required style="width:100%; padding:0.8rem; background:var(--bg-color); border:1px solid var(--border-color); color:white; border-radius:4px;">
|
||||
</div>
|
||||
<div style="margin-bottom:1rem;">
|
||||
<input type="text" name="vin" placeholder="VIN Number" required style="width:100%; padding:0.8rem; background:var(--bg-color); border:1px solid var(--border-color); color:white; border-radius:4px;">
|
||||
</div>
|
||||
@ -143,8 +164,15 @@ $cars = $stmt->fetchAll();
|
||||
// Actually the inline style 'display:none' on the wrapper div is correct.
|
||||
// I'll add a script to ensure it works.
|
||||
const modal = document.getElementById('addCarModal');
|
||||
// Ensure it's hidden on load
|
||||
modal.style.display = 'none';
|
||||
|
||||
// Auto-open if action=add
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
if (urlParams.get('action') === 'add') {
|
||||
modal.style.display = 'flex';
|
||||
} else {
|
||||
// Ensure it's hidden on load if not requested
|
||||
modal.style.display = 'none';
|
||||
}
|
||||
|
||||
// Override the button to show it as flex for centering
|
||||
document.querySelector('.page-header button').onclick = function() {
|
||||
|
||||
@ -12,6 +12,25 @@ if (isset($_POST['delete_user'])) {
|
||||
}
|
||||
}
|
||||
|
||||
// Handle Add User
|
||||
if (isset($_POST['add_user'])) {
|
||||
$username = $_POST['username'];
|
||||
$email = $_POST['email'];
|
||||
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
|
||||
$role = $_POST['role'];
|
||||
|
||||
// Check if exists
|
||||
$stmt = $pdo->prepare("SELECT id FROM users WHERE username = ? OR email = ?");
|
||||
$stmt->execute([$username, $email]);
|
||||
if ($stmt->fetch()) {
|
||||
echo "<div style='padding: 1rem; background: #f44336; color: white;'>User already exists</div>";
|
||||
} else {
|
||||
$stmt = $pdo->prepare("INSERT INTO users (username, email, password, role) VALUES (?, ?, ?, ?)");
|
||||
$stmt->execute([$username, $email, $password, $role]);
|
||||
echo "<div style='padding: 1rem; background: #4caf50; color: white;'>User Added Successfully</div>";
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST['update_role'])) {
|
||||
$id = $_POST['user_id'];
|
||||
$role = $_POST['role'];
|
||||
@ -28,6 +47,7 @@ $users = $stmt->fetchAll();
|
||||
|
||||
<div class="page-header">
|
||||
<h1>User Management</h1>
|
||||
<button onclick="document.getElementById('addUserModal').style.display='block'" class="btn-sm btn-primary">Add New User</button>
|
||||
</div>
|
||||
|
||||
<div style="overflow-x: auto;">
|
||||
@ -84,3 +104,42 @@ $users = $stmt->fetchAll();
|
||||
</div>
|
||||
|
||||
<?php require_once 'includes/footer.php'; ?>
|
||||
|
||||
<!-- Add User Modal -->
|
||||
<div id="addUserModal" style="display:none; position:fixed; top:0; left:0; width:100%; height:100%; background:rgba(0,0,0,0.8); z-index:1000;">
|
||||
<div style="background:var(--card-bg); width:400px; margin: 100px auto; padding:2rem; border-radius:8px; border:1px solid var(--border-color);">
|
||||
<h2 style="margin-bottom:1rem; color:var(--text-primary);">Add User</h2>
|
||||
<form method="POST">
|
||||
<div style="margin-bottom:1rem;">
|
||||
<label style="display:block; color:var(--text-secondary); margin-bottom:0.5rem;">Username</label>
|
||||
<input type="text" name="username" required style="width:100%; padding:0.8rem; background:var(--bg-color); border:1px solid var(--border-color); color:var(--text-primary);">
|
||||
</div>
|
||||
<div style="margin-bottom:1rem;">
|
||||
<label style="display:block; color:var(--text-secondary); margin-bottom:0.5rem;">Email</label>
|
||||
<input type="email" name="email" required style="width:100%; padding:0.8rem; background:var(--bg-color); border:1px solid var(--border-color); color:var(--text-primary);">
|
||||
</div>
|
||||
<div style="margin-bottom:1rem;">
|
||||
<label style="display:block; color:var(--text-secondary); margin-bottom:0.5rem;">Password</label>
|
||||
<input type="password" name="password" required style="width:100%; padding:0.8rem; background:var(--bg-color); border:1px solid var(--border-color); color:var(--text-primary);">
|
||||
</div>
|
||||
<div style="margin-bottom:1rem;">
|
||||
<label style="display:block; color:var(--text-secondary); margin-bottom:0.5rem;">Role</label>
|
||||
<select name="role" style="width:100%; padding:0.8rem; background:var(--bg-color); border:1px solid var(--border-color); color:var(--text-primary);">
|
||||
<option value="Customer">Customer</option>
|
||||
<option value="Dealer">Dealer</option>
|
||||
<option value="Manager">Manager</option>
|
||||
<option value="Admin">Admin</option>
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" name="add_user" class="btn-sm btn-primary" style="width:100%;">Create User</button>
|
||||
<button type="button" onclick="document.getElementById('addUserModal').style.display='none'" class="btn-sm" style="width:100%; margin-top:0.5rem; background:transparent; border:1px solid var(--border-color);">Cancel</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
if (urlParams.get('action') === 'add') {
|
||||
document.getElementById('addUserModal').style.display = 'block';
|
||||
}
|
||||
</script>
|
||||
|
||||
117
car_details.php
Normal file
117
car_details.php
Normal file
@ -0,0 +1,117 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
require_once __DIR__ . '/includes/header.php';
|
||||
|
||||
$id = $_GET['id'] ?? 0;
|
||||
$car = null;
|
||||
|
||||
try {
|
||||
$db = db();
|
||||
$stmt = $db->prepare("SELECT c.*, b.name as branch_name, b.address as branch_address, b.phone as branch_phone
|
||||
FROM cars c
|
||||
LEFT JOIN branches b ON c.branch_id = b.id
|
||||
WHERE c.id = ?");
|
||||
$stmt->execute([$id]);
|
||||
$car = $stmt->fetch();
|
||||
} catch (Exception $e) {
|
||||
// Log error if needed
|
||||
}
|
||||
|
||||
if (!$car) {
|
||||
echo "<div class='container' style='padding: 4rem; text-align: center;'>
|
||||
<h2>Car not found</h2>
|
||||
<p>The vehicle you are looking for does not exist or has been removed.</p>
|
||||
<a href='marketplace.php' class='btn'>Browse Inventory</a>
|
||||
</div>";
|
||||
require_once __DIR__ . '/includes/footer.php';
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<section class="container" style="padding-top: 4rem;">
|
||||
<div class="grid" style="grid-template-columns: 1.5fr 1fr; gap: 3rem; align-items: start;">
|
||||
|
||||
<!-- Left Column: Images -->
|
||||
<div>
|
||||
<div class="car-image" style="height: 500px; margin-bottom: 1rem;">
|
||||
<?php if ($car['is_featured']): ?>
|
||||
<span class="car-badge">FEATURED</span>
|
||||
<?php endif; ?>
|
||||
<img src="<?= htmlspecialchars($car['image_url']) ?>" alt="<?= htmlspecialchars($car['brand']) ?>" style="width: 100%; height: 100%; object-fit: cover; border-radius: var(--border-radius);">
|
||||
</div>
|
||||
<!-- Placeholder for additional gallery images if we had them -->
|
||||
<div class="grid" style="grid-template-columns: repeat(4, 1fr); gap: 1rem;">
|
||||
<!-- Just repeating main image for gallery effect since we only have one -->
|
||||
<img src="<?= htmlspecialchars($car['image_url']) ?>" style="height: 80px; width: 100%; object-fit: cover; border-radius: 8px; cursor: pointer; opacity: 0.7;">
|
||||
<img src="<?= htmlspecialchars($car['image_url']) ?>" style="height: 80px; width: 100%; object-fit: cover; border-radius: 8px; cursor: pointer; opacity: 0.7;">
|
||||
<img src="<?= htmlspecialchars($car['image_url']) ?>" style="height: 80px; width: 100%; object-fit: cover; border-radius: 8px; cursor: pointer; opacity: 0.7;">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Right Column: Details -->
|
||||
<div>
|
||||
<div style="margin-bottom: 1rem; color: var(--accent-color); font-weight: 700; text-transform: uppercase; letter-spacing: 1px;">
|
||||
<?= htmlspecialchars($car['status']) ?>
|
||||
</div>
|
||||
|
||||
<h1 style="font-size: 2.5rem; margin-bottom: 0.5rem; line-height: 1.2;">
|
||||
<?= htmlspecialchars($car['year'] . ' ' . $car['brand'] . ' ' . $car['model']) ?>
|
||||
</h1>
|
||||
|
||||
<div style="font-size: 2rem; font-weight: 800; color: var(--accent-color); margin-bottom: 2rem;">
|
||||
$<?= number_format((float)$car['price'], 0) ?>
|
||||
</div>
|
||||
|
||||
<div style="background: var(--surface-color); padding: 2rem; border-radius: var(--border-radius); border: 1px solid var(--border-color); margin-bottom: 2rem;">
|
||||
<h3 style="margin-bottom: 1.5rem; border-bottom: 1px solid var(--border-color); padding-bottom: 0.5rem;">Vehicle Specifications</h3>
|
||||
|
||||
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem;">
|
||||
<div>
|
||||
<div style="color: var(--text-secondary); font-size: 0.9rem;">Mileage</div>
|
||||
<div style="font-weight: 600;"><?= number_format((float)$car['mileage'], 0) ?> km</div>
|
||||
</div>
|
||||
<div>
|
||||
<div style="color: var(--text-secondary); font-size: 0.9rem;">Transmission</div>
|
||||
<div style="font-weight: 600;"><?= htmlspecialchars($car['transmission'] ?? 'Automatic') ?></div>
|
||||
</div>
|
||||
<div>
|
||||
<div style="color: var(--text-secondary); font-size: 0.9rem;">Fuel Type</div>
|
||||
<div style="font-weight: 600;"><?= htmlspecialchars($car['fuel_type'] ?? 'Petrol') ?></div>
|
||||
</div>
|
||||
<div>
|
||||
<div style="color: var(--text-secondary); font-size: 0.9rem;">VIN</div>
|
||||
<div style="font-weight: 600;"><?= htmlspecialchars($car['vin']) ?></div>
|
||||
</div>
|
||||
<div>
|
||||
<div style="color: var(--text-secondary); font-size: 0.9rem;">Location</div>
|
||||
<div style="font-weight: 600;"><?= htmlspecialchars($car['branch_name'] ?? 'Main Showroom') ?></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($car['installment_available']): ?>
|
||||
<div style="background: rgba(255, 215, 0, 0.1); padding: 1.5rem; border-radius: var(--border-radius); border: 1px solid var(--accent-color); margin-bottom: 2rem;">
|
||||
<h3 style="color: var(--accent-color); margin-bottom: 0.5rem;"><i class="fas fa-calculator"></i> Installment Plan</h3>
|
||||
<p style="margin-bottom: 1rem; font-size: 0.9rem;">Flexible financing options available for this vehicle.</p>
|
||||
<div style="font-size: 1.2rem; font-weight: 700;">
|
||||
Est. $<?= number_format($car['price'] / 60, 0) ?> / month
|
||||
<span style="font-size: 0.9rem; font-weight: 400; color: var(--text-secondary);">(60 months)</span>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div style="display: flex; gap: 1rem;">
|
||||
<a href="contact.php?subject=Purchase%20Inquiry%20-%20<?= urlencode($car['brand'] . ' ' . $car['model']) ?>&car_id=<?= $car['id'] ?>" class="btn" style="flex: 1; text-align: center;">Request to Buy</a>
|
||||
<?php if ($car['installment_available']): ?>
|
||||
<a href="contact.php?subject=Installment%20Inquiry%20-%20<?= urlencode($car['brand'] . ' ' . $car['model']) ?>&car_id=<?= $car['id'] ?>" class="btn btn-outline" style="flex: 1; text-align: center;">Apply for Installment</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<p style="margin-top: 1.5rem; font-size: 0.8rem; color: var(--text-secondary); text-align: center;">
|
||||
* Price excludes tax and registration fees. Contact us for final pricing.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|
||||
20
contact.php
20
contact.php
@ -1,6 +1,14 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
require_once __DIR__ . '/includes/header.php';
|
||||
|
||||
$subject = $_GET['subject'] ?? '';
|
||||
$car_id = $_GET['car_id'] ?? '';
|
||||
$message_placeholder = "Please provide details about the vehicle or service you are interested in...";
|
||||
|
||||
if ($car_id) {
|
||||
$message_placeholder = "I am interested in vehicle ID #$car_id. Please provide more information.";
|
||||
}
|
||||
?>
|
||||
|
||||
<section class="container" style="padding-top: 6rem;">
|
||||
@ -31,16 +39,16 @@ require_once __DIR__ . '/includes/header.php';
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Inquiry Subject</label>
|
||||
<select style="width: 100%; padding: 1.2rem; background: var(--bg-color); border: 1px solid rgba(255,255,255,0.1); border-radius: 8px; color: white; outline: none; cursor: pointer;">
|
||||
<option>Purchase Interest</option>
|
||||
<option>Installment Inquiry</option>
|
||||
<option>Vehicle Valuation (Selling)</option>
|
||||
<option>Technical Support</option>
|
||||
<select name="subject" style="width: 100%; padding: 1.2rem; background: var(--bg-color); border: 1px solid rgba(255,255,255,0.1); border-radius: 8px; color: white; outline: none; cursor: pointer;">
|
||||
<option value="Purchase Interest" <?= strpos($subject, 'Purchase') !== false ? 'selected' : '' ?>>Purchase Interest</option>
|
||||
<option value="Installment Inquiry" <?= strpos($subject, 'Installment') !== false ? 'selected' : '' ?>>Installment Inquiry</option>
|
||||
<option value="Vehicle Valuation" <?= strpos($subject, 'Valuation') !== false ? 'selected' : '' ?>>Vehicle Valuation (Selling)</option>
|
||||
<option value="Technical Support" <?= strpos($subject, 'Support') !== false ? 'selected' : '' ?>>Technical Support</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Your Message</label>
|
||||
<textarea rows="6" placeholder="Please provide details about the vehicle or service you are interested in..." required></textarea>
|
||||
<textarea name="message" rows="6" placeholder="<?= htmlspecialchars($message_placeholder) ?>" required></textarea>
|
||||
</div>
|
||||
<button type="submit" class="btn" style="width: 100%;">Send Message</button>
|
||||
</form>
|
||||
|
||||
@ -30,9 +30,15 @@ $current_page = basename($_SERVER['PHP_SELF']);
|
||||
<li><a href="about.php" <?= $current_page == 'about.php' ? 'class="active"' : '' ?>>About</a></li>
|
||||
<li><a href="contact.php" <?= $current_page == 'contact.php' ? 'class="active"' : '' ?>>Contact Us</a></li>
|
||||
<?php if (isLoggedIn()): ?>
|
||||
<?php if (isAdmin()): ?>
|
||||
<li><a href="/admin/index.php" class="admin-link"><i class="fas fa-chart-line"></i> Dashboard</a></li>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
$dashboardLink = '/buyer/index.php'; // Default
|
||||
if (isAdmin()) {
|
||||
$dashboardLink = '/admin/index.php';
|
||||
} elseif (isset($_SESSION['role']) && $_SESSION['role'] === 'Dealer') {
|
||||
$dashboardLink = '/dealer/index.php';
|
||||
}
|
||||
?>
|
||||
<li><a href="<?= $dashboardLink ?>" class="admin-link"><i class="fas fa-chart-line"></i> Dashboard</a></li>
|
||||
<li><a href="/logout.php" class="admin-link"><i class="fas fa-sign-out-alt"></i> Logout</a></li>
|
||||
<?php else: ?>
|
||||
<li><a href="/login.php" class="admin-link"><i class="fas fa-user"></i> Login</a></li>
|
||||
|
||||
@ -88,7 +88,7 @@ try {
|
||||
Installments from <strong>$<?= number_format($car['price'] / 60, 0) ?>/mo</strong>
|
||||
</div>
|
||||
<div style="margin-top: 1.5rem;">
|
||||
<a href="marketplace.php" class="btn" style="width: 100%; padding: 0.8rem;">View Details</a>
|
||||
<a href="car_details.php?id=<?= $car['id'] ?>" class="btn" style="width: 100%; padding: 0.8rem;">View Details</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -56,7 +56,7 @@ try {
|
||||
</div>
|
||||
|
||||
<div style="margin-top: 1.5rem;">
|
||||
<a href="#" class="btn" style="width: 100%;">Reserve Vehicle</a>
|
||||
<a href="car_details.php?id=<?= $car['id'] ?>" class="btn" style="width: 100%;">View Details</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user