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

$db = new Operations();

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

$staffid = $_SESSION['user'];
$statement = "";
if(isset($_GET['examcode'])) {
    $param =  $_GET['examcode'];
    
   //  $db->findSubjectById($param);

    // $statement = $db->getQuestionsByExamID($param);
    
    
    }

  
    $results_per_page = 1;  

$number_of_result = $db->getQuestionsByExamIDStaffCount($param);

//determine the total number of pages available  
$number_of_page = ceil ($number_of_result / $results_per_page);  
  
//determine which page number visitor is currently on  
if (!isset ($_GET['page']) ) {  
    $page = 1;  
} else {  
    $page = $_GET['page'];  
}  



//determine the sql LIMIT starting number for the results on the displaying page  
$page_first_result = ($page-1) * $results_per_page; 
    

$statement = $db->getQuestionsByExamIDStaffLimit($param,$page_first_result,$results_per_page);
//$statement = $db->getAllSchedule();


if(isset($_POST['submit'])){
	$id = $_POST['id'];
	
	$db->deleteQuestion($id);
  ?>
  <script>
alert('record deleted successfully');
window.location.href='editQuestionsStaff.php';

</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">
  <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.2/css/bootstrap.css" rel="stylesheet" >
  <link rel="stylesheet" href="https://cdn.datatables.net/1.10.24/css/dataTables.bootstrap4.min.css" type="text/css">
  <style>   
    table {  
        border-collapse: collapse;  
    }  
        .inline{   
            display: inline-block;   
            float: right;   
            margin: 20px 0px;   
        }   
         
        input, button{   
            height: 34px;   
        }   
  
    .pagination {   
        display: inline-block;   
    }   
    .pagination a {   
        font-weight:bold;   
        font-size:18px;   
        color: black;   
        float: left;   
        padding: 8px 16px;   
        text-decoration: none;   
        border:1px solid black;   
    }   
    .pagination a.active {   
            background-color: pink;   
    }   
    .pagination a:hover:not(.active) {   
        background-color: skyblue;   
    }   
        </style> 
</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('staffmenu.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 -->
          
           <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>
          <div class="card " >
    <div class="card-body">
   
          <!-- Card stats -->
         
          <!-- put content  -->




          
<?php
$rowCount1 = 0;
        while ($row = $statement->fetch(PDO::FETCH_ASSOC)){
            extract($row);
        $rowCount1++;

        

        ?>
            

       <div class="row">
  <div class="col-xs-12 col-md-12" style ="padding: 5px; width:500px;">
      

<a href = "addPassageStaff.php?examcode=<?php echo $param ;?>" class = "btn btn-primary">Edit Passage/instructions</a>
  <?php 
  echo $row['question'];
   ?>
   </div>
  <div class="col-xs-12 col-md-12">Option A :<?php echo $row['optionA'] ?></div> 
  <div class="col-xs-12 col-md-12">Option B :<?php echo $row['optionB'] ?></div>
  <div class="col-xs-12 col-md-12">Option C:<?php echo $row['optionC'] ?></div>
 <div class="col-xs-12 col-md-12">Option D:<?php echo $row['optionD'] ?></div>
  <div class="col-xs-12 col-md-12">Answer:<?php echo $row['answer'] ?></div>

 
  <div class = "row">
  <div class="col-xs-6 col-md-6"><a href="editQuestionsPageStaff.php?id=<?php echo $row['id'] ;?>&id=<?php echo urlencode($row['id']) ;?>" class="btn btn-primary ">Edit Questions</a></div>

  <div class="col-xs-6 col-md-6"><form action="" method="post" name="form3">
    <input name="id" type="hidden" value="<?php  echo $row['id']?>">
    <input type="submit" value="Delete Questions" name="submit" class="btn btn-danger" onclick="return confirm('Are you sure you want to delete this record?')"/></div>
    </div>
</div>     
            
<?php } ?>



<div class="pagination">  

    <?php
    


    echo "</br>";     
        // Number of pages required.   
        $total_pages = ceil ($number_of_result / $results_per_page); 
        
   
        $pagLink = "";       
      
        if($page>=2){   
            echo "<a href='editQuestionsStaff.php?examcode=".$param."&page=".($page-1)."'>  Prev </a>";   
        }       
                   
        for ($i=1; $i<=$total_pages; $i++) {   
          if ($i == $page) {   
              $pagLink .= "<a class = 'active' href='editQuestionsStaff.php?examcode=".($param)."&page="  
                                                .$i."'>".$i." </a>";   
          }               
          else  {   
              $pagLink .= "<a href='editQuestionsStaff.php?examcode=".($param)."&page=".$i."'>   
                                                ".$i." </a>";     
          }   
        }     
        echo $pagLink;   
     $param1 = 5;
       
        if($page<$total_pages){   
            echo "<a href='editQuestionsStaff.php?examcode=".($param)."&page=".($page+1)."'>  Next </a>";   
        }   
  
      ?>    
      </div>  
  
  
      
    </div>   
  </div>  
</center>   
  



<div>
</div>
   
  <!---  card ends here -->

          <!-- 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>
  <!-- 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 type="text/javascript" language="javascript" src="https://code.jquery.com/jquery-3.5.1.js"></script>
  <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.10.24/js/jquery.dataTables.min.js"></script>
  <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.10.24/js/dataTables.bootstrap4.min.js"></script>
<script>
  $(document).ready(function() {
	$('#example').DataTable();
} );

	</script>
</body>

</html>