<?php

include('phpClasses/Course.php');
$course = new Course();

if (isset($_POST['coscode_check'])) {
    $cos_code = filter_var($_POST['coscode'], FILTER_SANITIZE_STRING);
    $avail = $course->checkCsCode($cos_code);
    if ($avail == 'taken') {
        echo "taken";
        exit();
    } else {
        echo 'not_taken';

        exit();
    }
    exit();
}

if (isset($_POST['save'])) {
    $cos_code = filter_var($_POST['coscode'], FILTER_SANITIZE_STRING);
    $sem_code = filter_var($_POST['semcode'], FILTER_SANITIZE_STRING);
    $dep_code = filter_var($_POST['depcode'], FILTER_SANITIZE_STRING);
    $lvl_code = filter_var($_POST['lvlcode'], FILTER_SANITIZE_STRING);
    $cat_code = filter_var($_POST['catcode'], FILTER_SANITIZE_STRING);
    $avail = $course->checkCsCode($cos_code);

    if ($avail == 'taken') {
        //echo "exists course";
        $avail2 = $course->checkCsAssign($cos_code, $dep_code, $lvl_code, $sem_code);
        if ($avail2 == 'exist') {
            echo ("assigned");
            exit();
        } else {
            $course->assignCourse($cos_code, $dep_code, $lvl_code, $sem_code, $cat_code);
            echo ("saved");

            exit();
        }
    } else {
        echo 'Not Exist';
        exit();
    }
}
?>
