<?php
// Connect to the database (assuming db_connection.php includes your connection code)
include('db_connection.php');

// Fetch all attendance records
$select_query = "SELECT a.attendance_id, a.teacher_id, a.attendance_date, a.status, t.name AS teacher_name
                 FROM attendance a
                 INNER JOIN teachers t ON a.teacher_id = t.teacher_id";
$result = $conn->query($select_query);

if (!$result) {
    // Handle error, e.g., display an error message
    die('Error fetching attendance records: ' . $conn->error);
}

// Close database connection
$conn->close();
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>View Attendance</title>
    <link rel="stylesheet" href="#">
    <style type="text/css">
        <style type="text/css">
        /* Reset default browser styles */
/* Reset default browser styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Body styles */
body {
    font-family: Arial, sans-serif;
    background-color: #f0f0f0;
    padding: 20px;
}

/* Container styles */
.container {
    max-width: 800px;
    margin: 0 auto;
    background-color: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

/* Table styles */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
}

table th, table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #ddd;
}

table th {
    background-color: #f2f2f2;
}

/* Button styles */
.button {
    background-color: #4CAF50;
    color: white;
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    text-decoration: none;
}

.button:hover {
    background-color: #45a049;
}

/* Responsive styles */
@media (max-width: 768px) {
    .container {
        width: 90%;
    }
}

    </style>
    </style>
</head>
<body>
    <h2>View Attendance</h2>
    <table>
        <tr>
            <th>Teacher Name</th>
            <th>Date</th>
            <th>Status</th>
            <th>Action</th>
        </tr>
        <?php while ($row = $result->fetch_assoc()) { ?>
        <tr>
            <td><?php echo $row['teacher_name']; ?></td>
            <td><?php echo $row['attendance_date']; ?></td>
            <td><?php echo $row['status']; ?></td>
            <td>
                <a href="edit_attendance.php?attendance_id=<?php echo $row['attendance_id']; ?>">Edit</a> |
                <a href="delete_attendance.php?attendance_id=<?php echo $row['attendance_id']; ?>" onclick="return confirm('Are you sure you want to delete this attendance record?')">Delete</a>
            </td>
        </tr>
        <?php } ?>
    </table>
</body>
</html>
