Commit | Line | Data |
---|---|---|
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 | * | |
01773a6d | 38 | * @package mod_quiz |
ba643847 TH |
39 | * @copyright 1999 onwards Martin Dougiamas and others {@link http://moodle.com} |
40 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
f9b0500f TH |
41 | */ |
42 | ||
f4b879dd | 43 | |
324d6576 | 44 | require_once('../../config.php'); |
45 | require_once($CFG->dirroot . '/mod/quiz/editlib.php'); | |
94dbfb3a | 46 | require_once($CFG->dirroot . '/mod/quiz/addrandomform.php'); |
324d6576 | 47 | require_once($CFG->dirroot . '/question/category_class.php'); |
fa583f5f | 48 | |
f9b0500f | 49 | |
fa583f5f | 50 | /** |
51 | * Callback function called from question_list() function | |
52 | * (which is called from showbank()) | |
53 | * Displays button in form with checkboxes for each question. | |
54 | */ | |
324d6576 | 55 | function module_specific_buttons($cmid, $cmoptions) { |
92e01ab7 | 56 | global $OUTPUT; |
76cf77e4 TH |
57 | $params = array( |
58 | 'type' => 'submit', | |
59 | 'name' => 'add', | |
60 | 'value' => $OUTPUT->larrow() . ' ' . get_string('addtoquiz', 'quiz'), | |
61 | ); | |
324d6576 | 62 | if ($cmoptions->hasattempts) { |
76cf77e4 | 63 | $params['disabled'] = 'disabled'; |
324d6576 | 64 | } |
76cf77e4 | 65 | return html_writer::empty_tag('input', $params); |
fa583f5f | 66 | } |
271e6dec | 67 | |
fa583f5f | 68 | /** |
69 | * Callback function called from question_list() function | |
70 | * (which is called from showbank()) | |
71 | */ | |
324d6576 | 72 | function module_specific_controls($totalnumber, $recurse, $category, $cmid, $cmoptions) { |
f9b0500f | 73 | global $OUTPUT; |
fa583f5f | 74 | $out = ''; |
d197ea43 | 75 | $catcontext = context::instance_by_id($category->contextid); |
324d6576 | 76 | if (has_capability('moodle/question:useall', $catcontext)) { |
77 | if ($cmoptions->hasattempts) { | |
94dbfb3a | 78 | $disabled = ' disabled="disabled"'; |
324d6576 | 79 | } else { |
80 | $disabled = ''; | |
fa583f5f | 81 | } |
68b1b19b | 82 | $randomusablequestions = |
f9b0500f TH |
83 | question_bank::get_qtype('random')->get_available_questions_from_category( |
84 | $category->id, $recurse); | |
fa583f5f | 85 | $maxrand = count($randomusablequestions); |
86 | if ($maxrand > 0) { | |
324d6576 | 87 | for ($i = 1; $i <= min(10, $maxrand); $i++) { |
fa583f5f | 88 | $randomcount[$i] = $i; |
85c375c3 | 89 | } |
324d6576 | 90 | for ($i = 20; $i <= min(100, $maxrand); $i += 10) { |
fa583f5f | 91 | $randomcount[$i] = $i; |
92 | } | |
94dbfb3a TH |
93 | } else { |
94 | $randomcount[0] = 0; | |
95 | $disabled = ' disabled="disabled"'; | |
85c375c3 | 96 | } |
94dbfb3a TH |
97 | |
98 | $out = '<strong><label for="menurandomcount">'.get_string('addrandomfromcategory', 'quiz'). | |
99 | '</label></strong><br />'; | |
100 | $attributes = array(); | |
101 | $attributes['disabled'] = $disabled ? 'disabled' : null; | |
102 | $select = html_writer::select($randomcount, 'randomcount', '1', null, $attributes); | |
103 | $out .= get_string('addrandom', 'quiz', $select); | |
104 | $out .= '<input type="hidden" name="recurse" value="'.$recurse.'" />'; | |
105 | $out .= '<input type="hidden" name="categoryid" value="' . $category->id . '" />'; | |
106 | $out .= ' <input type="submit" name="addrandom" value="'. | |
107 | get_string('addtoquiz', 'quiz').'"' . $disabled . ' />'; | |
108 | $out .= $OUTPUT->help_icon('addarandomquestion', 'quiz'); | |
271e6dec | 109 | } |
fa583f5f | 110 | return $out; |
111 | } | |
271e6dec | 112 | |
9e83f3d1 TH |
113 | // These params are only passed from page request to request while we stay on |
114 | // this page otherwise they would go in question_edit_setup. | |
eb02301a | 115 | $quiz_reordertool = optional_param('reordertool', -1, PARAM_BOOL); |
56ed242b | 116 | $quiz_qbanktool = optional_param('qbanktool', -1, PARAM_BOOL); |
fd214b59 | 117 | $scrollpos = optional_param('scrollpos', '', PARAM_INT); |
56ed242b | 118 | |
fa583f5f | 119 | list($thispageurl, $contexts, $cmid, $cm, $quiz, $pagevars) = |
453b28d8 | 120 | question_edit_setup('editq', '/mod/quiz/edit.php', true); |
fa583f5f | 121 | |
122 | $defaultcategoryobj = question_make_default_categories($contexts->all()); | |
94dbfb3a | 123 | $defaultcategory = $defaultcategoryobj->id . ',' . $defaultcategoryobj->contextid; |
324d6576 | 124 | |
fa583f5f | 125 | if ($quiz_qbanktool > -1) { |
126 | $thispageurl->param('qbanktool', $quiz_qbanktool); | |
324d6576 | 127 | set_user_preference('quiz_qbanktool_open', $quiz_qbanktool); |
fa583f5f | 128 | } else { |
324d6576 | 129 | $quiz_qbanktool = get_user_preferences('quiz_qbanktool_open', 0); |
fa583f5f | 130 | } |
131 | ||
eb02301a TH |
132 | if ($quiz_reordertool > -1) { |
133 | $thispageurl->param('reordertool', $quiz_reordertool); | |
134 | set_user_preference('quiz_reordertab', $quiz_reordertool); | |
135 | } else { | |
136 | $quiz_reordertool = get_user_preferences('quiz_reordertab', 0); | |
137 | } | |
138 | ||
76cf77e4 TH |
139 | $canaddrandom = $contexts->have_cap('moodle/question:useall'); |
140 | $canaddquestion = (bool) $contexts->having_add_and_use(); | |
141 | ||
3e10e429 | 142 | $quizhasattempts = quiz_has_attempts($quiz->id); |
fa583f5f | 143 | |
eb02301a | 144 | $PAGE->set_url($thispageurl); |
fa583f5f | 145 | |
fa583f5f | 146 | // Get the course object and related bits. |
324d6576 | 147 | $course = $DB->get_record('course', array('id' => $quiz->course)); |
148 | if (!$course) { | |
fa583f5f | 149 | print_error('invalidcourseid', 'error'); |
150 | } | |
151 | ||
612106b3 | 152 | $questionbank = new quiz_question_bank_view($contexts, $thispageurl, $course, $cm, $quiz); |
3e10e429 | 153 | $questionbank->set_quiz_has_attempts($quizhasattempts); |
971c6fca | 154 | |
324d6576 | 155 | // You need mod/quiz:manage in addition to question capabilities to access this page. |
fa583f5f | 156 | require_capability('mod/quiz:manage', $contexts->lowest()); |
7bd1aa1d | 157 | |
5e8f7365 MN |
158 | // Log this visit. |
159 | $params = array( | |
160 | 'courseid' => $course->id, | |
161 | 'context' => $contexts->lowest(), | |
162 | 'other' => array( | |
163 | 'quizid' => $quiz->id | |
164 | ) | |
165 | ); | |
166 | $event = \mod_quiz\event\edit_page_viewed::create($params); | |
167 | $event->trigger(); | |
168 | ||
4299df1d | 169 | // Process commands ============================================================ |
170 | ||
171 | // Get the list of question ids had their check-boxes ticked. | |
ccba5b88 | 172 | $selectedslots = array(); |
4299df1d | 173 | $params = (array) data_submitted(); |
174 | foreach ($params as $key => $value) { | |
175 | if (preg_match('!^s([0-9]+)$!', $key, $matches)) { | |
ccba5b88 | 176 | $selectedslots[] = $matches[1]; |
6a952ce7 | 177 | } |
fa583f5f | 178 | } |
179 | ||
fd214b59 TH |
180 | $afteractionurl = new moodle_url($thispageurl); |
181 | if ($scrollpos) { | |
182 | $afteractionurl->param('scrollpos', $scrollpos); | |
183 | } | |
4299df1d | 184 | if (($up = optional_param('up', false, PARAM_INT)) && confirm_sesskey()) { |
ccba5b88 | 185 | quiz_move_question_up($quiz, $up); |
f9b0500f | 186 | quiz_delete_previews($quiz); |
fd214b59 | 187 | redirect($afteractionurl); |
4299df1d | 188 | } |
189 | ||
190 | if (($down = optional_param('down', false, PARAM_INT)) && confirm_sesskey()) { | |
ccba5b88 | 191 | quiz_move_question_down($quiz, $down); |
f9b0500f | 192 | quiz_delete_previews($quiz); |
fd214b59 | 193 | redirect($afteractionurl); |
4299df1d | 194 | } |
195 | ||
196 | if (optional_param('repaginate', false, PARAM_BOOL) && confirm_sesskey()) { | |
9e83f3d1 | 197 | // Re-paginate the quiz. |
4299df1d | 198 | $questionsperpage = optional_param('questionsperpage', $quiz->questionsperpage, PARAM_INT); |
ccba5b88 | 199 | quiz_repaginate_questions($quiz->id, $questionsperpage ); |
f9b0500f | 200 | quiz_delete_previews($quiz); |
fd214b59 | 201 | redirect($afteractionurl); |
fa583f5f | 202 | } |
324d6576 | 203 | |
204 | if (($addquestion = optional_param('addquestion', 0, PARAM_INT)) && confirm_sesskey()) { | |
9e83f3d1 | 205 | // Add a single question to the current quiz. |
76cf77e4 | 206 | quiz_require_question_use($addquestion); |
324d6576 | 207 | $addonpage = optional_param('addonpage', 0, PARAM_INT); |
fa583f5f | 208 | quiz_add_quiz_question($addquestion, $quiz, $addonpage); |
4299df1d | 209 | quiz_delete_previews($quiz); |
f9b0500f | 210 | quiz_update_sumgrades($quiz); |
455d765f | 211 | $thispageurl->param('lastchanged', $addquestion); |
fd214b59 | 212 | redirect($afteractionurl); |
fa583f5f | 213 | } |
214 | ||
324d6576 | 215 | if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) { |
9e83f3d1 | 216 | // Add selected questions to the current quiz. |
fa583f5f | 217 | $rawdata = (array) data_submitted(); |
9e83f3d1 | 218 | foreach ($rawdata as $key => $value) { // Parse input for question ids. |
fa583f5f | 219 | if (preg_match('!^q([0-9]+)$!', $key, $matches)) { |
220 | $key = $matches[1]; | |
76cf77e4 | 221 | quiz_require_question_use($key); |
fa583f5f | 222 | quiz_add_quiz_question($key, $quiz); |
fef9b51d | 223 | } |
fef9b51d | 224 | } |
4299df1d | 225 | quiz_delete_previews($quiz); |
f9b0500f | 226 | quiz_update_sumgrades($quiz); |
fd214b59 | 227 | redirect($afteractionurl); |
fa583f5f | 228 | } |
229 | ||
94dbfb3a | 230 | if ((optional_param('addrandom', false, PARAM_BOOL)) && confirm_sesskey()) { |
9e83f3d1 | 231 | // Add random questions to the quiz. |
fa583f5f | 232 | $recurse = optional_param('recurse', 0, PARAM_BOOL); |
324d6576 | 233 | $addonpage = optional_param('addonpage', 0, PARAM_INT); |
94dbfb3a TH |
234 | $categoryid = required_param('categoryid', PARAM_INT); |
235 | $randomcount = required_param('randomcount', PARAM_INT); | |
236 | quiz_add_random_questions($quiz, $addonpage, $categoryid, $randomcount, $recurse); | |
6a952ce7 | 237 | |
4299df1d | 238 | quiz_delete_previews($quiz); |
f9b0500f | 239 | quiz_update_sumgrades($quiz); |
fd214b59 | 240 | redirect($afteractionurl); |
fa583f5f | 241 | } |
324d6576 | 242 | |
25a03faa | 243 | if (optional_param('addnewpagesafterselected', null, PARAM_CLEAN) && |
ccba5b88 TH |
244 | !empty($selectedslots) && confirm_sesskey()) { |
245 | foreach ($selectedslots as $slot) { | |
246 | quiz_add_page_break_after_slot($quiz, $slot); | |
fa583f5f | 247 | } |
f9b0500f | 248 | quiz_delete_previews($quiz); |
fd214b59 | 249 | redirect($afteractionurl); |
fa583f5f | 250 | } |
271e6dec | 251 | |
324d6576 | 252 | $addpage = optional_param('addpage', false, PARAM_INT); |
4299df1d | 253 | if ($addpage !== false && confirm_sesskey()) { |
ccba5b88 | 254 | quiz_add_page_break_after_slot($quiz, $addpage); |
f9b0500f | 255 | quiz_delete_previews($quiz); |
fd214b59 | 256 | redirect($afteractionurl); |
fa583f5f | 257 | } |
6a952ce7 | 258 | |
324d6576 | 259 | $deleteemptypage = optional_param('deleteemptypage', false, PARAM_INT); |
260 | if (($deleteemptypage !== false) && confirm_sesskey()) { | |
ccba5b88 | 261 | quiz_delete_empty_page($quiz, $deleteemptypage); |
f9b0500f | 262 | quiz_delete_previews($quiz); |
fd214b59 | 263 | redirect($afteractionurl); |
fa583f5f | 264 | } |
4e6f553d | 265 | |
4299df1d | 266 | $remove = optional_param('remove', false, PARAM_INT); |
ccba5b88 | 267 | if ($remove && confirm_sesskey() && quiz_has_question_use($quiz, $remove)) { |
76cf77e4 TH |
268 | // Remove a question from the quiz. |
269 | // We require the user to have the 'use' capability on the question, | |
9fc29eec TH |
270 | // so that then can add it back if they remove the wrong one by mistake, |
271 | // but, if the question is missing, it can always be removed. | |
ccba5b88 | 272 | quiz_remove_slot($quiz, $remove); |
4299df1d | 273 | quiz_delete_previews($quiz); |
18dff757 | 274 | quiz_update_sumgrades($quiz); |
fd214b59 | 275 | redirect($afteractionurl); |
fa583f5f | 276 | } |
ee1fb969 | 277 | |
25a03faa | 278 | if (optional_param('quizdeleteselected', false, PARAM_BOOL) && |
ccba5b88 TH |
279 | !empty($selectedslots) && confirm_sesskey()) { |
280 | // Work backwards, since removing a question renumbers following slots. | |
281 | foreach (array_reverse($selectedslots) as $slot) { | |
282 | if (quiz_has_question_use($quiz, $slot)) { | |
283 | quiz_remove_slot($quiz, $slot); | |
76cf77e4 | 284 | } |
b37cacae | 285 | } |
4299df1d | 286 | quiz_delete_previews($quiz); |
f9b0500f | 287 | quiz_update_sumgrades($quiz); |
fd214b59 | 288 | redirect($afteractionurl); |
fa583f5f | 289 | } |
290 | ||
324d6576 | 291 | if (optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) { |
f9b0500f TH |
292 | $deletepreviews = false; |
293 | $recomputesummarks = false; | |
294 | ||
3e10e429 | 295 | $rawdata = (array) data_submitted(); |
fa583f5f | 296 | $moveonpagequestions = array(); |
3e10e429 | 297 | $moveselectedonpage = optional_param('moveselectedonpagetop', 0, PARAM_INT); |
298 | if (!$moveselectedonpage) { | |
299 | $moveselectedonpage = optional_param('moveselectedonpagebottom', 0, PARAM_INT); | |
fa583f5f | 300 | } |
70c01adb | 301 | |
ccba5b88 | 302 | $newslotorder = array(); |
3e10e429 | 303 | foreach ($rawdata as $key => $value) { |
4299df1d | 304 | if (preg_match('!^g([0-9]+)$!', $key, $matches)) { |
9e83f3d1 | 305 | // Parse input for question -> grades. |
ccba5b88 TH |
306 | $slotnumber = $matches[1]; |
307 | $newgrade = unformat_float($value); | |
308 | quiz_update_slot_maxmark($DB->get_record('quiz_slots', | |
309 | array('quizid' => $quiz->id, 'slot' => $slotnumber), '*', MUST_EXIST), $newgrade); | |
f9b0500f TH |
310 | $deletepreviews = true; |
311 | $recomputesummarks = true; | |
b72ff476 | 312 | |
3e10e429 | 313 | } else if (preg_match('!^o(pg)?([0-9]+)$!', $key, $matches)) { |
9e83f3d1 | 314 | // Parse input for ordering info. |
ccba5b88 | 315 | $slotnumber = $matches[2]; |
3e10e429 | 316 | // Make sure two questions don't overwrite each other. If we get a second |
317 | // question with the same position, shift the second one along to the next gap. | |
1e12c120 | 318 | $value = clean_param($value, PARAM_INT); |
ccba5b88 | 319 | while (array_key_exists($value, $newslotorder)) { |
fa583f5f | 320 | $value++; |
321 | } | |
3e10e429 | 322 | if ($matches[1]) { |
323 | // This is a page-break entry. | |
ccba5b88 | 324 | $newslotorder[$value] = 0; |
3e10e429 | 325 | } else { |
ccba5b88 | 326 | $newslotorder[$value] = $slotnumber; |
3e10e429 | 327 | } |
f9b0500f | 328 | $deletepreviews = true; |
fa583f5f | 329 | } |
330 | } | |
4299df1d | 331 | |
4299df1d | 332 | if ($moveselectedonpage) { |
ccba5b88 TH |
333 | |
334 | // Make up a $newslotorder, then let the next if statement do the work. | |
335 | $oldslots = $DB->get_records('quiz_slots', array('quizid' => $quiz->id), 'slot'); | |
336 | ||
337 | $beforepage = array(); | |
338 | $onpage = array(); | |
339 | $afterpage = array(); | |
340 | foreach ($oldslots as $oldslot) { | |
341 | if (in_array($oldslot->slot, $selectedslots)) { | |
342 | $onpage[] = $oldslot; | |
343 | } else if ($oldslot->page <= $moveselectedonpage) { | |
344 | $beforepage[] = $oldslot; | |
345 | } else { | |
346 | $afterpage[] = $oldslot; | |
218dfb91 | 347 | } |
348 | } | |
324d6576 | 349 | |
ccba5b88 TH |
350 | $newslotorder = array(); |
351 | $currentpage = 1; | |
352 | $index = 10; | |
353 | foreach ($beforepage as $slot) { | |
354 | while ($currentpage < $slot->page) { | |
355 | $newslotorder[$index] = 0; | |
356 | $index += 10; | |
357 | $currentpage += 1; | |
358 | } | |
359 | $newslotorder[$index] = $slot->slot; | |
360 | $index += 10; | |
361 | } | |
800944b0 | 362 | |
ccba5b88 TH |
363 | while ($currentpage < $moveselectedonpage) { |
364 | $newslotorder[$index] = 0; | |
365 | $index += 10; | |
366 | $currentpage += 1; | |
367 | } | |
368 | foreach ($onpage as $slot) { | |
369 | $newslotorder[$index] = $slot->slot; | |
370 | $index += 10; | |
800944b0 | 371 | } |
800944b0 | 372 | |
ccba5b88 TH |
373 | foreach ($afterpage as $slot) { |
374 | while ($currentpage < $slot->page) { | |
375 | $newslotorder[$index] = 0; | |
376 | $index += 10; | |
377 | $currentpage += 1; | |
378 | } | |
379 | $newslotorder[$index] = $slot->slot; | |
380 | $index += 10; | |
381 | } | |
382 | } | |
800944b0 | 383 | |
ccba5b88 TH |
384 | // If ordering info was given, reorder the questions. |
385 | if ($newslotorder) { | |
386 | ksort($newslotorder); | |
387 | $currentpage = 1; | |
388 | $currentslot = 1; | |
389 | $slotreorder = array(); | |
390 | $slotpages = array(); | |
391 | foreach ($newslotorder as $slotnumber) { | |
392 | if ($slotnumber == 0) { | |
393 | $currentpage += 1; | |
394 | continue; | |
395 | } | |
396 | $slotreorder[$slotnumber] = $currentslot; | |
397 | $slotpages[$currentslot] = $currentpage; | |
398 | $currentslot += 1; | |
399 | } | |
400 | $trans = $DB->start_delegated_transaction(); | |
401 | update_field_with_unique_index('quiz_slots', | |
402 | 'slot', $slotreorder, array('quizid' => $quiz->id)); | |
403 | foreach ($slotpages as $slotnumber => $page) { | |
404 | $DB->set_field('quiz_slots', 'page', $page, array('quizid' => $quiz->id, 'slot' => $slotnumber)); | |
405 | } | |
406 | $trans->allow_commit(); | |
f9b0500f | 407 | $deletepreviews = true; |
fa583f5f | 408 | } |
3e10e429 | 409 | |
9e83f3d1 | 410 | // If rescaling is required save the new maximum. |
7f5f3844 | 411 | $maxgrade = unformat_float(optional_param('maxgrade', -1, PARAM_RAW)); |
fa583f5f | 412 | if ($maxgrade >= 0) { |
3e10e429 | 413 | quiz_set_grade($maxgrade, $quiz); |
70c01adb | 414 | } |
ee1fb969 | 415 | |
f9b0500f TH |
416 | if ($deletepreviews) { |
417 | quiz_delete_previews($quiz); | |
418 | } | |
419 | if ($recomputesummarks) { | |
420 | quiz_update_sumgrades($quiz); | |
421 | quiz_update_all_attempt_sumgrades($quiz); | |
422 | quiz_update_all_final_grades($quiz); | |
423 | quiz_update_grades($quiz, 0, true); | |
424 | } | |
fd214b59 | 425 | redirect($afteractionurl); |
fa583f5f | 426 | } |
6551bb89 | 427 | |
f4b879dd | 428 | $questionbank->process_actions($thispageurl, $cm); |
b37cacae | 429 | |
4299df1d | 430 | // End of process commands ===================================================== |
fa583f5f | 431 | |
25a03faa TH |
432 | $PAGE->requires->skip_link_to('questionbank', |
433 | get_string('skipto', 'access', get_string('questionbank', 'question'))); | |
434 | $PAGE->requires->skip_link_to('quizcontentsblock', | |
435 | get_string('skipto', 'access', get_string('questionsinthisquiz', 'quiz'))); | |
4c7f377d | 436 | $PAGE->set_title(get_string('editingquizx', 'quiz', format_string($quiz->name))); |
56ed242b | 437 | $PAGE->set_heading($course->fullname); |
eb02301a TH |
438 | $node = $PAGE->settingsnav->find('mod_quiz_edit', navigation_node::TYPE_SETTING); |
439 | if ($node) { | |
440 | $node->make_active(); | |
441 | } | |
03da0c39 | 442 | echo $OUTPUT->header(); |
6f030b0f | 443 | |
1372b5d2 | 444 | // Initialise the JavaScript. |
0ff4bd08 | 445 | $quizeditconfig = new stdClass(); |
b9bc2019 | 446 | $quizeditconfig->url = $thispageurl->out(true, array('qbanktool' => '0')); |
3e10e429 | 447 | $quizeditconfig->dialoglisteners = array(); |
ccba5b88 TH |
448 | $numberoflisteners = $DB->get_field_sql(" |
449 | SELECT COALESCE(MAX(page), 1) | |
450 | FROM {quiz_slots} | |
451 | WHERE quizid = ?", array($quiz->id)); | |
452 | ||
1372b5d2 | 453 | for ($pageiter = 1; $pageiter <= $numberoflisteners; $pageiter++) { |
454 | $quizeditconfig->dialoglisteners[] = 'addrandomdialoglaunch_' . $pageiter; | |
455 | } | |
cf615522 | 456 | $PAGE->requires->data_for_js('quiz_edit_config', $quizeditconfig); |
fd214b59 | 457 | $PAGE->requires->js('/question/qengine.js'); |
f387bb9b PS |
458 | $module = array( |
459 | 'name' => 'mod_quiz_edit', | |
460 | 'fullpath' => '/mod/quiz/edit.js', | |
461 | 'requires' => array('yui2-dom', 'yui2-event', 'yui2-container'), | |
462 | 'strings' => array(), | |
463 | 'async' => false, | |
464 | ); | |
465 | $PAGE->requires->js_init_call('quiz_edit_init', null, false, $module); | |
1372b5d2 | 466 | |
eb02301a TH |
467 | // Print the tabs to switch mode. |
468 | if ($quiz_reordertool) { | |
469 | $currenttab = 'reorder'; | |
470 | } else { | |
471 | $currenttab = 'edit'; | |
fa583f5f | 472 | } |
eb02301a | 473 | $tabs = array(array( |
25a03faa TH |
474 | new tabobject('edit', new moodle_url($thispageurl, |
475 | array('reordertool' => 0)), get_string('editingquiz', 'quiz')), | |
476 | new tabobject('reorder', new moodle_url($thispageurl, | |
477 | array('reordertool' => 1)), get_string('orderingquiz', 'quiz')), | |
eb02301a TH |
478 | )); |
479 | print_tabs($tabs, $currenttab); | |
fa583f5f | 480 | |
324d6576 | 481 | if ($quiz_qbanktool) { |
482 | $bankclass = ''; | |
483 | $quizcontentsclass = ''; | |
484 | } else { | |
e6fb2c60 | 485 | $bankclass = 'collapsed '; |
324d6576 | 486 | $quizcontentsclass = 'quizwhenbankcollapsed'; |
487 | } | |
5669badf | 488 | |
6605ff8c | 489 | echo '<div class="questionbankwindow ' . $bankclass . 'block">'; |
e6fb2c60 | 490 | echo '<div class="header"><div class="title"><h2>'; |
491 | echo get_string('questionbankcontents', 'quiz') . | |
bd5d8b50 ME |
492 | ' [<a href="' . $thispageurl->out(true, array('qbanktool' => '1')) . |
493 | '" id="showbankcmd">' . get_string('show'). | |
494 | '</a><a href="' . $thispageurl->out(true, array('qbanktool' => '0')) . | |
495 | '" id="hidebankcmd">' . get_string('hide'). | |
496 | '</a>]'; | |
e6fb2c60 | 497 | echo '</h2></div></div><div class="content">'; |
498 | ||
5669badf | 499 | echo '<span id="questionbank"></span>'; |
1cdbd5e4 | 500 | echo '<div class="container">'; |
fa583f5f | 501 | echo '<div id="module" class="module">'; |
502 | echo '<div class="bd">'; | |
5bd22790 | 503 | $questionbank->display('editq', |
fa583f5f | 504 | $pagevars['qpage'], |
b72b4137 | 505 | $pagevars['qperpage'], |
fa583f5f | 506 | $pagevars['cat'], $pagevars['recurse'], $pagevars['showhidden'], |
e20ad67d | 507 | $pagevars['qbshowtext']); |
324d6576 | 508 | echo '</div>'; |
509 | echo '</div>'; | |
510 | echo '</div>'; | |
a5cb8d69 | 511 | |
e6fb2c60 | 512 | echo '</div></div>'; |
fa583f5f | 513 | |
324d6576 | 514 | echo '<div class="quizcontents ' . $quizcontentsclass . '" id="quizcontentsblock">'; |
3e10e429 | 515 | if ($quiz->shufflequestions) { |
324d6576 | 516 | $repaginatingdisabledhtml = 'disabled="disabled"'; |
517 | $repaginatingdisabled = true; | |
518 | } else { | |
519 | $repaginatingdisabledhtml = ''; | |
520 | $repaginatingdisabled = false; | |
521 | } | |
522 | if ($quiz_reordertool) { | |
25a03faa TH |
523 | echo '<div class="repaginatecommand"><button id="repaginatecommand" ' . |
524 | $repaginatingdisabledhtml.'>'. | |
324d6576 | 525 | get_string('repaginatecommand', 'quiz').'...</button>'; |
fa583f5f | 526 | echo '</div>'; |
527 | } | |
16cad79b TH |
528 | |
529 | if ($quiz_reordertool) { | |
4c7f377d | 530 | echo $OUTPUT->heading_with_help(get_string('orderingquizx', 'quiz', format_string($quiz->name)), |
16cad79b TH |
531 | 'orderandpaging', 'quiz'); |
532 | } else { | |
4c7f377d | 533 | echo $OUTPUT->heading(get_string('editingquizx', 'quiz', format_string($quiz->name)), 2); |
16cad79b TH |
534 | echo $OUTPUT->help_icon('editingquiz', 'quiz', get_string('basicideasofquiz', 'quiz')); |
535 | } | |
3e10e429 | 536 | quiz_print_status_bar($quiz); |
fa583f5f | 537 | |
3e10e429 | 538 | $tabindex = 0; |
18dff757 | 539 | quiz_print_grading_form($quiz, $thispageurl, $tabindex); |
3e10e429 | 540 | |
541 | $notifystrings = array(); | |
542 | if ($quizhasattempts) { | |
a49cb927 | 543 | $reviewlink = quiz_attempt_summary_link_to_reports($quiz, $cm, $contexts->lowest()); |
3e10e429 | 544 | $notifystrings[] = get_string('cannoteditafterattempts', 'quiz', $reviewlink); |
324d6576 | 545 | } |
3e10e429 | 546 | if ($quiz->shufflequestions) { |
324d6576 | 547 | $updateurl = new moodle_url("$CFG->wwwroot/course/mod.php", |
548 | array('return' => 'true', 'update' => $quiz->cmid, 'sesskey' => sesskey())); | |
3e10e429 | 549 | $updatelink = '<a href="'.$updateurl->out().'">' . get_string('updatethis', '', |
550 | get_string('modulename', 'quiz')) . '</a>'; | |
551 | $notifystrings[] = get_string('shufflequestionsselected', 'quiz', $updatelink); | |
fa583f5f | 552 | } |
3e10e429 | 553 | if (!empty($notifystrings)) { |
3b1d5cc4 | 554 | echo $OUTPUT->box('<p>' . implode('</p><p>', $notifystrings) . '</p>', 'statusdisplay'); |
fa583f5f | 555 | } |
556 | ||
324d6576 | 557 | if ($quiz_reordertool) { |
94dbfb3a | 558 | $perpage = array(); |
fa583f5f | 559 | $perpage[0] = get_string('allinone', 'quiz'); |
324d6576 | 560 | for ($i = 1; $i <= 50; ++$i) { |
fa583f5f | 561 | $perpage[$i] = $i; |
562 | } | |
324d6576 | 563 | $gostring = get_string('go'); |
fa583f5f | 564 | echo '<div id="repaginatedialog"><div class="hd">'; |
324d6576 | 565 | echo get_string('repaginatecommand', 'quiz'); |
fa583f5f | 566 | echo '</div><div class="bd">'; |
567 | echo '<form action="edit.php" method="post">'; | |
568 | echo '<fieldset class="invisiblefieldset">'; | |
6ea66ff3 | 569 | echo html_writer::input_hidden_params($thispageurl); |
d4a1fcaf | 570 | echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />'; |
9e83f3d1 | 571 | // YUI does not submit the value of the submit button so we need to add the value. |
fa583f5f | 572 | echo '<input type="hidden" name="repaginate" value="'.$gostring.'" />'; |
3224f709 PS |
573 | $attributes = array(); |
574 | $attributes['disabled'] = $repaginatingdisabledhtml ? 'disabled' : null; | |
25a03faa TH |
575 | $select = html_writer::select( |
576 | $perpage, 'questionsperpage', $quiz->questionsperpage, null, $attributes); | |
3224f709 | 577 | print_string('repaginate', 'quiz', $select); |
fa583f5f | 578 | echo '<div class="quizquestionlistcontrols">'; |
25a03faa TH |
579 | echo ' <input type="submit" name="repaginate" value="'. $gostring . '" ' . |
580 | $repaginatingdisabledhtml.' />'; | |
fa583f5f | 581 | echo '</div></fieldset></form></div></div>'; |
582 | } | |
fa583f5f | 583 | |
56ed242b SH |
584 | if ($quiz_reordertool) { |
585 | echo '<div class="reorder">'; | |
586 | } else { | |
587 | echo '<div class="editq">'; | |
588 | } | |
589 | ||
76cf77e4 TH |
590 | quiz_print_question_list($quiz, $thispageurl, true, $quiz_reordertool, $quiz_qbanktool, |
591 | $quizhasattempts, $defaultcategoryobj, $canaddquestion, $canaddrandom); | |
3e10e429 | 592 | echo '</div>'; |
4e6f553d | 593 | |
9e83f3d1 | 594 | // Close <div class="quizcontents">. |
fa583f5f | 595 | echo '</div>'; |
596 | ||
76cf77e4 | 597 | if (!$quiz_reordertool && $canaddrandom) { |
94dbfb3a TH |
598 | $randomform = new quiz_add_random_form(new moodle_url('/mod/quiz/addrandom.php'), $contexts); |
599 | $randomform->set_data(array( | |
600 | 'category' => $pagevars['cat'], | |
a530d4a9 | 601 | 'returnurl' => $thispageurl->out_as_local_url(false), |
94dbfb3a TH |
602 | 'cmid' => $cm->id, |
603 | )); | |
fa583f5f | 604 | ?> |
25a03faa TH |
605 | <div id="randomquestiondialog"> |
606 | <div class="hd"><?php print_string('addrandomquestiontoquiz', 'quiz', $quiz->name); ?> | |
607 | <span id="pagenumber"><!-- JavaScript will insert the page number here. --> | |
608 | </span> | |
609 | </div> | |
610 | <div class="bd"><?php | |
611 | $randomform->display(); | |
612 | ?></div> | |
613 | </div> | |
fa583f5f | 614 | <?php |
615 | } | |
867847e3 | 616 | echo $OUTPUT->footer(); |