<?php
session_start();

$ic = $_SESSION["ic"];

if(isset($_SESSION["name"])){
?>
<!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">
  <script type = "text/javascript" >
  history.pushState(null, null, 'index.html');
 window.addEventListener('popstate', function(event) {
  history.pushState(null, null, 'index.html');
    });

</script>
</head>
<body>

<!-- ======= Header ======= -->
  <header id="header" class="fixed-top  header-transparent ">
    <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.html">KVS DIGITAL E- VOTING</a></h1>
        </a>
      </div>

      <nav class="nav-menu d-none d-lg-block">
        
        <ul>
          <li class="active"><a href="index.php">Home</a></li>
          <li><a href="#features">Tatacara</a></li>
          <li><a href="#features">JOM UNDI</a></li>
          <li><a href="profile.php">Profil Calon</a></li>
          <li><a href="#" data-target="#loginModal" data-toggle="modal">ADMIN</a></li>
         <li class="get-started"><a href="logout.php">LOGOUT</a></li>
         
        </ul>
      </nav><!-- .nav-menu -->
 
    </div>
  </header><!-- End Header -->
<br><br><br><hr>
 <div class="container">
<?php
include 'dbconn.php';

if (isset($_POST['submit1'])) {
    

//<!-- <form name="undisijil" action="undian3a.php" method="post"> -->

// Loop to store and display values of individual checked checkbox.
$selected = $_POST["check"];
$N = count($selected);
echo "<h4>Calon MPP Pilihan anda</h4><br><br>";

for($i=0; $i < $N; $i++)
{
//echo($selected[$i] . " ");
$id = $selected[$i];
 $votecast = "select * from tblcandidate WHERE candID='$id'";
$cast = mysqli_query($conn,$votecast);
$row = mysqli_fetch_assoc($cast);
echo $row[candName];

echo "<br>"; 
$v=$row[voteCount];
        $v = $v + 1;
        $sq1 = "UPDATE tblcandidate SET voteCount='$v' WHERE candID='$id'";
        $qq=mysqli_query($conn, $sq1);

 }   
$sq = "UPDATE tblstudent SET voteStatus='1' WHERE studentIC='$ic'";

$update = mysqli_query($conn,$sq);
}
echo "<br><br><h5>Terima kasih kerana menggunakan kvsdigital Voting System</h5><br><br>";
session_destroy();
}else{
     header("Location: ../index.php?error= You are not logged in");
     //echo "yoouu";
} 
?>

</div>

<br><br><br><hr>
  <!-- ======= 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">
        Designed by Bootstrap 
      </div>
    </div>
  </footer><!-- End Footer -->

</body>
</html>
