<?php

//exam.php 
include('../admin/orbital_001/Soes.php');

$object = new Soes;

 if (!isset($_SESSION['student_email_id'])) {
    header ('Location:../index.php');
    exit;
}
 $s_id=$_GET['frtj67hs34fki9dns3'];
$object->query = "
    SELECT class_id FROM student_to_class_soes 
    WHERE student_id = '".$_SESSION["student_id"]." ' AND subject_id='$s_id'
";

$result = $object->get_result();

$class_id = '';

foreach($result as $row)
{
    $class_id = $row["class_id"];
}


$object->query = "
    SELECT course FROM student_soes 
    WHERE student_id = '".$_SESSION["student_id"]."'
";

$result = $object->get_result();

$course = '';

foreach($result as $row1)
{
    $course = $row1["course"];
}

// $user_query = mysqli_query($conn,"select * from student_soes where student_id = '".$_SESSION["student_id"]."'")or die(mysqli_error());
// $user_row = mysqli_fetch_array($user_query);             
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="">
  <meta name="author" content="">
  <title>Cybercode Africa| Cybersecurity Training and resources</title> 
  <meta content="" name="keywords">

  <!-- Favicons -->
  <link href="../assets/img/icon1.png" rel="icon">
  <link href="../assets/img/icon1.png" rel="apple-touch-icon"> 
  <!-- DataTables -->
  <link rel="stylesheet" href="../stp_con/datatables-bs4/css/dataTables.bootstrap4.min.css">
  <link rel="stylesheet" href="../stp_con/datatables-responsive/css/responsive.bootstrap4.min.css">
  <link rel="stylesheet" href="../stp_con/datatables-buttons/css/buttons.bootstrap4.min.css"> 
  <link rel="stylesheet" href="../assets/css/adminlte.min.css"> 
 <link rel="stylesheet" href="../stp_con/summernote/summernote-bs4.min.css">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="../stp_con/fontawesome-free/css/all.min.css">
  <!-- overlayScrollbars -->
  <link rel="stylesheet" href="../stp_con/overlayScrollbars/css/OverlayScrollbars.min.css"> 
  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <link type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/south-street/jquery-ui.css" rel="stylesheet"> 
    <script type="text/javascript" src="../assets/js/jquery.signature.min.js"></script>
    <link rel="stylesheet" type="text/css" href="../assets/css/jquery.signature.css"> 
</head>

<body class="hold-transition sidebar-mini layout-fixed top-nav  pace-primary">

<div class="container-fluid px-4">
 <h1 class="mt-4">Exam Management</h1>
  <ol class="breadcrumb mb-4" style="background: linear-gradient(#d8d7e8,#f8fcf7,#d8d7e8);" >
    <li class="breadcrumb-item"><a href="../admin.php?page=dashboard&Id_2=<?php echo $course; ?>">Dashboard</a></li>
        <li class="breadcrumb-item active">Exam List</li>
    </ol>
    
    <span id="message"></span>
    <div class="card shadow mb-4">
        <div class="card-header py-3">
            <div class="row">
                <div class="col">
                    <h6 class="m-0 font-weight-bold">Exam List</h6>
                </div>
                <div class="col" align="right">
                </div>
            </div>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-bordered" id="exam_table" width="100%" cellspacing="0">
                    <thead>
                        <tr>
                            <th>Exam Name</th>
                            <th>Exam Duration</th>
                            <th>Result Date & Time</th>
                            <th>Status</th>
                            <th>Timetable</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                    <tbody>
                        
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
 <script src="../vendor/jquery/jquery-3.6.0.min.js"></script>
    <script src="../vendor/bootstrap/bootstrap.bundle.min.js"></script>
    <script src="../js/scripts.js"></script>
    <script src="../vendor/parsley/dist/parsley.min.js"></script>
    <script src="../vendor/datatables/jquery.dataTables.min.js"></script>
    <script src="../vendor/datatables/dataTables.bootstrap5.min.js"></script>

<div id="examtimetableModal" class="modal fade">
    <div class="modal-dialog" style="width: 100%; max-width: 1100px;">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="modal_title">Exam Schedule Details</h4>
                <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>
            <div class="modal-body">
                <div id="exam_schedule_details"></div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

<script>
$(document).ready(function(){

	var dataTable = $('#exam_table').DataTable({
		"processing" : true,
		"serverSide" : true,
		"order" : [],
		"ajax" : {
			url:"ajax_action.php",
			type:"POST",
			data:{page:'exam', action:'fetch', class_id:'<?php echo $class_id; ?>'}
		},
		"columnDefs":[
			{
				"targets":[4, 5],
				"orderable":false,
			},
		],
	});


    $(document).on('click', '.view_timetable', function(){
        var exam_id = $(this).data('id');
        $.ajax({
            url:"ajax_action.php",
            method:"POST",
            data:{page:"exam", action:"fetch_timetable", exam_id:exam_id},
            success:function(data)
            {
                $('#examtimetableModal').modal('show');
                $('#exam_schedule_details').html(data);
            }
        })
    });
    

});
</script>