<?php
session_start();
if(isset($_SESSION["name"])){
?>
<!DOCTYPE html>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 <title>KVS DIGITAL - E-VOTING SYSTEM</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="css/bootstrap.min.css"/>
 <!-- Favicons -->
  <link href="assets/img/kvs.png" rel="icon">
  <link href="assets/img/apple-touch-icon.png" rel="apple-touch-icon">
  
    <!-- Vendor CSS Files -->
  <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">
  
<style>
.thumbnail
{
      width: 164px;
      height: 164px;
      overflow: hidden;
       margin: auto;
}
.thumbnail img {
    width: 164px;
    height: 100%;
    border: 2px solid #2894CF;
    padding: 5px;
    object-fit: cover;
}
  /* Base for label styling */
[type="checkbox"]:not(:checked),
[type="checkbox"]:checked {
  position: absolute;
  left: -9999px;
}
[type="checkbox"]:not(:checked) + label,
[type="checkbox"]:checked + label {
  position: relative;
  padding-left: 25px;
  cursor: pointer;
}

/* checkbox aspect */
[type="checkbox"]:not(:checked) + label:before,
[type="checkbox"]:checked + label:before {
  content: '';
  position: absolute;
  left:0; top: 2px;
  width: 27px; height: 27px;
  border: 1px solid #aaa;
  background: #f8f8f8;
  border-radius: 3px;
  box-shadow: inset 0 1px 3px rgba(0,0,0,.3)
}
/* checked mark aspect */
[type="checkbox"]:not(:checked) + label:after,
[type="checkbox"]:checked + label:after {
  content: 'X';
  position: absolute;
  top: 3px; left: 4px;
  font-size: 28px;
  line-height: 0.8;
  color: #09ad7e;
  transition: all .2s;
}
/* checked mark aspect changes */
[type="checkbox"]:not(:checked) + label:after {
  opacity: 0;
  transform: scale(0);
}
[type="checkbox"]:checked + label:after {
  opacity: 1;
  transform: scale(1);
}
/* disabled checkbox */
[type="checkbox"]:disabled:not(:checked) + label:before,
[type="checkbox"]:disabled:checked + label:before {
  box-shadow: none;
  border-color: #bbb;
  background-color: #ddd;
}
[type="checkbox"]:disabled:checked + label:after {
  color: #999;
}
[type="checkbox"]:disabled + label {
  color: #aaa;
}
/* accessibility */
[type="checkbox"]:checked:focus + label:before,
[type="checkbox"]:not(:checked):focus + label:before {
  border: 1px dotted blue;
}

.submitbtn, .gambar{
    margin : 0 auto;
    border-radius : 0;
}

.avatar {
      
      border-radius: 50%;
      
    }
</style>

  </head>
<body>
<div class="container">
     <!-- ======= 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 -->
         
          <h1 class="text-light"><a href="index.html">KVSDigital E- VOTING</a></h1>
          <h4 class="fst-italic">PILIHANRAYA MAJLIS PERWAKILAN PELAJAR KOLEJ VOKASIONAL SEPANG <? echo date("Y");?></h4><br>
        </a>
      </div>

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

    </div>
  </header><!-- End Header -->
  <section class="features contact">
   <br><hr> <br><hr>
 <div class="section-title">
 <h3>SELAMAT DATANG <?php echo $_SESSION["name"];?></h3>
 <h4>PASTIKAN ANDA MENGUNDI 15 CALON</h4></div>
   <hr>
 </section>

<div class = "row">
    <form name="checkbox" action="undiantest.php" method="post" onsubmit="return checkboxes()">
  <?php   

include 'dbconn.php';

//CHECK STUDENT STATUS

 
//SELECT ALL CANDIDATE 
 $sql = "SELECT * FROM tblcandidate ORDER BY candCourse";
 $result = mysqli_query($conn, $sql);

  if ($result) {
       
    while($row = mysqli_fetch_assoc($result)) {
?>

              <div class="col-lg-4 col-md-4">
                  <br>
                       <div class="thumbnail border-0">
                         <img src="<?php echo $row[image];?>" class="avatar"/>
                         <br><br><br>
                           </div> 
                            <div class="d-flex justify-content-center"><h3><?php echo $row[candN];?></h3></div>
                             <div class="d-flex justify-content-center"><h4><?php echo $row[candCourse];?></h4></div>
                             <div class="d-flex justify-content-center" style="font-size:12px">
                              <?php echo $row[motto];?>
                            </div>
                             <div class="d-flex justify-content-center">
                          <input type="checkbox" id="test<?php echo $row[candID];?>" name="check[]" value="<?php echo $row[candID];?>"  onclick="chkChecks('check[]')">
                                 
                                <label for="test<?php echo $row[candID];?>"></label>
                             </div>
                           
                    <br><br><br>              
              </div>
 <?php

}
}
?> 
</div>
<br>
<div class="row">

    <div class="submitbtn"><button type="submit" name="submit1" class="btn btn-primary"><h2>Hantar Undian Anda</h2></button></div>
    
</div>    
</form>
<br>
<?php
}else{
     header("Location: ../index.php?error= You are not logged in");
}
?>

<script type="text/javascript">

function chkChecks(nme) {
var isChecked = 0;
var c = document.getElementsByName(nme);
for (var i = 0; i < c.length; i++) {
if (c[i].checked) {
isChecked ++;

if (isChecked >15) {  // maximum of seven checkboxes - change as required
alert ('ANDA HANYA BOLEH MENGUNDI TIDAK LEBIH DARI 15 CALON');

c[i].checked = false;
return false;
}
}
}
}

function countCheck(nme) {
 var isChecked = 0;
var c = document.getElementsByName(nme);
for (var i = 0; i < c.length; i++) {
if (c[i].checked) {
isChecked ++;
}

alert ('anda pasti');
return false;

}
}

function checkboxes()
   {
    var inputElems = document.getElementsByTagName("input"),
     count = 0;

     for (var i=0; i<inputElems.length; i++) {
        if (inputElems[i].type == "checkbox" && inputElems[i].checked == true){
           count++;

        }
     }
     if(count!=15){
      alert('SILA UNDI 15 CALON');
      return false;
      }
      
      
  }

</script>

</div>


   <!-- Vendor JS Files -->
 
  <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>
 <!-- ======= 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
        credit to : afiq1DKA
      </div>
    </div>
  </footer><!-- End Footer -->

  <a href="#" class="back-to-top"><i class="icofont-simple-up"></i></a>
</body>
</html>
