Updated question scripts to work in their new location

This commit is contained in:
gustav_delius
2006-02-24 10:35:28 +00:00
parent e56a08dc15
commit e586cfb4b0
27 changed files with 249 additions and 873 deletions
+7 -11
View File
@@ -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'), '',
"<a href=\"index.php?id=$course->id\">".get_string('modulenameplural', 'quiz').'</a>'.
" -> <a href=\"view.php?q=$quiz->id\">".format_string($quiz->name).'</a>'.
"<a href=\"$CFG->wwwroot/mod/quiz/index.php?id=$course->id\">".get_string('modulenameplural', 'quiz').'</a>'.
" -> <a href=\"$CFG->wwwroot/mod/quiz/view.php?q=$quiz->id\">".format_string($quiz->name).'</a>'.
' -> '.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'), '',
"<a href=\"index.php?id=$course->id\">".get_string('modulenameplural', 'quiz').'</a>'.
'-> <a href="edit.php">'.get_string('editquestions', 'quiz').'</a>'.
' -> '.get_string('editcategories', 'quiz'));
}
+4
View File
@@ -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
+13 -487
View File
@@ -1,119 +1,24 @@
<?php // $Id$
/**
* Page to edit quizzes
* Page to edit the question bank
*
* This page generally has two columns:
* The right column lists all available questions in a chosen category and
* allows them to be edited or more to be added. This column is only there if
* the quiz does not already have student attempts
* The left column lists all questions that have been added to the current quiz.
* This column is only there if this page has been called in the context of a quiz.
* The lecturer can add questions from the right hand list to the quiz or remove them
*
* The script also processes a number of actions:
* Actions affecting a quiz:
* up and down Changes the order of questions and page breaks
* addquestion Adds a single question to the quiz
* add Adds several selected questions to the quiz
* addrandom Adds a certain number of random questions to the quiz
* delete Removes a question from the quiz
* savechanges Saves the order and grades for questions in the quiz
* repaginate Re-paginates the quiz
* 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
* TODO: add logging
*
* @version $Id$
* @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}
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package quiz
* @package question
*/
require_once("../../config.php");
require_once("../config.php");
require_once("editlib.php");
require_login();
$courseid = optional_param('courseid');
$quizid = optional_param('quizid');
$page = optional_param('page', -1);
$perpage = optional_param('perpage', 20);
$sortorder = optional_param('sortorder', 'qtype, name ASC');
if (preg_match("/[';]/", $sortorder)) {
error("Incorrect use of the parameter 'sortorder'");
}
$courseid = required_param('courseid', 0, PARAM_INT);
$strquizzes = get_string('modulenameplural', 'quiz');
$strquiz = get_string('modulename', 'quiz');
$streditingquestions = get_string('editquestions', "quiz");
$streditingquiz = get_string("editinga", "moodle", $strquiz);
if ($modform = data_submitted() and !empty($modform->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.
?>
<script type="text/javascript">
<!--
if (self.name == 'editquestion') {
self.close();
}
-->
</script>
<noscript>
<?php notify(get_string('pleaseclose', 'quiz')); ?>
</noscript>
<?php
// no quiz or course was specified so we need to use the stored modform
if (isset($SESSION->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 <br /> 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).'<br />';
}
}
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&amp;deleteselected=$questionlist&amp;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, '',
"<a href=\"index.php?id=$course->id\">$strquizzes</a>".
" -> <a href=\"view.php?q=$modform->instance\">".format_string($modform->name).'</a>'.
" -> $streditingquiz", "", "",
true, $strupdatemodule);
$streditingquestions = get_string('editquestions', "quiz");
print_header_simple($streditingquestions, '',
"$streditingquestions");
print_heading_with_help(get_string('questions', 'quiz'), 'questionbank');
echo '<table align="center" border="0" cellpadding="2" cellspacing="0">';
echo '<tr><td valign="top">';
$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 "<center>\n";
echo "$strattemptsexist<br /><a href=\"report.php?mode=overview&amp;id=$cm->id\">$strviewallanswers ($usercount $strusers)</a>";
echo "<form target=\"_parent\" method=\"get\" action=\"$CFG->wwwroot/mod/quiz/edit.php\">\n";
echo " <input type=\"hidden\" name=\"courseid\" value=\"$course->id\" />\n";
echo " <input type=\"submit\" value=\"".get_string("editcatquestions", "quiz")."\" />\n";
echo "</form>";
echo "</center><br/ >\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 '<table align="center" border="0" cellpadding="2" cellspacing="0">';
echo '<tr><td valign="top">';
} 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, '',
"<a href=\"index.php?id=$course->id\">$strquizzes</a>".
" -> <a href=\"view.php?q=$modform->instance\">".format_string($modform->name).'</a>'.
" -> $streditingquiz",
"", "", true, $strupdatemodule);
$currenttab = 'edit';
$mode = 'editq';
$quiz = &$modform;
include('tabs.php');
echo '<table border="0" width="100%" cellpadding="2" cellspacing="0">';
echo '<tr><td width="50%" valign="top">';
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 '</td><td valign="top" width="50%">';
}
// 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 '</td></tr>';
echo '</table>';
print_footer($course);
?>
+17 -335
View File
@@ -1,16 +1,19 @@
<?php // $Id$
/**
* Functions used by edit.php to edit quizzes
* Functions used by showbank.php to show question editing interface
*
* TODO: currently the function question_list still provides controls specific
* to the quiz module. This needs to be generalised.
*
* @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("locallib.php");
require_once($CFG->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 "<p align=\"center\">";
print_string("noquestions", "quiz");
echo "</p>";
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 "<p align=\"center\">";
print_string("noquestions", "quiz");
echo "</p>";
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 "<form method=\"post\" action=\"edit.php\">";
echo "<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
print_simple_box_start('center', '100%', '#ffffff', 0);
echo "<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\" width=\"100%\">\n";
echo "<tr><th colspan=\"3\" nowrap=\"nowrap\" class=\"header\">$strorder</th><th class=\"header\">#</th><th align=\"left\" width=\"100%\" nowrap=\"nowrap\" class=\"header\">$strquestionname</th><th nowrap=\"nowrap\" class=\"header\">$strtype</th><th nowrap=\"nowrap\" class=\"header\">$strgrade</th><th align=\"center\" width=\"60\" nowrap=\"nowrap\" class=\"header\">$straction</th></tr>\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 '<tr><td><input type="text" name="o'.$i.'" size="2" value="'.(10*$count+10).'" /></td>';
} else {
echo '<tr><td><input type="hidden" name="o'.$i.'" size="2" value="'.(10*$count+10).'" /></td>';
}
} else {
echo '<tr><td></td>';
}
if ($qnum == 0) { // This is a page break
if ($showbreaks) {
echo '<td colspan ="3">&nbsp;</td>';
echo '<td><table width="100%" style="line-height:11px; font-size:9px; margin: -5px -5px;"><tr>';
echo '<td><hr noshade="noshade" /></td>';
echo '<td width="50">Page break</td>';
echo '<td><hr noshade="noshade" /></td><td width="45">';
if ($count > 1) {
echo "<a title=\"$strmoveup\" href=\"edit.php?up=$count&amp;sesskey=$USER->sesskey\"><img
src=\"$CFG->pixpath/t/up.gif\" border=\"0\" alt=\"$strmoveup\" /></a>";
}
echo '&nbsp;';
if ($count < $lastindex) {
echo "<a title=\"$strmovedown\" href=\"edit.php?down=$count&amp;sesskey=$USER->sesskey\"><img
src=\"$CFG->pixpath/t/down.gif\" border=\"0\" alt=\"$strmovedown\" /></a>";
echo "<a title=\"$strremove\" href=\"edit.php?delete=$count&amp;sesskey=$USER->sesskey\">
<img src=\"$CFG->pixpath/t/delete.gif\" border=\"0\" alt=\"$strremove\" /></a>";
}
echo '</td></tr></table></td>';
echo '<td colspan="2">&nbsp;</td></tr>';
}
$count++;
continue;
}
$question = $questions[$qnum];
$canedit = isteacheredit($question->course);
echo "<td>";
if ($count != 0) {
echo "<a title=\"$strmoveup\" href=\"edit.php?up=$count&amp;sesskey=$USER->sesskey\"><img
src=\"$CFG->pixpath/t/up.gif\" border=\"0\" alt=\"$strmoveup\" /></a>";
}
echo "</td>";
echo "<td>";
if ($count < $lastindex-1) {
echo "<a title=\"$strmovedown\" href=\"edit.php?down=$count&amp;sesskey=$USER->sesskey\"><img
src=\"$CFG->pixpath/t/down.gif\" border=\"0\" alt=\"$strmovedown\" /></a>";
}
echo "</td>";
if (!$quiz->shufflequestions) {
// Print and increment question number
echo '<td>'.($question->length ? $qno : '&nbsp;').'</td>';
$qno += $question->length;
} else {
echo '<td>&nbsp;</td>';
}
echo "<td>$question->name</td>";
echo "<td align=\"center\">";
quiz_print_question_icon($question, $canedit);
echo "</td>";
echo '<td align="left">';
if ($question->qtype == DESCRIPTION) {
echo "<input type=\"hidden\" name=\"q$qnum\" value=\"0\" /> \n";
} else {
echo '<input type="text" name="q'.$qnum.'" size="2" value="'.$quiz->grades[$qnum].
'" tabindex="'.($lastindex+$qno).'" />';
}
echo '</td><td align="center">';
$context = $quiz->id ? '&amp;contextquiz='.$quiz->id : '';
$quiz_id = $quiz->id ? '&amp;quizid=' . $quiz->id : '';
echo "<a title=\"$strpreview\" href=\"javascript:void();\" onClick=\"openpopup('/mod/quiz/preview.php?id=$qnum$quiz_id','$strpreview','scrollbars=yes,resizable=yes,width=700,height=480', false)\">
<img src=\"$CFG->pixpath/t/preview.gif\" border=\"0\" alt=\"$strpreview\" /></a>";
if ($canedit) {
echo "<a title=\"$stredit\" href=\"question.php?id=$qnum$context\">
<img src=\"$CFG->pixpath/t/edit.gif\" border=\"0\" alt=\"$stredit\" /></a>";
}
if ($allowdelete) {
echo "<a title=\"$strremove\" href=\"edit.php?delete=$count&amp;sesskey=$USER->sesskey\">
<img src=\"$CFG->pixpath/t/removeright.gif\" border=\"0\" alt=\"$strremove\" /></a>";
}
echo "</td></tr>";
$count++;
$sumgrade += $quiz->grades[$qnum];
}
echo "<tr><td colspan=\"6\" align=\"right\">\n";
print_string('total');
echo ": <td align=\"left\">\n";
echo "<b>$sumgrade</b>";
echo "</td><td>&nbsp;\n</td></tr>\n";
echo "<tr><td colspan=\"6\" align=\"right\">\n";
print_string('maximumgrade');
echo ": <td align=\"left\">\n";
echo '<input type="text" name="maxgrade" size="2" tabindex="'.($qno+1)
.'" value="'.$quiz->grade.'" />';
echo '</td><td align="left">';
helpbutton("maxgrade", get_string("maximumgrade"), "quiz");
echo "</td></tr></table>\n";
echo '<div align="center"><input type="submit" value="'.get_string('savechanges').'" />';
echo '<input type="hidden" name="savechanges" value="save" /></div>';
print_simple_box_end();
echo "</form>\n";
/// Form to choose to show pagebreaks and to repaginate quiz
echo '<form method="post" action="edit.php" name="showbreaks">';
echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
echo '<input type="hidden" name="showbreaks" value="0" />';
echo '<input type="checkbox" name="showbreaks" value="1"';
if ($showbreaks) {
echo ' checked="checked"';
}
echo ' onchange="document.showbreaks.submit(); return true;" />';
print_string('showbreaks', 'quiz');
if ($showbreaks) {
$perpage= array();
for ($i=0; $i<=50; ++$i) {
$perpage[$i] = $i;
}
$perpage[0] = get_string('allinone', 'quiz');
echo '<br />&nbsp;&nbsp;';
print_string('repaginate', 'quiz',
choose_from_menu($perpage, 'questionsperpage', $quiz->questionsperpage, '', '', '', true));
}
echo '<br /><input type="hidden" name="reordertool" value="0" />';
echo '<input type="checkbox" name="reordertool" value="1"';
if ($reordertool) {
echo ' checked="checked"';
}
echo ' onchange="document.showbreaks.submit(); return true;" />';
print_string('reordertool', 'quiz');
helpbutton('reorderingtool', get_string('reorderingtool', 'quiz'), 'quiz');
echo '<div align="center"><input type="submit" name="repaginate" value="'. get_string('go') .'" /></div>';
echo '</form>';
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 "</td><td>";
popup_form ("edit.php?cat=", $catmenu, "catmenu", $current, "", "", "", false, "self");
echo "</td><td align=\"right\">";
echo "<form method=\"get\" action=\"category.php\">";
echo "<form method=\"get\" action=\"$CFG->wwwroot/question/category.php\">";
echo "<input type=\"hidden\" name=\"id\" value=\"$course->id\" />";
echo "<input type=\"submit\" value=\"$streditcats\" />";
echo "</form>";
@@ -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 "<td valign=\"top\"><b>$strcreatenewquestion:</b></td>";
echo '<td valign="top" align="right">';
popup_form ("question.php?category=$category->id&amp;qtype=", $QUIZ_QUESTION_TYPE, "addquestion",
popup_form ("$CFG->wwwroot/question/question.php?category=$category->id&amp;qtype=", $QUIZ_QUESTION_TYPE, "addquestion",
"", "choose", "", "", false, "self");
echo '</td><td width="10" valign="top" align="right">';
helpbutton("questiontypes", $strcreatenewquestion, "quiz");
@@ -497,11 +179,11 @@ function quiz_print_cat_question_list($course, $categoryid, $quizid,
echo '<tr><td colspan="3" align="right"><font size="2">';
if (isteacheredit($category->course)) {
echo '<a href="import.php?category='.$category->id.'">'.$strimportquestions.'</a>';
echo '<a href="'.$CFG->wwwroot.'/mod/quiz/import.php?category='.$category->id.'">'.$strimportquestions.'</a>';
helpbutton("import", $strimportquestions, "quiz");
echo ' | ';
}
echo "<a href=\"export.php?category={$category->id}&amp;courseid={$course->id}\">$strexportquestions</a>";
echo "<a href=\"$CFG->wwwroot/mod/quiz/export.php?category={$category->id}&amp;courseid={$course->id}\">$strexportquestions</a>";
helpbutton("export", $strexportquestions, "quiz");
echo '</font></td></tr>';
@@ -562,17 +244,17 @@ function quiz_print_cat_question_list($course, $categoryid, $quizid,
echo "<a title=\"$straddtoquiz\" href=\"edit.php?addquestion=$question->id&amp;sesskey=$USER->sesskey\"><img
src=\"$CFG->pixpath/t/moveleft.gif\" border=\"0\" alt=\"$straddtoquiz\" /></a>&nbsp;";
}
echo "<a title=\"$strpreview\" href=\"javascript:void();\" onClick=\"openpopup('/mod/quiz/preview.php?id=$question->id&quizid=$quizid','$strpreview','scrollbars=yes,resizable=yes,width=700,height=480', false)\"><img
echo "<a title=\"$strpreview\" href=\"javascript:void();\" onClick=\"openpopup('/question/preview.php?id=$question->id&quizid=$quizid','$strpreview','scrollbars=yes,resizable=yes,width=700,height=480', false)\"><img
src=\"$CFG->pixpath/t/preview.gif\" border=\"0\" alt=\"$strpreview\" /></a>&nbsp;";
if ($canedit) {
echo "<a title=\"$stredit\" href=\"question.php?id=$question->id\"><img
echo "<a title=\"$stredit\" href=\"$CFG->wwwroot/question/question.php?id=$question->id\"><img
src=\"$CFG->pixpath/t/edit.gif\" border=\"0\" alt=\"$stredit\" /></a>&nbsp;";
// hide-feature
if($question->hidden) {
echo "<a title=\"$strrestore\" href=\"question.php?id=$question->id&amp;hide=0&amp;sesskey=$USER->sesskey\"><img
echo "<a title=\"$strrestore\" href=\"$CFG->wwwroot/question/question.php?id=$question->id&amp;hide=0&amp;sesskey=$USER->sesskey\"><img
src=\"$CFG->pixpath/t/restore.gif\" border=\"0\" alt=\"$strrestore\" /></a>";
} else {
echo "<a title=\"$strdelete\" href=\"question.php?id=$question->id&amp;delete=$question->id\"><img
echo "<a title=\"$strdelete\" href=\"$CFG->wwwroot/question/question.php?id=$question->id&amp;delete=$question->id\"><img
src=\"$CFG->pixpath/t/delete.gif\" border=\"0\" alt=\"$strdelete\" /></a>";
}
}
+10 -6
View File
@@ -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 ? '&amp;quizid=' . $quizid : '';
redirect($CFG->wwwroot . '/mod/quiz/preview.php?id=' . $id . $quizid .
redirect($CFG->wwwroot . '/question/preview.php?id=' . $id . $quizid .
'&amp;continue=1');
}
+16 -8
View File
@@ -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 = '<a href="edit.php">'.get_string('editingquiz', 'quiz').'</a> -> '.
@@ -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;
@@ -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 **/
@@ -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();
}
@@ -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!');
@@ -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");
?>
require("$CFG->dirroot/question/questiontypes/datasetdependent/questiondatasets.html");
?>
@@ -1,6 +1,6 @@
<?php // $Id$
print_heading_with_help(get_string("editingdescription", "quiz"), "description", "quiz");
require("$CFG->dirroot/mod/quiz/questiontypes/description/description.html");
require("$CFG->dirroot/question/questiontypes/description/description.html");
?>
@@ -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 '<font size="1">';
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 '</font>';
}
@@ -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");
?>
@@ -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");
?>
@@ -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");
?>
@@ -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");
?>
@@ -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) {
@@ -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");
?>
@@ -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 {
+4 -4
View File
@@ -459,7 +459,7 @@ class quiz_default_questiontype {
if (isteacheredit($cmoptions->course)) {
$stredit = get_string('edit');
$linktext = '<img src="'.$CFG->pixpath.'/t/edit.gif" border="0" alt="'.$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) ? '<b>' : '';
$be = ($state->id == $st->id) ? '</b>' : '';
$table->data[] = array (
($state->id == $st->id) ? '<b>'.$st->seq_number.'</b>' : link_to_popup_window ('/mod/quiz/reviewquestion.php?state='.$st->id.'&amp;number='.$number, 'reviewquestion', $st->seq_number, 450, 650, $strreviewquestion, 'none', true),
($state->id == $st->id) ? '<b>'.$st->seq_number.'</b>' : link_to_popup_window ('/question/reviewquestion.php?state='.$st->id.'&amp;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
@@ -1,6 +1,6 @@
<?php // $Id$
print_heading_with_help(get_string("editingrandom", "quiz"), "random", "quiz");
require("$CFG->dirroot/mod/quiz/questiontypes/random/random.html");
require("$CFG->dirroot/question/questiontypes/random/random.html");
?>
@@ -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");
?>
@@ -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");
?>
@@ -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
@@ -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");
?>
@@ -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) {
+156
View File
@@ -0,0 +1,156 @@
<?php // $Id$
/**
* Shows the question bank editing interface. To be included by other pages
*
* The script 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
*
* @version $Id$
* @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}
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package question
*/
// Make sure this can only be used from within Moodle scripts
defined('MOODLE_INTERNAL') or die('Direct access to this script is forbidden.');
require_once($CFG->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 <br /> 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).'<br />';
}
}
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&amp;deleteselected=$questionlist&amp;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();
?>