<?php
session_start();
$conn = new mysqli("localhost", "job_portal", "job_portal", "job_portal");
if (isset($_GET['delete_id'])) {
    $id = intval($_GET['delete_id']);
    $conn->query("DELETE FROM tour_bookings WHERE id=$id");
    header("Location: display_bookings.php");
    exit;
}
$result = $conn->query("SELECT * FROM tour_bookings ORDER BY submitted_at DESC");
?>
<!DOCTYPE html>
<html>
<head>
    <title>Tour Booking Display</title>
    <style>
        body {
            font-family: Arial, sans-serif;
        }

        h2 {
            margin-bottom: 10px;
        }

        table {
            border-collapse: collapse;
            width: 100%;
            font-size: 12px;
        }

        th, td {
            padding: 6px;
            border: 1px solid #999;
            text-align: left;
        }

        th {
            background-color: #004080;
            color: white;
        }

        .btn {
            padding: 6px 12px;
            border-radius: 3px;
            text-decoration: none;
            color: white;
            font-size: 13px;
            margin: 5px 0;
            display: inline-block;
        }

        .delete { background-color: #dc3545; }
        .print { background-color: #198754; }
        .logout { background-color: #0d6efd; float: right; }

        @media print {
            .btn, .logout {
                display: none !important;
            }
            body {
                margin: 0;
            }
            table {
                page-break-inside: avoid;
            }
        }

        /* A4 paper styling for print */
        @page {
            size: A4;
            margin: 1cm;
        }
    </style>
</head>
<body>

    <h2>Tour Bookings 
        <a href="logout.php" class="btn logout">Logout</a>
    </h2>

    <button onclick="window.print()" class="btn print">Print</button>

    <table>
        <tr>
            <th>ID</th>
            <th>Type</th>
            <th>Membership No</th>
            <th>Name</th>
            <th>Guest</th>
            <th>Contact</th>
            <th>Email</th>
            <th>Destination</th>
            <th>Rooms</th>
            <th>Adults</th>
            <th>Child</th>
            <th>Check-In</th>
            <th>Check-Out</th>
            <th>Submitted</th>
            <th>Action</th>
        </tr>
        <?php while($row = $result->fetch_assoc()) { ?>
        <tr>
            <td><?= $row['id'] ?></td>
            <td><?= htmlspecialchars($row['type']) ?></td>
            <td><?= htmlspecialchars($row['membership_no']) ?></td>
            <td><?= htmlspecialchars($row['name']) ?></td>
            <td><?= htmlspecialchars($row['guest']) ?></td>
            <td><?= htmlspecialchars($row['contact']) ?></td>
            <td><?= htmlspecialchars($row['email']) ?></td>
            <td><?= htmlspecialchars($row['destination']) ?></td>
            <td><?= $row['number_of_rooms'] ?></td>
            <td><?= $row['adults'] ?></td>
            <td><?= $row['child_below_6_years'] ?></td>
            <td><?= $row['check_in'] ?></td>
            <td><?= $row['check_out'] ?></td>
            <td><?= $row['submitted_at'] ?></td>
            <td>
                <a href="?delete_id=<?= $row['id'] ?>" class="btn delete" onclick="return confirm('Are you sure?')">Delete</a>
            </td>
        </tr>
        <?php } ?>
    </table>

</body>
</html>
