119 lines
5.1 KiB
PHP
119 lines
5.1 KiB
PHP
<?php
|
|
// car_detail.php
|
|
require_once 'includes/auth.php';
|
|
require_once 'includes/header.php';
|
|
global $pdo;
|
|
|
|
$id = $_GET['id'] ?? 0;
|
|
$stmt = $pdo->prepare("SELECT * FROM cars WHERE id = ?");
|
|
$stmt->execute([$id]);
|
|
$car = $stmt->fetch();
|
|
|
|
if (!$car) {
|
|
die("<div class='container mt-5'><h1>Car not found</h1><a href='marketplace.php'>Back to Marketplace</a></div>");
|
|
}
|
|
|
|
// Fetch Branch Info
|
|
$stmt = $pdo->prepare("SELECT * FROM branches WHERE id = ?");
|
|
$stmt->execute([$car['branch_id']]);
|
|
$branch = $stmt->fetch();
|
|
?>
|
|
|
|
<div class="container mt-5">
|
|
<a href="marketplace.php" class="btn-outline" style="margin-bottom: 20px; display: inline-block;">← Back to Marketplace</a>
|
|
|
|
<div class="grid" style="grid-template-columns: 2fr 1fr; gap: 40px;">
|
|
<!-- Left Column: Image & Desc -->
|
|
<div>
|
|
<div class="card" style="padding: 0; margin-bottom: 20px;">
|
|
<img src="<?= htmlspecialchars($car['image_path'] ?? $car['image_url'] ?? '') ?>" alt="<?= htmlspecialchars($car['brand']) ?>" style="height: auto; max-height: 500px;">
|
|
</div>
|
|
|
|
<div class="card" style="padding: 30px;">
|
|
<h2>Vehicle Description</h2>
|
|
<p><?= nl2br(htmlspecialchars($car['description'])) ?></p>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Right Column: Details & Actions -->
|
|
<div>
|
|
<div class="card" style="padding: 30px;">
|
|
<h1 style="color: var(--primary); margin-bottom: 10px;">
|
|
<?= htmlspecialchars($car['year'] . ' ' . $car['brand'] . ' ' . $car['model']) ?>
|
|
</h1>
|
|
<div style="font-size: 2rem; font-weight: bold; margin-bottom: 20px;">
|
|
$<?= number_format((float)$car['price']) ?>
|
|
</div>
|
|
|
|
<table style="margin-bottom: 30px;">
|
|
<tr><th>Mileage</th><td><?= number_format((float)$car['mileage']) ?> km</td></tr>
|
|
<tr><th>Fuel</th><td><?= htmlspecialchars($car['fuel_type']) ?></td></tr>
|
|
<tr><th>Transmission</th><td><?= htmlspecialchars($car['transmission']) ?></td></tr>
|
|
<tr><th>Status</th><td><?= htmlspecialchars(ucfirst($car['status'])) ?></td></tr>
|
|
<tr><th>Location</th><td><?= htmlspecialchars($branch['city'] ?? 'Unknown') ?></td></tr>
|
|
</table>
|
|
|
|
<a href="contact.php?inquiry=<?= $car['id'] ?>" class="btn" style="width: 100%; margin-bottom: 10px;">Request to Buy</a>
|
|
<button onclick="document.getElementById('calc-section').scrollIntoView({behavior: 'smooth'})" class="btn-outline" style="width: 100%;">Calculate Installments</button>
|
|
</div>
|
|
|
|
<div class="card" style="padding: 20px; margin-top: 20px;">
|
|
<h3>Branch Contact</h3>
|
|
<p><strong><?= htmlspecialchars($branch['name'] ?? '') ?></strong></p>
|
|
<p><?= htmlspecialchars($branch['address'] ?? '') ?></p>
|
|
<p><?= htmlspecialchars($branch['phone'] ?? '') ?></p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Installment Calculator for this car -->
|
|
<div id="calc-section" class="card mt-5" style="padding: 40px;">
|
|
<h2>Installment Calculator</h2>
|
|
<div class="grid" style="grid-template-columns: 1fr 1fr 1fr;">
|
|
<div>
|
|
<label>Vehicle Price</label>
|
|
<input type="text" class="form-control" value="$<?= number_format((float)$car['price']) ?>" disabled>
|
|
</div>
|
|
<div>
|
|
<label>Down Payment ($)</label>
|
|
<input type="number" id="downPayment" class="form-control" value="<?= (float)$car['price'] * 0.2 ?>" oninput="calc()">
|
|
</div>
|
|
<div>
|
|
<label>Term</label>
|
|
<select id="term" class="form-control" onchange="calc()">
|
|
<option value="12">12 Months</option>
|
|
<option value="24" selected>24 Months</option>
|
|
<option value="36">36 Months</option>
|
|
<option value="48">48 Months</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
<div style="margin-top: 20px; font-size: 1.5rem; text-align: center;">
|
|
Estimated Monthly Payment: <span id="monthlyPayment" style="color: var(--primary); font-weight: bold;">---</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
function calc() {
|
|
const price = <?= (float)$car['price'] ?>;
|
|
const down = parseFloat(document.getElementById('downPayment').value) || 0;
|
|
const months = parseInt(document.getElementById('term').value);
|
|
|
|
const principal = price - down;
|
|
if (principal < 0) {
|
|
document.getElementById('monthlyPayment').innerText = "Down payment exceeds price!";
|
|
return;
|
|
}
|
|
|
|
const interest = 0.05; // 5% flat
|
|
const total = principal * (1 + interest);
|
|
const monthly = total / months;
|
|
|
|
document.getElementById('monthlyPayment').innerText = "$" + monthly.toFixed(2);
|
|
}
|
|
calc(); // Run on load
|
|
</script>
|
|
|
|
<?php require_once 'includes/footer.php'; ?>
|