Updated questionlib to work with the new location of the question scripts
[moodle.git] / question / editlib.php
CommitLineData
516cf3eb 1<?php // $Id$
2/**
3* Functions used by edit.php to edit quizzes
4*
5* @version $Id$
6* @author Martin Dougiamas and many others. This has recently been extensively
7* rewritten by members of the Serving Mathematics project
8* {@link http://maths.york.ac.uk/serving_maths}
9* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
10* @package quiz
11*/
12
13require_once("locallib.php");
14
15/**
16* Array of question types names translated to the user's language
17*
18* The $QUIZ_QUESTION_TYPE array holds the names of all the question types that the user should
19* be able to create directly. Some internal question types like random questions are excluded.
20* The complete list of question types can be found in {@link $QUIZ_QTYPES}.
21*/
22
23$QUIZ_QUESTION_TYPE = array ( MULTICHOICE => get_string("multichoice", "quiz"),
24 TRUEFALSE => get_string("truefalse", "quiz"),
25 SHORTANSWER => get_string("shortanswer", "quiz"),
26 NUMERICAL => get_string("numerical", "quiz"),
27 CALCULATED => get_string("calculated", "quiz"),
28 MATCH => get_string("match", "quiz"),
29 DESCRIPTION => get_string("description", "quiz"),
30 RANDOMSAMATCH => get_string("randomsamatch", "quiz"),
31 MULTIANSWER => get_string("multianswer", "quiz"),
32 ESSAY => get_string("essay", "quiz")
33 );
34// add remote question types
35if ($rqp_types = get_records('quiz_rqp_types')) {
36 foreach($rqp_types as $type) {
37 $QUIZ_QUESTION_TYPE[100+$type->id] = $type->name;
38 }
39}
40
41
42/**
43* Delete a question from a quiz
44*
45* Deletes a question or a pagebreak from a quiz by updating $modform
46* as well as the quiz, quiz_question_instances
47* @return boolean false if the question was not in the quiz
48* @param int $id The id of the question to be deleted
49* @param object $modform The extended quiz object as used by edit.php
50* This is updated by this function
51*/
52function quiz_delete_quiz_question($id, &$modform) {
53 // TODO: For the sake of safety check that this question can be deleted
54 // safely, i.e., that it is not already in use.
55 $questions = explode(",", $modform->questions);
56
57 // only do something if this question exists
58 if (!isset($questions[$id])) {
59 return false;
60 }
61
62 $question = $questions[$id];
63 unset($questions[$id]);
64 // If we deleted the question at the top and it was followed by
65 // a page break then delete page break as well
66 if ($id == 0 and $questions[1] == 0) {
67 unset($questions[1]);
68 }
69 $modform->questions = implode(",", $questions);
70 // Avoid duplicate page breaks
71 $modform->questions = str_replace(',0,0', ',0', $modform->questions);
72 // save new questionlist in database
73 if (!set_field('quiz', 'questions', $modform->questions, 'id', $modform->instance)) {
74 error('Could not save question list');
75 }
76}
77
78
79/**
80* Add a question to a quiz
81*
82* Adds a question to a quiz by updating $modform as well as the
83* quiz and quiz_question_instances tables. It also adds a page break
84* if required.
85* @return boolean false if the question was already in the quiz
86* @param int $id The id of the question to be added
87* @param object $modform The extended quiz object as used by edit.php
88* This is updated by this function
89*/
90function quiz_add_quiz_question($id, &$modform) {
91 $questions = explode(",", $modform->questions);
92
93 if (in_array($id, $questions)) {
94 return false;
95 }
96
97 // remove ending page break if it is not needed
98 if ($breaks = array_keys($questions, 0)) {
99 // determine location of the last two page breaks
100 $end = end($breaks);
101 $last = prev($breaks);
102 $last = $last ? $last : -1;
103 if (!$modform->questionsperpage or (($end - $last -1) < $modform->questionsperpage)) {
104 array_pop($questions);
105 }
106 }
107 // add question
108 $questions[] = $id;
109 // add ending page break
110 $questions[] = 0;
111
112 // Save new questionslist in database
113 $modform->questions = implode(",", $questions);
114 if (!set_field('quiz', 'questions', $modform->questions, 'id', $modform->id)) {
115 error('Could not save question list');
116 }
117
118 // update question grades
119 $questionrecord = get_record("quiz_questions", "id", $id);
120 $modform->grades[$id] = $questionrecord->defaultgrade;
121 quiz_update_question_instance($modform->grades[$id], $id, $modform->instance);
122
123 return true;
124}
125
126/**
127* Save changes to question instance
128*
129* Saves changes to the question grades in the quiz_question_instances table.
130* It does not update 'sumgrades' in the quiz table.
131* @return boolean Indicates success or failure.
132* @param integer grade The maximal grade for the question
133* @param integer $questionid The id of the question
134* @param integer $quizid The id of the quiz to update / add the instances for.
135*/
136function quiz_update_question_instance($grade, $questionid, $quizid) {
137 if ($instance = get_record("quiz_question_instances", "quiz", $quizid, 'question', $questionid)) {
138 $instance->grade = $grade;
139 return update_record('quiz_question_instances', $instance);
140 } else {
141 unset($instance);
142 $instance->quiz = $quizid;
143 $instance->question = $questionid;
144 $instance->grade = $grade;
145 return insert_record("quiz_question_instances", $instance);
146 }
147}
148
149/**
150* Prints a list of quiz questions in a small layout form with knobs
151*
152* @return int sum of maximum grades
153* @param object $quiz This is not the standard quiz object used elsewhere but
154* it contains the quiz layout in $quiz->questions and the grades in
155* $quiz->grades
156* @param boolean $allowdelete Indicates whether the delete icons should be displayed
157* @param boolean $showbreaks Indicates whether the page breaks should be displayed
158* @param boolean $showbreaks Indicates whether the reorder tool should be displayed
159*/
160function quiz_print_question_list($quiz, $allowdelete=true, $showbreaks=true, $reordertool=false) {
161 global $USER, $CFG, $QUIZ_QTYPES;
162
163 $strorder = get_string("order");
164 $strquestionname = get_string("questionname", "quiz");
165 $strgrade = get_string("grade");
166 $strremove = get_string('remove', 'quiz');
167 $stredit = get_string("edit");
168 $straction = get_string("action");
169 $strmoveup = get_string("moveup");
170 $strmovedown = get_string("movedown");
171 $strsavegrades = get_string("savegrades", "quiz");
172 $strtype = get_string("type", "quiz");
173 $strpreview = get_string("preview", "quiz");
174
175 if (!$quiz->questions) {
176 echo "<p align=\"center\">";
177 print_string("noquestions", "quiz");
178 echo "</p>";
179 return 0;
180 }
181
182 if (!$questions = get_records_sql("SELECT q.*,c.course
183 FROM {$CFG->prefix}quiz_questions q,
184 {$CFG->prefix}quiz_categories c
185 WHERE q.id in ($quiz->questions)
186 AND q.category = c.id")) {
187 echo "<p align=\"center\">";
188 print_string("noquestions", "quiz");
189 echo "</p>";
190 return 0;
191 }
192
193 $count = 0;
194 $qno = 1;
195 $sumgrade = 0;
196 $order = explode(",", $quiz->questions);
197 $lastindex = count($order)-1;
198 // If the list does not end with a pagebreak then add it on.
199 if ($order[$lastindex] != 0) {
200 $order[] = 0;
201 $lastindex++;
202 }
203 echo "<form method=\"post\" action=\"edit.php\">";
204 echo "<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
205
206 print_simple_box_start('center', '100%', '#ffffff', 0);
207 echo "<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\" width=\"100%\">\n";
208 echo "<tr><th colspan=\"3\" nowrap=\"nowrap\" class=\"header\">$strorder</th><th class=\"header\">#</th><th align=\"left\" width=\"100%\" nowrap=\"nowrap\" class=\"header\">$strquestionname</th><th nowrap=\"nowrap\" class=\"header\">$strtype</th><th nowrap=\"nowrap\" class=\"header\">$strgrade</th><th align=\"center\" width=\"60\" nowrap=\"nowrap\" class=\"header\">$straction</th></tr>\n";
209 foreach ($order as $i => $qnum) {
210
211 if ($qnum and empty($questions[$qnum])) {
212 continue;
213 }
214 // Show the re-ordering field if the tool is turned on.
215 // But don't show it in front of pagebreaks if they are hidden.
216 if ($reordertool) {
217 if ($qnum or $showbreaks) {
218 echo '<tr><td><input type="text" name="o'.$i.'" size="2" value="'.(10*$count+10).'" /></td>';
219 } else {
220 echo '<tr><td><input type="hidden" name="o'.$i.'" size="2" value="'.(10*$count+10).'" /></td>';
221 }
222 } else {
223 echo '<tr><td></td>';
224 }
225 if ($qnum == 0) { // This is a page break
226 if ($showbreaks) {
227 echo '<td colspan ="3">&nbsp;</td>';
228 echo '<td><table width="100%" style="line-height:11px; font-size:9px; margin: -5px -5px;"><tr>';
229 echo '<td><hr noshade="noshade" /></td>';
230 echo '<td width="50">Page break</td>';
231 echo '<td><hr noshade="noshade" /></td><td width="45">';
232 if ($count > 1) {
233 echo "<a title=\"$strmoveup\" href=\"edit.php?up=$count&amp;sesskey=$USER->sesskey\"><img
234 src=\"$CFG->pixpath/t/up.gif\" border=\"0\" alt=\"$strmoveup\" /></a>";
235 }
236 echo '&nbsp;';
237 if ($count < $lastindex) {
238 echo "<a title=\"$strmovedown\" href=\"edit.php?down=$count&amp;sesskey=$USER->sesskey\"><img
239 src=\"$CFG->pixpath/t/down.gif\" border=\"0\" alt=\"$strmovedown\" /></a>";
240
241 echo "<a title=\"$strremove\" href=\"edit.php?delete=$count&amp;sesskey=$USER->sesskey\">
242 <img src=\"$CFG->pixpath/t/delete.gif\" border=\"0\" alt=\"$strremove\" /></a>";
243 }
244 echo '</td></tr></table></td>';
245 echo '<td colspan="2">&nbsp;</td></tr>';
246 }
247 $count++;
248 continue;
249 }
250 $question = $questions[$qnum];
251 $canedit = isteacheredit($question->course);
252
253 echo "<td>";
254 if ($count != 0) {
255 echo "<a title=\"$strmoveup\" href=\"edit.php?up=$count&amp;sesskey=$USER->sesskey\"><img
256 src=\"$CFG->pixpath/t/up.gif\" border=\"0\" alt=\"$strmoveup\" /></a>";
257 }
258 echo "</td>";
259 echo "<td>";
260 if ($count < $lastindex-1) {
261 echo "<a title=\"$strmovedown\" href=\"edit.php?down=$count&amp;sesskey=$USER->sesskey\"><img
262 src=\"$CFG->pixpath/t/down.gif\" border=\"0\" alt=\"$strmovedown\" /></a>";
263 }
264 echo "</td>";
265
266 if (!$quiz->shufflequestions) {
267 // Print and increment question number
268 echo '<td>'.($question->length ? $qno : '&nbsp;').'</td>';
269 $qno += $question->length;
270 } else {
271 echo '<td>&nbsp;</td>';
272 }
273
274 echo "<td>$question->name</td>";
275 echo "<td align=\"center\">";
276 quiz_print_question_icon($question, $canedit);
277 echo "</td>";
278 echo '<td align="left">';
279 if ($question->qtype == DESCRIPTION) {
280 echo "<input type=\"hidden\" name=\"q$qnum\" value=\"0\" /> \n";
281 } else {
282 echo '<input type="text" name="q'.$qnum.'" size="2" value="'.$quiz->grades[$qnum].
283 '" tabindex="'.($lastindex+$qno).'" />';
284 }
285 echo '</td><td align="center">';
286
287 $context = $quiz->id ? '&amp;contextquiz='.$quiz->id : '';
288 $quiz_id = $quiz->id ? '&amp;quizid=' . $quiz->id : '';
289 echo "<a title=\"$strpreview\" href=\"javascript:void();\" onClick=\"openpopup('/mod/quiz/preview.php?id=$qnum$quiz_id','$strpreview','scrollbars=yes,resizable=yes,width=700,height=480', false)\">
290 <img src=\"$CFG->pixpath/t/preview.gif\" border=\"0\" alt=\"$strpreview\" /></a>";
291 if ($canedit) {
292 echo "<a title=\"$stredit\" href=\"question.php?id=$qnum$context\">
293 <img src=\"$CFG->pixpath/t/edit.gif\" border=\"0\" alt=\"$stredit\" /></a>";
294 }
295 if ($allowdelete) {
296 echo "<a title=\"$strremove\" href=\"edit.php?delete=$count&amp;sesskey=$USER->sesskey\">
297 <img src=\"$CFG->pixpath/t/removeright.gif\" border=\"0\" alt=\"$strremove\" /></a>";
298 }
299
300 echo "</td></tr>";
301 $count++;
302 $sumgrade += $quiz->grades[$qnum];
303 }
304
305 echo "<tr><td colspan=\"6\" align=\"right\">\n";
306 print_string('total');
307 echo ": <td align=\"left\">\n";
308 echo "<b>$sumgrade</b>";
309 echo "</td><td>&nbsp;\n</td></tr>\n";
310
311 echo "<tr><td colspan=\"6\" align=\"right\">\n";
312 print_string('maximumgrade');
313 echo ": <td align=\"left\">\n";
314 echo '<input type="text" name="maxgrade" size="2" tabindex="'.($qno+1)
315 .'" value="'.$quiz->grade.'" />';
316 echo '</td><td align="left">';
317 helpbutton("maxgrade", get_string("maximumgrade"), "quiz");
318 echo "</td></tr></table>\n";
319
320 echo '<div align="center"><input type="submit" value="'.get_string('savechanges').'" />';
321 echo '<input type="hidden" name="savechanges" value="save" /></div>';
322
323 print_simple_box_end();
324 echo "</form>\n";
325
326/// Form to choose to show pagebreaks and to repaginate quiz
327 echo '<form method="post" action="edit.php" name="showbreaks">';
328 echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
329 echo '<input type="hidden" name="showbreaks" value="0" />';
330 echo '<input type="checkbox" name="showbreaks" value="1"';
331 if ($showbreaks) {
332 echo ' checked="checked"';
333 }
334 echo ' onchange="document.showbreaks.submit(); return true;" />';
335 print_string('showbreaks', 'quiz');
336
337 if ($showbreaks) {
338 $perpage= array();
339 for ($i=0; $i<=50; ++$i) {
340 $perpage[$i] = $i;
341 }
342 $perpage[0] = get_string('allinone', 'quiz');
343 echo '<br />&nbsp;&nbsp;';
344 print_string('repaginate', 'quiz',
345 choose_from_menu($perpage, 'questionsperpage', $quiz->questionsperpage, '', '', '', true));
346 }
347
348 echo '<br /><input type="hidden" name="reordertool" value="0" />';
349 echo '<input type="checkbox" name="reordertool" value="1"';
350 if ($reordertool) {
351 echo ' checked="checked"';
352 }
353 echo ' onchange="document.showbreaks.submit(); return true;" />';
354 print_string('reordertool', 'quiz');
355 helpbutton('reorderingtool', get_string('reorderingtool', 'quiz'), 'quiz');
356
357 echo '<div align="center"><input type="submit" name="repaginate" value="'. get_string('go') .'" /></div>';
358 echo '</form>';
359
360 return $sumgrade;
361}
362
363function quiz_print_category_form($course, $current, $recurse=1, $showhidden=false) {
364/// Prints a form to choose categories
365
366/// Make sure the default category exists for this course
367 if (!$categories = get_records("quiz_categories", "course", $course->id, "id ASC")) {
368 if (!$category = quiz_get_default_category($course->id)) {
369 notify("Error creating a default category!");
370 }
371 }
372
373/// Get all the existing categories now
374 if (!$categories = get_records_select("quiz_categories", "course = '{$course->id}' OR publish = '1'", "parent, sortorder, name ASC")) {
375 notify("Could not find any question categories!");
376 return false; // Something is really wrong
377 }
378 $categories = add_indented_names($categories);
379 foreach ($categories as $key => $category) {
380 if ($catcourse = get_record("course", "id", $category->course)) {
381 if ($category->publish && $category->course != $course->id) {
382 $category->indentedname .= " ($catcourse->shortname)";
383 }
384 $catmenu[$category->id] = $category->indentedname;
385 }
386 }
387 $strcategory = get_string("category", "quiz");
388 $strshow = get_string("show", "quiz");
389 $streditcats = get_string("editcategories", "quiz");
390
391 echo "<table width=\"100%\"><tr><td width=\"20\" nowrap=\"nowrap\">";
392 echo "<b>$strcategory:</b>&nbsp;";
393 echo "</td><td>";
394 popup_form ("edit.php?cat=", $catmenu, "catmenu", $current, "", "", "", false, "self");
395 echo "</td><td align=\"right\">";
396 echo "<form method=\"get\" action=\"category.php\">";
397 echo "<input type=\"hidden\" name=\"id\" value=\"$course->id\" />";
398 echo "<input type=\"submit\" value=\"$streditcats\" />";
399 echo "</form>";
400 echo '</td></tr></table>';
401 echo '<form method="post" action="edit.php" name="displayoptions">';
402 echo '<table><tr><td>';
403 echo '<input type="hidden" name="recurse" value="0" />';
404 echo '<input type="checkbox" name="recurse" value="1"';
405 if ($recurse) {
406 echo ' checked="checked"';
407 }
408 echo ' onchange="document.displayoptions.submit(); return true;" />';
409 print_string('recurse', 'quiz');
410 // hide-feature
411 echo '<br />';
412 echo '<input type="hidden" name="showhidden" value="0" />';
413 echo '<input type="checkbox" name="showhidden"';
414 if ($showhidden) {
415 echo ' checked="checked"';
416 }
417 echo ' onchange="document.displayoptions.submit(); return true;" />';
418 print_string('showhidden', 'quiz');
419 echo '</td><noscript><td valign="center">';
420 echo ' <input type="submit" value="'. get_string('go') .'" />';
421 echo '</td></noscript></tr></table></form>';
422}
423
424
425/**
426* Prints the table of questions in a category with interactions
427*
428* @param object $course The course object
429* @param int $categoryid The id of the question category to be displayed
430* @param int $quizid The quiz id if we are in the context of a particular quiz, 0 otherwise
431* @param int $recurse This is 1 if subcategories should be included, 0 otherwise
432* @param int $page The number of the page to be displayed
433* @param int $perpage Number of questions to show per page
434* @param boolean $showhidden True if also hidden questions should be displayed
435*/
436function quiz_print_cat_question_list($course, $categoryid, $quizid,
437 $recurse=1, $page, $perpage, $showhidden=false, $sortorder='qtype, name ASC') {
438 global $QUIZ_QUESTION_TYPE, $USER, $CFG;
439
440 $strcategory = get_string("category", "quiz");
441 $strquestion = get_string("question", "quiz");
442 $straddquestions = get_string("addquestions", "quiz");
443 $strimportquestions = get_string("importquestions", "quiz");
444 $strexportquestions = get_string("exportquestions", "quiz");
445 $strnoquestions = get_string("noquestions", "quiz");
446 $strselect = get_string("select", "quiz");
447 $strselectall = get_string("selectall", "quiz");
448 $strselectnone = get_string("selectnone", "quiz");
449 $strcreatenewquestion = get_string("createnewquestion", "quiz");
450 $strquestionname = get_string("questionname", "quiz");
451 $strdelete = get_string("delete");
452 $stredit = get_string("edit");
453 $straction = get_string("action");
454 $strrestore = get_string('restore');
455
456 $straddtoquiz = get_string("addtoquiz", "quiz");
457 $strtype = get_string("type", "quiz");
458 $strcreatemultiple = get_string("createmultiple", "quiz");
459 $strpreview = get_string("preview","quiz");
460
461 if (!$categoryid) {
462 echo "<p align=\"center\"><b>";
463 print_string("selectcategoryabove", "quiz");
464 echo "</b></p>";
465 if ($quizid) {
466 echo "<p>";
467 print_string("addingquestions", "quiz");
468 echo "</p>";
469 }
470 return;
471 }
472
473 if (!$category = get_record("quiz_categories", "id", "$categoryid")) {
474 notify("Category not found!");
475 return;
476 }
477 echo "<center>";
478 echo format_text($category->info, FORMAT_MOODLE);
479
480 echo '<table><tr>';
481
482 // check if editing of this category is allowed
483 if (isteacheredit($category->course)) {
484 echo "<td valign=\"top\"><b>$strcreatenewquestion:</b></td>";
485 echo '<td valign="top" align="right">';
486 popup_form ("question.php?category=$category->id&amp;qtype=", $QUIZ_QUESTION_TYPE, "addquestion",
487 "", "choose", "", "", false, "self");
488 echo '</td><td width="10" valign="top" align="right">';
489 helpbutton("questiontypes", $strcreatenewquestion, "quiz");
490 echo '</td></tr>';
491 }
492 else {
493 echo '<tr><td>';
494 print_string("publishedit","quiz");
495 echo '</td></tr>';
496 }
497
498 echo '<tr><td colspan="3" align="right"><font size="2">';
499 if (isteacheredit($category->course)) {
500 echo '<a href="import.php?category='.$category->id.'">'.$strimportquestions.'</a>';
501 helpbutton("import", $strimportquestions, "quiz");
502 echo ' | ';
503 }
504 echo "<a href=\"export.php?category={$category->id}&amp;courseid={$course->id}\">$strexportquestions</a>";
505 helpbutton("export", $strexportquestions, "quiz");
506 echo '</font></td></tr>';
507
508 echo '</table>';
509
510 echo '</center>';
511
512 $categorylist = ($recurse) ? quiz_categorylist($category->id) : $category->id;
513
514 // hide-feature
515 $showhidden = $showhidden ? '' : " AND hidden = '0'";
516
517 if (!$totalnumber = count_records_select('quiz_questions', "category IN ($categorylist) AND parent = '0' $showhidden")) {
518 echo "<p align=\"center\">";
519 print_string("noquestions", "quiz");
520 echo "</p>";
521 return;
522 }
523
524 if (!$questions = get_records_select('quiz_questions', "category IN ($categorylist) AND parent = '0' $showhidden", $sortorder, '*', $page*$perpage, $perpage)) {
525 // There are no questions on the requested page.
526 $page = 0;
527 if (!$questions = get_records_select('quiz_questions', "category IN ($categorylist) AND parent = '0' $showhidden", $sortorder, '*', 0, $perpage)) {
528 // There are no questions at all
529 echo "<p align=\"center\">";
530 print_string("noquestions", "quiz");
531 echo "</p>";
532 return;
533 }
534 }
535
536 print_paging_bar($totalnumber, $page, $perpage,
537 "edit.php?perpage=$perpage&amp;");
538
539 $canedit = isteacheredit($category->course);
540
541 echo '<form method="post" action="edit.php">';
542 echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
543 print_simple_box_start('center', '100%', '#ffffff', 0);
544 echo '<table id="categoryquestions" cellspacing="0"><tr>';
545 $actionwidth = $canedit ? 95 : 70;
546 echo "<th width=\"$actionwidth\" nowrap=\"nowrap\" class=\"header\">$straction</th>";
547
548 $sortoptions = array('name, qtype ASC' => get_string("sortalpha", "quiz"),
549 'qtype, name ASC' => get_string("sorttypealpha", "quiz"),
550 'id ASC' => get_string("sortage", "quiz"));
551 $orderselect = choose_from_menu ($sortoptions, 'sortorder', $sortorder, false, 'this.form.submit();', '0', true);
552 $orderselect .= '<noscript><input type="submit" value="'.get_string("sortsubmit", "quiz").'" /></noscript>';
553 echo "<th width=\"100%\" align=\"left\" nowrap=\"nowrap\" class=\"header\">$strquestionname $orderselect</th>
554 <th nowrap=\"nowrap\" class=\"header\">$strtype</th>";
555 echo "</tr>\n";
556 foreach ($questions as $question) {
557 if ($question->qtype == RANDOM) {
558 //continue;
559 }
560 echo "<tr>\n<td nowrap=\"nowrap\">\n";
561 if ($quizid) {
562 echo "<a title=\"$straddtoquiz\" href=\"edit.php?addquestion=$question->id&amp;sesskey=$USER->sesskey\"><img
563 src=\"$CFG->pixpath/t/moveleft.gif\" border=\"0\" alt=\"$straddtoquiz\" /></a>&nbsp;";
564 }
565 echo "<a title=\"$strpreview\" href=\"javascript:void();\" onClick=\"openpopup('/mod/quiz/preview.php?id=$question->id&quizid=$quizid','$strpreview','scrollbars=yes,resizable=yes,width=700,height=480', false)\"><img
566 src=\"$CFG->pixpath/t/preview.gif\" border=\"0\" alt=\"$strpreview\" /></a>&nbsp;";
567 if ($canedit) {
568 echo "<a title=\"$stredit\" href=\"question.php?id=$question->id\"><img
569 src=\"$CFG->pixpath/t/edit.gif\" border=\"0\" alt=\"$stredit\" /></a>&nbsp;";
570 // hide-feature
571 if($question->hidden) {
572 echo "<a title=\"$strrestore\" href=\"question.php?id=$question->id&amp;hide=0&amp;sesskey=$USER->sesskey\"><img
573 src=\"$CFG->pixpath/t/restore.gif\" border=\"0\" alt=\"$strrestore\" /></a>";
574 } else {
575 echo "<a title=\"$strdelete\" href=\"question.php?id=$question->id&amp;delete=$question->id\"><img
576 src=\"$CFG->pixpath/t/delete.gif\" border=\"0\" alt=\"$strdelete\" /></a>";
577 }
578 }
579 echo "&nbsp;<input title=\"$strselect\" type=\"checkbox\" name=\"q$question->id\" value=\"1\" />";
580 echo "</td>\n";
581
582 if ($question->hidden) {
583 echo '<td class="dimmed_text">'.$question->name."</td>\n";
584 } else {
585 echo "<td>".$question->name."</td>\n";
586 }
587 echo "<td align=\"center\">\n";
588 quiz_print_question_icon($question, $canedit);
589 echo "</td>\n";
590 echo "</tr>\n";
591 }
592 echo '<tr><td colspan="3">';
593 print_paging_bar($totalnumber, $page, $perpage, "edit.php?perpage=$perpage&amp;");
594 echo "</td></tr></table>\n";
595 print_simple_box_end();
596
597 echo '<table class="quiz-edit-selected"><tr><td colspan="2">';
598 echo '<a href="javascript:select_all_in(\'TABLE\', null, \'categoryquestions\');">'.$strselectall.'</a> /'.
599 ' <a href="javascript:deselect_all_in(\'TABLE\', null, \'categoryquestions\');">'.$strselectnone.'</a>'.
600 '</td><td align="right"><b>&nbsp;'.get_string('withselected', 'quiz').':</b></td></tr><tr><td>';
601 if ($quizid) {
602 echo "<input type=\"submit\" name=\"add\" value=\"<< $straddtoquiz\" />\n";
603 echo '</td><td>';
604 }
605 if ($canedit) {
606 echo '<input type="submit" name="deleteselected" value="'.$strdelete."\" /></td><td>\n";
607 echo '<input type="submit" name="move" value="'.get_string('moveto', 'quiz')."\" />\n";
608 quiz_category_select_menu($course->id, false, true, $category->id);
609 }
610 echo "</td></tr></table>";
611
612 if ($quizid) {
613 for ($i=1;$i<=10; $i++) {
614 $randomcount[$i] = $i;
615 }
616 echo '<br />';
617 print_string('addrandom', 'quiz',
618 choose_from_menu($randomcount, 'randomcount', '1', '', '', '', true));
619 echo '<input type="hidden" name="recurse" value="'.$recurse.'" />';
620 echo "<input type=\"hidden\" name=\"categoryid\" value=\"$category->id\" />";
621 echo ' <input type="submit" name="addrandom" value="'. get_string('add') .'" />';
622 helpbutton('random', get_string('random', 'quiz'), 'quiz');
623 }
624
625 echo "</form>\n";
626}
627
628?>