<!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>KOLEJ VOKASIONAL SEPANG - E-VOTING SYSTEM</h1>
    <ul class="nav navbar-nav">
      <li class="active"><a href="index.html">Home</a></li>
      <li><a href="#">Profile Calon</a></li>
      <li><a href="#">Carian</a></li>
      <li><a href="loginregister.html">Undi</a></li>
      <li><a href="keputusan.php">Keputusan</a></li>
      <li><a href="loginregister.html">Login</a></li>
    </ul>

  </nav>

  <?php   

   include 'dbconn.php';

 $studentIC=$_POST['studentIC'];

//check if username already been used

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

  
$count1=mysqli_num_rows($result);

$row = mysqli_fetch_assoc($result);
$course=$row[studentCourse];
if($count1 == 1)
{

 	if($row[voteStatus] == 0)
 	{
?>           

<div class = "container">

<?php
include_once('nav.php');

?>

<div class ="container">
<h2>Anda hanya boleh mengundi tidak lebih 7 calon untuk AJK tertinggi MPP dan seorang calon Jabatan</h2>
              <form name="checkbox" action="undiantest1.php" method="post">
                 <input type="text" name="var1" value="<?=$studentIC?>"/>
                <div class="row">
                   <div class="col-md-3">
                     <h2>CALON 1</h2>
                    <p><img src="/evote/img/img1.jpg" alt="calon2" style="width:200px;height:225px;"/></p>
                    
                     
                     <input type="checkbox" id="test1" name="check[]" value="calon1" onclick="chkChecks('check[]')">
                     <label for="test1"><br><br>Undi saya</label>
        </p>
                   </div>

                   <div class="col-md-3">
                     <h2>CALON 2</h2>
                     <p><img src="/evote/img/img2.jpg" alt="calon2" style="width:200px;height:225px;"/></p>
                    
                     <input type="checkbox" id="test2" name="check[]" value="calon2" onclick="chkChecks('check[]')">
                     <label for="test2"><br><br>Undi saya</label>
                   </div>

                      <div class="col-md-3">
                         <h2>CALON 3</h2>
                         <p><img src="/evote/img/img3.jpg" alt="calon3" style="width:200px;height:225px;"/></p>
                         
                         <input type="checkbox" id="test3" name="check[]" value="calon3" onclick="chkChecks('check[]')">
                         <label for="test3"><br><br>Undi saya</label>
                       </div>
                       <div class="col-md-3">
                         <h2>CALON 4</h2>
                          <p><img src="/evote/img/img4.jpg" alt="calon4" style="width:200px;height:225px;"/></p>
                        
                         <input type="checkbox" id= "test4" name="check[]" value="calon4" onclick="chkChecks('check[]')">
                         <label for="test4"><br><br>Undi saya</label>
                     </div>
                     </div>

   <div class="row">
                   <div class="col-md-3">
                     <h2>CALON 5</h2>
                      <p><img src="/evote/img/img5.jpg" alt="calon5" style="width:200px;height:225px;"/></p>
                    

                     <input type="checkbox" id="test5" name="check[]" value="calon5" onclick="chkChecks('check[]')">
                     <label for="test5"><br><br>Undi saya</label>
        </p>
                   </div>
                   <div class="col-md-3">
                     <h2>CALON 6</h2>
                      <p><img src="/evote/img/img6.jpg" alt="calon6" style="width:200px;height:225px;"/></p>
                     
                     <input type="checkbox" id="test6" name="check[]" value="calon6" onclick="chkChecks('check[]')">
                     <label for="test6"><br><br>Undi saya</label>
                   </div>
                       <div class="col-md-3">
                         <h2>CALON 7</h2>
                          <p><img src="/evote/img/img7.jpg" alt="calon7" style="width:200px;height:225px;"/></p>
                         
                         <input type="checkbox" id="test7" name="check[]" value="calon7" onclick="chkChecks('check[]')">
                         <label for="test7"><br><br>Undi saya</label>
                       </div>
                       <div class="col-md-3">
                         <h2>CALON 8</h2>
                          <p><img src="/evote/img/img8.jpg" alt="calon8" style="width:200px;height:225px;"/></p>
                        
                         <input type="checkbox" id= "test8" name="check[]" value="calon8" onclick="chkChecks('check[]')">
                         <label for="test8"><br><br>Undi saya</label>
                     </div>
                     </div>
<?php

if($course=="automotif"){
?>
       <div class="row">
                      <h2>Jabatan Automotif</h2>
                      <div class="col-md-6">
                        <h2>CALON 1</h2>
                         <p><img src="evote/img/img3.jpg" alt="calon3" style="width:200px;height:225px;"/></p>
                       
                        <div class="radio">
                          <label><input type="radio" name="optradio" value="calon9">Undi Saya</label>
                        </div>
                      </div>
                      <div class="col-md-6">
                        <h2>CALON 2</h2>
                         <p><img src="evote/img/img3.jpg" alt="calon3" style="width:200px;height:225px;"/></p>
                        
                        <div class="radio">
                          <label><input type="radio" name="optradio" value="calon10">Undi Saya</label>
                        </div>
                    </div>

<?php
}
?>
      <input type="submit" class="btn btn-success" name="submit1" value="hantar undian anda">
  </div>
 
    </form>
<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 >7) {  // maximum of two checkboxes - change as required
alert ('ANDA HANYA BOLEH MENGUNDI TIDAK LEBIH DARI 7 CALON');
c[i].checked = false;
return false;
}
}
}
}

function showchoices(nme) {
var checkedVals = "";
var report = "SILA UNDI CALON PILIHAN ANDA";
var c = document.getElementsByName(nme);
for (var i = 0; i < c.length; i++) {
if (c[i].checked) {
checkedVals += c[i].value + " ";
}
}

if (checkedVals != "") {report = "You have selected " + checkedVals}
alert (report);
}

</script>


<?php
                                 if (isset($_POST['submit1'])){
                                  echo "hello";
                                  $checked=$_POST['checkbox'];
                                   $count=count($checked);
                                  echo $count;
                                       if($count > 7){
                                             echo '<script type="text/javascript">alert("You are allowed to vote maximum 7 candidates... try again");                   
                                              </script>';
                                               }
                                       else{
                                             echo "success";
                                               }
                                     }
            }
     else
     {
        echo "<h3>Anda telah mengundi. Undian anda sedang diproses</h3>";
      }//end of if voting status
}
else
{

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

?>
</div>
</div>
</body>
</html>
