if (isset($_REQUEST['repaginate']) and confirm_sesskey()) { /// Re-paginate the quiz if (isset($_REQUEST['questionsperpage'])) { $quiz->questionsperpage = required_param('questionsperpage', PARAM_INT); if (!set_field('quiz', 'questionsperpage', $quiz->questionsperpage, 'id', $quiz->id)) { error('Could not save number of questions per page'); } } $quiz->questions = quiz_repaginate($quiz->questions, $quiz->questionsperpage); if (!set_field('quiz', 'questions', $quiz->questions, 'id', $quiz->id)) { error('Could not save layout'); } } if (isset($_REQUEST['delete']) and confirm_sesskey()) { /// Remove a question from the quiz quiz_delete_quiz_question($_REQUEST['delete'], $quiz); } if (isset($_REQUEST['savechanges']) and confirm_sesskey()) { /// We need to save the new ordering (if given) and the new grades $oldquestions = explode(",", $quiz->questions); // the questions in the old order $questions = array(); // for questions in the new order $rawgrades = $_POST; unset($quiz->grades); foreach ($rawgrades as $key => $value) { // Parse input for question -> grades if (preg_match('!^q([0-9]+)$!', $key, $matches)) { $key = $matches[1]; $quiz->grades[$key] = $value; quiz_update_question_instance($quiz->grades[$key], $key, $quiz->instance);
$questionsperpage = optional_param('questionsperpage', $quiz->questionsperpage, PARAM_INT); if ($questionsperpage != $quiz->questionsperpage) { $quiz->questionsperpage = $questionsperpage; if (!set_field('quiz', 'questionsperpage', $quiz->questionsperpage, 'id', $quiz->id)) { error('Could not save number of questions per page'); } } $quiz->questions = quiz_repaginate($quiz->questions, $quiz->questionsperpage); if (!set_field('quiz', 'questions', $quiz->questions, 'id', $quiz->id)) { error('Could not save layout'); } $significantchangemade = true; } if (($delete = optional_param('delete', false, PARAM_INT)) !== false and confirm_sesskey()) { /// Remove a question from the quiz quiz_delete_quiz_question($delete, $quiz); $significantchangemade = true; } if (optional_param('savechanges', false, PARAM_BOOL) and confirm_sesskey()) { /// We need to save the new ordering (if given) and the new grades $oldquestions = explode(",", $quiz->questions); // the questions in the old order $questions = array(); // for questions in the new order $rawgrades = (array) data_submitted(); unset($quiz->grades); foreach ($rawgrades as $key => $value) { /// Parse input for question -> grades if (preg_match('!^q([0-9]+)$!', $key, $matches)) { $key = $matches[1]; $quiz->grades[$key] = clean_param($value, PARAM_INTEGER);
if (isset($_REQUEST['repaginate']) and confirm_sesskey()) { /// Re-paginate the quiz if (isset($_REQUEST['questionsperpage'])) { $modform->questionsperpage = required_param('questionsperpage', PARAM_INT); if (!set_field('quiz', 'questionsperpage', $modform->questionsperpage, 'id', $modform->id)) { error('Could not save number of questions per page'); } } $modform->questions = quiz_repaginate($modform->questions, $modform->questionsperpage); if (!set_field('quiz', 'questions', $modform->questions, 'id', $modform->id)) { error('Could not save layout'); } } if (isset($_REQUEST['delete']) and confirm_sesskey()) { /// Remove a question from the quiz quiz_delete_quiz_question($_REQUEST['delete'], $modform); } if (isset($_REQUEST['savechanges']) and confirm_sesskey()) { $savequizid = required_param('savequizid', PARAM_INT); if ($modform->id != $savequizid) { error("Error saving quiz settings, please do not change two quizes from the same browser", $CFG->wwwroot . '/mod/quiz/edit.php?quizid=' . $savequizid); } /// We need to save the new ordering (if given) and the new grades $oldquestions = explode(",", $modform->questions); // the questions in the old order $questions = array(); // for questions in the new order $rawgrades = $_POST; unset($modform->grades); foreach ($rawgrades as $key => $value) { // Parse input for question -> grades