<?php
ob_start();
require_once('operations.php');
session_start();
$db = new Operations();

$examcode = $_SESSION['examcode'];
$countExam = $db->checkExamsCode($examcode);

echo $examcode;

if($countExam < 1) {
  ?>
  <script>
  alert('exam code does not exist');
window.location.href='firstPageExam.php';

</script>
  <?php
}

else {

$countQuestion = $db->getCountQuestionsByExamID($examcode);

if($countQuestion < 1) {

  ?>
  <script>
  alert('questions are not ready for this exams');
window.location.href='firstPageExam.php';

</script>
  <?php
  
}

else {

  $db->findExamsById($examcode);


   $db->findSubjectById($db->subject_id);

  // echo $db->subject_id;


}



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

 // addScores($subject_id,$examcode,$lname,$class,$admissionno)
	
    $name = strtoupper(strip_tags($_POST['username']));
    $admissionno = strtoupper(strip_tags($_POST['admissionno']));
    $_SESSION["name"] = $name;
    $_SESSION["admissionno"] = $admissionno;
    $_SESSION["subject"] = $db->title;
    $_SESSION["class"] = $db->class;

    
    
  //  $db->addScores($db->subject_id,$examcode,$name,$db->class,$admissionno);
    header("Location: examsPage.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="cbt app">
  <meta name="author" content="Creative Tim">
  <title>CBT 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">
  <!-- Argon CSS -->
  <link rel="stylesheet" href="assets/css/argon.css?v=1.2.0" type="text/css">
</head>

<body class="bg-default">
  <!-- Navbar -->
  <nav id="navbar-main" class="navbar navbar-horizontal navbar-transparent navbar-main navbar-expand-lg navbar-light">
    <div class="container">
      <a class="navbar-brand" href="dashboard.html">
        <img src="../assets/img/brand/white.png">
      </a>
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar-collapse" aria-controls="navbar-collapse" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>
      <div class="navbar-collapse navbar-custom-collapse collapse" id="navbar-collapse">
        <div class="navbar-collapse-header">
          <div class="row">
            <div class="col-6 collapse-brand">
              <a href="dashboard.html">
                  <div>
                      <h4>EXAM APP</h4>
</div>
              </a>
            </div>
            <div class="col-6 collapse-close">
              <button type="button" class="navbar-toggler" data-toggle="collapse" data-target="#navbar-collapse" aria-controls="navbar-collapse" aria-expanded="false" aria-label="Toggle navigation">
                <span></span>
                <span></span>
              </button>
            </div>
          </div>
        </div>
        <ul class="navbar-nav mr-auto">
          <li class="nav-item">
            <a href="firstPageExam.php" class="nav-link">
              <span class="nav-link-inner--text">Write Exam</span>
            </a>
          </li>
          <li class="nav-item">
            <a href="#" class="nav-link">
              <span class="nav-link-inner--text">Login Admin</span>
            </a>
          </li>
          <li class="nav-item">
            <a href="#" class="nav-link">
              <span class="nav-link-inner--text">Register</span>
            </a>
          </li>
        </ul>
        <hr class="d-lg-none" />
        <ul class="navbar-nav align-items-lg-center ml-lg-auto">
          <li class="nav-item">
            <a class="nav-link nav-link-icon" href="instructions.html">
              
              Instructions
            </a>
          </li>
          
        </ul>
      </div>
    </div>
  </nav>
  <!-- Main content -->
  <div class="main-content">
    <!-- Header -->
    <div class="header bg-gradient-primary py-7 py-lg-8 pt-lg-9">
      <div class="container">
        <div class="header-body text-center mb-7">
          <div class="row justify-content-center">
            <div class="col-xl-5 col-lg-6 col-md-8 px-5">
              <h1 class="text-white">Welcome!</h1>
              <p class="text-lead text-white">Exams Code : <?php echo $examcode ." "."Subject :". $db->title;   ?></p>
              
              <p class="text-lead text-white">Duration : <?php echo $db->duration. " minuites   Class: ".$db->class;  ?></p>
  
              <p class="text-lead text-white">Total no of questions : <?php echo $db->total;  ?></p>
            </div>
          </div>
        </div>
      </div>
      <!--
      <div class="separator separator-bottom separator-skew zindex-100">
        <svg x="0" y="0" viewBox="0 0 2560 100" preserveAspectRatio="none" version="1.1" xmlns="http://www.w3.org/2000/svg">
          <polygon class="fill-default" points="2560 0 2560 100 0 100"></polygon>
        </svg>
      </div>
      -->
    </div>
    <!-- Page content -->
    <div class="container mt--8 pb-5">
      <div class="row justify-content-center">
        <div class="col-lg-5 col-md-7">
          <div class="card bg-secondary border-0 mb-0">
            <div class="card-header bg-transparent pb-5">
             
            
              <form role="form" method = "post" action = "">
                <div class="form-group mb-3">
                  <div class="input-group input-group-merge input-group-alternative">
                  <label class="form-control-label" for="input-username">Enter your name</label>
                    <div class="input-group-prepend">
                      <span class="input-group-text"><i class="ni ni-single-02"></i></span>
                    </div>
                    <input class="form-control" placeholder="enter your name" type="text" name = "username" required>
                  </div>
                </div>


                <div class="input-group input-group-merge input-group-alternative">
                  <label class="form-control-label" for="input-username">Enter Admission Number</label>
                    <div class="input-group-prepend">
                      <span class="input-group-text"><i class="ni ni-single-02"></i></span>
                    </div>
                    <input class="form-control" placeholder="enter your name" type="text" name = "admissionno" required>
                  </div>
                </div>
               
                <div class="text-center">
                  <button type="submit" name = "submit" class="btn btn-primary my-4">START EXAM</button>
                </div>
              </form>
            </div>
          </div>
          <div class="row mt-3">
            
        </div>
      </div>
    </div>
  </div>
  <!-- Footer -->
  <footer class="py-5" id="footer-main">
    <div class="container">
      <div class="row align-items-center justify-content-xl-between">
        <div class="col-xl-6">
          <div class="copyright text-center text-xl-left text-muted">
            &copy; <?php echo date("Y") ?> <a href="#" class="font-weight-bold ml-1" target="_blank">Dcube-International</a>
          </div>
        </div>
        <div class="col-xl-6">

          
        </div>
      </div>
    </div>
  </footer>
  <!-- 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>
  <!-- Argon JS -->
  <script src="assets/js/argon.js?v=1.2.0"></script>
</body>

</html>