<?php
session_start();
include('db_connection.php');

// Check if the teacher is logged in
if (!isset($_SESSION['teacher_id'])) {
    header("Location: teacher_login.php");
    exit();
}

// Get the student ID from the query string
$student_id = isset($_GET['student_id']) ? intval($_GET['student_id']) : 0;

if ($student_id > 0) {
    // Fetch attendance records for the student
    $sql = "SELECT attendance_id, date, status FROM student_attendance WHERE student_id = ?";
    $stmt = $conn->prepare($sql);
    $stmt->bind_param("i", $student_id);
    $stmt->execute();
    $result = $stmt->get_result();
    $attendances = $result->fetch_all(MYSQLI_ASSOC);
    $stmt->close();
} else {
    echo "Invalid student ID.";
    exit();
}

$conn->close();
?>
<!DOCTYPE html>


<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Manage Attendance</title>
    <link rel="stylesheet" href="../styles.css"> <!-- Link to your CSS file -->
  <style>
       body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f4f4f4;
            overflow: hidden; /* Prevent vertical scrolling */
    overflow-y: auto; /* Enable vertical scrolling */
        }
        .header {
            background-color: #34495e;
            color: #fff;
            width: 100%;
            display: flex;
            padding: 0 20px;
            text-align: left;
            position: relative;
            justify-content: flex-end;
            height: 60px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
            align-items: center;
            display: flex;
            gap: 20px;
            top: 0;
        }
        .sidebar {
           width: 250px;
    height: 100%;
    background-color: #34495e;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1;
    overflow-x: hidden;
    padding-top: 20px;
    transition: width 0.3s;
        }
        .sidebar a {
            color: #fff;
            padding: 10px 15px;
            display: block;
            text-decoration: none;
        }
        .sidebar a:hover {
            background: #555;
        }
        .main-content {
            margin-left: 200px; /* Same as the width of the sidebar */
            padding: 20px;
            padding-top: 80px; /* Height of the header */
        }
        .footer {
            background: #34495e;
            color: #fff;
            text-align: center;
            padding: 10px 0;
            position: fixed;
            bottom: 0;
            width: 100%;
        }
        .container {
            width: 80%;
            margin: auto;
            overflow: hidden;
        }
        .content {
            padding: 2rem;
            background: #fff;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
        }
        .widget {
            padding: 20px;
            margin-bottom: 20px;
            background: #fff;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
        }
        table {
            width: 100%;
            border-collapse: collapse;
        }
        table, th, td {
            border: 1px solid #ddd;
        }
        th, td {
            padding: 8px;
            text-align: left;
        }
        th {
            background-color: #f2f2f2;
        }
    </style>
</head>
<body>
    <div class="header">
        <h1>Manage Attendance</h1>
    </div>

   <div class="sidebar">
        <a href="teacher_dashboard.php">Dashboard</a>
        <a href="feedback_grading.php">Manage Grade</a>
        <a href="attendance.php">Manage Attendance</a>
        <a href="add_homework.php">Add Assignment</a>
        <a href="class_timetable.php">Class Timetable</a>
        <a href="profile.php">Profile</a>
        <a href="logout.php">Logout</a>
    </div>
    <div class="main-content">
        <div class="container">
            <div class="content">
                <h2>Attendance Records</h2>
                <table>
                    <thead>
                        <tr>
                            <th>Date</th>
                            <th>Status</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($attendances as $record): ?>
                            <tr>
                                <td><?php echo htmlspecialchars($record['date']); ?></td>
                                <td><?php echo htmlspecialchars($record['status']); ?></td>
                                <td>
                                    <a href="edit_attendance.php?attendance_id=<?php echo htmlspecialchars($record['attendance_id']); ?>" class="btn btn-secondary">Edit</a>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <div class="footer">
        <p>&copy; 2024 Your School Name. All rights reserved.</p>
    </div>
</body>
</html>
