<!-- Enter Student Attendance.php -->
<?php
include('session_validator.php');
include("includes/db.php"); // Include database connection

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $exam_type = $_POST['exam_type'];
    $working_days = $_POST['working_days'];
    $school_days = $_POST['school_days'];
    $remarks = $_POST['remarks'];

    // Insert data into school_days table
    $sql = "INSERT INTO school_days (exam_type, working_days, school_days, remarks) VALUES (?, ?, ?, ?)";
    $stmt = $conn->prepare($sql);
    $stmt->bind_param("siis", $exam_type, $working_days, $school_days, $remarks);

    if ($stmt->execute()) {
        echo "<div class='alert alert-success'>Data successfully saved!</div>";
    } else {
        echo "<div class='alert alert-danger'>Error: " . $stmt->error . "</div>";
    }

    $stmt->close();
    $conn->close();
}
?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>SRMS Admin Manage Subjects</title>
    <link rel="stylesheet" href="css/bootstrap.min.css" media="screen">
    <link rel="stylesheet" href="css/font-awesome.min.css" media="screen">
    <link rel="stylesheet" href="css/animate-css/animate.min.css" media="screen">
    <link rel="stylesheet" href="css/lobipanel/lobipanel.min.css" media="screen">
    <link rel="stylesheet" href="css/prism/prism.css" media="screen">
    <link rel="stylesheet" href="css/select2/select2.min.css">
    <link rel="stylesheet" href="css/main.css" media="screen">
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="js/modernizr/modernizr.min.js"></script>
</head>

<body class="top-navbar-fixed">
    <div class="main-wrapper">
        <?php include('includes/topbar.php'); ?>
        <div class="content-wrapper">
            <?php include('includes/leftbar.php'); ?>
            <div class="main-page">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-md-12">
                            <div class="panel">
                                <div class="panel-heading">
                                    <div class="panel-title">
                                        <h5>Enter Attendance</h5>
                                    </div>
                                </div>
                                <div class="panel-body">
                                    <form action="" method="POST">
                                        <div class="row">
                                        <div class="form-group col-md-4">
                                            <label for="exam_type">Exam Type</label>
                                            <select id="exam_type" name="exam_type" class="form-control" required>
                                                <option value="">Select Exam Type</option>
                                                <!-- Options filled dynamically from the database -->
                                                <?php
                                                include("includes/db.php");
                                                $fetchExamTypesQuery = "SELECT id, exam_type,exm_year FROM examination_type";
                                                $examTypesResult = $conn->query($fetchExamTypesQuery);
                                                if ($examTypesResult->num_rows > 0) {
                                                    while ($row = $examTypesResult->fetch_assoc()) {
                                                        echo '<option value="' . $row['id'] . '">' . $row['exam_type'] .'-'.$row['exm_year'] .'</option>';
                                                    }
                                                }
                                                ?>
                                            </select>
                                        </div>
                                        <div class="form-group col-md-2">
                                            <label for="working_days">Working Days</label>
                                            <input type="number" class="form-control" id="working_days" name="working_days" required>
                                        </div>
                                        <div class="form-group col-md-2">
                                            <label for="school_days">School Days</label>
                                            <input type="number" class="form-control" id="school_days" name="school_days" required>
                                        </div>
                                        <div class="form-group col-md-3">
                                            <label for="remarks">Remarks</label>
                                            <input class="form-control" id="remarks" name="remarks"/>
                                        </div>
                                        </div>
                                        <button type="submit" class="btn btn-primary">Save</button>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- /.col-md-12 -->
                </div>
            </div>
        </div>
        <!-- /.main-wrapper -->
        <script src="js/jquery/jquery-2.2.4.min.js"></script>
        <script src="js/bootstrap/bootstrap.min.js"></script>
        <script src="js/pace/pace.min.js"></script>
        <script src="js/lobipanel/lobipanel.min.js"></script>
        <script src="js/iscroll/iscroll.js"></script>
        <script src="js/prism/prism.js"></script>
        <script src="js/select2/select2.min.js"></script>
        <script src="js/main.js"></script>
    </body>
</html>
