libdir.'/questionlib.php'); define('DEFAULT_QUESTIONS_PER_PAGE', 20); /** * Function to read all questions for category into big array * * @param int $category category number * @param bool $noparent if true only questions with NO parent will be selected * @param bool $recurse include subdirectories * @param bool $export set true if this is called by questionbank export * @author added by Howard Miller June 2004 */ function get_questions_category( $category, $noparent=false, $recurse=true, $export=true ) { global $QTYPES; // questions will be added to an array $qresults = array(); // build sql bit for $noparent $npsql = ''; if ($noparent) { $npsql = " and parent='0' "; } // get (list) of categories if ($recurse) { $categorylist = question_categorylist( $category->id ); } else { $categorylist = $category->id; } // get the list of questions for the category if ($questions = get_records_select("question","category IN ($categorylist) $npsql", "qtype, name ASC")) { // iterate through questions, getting stuff we need foreach($questions as $question) { $questiontype = $QTYPES[$question->qtype]; $question->export_process = $export; $questiontype->get_question_options( $question ); $qresults[] = $question; } } return $qresults; } /** * Gets the default category in a course * * It returns the first category with no parent category. If no categories * exist yet then one is created. * @return object The default category * @param integer $courseid The id of the course whose default category is wanted */ function get_default_question_category($courseid) { // If it already exists, just return it. if ($category = get_records_select("question_categories", "course = '$courseid' AND parent = '0'", 'id', '*', '', 1)) { return reset($category); } // Otherwise, we need to make one $category = new stdClass; $category->name = get_string("default", "quiz"); $category->info = get_string("defaultinfo", "quiz"); $category->course = $courseid; $category->parent = 0; $category->sortorder = 999; // By default, all categories get this number, and are sorted alphabetically. $category->publish = 0; $category->stamp = make_unique_id_code(); if (!$category->id = insert_record("question_categories", $category)) { notify("Error creating a default category!"); return false; } return $category; } /** * prints a form to choose categories */ function question_category_form($course, $current, $recurse=1, $showhidden=false, $showquestiontext=false) { global $CFG; /// Make sure the default category exists for this course get_default_question_category($course->id); /// Get all the existing categories now $catmenu = question_category_options($course->id, true); $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 "
"; echo "id\" />"; echo ""; echo '
'; echo "
"; echo '
'; echo '
'; echo "
"; echo "id}\" />\n"; question_category_form_checkbox('recurse', $recurse); question_category_form_checkbox('showhidden', $showhidden); question_category_form_checkbox('showquestiontext', $showquestiontext); echo '
'; } /** * Private funciton to help the preceeding function. */ function question_category_form_checkbox($name, $checked) { echo '
'; echo ''; echo '
\n"; } /** * 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 * @param boolean $showquestiontext whether the text of each question should be shown in the list */ function question_list($course, $categoryid, $quizid=0, $recurse=1, $page=0, $perpage=100, $showhidden=false, $sortorder='qtype, name ASC', $showquestiontext = false) { global $QTYPE_MENU, $USER, $CFG, $THEME; $qtypemenu = $QTYPE_MENU; if ($rqp_types = get_records('question_rqp_types')) { foreach($rqp_types as $type) { $qtypemenu['rqp_'.$type->id] = $type->name; } } $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; } $canedit = has_capability('moodle/question:manage', get_context_instance(CONTEXT_COURSE, $category->course)); $editingquiz = false; if ($quizid) { $cm = get_coursemodule_from_instance('quiz', $quizid); $editingquiz = has_capability('mod/quiz:manage', get_context_instance(CONTEXT_MODULE, $cm->id)); } echo '
'; $formatoptions = new stdClass; $formatoptions->noclean = true; echo format_text($category->info, FORMAT_MOODLE, $formatoptions, $course->id); echo ''; // check if editing questions in this category is allowed if ($canedit) { echo ""; echo ''; } else { echo ''; } echo '
$strcreatenewquestion:'; popup_form ("$CFG->wwwroot/question/question.php?category=$category->id&qtype=", $qtypemenu, "addquestion", "", "choose", "", "", false, "self"); echo ''; helpbutton("questiontypes", $strcreatenewquestion, "quiz"); echo ''; print_string("publishedit","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&"); echo '
'; echo '
'; echo ''; echo ''; 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) { $nameclass = ''; $textclass = ''; if ($question->hidden) { $nameclass = 'dimmed_text'; $textclass = 'dimmed_text'; } if ($showquestiontext) { $nameclass .= ' header'; } if ($nameclass) { $nameclass = 'class="' . $nameclass . '"'; } if ($textclass) { $textclass = 'class="' . $textclass . '"'; } echo "\n\n"; echo "\n"; echo "\n"; echo "\n"; if($showquestiontext){ echo '\n"; } } echo "
$straction$strquestionname $orderselect $strtype
\n"; // add to quiz if ($editingquiz) { echo "id&quizid=$quizid&sesskey=$USER->sesskey\">pixpath/t/moveleft.gif\" alt=\"$straddtoquiz\" /> "; } // preview echo "id&quizid=$quizid','$strpreview', " . QUESTION_PREVIEW_POPUP_OPTIONS . ", false)\">pixpath/t/preview.gif\" alt=\"$strpreview\" /> "; // edit, hide, delete question, using question capabilities, not quiz capabilieies if ($canedit) { echo "wwwroot/question/question.php?id=$question->id\">pixpath/t/edit.gif\" alt=\"$stredit\" /> "; // hide-feature if($question->hidden) { echo "id&unhide=$question->id&sesskey=$USER->sesskey\">pixpath/t/restore.gif\" alt=\"$strrestore\" />"; } else { echo "id&deleteselected=$question->id&q$question->id=1\">pixpath/t/delete.gif\" alt=\"$strdelete\" />"; } } echo " id\" value=\"1\" />"; echo "" . format_string($question->name) . "\n"; print_question_icon($question); echo "
'; $formatoptions = new stdClass; $formatoptions->noclean = true; $formatoptions->para = false; echo format_text($question->questiontext, $question->questiontextformat, $formatoptions, $course->id); echo "
\n"; $paging = print_paging_bar($totalnumber, $page, $perpage, "edit.php?courseid={$course->id}&perpage=$perpage&", 'page', false, true); if ($totalnumber > DEFAULT_QUESTIONS_PER_PAGE) { if ($perpage == DEFAULT_QUESTIONS_PER_PAGE) { $showall = ''.get_string('showall', 'moodle', $totalnumber).''; } else { $showall = ''.get_string('showperpage', 'moodle', DEFAULT_QUESTIONS_PER_PAGE).''; } if ($paging) { $paging = substr($paging, 0, strrpos($paging, '')); $paging .= "
$showall"; } else { $paging = "
$showall
"; } } echo $paging; echo '
'; echo ''.$strselectall.' /'. ' '.$strselectnone.''. ' '.get_string('withselected', 'quiz').':
'; if ($editingquiz) { echo "larrow} $straddtoquiz\" />\n"; echo ''; } // print delete and move selected question if ($canedit) { echo '\n"; echo '\n"; question_category_select_menu($course->id, false, true, $category->id); } echo "
"; // add random question if ($editingquiz) { for ($i = 1;$i <= min(10, $totalnumber); $i++) { $randomcount[$i] = $i; } for ($i = 20;$i <= min(100, $totalnumber); $i += 10) { $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 '
'; echo "
\n"; } ?>