change to print_paging_bar function to optionally support the use of a moodle_url...
[moodle.git] / question / editlib.php
CommitLineData
516cf3eb 1<?php // $Id$
2/**
4323d029 3 * Functions used by showbank.php to show question editing interface
4 *
5 * TODO: currently the function question_list still provides controls specific
6 * to the quiz module. This needs to be generalised.
7 *
8 * @author Martin Dougiamas and many others. This has recently been extensively
9 * rewritten by members of the Serving Mathematics project
10 * {@link http://maths.york.ac.uk/serving_maths}
11 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
12 * @package questionbank
13 */
516cf3eb 14
4fbfd971 15require_once($CFG->libdir.'/questionlib.php');
516cf3eb 16
f92cf442 17define('DEFAULT_QUESTIONS_PER_PAGE', 20);
18
86909ce0 19function get_module_from_cmid($cmid){
20 global $CFG;
21 if (!$cmrec = get_record_sql("SELECT cm.*, md.name as modname
22 FROM {$CFG->prefix}course_modules cm,
23 {$CFG->prefix}modules md
24 WHERE cm.id = '$cmid' AND
25 md.id = cm.module")){
26 error('cmunknown');
27 } elseif (!$modrec =get_record($cmrec->modname, 'id', $cmrec->instance)) {
28 error('cmunknown');
29 }
30 $modrec->instance = $modrec->id;
31 $modrec->cmid = $modrec->id;
32
33 return array($modrec, $cmrec);
34}
4fbfd971 35/**
36* Function to read all questions for category into big array
37*
38* @param int $category category number
36e2232e 39* @param bool $noparent if true only questions with NO parent will be selected
40* @param bool $recurse include subdirectories
5fd8f999 41* @param bool $export set true if this is called by questionbank export
4fbfd971 42* @author added by Howard Miller June 2004
43*/
5fd8f999 44function get_questions_category( $category, $noparent=false, $recurse=true, $export=true ) {
4fbfd971 45
46 global $QTYPES;
47
48 // questions will be added to an array
49 $qresults = array();
50
51 // build sql bit for $noparent
52 $npsql = '';
53 if ($noparent) {
54 $npsql = " and parent='0' ";
55 }
56
36e2232e 57 // get (list) of categories
58 if ($recurse) {
59 $categorylist = question_categorylist( $category->id );
60 }
61 else {
62 $categorylist = $category->id;
63 }
64
4fbfd971 65 // get the list of questions for the category
36e2232e 66 if ($questions = get_records_select("question","category IN ($categorylist) $npsql", "qtype, name ASC")) {
4fbfd971 67
68 // iterate through questions, getting stuff we need
69 foreach($questions as $question) {
70 $questiontype = $QTYPES[$question->qtype];
5fd8f999 71 $question->export_process = $export;
4fbfd971 72 $questiontype->get_question_options( $question );
73 $qresults[] = $question;
74 }
75 }
76
77 return $qresults;
78}
79
80/**
81* Gets the default category in a course
82*
83* It returns the first category with no parent category. If no categories
84* exist yet then one is created.
85* @return object The default category
86* @param integer $courseid The id of the course whose default category is wanted
87*/
88function get_default_question_category($courseid) {
b030a630 89 // If it already exists, just return it.
90 if ($category = get_records_select("question_categories", "course = '$courseid' AND parent = '0'", 'id', '*', '', 1)) {
91 return reset($category);
4fbfd971 92 }
93
94 // Otherwise, we need to make one
b030a630 95 $category = new stdClass;
4fbfd971 96 $category->name = get_string("default", "quiz");
97 $category->info = get_string("defaultinfo", "quiz");
98 $category->course = $courseid;
99 $category->parent = 0;
b030a630 100 $category->sortorder = 999; // By default, all categories get this number, and are sorted alphabetically.
4fbfd971 101 $category->publish = 0;
102 $category->stamp = make_unique_id_code();
103
104 if (!$category->id = insert_record("question_categories", $category)) {
105 notify("Error creating a default category!");
106 return false;
107 }
108 return $category;
109}
110
4fbfd971 111/**
112 * prints a form to choose categories
113 */
86909ce0 114function question_category_form($course, $pageurl, $current, $recurse=1, $showhidden=false, $showquestiontext=false) {
e586cfb4 115 global $CFG;
516cf3eb 116
117/// Make sure the default category exists for this course
b030a630 118 get_default_question_category($course->id);
516cf3eb 119
120/// Get all the existing categories now
b030a630 121 $catmenu = question_category_options($course->id, true);
dcd51df2 122
516cf3eb 123 $strcategory = get_string("category", "quiz");
124 $strshow = get_string("show", "quiz");
125 $streditcats = get_string("editcategories", "quiz");
126
0fd5feef 127 echo "<strong>$strcategory:</strong>&nbsp;";
86909ce0 128 popup_form ("edit.php?".$pageurl->get_query_string()."&amp;cat=", $catmenu, "catmenu", $current, "", "", "", false, "self");
0fd5feef 129
d2ce367f 130 echo '<form method="post" action="edit.php" id="displayoptions">';
0fd5feef 131 echo "<fieldset class='invisiblefieldset'>";
86909ce0 132 echo $pageurl->hidden_params_out();
624cbc9c 133 question_category_form_checkbox('recurse', $recurse);
134 question_category_form_checkbox('showhidden', $showhidden);
135 question_category_form_checkbox('showquestiontext', $showquestiontext);
136 echo '<noscript><div class="centerpara"><input type="submit" value="'. get_string('go') .'" />';
137 echo '</div></noscript></fieldset></form>';
138}
139
140/**
141 * Private funciton to help the preceeding function.
142 */
143function question_category_form_checkbox($name, $checked) {
144 echo '<div><input type="hidden" id="' . $name . '_off" name="' . $name . '" value="0" />';
145 echo '<input type="checkbox" id="' . $name . '_on" name="' . $name . '" value="1"';
146 if ($checked) {
516cf3eb 147 echo ' checked="checked"';
148 }
d2ce367f 149 echo ' onchange="getElementById(\'displayoptions\').submit(); return true;" />';
624cbc9c 150 echo '<label for="' . $name . '_on">';
151 print_string($name, 'quiz');
152 echo "</label></div>\n";
516cf3eb 153}
154
516cf3eb 155/**
156* Prints the table of questions in a category with interactions
157*
158* @param object $course The course object
159* @param int $categoryid The id of the question category to be displayed
86909ce0 160* @param int $cm The course module record if we are in the context of a particular module, 0 otherwise
516cf3eb 161* @param int $recurse This is 1 if subcategories should be included, 0 otherwise
162* @param int $page The number of the page to be displayed
163* @param int $perpage Number of questions to show per page
164* @param boolean $showhidden True if also hidden questions should be displayed
dcc2ffde 165* @param boolean $showquestiontext whether the text of each question should be shown in the list
516cf3eb 166*/
86909ce0 167function question_list($course, $pageurl, $categoryid, $cm = null,
624cbc9c 168 $recurse=1, $page=0, $perpage=100, $showhidden=false, $sortorder='qtype, name ASC',
169 $showquestiontext = false) {
95947ac9 170 global $QTYPE_MENU, $USER, $CFG, $THEME;
3765fd53 171
50530eb7 172 $qtypemenu = $QTYPE_MENU;
173 if ($rqp_types = get_records('question_rqp_types')) {
174 foreach($rqp_types as $type) {
175 $qtypemenu['rqp_'.$type->id] = $type->name;
176 }
177 }
178
516cf3eb 179 $strcategory = get_string("category", "quiz");
180 $strquestion = get_string("question", "quiz");
181 $straddquestions = get_string("addquestions", "quiz");
182 $strimportquestions = get_string("importquestions", "quiz");
183 $strexportquestions = get_string("exportquestions", "quiz");
184 $strnoquestions = get_string("noquestions", "quiz");
185 $strselect = get_string("select", "quiz");
186 $strselectall = get_string("selectall", "quiz");
187 $strselectnone = get_string("selectnone", "quiz");
188 $strcreatenewquestion = get_string("createnewquestion", "quiz");
189 $strquestionname = get_string("questionname", "quiz");
190 $strdelete = get_string("delete");
191 $stredit = get_string("edit");
192 $straction = get_string("action");
193 $strrestore = get_string('restore');
194
195 $straddtoquiz = get_string("addtoquiz", "quiz");
196 $strtype = get_string("type", "quiz");
197 $strcreatemultiple = get_string("createmultiple", "quiz");
198 $strpreview = get_string("preview","quiz");
199
200 if (!$categoryid) {
0fd5feef 201 echo "<p style=\"text-align:center;\"><b>";
516cf3eb 202 print_string("selectcategoryabove", "quiz");
203 echo "</b></p>";
516cf3eb 204 return;
205 }
206
dcc2ffde 207 if (!$category = get_record('question_categories', 'id', $categoryid)) {
208 notify('Category not found!');
516cf3eb 209 return;
210 }
dcc2ffde 211 $canedit = has_capability('moodle/question:manage', get_context_instance(CONTEXT_COURSE, $category->course));
86909ce0 212
213 if ($cm AND $cm->modname == 'quiz') {
214 $editingquiz = has_capability("mod/quiz:manage", get_context_instance(CONTEXT_MODULE, $cm->id));
215 $quizid = $cm->instance;
216 } else {
217 $editingquiz = false;
218 $quizid = 0;
dcc2ffde 219 }
220
09275894 221 echo '<div class="boxaligncenter">';
4abc23b2 222 $formatoptions = new stdClass;
7347c60b 223 $formatoptions->noclean = true;
224 echo format_text($category->info, FORMAT_MOODLE, $formatoptions, $course->id);
516cf3eb 225
226 echo '<table><tr>';
227
dcc2ffde 228 // check if editing questions in this category is allowed
229 if ($canedit) {
516cf3eb 230 echo "<td valign=\"top\"><b>$strcreatenewquestion:</b></td>";
231 echo '<td valign="top" align="right">';
86909ce0 232 $returnurl = urlencode($pageurl->out());
233 popup_form ("$CFG->wwwroot/question/question.php?returnurl=$returnurl&amp;category=$category->id&amp;qtype=", $qtypemenu, "addquestion",
516cf3eb 234 "", "choose", "", "", false, "self");
624cbc9c 235 echo '</td><td valign="top" align="right">';
516cf3eb 236 helpbutton("questiontypes", $strcreatenewquestion, "quiz");
dcc2ffde 237 echo '</td>';
516cf3eb 238 }
239 else {
dcc2ffde 240 echo '<td>';
516cf3eb 241 print_string("publishedit","quiz");
dcc2ffde 242 echo '</td>';
516cf3eb 243 }
244
dcc2ffde 245 echo '</tr></table>';
09275894 246 echo '</div>';
516cf3eb 247
dc1f00de 248 $categorylist = ($recurse) ? question_categorylist($category->id) : $category->id;
516cf3eb 249
250 // hide-feature
251 $showhidden = $showhidden ? '' : " AND hidden = '0'";
252
4f48fb42 253 if (!$totalnumber = count_records_select('question', "category IN ($categorylist) AND parent = '0' $showhidden")) {
0fd5feef 254 echo "<p style=\"text-align:center;\">";
516cf3eb 255 print_string("noquestions", "quiz");
256 echo "</p>";
257 return;
258 }
259
4f48fb42 260 if (!$questions = get_records_select('question', "category IN ($categorylist) AND parent = '0' $showhidden", $sortorder, '*', $page*$perpage, $perpage)) {
516cf3eb 261 // There are no questions on the requested page.
262 $page = 0;
4f48fb42 263 if (!$questions = get_records_select('question', "category IN ($categorylist) AND parent = '0' $showhidden", $sortorder, '*', 0, $perpage)) {
516cf3eb 264 // There are no questions at all
0fd5feef 265 echo "<p style=\"text-align:center;\">";
516cf3eb 266 print_string("noquestions", "quiz");
267 echo "</p>";
268 return;
269 }
270 }
271
272 print_paging_bar($totalnumber, $page, $perpage,
a0e512fe 273 "edit.php?courseid={$course->id}&amp;perpage=$perpage&amp;");
516cf3eb 274
86909ce0 275 echo '<form method="post" action="edit.php">';
624cbc9c 276 echo '<fieldset class="invisiblefieldset" style="display: block;">';
516cf3eb 277 echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
86909ce0 278 echo $pageurl->hidden_params_out();
624cbc9c 279 echo '<table id="categoryquestions" style="width: 100%"><tr>';
280 echo "<th style=\"white-space:nowrap;\" class=\"header\" scope=\"col\">$straction</th>";
516cf3eb 281
282 $sortoptions = array('name, qtype ASC' => get_string("sortalpha", "quiz"),
283 'qtype, name ASC' => get_string("sorttypealpha", "quiz"),
284 'id ASC' => get_string("sortage", "quiz"));
285 $orderselect = choose_from_menu ($sortoptions, 'sortorder', $sortorder, false, 'this.form.submit();', '0', true);
09275894 286 $orderselect .= '<noscript><div><input type="submit" value="'.get_string("sortsubmit", "quiz").'" /></div></noscript>';
624cbc9c 287 echo "<th style=\"white-space:nowrap; text-align: left;\" class=\"header\" scope=\"col\">$strquestionname $orderselect</th>
288 <th style=\"white-space:nowrap; text-align: right;\" class=\"header\" scope=\"col\">$strtype</th>";
516cf3eb 289 echo "</tr>\n";
290 foreach ($questions as $question) {
624cbc9c 291 $nameclass = '';
292 $textclass = '';
293 if ($question->hidden) {
294 $nameclass = 'dimmed_text';
295 $textclass = 'dimmed_text';
296 }
297 if ($showquestiontext) {
298 $nameclass .= ' header';
299 }
300 if ($nameclass) {
301 $nameclass = 'class="' . $nameclass . '"';
302 }
303 if ($textclass) {
304 $textclass = 'class="' . $textclass . '"';
305 }
306
307 echo "<tr>\n<td style=\"white-space:nowrap;\" $nameclass>\n";
3765fd53 308
309 // add to quiz
dcc2ffde 310 if ($editingquiz) {
86909ce0 311 echo "<a title=\"$straddtoquiz\" href=\"edit.php?".$pageurl->get_query_string()."&amp;addquestion=$question->id&amp;sesskey=$USER->sesskey\"><img
0fd5feef 312 src=\"$CFG->pixpath/t/moveleft.gif\" alt=\"$straddtoquiz\" /></a>&nbsp;";
516cf3eb 313 }
3765fd53 314
315 // preview
7d87171b 316 link_to_popup_window('/question/preview.php?id=' . $question->id . '&amp;quizid=' . $quizid, 'questionpreview',
317 "<img src=\"$CFG->pixpath/t/preview.gif\" class=\"iconsmall\" alt=\"$strpreview\" />",
318 0, 0, $strpreview, QUESTION_PREVIEW_POPUP_OPTIONS);
3765fd53 319
320 // edit, hide, delete question, using question capabilities, not quiz capabilieies
dcc2ffde 321 if ($canedit) {
e586cfb4 322 echo "<a title=\"$stredit\" href=\"$CFG->wwwroot/question/question.php?id=$question->id\"><img
0fd5feef 323 src=\"$CFG->pixpath/t/edit.gif\" alt=\"$stredit\" /></a>&nbsp;";
516cf3eb 324 // hide-feature
325 if($question->hidden) {
86909ce0 326 echo "<a title=\"$strrestore\" href=\"edit.php?".$pageurl->get_query_string()."&amp;unhide=$question->id&amp;sesskey=$USER->sesskey\"><img
0fd5feef 327 src=\"$CFG->pixpath/t/restore.gif\" alt=\"$strrestore\" /></a>";
516cf3eb 328 } else {
86909ce0 329 echo "<a title=\"$strdelete\" href=\"edit.php?".$pageurl->get_query_string()."&amp;deleteselected=$question->id&amp;q$question->id=1\"><img
0fd5feef 330 src=\"$CFG->pixpath/t/delete.gif\" alt=\"$strdelete\" /></a>";
516cf3eb 331 }
332 }
333 echo "&nbsp;<input title=\"$strselect\" type=\"checkbox\" name=\"q$question->id\" value=\"1\" />";
334 echo "</td>\n";
335
70ed7667 336 echo "<td $nameclass>" . format_string($question->name) . "</td>\n";
624cbc9c 337 echo "<td $nameclass style='text-align: right'>\n";
dcc2ffde 338 print_question_icon($question);
516cf3eb 339 echo "</td>\n";
340 echo "</tr>\n";
624cbc9c 341 if($showquestiontext){
342 echo '<tr><td colspan="3" ' . $textclass . '>';
343 $formatoptions = new stdClass;
344 $formatoptions->noclean = true;
345 $formatoptions->para = false;
346 echo format_text($question->questiontext, $question->questiontextformat,
347 $formatoptions, $course->id);
348 echo "</td></tr>\n";
349 }
516cf3eb 350 }
624cbc9c 351 echo "</table>\n";
624cbc9c 352
353 $paging = print_paging_bar($totalnumber, $page, $perpage,
86909ce0 354 "edit.php?".$pageurl->get_query_string()."&amp;perpage=$perpage&amp;", 'page',
624cbc9c 355 false, true);
f92cf442 356 if ($totalnumber > DEFAULT_QUESTIONS_PER_PAGE) {
357 if ($perpage == DEFAULT_QUESTIONS_PER_PAGE) {
86909ce0 358 $showall = '<a href="edit.php?'.$pageurl->get_query_string().'&amp;perpage=1000">'.get_string('showall', 'moodle', $totalnumber).'</a>';
f92cf442 359 } else {
86909ce0 360 $showall = '<a href="edit.php?'.$pageurl->get_query_string().'&amp;perpage=' . DEFAULT_QUESTIONS_PER_PAGE . '">'.get_string('showperpage', 'moodle', DEFAULT_QUESTIONS_PER_PAGE).'</a>';
624cbc9c 361 }
362 if ($paging) {
363 $paging = substr($paging, 0, strrpos($paging, '</div>'));
364 $paging .= "<br />$showall</div>";
365 } else {
366 $paging = "<div class='paging'>$showall</div>";
f92cf442 367 }
3abfa3a0 368 }
624cbc9c 369 echo $paging;
516cf3eb 370
371 echo '<table class="quiz-edit-selected"><tr><td colspan="2">';
372 echo '<a href="javascript:select_all_in(\'TABLE\', null, \'categoryquestions\');">'.$strselectall.'</a> /'.
373 ' <a href="javascript:deselect_all_in(\'TABLE\', null, \'categoryquestions\');">'.$strselectnone.'</a>'.
374 '</td><td align="right"><b>&nbsp;'.get_string('withselected', 'quiz').':</b></td></tr><tr><td>';
95947ac9 375
dcc2ffde 376 if ($editingquiz) {
95947ac9 377 echo "<input type=\"submit\" name=\"add\" value=\"{$THEME->larrow} $straddtoquiz\" />\n";
516cf3eb 378 echo '</td><td>';
379 }
3765fd53 380 // print delete and move selected question
dcc2ffde 381 if ($canedit) {
516cf3eb 382 echo '<input type="submit" name="deleteselected" value="'.$strdelete."\" /></td><td>\n";
383 echo '<input type="submit" name="move" value="'.get_string('moveto', 'quiz')."\" />\n";
dc1f00de 384 question_category_select_menu($course->id, false, true, $category->id);
516cf3eb 385 }
386 echo "</td></tr></table>";
387
3765fd53 388 // add random question
dcc2ffde 389 if ($editingquiz) {
b28e2577 390 for ($i = 1;$i <= min(10, $totalnumber); $i++) {
391 $randomcount[$i] = $i;
392 }
393 for ($i = 20;$i <= min(100, $totalnumber); $i += 10) {
516cf3eb 394 $randomcount[$i] = $i;
395 }
396 echo '<br />';
86909ce0 397 print_string('addrandom', 'quiz', choose_from_menu($randomcount, 'randomcount', '1', '', '', '', true));
516cf3eb 398 echo '<input type="hidden" name="recurse" value="'.$recurse.'" />';
399 echo "<input type=\"hidden\" name=\"categoryid\" value=\"$category->id\" />";
400 echo ' <input type="submit" name="addrandom" value="'. get_string('add') .'" />';
401 helpbutton('random', get_string('random', 'quiz'), 'quiz');
402 }
09275894 403 echo '</fieldset>';
404 echo "</form>\n";
516cf3eb 405}
86909ce0 406/**
407 * Shows the question bank editing interface.
408 *
409 * The function also processes a number of actions:
410 *
411 * Actions affecting the question pool:
412 * move Moves a question to a different category
413 * deleteselected Deletes the selected questions from the category
414 * Other actions:
415 * cat Chooses the category
416 * displayoptions Sets display options
417 *
418 * @author Martin Dougiamas and many others. This has recently been extensively
419 * rewritten by Gustav Delius and other members of the Serving Mathematics project
420 * {@link http://maths.york.ac.uk/serving_maths}
421 * @param moodle_url $pageurl object representing this pages url.
422 */
423function showbank($pageurl, $cm){
424 global $SESSION, $COURSE;
425 $page = optional_param('page', -1, PARAM_INT);
426 $perpage = optional_param('perpage', -1, PARAM_INT);
427 $sortorder = optional_param('sortorder', '');
428 if (preg_match("/[';]/", $sortorder)) {
429 error("Incorrect use of the parameter 'sortorder'");
430 }
516cf3eb 431
86909ce0 432 if ($page > -1) {
433 $SESSION->questionpage = $page;
434 } else {
435 $page = isset($SESSION->questionpage) ? $SESSION->questionpage : 0;
436 }
437
438 if ($perpage > -1) {
439 $SESSION->questionperpage = $perpage;
440 } else {
441 $perpage = isset($SESSION->questionperpage) ? $SESSION->questionperpage : DEFAULT_QUESTIONS_PER_PAGE;
442 }
443
444 if ($sortorder) {
445 $SESSION->questionsortorder = $sortorder;
446 } else {
447 $sortorder = isset($SESSION->questionsortorder) ? $SESSION->questionsortorder : 'qtype, name ASC';
448 }
449 $SESSION->fromurl = $pageurl->out();
450
451/// Now, check for commands on this page and modify variables as necessary
452 if (isset($_REQUEST['move']) and confirm_sesskey()) { /// Move selected questions to new category
453 $tocategoryid = required_param('category', PARAM_INT);
454 if (!$tocategory = get_record('question_categories', 'id', $tocategoryid)) {
455 error('Invalid category');
456 }
457 if (!has_capability('moodle/question:managecategory', get_context_instance(CONTEXT_COURSE, $tocategory->course))){
458 error(get_string('categorynoedit', 'quiz', $tocategory->name), $pageurl->out());
459 }
460 foreach ($_POST as $key => $value) { // Parse input for question ids
461 if (substr($key, 0, 1) == "q") {
462 $key = substr($key,1);
463 if (!set_field('question', 'category', $tocategory->id, 'id', $key)) {
464 error('Could not update category field');
465 }
466 }
467 }
468 }
469
470 if (isset($_REQUEST['deleteselected'])) { // delete selected questions from the category
471
472 if (isset($_REQUEST['confirm']) and confirm_sesskey()) { // teacher has already confirmed the action
473 $deleteselected = required_param('deleteselected');
474 if ($_REQUEST['confirm'] == md5($deleteselected)) {
475 if ($questionlist = explode(',', $deleteselected)) {
476 // for each question either hide it if it is in use or delete it
477 foreach ($questionlist as $questionid) {
478 if (record_exists('quiz_question_instances', 'question', $questionid) or
479 record_exists('question_states', 'originalquestion', $questionid)) {
480 if (!set_field('question', 'hidden', 1, 'id', $questionid)) {
481 error('Was not able to hide question');
482 }
483 } else {
484 delete_question($questionid);
485 }
486 }
487 }
488 echo '</td></tr>';
489 echo '</table>';
490 echo '</div>';
491 redirect($pageurl->out());
492 } else {
493 error("Confirmation string was incorrect");
494 }
495
496 } else { // teacher still has to confirm
497 // make a list of all the questions that are selected
498 $rawquestions = $_REQUEST;
499 $questionlist = ''; // comma separated list of ids of questions to be deleted
500 $questionnames = ''; // string with names of questions separated by <br /> with
501 // an asterix in front of those that are in use
502 $inuse = false; // set to true if at least one of the questions is in use
503 foreach ($rawquestions as $key => $value) { // Parse input for question ids
504 if (substr($key, 0, 1) == "q") {
505 $key = substr($key,1);
506 $questionlist .= $key.',';
507 if (record_exists('quiz_question_instances', 'question', $key) or
508 record_exists('question_states', 'originalquestion', $key)) {
509 $questionnames .= '* ';
510 $inuse = true;
511 }
512 $questionnames .= get_field('question', 'name', 'id', $key).'<br />';
513 }
514 }
515 if (!$questionlist) { // no questions were selected
516 redirect($pageurl->out());
517 }
518 $questionlist = rtrim($questionlist, ',');
519
520 // Add an explanation about questions in use
521 if ($inuse) {
522 $questionnames .= '<br />'.get_string('questionsinuse', 'quiz');
523 }
524 notice_yesno(get_string("deletequestionscheck", "quiz", $questionnames),
525 $pageurl->out_action(array('deleteselected'=>$questionlist, 'confirm'=>md5($questionlist))),
526 $pageurl->out_action());
527
528 echo '</td></tr>';
529 echo '</table>';
530 print_footer($COURSE);
531 exit;
532 }
533 }
534
535 // Unhide a question
536 if(isset($_REQUEST['unhide']) && confirm_sesskey()) {
537 $unhide = required_param('unhide', PARAM_INT);
538 if(!set_field('question', 'hidden', 0, 'id', $unhide)) {
539 error("Failed to unhide the question.");
540 }
541 redirect($pageurl->out());
542 }
543
544 if ($categoryid = optional_param('cat', 0, PARAM_INT)) { /// coming from category selection drop-down menu
545 $SESSION->questioncat = $categoryid;
546 $page = 0;
547 $SESSION->questionpage = 0;
548 }
549
550 if (empty($SESSION->questioncat) or !count_records_select("question_categories", "id = '{$SESSION->questioncat}' AND (course = '{$COURSE->id}' OR publish = '1')")) {
551 $category = get_default_question_category($COURSE->id);
552 $SESSION->questioncat = $category->id;
553 }
554
555 if(($recurse = optional_param('recurse', -1, PARAM_BOOL)) != -1) {
556 $SESSION->questionrecurse = $recurse;
557 }
558 if (!isset($SESSION->questionrecurse)) {
559 $SESSION->questionrecurse = 1;
560 }
561
562 if(($showhidden = optional_param('showhidden', -1, PARAM_BOOL)) != -1) {
563 $SESSION->questionshowhidden = $showhidden;
564 }
565 if (!isset($SESSION->questionshowhidden)) {
566 $SESSION->questionshowhidden = 0;
567 }
568
569 if(($showquestiontext = optional_param('showquestiontext', -1, PARAM_BOOL)) != -1) {
570 $SESSION->questionshowquestiontext = $showquestiontext;
571 }
572 if (!isset($SESSION->questionshowquestiontext)) {
573 $SESSION->questionshowquestiontext = 0;
574 }
575
576 // starts with category selection form
577 print_box_start('generalbox questionbank');
578 print_heading(get_string('questionbank', 'question'), '', 2);
579 question_category_form($COURSE, $pageurl, $SESSION->questioncat, $SESSION->questionrecurse,
580 $SESSION->questionshowhidden, $SESSION->questionshowquestiontext);
581
582 // continues with list of questions
583 question_list($COURSE, $pageurl, $SESSION->questioncat, isset($cm) ? $cm : null,
584 $SESSION->questionrecurse, $page, $perpage, $SESSION->questionshowhidden, $sortorder,
585 $SESSION->questionshowquestiontext);
586
587 print_box_end();
588}
5fd8f999 589?>