<?php
include('session_validator.php');
include("includes/db.php"); ?>

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <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="nepali.datepicker.v4.0.1\css\main.css" media="screen">
    <title>Grade Sheet Generator</title>
</head>

<body class="top-navbar-fixed">
    <div class="main-wrapper">
        <!-- ========== TOP NAVBAR ========== -->
        <?php include('includes/topbar.php'); ?>
        <!-- ========== WRAPPER FOR BOTH SIDEBARS & MAIN CONTENT ========== -->
        <div class="content-wrapper">
            <div class="content-container">
                <!-- ========== LEFT SIDEBAR ========== -->
                <?php include('includes/leftbar.php'); ?>
                <!-- /.left-sidebar -->
                <div class="main-page">
                    <div class="container-fluid">
                        <div class="row page-title-div">
                            <div class="col-md-6">
                                <h2 class="title">Select Class to Generate Blank Mark Slip</h2>
                            </div>
                        </div>
                        <div class="row breadcrumb-div">
                            <div class="col-md-6">
                                <ul class="breadcrumb">
                                    <li><a href="dashboard.php"><i class="fa fa-home"></i> Home</a></li>
                                    <li> Marks </li>
                                    <li class="">Blank Mark Slip</li>
                                </ul>
                            </div>
                        </div>
                    </div>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="panel">
                                    <div class="panel-heading">
                                        <div class="panel-title">
                                            <h5>Select Class to Generate Blank Mark Slip</h5>
                                        </div>
                                    </div>
                                    <div class="panel-body">
                                
                                        <div class="form-group">
                                            <form id="gradesheetForm" action="get_final_gradesheet_thpr.php" method="post">



                                                <label for="exam_id">Select Exam:</label>
  <select id="exam_id" name="exam_id" class="form-control" style="width: 300px;" required>
    <option value="">Select Exam</option>
                    <?php
                    // Include the database configuration file
                    include("includes/db.php");

                    // Fetch class names from the 'classes' table
                    $queryexam = "SELECT id, exm_year , exam_type FROM examination_type";
                    $resultexam = $conn->query($queryexam);

                    // Populate the dropdown with class names and sections
                    while ($row = $resultexam->fetch_assoc()) {
                        echo "<option value='" . $row['id'] . "'>" . $row['exam_type'] . " - " . $row['exm_year'] . "</option>";
                    }

                    ?>

</select>

    </div>


                                                <label for="class_id">Select Class:</label>
                                                <select name="class_id" id="class_id" class="form-control"
                                                    style="width: 300px;" required onchange="updateCheckedBy()">
                                                    <option>Select Class</option>
                                                    <!-- Populate dropdown options dynamically from your database -->
                                                    <?php
                                                    $classQuery = "SELECT class_id, class_name, section FROM classes";
                                                    
                                                    $classResult = $conn->query($classQuery);
                                                    while ($row = $classResult->fetch_assoc()) {
                                                        echo "<option value='" . $row['class_id'] . "'>" . $row['class_name'] . " - " . $row['section'] . "</option>";
                                                    }
                                                    ?>
                                                </select>
                                                <br>

                                                Date of Issue: <input type="" id="issuedate" name="issuedate"
                                                    class="form-control" style="width:300px" required />
                                                <br>

                                                Checked By: <input type="text" id="checked_by" name="checked_by"
                                                    class="form-control" style="width:300px"  />
                                                <br>

                                                Prepared By: 
                                                <select name="prepared_by" id="prepared_by" class="form-control"
                                                    style="width: 300px;" required>
                                                    <!-- Populate this dropdown as needed -->
                                                    <option value="Saurav Neupane">Saurav Neupane</option>
                                                    <option value="Dambaru Ballav Ojha">Dambaru Ballav Ojha</option>
                                                    <!-- Add more options as needed -->
                                                </select>
                                                <br>

                                                <button type="submit" class="form-control"
                                                    style="width: 300px; color:white; background:green">Show Marksheets
                                                </button>
                                            </form>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!-- /.col-md-12 -->
                        </div>
                    </div>
                </div>
            </div>
            <!-- /.content-container -->
        </div>
        <!-- /.content-wrapper -->
    </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/main.js"></script>
    <script src="js/modernizr/modernizr.min.js"></script>
    <link href="nepali.datepicker.v4.0.1/css/nepali.datepicker.v4.0.1.min.css" rel="stylesheet" type="text/css" />
    <script src="nepali.datepicker.v4.0.1/js/nepali.datepicker.v4.0.1.min.js"></script>
    <script>
        window.onload = function () {
            var mainInput1 = document.getElementById("issuedate");
            mainInput1.nepaliDatePicker({
                ndpYear: true,
                ndpMonth: true,
                ndpYearCount: 100,
            })
        };

        function updateCheckedBy() {
            var classId = document.getElementById("class_id").value;

            // Use AJAX to fetch the class teacher based on the selected class
            $.ajax({
                type: "POST",
                url: "get_class_teacher.php", // Create a PHP file to handle this request
                data: {
                    class_id: classId
                },
                success: function (response) {
                    document.getElementById("checked_by").value = response;
                }
            });
        }
    </script>
</body>

</html>
