<?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 class_id = '$_GET[Class]' AND subject_id = '$_GET[Subject]'";

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

    $resultRow = mysqli_fetch_assoc($result);

    $mocktest_result = "SELECT * FROM mocktest_result  WHERE mocktest_id = '$resultRow[id]' ORDER BY obtained_marks DESC";

    $sql_result = mysqli_query($con, $mocktest_result);

    $MocktesRowCount = mysqli_num_rows($sql_result);

    

    $admin_2_run = "SELECT admin_ref FROM users WHERE uref = '$_SESSION[uref]'";

    $admin_2_row2 = mysqli_query($con, $admin_2_run);

    $admin_2_row = mysqli_fetch_assoc($admin_2_row2);

    $admin_2 = $admin_2_row["admin_ref"];



?>

<!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;

    }

  </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 table-responsive">

          <h1 class="h3 mb-2 text-gray-800 text-center"><?php echo $resultRow['mocktest_name']?></h1>

          <hr>

          <a href="view-mocktest.php" class="btn btn-primary">Go to Back</a>

         <?php if($MocktesRowCount>0){?>

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

            <thead>

              <tr>

                <th>Sl</th>

                <th>Student Name</th>

                <th>Total Marks</th>

                <th>Obtained Marks</th>

              </tr>

            </thead>

            <tbody>

              <?php 

                foreach($sql_result as $key => $sqlData){

                 

                  $StudentSQl = "SELECT * FROM users WHERE uid = '$sqlData[student_id]'";

                  $StudentRun = mysqli_query($con, $StudentSQl);

                  $StudentData = mysqli_fetch_assoc($StudentRun);

                  ?>

                  <tr>

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

                    <td><?php echo $StudentData['uname'];?></td>

                    <td><?php echo $sqlData['total_marks'];?></td>

                    <td><?php echo $sqlData['obtained_marks'];?></td>

                  </tr>

                <?php }

              ?>

            </tbody>

          </table>

        <?php }else{ ?><span class="text-danger font-weight-bold">No Data Found !</span>

              <?php }?>

          <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>