<?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>
    </head>
    

    <script>
$(document).ready(function() {
    $('#subjectsTable').DataTable({
        "paging": true,  // Enable pagination
        "lengthMenu": [20, 40, 50, 75, 100],  // Customize page length options
        "searching": true,  // Enable search
        "ordering": true,  // Enable sorting
        "info": true,  // Show information (e.g., "Showing 1 to 10 of 100 entries")
    });
});

</script>
    <script>
$(document).ready(function() {
    $('#subjectsTable1').DataTable({
        "paging": true,  // Enable pagination
        "lengthMenu": [20, 40, 50, 75, 100],  // Customize page length options
        "searching": true,  // Enable search
        "ordering": true,  // Enable sorting
        "info": true,  // Show information (e.g., "Showing 1 to 10 of 100 entries")
    });
});

</script>

    <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">



<div class="main" style="margin-left:10px" >
        <?php
        include("includes/db.php");

        // Fetch distinct class-sections and their corresponding subjects
        $classSectionQuery = "SELECT DISTINCT classes.class_name, classes.section, subjects.subject_code, subjects.subject_name, COUNT(marks.marks) AS num_students
                              FROM classes
                              INNER JOIN marks ON classes.class_id = marks.class_id
                              INNER JOIN subjects ON marks.subject_id = subjects.id
                              WHERE marks.marks > 0
                              GROUP BY classes.class_name, classes.section, subjects.subject_code, subjects.subject_name";
        $classSectionResult = $conn->query($classSectionQuery);

        if ($classSectionResult->num_rows > 0) {
            $currentClass = "";
            $currentSection = "";
?>
        
    <h2>Marks Submitted Report</h2>
   <table  id="subjectsTable" class="display"> 
  <?php          echo "
  <thead> <tr><th>Class</th><th>Subject Code</th><th>Subject Name</th><th>Number of Students with > 0 Marks</th></tr> </thead>";

            while ($row = $classSectionResult->fetch_assoc()) {
                $className = $row['class_name'];
                $section = $row['section'];
                $subjectCode = $row['subject_code'];
                $subjectName = $row['subject_name'];
                $numStudents = $row['num_students'];

                echo "<tr>";
                echo "<td>$className  -  $section</td>";
                               echo "<td>$subjectCode</td>";
                echo "<td>$subjectName</td>";
                echo "<td>$numStudents</td>";
                echo "</tr>";
            }
?>
    
</table>
<?php
        } else {
            echo "<p>No data found.</p>";
        }
        ?>
   
   </body> </div>

<body>

<div class="main" style="margin-left:10px" >

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

        // Fetch data for marks submit report
        $marksReportQuery = "SELECT marks.student_id, students.name as student_name, subjects.subject_name, marks.marks, classes.class_name ,classes.section
                             FROM marks
                             INNER JOIN classes ON marks.class_id = classes.Class_id 
                             INNER JOIN students ON marks.student_id = students.student_id
                             INNER JOIN subjects ON marks.subject_id = subjects.id
                             WHERE (marks.subject_id, marks.class_id, marks.marks) 
                             IN (SELECT marks.subject_id, marks.class_id, MAX(marks.marks) 
                             FROM marks 
                             GROUP BY marks.subject_id, marks.class_id)";

        $marksReportResult = $conn->query($marksReportQuery);

        if ($marksReportResult->num_rows > 0) {
            echo "<h2>Subjectwise Highest Marks Report</h2>";
            echo "<table id='subjectsTable1' class='display'>";
            echo "<tr>
            <th> Class </th>
            <th>Student Name</th>
            <th>Subject Name</th>
            <th>Marks Obtained</th>
            </tr>";

            while ($row = $marksReportResult->fetch_assoc()) {
                $studentName = $row['student_name'];
                $subjectName = $row['subject_name'];
                $marksObtained = $row['marks'];
                $class1 = $row['class_name'].'-'. $row['section'];

                echo "<tr>";
                echo "<td> $class1</td>";
                echo "<td>$studentName</td>";
                echo "<td>$subjectName</td>";
                echo "<td>$marksObtained</td>";
                echo "</tr>";
            }

            echo "</table>";
        } else {
            echo "<p>No data found in marks submit report.</p>";
        }
        ?>
    </section>
           <!-- ========== COMMON JS FILES ========== -->
        <script src="js/jquery/jquery-2.2.4.min.js"></script>
        <script src="js/jquery-ui/jquery-ui.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>

        <!-- ========== PAGE JS FILES ========== -->
        <script src="js/prism/prism.js"></script>
        <script src="js/waypoint/waypoints.min.js"></script>
        <script src="js/counterUp/jquery.counterup.min.js"></script>
        <script src="js/amcharts/amcharts.js"></script>
        <script src="js/amcharts/serial.js"></script>
        <script src="js/amcharts/plugins/export/export.min.js"></script>
        <link rel="stylesheet" href="js/amcharts/plugins/export/export.css" type="text/css" media="all" />
        <script src="js/amcharts/themes/light.js"></script>
        <script src="js/toastr/toastr.min.js"></script>
        <script src="js/icheck/icheck.min.js"></script>

        <!-- ========== THEME JS ========== -->
        <script src="js/main.js"></script>
        <script src="js/production-chart.js"></script>
        <script src="js/traffic-chart.js"></script>
        <script src="js/task-list.js"></script>
        <script>
            $(function(){

                // Counter for dashboard stats
                $('.counter').counterUp({
                    delay: 10,
                    time: 1000
                });

                // Welcome notification
                toastr.options = {
                  "closeButton": true,
                  "debug": false,
                  "newestOnTop": false,
                  "progressBar": false,
                  "positionClass": "toast-top-right",
                  "preventDuplicates": false,
                  "onclick": null,
                  "showDuration": "300",
                  "hideDuration": "1000",
                  "timeOut": "5000",
                  "extendedTimeOut": "1000",
                  "showEasing": "swing",
                  "hideEasing": "linear",
                  "showMethod": "fadeIn",
                  "hideMethod": "fadeOut"
                }
                toastr["success"]( "Welcome to student Result Management System!");

            });
        </script>
</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>

    </body>
</html>

