require_once $_SERVER['DOCUMENT_ROOT'] . "/exam-simulator/private/functions/input.php";
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $examID = fix_string($_POST['examID']);
    $question = fix_string($_POST['question']);
    $question_type = fix_string($_POST['questionType']);
    $questionID = fix_string($_POST['questionID']);
    edit_question($examID, $question, $questionID);
    switch ($question_type) {
        case 'mult_answers':
            $json_assoc_array = json_decode($_POST['answers']);
            $mult_answers = fix_input_assoc_array($json_assoc_array);
            // assoc array e.g {answer : 'true'}
            delete_answers($questionID, $question_type);
            create_multiple_choice_answers($questionID, $mult_answers);
            break;
        case 'single_answers':
            $answer = fix_string($_POST['answer']);
            delete_answers($questionID, $question_type);
            create_single_answer($answer, $questionID);
            break;
        case 'keyword_answers':
            $keywords = json_decode($_POST['answers']);
            $keywords = fix_input_array($keywords);
            remove_non_alphanumeric($keywords);
            delete_answers($questionID, $question_type);
            create_keyword_answers($questionID, $keywords);
            break;
    }
} else {
    go_home();
}
function cancel_request()
{
    $request_id = addslashes($_REQUEST["request_id"]);
    $DB = new DB();
    $query = "DELETE FROM tutor_request\n             WHERE id={$request_id}";
    $DB->query($query);
    delete_answers($request_id);
}