MDL-19976 Changing redirect($url->out()) to redirect($url). NEVER, NEVER use redirect...
[moodle.git] / mod / quiz / edit.php
CommitLineData
d1290cec 1<?php // $Id$
f4b879dd 2
3///////////////////////////////////////////////////////////////////////////
4// //
5// NOTICE OF COPYRIGHT //
6// //
7// Moodle - Modular Object-Oriented Dynamic Learning Environment //
8// http://moodle.org //
9// //
10// Copyright (C) 1999 onwards Martin Dougiamas and others //
11// //
12// This program is free software; you can redistribute it and/or modify //
13// it under the terms of the GNU General Public License as published by //
14// the Free Software Foundation; either version 2 of the License, or //
15// (at your option) any later version. //
16// //
17// This program is distributed in the hope that it will be useful, //
18// but WITHOUT ANY WARRANTY; without even the implied warranty of //
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
20// GNU General Public License for more details: //
21// //
22// http://www.gnu.org/copyleft/gpl.html //
23// //
24///////////////////////////////////////////////////////////////////////////
25
ee1fb969 26/**
7ca4613b 27 * Page to edit quizzes
28 *
29 * This page generally has two columns:
30 * The right column lists all available questions in a chosen category and
31 * allows them to be edited or more to be added. This column is only there if
32 * the quiz does not already have student attempts
33 * The left column lists all questions that have been added to the current quiz.
34 * The lecturer can add questions from the right hand list to the quiz or remove them
35 *
36 * The script also processes a number of actions:
37 * Actions affecting a quiz:
38 * up and down Changes the order of questions and page breaks
39 * addquestion Adds a single question to the quiz
40 * add Adds several selected questions to the quiz
41 * addrandom Adds a certain number of random questions to the quiz
42 * repaginate Re-paginates the quiz
43 * delete Removes a question from the quiz
44 * savechanges Saves the order and grades for questions in the quiz
45 *
7ca4613b 46 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
47 * @package quiz
f4b879dd 48 *//** */
49
324d6576 50require_once('../../config.php');
51require_once($CFG->dirroot . '/mod/quiz/editlib.php');
52require_once($CFG->dirroot . '/question/category_class.php');
25ddb7ef 53$PAGE->requires->yui_lib('container');
54$PAGE->requires->yui_lib('dragdrop');
fa583f5f 55
fa583f5f 56/**
57 * Callback function called from question_list() function
58 * (which is called from showbank())
59 * Displays button in form with checkboxes for each question.
60 */
324d6576 61function module_specific_buttons($cmid, $cmoptions) {
fa583f5f 62 global $THEME;
324d6576 63 if ($cmoptions->hasattempts) {
64 $disabled = 'disabled="disabled" ';
65 } else {
66 $disabled = '';
67 }
68 $straddtoquiz = get_string('addtoquiz', 'quiz');
69 $out = '<input type="submit" name="add" value="' . $THEME->larrow . ' ' . $straddtoquiz .
70 '" ' . $disabled . "/>\n";
fa583f5f 71 return $out;
72}
271e6dec 73
fa583f5f 74/**
75 * Callback function called from question_list() function
76 * (which is called from showbank())
77 */
324d6576 78function module_specific_controls($totalnumber, $recurse, $category, $cmid, $cmoptions) {
c207b6be 79 global $QTYPES;
fa583f5f 80 $out = '';
81 $catcontext = get_context_instance_by_id($category->contextid);
324d6576 82 if (has_capability('moodle/question:useall', $catcontext)) {
83 if ($cmoptions->hasattempts) {
84 $disabled = 'disabled="disabled"';
85 } else {
86 $disabled = '';
fa583f5f 87 }
68b1b19b 88 $randomusablequestions =
89 $QTYPES['random']->get_usable_questions_from_category($category->id, $recurse, '0');
fa583f5f 90 $maxrand = count($randomusablequestions);
91 if ($maxrand > 0) {
324d6576 92 for ($i = 1; $i <= min(10, $maxrand); $i++) {
fa583f5f 93 $randomcount[$i] = $i;
85c375c3 94 }
324d6576 95 for ($i = 20; $i <= min(100, $maxrand); $i += 10) {
fa583f5f 96 $randomcount[$i] = $i;
97 }
324d6576 98 $straddtoquiz = get_string('addtoquiz', 'quiz');
99 $out = '<strong><label for="menurandomcount">'.get_string('addrandomfromcategory', 'quiz').
3e6ad1d7 100 '</label></strong><br />';
fa583f5f 101 $out .= get_string('addrandom', 'quiz', choose_from_menu($randomcount,
324d6576 102 'randomcount', '1', '', '', '', true, $cmoptions->hasattempts));
fa583f5f 103 $out .= '<input type="hidden" name="recurse" value="'.$recurse.'" />';
324d6576 104 $out .= '<input type="hidden" name="categoryid" value="' . $category->id . '" />';
fa583f5f 105 $out .= ' <input type="submit" name="addrandom" value="'.
106 $straddtoquiz.'" '.$disabled.' />';
107 $out .= helpbutton('random', get_string('random', 'quiz'), 'quiz',
108 true, false, '', true);
85c375c3 109 }
271e6dec 110 }
fa583f5f 111 return $out;
112}
271e6dec 113
fa583f5f 114list($thispageurl, $contexts, $cmid, $cm, $quiz, $pagevars) =
115 question_edit_setup('editq', true);
6f030b0f 116$PAGE->set_url('mod/quiz/edit.php', $thispageurl->params());
117$PAGE->set_generaltype('form');
fa583f5f 118
119$defaultcategoryobj = question_make_default_categories($contexts->all());
324d6576 120$defaultcategoryid = $defaultcategoryobj->id;
121$defaultcategorycontext = $defaultcategoryobj->contextid;
122$defaultcategory = $defaultcategoryid . ',' . $defaultcategorycontext;
123
fa583f5f 124//these params are only passed from page request to request while we stay on
125//this page otherwise they would go in question_edit_setup
126$quiz_reordertool = optional_param('reordertool', 0, PARAM_BOOL);
127$quiz_qbanktool = optional_param('qbanktool', -1, PARAM_BOOL);
128if ($quiz_qbanktool > -1) {
129 $thispageurl->param('qbanktool', $quiz_qbanktool);
324d6576 130 set_user_preference('quiz_qbanktool_open', $quiz_qbanktool);
fa583f5f 131} else {
324d6576 132 $quiz_qbanktool = get_user_preferences('quiz_qbanktool_open', 0);
fa583f5f 133}
134
135//will be set further down in the code
3e10e429 136$quizhasattempts = quiz_has_attempts($quiz->id);
fa583f5f 137
138if ($quiz_reordertool != 0) {
139 $thispageurl->param('reordertool', $quiz_reordertool);
140}
141
142$strquizzes = get_string('modulenameplural', 'quiz');
143$strquiz = get_string('modulename', 'quiz');
324d6576 144$streditingquestions = get_string('editquestions', 'quiz');
fa583f5f 145
146//this just does not work for at least finnish, where words are conjugated:
147//$streditingquiz = get_string('editinga', 'moodle', $strquiz);
148$streditingquiz = get_string('editingquiz', 'quiz');
149$strorderingquiz = get_string('orderingquiz', 'quiz');
324d6576 150$pagetitle = $streditingquiz;
151if ($quiz_reordertool) {
152 $pagetitle = $strorderingquiz;
fa583f5f 153}
154// Get the course object and related bits.
324d6576 155$course = $DB->get_record('course', array('id' => $quiz->course));
156if (!$course) {
fa583f5f 157 print_error('invalidcourseid', 'error');
158}
159
971c6fca 160$questionbank = new quiz_question_bank_view($contexts, $thispageurl, $course, $cm);
3e10e429 161$questionbank->set_quiz_has_attempts($quizhasattempts);
971c6fca 162
fa583f5f 163// Log this visit.
164add_to_log($cm->course, 'quiz', 'editquestions',
b72ff476 165 "view.php?id=$cm->id", "$quiz->id", $cm->id);
5cae1205 166
324d6576 167// You need mod/quiz:manage in addition to question capabilities to access this page.
fa583f5f 168require_capability('mod/quiz:manage', $contexts->lowest());
7bd1aa1d 169
3e10e429 170if (empty($quiz->grades)) { // Construct an array to hold all the grades.
fa583f5f 171 $quiz->grades = quiz_get_all_question_grades($quiz);
172}
32a189d6 173
4299df1d 174// Process commands ============================================================
3e10e429 175if ($quiz->shufflequestions) {
176 // Strip page breaks before processing actions, so that re-ordering works
177 // as expected when shuffle questions is on.
178 $quiz->questions = quiz_repaginate($quiz->questions, 0);
179}
4299df1d 180
181// Get the list of question ids had their check-boxes ticked.
182$selectedquestionids = array();
183$params = (array) data_submitted();
184foreach ($params as $key => $value) {
185 if (preg_match('!^s([0-9]+)$!', $key, $matches)) {
186 $selectedquestionids[] = $matches[1];
6a952ce7 187 }
fa583f5f 188}
189
4299df1d 190if (($up = optional_param('up', false, PARAM_INT)) && confirm_sesskey()) {
191 $quiz->questions = quiz_move_question_up($quiz->questions, $up);
192 quiz_save_new_layout($quiz);
e42f153c 193 redirect($thispageurl);
4299df1d 194}
195
196if (($down = optional_param('down', false, PARAM_INT)) && confirm_sesskey()) {
197 $quiz->questions = quiz_move_question_down($quiz->questions, $down);
198 quiz_save_new_layout($quiz);
e42f153c 199 redirect($thispageurl);
4299df1d 200}
201
202if (optional_param('repaginate', false, PARAM_BOOL) && confirm_sesskey()) {
203 // Re-paginate the quiz
204 $questionsperpage = optional_param('questionsperpage', $quiz->questionsperpage, PARAM_INT);
205 $quiz->questions = quiz_repaginate($quiz->questions, $questionsperpage );
206 quiz_save_new_layout($quiz);
fa583f5f 207}
324d6576 208
209if (($addquestion = optional_param('addquestion', 0, PARAM_INT)) && confirm_sesskey()) {
210/// Add a single question to the current quiz
211 $addonpage = optional_param('addonpage', 0, PARAM_INT);
fa583f5f 212 quiz_add_quiz_question($addquestion, $quiz, $addonpage);
4299df1d 213 quiz_update_sumgrades($quiz);
214 quiz_delete_previews($quiz);
e42f153c 215 redirect($thispageurl);
fa583f5f 216}
217
324d6576 218if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
219/// Add selected questions to the current quiz
fa583f5f 220 $rawdata = (array) data_submitted();
221 foreach ($rawdata as $key => $value) { // Parse input for question ids
222 if (preg_match('!^q([0-9]+)$!', $key, $matches)) {
223 $key = $matches[1];
224 quiz_add_quiz_question($key, $quiz);
fef9b51d 225 }
fef9b51d 226 }
4299df1d 227 quiz_update_sumgrades($quiz);
228 quiz_delete_previews($quiz);
e42f153c 229 redirect($thispageurl);
fa583f5f 230}
231
4299df1d 232$qcobject = new question_category_object($pagevars['cpage'], $thispageurl,
233 $contexts->having_one_edit_tab_cap('categories'), $defaultcategoryid,
234 $defaultcategory, null, $contexts->having_cap('moodle/question:add'));
fa583f5f 235
324d6576 236$newrandomcategory = false;
237$newquestioninfo = quiz_process_randomquestion_formdata($qcobject);
3e10e429 238if ($newquestioninfo && $newquestioninfo != 'cancelled') {
324d6576 239 $newrandomcategory = $newquestioninfo->newrandomcategory;
240 if (!$newrandomcategory) {
324d6576 241 print_error('cannotcreatecategory');
242 } else {
93cc3ea4 243 add_to_log($quiz->course, 'quiz', 'addcategory',
324d6576 244 "view.php?id=$cm->id", $newrandomcategory, $cm->id);
c7c7f25a 245 }
246}
fa583f5f 247
324d6576 248if ((optional_param('addrandom', false, PARAM_BOOL) || $newrandomcategory) && confirm_sesskey()) {
249
fa583f5f 250 /// Add random questions to the quiz
251 $recurse = optional_param('recurse', 0, PARAM_BOOL);
324d6576 252 $addonpage = optional_param('addonpage', 0, PARAM_INT);
253 if ($newrandomcategory) {
fa583f5f 254 $categoryid = $newrandomcategory;
324d6576 255 $randomcount = optional_param('randomcount', 1, PARAM_INT);
256 } else {
ee1fb969 257 $categoryid = required_param('categoryid', PARAM_INT);
258 $randomcount = required_param('randomcount', PARAM_INT);
fa583f5f 259 }
260 // load category
324d6576 261 $category = $DB->get_record('question_categories', array('id' => $categoryid));
262 if (!$category) {
fa583f5f 263 print_error('invalidcategoryid', 'error');
264 }
265 $catcontext = get_context_instance_by_id($category->contextid);
266 require_capability('moodle/question:useall', $catcontext);
267 $category->name = $category->name;
268 // Find existing random questions in this category that are
269 // not used by any quiz.
270 if ($existingquestions = $DB->get_records_sql(
ad65ff47 271 "SELECT q.id,q.qtype FROM {question} q
fa583f5f 272 WHERE qtype = '" . RANDOM . "'
273 AND category = ?
274 AND " . $DB->sql_compare_text('questiontext') . " = ?
275 AND NOT EXISTS (SELECT * FROM {quiz_question_instances} WHERE question = q.id)
276 ORDER BY id", array($category->id, $recurse))) {
ad65ff47 277 // Take as many of these as needed.
324d6576 278 while (($existingquestion = array_shift($existingquestions)) && $randomcount > 0) {
fa583f5f 279 quiz_add_quiz_question($existingquestion->id, $quiz, $addonpage);
280 $randomcount--;
6a952ce7 281 }
ee1fb969 282 }
283
fa583f5f 284 // If more are needed, create them.
285 if ($randomcount > 0) {
286 $form->questiontext = $recurse; // we use the questiontext field
287 // to store the info on whether to include
288 // questions in subcategories
289 $form->questiontextformat = 0;
290 $form->image = '';
291 $form->defaultgrade = 1;
292 $form->hidden = 1;
293 for ($i = 0; $i < $randomcount; $i++) {
324d6576 294 $form->category = $category->id . ',' . $category->contextid;
fa583f5f 295 $form->stamp = make_unique_id_code(); // Set the unique
296 //code (not to be changed)
297 $question = new stdClass;
298 $question->qtype = RANDOM;
299 $question = $QTYPES[RANDOM]->save_question($question, $form,
300 $course);
301 if(!isset($question->id)) {
302 print_error('cannotinsertrandomquestion', 'quiz');
ee1fb969 303 }
fa583f5f 304 quiz_add_quiz_question($question->id, $quiz, $addonpage);
2a2c9725 305 }
6a952ce7 306 }
307
4299df1d 308 quiz_update_sumgrades($quiz);
309 quiz_delete_previews($quiz);
e42f153c 310 redirect($thispageurl);
fa583f5f 311}
324d6576 312
4299df1d 313if (optional_param('addnewpagesafterselected', null) && !empty($selectedquestionids) && confirm_sesskey()) {
314 foreach ($selectedquestionids as $questionid) {
315 $quiz->questions = quiz_add_page_break_after($quiz->questions, $questionid);
fa583f5f 316 }
4299df1d 317 quiz_save_new_layout($quiz);
e42f153c 318 redirect($thispageurl);
fa583f5f 319}
271e6dec 320
324d6576 321$addpage = optional_param('addpage', false, PARAM_INT);
4299df1d 322if ($addpage !== false && confirm_sesskey()) {
323 $quiz->questions = quiz_add_page_break_at($quiz->questions, $addpage);
324 quiz_save_new_layout($quiz);
e42f153c 325 redirect($thispageurl);
fa583f5f 326}
6a952ce7 327
324d6576 328$deleteemptypage = optional_param('deleteemptypage', false, PARAM_INT);
329if (($deleteemptypage !== false) && confirm_sesskey()) {
4299df1d 330 $quiz->questions = quiz_delete_empty_page($quiz->questions, $deleteemptypage);
331 quiz_save_new_layout($quiz);
e42f153c 332 redirect($thispageurl);
fa583f5f 333}
4e6f553d 334
4299df1d 335$remove = optional_param('remove', false, PARAM_INT);
336if (($remove = optional_param('remove', false, PARAM_INT)) && confirm_sesskey()) {
337 quiz_remove_question($quiz, $remove);
338 quiz_update_sumgrades($quiz);
339 quiz_delete_previews($quiz);
e42f153c 340 redirect($thispageurl);
fa583f5f 341}
ee1fb969 342
4299df1d 343if (optional_param('quizdeleteselected', false, PARAM_BOOL) && !empty($selectedquestionids) && confirm_sesskey()) {
344 foreach ($selectedquestionids as $questionid) {
345 quiz_remove_question($quiz, $questionid);
b37cacae 346 }
4299df1d 347 quiz_update_sumgrades($quiz);
348 quiz_delete_previews($quiz);
e42f153c 349 redirect($thispageurl);
fa583f5f 350}
351
324d6576 352if (optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) {
353 $oldquestions = explode(',', $quiz->questions); // the questions in the old order
fa583f5f 354 $questions = array(); // for questions in the new order
3e10e429 355 $rawdata = (array) data_submitted();
fa583f5f 356 $moveonpagequestions = array();
3e10e429 357 $moveselectedonpage = optional_param('moveselectedonpagetop', 0, PARAM_INT);
358 if (!$moveselectedonpage) {
359 $moveselectedonpage = optional_param('moveselectedonpagebottom', 0, PARAM_INT);
fa583f5f 360 }
70c01adb 361
3e10e429 362 foreach ($rawdata as $key => $value) {
4299df1d 363 if (preg_match('!^g([0-9]+)$!', $key, $matches)) {
fa583f5f 364 /// Parse input for question -> grades
3e10e429 365 $questionid = $matches[1];
51b9ccc0 366 $quiz->grades[$questionid] = clean_param($value, PARAM_FLOAT);
3e10e429 367 quiz_update_question_instance($quiz->grades[$questionid], $questionid, $quiz->id);
368 quiz_delete_previews($quiz);
369 quiz_update_sumgrades($quiz);
b72ff476 370
3e10e429 371 } else if (preg_match('!^o(pg)?([0-9]+)$!', $key, $matches)) {
fa583f5f 372 /// Parse input for ordering info
3e10e429 373 $questionid = $matches[2];
374 // Make sure two questions don't overwrite each other. If we get a second
375 // question with the same position, shift the second one along to the next gap.
51b9ccc0 376 $value = clean_param($value, PARAM_INTEGER);
fa583f5f 377 while (array_key_exists($value, $questions)) {
378 $value++;
379 }
3e10e429 380 if ($matches[1]) {
381 // This is a page-break entry.
382 $questions[$value] = 0;
383 } else {
384 $questions[$value] = $questionid;
385 }
fa583f5f 386 }
387 }
4299df1d 388
fa583f5f 389 // If ordering info was given, reorder the questions
390 if ($questions) {
391 ksort($questions);
3e10e429 392 $questions[] = 0;
393 $quiz->questions = implode(',', $questions);
394 quiz_save_new_layout($quiz);
395 quiz_delete_previews($quiz);
fa583f5f 396 }
4299df1d 397
fa583f5f 398 //get a list of questions to move, later to be added in the appropriate
399 //place in the string
4299df1d 400 if ($moveselectedonpage) {
324d6576 401 $questions = explode(',', $quiz->questions);
3e10e429 402 $newquestions = array();
403 //remove the questions from their original positions first
404 foreach ($questions as $questionid) {
405 if (!in_array($questionid, $selectedquestionids)) {
406 $newquestions[] = $questionid;
218dfb91 407 }
408 }
324d6576 409 $questions = $newquestions;
410
218dfb91 411 //move to the end of the selected page
3e10e429 412 $pagebreakpositions = array_keys($questions, 0);
413 $numpages = count($pagebreakpositions);
414 // Ensure the target page number is in range.
415 $moveselectedonpage = max(1, min($moveselectedonpage, $pagebreakpositions));
324d6576 416 $moveselectedpos = $pagebreakpositions[$moveselectedonpage - 1];
3e10e429 417 array_splice($questions, $moveselectedpos, 0, $selectedquestionids);
324d6576 418 $quiz->questions = implode(',', $questions);
3e10e429 419 quiz_save_new_layout($quiz);
420 quiz_delete_previews($quiz);
fa583f5f 421 }
3e10e429 422
fa583f5f 423 // If rescaling is required save the new maximum
51b9ccc0 424 $maxgrade = optional_param('maxgrade', -1, PARAM_FLOAT);
fa583f5f 425 if ($maxgrade >= 0) {
3e10e429 426 quiz_set_grade($maxgrade, $quiz);
70c01adb 427 }
ee1fb969 428
e42f153c 429 redirect($thispageurl);
fa583f5f 430}
6551bb89 431
f4b879dd 432$questionbank->process_actions($thispageurl, $cm);
b37cacae 433
4299df1d 434// End of process commands =====================================================
fa583f5f 435
1372b5d2 436// Print the header.
324d6576 437$questionbankmanagement = '<a href="'.$CFG->wwwroot.
1372b5d2 438 '/question/edit.php?courseid='.$course->id.'">'.
324d6576 439 get_string('questionbankmanagement', 'quiz').'</a> ';
fa583f5f 440$strupdatemodule = has_capability('moodle/course:manageactivities',
441 $contexts->lowest()) ?
442 update_module_button($cm->id, $course->id,
443 get_string('modulename', 'quiz')) :
444 "";
445$navigation = build_navigation($pagetitle, $cm);
6f030b0f 446
447$PAGE->requires->skip_link_to('questionbank', get_string('skipto', 'access', get_string('questionbank', 'question')));
448$PAGE->requires->skip_link_to('quizcontentsblock', get_string('skipto', 'access', get_string('questionsinthisquiz', 'quiz')));
449
34a2777c 450print_header_simple($pagetitle, '', $navigation, '', '', true,
fa583f5f 451 $questionbankmanagement.$strupdatemodule);
6f030b0f 452
1372b5d2 453// Initialise the JavaScript.
454$quizeditconfig = new stdClass;
455$quizeditconfig->url = $thispageurl->out(false, array('qbanktool' => '0'));
3e10e429 456$quizeditconfig->dialoglisteners = array();
1372b5d2 457$numberoflisteners = max(quiz_number_of_pages($quiz->questions), 1);
458for ($pageiter = 1; $pageiter <= $numberoflisteners; $pageiter++) {
459 $quizeditconfig->dialoglisteners[] = 'addrandomdialoglaunch_' . $pageiter;
460}
cf615522 461$PAGE->requires->data_for_js('quiz_edit_config', $quizeditconfig);
462$PAGE->requires->js('mod/quiz/edit.js');
1372b5d2 463
464// Print the tabs.
324d6576 465$currenttab = 'edit';
fa583f5f 466$mode = 'editq';
324d6576 467if ($quiz_reordertool) {
468 $mode = 'reorder';
fa583f5f 469}
470include('tabs.php');
471
324d6576 472if ($quiz_qbanktool) {
473 $bankclass = '';
474 $quizcontentsclass = '';
475} else {
476 $bankclass = 'collapsed';
477 $quizcontentsclass = 'quizwhenbankcollapsed';
478}
5669badf 479
a5cb8d69 480// Nasty short-term hack, becuase I am getting rid of separate print_side_block_start/end functions.
481ob_start();
5669badf 482echo '<span id="questionbank"></span>';
1cdbd5e4 483echo '<div class="container">';
fa583f5f 484echo '<div id="module" class="module">';
485echo '<div class="bd">';
5bd22790 486$questionbank->display('editq',
fa583f5f 487 $pagevars['qpage'],
488 $pagevars['qperpage'], $pagevars['qsortorder'],
489 $pagevars['qsortorderdecoded'],
490 $pagevars['cat'], $pagevars['recurse'], $pagevars['showhidden'],
f4b879dd 491 $pagevars['showquestiontext']);
324d6576 492echo '</div>';
493echo '</div>';
494echo '</div>';
a5cb8d69 495$qbhtml = ob_get_contents();
496ob_end_clean();
497
498print_side_block(get_string('questionbankcontents', 'quiz') .
499 ' <a href="' . $thispageurl->out(false, array('qbanktool' => '1')) .
500 '" id="showbankcmd">[' . get_string('show').
501 ']</a>
502 <a href="' . $thispageurl->out(false, array('qbanktool' => '0')) .
503 '" id="hidebankcmd">[' . get_string('hide').
504 ']</a>
505 ', $qbhtml, null, null, '', array('class' => 'questionbankwindow ' . $bankclass));
fa583f5f 506
324d6576 507echo '<div class="quizcontents ' . $quizcontentsclass . '" id="quizcontentsblock">';
3e10e429 508if ($quiz->shufflequestions) {
324d6576 509 $repaginatingdisabledhtml = 'disabled="disabled"';
510 $repaginatingdisabled = true;
3e10e429 511 $quiz->questions = quiz_repaginate($quiz->questions, $quiz->questionsperpage);
324d6576 512} else {
513 $repaginatingdisabledhtml = '';
514 $repaginatingdisabled = false;
515}
516if ($quiz_reordertool) {
fa583f5f 517 echo '<div class="repaginatecommand"><button id="repaginatecommand" '.$repaginatingdisabledhtml.'>'.
324d6576 518 get_string('repaginatecommand', 'quiz').'...</button>';
fa583f5f 519 echo '</div>';
520}
6f030b0f 521print_heading($pagetitle.": ".$quiz->name, '', 2);
324d6576 522helpbutton('editconcepts', get_string('basicideasofquiz', 'quiz'), 'quiz',
523 true, get_string('basicideasofquiz', 'quiz'));
3e10e429 524quiz_print_status_bar($quiz);
fa583f5f 525
3e10e429 526$tabindex = 0;
527if (!$quiz_reordertool) {
528 quiz_print_grading_form($quiz, $thispageurl, $tabindex);
fa583f5f 529}
3e10e429 530
531$notifystrings = array();
532if ($quizhasattempts) {
533 $reviewlink = '<a href="' . $CFG->wwwroot . '/mod/quiz/report.php?mode=overview&amp;id=' . $cm->id . '">' .
534 quiz_num_attempt_summary($quiz, $cm) . '</a>';
535 $notifystrings[] = get_string('cannoteditafterattempts', 'quiz', $reviewlink);
324d6576 536}
3e10e429 537if ($quiz->shufflequestions) {
324d6576 538 $updateurl = new moodle_url("$CFG->wwwroot/course/mod.php",
539 array('return' => 'true', 'update' => $quiz->cmid, 'sesskey' => sesskey()));
3e10e429 540 $updatelink = '<a href="'.$updateurl->out().'">' . get_string('updatethis', '',
541 get_string('modulename', 'quiz')) . '</a>';
542 $notifystrings[] = get_string('shufflequestionsselected', 'quiz', $updatelink);
fa583f5f 543}
3e10e429 544if (!empty($notifystrings)) {
545 print_box('<p>' . implode('</p><p>', $notifystrings) . '</p>', 'statusdisplay');
fa583f5f 546}
547
324d6576 548if ($quiz_reordertool) {
fa583f5f 549 $perpage= array();
550 $perpage[0] = get_string('allinone', 'quiz');
324d6576 551 for ($i = 1; $i <= 50; ++$i) {
fa583f5f 552 $perpage[$i] = $i;
553 }
324d6576 554 $gostring = get_string('go');
fa583f5f 555 echo '<div id="repaginatedialog"><div class="hd">';
324d6576 556 echo get_string('repaginatecommand', 'quiz');
fa583f5f 557 echo '</div><div class="bd">';
558 echo '<form action="edit.php" method="post">';
559 echo '<fieldset class="invisiblefieldset">';
560 echo $thispageurl->hidden_params_out();
d4a1fcaf 561 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
fa583f5f 562 //YUI does not submit the value of the submit button so
563 //we need to add the value:
564 echo '<input type="hidden" name="repaginate" value="'.$gostring.'" />';
565 print_string('repaginate', 'quiz',
566 choose_from_menu($perpage, 'questionsperpage',
324d6576 567 $quiz->questionsperpage, '', '', '', true, $repaginatingdisabled));
fa583f5f 568 echo '<div class="quizquestionlistcontrols">';
569 echo ' <input type="submit" name="repaginate" value="'. $gostring .'" '.$repaginatingdisabledhtml.' />';
570 echo '</div></fieldset></form></div></div>';
571}
fa583f5f 572
3e10e429 573echo '<div class="' . $currenttab . '">';
574quiz_print_question_list($quiz, $thispageurl, true,
575 $quiz_reordertool, $quiz_qbanktool, $quizhasattempts);
576echo '</div>';
4e6f553d 577
578// Close <div class="quizcontents">:
fa583f5f 579echo '</div>';
580
324d6576 581if (!$quiz_reordertool) {
fa583f5f 582 // display category adding UI
583 ?>
584<div id="randomquestiondialog">
3e10e429 585<div class="hd"><?php print_string('addrandomquestiontoquiz', 'quiz', $quiz->name); ?>
6f030b0f 586<span id="pagenumber"><!-- JavaScript will insert the page number here. -->
fa583f5f 587</span>
588</div>
589<div class="bd"><?php
590$qcobject->display_randomquestion_user_interface();
591?></div>
592</div>
593 <?php
594}
595print_footer($course);
e42f153c 596?>