<?php
chdir('../../');
require_once 'autoload.php';
$courses = new courses_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($courses->check($sanitezed_data['code'], $_POST['id']))) {

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

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

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

}else{

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

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

}
}else{

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

}
?>
