<?php

include('phpClasses/Faculty.php');
$faculty = new Faculty();

if (isset($_POST['falcode_check'])) {
    $fal_code = $_POST['falcode'];
    //console_log( $fal_code );
    $avail = $faculty->checkFacCode($fal_code);
    if ($avail == 'taken') {
        echo "taken";
        exit();
    } else {
        echo 'not_taken';
        exit();
    }
    exit();
}

if (isset($_POST['save'])) {
    $fal_code = $_POST['falcode'];
    $description= $_POST['description'];
     $avail = $faculty->checkFacCode($fal_code);
    if ($avail == 'taken') {
        echo "exists";
        exit();
    } else {
        $faculty->insertFaculty($fal_code, $description);
        echo 'Saved!';
        exit();
    }
}
?>
