<?php
chdir('../../');
require_once 'autoload.php';
$exam_session = new exam_sessions_controller;

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['csrf_token']) && isset($_POST['csrf_form_id']) && $waf->csrf_validate($_POST['csrf_form_id'], $_POST['csrf_token'], $utility->action_name())) {

$sanitezed_data = $utility->sanitize_request($_POST);

if (empty($exam_session->check($sanitezed_data['code'], $_POST['id']))) {

$exam_session->update($_POST['id'], $sanitezed_data);

$utility->setMessage("success", 'Exam session updated');

header("location:../sessions");

}else{

$utility->setMessage("warning", 'Exam session is already registered');

header("location:../sessions");

}
}else{

header("location:../sessions");

}
?>
