<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <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"/>
  <title>KVS DIGITAL - E-Vote</title>
<style>
  /* 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;
}
</style>

  </head>
<body>
<div class="container">
    <nav class="navbar navbar-default">

    <h1>KVS Digital - VOTING SYSTEM</h1>
    <ul class="nav navbar-nav">
      <li class="active"><a href="index.html">Home</a></li>
       <li><a href="login.html">Undian</a></li>
      <li><a href="admin.html">Admin</a></li>
    </ul>

  </nav>

  <?php   

    include 'dbconn.php';

//CHECK STUDENT STATUS

$studentIC=$_POST['studentIC'];

//check FOR IF STUDENT EXIST BASED ON IC

  $student = "SELECT * FROM tblstudent WHERE studentIC = '$studentIC'";
  $result1= mysqli_query($conn,$student);
 

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

  if (!$result) {
    echo "Error".mysqli_error($conn);
}

$count1=mysqli_num_rows($result1);

$row1= mysqli_fetch_assoc($result1);
$name = $row1[studentName];

if($count1 == 1 )
{

 	if($row1[voteStatus] == 1)//mAKE SURE STUDENT VOTE STATUS
 	{
 	    header( 'Location: undian3a.php?ic='.$studentIC) ;
 	}
 	elseif($row1[voteStatus]==0)
 	{


        echo "<h3>PILIHANRAYA MAJLIS PERWAKILAN PELAJAR KOLEJ VOKASIONAL SEPANG 2022</h3><br>";
        echo "<h4>SELAMAT DATANG ".$name." <h4><br>";
        echo "<h4>PASTIKAN ANDA MENGUNDI 15 CALON</h4><br>";
 
    while($row = mysqli_fetch_assoc($result)) {



?>

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

<?php
if($row[candPost] == "DIPLOMA") {?>
              
              <div class="col-md-3">
                                  
                     <p><?php echo $row[candN];?></p>
                     <p><?php echo $row[candCourse];?></p>
                     
                    <p><img src="<?php echo $row[image];?>" style="width:220px;height:200px;"/></p>
                              
                    <p><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];?>"><br><br></label></p>
                
               
              </div>

        
 <?php
}
}

?>                                 

<input type="hidden" name="var1" value="<?=$studentIC?>"/>
<input type="submit" class="btn btn-success" name="submit1" value="hantar undian anda">

</form>


<?php
  }
  else
  {
      echo "<h4>ANDA TELAH MENGUNDI</h4><br>";
  }
  }
else
{

echo "<h3>Nama anda tidak didaftarkan sebagai pengundi - rujuk admin</h3>";
}
?>

<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>
</body>
</html>
