<?php
include('session_validator.php');
?>
<!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="js/modernizr/modernizr.min.js"></script>
        <link rel="stylesheet" href="css/print-style.css" type="text/css" media="print" />

    </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>
                                
                                <!-- /.col-md-6 text-right -->
                            </div>
                            <!-- /.row -->
                            <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>
                            <!-- /.row -->
                        </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">


    <form action="generate_blank_mark_slip.php" method="get"> <!--generate_blank_mark_slip -->
        <div class="form-row">
                <div class="form-group col-md-3">
                    <label for="exam_id1">Select Exam:</label>
                    <select id="exam_id1" name="exam_id1" class="form-control" required>
                        <option value="">Select Exam</option>
                        <?php
                        $queryexam = "SELECT id, exm_year, exam_type FROM examination_type";
                        $resultexam = $conn->query($queryexam);

                        while ($row = $resultexam->fetch_assoc()) {
                            echo "<option value='" . $row['id'] . "'>" . $row['exm_year'] . " - " . $row['exam_type'] . " </option>";
                        }
                        ?>
                    </select>
                </div>

                <div class="form-group col-md-3">
                    <label for="class_id">Select Class:</label>
                    <select id="class_id" name="class_id" class="form-control" required>
                        <option value="">Select Class</option>
                        <?php
                        $query = "SELECT class_id, class_name, section FROM classes";
                        $result = $conn->query($query);

                        while ($row = $result->fetch_assoc()) {
                            echo "<option value='" . $row['class_id'] . "'>" . $row['class_name'] . " - " . $row['section'] . "</option>";
                        }
                        ?>
                    </select>
                </div>

                <div class="form-group col-md-4">
                    <label for="subject_id">Select Subject:</label>
                    <select id="subject_id" name="subject_id" class="form-control" required>
                        <option value="">Select Subject</option>
                    </select>
                </div>
            </div>
    
   <br>
    <div>
        <button  class="btn btn-primary" type="submit">Generate Blank Mark Slip</button>
    </div>
     </form>

</div>
                                            </div>
                                        </div>
                                    </div>
                                    <!-- /.col-md-12 -->
                                </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/select2/select2.min.js"></script>
        <script src="js/main.js"></script>

              <script>
            $(document).ready(function () {
                $('#subject_id').change(function () {
                    var subjectId = $(this).val();

                    // AJAX request to fetch internal full marks for the selected subject
                    $.ajax({
                        type: 'POST',
                        url: 'get_theory_full_marks.php', // PHP script to handle the request and fetch internal full marks
                        data: { subjectId: subjectId },
                        success: function (response) {
                            if (response === "N/A") {
                                $('#theory-full-marks').text("Not available");
                            } else {
                                $('#theory-full-marks').text(response);
                            }
                        }
                    });
                });
            });
        </script>

        <script>
            $(document).ready(function () {
              
              

                // Event handler for class selection
                $('#class_id').change(function () {
                    var classId = $(this).val();
                    var subjectId = $('#subject_id').val();

                    // Fetch and populate students based on class and subject
                    fetchStudents(classId, subjectId);
                });

                // Event handler for subject selection
                $('#subject_id').change(function () {
                    var subjectId = $(this).val();
                    var classId = $('#class_id').val();

                    // Fetch and populate students based on class and subject
                    fetchStudents(classId, subjectId);
                });
            });
        </script>
        <script>
            document.getElementById("class_id").addEventListener("change", function () {
                var classId = this.value;
                var subjectDropdown = document.getElementById("subject_id");

                subjectDropdown.innerHTML = "<option value=''>Select Subject</option>";

                fetch(`getSubjects.php?class_id=${classId}`)
                    .then(response => response.json())
                    .then(data => {
                        data.forEach(subject => {
                            var option = document.createElement("option");
                            option.value = subject.id;
                            option.textContent = subject.subject_name;
                            subjectDropdown.appendChild(option);
                        });
                    })
                    .catch(error => {
                        console.error('Error:', error);
                    });
            });
        </script>

    </body>
</html>