����JFIF��`�`�����Viewing File: /home/u820193700/domains/throtllr.in/public_html/admin/manage_bikes.php
<?php
require_once '../includes/db.php';
require_once '../includes/functions.php';
if(!is_logged_in()) { redirect("login.php"); }

if (isset($_GET['delete'])) {
    $del_id = intval($_GET['delete']);
    try {
        $stmt = $pdo->prepare("DELETE FROM bikes WHERE id = ?");
        $stmt->execute([$del_id]);
        redirect("manage_bikes.php?msg=deleted");
    } catch (\PDOException $e) {
        $error = "Cannot delete this bike because it is linked to other records (e.g. inspections).";
    }
}

$stmt = $pdo->query("SELECT b.*, 
    (SELECT image_url FROM bike_images WHERE bike_id = b.id AND is_main = TRUE LIMIT 1) as main_image,
    (SELECT COUNT(*) FROM bike_360_images WHERE bike_id = b.id) as has_360
    FROM bikes b ORDER BY b.created_at DESC");
$bikes = $stmt->fetchAll();
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Manage Bikes - ReOwn Admin</title>
    <link href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="admin.css?v=<?php echo time(); ?>">
</head>
<body>

<?php include 'admin_sidebar.php'; ?>

<div id="main-content">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h2>Manage Bikes</h2>
        <a href="add_bike.php" class="btn btn-danger"><i class="fas fa-plus me-2"></i> Add New Bike</a>
    </div>

    <?php if(isset($_GET['msg']) && $_GET['msg'] == 'deleted'): ?>
        <div class="alert alert-success">Bike deleted successfully.</div>
    <?php endif; ?>
    <?php if(isset($error)): ?>
        <div class="alert alert-danger"><?php echo htmlspecialchars($error); ?></div>
    <?php endif; ?>

    <div class="glass-card p-4">
        <div class="table-responsive">
            <table class="table table-dark table-hover align-middle">
                <thead>
                    <tr>
                        <th>Ref ID</th>
                        <th>Image</th>
                        <th>Model Name</th>
                        <th>Price</th>
                        <th>Year</th>
                        <th>Status</th>
                        <th>360°</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                    <tbody>
                        <?php if (count($bikes) > 0): ?>
                            <?php foreach($bikes as $bike): ?>
                            <tr>
                                <td><?php echo htmlspecialchars($bike['reference_id']); ?></td>
                                <td>
                                    <?php if($bike['main_image']): ?>
                                        <img src="../<?php echo htmlspecialchars($bike['main_image']); ?>" class="rounded" width="60" height="40" style="object-fit: cover;">
                                    <?php else: ?>
                                        <div class="bg-secondary rounded d-flex align-items-center justify-content-center" style="width: 60px; height: 40px;"><i class="fas fa-motorcycle text-dark"></i></div>
                                    <?php endif; ?>
                                </td>
                                <td><?php echo htmlspecialchars($bike['model_name']); ?></td>
                                <td>₹ <?php echo number_format($bike['price']); ?></td>
                                <td><?php echo htmlspecialchars($bike['year']); ?></td>
                                <td>
                                    <?php 
                                    $statusClass = 'bg-secondary';
                                    if($bike['status'] == 'available') $statusClass = 'bg-success';
                                    if($bike['status'] == 'sold') $statusClass = 'bg-danger';
                                    if($bike['status'] == 'pending') $statusClass = 'bg-warning text-dark';
                                    ?>
                                    <span class="badge <?php echo $statusClass; ?>"><?php echo ucfirst($bike['status']); ?></span>
                                </td>
                                <td>
                                    <?php if($bike['has_360']): ?>
                                        <i class="fas fa-check-circle text-success"></i>
                                    <?php else: ?>
                                        <i class="fas fa-times-circle text-danger"></i>
                                    <?php endif; ?>
                                </td>
                                <td>
                                    <a href="edit_bike.php?id=<?php echo $bike['id']; ?>" class="btn btn-sm btn-outline-light me-1" title="Edit"><i class="fas fa-edit"></i></a>
                                    <a href="manage_bikes.php?delete=<?php echo $bike['id']; ?>" class="btn btn-sm btn-outline-danger" title="Delete" onclick="return confirm('Are you sure you want to delete this bike?');"><i class="fas fa-trash"></i></a>
                                </td>
                            </tr>
                            <?php endforeach; ?>
                        <?php else: ?>
                            <tr><td colspan="8" class="text-center text-muted">No bikes found.</td></tr>
                        <?php endif; ?>
                    </tbody>
            </table>
        </div>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
Back to Directory �������}�!1AQa"q2���#B��R��$3br� %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz�������������������������������������������������������������������������������� ������w�!1AQaq"2�B���� #3R�br� $4�%�&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz������������������������������������������������������������������������ ��?��_��+��?��(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(�����