### 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 .= '
';
} else {
$icons .= '
';
}
if (!$first) {
- $icons .= '
+ $icons .= '
';
} else {
$icons .= '
';
}
if (!$last) {
- $icons .= '
+ $icons .= '
';
} else {
$icons .= '
';
@@ -571,7 +522,7 @@
if (!empty($lastitem)) {
$makechildof = get_string('makechildof', 'question', $lastitem->name);
- $icons .= '
+ $icons .= '
';
} 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 "