<?php
session_start();
if(isset($_SESSION["admin"])){
    
?>
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0" name="viewport">

  <title>KVS DIGITAL - E-VOTING SYSTEM</title>
  <meta content="" name="description">
  <meta content="" name="keywords">

  <!-- Favicons -->
  <link href="assets/img/kvs.png" rel="icon">
  <link href="assets/img/apple-touch-icon.png" rel="apple-touch-icon">

  <!-- Google Fonts -->
  <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Raleway:300,300i,400,400i,500,500i,600,600i,700,700i|Poppins:300,300i,400,400i,500,500i,600,600i,700,700i" rel="stylesheet">

  <!-- Vendor CSS Files -->
 	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <link href="assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
  <link href="assets/vendor/icofont/icofont.min.css" rel="stylesheet">
  <link href="assets/vendor/boxicons/css/boxicons.min.css" rel="stylesheet">
  <link href="assets/vendor/owl.carousel/assets/owl.carousel.min.css" rel="stylesheet">
  <link href="assets/vendor/venobox/venobox.css" rel="stylesheet">
  <link href="assets/vendor/aos/aos.css" rel="stylesheet">

  <!-- Template Main CSS File -->
  <link href="assets/css/style.css" rel="stylesheet">

  <!-- =======================================================
 
  ======================================================== -->
</head>

<body>

  <!-- ======= Header ======= -->
  <header id="header" class="fixed-top">
    <div class="container d-flex align-items-center">
      
      <div class="logo mr-auto">      
        
        <!-- Uncomment below if you prefer to use an image logo -->
        <a class="navbar-brand" href="#"></a>
          <h1 class="text-light"><a href="index.php">KVS DIGITAL E- VOTING</h1><h5>ADMIN page</h5></a>
        </a>
      </div>

      <nav class="nav-menu d-none d-lg-block">
        
        <ul>
          <li class="active"><a href="admin.php">Home</a></li>
          <li class="get-started"><a href="logout.php">logout</a></li>
        
        </ul>
      </nav><!-- .nav-menu -->

    </div>
  </header><!-- End Header -->
  </div>
<!--new user registration  -->
<?php
include 'dbconn.php';

$sql = "SELECT studentName, studentClass FROM tblstudent WHERE voteStatus = 0 ORDER BY studentName ASC";
$result = mysqli_query($conn, $sql);

$totalStudentQuery = mysqli_query($conn, "SELECT COUNT(*) AS total FROM tblstudent");
$totalStudentRow = $totalStudentQuery ? mysqli_fetch_assoc($totalStudentQuery) : array("total" => 0);
$rowcount = (int)$totalStudentRow["total"];


?>
</div>
<br><br<br><br><br<br><br><br<br><br><hr>
<div class="container">
<div id="printArea">
<table class="table table-striped">
<thead><h4>SENARAI PELAJAR YANG BELUM MENGUNDI</h4></thead>

<tbody>
  <tr>
    <th>No </th>
    <th>Nama</th>
    <th>Kelas</th>
  </tr>

</tbody>
<?php
$total = 0;
while($row = mysqli_fetch_assoc($result)) {
$total = $total + 1;
?>

<tr>
  <td><?php echo $total;?></td>
  <td><?php echo $row["studentName"];?></td>
  <td><?php echo $row["studentClass"];}?></td>
</tr>

</table>
<?php
echo "<br>JUMLAH PELAJAR BELUM MENGUNDI : " . $total;
$peratus = 0;
if ($rowcount > 0) {
  $peratus = (($rowcount - $total) / $rowcount) * 100;
}
echo "<br>PERATUS KELUAR MENGUNDI : " . round($peratus, 2) . "%";
?>
</div>
<button class="btn btn-info" onclick="printSpecificArea()">CETAK</button>
</div>
<!-- ======= Footer ======= -->
  <footer id="footer">
    <div class="container py-4">
      <div class="copyright">
        &copy; Copyright 2021<strong><span>kvsdigital.my </span></strong>. All Rights Reserved
      </div>
      <div class="credits">
        <!-- All the links in the footer should remain intact. -->
        <!-- You can delete the links only if you purchased the pro version. -->
        <!-- Licensing information: https://bootstrapmade.com/license/ -->
        <!-- Purchase the pro version with working PHP/AJAX contact form: https://bootstrapmade.com/free-bootstrap-app-landing-page-template/ -->
        Designed by Bootstrap</a>
      </div>
    </div>
  </footer><!-- End Footer -->

  <a href="#" class="back-to-top"><i class="icofont-simple-up"></i></a>
<?php
}else{
     header("Location: ../index.php?error= You are not logged in");
}    
?>
<!-- Vendor JS Files -->
  <script src="assets/vendor/jquery/jquery.min.js"></script>
  <script src="assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
  <script src="assets/vendor/jquery.easing/jquery.easing.min.js"></script>
  <script src="assets/vendor/php-email-form/validate.js"></script>
  <script src="assets/vendor/owl.carousel/owl.carousel.min.js"></script>
  <script src="assets/vendor/venobox/venobox.min.js"></script>
  <script src="assets/vendor/aos/aos.js"></script>

  <!-- Template Main JS File -->
  <script src="assets/js/main.js"></script>
  <script>
        function printSpecificArea() {
            var printContents = document.getElementById('printArea').innerHTML;
            var originalContents = document.body.innerHTML;

            document.body.innerHTML = printContents;

            window.print();

            document.body.innerHTML = originalContents;
            location.reload();  // Refresh the page to restore the original contents
        }
    </script>
</body>
</html>