<?php

    session_start();

    include "../db.php";

    date_default_timezone_set('Asia/Kolkata');

    $currentTime = date('M j, Y g:i a');



    if ( !isset($_SESSION['uid']) && !isset($_SESSION['uref']) && !isset($_SESSION['utype']) && !isset($_SESSION['uname']) )

        header("Location: logout.php");



    $mocktest = "SELECT * FROM mocktest WHERE status = 1";

    $result = mysqli_query($con, $mocktest);

?>



<!DOCTYPE html>

<html lang="en">



<head>

<?php include "includes/meta.php"; ?>        

    <?php include "includes/css.php"; ?>     





  <style>

    .modal.fade .modal-dialog {

      width: 100%;

      margin: 0 auto;

    }

    .dataTables_info{

      display:none;

    }

    .dataTables_length{

      display:none;

    }

    #MockTest thead tr{

      background: #00428a;

      color:#fff;

    }

    .btn-primary{

      background: #00428a;

      border-color: #00428a;

      color:#fff;

    }

    div.dataTables_wrapper div.dataTables_filter {

      text-align: right;

    }

  </style>

</head>



<body id="page-top" class="mt-55">

  <div style="margin-top: 70px;"></div>

  <?php include "includes/header2.php"; ?>

  <div class="container">

    <div class="row">

      <div class="col-12 col-sm-12 col-md-12">

        <div cla ss="card-body">

          <h1 class="h3 mb-2 text-gray-800 text-center">All Mock Test</h1>

          <hr>

          <table id="MockTest" class="table table-striped table-borderless" style="width:100%">

            <thead>

              <tr>

                <th>Sl</th>

                <th>Name</th>

                <th>Class</th>

                <th>Subject</th>

                <th>Time(minutes)</th>

                <th>Uploaded By(Teacher)</th>

                <th>Questions</th>

              </tr>

            </thead>

            <tbody>

              <?php foreach($result as $key => $row){

                $class = "SELECT sclass, sid FROM class WHERE sid = '$row[class_id]'";

                $classresult = mysqli_query($con, $class);

                $classRow = mysqli_fetch_array($classresult);

                $subject = "SELECT sc_name, sc_id FROM subject WHERE sc_id = '$row[subject_id]'";

                $subjectresult = mysqli_query($con, $subject);

                $subjectRow = mysqli_fetch_array($subjectresult);

                $teacher = "SELECT * FROM users WHERE uref = '$row[uploaded_by]'";

                $teacherResult = mysqli_query($con, $teacher);

                $teacherRow = mysqli_fetch_array($teacherResult);

                ?>

                <tr>

                <td><?php echo $key+1?></td>

                <td><?php echo $row['mocktest_name'];?></td>

                <td><?php echo $classRow['sclass'];?></td>

                <td><?php echo $subjectRow['sc_name'];?></td>

                <td><?php echo $row['mock_time'];?></td>

                <td>

                     <?php echo $teacherRow['uname'];?>

                </td>

                <td>

                  <div class="py-3">

                    <a href="view-questions.php?mocktest=<?php echo $row['id'];?>" class="btn btn-primary">View Questions</a>

                  </div>

                </td>

              </tr>

              <?php }?>

            </tbody>

          </table>

          <hr>

        </div>

      </div>

    </div>

  </div>



  <?php include "includes/ft.php"; ?>

       <?php include "includes/js.php"; ?>

  <script src="https://cdn.datatables.net/1.13.2/js/jquery.dataTables.min.js"></script>

  <script src="https://cdn.datatables.net/1.13.2/js/dataTables.bootstrap4.min.js"></script>

  <script>

    $(document).ready(function () {

      $('#MockTest').DataTable();

    });

  </script>



</body>



</html>