/** * Delete selected question (or disable it if used) * @author Nicola Asuni * @since 2008-11-26 * @param $question_id (int) question ID * @param $subject_id (int) subject ID */ function F_question_delete($question_id, $subject_id) { global $l, $db; require_once '../config/tce_config.php'; $question_id = intval($question_id); $subject_id = intval($subject_id); // check if this record is used (test_log) if (!F_check_unique(K_TABLE_TESTS_LOGS, 'testlog_question_id=' . $question_id . '')) { F_question_set_enabled($question_id, false); } else { $sql = 'START TRANSACTION'; if (!($r = F_db_query($sql, $db))) { F_display_db_error(); } // get question position (if defined) $question_position = F_question_get_position($question_id); // delete question $sql = 'DELETE FROM ' . K_TABLE_QUESTIONS . ' WHERE question_id=' . $question_id . ''; if (!($r = F_db_query($sql, $db))) { F_display_db_error(false); F_db_query('ROLLBACK', $db); // rollback transaction } else { // adjust questions ordering if ($question_position > 0) { $sql = 'UPDATE ' . K_TABLE_QUESTIONS . ' SET question_position=question_position-1 WHERE question_subject_id=' . $subject_id . ' AND question_position>' . $question_position . ''; if (!($r = F_db_query($sql, $db))) { F_display_db_error(false); F_db_query('ROLLBACK', $db); // rollback transaction } } $sql = 'COMMIT'; if (!($r = F_db_query($sql, $db))) { F_display_db_error(); } } } }
F_question_delete($question_id, $subject_id); } break; case 'copy': if (isset($new_subject_id) and $new_subject_id > 0) { F_question_copy($question_id, $new_subject_id); } break; case 'delete': F_question_delete($question_id, $subject_id); break; case 'disable': F_question_set_enabled($question_id, false); break; case 'enable': F_question_set_enabled($question_id, true); break; } // end of switch } } F_print_error('MESSAGE', $l['m_updated']); } echo '<div class="container">' . K_NEWLINE; echo '<div class="tceformbox">' . K_NEWLINE; echo '<form action="' . $_SERVER['SCRIPT_NAME'] . '" method="post" enctype="multipart/form-data" id="form_selectquestions">' . K_NEWLINE; echo '<div class="row">' . K_NEWLINE; echo '<span class="label">' . K_NEWLINE; echo '<label for="subject_module_id">' . $l['w_module'] . '</label>' . K_NEWLINE; echo '</span>' . K_NEWLINE; echo '<span class="formw">' . K_NEWLINE;