<?php

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

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

//echo $examcode;

//$name = $_SESSION['name'];

$db->findExamsById($examcode);

$duration = $db->duration;

$statement = $db2->getQuestionsByExamID($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->findSubjectById($db->subject_id);

  // echo $db->subject_id;


}



}

/*
if (isset($_POST['submit'])){
	
    $examcode = strtouppe(strip_tags($_POST['username']));
    
    $_SESSION["examcode"] = $examcode;
    header("Location: secondPageExam.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 -->
  <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>
  <link rel="stylesheet" href="style.css" type="text/css"> 
  <link href='https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css'>
  <script src='https://stackpath.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.bundle.min.js'></script>
  <link href='https://use.fontawesome.com/releases/v5.7.2/css/all.css'>
  
  
 
 
</head>

<body class="bg-default">
  <!-- Navbar -->
  
  <!-- Main content -->
  <div style="font-weight: bold; background-color:white;" id="quiz-time-left"></div>

  <script type="text/javascript">
var max_time = <?php echo $duration ?>;
var c_seconds  = 0;


var total_seconds =60*max_time;
max_time = parseInt(total_seconds/60);
c_seconds = parseInt(total_seconds%60);
document.getElementById("quiz-time-left").innerHTML='Time Left: ' + max_time + ' minutes ' + c_seconds + ' seconds';
function init(){
document.getElementById("quiz-time-left").innerHTML='Time Left: ' + max_time + ' minutes ' + c_seconds + ' seconds';
setTimeout("CheckTime()",999);
}
function CheckTime(){
document.getElementById("quiz-time-left").innerHTML='Time Left: ' + max_time + ' minutes ' + c_seconds + ' seconds' ;
if(total_seconds <=0){
setTimeout('document.form.submit()',1);
   
    } else
    {
total_seconds = total_seconds -1;
max_time = parseInt(total_seconds/60);
c_seconds = parseInt(total_seconds%60);
setTimeout("CheckTime()",999);
}

}
init();


</script>
<style>
#quiz-time-left{
	color:black;
	padding:5px;
	font-size:18px;
	
	}
</style>



<div class="wrapper">

<?php



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

if (isset($_GET['page_no']) && $_GET['page_no']!="") {

    $page_no = $_GET['page_no'];

    } else {

        $page_no = 1;

        }

      
        $total_records_per_page = 1;

$offset = ($page_no-1) * $total_records_per_page;

$previous_page = $page_no - 1;

$next_page = $page_no + 1;

$adjacents = "1";


$total_records = $totalPages;

$total_no_of_pages = ceil($total_records / $total_records_per_page);

$second_last = $total_no_of_pages - 1; 

  
   $statement2 = $db2->getQuestionsByExamIDLIMIT1($examcode,$offset);

   $totalPages = $countQuestion;
    $rowCount1 = 0;
            while ($row = $statement2->fetch(PDO::FETCH_ASSOC)){
                extract($row);
            $rowCount1++;
    
           
            ?>

    <div class="wrap" id="q<?php echo $rowCount1 ?>">
        <div class="text-center pb-4">
            <div class="h5 font-weight-bold"><span id="number"> </span><?php echo $rowCount1 ." of " .$db->total;  ?>  </div>
        </div>
        <div class="h4 font-weight-bold">  <?php  echo $row['question'] ?>  
                    <input type="hidden" name="id[<?php echo $rowCount1 ?>]" value="<?php echo $row['id'];?>" /></div>
        <div class="pt-4">
            <form> <label class="options">Rahul Gandhi <input type="radio" name="radio"> <span class="checkmark"></span> </label> <label class="options">Indira Gandhi <input type="radio" name="radio"> <span class="checkmark"></span> </label> <label class="options">Narendra Modi <input type="radio" name="radio" id="rd" checked> <span class="checkmark"></span> </label> <label class="options">Ram Nath Kovind <input type="radio" name="radio"> <span class="checkmark"></span> </label> </form>
        </div>
        <?php }
       
        ?>


        <!--
       
       
        <div class="d-flex justify-content-end pt-2"> <a href = "newExam.php?page=<?php echo $page + 1 ;?>" class="btn btn-primary" id="next1">Next <span class="fas fa-arrow-right"></span> </a> </div> -->
    
        <div style='padding: 10px 20px 0px; border-top: dotted 1px #CCC;'>

<strong>Page <?php echo $page_no." of ".$total_no_of_pages; ?></strong>

</div>

Create the pagination button:

<ul class="pagination">

<?php if($page_no > 1){

echo "<li><a href='?page_no=1'>First Page</a></li>";

} ?>

<li <?php if($page_no <= 1){ echo "class='disabled'"; } ?>>

<a <?php if($page_no > 1){

echo "href='?page_no=$previous_page'";

} ?>>Previous</a>

</li>  

<li <?php if($page_no >= $total_no_of_pages){

echo "class='disabled'";

} ?>>

<a <?php if($page_no < $total_no_of_pages) {

echo "href='?page_no=$next_page'";

} ?>>Next</a>

</li>


<?php if($page_no < $total_no_of_pages){

echo "<li><a href='?page_no=$total_no_of_pages'>Last &rsaquo;&rsaquo;</a></li>";

} ?>

</ul>
    </div>
    
    
   

</div>
<?php
/*
echo "<ul class='pagination'>";
echo "<li><a href='newExam.php?page=".($page-1)."' class='button'>Previous</a></li>"; 

for ($i=1; $i<=$totalPages; $i++) {  
    echo "<li><a href='newExam.php?page=".$i."'>".$i."</a></li>";
} 

echo "<li><a href='newExam.php?page=".($page+1)."' class='button'>NEXT</a></li>";
echo "</ul>";  
*/
?>
<div class="d-flex flex-column align-items-center">
    <div class="h3 font-weight-bold text-white">Go Dark</div> <label class="switch"> <input type="checkbox"> <span class="slider round"></span> </label>
</div>
<script>
/*
    var q1 = document.getElementById("q1");
    var q2 = document.getElementById("q2");
    var q3 = document.getElementById("q3");
    var next1 = document.getElementById('next1')
    var back1 = document.getElementById('back1')
    var next2 = document.getElementById('next2')
    var back2 = document.getElementById('back2')
    document.addEventListener('DOMContentLoaded', function() {
        let query = window.matchMedia("(max-width: 767px)");
        if (query.matches) {
            next1.onclick = function() {
                q1.style.left = "-650px";
                q2.style.left = "15px";
            }
            back1.onclick = function() {
                q1.style.left = "15px";
                q2.style.left = "650px";
            }
            back2.onclick = function() {
                q2.style.left = "15px";
                q3.style.left = "650px";
            }
            next2.onclick = function() {
                q2.style.left = "-650px";
                q3.style.left = "15px";
            }
        } else {
            next1.onclick = function() {
                q1.style.left = "-650px";
                q2.style.left = "50px";
            }
            back1.onclick = function() {
                q1.style.left = "50px";
                q2.style.left = "650px";
            }
            back2.onclick = function() {
                q2.style.left = "50px";
                q3.style.left = "650px";
            }
            next2.onclick = function() {
                q2.style.left = "-650px";
                q3.style.left = "50px";
            }
        }
    });
  */
    function uncheck() {
        var rad = document.getElementById('rd')
        rad.removeAttribute('checked')
    }
    document.addEventListener('DOMContentLoaded', function() {
        const main = document.querySelector('body')
        const toggleSwitch = document.querySelector('.slider')
        toggleSwitch.addEventListener('click', () => {
            main.classList.toggle('dark-theme')
        })
    })
  
</script>

  
</body>

</html>