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


// SQL query to fetch leftover/missing marks
$sql = "
    SELECT 
        lm.id,
        lm.class_sec,
        cls.class_name,
        cls.section,
        lm.std_symbolnumber,
        lm.std_id,
        lm.student_name,
        sub.subject_name,
        sub.subject_code,
        sub.theory_full_marks,
        lm.marks,
        lm.entered_by,
        lm.date
    FROM 
        leftover_marks lm
    JOIN 
        classes cls ON lm.class_sec = cls.Class_id
    JOIN 
        subjects sub ON lm.subject_id = sub.id
   ORDER BY class_sec, student_name";

$stmt = $conn->prepare($sql);
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);

?>
<!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 Classes</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" type="text/css" href="js/DataTables/datatables.min.css" />
    <link rel="stylesheet" href="css/main.css" media="screen">
</head>

<body class="top-navbar-fixed">
    <div class="main-wrapper">
        <?php include('includes/topbar.php'); ?>
        <div class="content-wrapper">
            <div class="content-container">
                <?php include('includes/leftbar.php'); ?>
                <div class="main-page">
                    <div class="container-fluid">
                        <div class="row page-title-div">
                            <div class="col-md-6">
                                <h2 class="title">Missing Marks Report</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>Reports</li>
                                    <li class="">Missing Marks Report</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>Missing Marks Report</h5>
                                        </div>
                                    </div>
                                    <div class="panel-body">
                                        <?php
                                        if (count($results) > 0) {
                                            echo "<table class='table table-bordered'>";
                                            echo "<tr>
                                                    <th>ID</th>
                                                    <th>Class</th>
                                                    <th>Section</th>
                                                    <th>Student Symbol No.</th>
                                                    <th>Student Name</th>
                                                    <th>Subject Code</th>
                                                    <th>Subject Name</th>
                                                    <th>Full Marks</th>
                                                    <th>Marks Obtained</th>
                                                    <th>Entered By</th>
                                                    <th>Date</th>
                                                  </tr>";
                                            foreach ($results as $row) {
                                                echo "<tr>
                                                        <td>" . htmlspecialchars($row['id']) . "</td>
                                                        <td>" . htmlspecialchars($row['class_name']) . "</td>
                                                        <td>" . htmlspecialchars($row['section']) . "</td>
                                                        <td>" . htmlspecialchars($row['std_symbolnumber']) . "</td>
                                                        <td>" . htmlspecialchars($row['student_name']) . "</td>
                                                        <td>" . htmlspecialchars($row['subject_code']) . "</td>
                                                        <td>" . htmlspecialchars($row['subject_name']) . "</td>
                                                        <td>" . htmlspecialchars($row['theory_full_marks']) . "</td>
                                                        <td>" . htmlspecialchars($row['marks']) . "</td>
                                                        <td>" . htmlspecialchars($row['entered_by']) . "</td>
                                                        <td>" . htmlspecialchars($row['date']) . "</td>
                                                      </tr>";
                                            }
                                            echo "</table>";
                                        } else {
                                            echo "No records found.";
                                        }
                                        ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <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/DataTables/datatables.min.js"></script>
        <script src="js/main.js"></script>
    </body>
</html>
