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

<!-- This page unique styles -->
<style>
/*Core setup styles*/
.sideNav{
    height: 100%;
    /*width: 220px;*/
    position: fixed;
    z-index: 9;
}
.navbar{
    top: 0;
    position: fixed;
    z-index: 9999;
}
.the-links{
    padding-top: 10px;
}
/*.nav-links{
    height: 100%;
    overflow-y: auto;
}*/
.insider{
    margin-top: -30px;
    position: relative;
}
.card{
    height: auto;
}
.cat-pag{
    position: relative;
}
.cat-page-header{
    position: sticky;
    width: 100%;
    height: 50px;
    background:#F7F9FB; 
    top: 60px;
    right: 60px;
    z-index: 1;
}

.card-header h5{
    font-size: 14px;
}
.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;
}
@media(max-width: 992px){
    .insider{
        margin-top: -30px;
        padding-left: 10px;
        padding-right: 10px;
    } 
    .negative h5{
        font-size: 15px;
    } 
    .negative p{
        font-size: 13px;
    }
    .negative i{
        font-size: 18px;
    }
    .text-sm{
        font-size: 12px;
    }      
}
</style>
<?php

// Print all Results
$sn = 0;
$provStatus = 'Approved';
$allstd = "SELECT * FROM result_approval WHERE status = ? ";
$stmt = $pdo->prepare($allstd);
$stmt->execute([$provStatus]);
$valid = $stmt->rowCount();
if ($valid < 1) {
    $table = "display:none";
    $negat = "display:flex";
}else{
    $table = "display:block";
    $negat = "display:none";
}


// Get the status for result approval
// $approRest = "SELECT status FROM result_approval 
//             WHERE class = ? AND term = ? AND session = ?";
// $queryRest = $pdo->prepare($approRest);
// $queryRest->execute([$className, $current_term, $current_session]);
// $countProval = $queryRest->rowCount();
// $rowproval = $queryRest->fetch(PDO::FETCH_ASSOC);
// $provalStatus = $rowproval['status'];

// if ($countProval < 1) {
//     $ca_color = 'warning-text';
//     $sta_text = 'Not Submitted';
// }else
// if ($provalStatus =='Pending') {
//     $ca_color = 'warning-text';
//     $sta_text = 'Pending';
// }else{
//     $ca_color = 'success-text';
//     $sta_text = 'Approved';
// }

?>

<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">
            </div>
            <div class="card mt-3">
                <div class="card-header card-header text-left d-flex justify-content-between align-items-center">
                    <h5>Approved Results</h5>
                    <span class="badge bg-primary me-2">Total: <?= $valid ?></span>
                </div>
                <div class="card-body">
                    <!-- If Empty -->
                    <div class="negative" style="<?=$negat?>">
                        <i class="fa fa-hourglass-half"></i>
                          <h5>No Approved Results</h5>
                          <p class="text-muted text-center">
                            This means no Vice Principal or Principal has approved any results so far. <br>
                            Kindly check back later.
                          </p>
                    </div>
                    <form action="" method="POST" id="mainForm" style="<?=$table?>">        
                        <div class="table-responsive">
                            <table id="example" class="display table table-striped table-bordered">
                                <thead>
                                    <tr>
                                        <th></th> <!-- This will be used for the toggle (+) -->
                                        <th data-priority="4" class="text-sm">S/N</th>
                                        <th data-priority="1" class="text-sm">Class</th>
                                        <th data-priority="2" class="text-sm">Term</th>
                                        <th data-priority="3" class="text-sm">Session</th>
                                        <th data-priority="1" class="text-sm">Submitted by</th>
                                        <!-- <th>Total</th> -->
                                        <th data-priority="1">Action</th>
                                    </tr>
                                </thead>
                                <tbody>
                                <!-- Display all student in this class -->
                                <?php
                                while ($stdRow = $stmt->fetch(PDO::FETCH_ASSOC)) {
                                    $class      = $stdRow['class'];
                                    $term       = $stdRow['term'];
                                    $session    = $stdRow['session'];
                                    $modified   = $stdRow['modified'];
                                    $author     = $stdRow['submitted_by'];
                                    $sn = $sn + 1;
                                    $package = $class.'*'.$term.'*'.$session;
                                    // Get the class teacher who submitted these reports

                                ?>
                                <tr>
                                    <td></td>
                                    <td class="text-sm"><?= $sn ?></td>
                                    <td class="text-sm">
                                        <?=$class?>
                                    </td>
                                    <td class="text-sm">
                                        <?=$term?>
                                    </td>
                                    <td class="text-sm">
                                        <?=$session?>
                                    </td>
                                    <td class="text-sm">
                                        <?=$author?>
                                    </td>
                                    <td>
                                        <a href="approved_review.php?rsltVal=<?= $package?>" class="btn btn-sm btn-primary">
                                            Review <i class="fa fa-eye"></i>
                                        </a>
                                    </td>
                                <?php } ?>
                                </tbody>
                            </table>
                        </div>
                        
                    </form>
                </div>
            </div>
        </div>
   
    </div>
</div>
<?php

?>


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

<!-- DataTables & jQuery -->
<link rel="stylesheet" href="https://cdn.datatables.net/1.11.3/css/jquery.dataTables.min.css">
<link rel="stylesheet" href="https://cdn.datatables.net/responsive/2.2.9/css/responsive.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 src="https://cdn.datatables.net/responsive/2.2.9/js/dataTables.responsive.min.js"></script>
<script>
    $('#example').DataTable({
      responsive: {
        details: {
          type: 'column',
          target: 0 // (+) icon for toggling hidden info
        }
      },

      columnDefs: [
        { className: 'control', orderable: false, targets: 0 }, // (+) toggle
        { orderable: false, targets: [1, -1] }, // disable sorting on checkbox & action
        { targets: 1, responsivePriority: 1 }, // Checkbox always visible
        { targets: 5, responsivePriority: 1 }, // Names always visible
        { targets: 6, responsivePriority: 1 }, // Roles always visible
        
        { targets: -1, responsivePriority: 2 }, // Action visible after roles
      ],
      paging: true,
      searching: true,
      info: true
    });

    language: {
      emptyTable: "No Pending Yet."
    }

</script>
<script type="">
    responsive: true,
    dom: '<"top"lf>rt<"bottom"ip><"clear">',
</script>




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

