From 36e298bc5820c9d2a6b8f8fae4bcb61f23cf5f2b Mon Sep 17 00:00:00 2001 From: jamiesensei Date: Fri, 4 May 2007 10:46:33 +0000 Subject: [PATCH] removed more session stuff from question list and category form in question bank display code --- mod/quiz/edit.php | 5 +- question/edit.php | 6 +- question/editlib.php | 133 ++++++++++++++++++++++++------------------- 3 files changed, 79 insertions(+), 65 deletions(-) diff --git a/mod/quiz/edit.php b/mod/quiz/edit.php index f612d493fa..61bac657fe 100644 --- a/mod/quiz/edit.php +++ b/mod/quiz/edit.php @@ -59,8 +59,6 @@ } $coursecontext = get_context_instance(CONTEXT_COURSE, $quiz->course); $quizcontext = get_context_instance(CONTEXT_MODULE, $quiz->cmid); - - require_login($course->id, false); // Log this visit. @@ -324,7 +322,8 @@ echo ''; - question_showbank($thispageurl, $cm, $pagevars['qpage'], $pagevars['qperpage'], $pagevars['qsortorder']); + question_showbank($thispageurl, $cm, $pagevars['qpage'], $pagevars['qperpage'], $pagevars['qsortorder'], $pagevars['qsortorderdecoded'], + $pagevars['cat'], $pagevars['recurse'], $pagevars['showhidden'], $pagevars['showquestiontext']); echo ''; echo ''; diff --git a/question/edit.php b/question/edit.php index e8d14f37aa..2858b5d82e 100644 --- a/question/edit.php +++ b/question/edit.php @@ -14,12 +14,11 @@ require_once("editlib.php"); list($thispageurl, $courseid, $cmid, $cm, $module, $pagevars) = question_edit_setup(); - + if (! $course = get_record("course", "id", $courseid)) { error("This course doesn't exist"); } $context = get_context_instance(CONTEXT_COURSE, $courseid); - require_login($course->id, false); $SESSION->returnurl = $FULLME; @@ -56,7 +55,8 @@ echo ''; echo ''; echo '
'; - question_showbank($thispageurl, $cm, $pagevars['qpage'], $pagevars['qperpage'], $pagevars['qsortorder']); + question_showbank($thispageurl, $cm, $pagevars['qpage'], $pagevars['qperpage'], $pagevars['qsortorder'], $pagevars['qsortorderdecoded'], + $pagevars['cat'], $pagevars['recurse'], $pagevars['showhidden'], $pagevars['showquestiontext']); echo '
'; diff --git a/question/editlib.php b/question/editlib.php index c1ad75f490..7a27faec9c 100644 --- a/question/editlib.php +++ b/question/editlib.php @@ -124,11 +124,11 @@ function question_category_form($course, $pageurl, $current, $recurse=1, $showhi $strshow = get_string("show", "quiz"); $streditcats = get_string("editcategories", "quiz"); - popup_form ("edit.php?".$pageurl->get_query_string()."&cat=", $catmenu, "catmenu", $current, "", "", "", false, "self", "$strcategory"); + popup_form ("edit.php?".$pageurl->get_query_string()."&catchange=", $catmenu, "catmenu", $current, "", "", "", false, "self", "$strcategory"); echo '
'; echo "
"; - echo $pageurl->hidden_params_out(); + echo $pageurl->hidden_params_out(array('recurse', 'showhidden', 'showquestiontext')); question_category_form_checkbox('recurse', $recurse); question_category_form_checkbox('showhidden', $showhidden); question_category_form_checkbox('showquestiontext', $showquestiontext); @@ -164,7 +164,7 @@ function question_category_form_checkbox($name, $checked) { * @param boolean $showquestiontext whether the text of each question should be shown in the list */ function question_list($course, $pageurl, $categoryid, $cm = null, - $recurse=1, $page=0, $perpage=100, $showhidden=false, $sortorder='qtype, name ASC', + $recurse=1, $page=0, $perpage=100, $showhidden=false, $sortorder='typename', $sortorderdecoded='qtype, name ASC', $showquestiontext = false) { global $QTYPE_MENU, $USER, $CFG, $THEME; @@ -229,9 +229,11 @@ function question_list($course, $pageurl, $categoryid, $cm = null, echo ''; $returnurl = urlencode($pageurl->out()); $questionurl = new moodle_url("$CFG->wwwroot/question/question.php", - array('cmid' => $cm->id, - 'returnurl' => $returnurl, + array('returnurl' => $returnurl, 'category' => $category->id)); + if ($cm!==null){ + $questionurl->param('cmid', $cm->id); + } popup_form ($questionurl->out().'&qtype=', $qtypemenu, "addquestion", "", "choose", "", "", false, "self", "$strcreatenewquestion"); echo ''; helpbutton("questiontypes", $strcreatenewquestion, "quiz"); @@ -258,10 +260,10 @@ function question_list($course, $pageurl, $categoryid, $cm = null, return; } - if (!$questions = get_records_select('question', "category IN ($categorylist) AND parent = '0' $showhidden", $sortorder, '*', $page*$perpage, $perpage)) { + if (!$questions = get_records_select('question', "category IN ($categorylist) AND parent = '0' $showhidden", $sortorderdecoded, '*', $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)) { + if (!$questions = get_records_select('question', "category IN ($categorylist) AND parent = '0' $showhidden", $sortorderdecoded, '*', 0, $perpage)) { // There are no questions at all echo "

"; print_string("noquestions", "quiz"); @@ -279,9 +281,9 @@ function question_list($course, $pageurl, $categoryid, $cm = null, echo ''; echo ""; - $sortoptions = array('name, qtype ASC' => get_string("sortalpha", "quiz"), - 'qtype, name ASC' => get_string("sorttypealpha", "quiz"), - 'id ASC' => get_string("sortage", "quiz")); + $sortoptions = array('alpha' => get_string("sortalpha", "quiz"), + 'typealpha' => get_string("sorttypealpha", "quiz"), + 'age' => get_string("sortage", "quiz")); $orderselect = choose_from_menu ($sortoptions, 'qsortorder', $sortorder, false, 'this.form.submit();', '0', true); $orderselect .= ''; echo " @@ -411,7 +413,7 @@ function question_list($course, $pageurl, $categoryid, $cm = null, * move Moves a question to a different category * deleteselected Deletes the selected questions from the category * Other actions: - * cat Chooses the category + * catchange Chooses the category * displayoptions Sets display options * * @author Martin Dougiamas and many others. This has recently been extensively @@ -419,7 +421,7 @@ function question_list($course, $pageurl, $categoryid, $cm = null, * {@link http://maths.york.ac.uk/serving_maths} * @param moodle_url $pageurl object representing this pages url. */ -function question_showbank($pageurl, $cm, $page, $perpage, $sortorder){ +function question_showbank($pageurl, $cm, $page, $perpage, $sortorder, $sortorderdecoded, $cat, $recurse, $showhidden, $showquestiontext){ global $SESSION, $COURSE; $SESSION->fromurl = $pageurl->out(); @@ -516,48 +518,16 @@ function question_showbank($pageurl, $cm, $page, $perpage, $sortorder){ redirect($pageurl->out()); } - if ($categoryid = optional_param('cat', 0, PARAM_INT)) { /// coming from category selection drop-down menu - $SESSION->questioncat = $categoryid; - $page = 0; - $SESSION->questionpage = 0; - } - - if (empty($SESSION->questioncat) or !count_records_select("question_categories", "id = '{$SESSION->questioncat}' AND (course = '{$COURSE->id}' OR publish = '1')")) { - $category = get_default_question_category($COURSE->id); - $SESSION->questioncat = $category->id; - } - - if(($recurse = optional_param('recurse', -1, PARAM_BOOL)) != -1) { - $SESSION->questionrecurse = $recurse; - } - if (!isset($SESSION->questionrecurse)) { - $SESSION->questionrecurse = 1; - } - - if(($showhidden = optional_param('showhidden', -1, PARAM_BOOL)) != -1) { - $SESSION->questionshowhidden = $showhidden; - } - if (!isset($SESSION->questionshowhidden)) { - $SESSION->questionshowhidden = 0; - } - - if(($showquestiontext = optional_param('showquestiontext', -1, PARAM_BOOL)) != -1) { - $SESSION->questionshowquestiontext = $showquestiontext; - } - if (!isset($SESSION->questionshowquestiontext)) { - $SESSION->questionshowquestiontext = 0; - } - // starts with category selection form print_box_start('generalbox questionbank'); print_heading(get_string('questionbank', 'question'), '', 2); - question_category_form($COURSE, $pageurl, $SESSION->questioncat, $SESSION->questionrecurse, - $SESSION->questionshowhidden, $SESSION->questionshowquestiontext); + question_category_form($COURSE, $pageurl, $cat, $recurse, + $showhidden, $showquestiontext); // continues with list of questions - question_list($COURSE, $pageurl, $SESSION->questioncat, isset($cm) ? $cm : null, - $SESSION->questionrecurse, $page, $perpage, $SESSION->questionshowhidden, $sortorder, - $SESSION->questionshowquestiontext); + question_list($COURSE, $pageurl, $cat, isset($cm) ? $cm : null, + $recurse, $page, $perpage, $showhidden, $sortorder, $sortorderdecoded, + $showquestiontext); print_box_end(); } @@ -568,6 +538,9 @@ function question_showbank($pageurl, $cm, $page, $perpage, $sortorder){ * @return array $thispageurl, $courseid, $cmid, $cm, $module, $pagevars */ function question_edit_setup($requirecmid = false, $requirecourseid = true){ + global $COURSE; + //$thispageurl is used to construct urls for all question edit pages we link to from this page. It contains an array + //of parameters that are passed from page to page. $thispageurl = new moodle_url(); if ($requirecmid){ $cmid =required_param('cmid', PARAM_INT); @@ -590,32 +563,74 @@ function question_edit_setup($requirecmid = false, $requirecourseid = true){ $thispageurl->params(compact('courseid')); } } + require_login($courseid, false); - $pagevars['qpage'] = optional_param('qpage', -1, PARAM_INT); - $pagevars['qperpage'] = optional_param('qperpage', -1, PARAM_INT); - $pagevars['qsortorder'] = optional_param('qsortorder', ''); - if (preg_match("/[';]/", $pagevars['qsortorder'])) { - error("Incorrect use of the parameter 'qsortorder'"); - } - + $pagevars['qpage'] = optional_param('qpage', -1, PARAM_INT); if ($pagevars['qpage'] > -1) { $thispageurl->param('qpage', $pagevars['qpage']); } else { $pagevars['qpage'] = 0; } + $pagevars['qperpage'] = optional_param('qperpage', -1, PARAM_INT); if ($pagevars['qperpage'] > -1) { $thispageurl->param('qperpage', $pagevars['qperpage']); } else { $pagevars['qperpage'] = DEFAULT_QUESTIONS_PER_PAGE; } - - if ($pagevars['qsortorder']) { - $thispageurl->param('qsortorder', $pagevars['qsortorder']); + + $sortoptions = array('alpha' => 'name, qtype ASC', + 'typealpha' => 'qtype, name ASC', + 'age' => 'id ASC'); + + if ($sortorder = optional_param('qsortorder', '', PARAM_ALPHA)) { + $pagevars['qsortorderdecoded'] = $sortoptions[$sortorder]; + $pagevars['qsortorder'] = $sortorder; + $thispageurl->param('qsortorder', $sortorder); } else { $pagevars['qsortorder'] = 'qtype, name ASC'; + } + + //pass cat from page to page and catchange comes a drop down menu + //on catchange then we also reset the qpage so we go to page 1 of + //a new cat. + $pagevars['cat'] = optional_param('cat', 0, PARAM_INT); + if ($catchange = optional_param('catchange', 0, PARAM_INT)){ + $pagevars['cat'] = $catchange; + $pagevars['qpage'] = 0; } + if ($pagevars['cat']){ + $thispageurl->param('cat', $pagevars['cat']); + } + + if (empty($pagevars['cat']) or !count_records_select("question_categories", "id = '".$pagevars['cat']."' AND (course = '{$COURSE->id}' OR publish = '1')")) { + $category = get_default_question_category($COURSE->id); + $pagevars['cat'] = $category->id; + $thispageurl->param('cat', $category->id); + } + + if(($recurse = optional_param('recurse', -1, PARAM_BOOL)) != -1) { + $pagevars['recurse'] = $recurse; + $thispageurl->param('recurse', $recurse); + } else { + $pagevars['recurse'] = 1; + } + + if(($showhidden = optional_param('showhidden', -1, PARAM_BOOL)) != -1) { + $pagevars['showhidden'] = $showhidden; + $thispageurl->param('showhidden', $showhidden); + } else { + $pagevars['showhidden'] = 0; + } + + if(($showquestiontext = optional_param('showquestiontext', -1, PARAM_BOOL)) != -1) { + $pagevars['showquestiontext'] = $showquestiontext; + $thispageurl->param('showquestiontext', $showquestiontext); + } else { + $pagevars['showquestiontext'] = 0; + } + return array($thispageurl, $courseid, $cmid, $cm, $module, $pagevars); } -- 2.39.5
$straction$strquestionname $orderselect