include $_SERVER['DOCUMENT_ROOT'] . "/WebBuilder/WebApp.class.php";
$db = new DBMain();
echo "
name: " . $_POST['test_name'];
echo "
info: " . $_POST['test_description'];
echo "
ngl: " . $_POST['nqf_level'];
echo "
credits: " . $_POST['credits'];
echo "
Sections total: " . $_POST['sections_total'];
echo "
Passmark: " . $_POST['passmark'];
$test_id = $_POST['test_id'];
var_dump($_POST);
echo "
";
$record = $db->Update('tests', ['test_name', 'test_description', 'nqf_level', 'credits', 'passmark'], [$_POST['test_name'], $_POST['test_description'], $_POST['nqf_level'], $_POST['credits'], $_POST['passmark']], "record_id = {$_POST['test_id']}");
echo "UPDATE FUNCTION"."`tests` SET `test_name` = '{$_POST['test_name']}', `test_description` = '{$_POST['test_description']}', `nqf_level` = '{$_POST['nqf_level']}', `credits` = '{$_POST['credits']}', `passmark` = '{$_POST['passmark']}' WHERE `record_id` = {$_POST['test_id']}
";
$db->delete_query("DELETE FROM `test_questions` WHERE `test_id` = {$_POST['test_id']}");
echo "DELETE FUNCTION"."`test_questions` WHERE `test_id` = $test_id
";
$index = 0;
while ($index <= $_POST['sections_total']) {
echo "
I: " . $index;
echo "
section_name: " . $_POST["section_" . $index . "_name"];
if (strlen($_POST["section_" . $index . "_name"]) != 0) {
$db->Update('test_questions', ['section_name'], [$_POST["section_" . $index . "_name"]], "record_id = {$_POST["section_$index" . "_id"]}");
echo "UPDATE FUNCTION"."`test_questions` SET `section_name` = '{$_POST["section_" . $index . "_name"]}' WHERE `record_id` = {$_POST["section_$index" . "_id"]}
";
$section_id = $db->insert("INSERT INTO `test_questions` (`test_id`,`section_name`) VALUES ($test_id,'{$_POST["section_" .$index . "_name"]}')");
echo "INSERT FUNCTION"."`test_questions` (`test_id`,`section_name`) VALUES ($test_id,'{$_POST["section_" . $index . "_name"]}')
";
echo "
test_section_id: " . $section_id;
$db->delete_query("DELETE FROM `test_answers` WHERE `test_question_id` = {$_POST["section_$index" . "_id"]}");
echo "section id: ".$_POST["section_$index" . "_id"]."
";
echo "DELETE FUNCTION"."`test_answers` WHERE `test_question_id` = $section_id
";
$a_index = 0;
while ($a_index <= $_POST['row_count_' . $index]) {
$answer = $_POST[$index . "_answer_$a_index"];
if (strlen($answer) != 0) {
echo "
answer: " . $answer;
$db->insert("INSERT INTO `test_answers` (`test_question_id`,`answer`,`option`) VALUES ($section_id,'$answer','{$_POST[$index . "_change_value_$a_index"]}')");
echo "
answer: " . $answer;
echo "
change_value: " . $_POST[$index . "_change_value_$a_index"] ."
";
echo "INSERT FUNCTION"."`test_answers` (`test_question_id`,`answer`,`option`) VALUES ($section_id,'$answer','{$_POST[$index . "_change_value_$a_index"]}')
";
} else {
echo "
SKIPPED answer $index _answer_$a_index: " . $answer;
echo $index . "_change_value_$a_index";
echo "
change_value: " . $_POST[$index . "_change_value_$a_index"];
}
$a_index++;
}
} else {
echo "
section_name: " . $_POST["section_" . $index . "_name"];
}
$index++;
}
echo "";