<?php
 session_start();
require_once('operations.php');

$db = new Operations();

if (!isset($_SESSION['staffno'])) {
   header( "Location: index.php" );
}

$statement = $db->getAllSubject();


if(isset($_GET['examcode']) && ($_GET['subject_id']) && ($_GET['title']) ) {
    $param =  $_GET['examcode'];
    $param2 = $_GET['subject_id'];
      $param3 =  $_GET['title'];
    
    
    $db->findExamsById($param);
    
    // $db2->
    
    
    }


    $month = date("n");
$year = date("Y");

if($month == 19 || $month == 10 || $month == 11 || $month == 12){

$session1 = $year . "/". ($year + 1);
$term1 = "First";
//$term1 = "Third";
}


else if($month == 1 || $month == 2 || $month == 3 || $month == 4){
$session1 = ($year-1)."/".$year;
$term1 = "Second";

//$term1 = "First";
}

else if($month == 5 || $month == 6 || $month == 7 || $month == 9){
$session1 = ($year-1)."/".$year;
$term1 = "Third";
//$term1 = "Second";
//$term1 = "First";
}	

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

 // $examcode = $code1;
  $class = $_POST['class'];
   $subject_id =  $_POST['subject_id'];
   $time = $_POST['time'];
   $date1 = $_POST['datepicker-13'];
   $date = date("Y-m-d");
   $duration = $_POST['duration'];
   $questions = $_POST['questions'];

   $time1 = $date." ".$time;

 	
  

  

  $countExam = $db->checkExamsCode($code1);


  
  if($countExam > 0){
  
  ?>
      
<script>alert('Error, exams code already exist');</script>	        
      
      <?php
  
  }
   else {
//addSchedule($examcode,$subject_id,$class,$time,$duration,$date,$questions,$term,$year,$total
//,$increment)
//updateSchedule($examcode,$subject_id,$class,$time,$duration,$date,$questions,$term,$year,$date1)
  if(!$db->updateSchedule($param,$subject_id,$class,$time,$duration,$date,$questions,$term1,$session1,$date1
  )) {
      
      ?>
      <script>alert('exam  updated Successfully'); 
      window.location.href='allSchedule.php';
      
   </script>
       <?php 
  }

  else {

      ?>
      <script>alert('Error updating exam');</script>    
          <?php 
  }

   }  

}
?>
<!--
=========================================================
* Argon Dashboard - v1.2.0
=========================================================
* Product Page: https://www.creative-tim.com/product/argon-dashboard


* Copyright  Creative Tim (http://www.creative-tim.com)
* Coded by www.creative-tim.com



=========================================================
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-->
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="Start your development with a Dashboard for Bootstrap 4.">
  <meta name="author" content="Creative Tim">
  <title>Exam App</title>
  <!-- Favicon 
  <link rel="icon" href="assets/img/brand/favicon.png" type="image/png">
  -->
  <!-- Fonts -->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700">
  <!-- Icons -->
  <link rel="stylesheet" href="assets/vendor/nucleo/css/nucleo.css" type="text/css">
  <link rel="stylesheet" href="assets/vendor/@fortawesome/fontawesome-free/css/all.min.css" type="text/css">
  <!-- Page plugins -->
  <!-- Argon CSS -->
  <link rel="stylesheet" href="assets/css/argon.css?v=1.2.0" type="text/css">
 
  <!-- date picker -->

  
  

  


  <link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
         rel = "stylesheet">

</head>

<body>
  <!-- Sidenav -->
  <nav class="sidenav navbar navbar-vertical  fixed-left  navbar-expand-xs navbar-light bg-white" id="sidenav-main">
    <div class="scrollbar-inner">
      <!-- Brand -->
      <div class="sidenav-header  align-items-center">
        <a class="navbar-brand" href="javascript:void(0)">
          <h4>Exam App</h4>
        </a>
      </div>
      <div class="navbar-inner">
        <!-- Collapse -->
        <div class="collapse navbar-collapse" id="sidenav-collapse-main">
          <!-- Nav items -->
          <?php include('menu.html')  ?>
          <!-- Divider -->
          <hr class="my-3">
          <!-- Heading -->
          
        </div>
      </div>
    </div>
  </nav>
  <!-- Main content -->
  <div class="main-content" id="panel">
    <!-- Topnav -->
    <nav class="navbar navbar-top navbar-expand navbar-dark bg-primary border-bottom">
      <div class="container-fluid">
        <div class="collapse navbar-collapse" id="navbarSupportedContent">
          <!-- Search form -->
          <form class="navbar-search navbar-search-light form-inline mr-sm-3" id="navbar-search-main">
            <div class="form-group mb-0">
              <div class="input-group input-group-alternative input-group-merge">
                <div class="input-group-prepend">
                  <span class="input-group-text"><i class="fas fa-search"></i></span>
                </div>
                <input class="form-control" placeholder="Search" type="text">
              </div>
            </div>
            <button type="button" class="close" data-action="search-close" data-target="#navbar-search-main" aria-label="Close">
              <span aria-hidden="true">×</span>
            </button>
          </form>
          <!-- Navbar links -->
          
           <nav class="navbar navbar-top navbar-expand navbar-dark bg-primary border-bottom">
        <ul class="navbar-nav align-items-center  ml-md-auto ">
            <li class="nav-item d-xl-none">
              <!-- Sidenav toggler -->
              <div class="pr-3 sidenav-toggler sidenav-toggler-dark" data-action="sidenav-pin" data-target="#sidenav-main">
                <div class="sidenav-toggler-inner">
                  <i class="sidenav-toggler-line"></i>
                  <i class="sidenav-toggler-line"></i>
                  <i class="sidenav-toggler-line"></i>
                </div>
              </div>
</li>
</ul>
          
          
        </div>
      </div>
    </nav>
    <!-- Header -->
    <!-- Header -->
    <div class="header bg-primary pb-6">
      <div class="container-fluid">
        <div class="header-body">
          <div class="row align-items-center py-4">
            
          
          </div>
          <!-- Card stats -->
         
          <!-- put content  -->




         



          <div class="container-fluid mt--6">
      
       
      <div class="row">
        <div class="col-xl-8">
          <div class="card">
            <div class="card-header border-0">
              <div class="row align-items-center">
                <div class="col">
                  <h3 class="mb-0">Edit Schedule  FOR <?php echo " ".$param3." Exam code ".$param  ?></h3>
                </div>
                <div class="col text-right">
                  
                </div>
              </div>
            </div>
            <div class="table-responsive">
              <!-- Projects table -->
              <div class="card-body">
              <form method = "post" action = "">
                
               
             
               

                  <div class="row">
                    <div class="col-lg-12">
                      <div class="form-group">
                        <label class="form-control-label" for="input-username">SELECT SUBJECT</label>
                        <select class="form-control" name = "subject_id" required>

  <option value = "<?php echo $param2 ?>"><?php echo $param3 ?></option>
  <?php 
  while ($row = $statement->fetch(PDO::FETCH_ASSOC)){
            extract($row);
            ?>
             <option value = "<?php echo $row['id'] ?>"><?php echo $row['title'] ?></option>
            <?php
  }
            ?>
</select>
                      </div>
                    </div>
                    </div>



                    <div class="row">
                    <div class="col-lg-12">
                      <div class="form-group">
                        <label class="form-control-label" for="input-username">Class</label>
                        <select class="form-control" name = "class" required>
  <option><?php echo $db->class ?></option>
  <option>JS1</option>
  <option>JS2</option>
  <option>JS3</option>
  <option>SS1</option>
  <option>SS2</option>
  <option>SS3</option>
</select>
                      </div>
                    </div>
                    </div>
                 

                   



                    <div class="row">
                    <div class="col-lg-12">
                      <div class="form-group">
                        <label class="form-control-label" for="input-username">Date of Exam</label>
                       <!-- <input type="text" id="input-username" class="form-control" placeholder="subject" name = "subject" value="" required> -->

                       <input type="text" class="form-control" id="datepicker-13" name="datepicker-13" placeholder="" required readonly
                       value = "<?php echo $db->date1 ?>"> 
  
          
      
                      </div>
                    </div>
                    </div>


                    <div class="row">
                    <div class="col-lg-12">
                      <div class="form-group">
                        <label class="form-control-label" for="input-username">Time of exam</label>
                        <select class="form-control" name = "time"  required>
                          <option><?php echo $db->time ?></option>
                        <option value="00:00">00:00</option>
<option value="00:15">00:15</option>
<option value="00:30">00:30</option>
<option value="00:45">00:45</option>
<option value="01:00">01:00</option>
<option value="01:15">01:15</option>
<option value="01:30">01:30</option>
<option value="01:45">01:45</option>
<option value="02:00">02:00</option>	
<option value="02:15">02:15</option>	
<option value="02:30">02:30</option>
<option value="02:45">02:45</option>	
<option value="03:00">03:00</option>	
<option value="03:15">03:15</option>	
<option value="03:45">03:45</option>	
<option value="04:00">04:00</option>	
<option value="04:15">04:15</option>	
<option value="04:30">04:30</option>	
<option value="04:45">04:45</option>	
<option value="05:00">05:00</option>	
<option value="05:15">05:15</option>	
<option value="05:30">05:30</option>	
<option value="05:45">05:45</option>	
<option value="06:00">06:00</option>	
<option value="06:15">06:15</option>	
<option value="06:30">06:30</option>	
<option value="06:45">06:45</option>
<option value="07:00">07:00</option>
<option value="07:15">07:15</option>
<option value="07:45">07:45</option>
<option value="08:00">08:00</option>
<option value="08:15">08:15</option>
<option value="08:30">08:30</option>
<option value="08:45">08:45</option>
<option value="09:00">09:00</option>
<option value="09:15">09:15</option>
<option value="09:30">09:30</option>
<option value="09:45">09:45</option>
<option value="10:00">10:00</option>
<option value="10:15">10:15</option>
<option value="10:30">10:30</option>
<option value="10:45">10:45</option>
<option value="11:00">11:00</option>
<option value="11:15">11:15</option>
<option value="11:30">11:30</option>
<option value="11:45">11:45</option>
<option value="12:00">12:00</option>
<option value="12:15">12:15</option>
<option value="12:30">12:30</option>
<option value="12:45">12:45</option>
<option value="13:00">13:00</option>
<option value="13:15">13:15</option>
<option value="13:30">13:30</option>
<option value="13:45">13:45</option>
<option value="14:00">14:00</option>	
<option value="14:15">14:15</option>
<option value="14:30">14:30</option>
<option value="14:45">14:45</option>
<option value="15:00">15:00</option>
<option value="15:15">15:15</option>
<option value="15:30">15:30</option>
<option value="15:45">15:45</option>

<option value="16:00">16:00</option>
<option value="16:15">16:15</option>
<option value="16:30">16:30</option>
<option value="16:45">16:45</option>

<option value="17:00">17:00</option>
<option value="17:15">17:15</option>
<option value="17:30">17:30</option>
<option value="17:45">17:45</option>


<option value="18:00">18:00</option>
<option value="18:15">18:15</option>
<option value="18:30">18:30</option>
<option value="18:45">18:45</option>	

<option value="19:00">19:00</option>
<option value="19:15">19:15</option>
<option value="19:30">19:30</option>
<option value="19:45">19:45</option>

<option value="20:00">20:00</option>
<option value="20:15">20:15</option>
<option value="20:30">20:30</option>
<option value="20:45">20:45</option>

<option value="21:00">21:00</option>
<option value="21:15">21:15</option>
<option value="21:30">21:30</option>
<option value="21:45">21:45</option>			

<option value="22:00">22:00</option>
<option value="22:15">22:15</option>
<option value="22:30">22:30</option>
<option value="22:45">22:45</option>

<option value="23:00">23:00</option>
<option value="23:15">23:15</option>
<option value="23:30">23:30</option>
<option value="23:45">23:45</option>
</select>			
                      </div>
                    </div>
                    </div>


                    <div class="row">
                    <div class="col-lg-12">
                      <div class="form-group">
                        <label class="form-control-label" for="input-username">Duration(min)</label>
                        <input type="text" id="input-username" onkeypress="javascript:return isNumber(event)" class="form-control" placeholder="subject" name = "duration" value="<?php echo $db->duration ?>" required>
                      </div>
                    </div>
                    </div>


                    <div class="row">
                    <div class="col-lg-12">
                      <div class="form-group">
                        <label class="form-control-label" for="input-username">Total Questions</label>
                        <input type="text" id="input-username" onkeypress="javascript:return isNumber(event)" class="form-control" placeholder="subject" name = "questions" value="<?php echo $db->questions ?>" required>
                      </div>
                    </div>
                    </div>


                

                
                  <div class="text-center">
                  <button type="submit" name = "submit" class="btn btn-primary my-4">Edit Schedule</button>
                </div>
                  </form>
              <!-- end -->
            </div>
          </div>
        </div>
        
            </div>
          </div>
        </div>
      </div>


          <!-- put content --->
          
        </div>
      </div>
    </div>
    <!-- Page content -->
    <div class="container-fluid mt--6">
    
       
      
        </div>
      </div>
      <!-- Footer -->
      <footer class="footer pt-0">
        <div class="row align-items-center justify-content-lg-between">
          <div class="col-lg-6">
            
          </div>
          <div class="col-lg-6">
            
          </div>
        </div>
      </footer>
    </div>
  </div>
  <!-- Argon Scripts -->
  <!-- Core -->

   <script src="assets/vendor/jquery/dist/jquery.min.js"></script> 
  <script src="assets/vendor/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
  <script src="assets/vendor/js-cookie/js.cookie.js"></script>
  <script src="assets/vendor/jquery.scrollbar/jquery.scrollbar.min.js"></script>
  <script src="assets/vendor/jquery-scroll-lock/dist/jquery-scrollLock.min.js"></script>
  <script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

  <script src ="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.1/moment.min.js"></script>  

<script src ="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.7.14/js/bootstrap-datetimepicker.min.js"></script>  
  <!-- Optional JS -->
  <script src="assets/vendor/chart.js/dist/Chart.min.js"></script>
  <script src="assets/vendor/chart.js/dist/Chart.extension.js"></script>
  <!-- Argon JS -->
 <script src="assets/js/argon.js?v=1.2.0"></script>

  <script>
    // WRITE THE VALIDATION SCRIPT.
    function isNumber(evt) {
        var iKeyCode = (evt.which) ? evt.which : evt.keyCode
        if (iKeyCode != 46 && iKeyCode > 31 && (iKeyCode < 48 || iKeyCode > 57))
            return false;

        return true;
    }    
</script>

<script>
         $(function() {
			  
            $( "#datepicker-13" ).datepicker(
			{dateFormat: 'yy-mm-dd',minDate:0}).datepicker("setDate", new Date());
           
			
			
         });
      </script>
</body>

</html>