diff --git a/question/category.php b/question/category.php index ef2aeebf32a..64cdc7965c5 100644 --- a/question/category.php +++ b/question/category.php @@ -6,11 +6,11 @@ * @author Martin Dougiamas and many others. * {@link http://moodle.org} * @license http://www.gnu.org/copyleft/gpl.html GNU Public License -* @package quiz +* @package question */ - require_once("../../config.php"); - require_once("locallib.php"); + require_once("../config.php"); + require_once($CFG->libdir.'/questionlib.php'); require_once("category_class.php"); // get values from form @@ -34,10 +34,6 @@ error("Course ID is incorrect"); } - if (isset($_REQUEST['backtoquiz'])) { - redirect("edit.php"); - } - require_login($course->id, false); if (!isteacheredit($course->id)) { @@ -51,21 +47,21 @@ // PAGE HEADER //========== + // TODO: generalise this to any activity if (isset($SESSION->modform->instance) and $quiz = get_record('quiz', 'id', $SESSION->modform->instance)) { $strupdatemodule = isteacheredit($course->id) ? update_module_button($SESSION->modform->cmid, $course->id, get_string('modulename', 'quiz')) : ""; print_header_simple(get_string('editcategories', 'quiz'), '', - "id\">".get_string('modulenameplural', 'quiz').''. - " -> id\">".format_string($quiz->name).''. + "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); $currenttab = 'edit'; $mode = 'categories'; - include('tabs.php'); + include($CFG->dirroot.'/mod/quiz/tabs.php'); } else { print_header_simple(get_string('editcategories', 'quiz'), '', - "id\">".get_string('modulenameplural', 'quiz').''. '-> '.get_string('editquestions', 'quiz').''. ' -> '.get_string('editcategories', 'quiz')); } diff --git a/question/category_class.php b/question/category_class.php index e227a60bcd2..af89615230d 100644 --- a/question/category_class.php +++ b/question/category_class.php @@ -4,6 +4,10 @@ * * Used for handling changes to the quiz categories * +* @version $Id$ +* @author Martin Dougiamas and many others. {@link http://moodle.org} +* @license http://www.gnu.org/copyleft/gpl.html GNU Public License +* @package question */ // number of categories to display on page diff --git a/question/edit.php b/question/edit.php index 2441ae698c8..3e3913ab2b8 100644 --- a/question/edit.php +++ b/question/edit.php @@ -1,119 +1,24 @@ course)) { // data submitted - - $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 - - $cm = get_coursemodule_from_instance('quiz', $modform->instance); - $modform->cmid = $cm->id; - // We don't log all visits to this page but only those that recreate modform - add_to_log($cm->course, 'quiz', 'editquestions', - "view.php?id=$cm->id", - "$quizid", $cm->id); - } - - } else if ($courseid) { // Page retrieve through "Edit Questions" link - no quiz selected - $modform->course = $courseid; - unset($modform->instance); - $SESSION->modform = $modform; // Save the form in the current session - - add_to_log($courseid, 'quiz', 'editquestions', "index.php?id=$courseid"); - - } 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 { - exit; - } - } else { - // we might get here after editing a question in - // a popup window. So close window automatically. -?> - - -modform)) { - $modform = $SESSION->modform; - } else { - exit; - } - } - - if (! $course = get_record("course", "id", $modform->course)) { + if (! $course = get_record("course", "id", $courseid)) { error("This course doesn't exist"); } @@ -123,398 +28,19 @@ if (self.name == 'editquestion') { error("You can't modify this course!"); } - if (isset($modform->instance) - && empty($modform->grades)) // Construct an array to hold all the grades. - { - $modform->grades = quiz_get_all_question_grades($modform); - } - - if ($page > -1) { - $modform->page = $page; - } else { - $page = isset($modform->page) ? $modform->page : 0; - } - -/// Now, check for commands on this page and modify variables as necessary - - if (isset($_REQUEST['up']) and confirm_sesskey()) { /// Move the given question up a slot - $questions = explode(",", $modform->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); - // Always have a page break at the end - $modform->questions = $modform->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)) { - error('Could not save question list'); - } - } - } - - if (isset($_REQUEST['down']) and confirm_sesskey()) { /// Move the given question down a slot - $questions = explode(",", $modform->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); - // Avoid duplicate page breaks - $modform->questions = str_replace(',0,0', ',0', $modform->questions); - if (!set_field('quiz', 'questions', $modform->questions, 'id', $modform->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); - } - - 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); - } - } - } - - if (isset($_REQUEST['addrandom']) and confirm_sesskey()) { /// Add random questions to the quiz - $recurse = optional_param('recurse', 0, PARAM_BOOL); - $categoryid = required_param('categoryid', PARAM_INT); - $randomcount = required_param('randomcount', PARAM_INT); - // load category - if (! $category = get_record('quiz_categories', 'id', $categoryid)) { - error('Category ID is incorrect'); - } - // find existing random questions in this category - $random = RANDOM; - if ($existingquestions = get_records_select('quiz_questions', "qtype = '$random' AND category = '$category->id'")) { - // now remove the ones that are already used in this quiz - if ($questionids = explode(',', $modform->questions)) { - foreach ($questionids as $questionid) { - unset($existingquestions[$questionid]); - } - } - // now take as many of these as needed - $i = 0; - 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); - $i++; - } - } - $randomcreate = $randomcount - $i; // the number of additional random questions needed. - } else { - $randomcreate = $randomcount; - } - - if ($randomcreate > 0) { - - $form->name = get_string('random', 'quiz') .' ('. $category->name .')'; - $form->questiontext = $recurse; // we use the questiontext field to store the info - // on whether to include questions in subcategories - $form->questiontextformat = 0; - $form->image = ''; - $form->defaultgrade = 1; - $form->hidden = 1; - for ($i=0; $i<$randomcreate; $i++) { - $form->stamp = make_unique_id_code(); // Set the unique code (not to be changed) - $question = new stdClass; - $question->category = $category->id; - $question->qtype = RANDOM; - $question = $QUIZ_QTYPES[RANDOM]->save_question($question, $form, $course); - if(!isset($question->id)) { - error('Could not insert new random question!'); - } - quiz_add_quiz_question($question->id, $modform); - } - } - } - - if (isset($_REQUEST['repaginate']) and confirm_sesskey()) { /// Re-paginate the quiz - if (isset($_REQUEST['questionsperpage'])) { - $modform->questionsperpage = required_param('questionsperpage', 1, PARAM_INT); - if (!set_field('quiz', 'questionsperpage', $modform->questionsperpage, 'id', $modform->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)) { - error('Could not save layout'); - } - } - - if (isset($_REQUEST['move']) and confirm_sesskey()) { /// Move selected questions to new category - if (!$tocategory = get_record('quiz_categories', 'id', $_REQUEST['category'])) { - error('Invalid category'); - } - if (!isteacheredit($tocategory->course)) { - error(get_string('categorynoedit', 'quiz', $tocategory->name), 'edit.php'); - } - foreach ($_POST as $key => $value) { // Parse input for question ids - if (substr($key, 0, 1) == "q") { - $key = substr($key,1); - if (!set_field('quiz_questions', 'category', $tocategory->id, 'id', $key)) { - error('Could not update category field'); - } - } - } - } - - if (isset($_REQUEST['delete']) and confirm_sesskey()) { /// Remove a question from the quiz - quiz_delete_quiz_question($_REQUEST['delete'], $modform); - } - - if (isset($_REQUEST['deleteselected'])) { // delete selected questions from the category - - if (isset($confirm) and confirm_sesskey()) { // teacher has already confirmed the action - if ($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('quiz_states', 'originalquestion', $questionid)) { - if (!set_field('quiz_questions', 'hidden', 1, 'id', $questionid)) { - error('Was not able to hide question'); - } - } else { - delete_records("quiz_questions", "id", $questionid); - } - } - } - redirect("edit.php"); - } else { - error("Confirmation string was incorrect"); - } - - } else { // teacher still has to confirm - // make a list of all the questions that are selected - $rawquestions = $_POST; - $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('quiz_states', 'originalquestion', $key)) { - $questionnames .= '* '; - $inuse = true; - } - $questionnames .= get_field('quiz_questions', 'name', 'id', $key).'
'; - } - } - if (!$questionlist) { // no questions were selected - redirect('edit.php'); - } - $questionlist = rtrim($questionlist, ','); - - // Add an explanation about questions in use - if ($inuse) { - $questionnames .= get_string('questionsinuse', 'quiz'); - } - print_header_simple($streditingquestions, '', - "$streditingquestions"); - notice_yesno(get_string("deletequestionscheck", "quiz", $questionnames), - "edit.php?sesskey=$USER->sesskey&deleteselected=$questionlist&confirm=".md5($questionlist), "edit.php"); - print_footer($course); - exit; - } - } - - if (isset($_REQUEST['savechanges']) and confirm_sesskey()) { - /// We need to save the new ordering (if given) and the new grades - $oldquestions = explode(",", $modform->questions); // the questions in the old order - $questions = array(); // for questions in the new order - $rawgrades = $_POST; - unset($modform->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); - } elseif (substr($key, 0, 1) == "o") { // Parse input for ordering info - $key = substr($key,1); - $questions[$value] = $oldquestions[$key]; - } - } - - // If ordering info was given, reorder the questions - if ($questions) { - ksort($questions); - $modform->questions = implode(",", $questions); - // Always have a page break at the end - $modform->questions = $modform->questions . ',0'; - // Avoid duplicate page breaks - while (strpos($modform->questions, ',0,0')) { - $modform->questions = str_replace(',0,0', ',0', $modform->questions); - } - if (!set_field('quiz', 'questions', $modform->questions, 'id', $modform->instance)) { - error('Could not save question list'); - } - } - - // If rescaling is required save the new maximum - if (isset($_REQUEST['maxgrade'])) { - $modform->grade = optional_param('maxgrade', 0); - if (!set_field('quiz', 'grade', $modform->grade, 'id', $modform->instance)) { - error('Could not set new maximal grade for quiz'); - } - } - } - - if (isset($_REQUEST['cat'])) { /// coming from category selection drop-down menu - $modform->category = $cat; - $page = 0; - $modform->page = 0; - } - - if(isset($_REQUEST['recurse'])) { - $SESSION->quiz_recurse = optional_param('recurse', 0, PARAM_BOOL); - } - if(isset($_REQUEST['showbreaks'])) { - $SESSION->quiz_showbreaks = optional_param('showbreaks', 0, PARAM_BOOL); - $SESSION->quiz_reordertool = optional_param('reordertool', 0, PARAM_BOOL); - } - if(isset($_REQUEST['showhidden'])) { - $SESSION->quiz_showhidden = optional_param('showhidden', 0, PARAM_BOOL); - } - -/// Delete any teacher preview attempts if the quiz has been modified - if (isset($_REQUEST['setgrades']) 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); - } - -/// all commands have been dealt with, now print the page - - if (empty($modform->category) or !record_exists('quiz_categories', 'id', $modform->category)) { - $category = quiz_get_default_category($course->id); - $modform->category = $category->id; - } - if (!isset($SESSION->quiz_recurse)) { - $SESSION->quiz_recurse = 1; - } - if (!isset($SESSION->quiz_showhidden)) { - $SESSION->quiz_showhidden = false; - } - if (!isset($SESSION->quiz_showbreaks)) { - $SESSION->quiz_showbreaks = ($CFG->quiz_questionsperpage < 2) ? 0 : 1; - } - if (!isset($SESSION->quiz_reordertool)) { - $SESSION->quiz_reordertool = 0; - } - - $SESSION->modform = $modform; - // Print basic page layout. - if (isset($modform->instance) and record_exists_sql("SELECT * FROM {$CFG->prefix}quiz_attempts WHERE quiz = '$modform->instance' AND preview = '0' LIMIT 1")){ - // one column layout with table of questions used in this quiz - $strupdatemodule = isteacheredit($course->id) - ? update_module_button($modform->cmid, $course->id, get_string('modulename', 'quiz')) - : ""; - print_header_simple($streditingquiz, '', - "id\">$strquizzes". - " -> instance\">".format_string($modform->name).''. - " -> $streditingquiz", "", "", - true, $strupdatemodule); + $streditingquestions = get_string('editquestions', "quiz"); + print_header_simple($streditingquestions, '', + "$streditingquestions"); + print_heading_with_help(get_string('questions', 'quiz'), 'questionbank'); + echo ''; + echo '
'; - $currenttab = 'edit'; - $mode = 'editq'; - $quiz = &$modform; - include('tabs.php'); - - print_simple_box_start("center"); - - $attemptcount = count_records('quiz_attempts', 'quiz', $modform->instance, 'preview', 0); - - $strviewallanswers = get_string("viewallanswers","quiz",$attemptcount); - $strattemptsexist = get_string("attemptsexist","quiz"); - $usercount = count_records_select('quiz_attempts', "quiz = '$modform->id' AND preview = '0'", 'COUNT(DISTINCT userid)'); - $strusers = $course->students; - if (! $cm = get_coursemodule_from_instance("quiz", $modform->instance, $course->id)) { - error("Course Module ID was incorrect"); - } - echo "
\n"; - echo "$strattemptsexist
id\">$strviewallanswers ($usercount $strusers)"; - echo "
wwwroot/mod/quiz/edit.php\">\n"; - echo " id\" />\n"; - echo " \n"; - echo "
"; - echo "

\n"; - - $sumgrades = quiz_print_question_list($modform, false, $SESSION->quiz_showbreaks, $SESSION->quiz_reordertool); - if (!set_field('quiz', 'sumgrades', $sumgrades, 'id', $modform->instance)) { - error('Failed to set sumgrades'); - } - - print_simple_box_end(); - print_footer($course); - exit; - } - - if (!isset($modform->instance)) { - // one column layout for non-quiz-specific editing page - print_header_simple($streditingquestions, '', - "$streditingquestions"); - print_heading_with_help(get_string('questions', 'quiz'), 'questionbank'); - echo ''; - echo '"; echo ''; @@ -562,17 +244,17 @@ function quiz_print_cat_question_list($course, $categoryid, $quizid, echo "id&sesskey=$USER->sesskey\">pixpath/t/moveleft.gif\" border=\"0\" alt=\"$straddtoquiz\" /> "; } - echo "id&quizid=$quizid','$strpreview','scrollbars=yes,resizable=yes,width=700,height=480', false)\">id&quizid=$quizid','$strpreview','scrollbars=yes,resizable=yes,width=700,height=480', false)\">pixpath/t/preview.gif\" border=\"0\" alt=\"$strpreview\" /> "; if ($canedit) { - echo "id\">wwwroot/question/question.php?id=$question->id\">pixpath/t/edit.gif\" border=\"0\" alt=\"$stredit\" /> "; // hide-feature if($question->hidden) { - echo "id&hide=0&sesskey=$USER->sesskey\">wwwroot/question/question.php?id=$question->id&hide=0&sesskey=$USER->sesskey\">pixpath/t/restore.gif\" border=\"0\" alt=\"$strrestore\" />"; } else { - echo "id&delete=$question->id\">wwwroot/question/question.php?id=$question->id&delete=$question->id\">pixpath/t/delete.gif\" border=\"0\" alt=\"$strdelete\" />"; } } diff --git a/question/preview.php b/question/preview.php index 05cb5a38bee..bde4579086c 100644 --- a/question/preview.php +++ b/question/preview.php @@ -2,19 +2,23 @@ /** * This page displays a preview of a question * -* The preview uses the option settings from the quiz within which the question -* is previewed or the default settings if no quiz is specified. The question session +* The preview uses the option settings from the activity within which the question +* is previewed or the default settings if no activity is specified. The question session * information is stored in the session as an array of subsequent states rather * than in the database. +* +* TODO: make this work with activities other than quiz +* * @version $Id$ * @author Alex Smith as part of the Serving Mathematics project * {@link http://maths.york.ac.uk/serving_maths} * @license http://www.gnu.org/copyleft/gpl.html GNU Public License -* @package quiz +* @package question */ - require_once("../../config.php"); - require_once("locallib.php"); + require_once("../config.php"); + require_once($CFG->libdir.'/questionlib.php'); + require_once($CFG->dirroot.'/mod/quiz/locallib.php'); // We really want to get rid of this $id = required_param('id', PARAM_INT); // question id // if no quiz id is specified then a dummy quiz with default options is used @@ -47,7 +51,7 @@ // Redirect to ourselves but with continue=1; prevents refreshing the page // from restarting an attempt (needed so that random questions don't change) $quizid = $quizid ? '&quizid=' . $quizid : ''; - redirect($CFG->wwwroot . '/mod/quiz/preview.php?id=' . $id . $quizid . + redirect($CFG->wwwroot . '/question/preview.php?id=' . $id . $quizid . '&continue=1'); } diff --git a/question/question.php b/question/question.php index 7f5989215ae..9006d553efa 100644 --- a/question/question.php +++ b/question/question.php @@ -10,16 +10,20 @@ * - if question is in use: display this conflict (allow to hide the question?) * - else: confirm deletion and delete from database (sesskey, id, delete, confirm) * - cancel (cancel) +* +* TODO: currently this still treats the quiz as special, for example it sometimes redirects +* to mod/quiz/edit.php. +* * @version $Id$ * @author Martin Dougiamas and many others. This has recently been extensively * rewritten by members of the Serving Mathematics project * {@link http://maths.york.ac.uk/serving_maths} * @license http://www.gnu.org/copyleft/gpl.html GNU Public License -* @package quiz +* @package question */ - require_once("../../config.php"); - require_once("locallib.php"); + require_once("../config.php"); + require_once($CFG->libdir.'/questionlib.php'); require_once($CFG->libdir.'/filelib.php'); $id = optional_param('id'); // question id @@ -33,17 +37,19 @@ $qtype = RQP; } - $contextquiz = optional_param('contextquiz'); // the quiz from which this question is being edited + // TODO: generalise this so it works for any activity + $contextquiz = optional_param('contextquiz', 0, PARAM_INT); // the quiz from which this question is being edited + $editurl = ($contextquiz ? $CFG->wwwroot.'/mod/quiz/edit.php' : 'edit.php'; if (isset($_REQUEST['cancel'])) { - redirect("edit.php"); + redirect($editurl); } if(!empty($id) && isset($_REQUEST['hide']) && confirm_sesskey()) { if(!set_field('quiz_questions', 'hidden', $_REQUEST['hide'], 'id', $id)) { error("Faild to hide the question."); } - redirect('edit.php'); + redirect($editurl); } if ($id) { @@ -90,7 +96,7 @@ error("You can't modify these questions!"); } - $strquizzes = get_string('modulenameplural', 'quiz'); + // TODO: remove restriction to quiz $streditingquestion = get_string('editingquestion', 'quiz'); if (isset($SESSION->modform->instance)) { $strediting = ''.get_string('editingquiz', 'quiz').' -> '. @@ -124,6 +130,7 @@ } } else { + // TODO: check for other modules using this question if ($quiznames = quizzes_question_used($id)) { $a->questionname = $question->name; $a->quiznames = implode(', ', $quiznames); @@ -276,10 +283,11 @@ // $QUIZ_QTYPES[$question->qtype]->get_question_options($question); // quiz_regrade_question_in_quizzes($question, $replaceinquiz); //} - redirect("edit.php"); + redirect($editurl); } } + // prepare the grades selector drop-down used by many question types $grades = array(1,0.9,0.8,0.75,0.70,0.66666,0.60,0.50,0.40,0.33333,0.30,0.25,0.20,0.16666,0.142857,0.125,0.11111,0.10,0.05,0); foreach ($grades as $grade) { $percentage = 100 * $grade; diff --git a/question/questiontypes/calculated/editquestion.php b/question/questiontypes/calculated/editquestion.php index f86e1580f0a..5818773b91f 100644 --- a/question/questiontypes/calculated/editquestion.php +++ b/question/questiontypes/calculated/editquestion.php @@ -83,7 +83,7 @@ if (empty($form)) { } } print_heading_with_help(get_string("editingcalculated", "quiz"), "calculated", "quiz"); - require("$CFG->dirroot/mod/quiz/questiontypes/calculated/calculated.html"); + require("$CFG->dirroot/question/questiontypes/calculated/calculated.html"); } else { // $form is not empty /*********************************************************/ /***** Any subsequent page of the question wizard **/ diff --git a/question/questiontypes/calculated/questiontype.php b/question/questiontypes/calculated/questiontype.php index 0630704f6f8..5443743cf9b 100644 --- a/question/questiontypes/calculated/questiontype.php +++ b/question/questiontypes/calculated/questiontype.php @@ -6,7 +6,7 @@ /// QUESTION TYPE CLASS ////////////////// -require_once("$CFG->dirroot/mod/quiz/questiontypes/datasetdependent/abstractqtype.php"); +require_once("$CFG->dirroot/question/questiontypes/datasetdependent/abstractqtype.php"); class quiz_calculated_qtype extends quiz_dataset_dependent_questiontype { @@ -308,7 +308,7 @@ class quiz_calculated_qtype extends quiz_dataset_dependent_questiontype { function create_virtual_qtype() { global $CFG; - require_once("$CFG->dirroot/mod/quiz/questiontypes/numerical/questiontype.php"); + require_once("$CFG->dirroot/question/questiontypes/numerical/questiontype.php"); return new quiz_numerical_qtype(); } diff --git a/question/questiontypes/datasetdependent/abstractqtype.php b/question/questiontypes/datasetdependent/abstractqtype.php index ddd584a55ea..0033623cd94 100644 --- a/question/questiontypes/datasetdependent/abstractqtype.php +++ b/question/questiontypes/datasetdependent/abstractqtype.php @@ -156,11 +156,11 @@ class quiz_dataset_dependent_questiontype extends quiz_default_questiontype { // See where we're coming from switch($form->wizardpage) { case 'question': - require("$CFG->dirroot/mod/quiz/questiontypes/datasetdependent/datasetdefinitions.php"); + require("$CFG->dirroot/question/questiontypes/datasetdependent/datasetdefinitions.php"); break; case 'datasetdefinitions': case 'datasetitems': - require("$CFG->dirroot/mod/quiz/questiontypes/datasetdependent/datasetitems.php"); + require("$CFG->dirroot/question/questiontypes/datasetdependent/datasetitems.php"); break; default: error('Incorrect or no wizard page specified!'); diff --git a/question/questiontypes/datasetdependent/datasetdefinitions.php b/question/questiontypes/datasetdependent/datasetdefinitions.php index 3ed92c46619..b334828c189 100644 --- a/question/questiontypes/datasetdependent/datasetdefinitions.php +++ b/question/questiontypes/datasetdependent/datasetdefinitions.php @@ -14,5 +14,5 @@ $datasets = $this->construct_dataset_menus( // Print the page print_heading_with_help(get_string("choosedatasetproperties", "quiz"), "questiondatasets", "quiz"); -require("$CFG->dirroot/mod/quiz/questiontypes/datasetdependent/questiondatasets.html"); -?> \ No newline at end of file +require("$CFG->dirroot/question/questiontypes/datasetdependent/questiondatasets.html"); +?> diff --git a/question/questiontypes/description/editquestion.php b/question/questiontypes/description/editquestion.php index 21f8c825730..eefbdb51ee1 100644 --- a/question/questiontypes/description/editquestion.php +++ b/question/questiontypes/description/editquestion.php @@ -1,6 +1,6 @@ dirroot/mod/quiz/questiontypes/description/description.html"); + require("$CFG->dirroot/question/questiontypes/description/description.html"); ?> diff --git a/question/questiontypes/description/questiontype.php b/question/questiontypes/description/questiontype.php index a1d856b0574..7418e8be931 100644 --- a/question/questiontypes/description/questiontype.php +++ b/question/questiontypes/description/questiontype.php @@ -35,7 +35,7 @@ class quiz_description_qtype extends quiz_default_questiontype { quiz_print_possible_question_image($question, $cmoptions->course); if (isteacher($cmoptions->course)) { echo ''; - link_to_popup_window ('/mod/quiz/question.php?id=' . $question->id, + link_to_popup_window ('/question/question.php?id=' . $question->id, 'editquestion', get_string('edit'), 450, 550, get_string('edit')); echo ''; } diff --git a/question/questiontypes/essay/editquestion.php b/question/questiontypes/essay/editquestion.php index da8c83ae53f..30d14745ee0 100644 --- a/question/questiontypes/essay/editquestion.php +++ b/question/questiontypes/essay/editquestion.php @@ -11,6 +11,6 @@ } print_heading_with_help(get_string("editingessay", "quiz"), "essay", "quiz"); - require("$CFG->dirroot/mod/quiz/questiontypes/essay/essay.html"); + require("$CFG->dirroot/question/questiontypes/essay/essay.html"); ?> diff --git a/question/questiontypes/match/editquestion.php b/question/questiontypes/match/editquestion.php index 39a01781e0e..c1add7411ec 100644 --- a/question/questiontypes/match/editquestion.php +++ b/question/questiontypes/match/editquestion.php @@ -32,6 +32,6 @@ $yesnooptions[1] = get_string("yes"); print_heading_with_help(get_string("editingmatch", "quiz"), "match", "quiz"); - require("$CFG->dirroot/mod/quiz/questiontypes/match/match.html"); + require("$CFG->dirroot/question/questiontypes/match/match.html"); ?> diff --git a/question/questiontypes/multianswer/editquestion.php b/question/questiontypes/multianswer/editquestion.php index 0e22abaa59c..af747479a5b 100644 --- a/question/questiontypes/multianswer/editquestion.php +++ b/question/questiontypes/multianswer/editquestion.php @@ -49,6 +49,6 @@ } print_heading_with_help(get_string('editingmultianswer', 'quiz'), 'multianswer', 'quiz'); - require("$CFG->dirroot/mod/quiz/questiontypes/multianswer/multianswer.html"); + require("$CFG->dirroot/question/questiontypes/multianswer/multianswer.html"); ?> diff --git a/question/questiontypes/multichoice/editquestion.php b/question/questiontypes/multichoice/editquestion.php index 6147f893ea2..7bf9a39f1d0 100644 --- a/question/questiontypes/multichoice/editquestion.php +++ b/question/questiontypes/multichoice/editquestion.php @@ -30,6 +30,6 @@ $yesnooptions[1] = get_string("yes"); print_heading_with_help(get_string("editingmultichoice", "quiz"), "multichoice", "quiz"); - require("$CFG->dirroot/mod/quiz/questiontypes/multichoice/multichoice.html"); + require("$CFG->dirroot/question/questiontypes/multichoice/multichoice.html"); ?> diff --git a/question/questiontypes/multichoice/questiontype.php b/question/questiontypes/multichoice/questiontype.php index d72cd638058..b081435c22f 100644 --- a/question/questiontypes/multichoice/questiontype.php +++ b/question/questiontypes/multichoice/questiontype.php @@ -313,7 +313,7 @@ class quiz_multichoice_qtype extends quiz_default_questiontype { $anss[] = clone($a); } - include("$CFG->dirroot/mod/quiz/questiontypes/multichoice/display.html"); + include("$CFG->dirroot/question/questiontypes/multichoice/display.html"); } function grade_responses(&$question, &$state, $cmoptions) { diff --git a/question/questiontypes/numerical/editquestion.php b/question/questiontypes/numerical/editquestion.php index 69ddfce2287..58b2d7d606d 100644 --- a/question/questiontypes/numerical/editquestion.php +++ b/question/questiontypes/numerical/editquestion.php @@ -22,6 +22,6 @@ } print_heading_with_help(get_string("editingnumerical", "quiz"), "numerical", "quiz"); - require("$CFG->dirroot/mod/quiz/questiontypes/numerical/numerical.html"); + require("$CFG->dirroot/question/questiontypes/numerical/numerical.html"); ?> diff --git a/question/questiontypes/numerical/questiontype.php b/question/questiontypes/numerical/questiontype.php index 1a76cc706b5..80815b82b08 100644 --- a/question/questiontypes/numerical/questiontype.php +++ b/question/questiontypes/numerical/questiontype.php @@ -14,7 +14,7 @@ /// This question type behaves like shortanswer in most cases. /// Therefore, it extends the shortanswer question type... -require_once("$CFG->dirroot/mod/quiz/questiontypes/shortanswer/questiontype.php"); +require_once("$CFG->dirroot/question/questiontypes/shortanswer/questiontype.php"); class quiz_numerical_qtype extends quiz_shortanswer_qtype { diff --git a/question/questiontypes/questiontype.php b/question/questiontypes/questiontype.php index 4ab12f10719..e29b8f4b47f 100644 --- a/question/questiontypes/questiontype.php +++ b/question/questiontypes/questiontype.php @@ -459,7 +459,7 @@ class quiz_default_questiontype { if (isteacheredit($cmoptions->course)) { $stredit = get_string('edit'); $linktext = ''.$stredit.''; - $editlink = link_to_popup_window('/mod/quiz/question.php?id='.$question->id, $stredit, $linktext, 450, 550, $stredit, '', true); + $editlink = link_to_popup_window('/question/question.php?id='.$question->id, $stredit, $linktext, 450, 550, $stredit, '', true); } $grade = ''; @@ -498,7 +498,7 @@ class quiz_default_questiontype { $b = ($state->id == $st->id) ? '' : ''; $be = ($state->id == $st->id) ? '' : ''; $table->data[] = array ( - ($state->id == $st->id) ? ''.$st->seq_number.'' : link_to_popup_window ('/mod/quiz/reviewquestion.php?state='.$st->id.'&number='.$number, 'reviewquestion', $st->seq_number, 450, 650, $strreviewquestion, 'none', true), + ($state->id == $st->id) ? ''.$st->seq_number.'' : link_to_popup_window ('/question/reviewquestion.php?state='.$st->id.'&number='.$number, 'reviewquestion', $st->seq_number, 450, 650, $strreviewquestion, 'none', true), $b.get_string('event'.$st->event, 'quiz').$be, $b.$this->response_summary($st).$be, $b.userdate($st->timestamp, get_string('timestr', 'quiz')).$be, @@ -510,7 +510,7 @@ class quiz_default_questiontype { $history = make_table($table); } } - include "$CFG->dirroot/mod/quiz/questiontypes/question.html"; + include "$CFG->dirroot/question/questiontypes/question.html"; } @@ -800,7 +800,7 @@ class quiz_default_questiontype { * get_string($name, 'quiz') will be called. * ->link The filename part of the URL for the link. The full URL * is contructed as - * "$CFG->wwwroot/mod/quiz/questiontypes/{$this->name()}/$link?sesskey=$sesskey" + * "$CFG->wwwroot/question/questiontypes/{$this->name()}/$link?sesskey=$sesskey" * [but with the relavant calls to the s and rawurlencode * functions] where $sesskey is the sesskey for the user. * @return array Array of objects describing the configuration options to diff --git a/question/questiontypes/random/editquestion.php b/question/questiontypes/random/editquestion.php index 819a6602eab..3a0a186ee19 100644 --- a/question/questiontypes/random/editquestion.php +++ b/question/questiontypes/random/editquestion.php @@ -1,6 +1,6 @@ dirroot/mod/quiz/questiontypes/random/random.html"); + require("$CFG->dirroot/question/questiontypes/random/random.html"); ?> diff --git a/question/questiontypes/randomsamatch/editquestion.php b/question/questiontypes/randomsamatch/editquestion.php index c6f6dbfc27f..54160c34a6e 100644 --- a/question/questiontypes/randomsamatch/editquestion.php +++ b/question/questiontypes/randomsamatch/editquestion.php @@ -14,6 +14,6 @@ $yesnooptions[1] = get_string("yes"); print_heading_with_help(get_string("editingrandomsamatch", "quiz"), "randomsamatch", "quiz"); - require("$CFG->dirroot/mod/quiz/questiontypes/randomsamatch/randomsamatch.html"); + require("$CFG->dirroot/question/questiontypes/randomsamatch/randomsamatch.html"); ?> diff --git a/question/questiontypes/shortanswer/editquestion.php b/question/questiontypes/shortanswer/editquestion.php index 220c8e3f05b..53ba06bf052 100644 --- a/question/questiontypes/shortanswer/editquestion.php +++ b/question/questiontypes/shortanswer/editquestion.php @@ -23,6 +23,6 @@ } print_heading_with_help(get_string("editingshortanswer", "quiz"), "shortanswer", "quiz"); - require("$CFG->dirroot/mod/quiz/questiontypes/shortanswer/shortanswer.html"); + require("$CFG->dirroot/question/questiontypes/shortanswer/shortanswer.html"); ?> diff --git a/question/questiontypes/shortanswer/questiontype.php b/question/questiontypes/shortanswer/questiontype.php index 2e6649c9b43..865a13c996b 100644 --- a/question/questiontypes/shortanswer/questiontype.php +++ b/question/questiontypes/shortanswer/questiontype.php @@ -165,7 +165,7 @@ class quiz_shortanswer_qtype extends quiz_default_questiontype { } } } - include("$CFG->dirroot/mod/quiz/questiontypes/shortanswer/display.html"); + include("$CFG->dirroot/question/questiontypes/shortanswer/display.html"); } // ULPGC ecastro diff --git a/question/questiontypes/truefalse/editquestion.php b/question/questiontypes/truefalse/editquestion.php index e64b42d97f9..a9c52bb6ff9 100644 --- a/question/questiontypes/truefalse/editquestion.php +++ b/question/questiontypes/truefalse/editquestion.php @@ -23,6 +23,6 @@ } print_heading_with_help(get_string("editingtruefalse", "quiz"), "truefalse", "quiz"); - require("$CFG->dirroot/mod/quiz/questiontypes/truefalse/truefalse.html"); + require("$CFG->dirroot/question/questiontypes/truefalse/truefalse.html"); ?> diff --git a/question/questiontypes/truefalse/questiontype.php b/question/questiontypes/truefalse/questiontype.php index 6b6de7eb74f..33f86495069 100644 --- a/question/questiontypes/truefalse/questiontype.php +++ b/question/questiontypes/truefalse/questiontype.php @@ -182,7 +182,7 @@ class quiz_truefalse_qtype extends quiz_default_questiontype { $feedback = format_text($chosenanswer->feedback, true, false); } - include("$CFG->dirroot/mod/quiz/questiontypes/truefalse/display.html"); + include("$CFG->dirroot/question/questiontypes/truefalse/display.html"); } function grade_responses(&$question, &$state, $cmoptions) { diff --git a/question/showbank.php b/question/showbank.php new file mode 100644 index 00000000000..d86ac4c1d0e --- /dev/null +++ b/question/showbank.php @@ -0,0 +1,156 @@ +dirroot.'/question/editlib.php'); + + $page = optional_param('page', -1, PARAM_INT); + $perpage = optional_param('perpage', 20, PARAM_INT); + $sortorder = optional_param('sortorder', 'qtype, name ASC'); + 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; + } + +/// 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 + if (!$tocategory = get_record('quiz_categories', 'id', $_REQUEST['category'])) { + error('Invalid category'); + } + if (!isteacheredit($tocategory->course)) { + error(get_string('categorynoedit', 'quiz', $tocategory->name), 'edit.php'); + } + foreach ($_POST as $key => $value) { // Parse input for question ids + if (substr($key, 0, 1) == "q") { + $key = substr($key,1); + if (!set_field('quiz_questions', 'category', $tocategory->id, 'id', $key)) { + error('Could not update category field'); + } + } + } + } + + if (isset($_REQUEST['deleteselected'])) { // delete selected questions from the category + + if (isset($confirm) and confirm_sesskey()) { // teacher has already confirmed the action + if ($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('quiz_states', 'originalquestion', $questionid)) { + if (!set_field('quiz_questions', 'hidden', 1, 'id', $questionid)) { + error('Was not able to hide question'); + } + } else { + delete_records("quiz_questions", "id", $questionid); + } + } + } + redirect("edit.php"); + } else { + error("Confirmation string was incorrect"); + } + + } else { // teacher still has to confirm + // make a list of all the questions that are selected + $rawquestions = $_POST; + $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('quiz_states', 'originalquestion', $key)) { + $questionnames .= '* '; + $inuse = true; + } + $questionnames .= get_field('quiz_questions', 'name', 'id', $key).'
'; + } + } + if (!$questionlist) { // no questions were selected + redirect('edit.php'); + } + $questionlist = rtrim($questionlist, ','); + + // Add an explanation about questions in use + if ($inuse) { + $questionnames .= get_string('questionsinuse', 'quiz'); + } + print_header_simple($streditingquestions, '', + "$streditingquestions"); + notice_yesno(get_string("deletequestionscheck", "quiz", $questionnames), + "edit.php?sesskey=$USER->sesskey&deleteselected=$questionlist&confirm=".md5($questionlist), "edit.php"); + print_footer($course); + exit; + } + } + + if (isset($_REQUEST['cat'])) { /// coming from category selection drop-down menu + $SESSION->questioncat = $cat; + $page = 0; + $SESSION->questionpage = 0; + } + + if(isset($_REQUEST['recurse'])) { + $SESSION->questionrecurse = optional_param('recurse', 0, PARAM_BOOL); + } + + if(isset($_REQUEST['showhidden'])) { + $SESSION->questionshowhidden = optional_param('showhidden', 0, PARAM_BOOL); + } + +/// all commands have been dealt with, now print the page + + if (empty($SESSION->questioncat) or !record_exists('quiz_categories', 'id', $SESSION->questioncat)) { + $category = quiz_get_default_category($course->id); + $SESSION->questioncat = $category->id; + } + if (!isset($SESSION->questionrecurse)) { + $SESSION->questionrecurse = 1; + } + if (!isset($SESSION->questionshowhidden)) { + $SESSION->questionshowhidden = false; + } + + // starts with category selection form + print_simple_box_start("center", "100%"); + question_category_form($course, $SESSION->questioncat, $SESSION->questionrecurse, $SESSION->questionshowhidden); + print_simple_box_end(); + + print_spacer(5,1); + + // continues with list of questions + print_simple_box_start("center", "100%"); + question_list($course, $SESSION->questioncat, isset($modform->instance) ? $modform->instance : 0, $SESSION->questionrecurse, $page, $perpage, $SESSION->questionshowhidden, $sortorder); + print_simple_box_end(); + +?>
'; - - } else { - // two column layout with quiz info in left column - $strupdatemodule = isteacheredit($course->id) - ? update_module_button($modform->cmid, $course->id, get_string('modulename', 'quiz')) - : ""; - print_header_simple($streditingquiz, '', - "id\">$strquizzes". - " -> instance\">".format_string($modform->name).''. - " -> $streditingquiz", - "", "", true, $strupdatemodule); - - $currenttab = 'edit'; - $mode = 'editq'; - $quiz = &$modform; - include('tabs.php'); - - echo ''; - echo ''; echo '
'; - print_simple_box_start("center", "100%"); - - $sumgrades = quiz_print_question_list($modform, true, $SESSION->quiz_showbreaks, $SESSION->quiz_reordertool); - if (!set_field('quiz', 'sumgrades', $sumgrades, 'id', $modform->instance)) { - error('Failed to set sumgrades'); - } - - print_simple_box_end(); - - echo ''; - } - // non-quiz-specific column - print_simple_box_start("center", "100%"); - // starts with category selection form - quiz_print_category_form($course, $modform->category, $SESSION->quiz_recurse, $SESSION->quiz_showhidden); - print_simple_box_end(); - - print_spacer(5,1); - // continues with list of questions - print_simple_box_start("center", "100%"); - quiz_print_cat_question_list($course, $modform->category, - isset($modform->instance) ? $modform->instance : 0, $SESSION->quiz_recurse, $page, $perpage, $SESSION->quiz_showhidden, $sortorder); - print_simple_box_end(); + include($CFG->dirroot.'/question/showbank.php'); echo '
'; - - print_footer($course); ?> diff --git a/question/editlib.php b/question/editlib.php index 6f1ab4fa121..ab2b56a7ae2 100644 --- a/question/editlib.php +++ b/question/editlib.php @@ -1,16 +1,19 @@ libdir.'/questionlib.php'); /** * Array of question types names translated to the user's language @@ -38,329 +41,8 @@ if ($rqp_types = get_records('quiz_rqp_types')) { } } - -/** -* Delete a question from a quiz -* -* Deletes a question or a pagebreak from a quiz by updating $modform -* 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 -* This is updated by this function -*/ -function quiz_delete_quiz_question($id, &$modform) { - // 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); - - // only do something if this question exists - if (!isset($questions[$id])) { - return false; - } - - $question = $questions[$id]; - unset($questions[$id]); - // If we deleted the question at the top and it was followed by - // a page break then delete page break as well - if ($id == 0 and $questions[1] == 0) { - unset($questions[1]); - } - $modform->questions = implode(",", $questions); - // Avoid duplicate page breaks - $modform->questions = str_replace(',0,0', ',0', $modform->questions); - // save new questionlist in database - if (!set_field('quiz', 'questions', $modform->questions, 'id', $modform->instance)) { - error('Could not save question list'); - } -} - - -/** -* Add a question to a quiz -* -* Adds a question to a quiz by updating $modform 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 -* This is updated by this function -*/ -function quiz_add_quiz_question($id, &$modform) { - $questions = explode(",", $modform->questions); - - if (in_array($id, $questions)) { - return false; - } - - // remove ending page break if it is not needed - if ($breaks = array_keys($questions, 0)) { - // determine location of the last two page breaks - $end = end($breaks); - $last = prev($breaks); - $last = $last ? $last : -1; - if (!$modform->questionsperpage or (($end - $last -1) < $modform->questionsperpage)) { - array_pop($questions); - } - } - // add question - $questions[] = $id; - // add ending page break - $questions[] = 0; - - // Save new questionslist in database - $modform->questions = implode(",", $questions); - if (!set_field('quiz', 'questions', $modform->questions, 'id', $modform->id)) { - error('Could not save question list'); - } - - // update question grades - $questionrecord = get_record("quiz_questions", "id", $id); - $modform->grades[$id] = $questionrecord->defaultgrade; - quiz_update_question_instance($modform->grades[$id], $id, $modform->instance); - - return true; -} - -/** -* Save changes to question instance -* -* Saves changes to the question grades in the quiz_question_instances table. -* It does not update 'sumgrades' in the quiz table. -* @return boolean Indicates success or failure. -* @param integer grade The maximal grade for the question -* @param integer $questionid The id of the question -* @param integer $quizid The id of the quiz to update / add the instances for. -*/ -function quiz_update_question_instance($grade, $questionid, $quizid) { - if ($instance = get_record("quiz_question_instances", "quiz", $quizid, 'question', $questionid)) { - $instance->grade = $grade; - return update_record('quiz_question_instances', $instance); - } else { - unset($instance); - $instance->quiz = $quizid; - $instance->question = $questionid; - $instance->grade = $grade; - return insert_record("quiz_question_instances", $instance); - } -} - -/** -* Prints a list of quiz questions in a small layout form with knobs -* -* @return int sum of maximum grades -* @param object $quiz This is not the standard quiz object used elsewhere but -* it contains the quiz layout in $quiz->questions and the grades in -* $quiz->grades -* @param boolean $allowdelete Indicates whether the delete icons should be displayed -* @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) { - global $USER, $CFG, $QUIZ_QTYPES; - - $strorder = get_string("order"); - $strquestionname = get_string("questionname", "quiz"); - $strgrade = get_string("grade"); - $strremove = get_string('remove', 'quiz'); - $stredit = get_string("edit"); - $straction = get_string("action"); - $strmoveup = get_string("moveup"); - $strmovedown = get_string("movedown"); - $strsavegrades = get_string("savegrades", "quiz"); - $strtype = get_string("type", "quiz"); - $strpreview = get_string("preview", "quiz"); - - if (!$quiz->questions) { - echo "

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

"; - return 0; - } - - if (!$questions = get_records_sql("SELECT q.*,c.course - FROM {$CFG->prefix}quiz_questions q, - {$CFG->prefix}quiz_categories c - WHERE q.id in ($quiz->questions) - AND q.category = c.id")) { - echo "

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

"; - return 0; - } - - $count = 0; - $qno = 1; - $sumgrade = 0; - $order = explode(",", $quiz->questions); - $lastindex = count($order)-1; - // If the list does not end with a pagebreak then add it on. - if ($order[$lastindex] != 0) { - $order[] = 0; - $lastindex++; - } - echo "
"; - echo "sesskey\" />"; - - print_simple_box_start('center', '100%', '#ffffff', 0); - echo "\n"; - echo "\n"; - foreach ($order as $i => $qnum) { - - if ($qnum and empty($questions[$qnum])) { - continue; - } - // Show the re-ordering field if the tool is turned on. - // But don't show it in front of pagebreaks if they are hidden. - if ($reordertool) { - if ($qnum or $showbreaks) { - echo ''; - } else { - echo ''; - } - } else { - echo ''; - } - if ($qnum == 0) { // This is a page break - if ($showbreaks) { - echo ''; - echo ''; - echo ''; - } - $count++; - continue; - } - $question = $questions[$qnum]; - $canedit = isteacheredit($question->course); - - echo ""; - echo ""; - - if (!$quiz->shufflequestions) { - // Print and increment question number - echo ''; - $qno += $question->length; - } else { - echo ''; - } - - echo ""; - echo ""; - echo '"; - $count++; - $sumgrade += $quiz->grades[$qnum]; - } - - echo "\n"; - - echo "
$strorder#$strquestionname$strtype$strgrade$straction
 '; - echo ''; - echo ''; - echo '

Page break
'; - if ($count > 1) { - echo "sesskey\">pixpath/t/up.gif\" border=\"0\" alt=\"$strmoveup\" />"; - } - echo ' '; - if ($count < $lastindex) { - echo "sesskey\">pixpath/t/down.gif\" border=\"0\" alt=\"$strmovedown\" />"; - - echo "sesskey\"> - pixpath/t/delete.gif\" border=\"0\" alt=\"$strremove\" />"; - } - echo '
 
"; - if ($count != 0) { - echo "sesskey\">pixpath/t/up.gif\" border=\"0\" alt=\"$strmoveup\" />"; - } - echo ""; - if ($count < $lastindex-1) { - echo "sesskey\">pixpath/t/down.gif\" border=\"0\" alt=\"$strmovedown\" />"; - } - echo "'.($question->length ? $qno : ' ').' $question->name"; - quiz_print_question_icon($question, $canedit); - echo "'; - if ($question->qtype == DESCRIPTION) { - echo " \n"; - } else { - echo ''; - } - echo ''; - - $context = $quiz->id ? '&contextquiz='.$quiz->id : ''; - $quiz_id = $quiz->id ? '&quizid=' . $quiz->id : ''; - echo " - pixpath/t/preview.gif\" border=\"0\" alt=\"$strpreview\" />"; - if ($canedit) { - echo " - pixpath/t/edit.gif\" border=\"0\" alt=\"$stredit\" />"; - } - if ($allowdelete) { - echo "sesskey\"> - pixpath/t/removeright.gif\" border=\"0\" alt=\"$strremove\" />"; - } - - echo "
\n"; - print_string('total'); - echo ": \n"; - echo "$sumgrade"; - echo " \n
\n"; - print_string('maximumgrade'); - echo ": \n"; - echo ''; - echo ''; - helpbutton("maxgrade", get_string("maximumgrade"), "quiz"); - echo "
\n"; - - echo '
'; - echo '
'; - - print_simple_box_end(); - echo "
\n"; - -/// Form to choose to show pagebreaks and to repaginate quiz - echo '
'; - echo ''; - echo ''; - echo ''; - print_string('showbreaks', 'quiz'); - - if ($showbreaks) { - $perpage= array(); - for ($i=0; $i<=50; ++$i) { - $perpage[$i] = $i; - } - $perpage[0] = get_string('allinone', 'quiz'); - echo '
  '; - print_string('repaginate', 'quiz', - choose_from_menu($perpage, 'questionsperpage', $quiz->questionsperpage, '', '', '', true)); - } - - echo '
'; - echo ''; - print_string('reordertool', 'quiz'); - helpbutton('reorderingtool', get_string('reorderingtool', 'quiz'), 'quiz'); - - echo '
'; - echo '
'; - - return $sumgrade; -} - -function quiz_print_category_form($course, $current, $recurse=1, $showhidden=false) { +function question_category_form($course, $current, $recurse=1, $showhidden=false) { + global $CFG; /// Prints a form to choose categories /// Make sure the default category exists for this course @@ -393,7 +75,7 @@ function quiz_print_category_form($course, $current, $recurse=1, $showhidden=fal echo "
"; popup_form ("edit.php?cat=", $catmenu, "catmenu", $current, "", "", "", false, "self"); echo ""; - echo "
"; + echo "wwwroot/question/category.php\">"; echo "id\" />"; echo ""; echo "
"; @@ -433,7 +115,7 @@ function quiz_print_category_form($course, $current, $recurse=1, $showhidden=fal * @param int $perpage Number of questions to show per page * @param boolean $showhidden True if also hidden questions should be displayed */ -function quiz_print_cat_question_list($course, $categoryid, $quizid, +function question_list($course, $categoryid, $quizid, $recurse=1, $page, $perpage, $showhidden=false, $sortorder='qtype, name ASC') { global $QUIZ_QUESTION_TYPE, $USER, $CFG; @@ -483,7 +165,7 @@ function quiz_print_cat_question_list($course, $categoryid, $quizid, if (isteacheredit($category->course)) { echo "
$strcreatenewquestion:'; - popup_form ("question.php?category=$category->id&qtype=", $QUIZ_QUESTION_TYPE, "addquestion", + popup_form ("$CFG->wwwroot/question/question.php?category=$category->id&qtype=", $QUIZ_QUESTION_TYPE, "addquestion", "", "choose", "", "", false, "self"); echo ''; helpbutton("questiontypes", $strcreatenewquestion, "quiz"); @@ -497,11 +179,11 @@ function quiz_print_cat_question_list($course, $categoryid, $quizid, echo '
'; if (isteacheredit($category->course)) { - echo ''.$strimportquestions.''; + echo ''.$strimportquestions.''; helpbutton("import", $strimportquestions, "quiz"); echo ' | '; } - echo "id}&courseid={$course->id}\">$strexportquestions"; + echo "wwwroot/mod/quiz/export.php?category={$category->id}&courseid={$course->id}\">$strexportquestions"; helpbutton("export", $strexportquestions, "quiz"); echo '