<?php session_start();?>
<?php include'includes/header.php'; ?>
<?php include'includes/sidebar.php';?>
<?php include'includes/functions.php';?>
<?php include'includes/navbar.php'; ?>

<!-- Handle Add Slider -->
<style>
    td span{
        padding: 10px; border-radius: 6px;
        font-size: 13px;
    }
    .card-header h3{
        font-size: 18px;
        font-weight: bold;
        font-family: sans-serif;
        color: #3C763D;
    }
    .card-header h5{
        font-size: 14px;
        /*font-weight: bold;*/
        font-family: sans-serif;

    }
    .cat-page-header h5{
        font-family: sans-serif;
        font-size: 18px;
        font-weight: bold;
    }
    .success_stutus{
        background: #E8FCEF; color: #4ECA74;
    }
    .error_status{
        background: #F8D7DA; color: #90151C;
    }
    .cat-page-header .warning-text{
        color: #90151C;
        font-weight: normal;
        /*font-style: italic;*/
    }
    .cat-page-header .success-text{
        color: #4ECA74;
        font-weight: normal;
        /*font-style: italic;*/
    }
    .negative{
        width: 100%;
        height: auto;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 10px;
        margin-top: 20px;
    }
    .negative i{
        font-size: 70px;
        color: #FE9C13;

    }
    .negative h5{
        font-size: 20px;
        color: #FE9C13;
        text-align: center;
        font-weight: bold;
        font-family: sans-serif; 
    }
    .negative a{
        padding: 10px;
        color: #fff;
        text-decoration: none;
        text-align: center;
        font-size: 17px;
        border-radius: 5px;
        /*font-weight: bold;*/
    }
    .negative a i{
        font-size: 17px;
        color: #fff;
    }
</style>
<?php

if (isset($_GET['class'])) {
    $getVal = $_GET['class'];
    $unvel = explode('*', $getVal);

    $class = $unvel[0];
    $subject = $unvel[1];
}
// Get your class student
$clastd = "SELECT class FROM class_teacher WHERE staffId = ?";
$thepdo = $pdo->prepare($clastd);
$thepdo->execute([$staffId]);
$filter = $thepdo->rowCount();
if ($filter == FALSE) {
    header('Location:index.php');
}else{
    $classRow = $thepdo->fetch(PDO::FETCH_ASSOC);
    $myClass = $classRow['class'];
}

// Validate to know if the test and exam is out for the current term and session
// Check for Test
$testExam = "SELECT test_score FROM results WHERE class = ? AND term = ? AND session = ?";
$stmt = $pdo->prepare($testExam);
$stmt->execute([$myClass, $current_term, $current_session]);
$validate = $stmt->rowCount();
if ($validate > 0) {
    $rstRow = $stmt->fetch(PDO::FETCH_ASSOC);
    $test_status = "Recorded";
}else{
    $test_status = "pending";
}

// Check for Exam
$testExam = "SELECT exam_score FROM results WHERE class = ? AND term = ? AND session = ?";
$stmt = $pdo->prepare($testExam);
$stmt->execute([$myClass, $current_term, $current_session]);
$validate = $stmt->rowCount();
if ($validate > 0) {
    $rstRow = $stmt->fetch(PDO::FETCH_ASSOC);
    $exam_status = "Recorded";
}else{
    $exam_status = "pending";
}


if ($test_status =='pending') {
    $ca_color = 'warning-text';
}else{
    $ca_color = 'success-text';
}

if ($exam_status =='pending') {
    $exam_color = 'warning-text';
}else{
    $exam_color = 'success-text';
}



?>

<div id="notification-containers" class="notification-containers"></div>
<div class="insider">
    <div class="container">
        <div class="cat-pag">
            <div class="cat-page-header d-flex justify-content-between align-items-center">
                <h5>CA Test: <span class="<?= $ca_color?>"><?= $test_status?></span> | 
                    Exam: <span class="<?= $exam_color?>"><?= $exam_status?></span>
                </h5>
                <div>
                    <a href="test_score.php?class=<?=$class.'*'.$subject?>" class="btn info text-white">Add New Student <i class="fa fa-user-plus"></i></a>

                    <a href="exam_score.php?class=<?=$class.'*'.$subject?>" class="btn invoice text-white">Remove <i class="fa fa-user-minus"></i></a>
                </div>
            </div>

            <div class="card mt-3">
                <div class="card-header text-center">
                    <h3>OBACCO COLLEGE</h3>
                    <h5 class="text-success"><?= $myClass?> | 
                        <?= $current_term?>Term <?= $current_session?> Academic Session
                    </h5>

                </div>
                <div class="card-body">
                    <form action="" method="POST" id="mainForm">                       

                        <div class="table-responsive">
                            <table id="example" class="display table table-striped table-bordered">
                                <thead>
                                    <tr>
                                        <th><input type="checkbox" id="SelectAllBoxes"></th>
                                        <th>ID</th>
                                        <th>Surname</th>
                                        <th>Othernames</th>
                                        <th>Image</th>
                                        <th>Gender</th>
                                        <!-- <th>Total</th> -->
                                        <th>Action</th>
                                    </tr>
                                </thead>
                                <tbody>
                                <!-- Display all student in this class -->
                                <?php
                                $sn = 0;
                                $allstd = "SELECT * FROM student WHERE class = ? 
                                        AND term = ? AND session = ?";
                                $stmt = $pdo->prepare($allstd);
                                $stmt->execute([$myClass, $current_term, $current_session]);
                                while ($stdRow = $stmt->fetch(PDO::FETCH_ASSOC)) {
                                    $stdId      = $stdRow['studId'];
                                    $surName    = $stdRow['surname'];
                                    $otherNames  = $stdRow['otherNames'];
                                    $gender     = $stdRow['gender'];
                                    $sn = $sn + 1;
                                ?>
                                    <tr>
                                        <td>
                                            <input type="checkbox" name="checkBoxArray[]" 
                                            value="<?= $prodId ?>" class='checkBoxes'>
                                        </td>
                                        <td><?= $sn ?></td>
                                        <td>
                                            <?=$surName?>
                                        </td>
                                        <td>
                                            <?=$otherNames?>
                                        </td>
                                        <td>
                                            Image
                                        </td>
                                        <td><?=$gender?></td>
                                        <td>
                                            <a href="report.php?val=<?= $stdId?>" class="btn btn-sm btn-primary">
                                                View <i class="fa fa-eye"></i>
                                            </a>
                                        </td>
                                    </tr>
                                   <?php } ?> 
                                </tbody>
                            </table>
                        </div>
                        
                    </form>
                </div>
            </div>
        </div>
   
    </div>
</div>



<?php include 'includes/footer.php'; ?>

<!-- DataTables & jQuery -->
<link rel="stylesheet" href="https://cdn.datatables.net/1.11.3/css/jquery.dataTables.min.css">
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.min.js"></script>

<script>
    $(document).ready(function () {
        $('#example').DataTable();
        $('#SelectAllBoxes').click(function () {
            $('.checkBoxes').prop('checked', this.checked);
        });
    });

    function openModal(id) {
        document.getElementById(id).style.display = "block";
    }

    function closeModal(id) {
        document.getElementById(id).style.display = "none";
    }

    function handleDelete() {
        const checked = document.querySelectorAll("input[name='checkBoxArray[]']:checked");
        if (checked.length === 0) {
            alert("No products selected!");
            return;
        }
        openModal('modal-delete');
    }
   
</script>


<!-- Modal Styling -->
<style>
    .modal {
        display: none;
        position: fixed;
        z-index: 99999;
        left: 0; top: 0;
        width: 100%; height: 100%;
        overflow: auto;
        background-color: rgba(0,0,0,0.5);

    }

    .modal-content {
        background-color: #fff;
        margin: auto;
        padding: 20px;
        border-radius: 8px;
        width: 80%;
        max-width: 500px;
        animation: fadeIn 0.3s;
    }

    .modal-header, .modal-footer {
        font-weight: bold;
    }

    @keyframes fadeIn {
        from { opacity: 0; transform: translateY(-20px); }
        to { opacity: 1; transform: translateY(0); }
    }

    .label-wraps{
        width: 100%;
        padding-left: 30px;
        padding-right: 30px;
        display: flex;
        justify-content: space-between;
      
    }
    .input-wraps{
        width: 100%;
        display: flex;
        gap:8px;
        padding: 5px;
    }
    .price-box{
        width: 50%;
        height: 55px;
        /*border-bottom: 2px solid #ddd;*/
        border:2px solid #ddd;
        padding: 15px;
        border-radius: 10px;
    }
    .price-box span{
        font-size: 18px;
        color: #666;
        /*font-weight: bold;*/
    }
    .price-box input{
        width: 85%;
        
        border:none;
        outline: none;
        font-size: 16px;
        color: 888;
       /* height: 20px;*/
    }
    .quant-box{
        width: 50%;
        height: 55px;
        /*border-bottom: 2px solid #ddd;*/
        border:2px solid #ddd;
        padding: 15px;
        border-radius: 10px;
    }
    .quant-box input{
        width: 100%;
        border:none;
        outline: none;
        font-size: 16px;
        color: 888;
    }
</style>

<!-- Notifications alert -->
<?php include'includes/notification-alert-js.php';?>

