<?php

include_once 'classes/Authentication.php';
include_once 'classes/Database.php';
include_once 'classes/User.php';
$db = Database::getDatabase();
Authentication::sec_session_start();
if (Authentication::login_check($db->getMysqli()) == true && $_SESSION['admin'] == true) {
    ?>

<?php 
} else {
    header('Location: access-error.php');
}
?>
  <?php 
$userExams = User::getAppointments($_POST['netID']);
$mycount = count($userExams);
?>
  <link rel="stylesheet" type="text/css" href="css/sortable_table.css">
  <div class="facultyScheduleExamFormContainer">
      <table id="student_exams_container" class="sortable_table">
        <tbody>
          <tr>
            <th sort_expression="netID">netID</th>
            <th sort_expression="ClassID">CourseName</th>
              <th sort_expression="ClassID">CourseNumber</th>
            <th sort_expression="ExamStartDate">ExamStartDate</th>
            <th sort_expression="ExamEndDate">ExamEndDate</th>
            <th sort_expression="ExamDuration">ExamStartTime</th>
            <th sort_expression="ExamDuration">ExamEndTime</th>
<?php

include "dbQueries.php";
//error_reporting(E_ALL);
//ini_set('display_errors', 'On');
include_once 'classes/Authentication.php';
include_once 'classes/Database.php';
$db = Database::getDatabase();
Authentication::sec_session_start();
if (Authentication::login_check($db->getMysqli()) == true) {
    try {
        $dbh = new PDO("mysql:host=mysql2.cs.stonybrook.edu;dbname=sachin", "sachin", "108610059");
    } catch (PDOException $e) {
        $message = "Couldnt connect to db.";
        echo "<script type='text/javascript'>alert('{$message}');</script>";
    }
    //gets previous information need for the queries and inserts.
    $dbh->beginTransaction();
    $examStartDate = $_POST[startDate];
    $examNetID = $_POST[netID];
    $examID = $_POST[examID];
    $examDuration = $_POST[examDuration];
    $examClassID = $_POST[examClassID];
    $term;
    $dayOfWeek = date('l', strtotime($examStartDate));
    $examTotalTime = intval($examDuration);
    $gaptime;
    $numSeats;
    // gets the last updated room change for the date the appointment is to be scheduled for
    $sql = "SELECT * FROM freyhalltestingcenterroom WHERE daysFrom<'{$examStartDate}' AND daysUntil> '{$examStartDate}'; ";
    $result = $dbh->prepare($sql);