MDL-33532 quiz editing: let uses enter locale floats.
[moodle.git] / mod / quiz / edit.php
CommitLineData
83192608 1<?php
f9b0500f
TH
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
f4b879dd 17
ee1fb969 18/**
7ca4613b 19 * Page to edit quizzes
20 *
21 * This page generally has two columns:
22 * The right column lists all available questions in a chosen category and
23 * allows them to be edited or more to be added. This column is only there if
24 * the quiz does not already have student attempts
25 * The left column lists all questions that have been added to the current quiz.
26 * The lecturer can add questions from the right hand list to the quiz or remove them
27 *
28 * The script also processes a number of actions:
29 * Actions affecting a quiz:
30 * up and down Changes the order of questions and page breaks
31 * addquestion Adds a single question to the quiz
32 * add Adds several selected questions to the quiz
33 * addrandom Adds a certain number of random questions to the quiz
34 * repaginate Re-paginates the quiz
35 * delete Removes a question from the quiz
36 * savechanges Saves the order and grades for questions in the quiz
37 *
ba643847 38 * @package mod
f9b0500f 39 * @subpackage quiz
ba643847
TH
40 * @copyright 1999 onwards Martin Dougiamas and others {@link http://moodle.com}
41 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
f9b0500f
TH
42 */
43
f4b879dd 44
324d6576 45require_once('../../config.php');
46require_once($CFG->dirroot . '/mod/quiz/editlib.php');
94dbfb3a 47require_once($CFG->dirroot . '/mod/quiz/addrandomform.php');
324d6576 48require_once($CFG->dirroot . '/question/category_class.php');
fa583f5f 49
f9b0500f 50
fa583f5f 51/**
52 * Callback function called from question_list() function
53 * (which is called from showbank())
54 * Displays button in form with checkboxes for each question.
55 */
324d6576 56function module_specific_buttons($cmid, $cmoptions) {
92e01ab7 57 global $OUTPUT;
76cf77e4
TH
58 $params = array(
59 'type' => 'submit',
60 'name' => 'add',
61 'value' => $OUTPUT->larrow() . ' ' . get_string('addtoquiz', 'quiz'),
62 );
324d6576 63 if ($cmoptions->hasattempts) {
76cf77e4 64 $params['disabled'] = 'disabled';
324d6576 65 }
76cf77e4 66 return html_writer::empty_tag('input', $params);
fa583f5f 67}
271e6dec 68
fa583f5f 69/**
70 * Callback function called from question_list() function
71 * (which is called from showbank())
72 */
324d6576 73function module_specific_controls($totalnumber, $recurse, $category, $cmid, $cmoptions) {
f9b0500f 74 global $OUTPUT;
fa583f5f 75 $out = '';
76 $catcontext = get_context_instance_by_id($category->contextid);
324d6576 77 if (has_capability('moodle/question:useall', $catcontext)) {
78 if ($cmoptions->hasattempts) {
94dbfb3a 79 $disabled = ' disabled="disabled"';
324d6576 80 } else {
81 $disabled = '';
fa583f5f 82 }
68b1b19b 83 $randomusablequestions =
f9b0500f
TH
84 question_bank::get_qtype('random')->get_available_questions_from_category(
85 $category->id, $recurse);
fa583f5f 86 $maxrand = count($randomusablequestions);
87 if ($maxrand > 0) {
324d6576 88 for ($i = 1; $i <= min(10, $maxrand); $i++) {
fa583f5f 89 $randomcount[$i] = $i;
85c375c3 90 }
324d6576 91 for ($i = 20; $i <= min(100, $maxrand); $i += 10) {
fa583f5f 92 $randomcount[$i] = $i;
93 }
94dbfb3a
TH
94 } else {
95 $randomcount[0] = 0;
96 $disabled = ' disabled="disabled"';
85c375c3 97 }
94dbfb3a
TH
98
99 $out = '<strong><label for="menurandomcount">'.get_string('addrandomfromcategory', 'quiz').
100 '</label></strong><br />';
101 $attributes = array();
102 $attributes['disabled'] = $disabled ? 'disabled' : null;
103 $select = html_writer::select($randomcount, 'randomcount', '1', null, $attributes);
104 $out .= get_string('addrandom', 'quiz', $select);
105 $out .= '<input type="hidden" name="recurse" value="'.$recurse.'" />';
106 $out .= '<input type="hidden" name="categoryid" value="' . $category->id . '" />';
107 $out .= ' <input type="submit" name="addrandom" value="'.
108 get_string('addtoquiz', 'quiz').'"' . $disabled . ' />';
109 $out .= $OUTPUT->help_icon('addarandomquestion', 'quiz');
271e6dec 110 }
fa583f5f 111 return $out;
112}
271e6dec 113
9e83f3d1
TH
114// These params are only passed from page request to request while we stay on
115// this page otherwise they would go in question_edit_setup.
eb02301a 116$quiz_reordertool = optional_param('reordertool', -1, PARAM_BOOL);
56ed242b 117$quiz_qbanktool = optional_param('qbanktool', -1, PARAM_BOOL);
fd214b59 118$scrollpos = optional_param('scrollpos', '', PARAM_INT);
56ed242b 119
fa583f5f 120list($thispageurl, $contexts, $cmid, $cm, $quiz, $pagevars) =
453b28d8 121 question_edit_setup('editq', '/mod/quiz/edit.php', true);
f9b0500f 122$quiz->questions = quiz_clean_layout($quiz->questions);
fa583f5f 123
124$defaultcategoryobj = question_make_default_categories($contexts->all());
94dbfb3a 125$defaultcategory = $defaultcategoryobj->id . ',' . $defaultcategoryobj->contextid;
324d6576 126
fa583f5f 127if ($quiz_qbanktool > -1) {
128 $thispageurl->param('qbanktool', $quiz_qbanktool);
324d6576 129 set_user_preference('quiz_qbanktool_open', $quiz_qbanktool);
fa583f5f 130} else {
324d6576 131 $quiz_qbanktool = get_user_preferences('quiz_qbanktool_open', 0);
fa583f5f 132}
133
eb02301a
TH
134if ($quiz_reordertool > -1) {
135 $thispageurl->param('reordertool', $quiz_reordertool);
136 set_user_preference('quiz_reordertab', $quiz_reordertool);
137} else {
138 $quiz_reordertool = get_user_preferences('quiz_reordertab', 0);
139}
140
76cf77e4
TH
141$canaddrandom = $contexts->have_cap('moodle/question:useall');
142$canaddquestion = (bool) $contexts->having_add_and_use();
143
3e10e429 144$quizhasattempts = quiz_has_attempts($quiz->id);
fa583f5f 145
eb02301a 146$PAGE->set_url($thispageurl);
fa583f5f 147
16cad79b 148$pagetitle = get_string('editingquiz', 'quiz');
324d6576 149if ($quiz_reordertool) {
16cad79b 150 $pagetitle = get_string('orderingquiz', 'quiz');
fa583f5f 151}
152// Get the course object and related bits.
324d6576 153$course = $DB->get_record('course', array('id' => $quiz->course));
154if (!$course) {
fa583f5f 155 print_error('invalidcourseid', 'error');
156}
157
612106b3 158$questionbank = new quiz_question_bank_view($contexts, $thispageurl, $course, $cm, $quiz);
3e10e429 159$questionbank->set_quiz_has_attempts($quizhasattempts);
971c6fca 160
fa583f5f 161// Log this visit.
162add_to_log($cm->course, 'quiz', 'editquestions',
b72ff476 163 "view.php?id=$cm->id", "$quiz->id", $cm->id);
5cae1205 164
324d6576 165// You need mod/quiz:manage in addition to question capabilities to access this page.
fa583f5f 166require_capability('mod/quiz:manage', $contexts->lowest());
7bd1aa1d 167
f9b0500f 168if (empty($quiz->grades)) {
fa583f5f 169 $quiz->grades = quiz_get_all_question_grades($quiz);
170}
32a189d6 171
4299df1d 172// Process commands ============================================================
3e10e429 173if ($quiz->shufflequestions) {
174 // Strip page breaks before processing actions, so that re-ordering works
175 // as expected when shuffle questions is on.
176 $quiz->questions = quiz_repaginate($quiz->questions, 0);
177}
4299df1d 178
179// Get the list of question ids had their check-boxes ticked.
180$selectedquestionids = array();
181$params = (array) data_submitted();
182foreach ($params as $key => $value) {
183 if (preg_match('!^s([0-9]+)$!', $key, $matches)) {
184 $selectedquestionids[] = $matches[1];
6a952ce7 185 }
fa583f5f 186}
187
fd214b59
TH
188$afteractionurl = new moodle_url($thispageurl);
189if ($scrollpos) {
190 $afteractionurl->param('scrollpos', $scrollpos);
191}
4299df1d 192if (($up = optional_param('up', false, PARAM_INT)) && confirm_sesskey()) {
193 $quiz->questions = quiz_move_question_up($quiz->questions, $up);
f9b0500f
TH
194 $DB->set_field('quiz', 'questions', $quiz->questions, array('id' => $quiz->id));
195 quiz_delete_previews($quiz);
fd214b59 196 redirect($afteractionurl);
4299df1d 197}
198
199if (($down = optional_param('down', false, PARAM_INT)) && confirm_sesskey()) {
200 $quiz->questions = quiz_move_question_down($quiz->questions, $down);
f9b0500f
TH
201 $DB->set_field('quiz', 'questions', $quiz->questions, array('id' => $quiz->id));
202 quiz_delete_previews($quiz);
fd214b59 203 redirect($afteractionurl);
4299df1d 204}
205
206if (optional_param('repaginate', false, PARAM_BOOL) && confirm_sesskey()) {
9e83f3d1 207 // Re-paginate the quiz.
4299df1d 208 $questionsperpage = optional_param('questionsperpage', $quiz->questionsperpage, PARAM_INT);
209 $quiz->questions = quiz_repaginate($quiz->questions, $questionsperpage );
f9b0500f
TH
210 $DB->set_field('quiz', 'questions', $quiz->questions, array('id' => $quiz->id));
211 quiz_delete_previews($quiz);
fd214b59 212 redirect($afteractionurl);
fa583f5f 213}
324d6576 214
215if (($addquestion = optional_param('addquestion', 0, PARAM_INT)) && confirm_sesskey()) {
9e83f3d1 216 // Add a single question to the current quiz.
76cf77e4 217 quiz_require_question_use($addquestion);
324d6576 218 $addonpage = optional_param('addonpage', 0, PARAM_INT);
fa583f5f 219 quiz_add_quiz_question($addquestion, $quiz, $addonpage);
4299df1d 220 quiz_delete_previews($quiz);
f9b0500f 221 quiz_update_sumgrades($quiz);
455d765f 222 $thispageurl->param('lastchanged', $addquestion);
fd214b59 223 redirect($afteractionurl);
fa583f5f 224}
225
324d6576 226if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
9e83f3d1 227 // Add selected questions to the current quiz.
fa583f5f 228 $rawdata = (array) data_submitted();
9e83f3d1 229 foreach ($rawdata as $key => $value) { // Parse input for question ids.
fa583f5f 230 if (preg_match('!^q([0-9]+)$!', $key, $matches)) {
231 $key = $matches[1];
76cf77e4 232 quiz_require_question_use($key);
fa583f5f 233 quiz_add_quiz_question($key, $quiz);
fef9b51d 234 }
fef9b51d 235 }
4299df1d 236 quiz_delete_previews($quiz);
f9b0500f 237 quiz_update_sumgrades($quiz);
fd214b59 238 redirect($afteractionurl);
fa583f5f 239}
240
94dbfb3a 241if ((optional_param('addrandom', false, PARAM_BOOL)) && confirm_sesskey()) {
9e83f3d1 242 // Add random questions to the quiz.
fa583f5f 243 $recurse = optional_param('recurse', 0, PARAM_BOOL);
324d6576 244 $addonpage = optional_param('addonpage', 0, PARAM_INT);
94dbfb3a
TH
245 $categoryid = required_param('categoryid', PARAM_INT);
246 $randomcount = required_param('randomcount', PARAM_INT);
247 quiz_add_random_questions($quiz, $addonpage, $categoryid, $randomcount, $recurse);
6a952ce7 248
4299df1d 249 quiz_delete_previews($quiz);
f9b0500f 250 quiz_update_sumgrades($quiz);
fd214b59 251 redirect($afteractionurl);
fa583f5f 252}
324d6576 253
25a03faa
TH
254if (optional_param('addnewpagesafterselected', null, PARAM_CLEAN) &&
255 !empty($selectedquestionids) && confirm_sesskey()) {
4299df1d 256 foreach ($selectedquestionids as $questionid) {
257 $quiz->questions = quiz_add_page_break_after($quiz->questions, $questionid);
fa583f5f 258 }
f9b0500f
TH
259 $DB->set_field('quiz', 'questions', $quiz->questions, array('id' => $quiz->id));
260 quiz_delete_previews($quiz);
fd214b59 261 redirect($afteractionurl);
fa583f5f 262}
271e6dec 263
324d6576 264$addpage = optional_param('addpage', false, PARAM_INT);
4299df1d 265if ($addpage !== false && confirm_sesskey()) {
266 $quiz->questions = quiz_add_page_break_at($quiz->questions, $addpage);
f9b0500f
TH
267 $DB->set_field('quiz', 'questions', $quiz->questions, array('id' => $quiz->id));
268 quiz_delete_previews($quiz);
fd214b59 269 redirect($afteractionurl);
fa583f5f 270}
6a952ce7 271
324d6576 272$deleteemptypage = optional_param('deleteemptypage', false, PARAM_INT);
273if (($deleteemptypage !== false) && confirm_sesskey()) {
4299df1d 274 $quiz->questions = quiz_delete_empty_page($quiz->questions, $deleteemptypage);
f9b0500f
TH
275 $DB->set_field('quiz', 'questions', $quiz->questions, array('id' => $quiz->id));
276 quiz_delete_previews($quiz);
fd214b59 277 redirect($afteractionurl);
fa583f5f 278}
4e6f553d 279
4299df1d 280$remove = optional_param('remove', false, PARAM_INT);
76cf77e4
TH
281if ($remove && confirm_sesskey()) {
282 // Remove a question from the quiz.
283 // We require the user to have the 'use' capability on the question,
284 // so that then can add it back if they remove the wrong one by mistake.
285 quiz_require_question_use($remove);
4299df1d 286 quiz_remove_question($quiz, $remove);
4299df1d 287 quiz_delete_previews($quiz);
18dff757 288 quiz_update_sumgrades($quiz);
fd214b59 289 redirect($afteractionurl);
fa583f5f 290}
ee1fb969 291
25a03faa
TH
292if (optional_param('quizdeleteselected', false, PARAM_BOOL) &&
293 !empty($selectedquestionids) && confirm_sesskey()) {
4299df1d 294 foreach ($selectedquestionids as $questionid) {
76cf77e4
TH
295 if (quiz_has_question_use($questionid)) {
296 quiz_remove_question($quiz, $questionid);
297 }
b37cacae 298 }
4299df1d 299 quiz_delete_previews($quiz);
f9b0500f 300 quiz_update_sumgrades($quiz);
fd214b59 301 redirect($afteractionurl);
fa583f5f 302}
303
324d6576 304if (optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) {
f9b0500f
TH
305 $deletepreviews = false;
306 $recomputesummarks = false;
307
9e83f3d1
TH
308 $oldquestions = explode(',', $quiz->questions); // The questions in the old order.
309 $questions = array(); // For questions in the new order.
3e10e429 310 $rawdata = (array) data_submitted();
fa583f5f 311 $moveonpagequestions = array();
3e10e429 312 $moveselectedonpage = optional_param('moveselectedonpagetop', 0, PARAM_INT);
313 if (!$moveselectedonpage) {
314 $moveselectedonpage = optional_param('moveselectedonpagebottom', 0, PARAM_INT);
fa583f5f 315 }
70c01adb 316
3e10e429 317 foreach ($rawdata as $key => $value) {
4299df1d 318 if (preg_match('!^g([0-9]+)$!', $key, $matches)) {
9e83f3d1 319 // Parse input for question -> grades.
3e10e429 320 $questionid = $matches[1];
7f5f3844 321 $quiz->grades[$questionid] = unformat_float($value);
f9b0500f
TH
322 quiz_update_question_instance($quiz->grades[$questionid], $questionid, $quiz);
323 $deletepreviews = true;
324 $recomputesummarks = true;
b72ff476 325
3e10e429 326 } else if (preg_match('!^o(pg)?([0-9]+)$!', $key, $matches)) {
9e83f3d1 327 // Parse input for ordering info.
3e10e429 328 $questionid = $matches[2];
329 // Make sure two questions don't overwrite each other. If we get a second
330 // question with the same position, shift the second one along to the next gap.
51b9ccc0 331 $value = clean_param($value, PARAM_INTEGER);
fa583f5f 332 while (array_key_exists($value, $questions)) {
333 $value++;
334 }
3e10e429 335 if ($matches[1]) {
336 // This is a page-break entry.
337 $questions[$value] = 0;
338 } else {
339 $questions[$value] = $questionid;
340 }
f9b0500f 341 $deletepreviews = true;
fa583f5f 342 }
343 }
4299df1d 344
9e83f3d1 345 // If ordering info was given, reorder the questions.
fa583f5f 346 if ($questions) {
347 ksort($questions);
3e10e429 348 $questions[] = 0;
349 $quiz->questions = implode(',', $questions);
f9b0500f
TH
350 $DB->set_field('quiz', 'questions', $quiz->questions, array('id' => $quiz->id));
351 $deletepreviews = true;
fa583f5f 352 }
4299df1d 353
9e83f3d1
TH
354 // Get a list of questions to move, later to be added in the appropriate
355 // place in the string.
4299df1d 356 if ($moveselectedonpage) {
324d6576 357 $questions = explode(',', $quiz->questions);
3e10e429 358 $newquestions = array();
9e83f3d1 359 // Remove the questions from their original positions first.
3e10e429 360 foreach ($questions as $questionid) {
361 if (!in_array($questionid, $selectedquestionids)) {
362 $newquestions[] = $questionid;
218dfb91 363 }
364 }
324d6576 365 $questions = $newquestions;
366
9e83f3d1 367 // Move to the end of the selected page.
3e10e429 368 $pagebreakpositions = array_keys($questions, 0);
369 $numpages = count($pagebreakpositions);
800944b0 370
3e10e429 371 // Ensure the target page number is in range.
800944b0
TH
372 for ($i = $moveselectedonpage; $i > $numpages; $i--) {
373 $questions[] = 0;
374 $pagebreakpositions[] = count($questions) - 1;
375 }
324d6576 376 $moveselectedpos = $pagebreakpositions[$moveselectedonpage - 1];
800944b0
TH
377
378 // Do the move.
3e10e429 379 array_splice($questions, $moveselectedpos, 0, $selectedquestionids);
324d6576 380 $quiz->questions = implode(',', $questions);
800944b0
TH
381
382 // Update the database.
f9b0500f
TH
383 $DB->set_field('quiz', 'questions', $quiz->questions, array('id' => $quiz->id));
384 $deletepreviews = true;
fa583f5f 385 }
3e10e429 386
9e83f3d1 387 // If rescaling is required save the new maximum.
7f5f3844 388 $maxgrade = unformat_float(optional_param('maxgrade', -1, PARAM_RAW));
fa583f5f 389 if ($maxgrade >= 0) {
3e10e429 390 quiz_set_grade($maxgrade, $quiz);
70c01adb 391 }
ee1fb969 392
f9b0500f
TH
393 if ($deletepreviews) {
394 quiz_delete_previews($quiz);
395 }
396 if ($recomputesummarks) {
397 quiz_update_sumgrades($quiz);
398 quiz_update_all_attempt_sumgrades($quiz);
399 quiz_update_all_final_grades($quiz);
400 quiz_update_grades($quiz, 0, true);
401 }
fd214b59 402 redirect($afteractionurl);
fa583f5f 403}
6551bb89 404
f4b879dd 405$questionbank->process_actions($thispageurl, $cm);
b37cacae 406
4299df1d 407// End of process commands =====================================================
fa583f5f 408
1a0e96c7
TH
409$PAGE->requires->yui2_lib('container');
410$PAGE->requires->yui2_lib('dragdrop');
25a03faa
TH
411$PAGE->requires->skip_link_to('questionbank',
412 get_string('skipto', 'access', get_string('questionbank', 'question')));
413$PAGE->requires->skip_link_to('quizcontentsblock',
414 get_string('skipto', 'access', get_string('questionsinthisquiz', 'quiz')));
03da0c39 415$PAGE->set_title($pagetitle);
56ed242b 416$PAGE->set_heading($course->fullname);
eb02301a
TH
417$node = $PAGE->settingsnav->find('mod_quiz_edit', navigation_node::TYPE_SETTING);
418if ($node) {
419 $node->make_active();
420}
03da0c39 421echo $OUTPUT->header();
6f030b0f 422
1372b5d2 423// Initialise the JavaScript.
0ff4bd08 424$quizeditconfig = new stdClass();
b9bc2019 425$quizeditconfig->url = $thispageurl->out(true, array('qbanktool' => '0'));
3e10e429 426$quizeditconfig->dialoglisteners = array();
1372b5d2 427$numberoflisteners = max(quiz_number_of_pages($quiz->questions), 1);
428for ($pageiter = 1; $pageiter <= $numberoflisteners; $pageiter++) {
429 $quizeditconfig->dialoglisteners[] = 'addrandomdialoglaunch_' . $pageiter;
430}
cf615522 431$PAGE->requires->data_for_js('quiz_edit_config', $quizeditconfig);
fd214b59 432$PAGE->requires->js('/question/qengine.js');
9dec75db 433$PAGE->requires->js('/mod/quiz/edit.js');
fd214b59 434$PAGE->requires->js_init_call('quiz_edit_init');
1372b5d2 435
eb02301a
TH
436// Print the tabs to switch mode.
437if ($quiz_reordertool) {
438 $currenttab = 'reorder';
439} else {
440 $currenttab = 'edit';
fa583f5f 441}
eb02301a 442$tabs = array(array(
25a03faa
TH
443 new tabobject('edit', new moodle_url($thispageurl,
444 array('reordertool' => 0)), get_string('editingquiz', 'quiz')),
445 new tabobject('reorder', new moodle_url($thispageurl,
446 array('reordertool' => 1)), get_string('orderingquiz', 'quiz')),
eb02301a
TH
447));
448print_tabs($tabs, $currenttab);
fa583f5f 449
324d6576 450if ($quiz_qbanktool) {
451 $bankclass = '';
452 $quizcontentsclass = '';
453} else {
e6fb2c60 454 $bankclass = 'collapsed ';
324d6576 455 $quizcontentsclass = 'quizwhenbankcollapsed';
456}
5669badf 457
6605ff8c 458echo '<div class="questionbankwindow ' . $bankclass . 'block">';
e6fb2c60 459echo '<div class="header"><div class="title"><h2>';
460echo get_string('questionbankcontents', 'quiz') .
b9bc2019 461 ' <a href="' . $thispageurl->out(true, array('qbanktool' => '1')) .
e6fb2c60 462 '" id="showbankcmd">[' . get_string('show').
463 ']</a>
b9bc2019 464 <a href="' . $thispageurl->out(true, array('qbanktool' => '0')) .
e6fb2c60 465 '" id="hidebankcmd">[' . get_string('hide').
466 ']</a>';
467echo '</h2></div></div><div class="content">';
468
5669badf 469echo '<span id="questionbank"></span>';
1cdbd5e4 470echo '<div class="container">';
fa583f5f 471echo '<div id="module" class="module">';
472echo '<div class="bd">';
5bd22790 473$questionbank->display('editq',
fa583f5f 474 $pagevars['qpage'],
b72b4137 475 $pagevars['qperpage'],
fa583f5f 476 $pagevars['cat'], $pagevars['recurse'], $pagevars['showhidden'],
e20ad67d 477 $pagevars['qbshowtext']);
324d6576 478echo '</div>';
479echo '</div>';
480echo '</div>';
a5cb8d69 481
e6fb2c60 482echo '</div></div>';
fa583f5f 483
324d6576 484echo '<div class="quizcontents ' . $quizcontentsclass . '" id="quizcontentsblock">';
3e10e429 485if ($quiz->shufflequestions) {
324d6576 486 $repaginatingdisabledhtml = 'disabled="disabled"';
487 $repaginatingdisabled = true;
3e10e429 488 $quiz->questions = quiz_repaginate($quiz->questions, $quiz->questionsperpage);
324d6576 489} else {
490 $repaginatingdisabledhtml = '';
491 $repaginatingdisabled = false;
492}
493if ($quiz_reordertool) {
25a03faa
TH
494 echo '<div class="repaginatecommand"><button id="repaginatecommand" ' .
495 $repaginatingdisabledhtml.'>'.
324d6576 496 get_string('repaginatecommand', 'quiz').'...</button>';
fa583f5f 497 echo '</div>';
498}
16cad79b
TH
499
500if ($quiz_reordertool) {
501 echo $OUTPUT->heading_with_help(get_string('orderingquiz', 'quiz') . ': ' . $quiz->name,
502 'orderandpaging', 'quiz');
503} else {
504 echo $OUTPUT->heading(get_string('editingquiz', 'quiz') . ': ' . $quiz->name, 2);
505 echo $OUTPUT->help_icon('editingquiz', 'quiz', get_string('basicideasofquiz', 'quiz'));
506}
3e10e429 507quiz_print_status_bar($quiz);
fa583f5f 508
3e10e429 509$tabindex = 0;
18dff757 510quiz_print_grading_form($quiz, $thispageurl, $tabindex);
3e10e429 511
512$notifystrings = array();
513if ($quizhasattempts) {
a49cb927 514 $reviewlink = quiz_attempt_summary_link_to_reports($quiz, $cm, $contexts->lowest());
3e10e429 515 $notifystrings[] = get_string('cannoteditafterattempts', 'quiz', $reviewlink);
324d6576 516}
3e10e429 517if ($quiz->shufflequestions) {
324d6576 518 $updateurl = new moodle_url("$CFG->wwwroot/course/mod.php",
519 array('return' => 'true', 'update' => $quiz->cmid, 'sesskey' => sesskey()));
3e10e429 520 $updatelink = '<a href="'.$updateurl->out().'">' . get_string('updatethis', '',
521 get_string('modulename', 'quiz')) . '</a>';
522 $notifystrings[] = get_string('shufflequestionsselected', 'quiz', $updatelink);
fa583f5f 523}
3e10e429 524if (!empty($notifystrings)) {
3b1d5cc4 525 echo $OUTPUT->box('<p>' . implode('</p><p>', $notifystrings) . '</p>', 'statusdisplay');
fa583f5f 526}
527
324d6576 528if ($quiz_reordertool) {
94dbfb3a 529 $perpage = array();
fa583f5f 530 $perpage[0] = get_string('allinone', 'quiz');
324d6576 531 for ($i = 1; $i <= 50; ++$i) {
fa583f5f 532 $perpage[$i] = $i;
533 }
324d6576 534 $gostring = get_string('go');
fa583f5f 535 echo '<div id="repaginatedialog"><div class="hd">';
324d6576 536 echo get_string('repaginatecommand', 'quiz');
fa583f5f 537 echo '</div><div class="bd">';
538 echo '<form action="edit.php" method="post">';
539 echo '<fieldset class="invisiblefieldset">';
6ea66ff3 540 echo html_writer::input_hidden_params($thispageurl);
d4a1fcaf 541 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
9e83f3d1 542 // YUI does not submit the value of the submit button so we need to add the value.
fa583f5f 543 echo '<input type="hidden" name="repaginate" value="'.$gostring.'" />';
3224f709
PS
544 $attributes = array();
545 $attributes['disabled'] = $repaginatingdisabledhtml ? 'disabled' : null;
25a03faa
TH
546 $select = html_writer::select(
547 $perpage, 'questionsperpage', $quiz->questionsperpage, null, $attributes);
3224f709 548 print_string('repaginate', 'quiz', $select);
fa583f5f 549 echo '<div class="quizquestionlistcontrols">';
25a03faa
TH
550 echo ' <input type="submit" name="repaginate" value="'. $gostring . '" ' .
551 $repaginatingdisabledhtml.' />';
fa583f5f 552 echo '</div></fieldset></form></div></div>';
553}
fa583f5f 554
56ed242b
SH
555if ($quiz_reordertool) {
556 echo '<div class="reorder">';
557} else {
558 echo '<div class="editq">';
559}
560
76cf77e4
TH
561quiz_print_question_list($quiz, $thispageurl, true, $quiz_reordertool, $quiz_qbanktool,
562 $quizhasattempts, $defaultcategoryobj, $canaddquestion, $canaddrandom);
3e10e429 563echo '</div>';
4e6f553d 564
9e83f3d1 565// Close <div class="quizcontents">.
fa583f5f 566echo '</div>';
567
76cf77e4 568if (!$quiz_reordertool && $canaddrandom) {
94dbfb3a
TH
569 $randomform = new quiz_add_random_form(new moodle_url('/mod/quiz/addrandom.php'), $contexts);
570 $randomform->set_data(array(
571 'category' => $pagevars['cat'],
a530d4a9 572 'returnurl' => $thispageurl->out_as_local_url(false),
94dbfb3a
TH
573 'cmid' => $cm->id,
574 ));
fa583f5f 575 ?>
25a03faa
TH
576 <div id="randomquestiondialog">
577 <div class="hd"><?php print_string('addrandomquestiontoquiz', 'quiz', $quiz->name); ?>
578 <span id="pagenumber"><!-- JavaScript will insert the page number here. -->
579 </span>
580 </div>
581 <div class="bd"><?php
582 $randomform->display();
583 ?></div>
584 </div>
fa583f5f 585 <?php
586}
867847e3 587echo $OUTPUT->footer();