### Eclipse Workspace Patch 1.0 #P moodle-HEAD Index: lib/listlib.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/listlib.php,v retrieving revision 1.2 diff -u -r1.2 listlib.php --- lib/listlib.php 27 Apr 2007 05:36:03 -0000 1.2 +++ lib/listlib.php 2 May 2007 17:07:40 -0000 @@ -88,9 +88,7 @@ var $pagecount; //------------------------------------------------------ var $pageurl; - var $pageparams = array(); - var $str; /** * Constructor function * @@ -98,62 +96,21 @@ * @param string $attributes * @param boolean $editable * @param integer $page if 0 no pagination. + * @param moodle_url $page if 0 no pagination. * @return moodle_list */ - function moodle_list($type='ul', $attributes='', $editable = false, $page = 0){ + function moodle_list($type='ul', $attributes='', $editable = false, $page = 0, $pageurl=null){ $this->editable = $editable; $this->attributes = $attributes; $this->type = $type; $this->page = $page; - $this->pageurl = strip_querystring(qualified_me());//default - if (!empty($this->page)){ - $this->add_page_params(array('page' => $this->page)); - } - } - /** - * Add an array of params to the params for this page. - * - * @param unknown_type $params - */ - function add_page_params($params){ - $this->pageparams = $params + $this->pageparams; - } - - /** - * Get url and query string for an action on this page (get_url() + sesskey) - * - * @param array $overrideparams an array of params which override $this->pageparams - * @return string - */ - function get_action_url($overrideparams = array()){ - global $USER; - - $arr = array(); - $paramarray = $overrideparams + $this->pageparams + array('sesskey'=>$USER->sesskey); - foreach ($paramarray as $key => $val){ - $arr[] = urlencode($key)."=".urlencode($val); - } - $params = implode($arr, "&"); - - return $this->pageurl.'?'.$params; - } - - /** - * Get url and query string for this page - * - * @param array $overrideparams an array of params which override $this->pageparams - * @return string - */ - function get_url($overrideparams = array()){ - - $arr = array(); - $paramarray = $overrideparams + $this->pageparams; - foreach ($paramarray as $key => $val){ - $arr[] = urlencode($key)."=".urlencode($val); + + if ($pageurl === null){ + $this->pageurl = new moodle_url(); + $this->pageurl->params(array('page' => $this->page)); + } else { + $this->pageurl = $pageurl; } - $params = implode($arr, "&"); - - return $this->pageurl.'?'.$params; } /** @@ -428,19 +385,19 @@ $this->move_item_up_down('up', $moveup); if ($moveup == $this->items[$this->firstitem -1]->id){//redirect to page that item has been moved to. $this->page --; - $this->add_page_params(array('page'=>$this->page)); + $this->pageurl->params(array('page'=>$this->page)); } } else if (!empty($movedown)) { $this->move_item_up_down('down', $movedown); if ($movedown == $this->items[$this->lastitem -1]->id){//redirect to page that item has been moved to. $this->page ++; - $this->add_page_params(array('page'=>$this->page)); + $this->pageurl->params(array('page'=>$this->page)); } } else { return false; } - redirect($this->get_url()); + redirect($this->pageurl->out()); } } @@ -493,9 +450,7 @@ $this->set_parent($parent); $this->attributes = $attributes; $parentlistclass = get_class($parent); - $this->children =& new $parentlistclass($parent->type, $parent->attributes, $parent->editable, $parent->page); - $this->children->add_page_params($parent->pageparams); - $this->children->pageurl = $parent->pageurl; + $this->children =& new $parentlistclass($parent->type, $parent->attributes, $parent->editable, $parent->page, $parent->pageurl); $this->children->set_parent($this); } /** @@ -537,11 +492,7 @@ $strmovedown = get_string('movedown'); $pixpath = $CFG->pixpath; $icons = ' '; - if (!empty($this->parentlist->page)) { - $pagelink="&page={$this->parentlist->page}"; - } else { - $pagelink=""; - } + if (isset($this->parentlist->parentitem)) { $parentitem =& $this->parentlist->parentitem; if (isset($parentitem->parentlist->parentitem)){ @@ -549,21 +500,21 @@ } else { $action = get_string('maketoplevelitem', 'question'); } - $icons .= ' + $icons .= ' ' . $action. ' '; } else { $icons .= ''; } if (!$first) { - $icons .= ' + $icons .= ' ' . $strmoveup. ' '; } else { $icons .= ''; } if (!$last) { - $icons .= ' + $icons .= ' ' .$strmovedown. ' '; } else { $icons .= ''; @@ -571,7 +522,7 @@ if (!empty($lastitem)) { $makechildof = get_string('makechildof', 'question', $lastitem->name); - $icons .= ' + $icons .= ' ' . $makechildof. ' '; } else { $icons .= ''; Index: lib/questionlib.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/questionlib.php,v retrieving revision 1.104 diff -u -r1.104 questionlib.php --- lib/questionlib.php 30 Apr 2007 06:48:57 -0000 1.104 +++ lib/questionlib.php 2 May 2007 17:07:43 -0000 @@ -554,22 +554,22 @@ return true; } -function questionbank_navigation_tabs(&$row, $context, $courseid) { +function questionbank_navigation_tabs(&$row, $context, $querystring) { global $CFG; if (has_capability('moodle/question:manage', $context)) { - $row[] = new tabobject('questions', "$CFG->wwwroot/question/edit.php?courseid=$courseid", get_string('questions', 'quiz'), get_string('editquestions', "quiz")); + $row[] = new tabobject('questions', "$CFG->wwwroot/question/edit.php?$querystring", get_string('questions', 'quiz'), get_string('editquestions', "quiz")); } if (has_capability('moodle/question:managecategory', $context)) { - $row[] = new tabobject('categories', "$CFG->wwwroot/question/category.php?courseid=$courseid", get_string('categories', 'quiz'), get_string('editqcats', 'quiz')); + $row[] = new tabobject('categories', "$CFG->wwwroot/question/category.php?$querystring", get_string('categories', 'quiz'), get_string('editqcats', 'quiz')); } if (has_capability('moodle/question:import', $context)) { - $row[] = new tabobject('import', "$CFG->wwwroot/question/import.php?courseid=$courseid", get_string('import', 'quiz'), get_string('importquestions', 'quiz')); + $row[] = new tabobject('import', "$CFG->wwwroot/question/import.php?$querystring", get_string('import', 'quiz'), get_string('importquestions', 'quiz')); } if (has_capability('moodle/question:export', $context)) { - $row[] = new tabobject('export', "$CFG->wwwroot/question/export.php?courseid=$courseid", get_string('export', 'quiz'), get_string('exportquestions', 'quiz')); + $row[] = new tabobject('export', "$CFG->wwwroot/question/export.php?$querystring", get_string('export', 'quiz'), get_string('exportquestions', 'quiz')); } } Index: lib/weblib.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/weblib.php,v retrieving revision 1.873 diff -u -r1.873 weblib.php --- lib/weblib.php 2 May 2007 09:35:35 -0000 1.873 +++ lib/weblib.php 2 May 2007 17:07:48 -0000 @@ -283,6 +283,137 @@ return $url_prefix . me(); } + +/** + * Class for creating and manipulating urls. + */ +class moodle_url { + var $scheme = '';// e.g. http + var $host = ''; + var $port = ''; + var $user = ''; + var $pass = ''; + var $path = ''; + var $fragment = ''; + var $params = array(); //associative array of query string params + + /** + * Pass no arguments to create a url that refers to this page. Use empty string to create empty url. + * + * @param string $url url + */ + function moodle_url($url = null){ + global $FULLME; + if ($url !== ''){ + if ($url === null){ + $url = strip_querystring($FULLME); + } + $parts = parse_url($url); + if ($parts === FALSE){ + error('invalidurl'); + } + if (isset($parts['query'])){ + parse_str($parts['query'], $this->params); + } + unset($parts['query']); + foreach ($parts as $key => $value){ + $this->$key = $value; + } + } + } + /** + * Add an array of params to the params for this page. The added params override existing ones if they + * have the same name. + * + * @param array $params + */ + function params($params){ + $this->params = $params + $this->params; + } + + /** + * Remove all params if no arguments passed. Or else remove param $arg1, $arg2, etc. + * + * @param string $arg1 + * @param string $arg2 + * @param string $arg3 + */ + function remove_params(){ + if ($thisargs = func_get_args()){ + foreach ($thisargs as $arg){ + if (isset($this->params->$arg)){ + unset($this->params->$arg); + } + } + } else { // no args + $this->params = array(); + } + } + + /** + * Add a param to the params for this page. The added param overrides existing one if they + * have the same name. + * + * @param string $paramname name + * @param string $param value + */ + function param($paramname, $param){ + $this->params = array($paramname => $param) + $this->params; + } + + + function get_query_string($overrideparams = array()){ + $arr = array(); + $params = $overrideparams + $this->params; + foreach ($params as $key => $val){ + $arr[] = urlencode($key)."=".urlencode($val); + } + return implode($arr, "&"); + } + /** + * Outputs params as hidden form elements. + * + * @return string html for form elements. + */ + function hidden_params_out($indent = 0){ + $tabindent = str_repeat("\t", $indent); + $str = ''; + foreach ($this->params as $key => $val){ + $str.= "$tabindent\n"; + } + return $str; + } + /** + * Output url + * + * @param boolean $noquerystring whether to output page params as a query string in the url. + * @param array $overrideparams params to add to the output url, these override existing ones with the same name. + * @return string url + */ + function out($noquerystring = false, $overrideparams = array()) { + $uri = $this->scheme ? $this->scheme.':'.((strtolower($this->scheme) == 'mailto') ? '':'//'): ''; + $uri .= $this->user ? $this->user.($this->pass? ':'.$this->pass:'').'@':''; + $uri .= $this->host ? $this->host : ''; + $uri .= $this->port ? ':'.$this->port : ''; + $uri .= $this->path ? $this->path : ''; + if (!$noquerystring){ + $uri .= (count($this->params)||count($overrideparams)) ? '?'.$this->get_query_string($overrideparams) : ''; + } + $uri .= $this->fragment ? '#'.$this->fragment : ''; + return $uri; + } + /** + * Output action url with sesskey + * + * @param boolean $noquerystring whether to output page params as a query string in the url. + * @return string url + */ + function out_action($overrideparams = array()) { + $overrideparams = array('sesskey'=> sesskey()) + $overrideparams; + return $this->out(false, $overrideparams); + } +} + /** * Determine if there is data waiting to be processed from a form * Index: mod/quiz/tabs.php =================================================================== RCS file: /cvsroot/moodle/moodle/mod/quiz/tabs.php,v retrieving revision 1.18 diff -u -r1.18 tabs.php --- mod/quiz/tabs.php 22 Mar 2007 11:46:16 -0000 1.18 +++ mod/quiz/tabs.php 2 May 2007 17:07:49 -0000 @@ -37,7 +37,7 @@ $row[] = new tabobject('preview', "$CFG->wwwroot/mod/quiz/attempt.php?q=$quiz->id", get_string('preview', 'quiz')); } if (has_capability('mod/quiz:manage', $context)) { - $row[] = new tabobject('edit', "$CFG->wwwroot/mod/quiz/edit.php?quizid=$quiz->id", get_string('edit')); + $row[] = new tabobject('edit', "$CFG->wwwroot/mod/quiz/edit.php?cmid=$cm->id", get_string('edit')); } if ($currenttab == 'info' && count($row) == 1) { @@ -82,8 +82,9 @@ $strquiz = get_string('modulename', 'quiz'); $streditingquiz = get_string("editinga", "moodle", $strquiz); $strupdate = get_string('updatethis', 'moodle', $strquiz); - $row[] = new tabobject('editq', "$CFG->wwwroot/mod/quiz/edit.php?quizid=$quiz->id", $strquiz, $streditingquiz); - questionbank_navigation_tabs($row, $context, $course->id); + + $row[] = new tabobject('editq', "$CFG->wwwroot/mod/quiz/edit.php?".$thispageurl->get_query_string(), $strquiz, $streditingquiz); + questionbank_navigation_tabs($row, $context, $thispageurl->get_query_string()); $tabs[] = $row; } Index: mod/quiz/view.php =================================================================== RCS file: /cvsroot/moodle/moodle/mod/quiz/view.php,v retrieving revision 1.114 diff -u -r1.114 view.php --- mod/quiz/view.php 25 Apr 2007 15:39:35 -0000 1.114 +++ mod/quiz/view.php 2 May 2007 17:07:49 -0000 @@ -39,7 +39,7 @@ // if no questions have been set up yet redirect to edit.php if (!$quiz->questions and has_capability('mod/quiz:manage', $context)) { - redirect('edit.php?quizid='.$quiz->id); + redirect('edit.php?cmid='.$cm->id); } add_to_log($course->id, "quiz", "view", "view.php?id=$cm->id", $quiz->id, $cm->id); Index: mod/quiz/editlib.php =================================================================== RCS file: /cvsroot/moodle/moodle/mod/quiz/editlib.php,v retrieving revision 1.49 diff -u -r1.49 editlib.php --- mod/quiz/editlib.php 24 Apr 2007 16:59:32 -0000 1.49 +++ mod/quiz/editlib.php 2 May 2007 17:07:49 -0000 @@ -15,17 +15,17 @@ /** * Delete a question from a quiz * -* Deletes a question or a pagebreak from a quiz by updating $modform +* Deletes a question or a pagebreak from a quiz by updating $quiz * as well as the quiz, quiz_question_instances * @return boolean false if the question was not in the quiz * @param int $id The id of the question to be deleted -* @param object $modform The extended quiz object as used by edit.php +* @param object $quiz The extended quiz object as used by edit.php * This is updated by this function */ -function quiz_delete_quiz_question($id, &$modform) { +function quiz_delete_quiz_question($id, &$quiz) { // TODO: For the sake of safety check that this question can be deleted // safely, i.e., that it is not already in use. - $questions = explode(",", $modform->questions); + $questions = explode(",", $quiz->questions); // only do something if this question exists if (!isset($questions[$id])) { @@ -39,14 +39,14 @@ if ($id == 0 && count($questions) > 1 && $questions[1] == 0) { unset($questions[1]); } - $modform->questions = implode(",", $questions); + $quiz->questions = implode(",", $questions); // Avoid duplicate page breaks - $modform->questions = str_replace(',0,0', ',0', $modform->questions); + $quiz->questions = str_replace(',0,0', ',0', $quiz->questions); // save new questionlist in database - if (!set_field('quiz', 'questions', $modform->questions, 'id', $modform->instance)) { + if (!set_field('quiz', 'questions', $quiz->questions, 'id', $quiz->instance)) { error('Could not save question list'); } - delete_records('quiz_question_instances', 'quiz', $modform->instance, 'question', $question); + delete_records('quiz_question_instances', 'quiz', $quiz->instance, 'question', $question); return true; } @@ -54,16 +54,16 @@ /** * Add a question to a quiz * -* Adds a question to a quiz by updating $modform as well as the +* Adds a question to a quiz by updating $quiz as well as the * quiz and quiz_question_instances tables. It also adds a page break * if required. * @return boolean false if the question was already in the quiz * @param int $id The id of the question to be added -* @param object $modform The extended quiz object as used by edit.php +* @param object $quiz The extended quiz object as used by edit.php * This is updated by this function */ -function quiz_add_quiz_question($id, &$modform) { - $questions = explode(",", $modform->questions); +function quiz_add_quiz_question($id, &$quiz) { + $questions = explode(",", $quiz->questions); if (in_array($id, $questions)) { return false; @@ -75,7 +75,7 @@ $end = end($breaks); $last = prev($breaks); $last = $last ? $last : -1; - if (!$modform->questionsperpage or (($end - $last -1) < $modform->questionsperpage)) { + if (!$quiz->questionsperpage or (($end - $last -1) < $quiz->questionsperpage)) { array_pop($questions); } } @@ -85,15 +85,15 @@ $questions[] = 0; // Save new questionslist in database - $modform->questions = implode(",", $questions); - if (!set_field('quiz', 'questions', $modform->questions, 'id', $modform->id)) { + $quiz->questions = implode(",", $questions); + if (!set_field('quiz', 'questions', $quiz->questions, 'id', $quiz->id)) { error('Could not save question list'); } // update question grades $questionrecord = get_record("question", "id", $id); - $modform->grades[$id] = $questionrecord->defaultgrade; - quiz_update_question_instance($modform->grades[$id], $id, $modform->instance); + $quiz->grades[$id] = $questionrecord->defaultgrade; + quiz_update_question_instance($quiz->grades[$id], $id, $quiz->instance); return true; } @@ -132,7 +132,7 @@ * @param boolean $showbreaks Indicates whether the page breaks should be displayed * @param boolean $showbreaks Indicates whether the reorder tool should be displayed */ -function quiz_print_question_list($quiz, $allowdelete=true, $showbreaks=true, $reordertool=false) { +function quiz_print_question_list($quiz, $pageurl, $allowdelete=true, $showbreaks=true, $reordertool=false) { global $USER, $CFG, $QTYPES; $strorder = get_string("order"); @@ -178,6 +178,7 @@ echo "
"; echo '
'; echo "sesskey\" />"; + echo $pageurl->hidden_params_out(); echo "\n"; echo ""; @@ -218,15 +219,15 @@ echo ''; echo '
$strorder
'; if ($count > 1) { - echo "id&sesskey=$USER->sesskey\">out_action(array('up'=>$count))."\">pixpath/t/up.gif\" class=\"iconsmall\" alt=\"$strmoveup\" />"; } echo ' '; if ($count < $lastindex) { - echo "id&sesskey=$USER->sesskey\">out_action(array('down'=>$count))."\">pixpath/t/down.gif\" class=\"iconsmall\" alt=\"$strmovedown\" />"; - echo "id&sesskey=$USER->sesskey\"> + echo "out_action(array('delete'=>$count))."\"> pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strremove\" />"; } echo '
'; @@ -242,13 +243,13 @@ echo ""; if ($count != 0) { - echo "id&sesskey=$USER->sesskey\">out_action(array('up'=>$count))."\">pixpath/t/up.gif\" class=\"iconsmall\" alt=\"$strmoveup\" />"; } echo ""; echo ""; if ($count < $lastindex-1) { - echo "id&sesskey=$USER->sesskey\">out_action(array('down'=>$count))."\">pixpath/t/down.gif\" class=\"iconsmall\" alt=\"$strmovedown\" />"; } echo ""; @@ -283,7 +284,7 @@ pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" />"; } if ($allowdelete) { - echo "id&sesskey=$USER->sesskey\"> + echo "out_action(array('delete'=>$count))."\"> pixpath/t/removeright.gif\" class=\"iconsmall\" alt=\"$strremove\" />"; } @@ -311,7 +312,6 @@ echo '
'; echo '
'; - echo ''; // ugly hack to prevent modform session "mistakes" echo '
'; echo "
\n"; @@ -319,6 +319,7 @@ /// Form to choose to show pagebreaks and to repaginate quiz echo '
'; echo '
'; + echo $pageurl->hidden_params_out(); echo ''; echo ''; echo 'dirroot.'/mod/quiz/editlib.php'); - require_login(); - $quizid = optional_param('quizid', 0, PARAM_INT); + $cmid = required_param('cmid', PARAM_INT); $strquizzes = get_string('modulenameplural', 'quiz'); $strquiz = get_string('modulename', 'quiz'); $streditingquestions = get_string('editquestions', "quiz"); - $streditingquiz = get_string("editinga", "moodle", $strquiz); + $streditingquiz = get_string('editinga', 'moodle', $strquiz); + + list($quiz, $cm) = get_module_from_cmid($cmid); - if ($modform = data_submitted() and !empty($modform->course)) { // data submitted + + $thispageurl = new moodle_url(); + $thispageurl->params(compact('cmid')); - $SESSION->modform = $modform; // Save the form in the current session - } else if ($quizid) { - if (isset($SESSION->modform->id) and $SESSION->modform->id == $quizid) { - // modform for this quiz already exists, use it - $modform = $SESSION->modform; - } else { - // create new modform from database - if (! $modform = get_record('quiz', 'id', $quizid)) { - error("The required quiz doesn't exist"); - } - $modform->instance = $modform->id; - $SESSION->modform = $modform; // Save the form in the current session - } - } else if (!empty($sortorder)) { - // no quiz or course was specified so we need to use the stored modform - if (isset($SESSION->modform)) { - $modform = $SESSION->modform; - } else { - error('cmunknown'); - } - } else { - // no quiz or course was specified so we need to use the stored modform - if (isset($SESSION->modform)) { - $modform = $SESSION->modform; - } else { - print_error('cmunknown'); - } - } // Get the course object and related bits. - if (! $course = get_record("course", "id", $modform->course)) { + if (! $course = get_record("course", "id", $quiz->course)) { error("This course doesn't exist"); } - $coursecontext = get_context_instance(CONTEXT_COURSE, $modform->course); + $coursecontext = get_context_instance(CONTEXT_COURSE, $quiz->course); + $quizcontext = get_context_instance(CONTEXT_MODULE, $quiz->cmid); require_login($course->id, false); - // Get the module and related bits. - $cm = get_coursemodule_from_instance('quiz', $modform->instance); - $modform->cmid = $cm->id; - $context = get_context_instance(CONTEXT_MODULE, $cm->id); // Log this visit. add_to_log($cm->course, 'quiz', 'editquestions', - "view.php?id=$cm->id", "$quizid", $cm->id); + "view.php?id=$cm->id", "$quiz->id", $cm->id); - require_capability('mod/quiz:manage', $context); + require_capability('mod/quiz:manage', $quizcontext); - if (isset($modform->instance) - && empty($modform->grades)) // Construct an array to hold all the grades. - { - $modform->grades = quiz_get_all_question_grades($modform); + if (isset($quiz->instance) + && empty($quiz->grades)){ // Construct an array to hold all the grades. + $quiz->grades = quiz_get_all_question_grades($quiz); } $SESSION->returnurl = $FULLME; @@ -102,18 +73,18 @@ if (isset($_REQUEST['up']) and confirm_sesskey()) { /// Move the given question up a slot $up = optional_param('up', 0, PARAM_INT); - $questions = explode(",", $modform->questions); + $questions = explode(",", $quiz->questions); if ($up > 0 and isset($questions[$up])) { $prevkey = ($questions[$up-1] == 0) ? $up-2 : $up-1; $swap = $questions[$prevkey]; $questions[$prevkey] = $questions[$up]; $questions[$up] = $swap; - $modform->questions = implode(",", $questions); + $quiz->questions = implode(",", $questions); // Always have a page break at the end - $modform->questions = $modform->questions . ',0'; + $quiz->questions = $quiz->questions . ',0'; // Avoid duplicate page breaks - $modform->questions = str_replace(',0,0', ',0', $modform->questions); - if (!set_field('quiz', 'questions', $modform->questions, 'id', $modform->instance)) { + $quiz->questions = str_replace(',0,0', ',0', $quiz->questions); + if (!set_field('quiz', 'questions', $quiz->questions, 'id', $quiz->instance)) { error('Could not save question list'); } } @@ -121,29 +92,29 @@ if (isset($_REQUEST['down']) and confirm_sesskey()) { /// Move the given question down a slot $down = optional_param('down', 0, PARAM_INT); - $questions = explode(",", $modform->questions); + $questions = explode(",", $quiz->questions); if ($down < count($questions)) { $nextkey = ($questions[$down+1] == 0) ? $down+2 : $down+1; $swap = $questions[$nextkey]; $questions[$nextkey] = $questions[$down]; $questions[$down] = $swap; - $modform->questions = implode(",", $questions); + $quiz->questions = implode(",", $questions); // Avoid duplicate page breaks - $modform->questions = str_replace(',0,0', ',0', $modform->questions); - if (!set_field('quiz', 'questions', $modform->questions, 'id', $modform->instance)) { + $quiz->questions = str_replace(',0,0', ',0', $quiz->questions); + if (!set_field('quiz', 'questions', $quiz->questions, 'id', $quiz->instance)) { error('Could not save question list'); } } } if (isset($_REQUEST['addquestion']) and confirm_sesskey()) { /// Add a single question to the current quiz - quiz_add_quiz_question($_REQUEST['addquestion'], $modform); + quiz_add_quiz_question($_REQUEST['addquestion'], $quiz); } if (isset($_REQUEST['add']) and confirm_sesskey()) { /// Add selected questions to the current quiz foreach ($_POST as $key => $value) { // Parse input for question ids if (substr($key, 0, 1) == "q") { - quiz_add_quiz_question(substr($key,1), $modform); + quiz_add_quiz_question(substr($key,1), $quiz); } } } @@ -161,7 +132,7 @@ $random = RANDOM; if ($existingquestions = get_records_select('question', "qtype = '$random' AND category = '$category->id'")) { // now remove the ones that are already used in this quiz - if ($questionids = explode(',', $modform->questions)) { + if ($questionids = explode(',', $quiz->questions)) { foreach ($questionids as $questionid) { unset($existingquestions[$questionid]); } @@ -171,7 +142,7 @@ while (($existingquestion = array_pop($existingquestions)) and ($i < $randomcount)) { if ($existingquestion->questiontext == $recurse) { // this question has the right recurse property, so use it - quiz_add_quiz_question($existingquestion->id, $modform); + quiz_add_quiz_question($existingquestion->id, $quiz); $i++; } } @@ -198,43 +169,39 @@ if(!isset($question->id)) { error('Could not insert new random question!'); } - quiz_add_quiz_question($question->id, $modform); + quiz_add_quiz_question($question->id, $quiz); } } } if (isset($_REQUEST['repaginate']) and confirm_sesskey()) { /// Re-paginate the quiz if (isset($_REQUEST['questionsperpage'])) { - $modform->questionsperpage = required_param('questionsperpage', PARAM_INT); - if (!set_field('quiz', 'questionsperpage', $modform->questionsperpage, 'id', $modform->id)) { + $quiz->questionsperpage = required_param('questionsperpage', PARAM_INT); + if (!set_field('quiz', 'questionsperpage', $quiz->questionsperpage, 'id', $quiz->id)) { error('Could not save number of questions per page'); } } - $modform->questions = quiz_repaginate($modform->questions, $modform->questionsperpage); - if (!set_field('quiz', 'questions', $modform->questions, 'id', $modform->id)) { + $quiz->questions = quiz_repaginate($quiz->questions, $quiz->questionsperpage); + if (!set_field('quiz', 'questions', $quiz->questions, 'id', $quiz->id)) { error('Could not save layout'); } } if (isset($_REQUEST['delete']) and confirm_sesskey()) { /// Remove a question from the quiz - quiz_delete_quiz_question($_REQUEST['delete'], $modform); + quiz_delete_quiz_question($_REQUEST['delete'], $quiz); } if (isset($_REQUEST['savechanges']) and confirm_sesskey()) { - $savequizid = required_param('savequizid', PARAM_INT); - if ($modform->id != $savequizid) { - error("Error saving quiz settings, please do not change two quizes from the same browser", $CFG->wwwroot.'/mod/quiz/edit.php?quizid='.$savequizid); - } /// We need to save the new ordering (if given) and the new grades - $oldquestions = explode(",", $modform->questions); // the questions in the old order + $oldquestions = explode(",", $quiz->questions); // the questions in the old order $questions = array(); // for questions in the new order $rawgrades = $_POST; - unset($modform->grades); + unset($quiz->grades); foreach ($rawgrades as $key => $value) { // Parse input for question -> grades if (substr($key, 0, 1) == "q") { $key = substr($key,1); - $modform->grades[$key] = $value; - quiz_update_question_instance($modform->grades[$key], $key, $modform->instance); + $quiz->grades[$key] = $value; + quiz_update_question_instance($quiz->grades[$key], $key, $quiz->instance); } elseif (substr($key, 0, 1) == "o") { // Parse input for ordering info $key = substr($key,1); $questions[$value] = $oldquestions[$key]; @@ -244,21 +211,21 @@ // If ordering info was given, reorder the questions if ($questions) { ksort($questions); - $modform->questions = implode(",", $questions); + $quiz->questions = implode(",", $questions); // Always have a page break at the end - $modform->questions = $modform->questions . ',0'; + $quiz->questions = $quiz->questions . ',0'; // Avoid duplicate page breaks - while (strpos($modform->questions, ',0,0')) { - $modform->questions = str_replace(',0,0', ',0', $modform->questions); + while (strpos($quiz->questions, ',0,0')) { + $quiz->questions = str_replace(',0,0', ',0', $quiz->questions); } - if (!set_field('quiz', 'questions', $modform->questions, 'id', $modform->instance)) { + if (!set_field('quiz', 'questions', $quiz->questions, 'id', $quiz->instance)) { error('Could not save question list'); } } // If rescaling is required save the new maximum if (isset($_REQUEST['maxgrade'])) { - if (!quiz_set_grade(optional_param('maxgrade', 0), $modform)) { + if (!quiz_set_grade(optional_param('maxgrade', 0), $quiz)) { error('Could not set a new maximum grade for the quiz'); } } @@ -271,14 +238,14 @@ /// Delete any teacher preview attempts if the quiz has been modified if (isset($_REQUEST['savechanges']) or isset($_REQUEST['delete']) or isset($_REQUEST['repaginate']) or isset($_REQUEST['addrandom']) or isset($_REQUEST['addquestion']) or isset($_REQUEST['up']) or isset($_REQUEST['down']) or isset($_REQUEST['add'])) { - delete_records('quiz_attempts', 'preview', '1', 'quiz', $modform->id); + delete_records('quiz_attempts', 'preview', '1', 'quiz', $quiz->id); } /// all commands have been dealt with, now print the page - if (empty($modform->category) or !record_exists('question_categories', 'id', $modform->category)) { + if (empty($quiz->category) or !record_exists('question_categories', 'id', $quiz->category)) { $category = get_default_question_category($course->id); - $modform->category = $category->id; + $quiz->category = $category->id; } if (!isset($SESSION->quiz_showbreaks)) { $SESSION->quiz_showbreaks = ($CFG->quiz_questionsperpage < 2) ? 0 : 1; @@ -287,17 +254,16 @@ $SESSION->quiz_reordertool = 0; } - $SESSION->modform = $modform; // Print basic page layout. - if (isset($modform->instance) and record_exists_select('quiz_attempts', "quiz = '$modform->instance' AND preview = '0'")){ + if (isset($quiz->instance) and record_exists_select('quiz_attempts', "quiz = '$quiz->instance' AND preview = '0'")){ // one column layout with table of questions used in this quiz $strupdatemodule = has_capability('moodle/course:manageactivities', $coursecontext) - ? update_module_button($modform->cmid, $course->id, get_string('modulename', 'quiz')) + ? update_module_button($cm->id, $course->id, get_string('modulename', 'quiz')) : ""; $crumbs[] = array('name' => $strquizzes, 'link' => "index.php?id=$course->id", 'type' => 'activity'); - $crumbs[] = array('name' => format_string($modform->name), 'link' => "view.php?q=$modform->instance", 'type' => 'activityinstance'); + $crumbs[] = array('name' => format_string($quiz->name), 'link' => "view.php?q=$quiz->instance", 'type' => 'activityinstance'); $crumbs[] = array('name' => $streditingquiz, 'link' => '', 'type' => 'title'); $navigation = build_navigation($crumbs); @@ -306,7 +272,7 @@ $currenttab = 'edit'; $mode = 'editq'; - $quiz = &$modform; + include('tabs.php'); print_box_start(); @@ -314,15 +280,15 @@ $a->attemptnum = count_records('quiz_attempts', 'quiz', $quiz->id, 'preview', 0); $a->studentnum = count_records_select('quiz_attempts', "quiz = '$quiz->id' AND preview = '0'", 'COUNT(DISTINCT userid)'); $a->studentstring = $course->students; - if (! $cm = get_coursemodule_from_instance("quiz", $modform->instance, $course->id)) { + if (! $cm = get_coursemodule_from_instance("quiz", $quiz->instance, $course->id)) { error("Course Module ID was incorrect"); } echo "
\n"; echo "id\">".get_string('numattempts', 'quiz', $a)."
".get_string("attemptsexist","quiz"); echo "

\n"; - $sumgrades = quiz_print_question_list($modform, false, $SESSION->quiz_showbreaks, $SESSION->quiz_reordertool); - if (!set_field('quiz', 'sumgrades', $sumgrades, 'id', $modform->instance)) { + $sumgrades = quiz_print_question_list($quiz, $thispageurl, false, $SESSION->quiz_showbreaks, $SESSION->quiz_reordertool); + if (!set_field('quiz', 'sumgrades', $sumgrades, 'id', $quiz->instance)) { error('Failed to set sumgrades'); } @@ -333,11 +299,11 @@ // two column layout with quiz info in left column $strupdatemodule = has_capability('moodle/course:manageactivities', $coursecontext) - ? update_module_button($modform->cmid, $course->id, get_string('modulename', 'quiz')) + ? update_module_button($cm->id, $course->id, get_string('modulename', 'quiz')) : ""; $crumbs[] = array('name' => $strquizzes, 'link' => "index.php?id=$course->id", 'type' => 'activity'); - $crumbs[] = array('name' => format_string($modform->name), 'link' => "view.php?q=$modform->instance", 'type' => 'activityinstance'); + $crumbs[] = array('name' => format_string($quiz->name), 'link' => "view.php?q=$quiz->instance", 'type' => 'activityinstance'); $crumbs[] = array('name' => $streditingquiz, 'link' => '', 'type' => 'title'); $navigation = build_navigation($crumbs); @@ -345,7 +311,7 @@ $currenttab = 'edit'; $mode = 'editq'; - $quiz = &$modform; + include('tabs.php'); echo ''; @@ -353,8 +319,8 @@ print_box_start('generalbox quizquestions'); print_heading(get_string('questionsinthisquiz', 'quiz'), '', 2); - $sumgrades = quiz_print_question_list($modform, true, $SESSION->quiz_showbreaks, $SESSION->quiz_reordertool); - if (!set_field('quiz', 'sumgrades', $sumgrades, 'id', $modform->instance)) { + $sumgrades = quiz_print_question_list($quiz, $thispageurl, true, $SESSION->quiz_showbreaks, $SESSION->quiz_reordertool); + if (!set_field('quiz', 'sumgrades', $sumgrades, 'id', $quiz->instance)) { error('Failed to set sumgrades'); } @@ -362,7 +328,7 @@ echo ''; echo '
'; - require($CFG->dirroot.'/question/showbank.php'); + showbank($thispageurl, $cm); echo '
'; Index: question/export.php =================================================================== RCS file: /cvsroot/moodle/moodle/question/export.php,v retrieving revision 1.33 diff -u -r1.33 export.php --- question/export.php 11 Apr 2007 12:21:25 -0000 1.33 +++ question/export.php 2 May 2007 17:07:51 -0000 @@ -13,9 +13,20 @@ require_once( "editlib.php" ); // get parameters + $thispageurl = new moodle_url(); + if (!$cmid = optional_param('cmid', 0, PARAM_INT)){ + $courseid = required_param('courseid', PARAM_INT); + $thispageurl->params(compact('courseid')); + $cm = null; + $module = null; + } else { + list($module, $cm) = get_module_from_cmid($cmid); + $courseid = $cm->course; + $thispageurl->params(compact('cmid')); + } $categoryid = optional_param('category',0, PARAM_INT); $cattofile = optional_param('cattofile',0, PARAM_BOOL); - $courseid = required_param('courseid',PARAM_INT); + $exportfilename = optional_param('exportfilename','',PARAM_FILE ); $format = optional_param('format','', PARAM_FILE ); @@ -41,7 +52,7 @@ if ($categoryid) { // update category in session variable $SESSION->questioncat = $categoryid; - } else { // try to get category from modform + } else { // try to get category from session if (isset($SESSION->questioncat)) { $categoryid = $SESSION->questioncat; } @@ -73,20 +84,28 @@ } /// Header - if (isset($SESSION->modform->instance) and $quiz = get_record('quiz', 'id', $SESSION->modform->instance)) { - $strupdatemodule = has_capability('moodle/course:manageactivities', $context) - ? update_module_button($SESSION->modform->cmid, $course->id, $txt->modulename ) + if ($cm!==null) { + $strupdatemodule = has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id)) + ? update_module_button($cm->id, $course->id, get_string('modulename', $cm->modname)) : ""; - print_header_simple($txt->exportquestions, '', - "wwwroot/mod/quiz/index.php?id=$course->id\">$txt->modulenameplural". - " -> wwwroot/mod/quiz/view.php?q=$quiz->id\">".format_string($quiz->name).''. - ' -> '.$txt->exportquestions, - "", "", true, $strupdatemodule); + $crumbs = array(); + $crumbs[] = array('name' => get_string('modulenameplural', $cm->modname), 'link' => "$CFG->wwwroot/mod/{$cm->modname}/index.php?id=$course->id", 'type' => 'activity'); + $crumbs[] = array('name' => format_string($module->name), 'link' => "$CFG->wwwroot/mod/{$cm->modname}/view.php?cmid={$cm->id}", 'type' => 'title'); + $crumbs[] = array('name' => $txt->exportquestions, 'link' => '', 'type' => 'title'); + $navigation = build_navigation($crumbs); + print_header_simple($txt->exportquestions, '', $navigation, "", "", true, $strupdatemodule); + $currenttab = 'edit'; $mode = 'export'; - include($CFG->dirroot.'/mod/quiz/tabs.php'); + ${$cm->modname} = $module; + include($CFG->dirroot."/mod/$cm->modname/tabs.php"); } else { - print_header_simple($txt->exportquestions, '', $txt->exportquestions); + // Print basic page layout. + $crumbs = array(); + $crumbs[] = array('name' => $txt->exportquestions, 'link' => '', 'type' => 'title'); + $navigation = build_navigation($crumbs); + + print_header_simple($txt->exportquestions, '', $navigation); // print tabs $currenttab = 'export'; include('tabs.php'); @@ -116,15 +135,15 @@ $qformat->setCattofile( $cattofile ); if (! $qformat->exportpreprocess()) { // Do anything before that we need to - error( $txt->exporterror, "$CFG->wwwroot/question/export.php?courseid={$course->id}&category=$category->id"); + error( $txt->exporterror, $thispageurl->out(false, array('category'=>$category->id))); } if (! $qformat->exportprocess()) { // Process the export data - error( $txt->exporterror, "$CFG->wwwroot/question/export.php?courseid={$course->id}&category=$category->id"); + error( $txt->exporterror, $thispageurl->out(false, array('category'=>$category->id))); } if (! $qformat->exportpostprocess()) { // In case anything needs to be done after - error( $txt->exporterror, "$CFG->wwwroot/question/export.php?courseid={$course->id}&category=$category->id"); + error( $txt->exporterror, $thispageurl->out(false, array('category'=>$category->id))); } echo "
"; @@ -139,7 +158,7 @@ echo "

"; echo "

$txt->downloadextra

"; - print_continue("edit.php?courseid=$course->id"); + print_continue("edit.php?".$thispageurl->get_query_string()); print_footer($course); exit; } @@ -161,8 +180,7 @@
- - + hidden_params_out(3); ?> Index: question/category_class.php =================================================================== RCS file: /cvsroot/moodle/moodle/question/category_class.php,v retrieving revision 1.22 diff -u -r1.22 category_class.php --- question/category_class.php 30 Apr 2007 06:48:58 -0000 1.22 +++ question/category_class.php 2 May 2007 17:07:50 -0000 @@ -15,9 +15,8 @@ class question_category_list extends moodle_list { var $table = "question_categories"; var $listitemclassname = 'question_category_list_item'; - function question_category_list($type='ul', $attributes='', $editable = false, $page = 0){ - parent::moodle_list($type, $attributes, $editable, $page); - } + + function get_records() { global $COURSE, $CFG; $categories = get_records($this->table, 'course', "{$COURSE->id}", $this->sortby); @@ -47,15 +46,11 @@ $linkcss = $category->publish ? ' class="published" ' : ' class="unpublished" '; - if (!empty($parent->page)) { - $pagelink="&page=".$parent->page; - } else { - $pagelink=""; - } /// Each section adds html to be displayed as part of this list item + - $item = ' + $item = ' ' .$str->edit. ' ' . $category->name . '('.$category->questioncount.')'. ''; @@ -63,15 +58,15 @@ if (!empty($category->publish)) { - $item .= ' + $item .= ' ' .$str->hide. ' '; } else { - $item .= ' + $item .= ' ' .$str->publish. ' '; } if ($category->id != $extraargs['defaultcategory']->id) { - $item .= ' + $item .= ' ' .$str->delete. ' '; } @@ -105,15 +100,17 @@ var $categorystrings; var $defaultcategory; //------------------------------------------------------ + /** + * @var moodle_url Object representing url for this page + */ var $pageurl; - var $pageparams = array(); /** * Constructor * * Gets necessary strings and sets relevant path information */ - function question_category_object($page) { + function question_category_object($page, $pageurl) { global $CFG, $COURSE; $this->tab = str_repeat(' ', $this->tabsize); @@ -141,63 +138,15 @@ $this->str->page = get_string('page'); $this->pixpath = $CFG->pixpath; - $this->editlist = new question_category_list('ul', '', true, $page); + $this->editlist = new question_category_list('ul', '', true, $page, $pageurl); - $this->add_page_params(array('courseid'=>$COURSE->id, 'page' => $this->page)); - $this->pageurl = strip_querystring(qualified_me());//default + $this->pageurl = $pageurl; $this->initialize(); } /** - * Add an array of params to the params for this page. - * - * @param unknown_type $params - */ - function add_page_params($params){ - $this->pageparams = $params + $this->pageparams; - $this->editlist->add_page_params($params); - } - - /** - * Get url and query string for an action on this page (get_url() + sesskey) - * - * @param array $overrideparams an array of params which override $this->pageparams - * @return string - */ - function get_action_url($overrideparams = array()){ - global $USER; - - $arr = array(); - $paramarray = $overrideparams + $this->pageparams + array('sesskey'=>$USER->sesskey); - foreach ($paramarray as $key => $val){ - $arr[] = urlencode($key)."=".urlencode($val); - } - $params = implode($arr, "&"); - - return $this->pageurl.'?'.$params; - } - - /** - * Get url and query string for this page - * - * @param array $overrideparams an array of params which override $this->pageparams - * @return string - */ - function get_url($overrideparams = array()){ - - $arr = array(); - $paramarray = $overrideparams + $this->pageparams; - foreach ($paramarray as $key => $val){ - $arr[] = urlencode($key)."=".urlencode($val); - } - $params = implode($arr, "&"); - - return $this->pageurl.'?'.$params; - } - - /** * Displays the user interface * */ @@ -284,7 +233,7 @@ echo ''; echo '
'; echo "sesskey\" />"; - echo ''; + echo $this->pageurl->hidden_params_out(); echo ''; print_table($this->newtable); echo '
'; @@ -297,7 +246,6 @@ * * $this->initialize() must have already been called * - * @param int $page page to display (0=do not paginate) */ function output_edit_list() { print_box_start('boxwidthwide boxaligncenter generalbox'); @@ -329,7 +277,7 @@ - function edit_single_category($categoryid, $page=1) { + function edit_single_category($categoryid) { /// Interface for adding a new category global $USER, $COURSE; @@ -340,12 +288,13 @@ helpbutton("categories_edit", $this->str->editcategory, "quiz"); echo ''; echo '
category; ?>:
'; - $this->output_edit_single_table($category, $page); + $this->output_edit_single_table($category); echo '
'; + //cancel button echo '

-
- - +
'; + echo $this->pageurl->hidden_params_out(); + echo '
@@ -363,8 +312,8 @@ * @param object category * @param int page current page */ - function output_edit_single_table($category, $page=1) { - global $USER, $COURSE; + function output_edit_single_table($category) { + global $USER; $publishoptions[0] = get_string("no"); $publishoptions[1] = get_string("yes"); $strupdate = get_string('update'); @@ -408,9 +357,8 @@ echo '

'; echo '
'; echo "sesskey\" />"; - echo ''; + echo $this->pageurl->hidden_params_out(); echo ''; - echo ""; print_table($edittable); echo '
'; echo '

'; @@ -534,7 +482,7 @@ /// Finally delete the category itself if (delete_records("question_categories", "id", $category->id)) { notify(get_string("categorydeleted", "quiz", format_string($category->name)), 'notifysuccess'); - redirect($this->get_url());//always redirect after successful action + redirect($this->pageurl->out());//always redirect after successful action } } @@ -555,7 +503,7 @@ if (! set_field("question_categories", "publish", $publish, "id", $tempcat->id)) { notify("Could not update that category!"); } else { - redirect($this->get_url());//always redirect after successful action + redirect($this->pageurl->out());//always redirect after successful action } } @@ -595,7 +543,7 @@ error("Could not insert the new question category '$newcategory'", "category.php?id={$newcourse}"); } else { notify(get_string("categoryadded", "quiz", $newcategory), 'notifysuccess'); - redirect($this->get_url());//always redirect after successful action + redirect($this->pageurl->out());//always redirect after successful action } } @@ -625,7 +573,7 @@ error("Could not update the category '$updatename'", "category.php?id={$courseid}"); } else { notify(get_string("categoryupdated", 'quiz'), 'notifysuccess'); - redirect($this->get_url()); + redirect($this->pageurl->out()); } } } Index: question/editlib.php =================================================================== RCS file: /cvsroot/moodle/moodle/question/editlib.php,v retrieving revision 1.54 diff -u -r1.54 editlib.php --- question/editlib.php 27 Apr 2007 11:27:57 -0000 1.54 +++ question/editlib.php 2 May 2007 17:07:51 -0000 @@ -16,6 +16,22 @@ define('DEFAULT_QUESTIONS_PER_PAGE', 20); +function get_module_from_cmid($cmid){ + global $CFG; + if (!$cmrec = get_record_sql("SELECT cm.*, md.name as modname + FROM {$CFG->prefix}course_modules cm, + {$CFG->prefix}modules md + WHERE cm.id = '$cmid' AND + md.id = cm.module")){ + error('cmunknown'); + } elseif (!$modrec =get_record($cmrec->modname, 'id', $cmrec->instance)) { + error('cmunknown'); + } + $modrec->instance = $modrec->id; + $modrec->cmid = $modrec->id; + + return array($modrec, $cmrec); +} /** * Function to read all questions for category into big array * @@ -95,7 +111,7 @@ /** * prints a form to choose categories */ -function question_category_form($course, $current, $recurse=1, $showhidden=false, $showquestiontext=false) { +function question_category_form($course, $pageurl, $current, $recurse=1, $showhidden=false, $showquestiontext=false) { global $CFG; /// Make sure the default category exists for this course @@ -109,11 +125,11 @@ $streditcats = get_string("editcategories", "quiz"); echo "$strcategory: "; - popup_form ("edit.php?courseid=$course->id&cat=", $catmenu, "catmenu", $current, "", "", "", false, "self"); + popup_form ("edit.php?".$pageurl->get_query_string()."&cat=", $catmenu, "catmenu", $current, "", "", "", false, "self"); echo '
'; echo "
"; - echo "id}\" />\n"; + echo $pageurl->hidden_params_out(); question_category_form_checkbox('recurse', $recurse); question_category_form_checkbox('showhidden', $showhidden); question_category_form_checkbox('showquestiontext', $showquestiontext); @@ -141,14 +157,14 @@ * * @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 $cm The course module record if we are in the context of a particular module, 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, +function question_list($course, $pageurl, $categoryid, $cm = null, $recurse=1, $page=0, $perpage=100, $showhidden=false, $sortorder='qtype, name ASC', $showquestiontext = false) { global $QTYPE_MENU, $USER, $CFG, $THEME; @@ -185,11 +201,6 @@ echo "

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

"; - if ($quizid) { - echo "

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

"; - } return; } @@ -198,10 +209,13 @@ 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)); + + if ($cm AND $cm->modname == 'quiz') { + $editingquiz = has_capability("mod/quiz:manage", get_context_instance(CONTEXT_MODULE, $cm->id)); + $quizid = $cm->instance; + } else { + $editingquiz = false; + $quizid = 0; } echo '
'; @@ -257,10 +271,10 @@ print_paging_bar($totalnumber, $page, $perpage, "edit.php?courseid={$course->id}&perpage=$perpage&"); - echo ''; + echo ''; echo '
'; echo ''; - + echo $pageurl->hidden_params_out(); echo ''; echo ""; @@ -293,7 +307,7 @@ // add to quiz if ($editingquiz) { - echo "id&quizid=$quizid&sesskey=$USER->sesskey\">get_query_string()."&addquestion=$question->id&sesskey=$USER->sesskey\">pixpath/t/moveleft.gif\" alt=\"$straddtoquiz\" /> "; } @@ -308,10 +322,10 @@ src=\"$CFG->pixpath/t/edit.gif\" alt=\"$stredit\" /> "; // hide-feature if($question->hidden) { - echo "id&unhide=$question->id&sesskey=$USER->sesskey\">get_query_string()."&unhide=$question->id&sesskey=$USER->sesskey\">pixpath/t/restore.gif\" alt=\"$strrestore\" />"; } else { - echo "id&deleteselected=$question->id&q$question->id=1\">get_query_string()."&deleteselected=$question->id&q$question->id=1\">pixpath/t/delete.gif\" alt=\"$strdelete\" />"; } } @@ -336,13 +350,13 @@ echo "
$straction
\n"; $paging = print_paging_bar($totalnumber, $page, $perpage, - "edit.php?courseid={$course->id}&perpage=$perpage&", 'page', + "edit.php?".$pageurl->get_query_string()."&perpage=$perpage&", 'page', false, true); if ($totalnumber > DEFAULT_QUESTIONS_PER_PAGE) { if ($perpage == DEFAULT_QUESTIONS_PER_PAGE) { - $showall = ''.get_string('showall', 'moodle', $totalnumber).''; + $showall = ''.get_string('showall', 'moodle', $totalnumber).''; } else { - $showall = ''.get_string('showperpage', 'moodle', DEFAULT_QUESTIONS_PER_PAGE).''; + $showall = ''.get_string('showperpage', 'moodle', DEFAULT_QUESTIONS_PER_PAGE).''; } if ($paging) { $paging = substr($paging, 0, strrpos($paging, '
')); @@ -379,8 +393,7 @@ $randomcount[$i] = $i; } echo '
'; - print_string('addrandom', 'quiz', - choose_from_menu($randomcount, 'randomcount', '1', '', '', '', true)); + print_string('addrandom', 'quiz', choose_from_menu($randomcount, 'randomcount', '1', '', '', '', true)); echo ''; echo "id\" />"; echo ' '; @@ -389,5 +402,187 @@ echo '
'; echo "
\n"; } +/** + * Shows the question bank editing interface. + * + * The function also processes a number of actions: + * + * Actions affecting the question pool: + * move Moves a question to a different category + * deleteselected Deletes the selected questions from the category + * Other actions: + * cat Chooses the category + * displayoptions Sets display options + * + * @author Martin Dougiamas and many others. This has recently been extensively + * rewritten by Gustav Delius and other members of the Serving Mathematics project + * {@link http://maths.york.ac.uk/serving_maths} + * @param moodle_url $pageurl object representing this pages url. + */ +function showbank($pageurl, $cm){ + global $SESSION, $COURSE; + $page = optional_param('page', -1, PARAM_INT); + $perpage = optional_param('perpage', -1, PARAM_INT); + $sortorder = optional_param('sortorder', ''); + if (preg_match("/[';]/", $sortorder)) { + error("Incorrect use of the parameter 'sortorder'"); + } + + if ($page > -1) { + $SESSION->questionpage = $page; + } else { + $page = isset($SESSION->questionpage) ? $SESSION->questionpage : 0; + } + + if ($perpage > -1) { + $SESSION->questionperpage = $perpage; + } else { + $perpage = isset($SESSION->questionperpage) ? $SESSION->questionperpage : DEFAULT_QUESTIONS_PER_PAGE; + } + + if ($sortorder) { + $SESSION->questionsortorder = $sortorder; + } else { + $sortorder = isset($SESSION->questionsortorder) ? $SESSION->questionsortorder : 'qtype, name ASC'; + } + $SESSION->fromurl = $pageurl->out(); + +/// Now, check for commands on this page and modify variables as necessary + if (isset($_REQUEST['move']) and confirm_sesskey()) { /// Move selected questions to new category + $tocategoryid = required_param('category', PARAM_INT); + if (!$tocategory = get_record('question_categories', 'id', $tocategoryid)) { + error('Invalid category'); + } + if (!has_capability('moodle/question:managecategory', get_context_instance(CONTEXT_COURSE, $tocategory->course))){ + error(get_string('categorynoedit', 'quiz', $tocategory->name), $pageurl->out()); + } + foreach ($_POST as $key => $value) { // Parse input for question ids + if (substr($key, 0, 1) == "q") { + $key = substr($key,1); + if (!set_field('question', 'category', $tocategory->id, 'id', $key)) { + error('Could not update category field'); + } + } + } + } + + if (isset($_REQUEST['deleteselected'])) { // delete selected questions from the category + + if (isset($_REQUEST['confirm']) and confirm_sesskey()) { // teacher has already confirmed the action + $deleteselected = required_param('deleteselected'); + if ($_REQUEST['confirm'] == md5($deleteselected)) { + if ($questionlist = explode(',', $deleteselected)) { + // for each question either hide it if it is in use or delete it + foreach ($questionlist as $questionid) { + if (record_exists('quiz_question_instances', 'question', $questionid) or + record_exists('question_states', 'originalquestion', $questionid)) { + if (!set_field('question', 'hidden', 1, 'id', $questionid)) { + error('Was not able to hide question'); + } + } else { + delete_question($questionid); + } + } + } + echo ''; + echo ''; + echo '
'; + redirect($pageurl->out()); + } else { + error("Confirmation string was incorrect"); + } + } else { // teacher still has to confirm + // make a list of all the questions that are selected + $rawquestions = $_REQUEST; + $questionlist = ''; // comma separated list of ids of questions to be deleted + $questionnames = ''; // string with names of questions separated by
with + // an asterix in front of those that are in use + $inuse = false; // set to true if at least one of the questions is in use + foreach ($rawquestions as $key => $value) { // Parse input for question ids + if (substr($key, 0, 1) == "q") { + $key = substr($key,1); + $questionlist .= $key.','; + if (record_exists('quiz_question_instances', 'question', $key) or + record_exists('question_states', 'originalquestion', $key)) { + $questionnames .= '* '; + $inuse = true; + } + $questionnames .= get_field('question', 'name', 'id', $key).'
'; + } + } + if (!$questionlist) { // no questions were selected + redirect($pageurl->out()); + } + $questionlist = rtrim($questionlist, ','); + + // Add an explanation about questions in use + if ($inuse) { + $questionnames .= '
'.get_string('questionsinuse', 'quiz'); + } + notice_yesno(get_string("deletequestionscheck", "quiz", $questionnames), + $pageurl->out_action(array('deleteselected'=>$questionlist, 'confirm'=>md5($questionlist))), + $pageurl->out_action()); + + echo ''; + echo ''; + print_footer($COURSE); + exit; + } + } + + // Unhide a question + if(isset($_REQUEST['unhide']) && confirm_sesskey()) { + $unhide = required_param('unhide', PARAM_INT); + if(!set_field('question', 'hidden', 0, 'id', $unhide)) { + error("Failed to unhide the question."); + } + 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); + + // continues with list of questions + question_list($COURSE, $pageurl, $SESSION->questioncat, isset($cm) ? $cm : null, + $SESSION->questionrecurse, $page, $perpage, $SESSION->questionshowhidden, $sortorder, + $SESSION->questionshowquestiontext); + + print_box_end(); +} ?> Index: question/category.php =================================================================== RCS file: /cvsroot/moodle/moodle/question/category.php,v retrieving revision 1.16 diff -u -r1.16 category.php --- question/category.php 30 Apr 2007 06:48:58 -0000 1.16 +++ question/category.php 2 May 2007 17:07:50 -0000 @@ -12,11 +12,25 @@ require_once("editlib.php"); require_once("category_class.php"); + // get values from form $param = new stdClass(); - $id = required_param('courseid', PARAM_INT); // course id + $thispageurl = new moodle_url(); $param->page = optional_param('page', 1, PARAM_INT); + $thispageurl->param('page', $param->page); + + if (!$cmid = optional_param('cmid', 0, PARAM_INT)){ + + $courseid = required_param('courseid', PARAM_INT); + $thispageurl->params(compact('courseid')); + $cm = null; + $module = null; + } else { + list($module, $cm) = get_module_from_cmid($cmid); + $courseid = $cm->course; + $thispageurl->params(compact('cmid')); + } $param->moveup = optional_param('moveup', 0, PARAM_INT); $param->movedown = optional_param('movedown', 0, PARAM_INT); @@ -33,35 +47,48 @@ $param->edit = optional_param('edit', 0, PARAM_INT); $param->updateid = optional_param('updateid', 0, PARAM_INT); - if (! $course = get_record("course", "id", $id)) { + if (! $course = get_record("course", "id", $courseid)) { error("Course ID is incorrect"); } - $context = get_context_instance(CONTEXT_COURSE, $id); + $context = get_context_instance(CONTEXT_COURSE, $courseid); require_login($course->id, false); require_capability('moodle/question:managecategory', $context); - $qcobject = new question_category_object($param->page); + $qcobject = new question_category_object($param->page, $thispageurl); + $streditingcategories = get_string('editcategories', 'quiz'); if ($qcobject->editlist->process_actions($param->left, $param->right, $param->moveup, $param->movedown)) { //processing of these actions is handled in the method and page redirects. - } else if (isset($SESSION->modform->instance) and $quiz = get_record('quiz', 'id', $SESSION->modform->instance)) { + } else if ($cm!==null) { // Page header - // TODO: generalise this to any activity $strupdatemodule = has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id)) - ? update_module_button($SESSION->modform->cmid, $course->id, get_string('modulename', 'quiz')) + ? update_module_button($cm->id, $course->id, get_string('modulename', $cm->modname)) : ""; - print_header_simple(get_string('editcategories', 'quiz'), '', - "wwwroot/mod/quiz/index.php?id=$course->id\">".get_string('modulenameplural', 'quiz').''. - " -> wwwroot/mod/quiz/view.php?q=$quiz->id\">".format_string($quiz->name).''. - ' -> '.get_string('editcategories', 'quiz'), - "", "", true, $strupdatemodule); + $crumbs = array(); + $crumbs[] = array('name' => get_string('modulenameplural', $cm->modname), + 'link' => "$CFG->wwwroot/mod/{$cm->modname}/index.php?id=$course->id", + 'type' => 'activity'); + $crumbs[] = array('name' => format_string($module->name), + 'link' => "$CFG->wwwroot/mod/{$cm->modname}/view.php?cmid={$cm->id}", + 'type' => 'title'); + $crumbs[] = array('name' => $streditingcategories, 'link' => '', 'type' => 'title'); + $navigation = build_navigation($crumbs); + print_header_simple($streditingcategories, '', $navigation, "", "", true, $strupdatemodule); + + $currenttab = 'edit'; $mode = 'categories'; - include($CFG->dirroot.'/mod/quiz/tabs.php'); + ${$cm->modname} = $module; + include($CFG->dirroot."/mod/{$cm->modname}/tabs.php"); } else { - print_header_simple(get_string('editcategories', 'quiz'), '', get_string('editcategories', 'quiz')); + // Print basic page layout. + $crumbs = array(); + $crumbs[] = array('name' => $streditingcategories, 'link' => '', 'type' => 'title'); + $navigation = build_navigation($crumbs); + + print_header_simple($streditingcategories, '', $navigation); // print tabs $currenttab = 'categories'; Index: question/import.php =================================================================== RCS file: /cvsroot/moodle/moodle/question/import.php,v retrieving revision 1.34 diff -u -r1.34 import.php --- question/import.php 30 Apr 2007 06:48:59 -0000 1.34 +++ question/import.php 2 May 2007 17:07:51 -0000 @@ -14,12 +14,24 @@ require_once($CFG->libdir . '/uploadlib.php'); require_once($CFG->libdir . '/questionlib.php'); + $thispageurl = new moodle_url(); + if (!$cmid = optional_param('cmid', 0, PARAM_INT)){ + if ($courseid = optional_param('courseid', 0, PARAM_INT)){ + $thispageurl->params(compact('courseid')); + } + $cm = null; + $module = null; + } else { + list($module, $cm) = get_module_from_cmid($cmid); + $courseid = $cm->course; + $thispageurl->params(compact('cmid')); + } + // get parameters $params = new stdClass; $params->choosefile = optional_param('choosefile','',PARAM_PATH); $categoryid = optional_param('category', 0, PARAM_INT); $catfromfile = optional_param('catfromfile', 0, PARAM_BOOL ); - $courseid = optional_param('courseid', 0, PARAM_INT); $format = optional_param('format','',PARAM_FILE); $params->matchgrades = optional_param('matchgrades','',PARAM_ALPHA); $params->stoponerror = optional_param('stoponerror', 0, PARAM_BOOL); @@ -28,7 +40,6 @@ $txt = new stdClass(); $txt->category = get_string('category','quiz'); $txt->choosefile = get_string('choosefile','quiz'); - $txt->editingquiz = get_string(isset($SESSION->modform->instance) ? "editingquiz" : "editquestions", "quiz"); $txt->file = get_string('file'); $txt->fileformat = get_string('fileformat','quiz'); $txt->fromfile = get_string('fromfile','quiz'); @@ -58,7 +69,7 @@ if ($categoryid) { // update category in session variable $SESSION->questioncat = $categoryid; - } else { // try to get category from modform + } else { // try to get category from session if (isset($SESSION->questioncat)) { $categoryid = $SESSION->questioncat; } @@ -94,20 +105,28 @@ // PAGE HEADER //========== - if (isset($SESSION->modform->instance) and $quiz = get_record('quiz', 'id', $SESSION->modform->instance)) { - $strupdatemodule = has_capability('moodle/course:manageactivities', $context) - ? update_module_button($SESSION->modform->cmid, $course->id, $txt->modulename) + if ($cm!==null) { + $strupdatemodule = has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id)) + ? update_module_button($cm->id, $course->id, get_string('modulename', $cm->modname)) : ""; - print_header_simple($txt->importquestions, '', - "wwwroot/mod/quiz/index.php?id=$course->id\">".$txt->modulenameplural.''. - " -> wwwroot/mod/quiz/view.php?q=$quiz->id\">".format_string($quiz->name).''. - ' -> '.$txt->importquestions, - "", "", true, $strupdatemodule); + $crumbs = array(); + $crumbs[] = array('name' => get_string('modulenameplural', $cm->modname), 'link' => "$CFG->wwwroot/mod/{$cm->modname}/index.php?id=$course->id", 'type' => 'activity'); + $crumbs[] = array('name' => format_string($module->name), 'link' => "$CFG->wwwroot/mod/{$cm->modname}/view.php?cmid={$cm->id}", 'type' => 'title'); + $crumbs[] = array('name' => $txt->importquestions, 'link' => '', 'type' => 'title'); + $navigation = build_navigation($crumbs); + print_header_simple($txt->importquestions, '', $navigation, "", "", true, $strupdatemodule); + $currenttab = 'edit'; $mode = 'import'; - include($CFG->dirroot.'/mod/quiz/tabs.php'); + ${$cm->modname} = $module; + include($CFG->dirroot."/mod/$cm->modname/tabs.php"); } else { - print_header_simple($txt->importquestions, '', $txt->importquestions); + // Print basic page layout. + $crumbs = array(); + $crumbs[] = array('name' => $txt->importquestions, 'link' => '', 'type' => 'title'); + $navigation = build_navigation($crumbs); + + print_header_simple($txt->importquestions, '', $navigation); // print tabs $currenttab = 'import'; include('tabs.php'); @@ -130,8 +149,7 @@ else { notify($txt->uploadproblem); } - } - else { + } else { // must be upload file if (empty($_FILES['newfile'])) { notify( $txt->uploadproblem ); @@ -168,24 +186,21 @@ // Do anything before that we need to if (! $qformat->importpreprocess()) { - error( $txt->importerror , - "$CFG->wwwroot/question/import.php?courseid={$course->id}&category=$category->id"); + error( $txt->importerror, $thispageurl->out(false, array('category'=>$category->id))); } // Process the uploaded file if (! $qformat->importprocess() ) { - error( $txt->importerror , - "$CFG->wwwroot/question/import.php?courseid={$course->id}&category=$category->id"); + error( $txt->importerror, $thispageurl->out(false, array('category'=>$category->id))); } // In case anything needs to be done after if (! $qformat->importpostprocess()) { - error( $txt->importerror , - "$CFG->wwwroot/question/import.php?courseid={$course->id}&category=$category->id"); + error( $txt->importerror, $thispageurl->out(false, array('category'=>$category->id))); } echo "
"; - print_continue("edit.php?courseid=$course->id"); + print_continue("edit.php?".$thispageurl->get_query_string()); print_footer($course); exit; } @@ -210,6 +225,7 @@
+ hidden_params_out(3); ?> Index: question/edit.php =================================================================== RCS file: /cvsroot/moodle/moodle/question/edit.php,v retrieving revision 1.12 diff -u -r1.12 edit.php --- question/edit.php 22 Mar 2007 11:46:15 -0000 1.12 +++ question/edit.php 2 May 2007 17:07:50 -0000 @@ -13,16 +13,21 @@ require_once("../config.php"); require_once("editlib.php"); - require_login(); - $courseid = required_param('courseid', PARAM_INT); - - // The optional parameter 'clean' allows us to clear module information, - // guaranteeing a module-independent question bank editing interface - if (optional_param('clean', false, PARAM_BOOL)) { - unset($SESSION->modform); + $thispageurl = new moodle_url(); + if (!$cmid = optional_param('cmid', 0, PARAM_INT)){ + + $courseid = required_param('courseid', PARAM_INT); + $thispageurl->params(compact('courseid')); + $cm = null; + $module = null; + } else { + list($module, $cm) = get_module_from_cmid($cmid); + $courseid = $cm->course; + $thispageurl->params(compact('cmid')); } + if (! $course = get_record("course", "id", $courseid)) { error("This course doesn't exist"); } @@ -31,39 +36,40 @@ $SESSION->returnurl = $FULLME; - // Print basic page layout. $streditingquestions = get_string('editquestions', "quiz"); - - // TODO: generalise this to any activity - $strquizzes = get_string('modulenameplural', 'quiz'); - $streditingquestions = get_string('editquestions', "quiz"); - if (isset($SESSION->modform->instance) and $quiz = get_record('quiz', 'id', $SESSION->modform->instance)) { + if ($cm!==null) { $strupdatemodule = has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id)) - ? update_module_button($SESSION->modform->cmid, $course->id, get_string('modulename', 'quiz')) + ? update_module_button($cm->id, $course->id, get_string('modulename', $cm->modname)) : ""; - print_header_simple($streditingquestions, '', - "wwwroot/mod/quiz/index.php?id=$course->id\">$strquizzes". - " -> wwwroot/mod/quiz/view.php?q={$SESSION->modform->instance}\">".format_string($SESSION->modform->name).''. - " -> $streditingquestions", - "", "", true, $strupdatemodule); + $crumbs = array(); + $crumbs[] = array('name' => get_string('modulenameplural', $cm->modname), 'link' => "$CFG->wwwroot/mod/{$cm->modname}/index.php?id=$course->id", 'type' => 'activity'); + $crumbs[] = array('name' => format_string($module->name), 'link' => "$CFG->wwwroot/mod/{$cm->modname}/view.php?cmid={$cm->id}", 'type' => 'title'); + $crumbs[] = array('name' => $streditingquestions, 'link' => '', 'type' => 'title'); + $navigation = build_navigation($crumbs); + print_header_simple($streditingquestions, '', $navigation, "", "", true, $strupdatemodule); $currenttab = 'edit'; $mode = 'questions'; - $quiz = &$SESSION->modform; - include($CFG->dirroot.'/mod/quiz/tabs.php'); + ${$cm->modname} = $module; + include($CFG->dirroot."/mod/$cm->modname/tabs.php"); } else { - print_header_simple($streditingquestions, '', - "$streditingquestions"); - + // Print basic page layout. + $crumbs = array(); + $crumbs[] = array('name' => $streditingquestions, 'link' => '', 'type' => 'title'); + $navigation = build_navigation($crumbs); + + print_header_simple($streditingquestions, '', $navigation); + // print tabs $currenttab = 'questions'; include('tabs.php'); } - + + echo '
'; echo ''; echo '
'; - include($CFG->dirroot.'/question/showbank.php'); + showbank($thispageurl, $cm); echo '
'; Index: question/tabs.php =================================================================== RCS file: /cvsroot/moodle/moodle/question/tabs.php,v retrieving revision 1.4 diff -u -r1.4 tabs.php --- question/tabs.php 21 Mar 2007 10:41:28 -0000 1.4 +++ question/tabs.php 2 May 2007 17:07:51 -0000 @@ -18,7 +18,7 @@ $tabs = array(); $inactive = array(); $row = array(); - questionbank_navigation_tabs($row, $context, $course->id); + questionbank_navigation_tabs($row, $context, 'courseid='.$course->id); $tabs[] = $row; print_tabs($tabs, $currenttab, array()); Index: question/showbank.php =================================================================== RCS file: question/showbank.php diff -N question/showbank.php --- question/showbank.php 22 Mar 2007 11:46:15 -0000 1.24 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,189 +0,0 @@ -dirroot.'/question/editlib.php'); - - $page = optional_param('page', -1, PARAM_INT); - $perpage = optional_param('perpage', -1, PARAM_INT); - $sortorder = optional_param('sortorder', ''); - if (preg_match("/[';]/", $sortorder)) { - error("Incorrect use of the parameter 'sortorder'"); - } - - if ($page > -1) { - $SESSION->questionpage = $page; - } else { - $page = isset($SESSION->questionpage) ? $SESSION->questionpage : 0; - } - - if ($perpage > -1) { - $SESSION->questionperpage = $perpage; - } else { - $perpage = isset($SESSION->questionperpage) ? $SESSION->questionperpage : DEFAULT_QUESTIONS_PER_PAGE; - } - - if ($sortorder) { - $SESSION->questionsortorder = $sortorder; - } else { - $sortorder = isset($SESSION->questionsortorder) ? $SESSION->questionsortorder : 'qtype, name ASC'; - } - $SESSION->fromurl = $FULLME; - -/// Now, check for commands on this page and modify variables as necessary - if (isset($_REQUEST['move']) and confirm_sesskey()) { /// Move selected questions to new category - $tocategoryid = required_param('category', PARAM_INT); - if (!$tocategory = get_record('question_categories', 'id', $tocategoryid)) { - error('Invalid category'); - } - if (!has_capability('moodle/question:managecategory', get_context_instance(CONTEXT_COURSE, $tocategory->course))){ - error(get_string('categorynoedit', 'quiz', $tocategory->name), 'edit.php?courseid=$course->id'); - } - foreach ($_POST as $key => $value) { // Parse input for question ids - if (substr($key, 0, 1) == "q") { - $key = substr($key,1); - if (!set_field('question', 'category', $tocategory->id, 'id', $key)) { - error('Could not update category field'); - } - } - } - } - - if (isset($_REQUEST['deleteselected'])) { // delete selected questions from the category - - if (isset($_REQUEST['confirm']) and confirm_sesskey()) { // teacher has already confirmed the action - $deleteselected = required_param('deleteselected'); - if ($_REQUEST['confirm'] == md5($deleteselected)) { - if ($questionlist = explode(',', $deleteselected)) { - // for each question either hide it if it is in use or delete it - foreach ($questionlist as $questionid) { - if (record_exists('quiz_question_instances', 'question', $questionid) or - record_exists('question_states', 'originalquestion', $questionid)) { - if (!set_field('question', 'hidden', 1, 'id', $questionid)) { - error('Was not able to hide question'); - } - } else { - delete_question($questionid); - } - } - } - echo ''; - echo ''; - echo '
'; - redirect("edit.php?courseid=$course->id"); - } else { - error("Confirmation string was incorrect"); - } - - } else { // teacher still has to confirm - // make a list of all the questions that are selected - $rawquestions = $_REQUEST; - $questionlist = ''; // comma separated list of ids of questions to be deleted - $questionnames = ''; // string with names of questions separated by
with - // an asterix in front of those that are in use - $inuse = false; // set to true if at least one of the questions is in use - foreach ($rawquestions as $key => $value) { // Parse input for question ids - if (substr($key, 0, 1) == "q") { - $key = substr($key,1); - $questionlist .= $key.','; - if (record_exists('quiz_question_instances', 'question', $key) or - record_exists('question_states', 'originalquestion', $key)) { - $questionnames .= '* '; - $inuse = true; - } - $questionnames .= get_field('question', 'name', 'id', $key).'
'; - } - } - if (!$questionlist) { // no questions were selected - redirect("edit.php?courseid=$course->id"); - } - $questionlist = rtrim($questionlist, ','); - - // Add an explanation about questions in use - if ($inuse) { - $questionnames .= '
'.get_string('questionsinuse', 'quiz'); - } - notice_yesno(get_string("deletequestionscheck", "quiz", $questionnames), - "edit.php?courseid=$course->id&sesskey=$USER->sesskey&deleteselected=$questionlist&confirm=".md5($questionlist), "edit.php?courseid=$course->id"); - - echo ''; - echo ''; - print_footer($course); - exit; - } - } - - // Unhide a question - if(isset($_REQUEST['unhide']) && confirm_sesskey()) { - $unhide = required_param('unhide', PARAM_INT); - if(!set_field('question', 'hidden', 0, 'id', $unhide)) { - error("Failed to unhide the question."); - } - redirect("edit.php?courseid=$course->id"); - } - - 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, $SESSION->questioncat, $SESSION->questionrecurse, - $SESSION->questionshowhidden, $SESSION->questionshowquestiontext); - - // continues with list of questions - question_list($course, $SESSION->questioncat, isset($modform->instance) ? $modform->instance : 0, - $SESSION->questionrecurse, $page, $perpage, $SESSION->questionshowhidden, $sortorder, - $SESSION->questionshowquestiontext); - - print_box_end(); - -?> Index: lang/en_utf8/error.php =================================================================== RCS file: /cvsroot/moodle/moodle/lang/en_utf8/error.php,v retrieving revision 1.19 diff -u -r1.19 error.php --- lang/en_utf8/error.php 19 Apr 2007 08:57:54 -0000 1.19 +++ lang/en_utf8/error.php 2 May 2007 17:07:40 -0000 @@ -39,6 +39,7 @@ $string['invalidmd5'] = 'Invalid md5'; $string['invalidrequest'] = 'Invalid request'; $string['invalidrole'] = 'Invalid role'; +$string['invalidurl'] = 'Invalid url'; $string['invalidxmlfile'] = '\"$a\" is not a valid XML file'; $string['listnopeers'] = 'No peers of item found.'; $string['listnoitem'] = 'Item not found.';