libdir.'/questionlib.php'); function question_category_form($course, $current, $recurse=1, $showhidden=false) { global $CFG; /// Prints a form to choose categories /// Make sure the default category exists for this course if (!$categories = get_records("question_categories", "course", $course->id, "id ASC")) { if (!$category = get_default_question_category($course->id)) { notify("Error creating a default category!"); } } /// Get all the existing categories now if (!$categories = get_records_select("question_categories", "course = '{$course->id}' OR publish = '1'", "parent, sortorder, name ASC")) { notify("Could not find any question categories!"); return false; // Something is really wrong } $categories = add_indented_names( $categories ); foreach ($categories as $key => $category) { if ($catcourse = get_record("course", "id", $category->course)) { if ($category->publish && $category->course != $course->id) { $category->indentedname .= " ($catcourse->shortname)"; } $catmenu[$category->id] = $category->indentedname; } } $strcategory = get_string("category", "quiz"); $strshow = get_string("show", "quiz"); $streditcats = get_string("editcategories", "quiz"); echo "
"; echo "$strcategory: "; echo ""; popup_form ("edit.php?courseid=$course->id&cat=", $catmenu, "catmenu", $current, "", "", "", false, "self"); echo ""; echo "
wwwroot/question/category.php\">"; echo "id\" />"; echo ""; echo "
"; echo '
'; echo '
'; echo '
'; echo "id}\" />"; echo ''; echo ''; print_string('recurse', 'quiz'); // hide-feature echo '
'; echo ''; echo ''; print_string('showhidden', 'quiz'); echo '
'; echo ' '; echo '
'; } /** * Prints the table of questions in a category with interactions * * @param object $course The course object * @param int $categoryid The id of the question category to be displayed * @param int $quizid The quiz id if we are in the context of a particular quiz, 0 otherwise * @param int $recurse This is 1 if subcategories should be included, 0 otherwise * @param int $page The number of the page to be displayed * @param int $perpage Number of questions to show per page * @param boolean $showhidden True if also hidden questions should be displayed */ function question_list($course, $categoryid, $quizid=0, $recurse=1, $page=0, $perpage=100, $showhidden=false, $sortorder='qtype, name ASC') { global $QTYPE_MENU, $USER, $CFG; $strcategory = get_string("category", "quiz"); $strquestion = get_string("question", "quiz"); $straddquestions = get_string("addquestions", "quiz"); $strimportquestions = get_string("importquestions", "quiz"); $strexportquestions = get_string("exportquestions", "quiz"); $strnoquestions = get_string("noquestions", "quiz"); $strselect = get_string("select", "quiz"); $strselectall = get_string("selectall", "quiz"); $strselectnone = get_string("selectnone", "quiz"); $strcreatenewquestion = get_string("createnewquestion", "quiz"); $strquestionname = get_string("questionname", "quiz"); $strdelete = get_string("delete"); $stredit = get_string("edit"); $straction = get_string("action"); $strrestore = get_string('restore'); $straddtoquiz = get_string("addtoquiz", "quiz"); $strtype = get_string("type", "quiz"); $strcreatemultiple = get_string("createmultiple", "quiz"); $strpreview = get_string("preview","quiz"); if (!$categoryid) { echo "

"; print_string("selectcategoryabove", "quiz"); echo "

"; if ($quizid) { echo "

"; print_string("addingquestions", "quiz"); echo "

"; } return; } if (!$category = get_record("question_categories", "id", "$categoryid")) { notify("Category not found!"); return; } echo "
"; $formatoptions->noclean = true; echo format_text($category->info, FORMAT_MOODLE, $formatoptions, $course->id); echo ''; // check if editing of this category is allowed if (isteacheredit($category->course)) { echo ""; echo ''; } else { echo ''; } echo ''; echo '
$strcreatenewquestion:'; popup_form ("$CFG->wwwroot/question/question.php?category=$category->id&qtype=", $QTYPE_MENU, "addquestion", "", "choose", "", "", false, "self"); echo ''; helpbutton("questiontypes", $strcreatenewquestion, "quiz"); echo '
'; print_string("publishedit","quiz"); echo '
'; if (isteacheredit($category->course)) { echo ''.$strimportquestions.''; helpbutton("import", $strimportquestions, "quiz"); echo ' | '; } echo "wwwroot/question/export.php?category={$category->id}&courseid={$course->id}\">$strexportquestions"; helpbutton("export", $strexportquestions, "quiz"); echo '
'; echo '
'; $categorylist = ($recurse) ? question_categorylist($category->id) : $category->id; // hide-feature $showhidden = $showhidden ? '' : " AND hidden = '0'"; if (!$totalnumber = count_records_select('question', "category IN ($categorylist) AND parent = '0' $showhidden")) { echo "

"; print_string("noquestions", "quiz"); echo "

"; return; } if (!$questions = get_records_select('question', "category IN ($categorylist) AND parent = '0' $showhidden", $sortorder, '*', $page*$perpage, $perpage)) { // There are no questions on the requested page. $page = 0; if (!$questions = get_records_select('question', "category IN ($categorylist) AND parent = '0' $showhidden", $sortorder, '*', 0, $perpage)) { // There are no questions at all echo "

"; print_string("noquestions", "quiz"); echo "

"; return; } } print_paging_bar($totalnumber, $page, $perpage, "edit.php?courseid={$course->id}&perpage=$perpage&"); $canedit = isteacheredit($category->course); echo '
'; echo ''; echo "id\" />"; print_simple_box_start('center', '100%', '#ffffff', 0); echo ''; $actionwidth = $canedit ? 95 : 70; echo ""; $sortoptions = array('name, qtype ASC' => get_string("sortalpha", "quiz"), 'qtype, name ASC' => get_string("sorttypealpha", "quiz"), 'id ASC' => get_string("sortage", "quiz")); $orderselect = choose_from_menu ($sortoptions, 'sortorder', $sortorder, false, 'this.form.submit();', '0', true); $orderselect .= ''; echo ""; echo "\n"; foreach ($questions as $question) { echo "\n\n"; if ($question->hidden) { echo '\n"; } else { echo "\n"; } echo "\n"; echo "\n"; } echo '
$straction$strquestionname $orderselect $strtype
\n"; if ($quizid) { echo "id&sesskey=$USER->sesskey\">pixpath/t/moveleft.gif\" border=\"0\" alt=\"$straddtoquiz\" /> "; } echo "id&quizid=$quizid','$strpreview','scrollbars=yes,resizable=yes,width=700,height=480', false)\">pixpath/t/preview.gif\" border=\"0\" alt=\"$strpreview\" /> "; if ($canedit) { echo "wwwroot/question/question.php?id=$question->id\">pixpath/t/edit.gif\" border=\"0\" alt=\"$stredit\" /> "; // hide-feature if($question->hidden) { echo "id&unhide=$question->id&sesskey=$USER->sesskey\">pixpath/t/restore.gif\" border=\"0\" alt=\"$strrestore\" />"; } else { echo "id&deleteselected=$question->id&q$question->id=1\">pixpath/t/delete.gif\" border=\"0\" alt=\"$strdelete\" />"; } } echo " id\" value=\"1\" />"; echo "'.$question->name."".$question->name."\n"; print_question_icon($question, $canedit); echo "
'; print_paging_bar($totalnumber, $page, $perpage, "edit.php?courseid={$course->id}&perpage=$perpage&"); if ($totalnumber > $perpage) { echo ''.get_string('showall', 'moodle', $totalnumber).''; } echo "
\n"; print_simple_box_end(); echo '
'; echo ''.$strselectall.' /'. ' '.$strselectnone.''. ' '.get_string('withselected', 'quiz').':
'; if ($quizid) { echo "\n"; echo ''; } if ($canedit) { echo '\n"; echo '\n"; question_category_select_menu($course->id, false, true, $category->id); } echo "
"; if ($quizid) { for ($i=1;$i<=10; $i++) { $randomcount[$i] = $i; } echo '
'; print_string('addrandom', 'quiz', choose_from_menu($randomcount, 'randomcount', '1', '', '', '', true)); echo ''; echo "id\" />"; echo ' '; helpbutton('random', get_string('random', 'quiz'), 'quiz'); } echo "
\n"; } ?>