Updated quiz scripts to work with the separate question scripts in moodle/question

This commit is contained in:
gustav_delius 2006-02-24 10:43:06 +00:00
parent e586cfb4b0
commit 80a5e194ff
15 changed files with 24 additions and 3194 deletions

View file

@ -1,126 +0,0 @@
<?php // $Id$
/**
* Allows a teacher to create, edit and delete 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 quiz
*/
require_once("../../config.php");
require_once("locallib.php");
require_once("category_class.php");
// get values from form
$param = new stdClass();
$id = required_param('id',PARAM_INT); // course id
$param->moveup = optional_param('moveup',0,PARAM_INT);
$param->movedown = optional_param('movedown',0,PARAM_INT);
$param->hide = optional_param('hide',0,PARAM_INT);
$param->delete = optional_param('delete',0,PARAM_INT);
$param->confirm = optional_param('confirm',0,PARAM_INT);
$param->cancel = optional_param('cancel','',PARAM_ALPHA);
$param->move = optional_param('move',0,PARAM_INT);
$param->moveto = optional_param('moveto',0,PARAM_INT);
$param->publish = optional_param('publish',0,PARAM_INT);
$param->addcategory = optional_param('addcategory','',PARAM_ALPHA);
$param->edit = optional_param('edit',0,PARAM_INT);
$param->updateid = optional_param('updateid',0,PARAM_INT);
$param->page = optional_param('page',1,PARAM_INT);
if (! $course = get_record("course", "id", $id)) {
error("Course ID is incorrect");
}
if (isset($_REQUEST['backtoquiz'])) {
redirect("edit.php");
}
require_login($course->id, false);
if (!isteacheredit($course->id)) {
error("Only teachers authorized to edit the course '{$course->fullname}' can use this page!");
}
$qcobject = new quiz_category_object();
$qcobject->set_course($course);
//==========
// PAGE HEADER
//==========
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>'.
' -> '.get_string('editcategories', 'quiz'),
"", "", true, $strupdatemodule);
$currenttab = 'edit';
$mode = 'categories';
include('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'));
}
//==========
// ACTIONS
//==========
if (isset($_REQUEST['sesskey']) and confirm_sesskey()) { // sesskey must be ok
if (!empty($param->delete) and empty($param->cancel)) {
if (!empty($param->confirm)) {
/// 'confirm' is the category to move existing questions to
$qcobject->delete_category($param->delete, $param->confirm);
} else {
$qcobject->delete_category($param->delete);
}
} else if (!empty($param->moveup)) {
$qcobject->move_category_up_down('up', $param->moveup);
} else if (!empty($param->movedown)) {
$qcobject->move_category_up_down('down', $param->movedown);
} else if (!empty($param->hide)) {
$qcobject->publish_category(false, $param->hide);
} else if (!empty($param->move) and !empty($param->moveto)) {
$qcobject->move_category($param->move, $param->moveto);
} else if (!empty($param->publish)) {
$qcobject->publish_category(true, $param->publish);
} else if (!empty($param->addcategory)) {
$param->newparent = required_param('newparent',PARAM_INT);
$param->newcategory = required_param('newcategory',PARAM_ALPHANUM);
$param->newinfo = required_param('newinfo',PARAM_CLEAN);
$param->newpublish = required_param('newpublish',PARAM_INT);
$qcobject->add_category($param->newparent, $param->newcategory, $param->newinfo,
$param->newpublish, $course->id);
} else if (!empty($param->edit)) {
$qcobject->edit_single_category($param->edit, $param->page);
} else if (!empty($param->updateid)) {
$param->updateparent = required_param('updateparent',PARAM_INT);
$param->updatename = required_param('updatename',PARAM_ALPHANUM);
$param->updateinfo = required_param('updateinfo',PARAM_CLEAN);
$param->updatepublish = required_param('updatepublish',PARAM_INT);
$qcobject->update_category($param->updateid, $param->updateparent, $param->updatename,
$param->updateinfo, $param->updatepublish, $course->id);
}
}
//==========
// DISPLAY
//==========
// display the user interface
$qcobject->display_user_interface($param->page);
print_footer($course);
?>

View file

@ -1,773 +0,0 @@
<? // $Id:
/**
* Class quiz_category_object
*
* Used for handling changes to the quiz categories
*
*/
// number of categories to display on page
define( "PAGE_LENGTH",25 );
class quiz_category_object {
var $str;
var $pixpath;
var $edittable;
var $newtable;
var $tab;
var $tabsize = 3;
var $categories;
var $categorystrings;
var $defaultcategory;
var $course;
var $topcount;
/**
* Constructor
*
* Gets necessary strings and sets relevant path information
*
*/
function quiz_category_object() {
global $CFG;
$this->tab = str_repeat('&nbsp;', $this->tabsize);
$this->str->course = get_string('course');
$this->str->category = get_string('category', 'quiz');
$this->str->categoryinfo = get_string('categoryinfo', 'quiz');
$this->str->questions = get_string('questions', 'quiz');
$this->str->add = get_string('add');
$this->str->delete = get_string('delete');
$this->str->moveup = get_string('moveup');
$this->str->movedown = get_string('movedown');
$this->str->edit = get_string('editthiscategory');
$this->str->hide = get_string('hide');
$this->str->publish = get_string('publish', 'quiz');
$this->str->order = get_string('order');
$this->str->parent = get_string('parent', 'quiz');
$this->str->add = get_string('add');
$this->str->action = get_string('action');
$this->str->top = get_string('top', 'quiz');
$this->str->addcategory = get_string('addcategory', 'quiz');
$this->str->editcategory = get_string('editcategory', 'quiz');
$this->str->cancel = get_string('cancel');
$this->str->editcategories = get_string('editcategories', 'quiz');
$this->str->page = get_string('page');
$this->pixpath = $CFG->pixpath;
}
/**
* Sets the course for this object
*
* @param object course
*/
function set_course($course) {
$this->course = $course;
}
/**
* Displays the user interface
*
* @param object modform
* @param int $page page number to display (0=don't paginate)
*/
function display_user_interface($page=0) {
$this->initialize();
/// Interface for adding a new category:
print_heading_with_help($this->str->addcategory, 'categories_edit', 'quiz');
$this->output_new_table();
echo '<br />';
/// Interface for editing existing categories
print_heading_with_help($this->str->editcategories, 'categories', 'quiz');
$this->output_edit_table($page);
if ($this->topcount>PAGE_LENGTH) {
$this->display_page_numbers($page);
}
echo '<br />';
}
/**
* Initializes this classes general category-related variables
*
*/
function initialize() {
/// Get the existing categories
if (!$this->defaultcategory = quiz_get_default_category($this->course->id)) {
error("Error: Could not find or make a category!");
}
$this->categories = $this->get_quiz_categories(null, "parent, sortorder, name ASC");
$this->categories = $this->arrange_categories($this->categories);
// create the array of id=>full_name strings
$this->categorystrings = $this->expanded_category_strings($this->categories);
// for pagination calculate number of 'top' categories and hence number of pages
// (pagination only based on top categories)
$count = 0;
foreach( $this->categories as $category ) {
if ($category->parent==0) {
++$count;
}
}
$this->topcount = $count;
$this->pagecount = (integer) ceil( $count / PAGE_LENGTH );
}
/**
* display list of page numbers for navigation
*/
function display_page_numbers( $page=0 ) {
global $USER;
echo "<div class=\"paging\">{$this->str->page}:\n";
foreach (range(1,$this->pagecount) as $currentpage) {
if ($page == $currentpage) {
echo " $currentpage \n";
}
else {
echo "<a href=\"category.php?id={$this->course->id}&amp;page=$currentpage&amp;sesskey={$USER->sesskey}\">";
echo " $currentpage </a>\n";
}
}
echo "</div>";
}
/**
* Outputs a table to allow entry of a new category
*
*/
function output_new_table() {
global $USER;
$publishoptions[0] = get_string("no");
$publishoptions[1] = get_string("yes");
$this->newtable->head = array ($this->str->parent, $this->str->category, $this->str->categoryinfo, $this->str->publish, $this->str->action);
$this->newtable->width = 200;
$this->newtable->data[] = array();
$this->newtable->tablealign = 'center';
/// Each section below adds a data cell to the table row
$viableparents[0] = $this->str->top;
$viableparents = $viableparents + $this->categorystrings;
$this->newtable->align['parent'] = "left";
$this->newtable->wrap['parent'] = "nowrap";
$row['parent'] = choose_from_menu ($viableparents, "newparent", $this->str->top, "", "", "", true);
$this->newtable->align['category'] = "left";
$this->newtable->wrap['category'] = "nowrap";
$row['category'] = '<input type="text" name="newcategory" value="" size="15" />';
$this->newtable->align['info'] = "left";
$this->newtable->wrap['info'] = "nowrap";
$row['info'] = '<input type="text" name="newinfo" value="" size="50" />';
$this->newtable->align['publish'] = "left";
$this->newtable->wrap['publish'] = "nowrap";
$row['publish'] = choose_from_menu ($publishoptions, "newpublish", "", "", "", "", true);
$this->newtable->align['action'] = "left";
$this->newtable->wrap['action'] = "nowrap";
$row['action'] = '<input type="submit" value="' . $this->str->add . '" />';
$this->newtable->data[] = $row;
// wrap the table in a form and output it
echo '<form action="category.php" method="post">';
echo "<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
echo '<input type="hidden" name="id" value="'. $this->course->id . '" />';
echo '<input type="hidden" name="addcategory" value="true" />';
print_table($this->newtable);
echo '</form>';
}
/**
* Outputs a table to allow editing/rearranging of existing categories
*
* $this->initialize() must have already been called
*
* @param object course
* @param int $page page to display (0=do not paginate)
*/
function output_edit_table($page=0) {
$this->edittable->head = array ($this->str->category, $this->str->categoryinfo, $this->str->questions, $this->str->publish,
$this->str->delete, $this->str->order, $this->str->parent);
$this->edittable->width = 200;
$this->edittable->tablealign = 'center';
$courses = $this->course->shortname;
// if pagination required work out range
if (!empty($page)) {
$firstcat = ($page-1) * PAGE_LENGTH + 1;
$lastcat = $firstcat + PAGE_LENGTH - 1;
}
else {
$firstcat = 1;
$lastcat = $this->topcount;
}
//echo "$firstcat $lastcat $page"; die;
$this->build_edit_table_body($this->categories, $page, $firstcat, $lastcat);
print_table($this->edittable);
}
/**
* Recursively builds up the edit-categories table body
*
* @param array categories contains category objects in a tree representation
* @param mixed courses String with shortname of course | array containing courseid=>shortname
* @param int depth controls the indenting
*/
function build_edit_table_body($categories, $page = 0, $firstcat = 1, $lastcat = 99999, $depth = 0) {
$countcats = count($categories);
$count = 0;
$first = true;
$last = false;
$topcount = 0;
foreach ($categories as $category) {
$count++;
if ($count == $countcats) {
$last = true;
}
// check if this category is on the display page
if ($depth==0) {
$topcount++;
if (($topcount<$firstcat) or ($topcount>$lastcat)) {
continue;
}
}
$up = $first ? false : true;
$down = $last ? false : true;
$first = false;
$this->quiz_edit_category_row($category, $depth, $up, $down, $page);
if (isset($category->children)) {
$this->build_edit_table_body($category->children, $page, $firstcat, $lastcat, $depth + 1);
}
}
}
/**
* gets all the courseids for the given categories
*
* @param array categories contains category objects in a tree representation
* @return array courseids flat array in form categoryid=>courseid
*/
function get_course_ids($categories) {
$courseids = array();
foreach ($categories as $key=>$cat) {
$courseids[$key] = $cat->course;
if (!empty($cat->children)) {
$courseids = array_merge($courseids, $this->get_course_ids($cat->children));
}
}
return $courseids;
}
/**
* Constructs each row of the edit-categories table
*
* @param object category
* @param int depth controls the indenting
* @param string shortname short name of the course
* @param boolean up can it be moved up?
* @param boolean down can it be moved down?
* @param int page page number
*/
function quiz_edit_category_row($category, $depth, $up = false, $down = false, $page = 0) {
global $USER;
$fill = str_repeat($this->tab, $depth);
$linkcss = $category->publish ? ' class="published"' : ' class="unpublished"';
if (!empty($page)) {
$pagelink="&amp;page=$page";
}
else {
$pagelink="";
}
/// Each section below adds a data cell to this table row
$this->edittable->align["$category->id.name"] = "left";
$this->edittable->wrap["$category->id.name"] = "nowrap";
$row["$category->id.name"] = '<a ' . $linkcss . 'title="' . $this->str->edit. '" href="category.php?id=' . $this->course->id .
'&amp;edit=' . $category->id . '&amp;sesskey='.$USER->sesskey.$pagelink.'"><img src="' . $this->pixpath . '/t/edit.gif" height="11" width="11" border="0"
alt="' .$this->str->edit. '" /> ' . $fill . $category->name . '</a>';
$this->edittable->align["$category->id.info"] = "left";
$this->edittable->wrap["$category->id.info"] = "nowrap";
$row["$category->id.info"] = '<a ' . $linkcss . 'title="' . $this->str->edit .'" href="category.php?id=' . $this->course->id .
'&amp;edit=' . $category->id . '&amp;sesskey='.$USER->sesskey.$pagelink.'">' . $category->info . '</a>';
$this->edittable->align["$category->id.qcount"] = "center";
$row["$category->id.qcount"] = $category->questioncount;
$this->edittable->align["$category->id.publish"] = "center";
$this->edittable->wrap["$category->id.publish"] = "nowrap";
if (!empty($category->publish)) {
$row["$category->id.publish"] = '<a title="' . $this->str->hide . '" href="category.php?id=' . $this->course->id . '&amp;hide=' . $category->id .
'&amp;sesskey='.$USER->sesskey.$pagelink.'"><img src="' . $this->pixpath . '/t/hide.gif" height="11" width="11" border="0" alt="' .$this->str->hide. '" /></a> ';
} else {
$row["$category->id.publish"] = '<a title="' . $this->str->publish . '" href="category.php?id=' . $this->course->id . '&amp;publish=' . $category->id .
'&amp;sesskey='.$USER->sesskey.$pagelink.'"><img src="' . $this->pixpath . '/t/show.gif" height="11" width="11" border="0" alt="' .$this->str->publish. '" /></a> ';
}
if ($category->id != $this->defaultcategory->id) {
$this->edittable->align["$category->id.delete"] = "center";
$this->edittable->wrap["$category->id.delete"] = "nowrap";
$row["$category->id.delete"] = '<a title="' . $this->str->delete . '" href="category.php?id=' . $this->course->id .
'&amp;delete=' . $category->id . '&amp;sesskey='.$USER->sesskey.$pagelink.'"><img src="' . $this->pixpath . '/t/delete.gif" height="11" width="11" border="0" alt="' .$this->str->delete. '" /></a> ';
} else {
$row["$category->id.delete"] = '';
}
$this->edittable->align["$category->id.order"] = "left";
$this->edittable->wrap["$category->id.order"] = "nowrap";
$icons = '';
if ($up) {
$icons .= '<a title="' . $this->str->moveup .'" href="category.php?id=' . $this->course->id . '&amp;moveup=' . $category->id . '&amp;sesskey='.$USER->sesskey.$pagelink.'">
<img src="' . $this->pixpath . '/t/up.gif" height="11" width="11" border="0" alt="' . $this->str->moveup. '" /></a> ';
}
if ($down) {
$icons .= '<a title="' . $this->str->movedown .'" href="category.php?id=' . $this->course->id . '&amp;movedown=' . $category->id . '&amp;sesskey='.$USER->sesskey.$pagelink.'">
<img src="' . $this->pixpath . '/t/down.gif" height="11" width="11" border="0" alt="' .$this->str->movedown. '" /></a> ';
}
$row["$category->id.order"]= $icons;
$this->edittable->align["$category->id.moveto"] = "left";
$this->edittable->wrap["$category->id.moveto"] = "nowrap";
if ($category->id != $this->defaultcategory->id) {
$viableparents = $this->categorystrings;
$this->set_viable_parents($viableparents, $category);
$viableparents = array(0=>$this->str->top) + $viableparents;
$row["$category->id.moveto"] = popup_form ("category.php?id={$this->course->id}&amp;move={$category->id}&amp;sesskey=$USER->sesskey$pagelink&amp;moveto=",
$viableparents, "moveform{$category->id}", "$category->parent", "", "", "", true);
} else {
$row["$category->id.moveto"]='---';
}
$this->edittable->data[$category->id] = $row;
}
function edit_single_category($categoryid,$page=1) {
/// Interface for adding a new category
global $USER;
$this->initialize();
/// Interface for editing existing categories
if ($category = get_record("quiz_categories", "id", $categoryid)) {
echo '<h2 align="center">';
echo $this->str->edit;
helpbutton("categories_edit", $this->str->editcategory, "quiz");
echo '</h2>';
echo '<table width="100%"><tr><td>';
$this->output_edit_single_table($category,$page);
echo '</td></tr></table>';
echo '<p><div align="center"><form action="category.php" method="get">
<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />
<input type="hidden" name="id" value="' . $this->course->id . '" />
<input type="submit" value="' . $this->str->cancel . '" /></form></div></p>';
print_footer($this->course);
exit;
} else {
error("Category $categoryid not found", "category.php?id={$this->course->id}");
}
}
/**
* Outputs a table to allow editing of an existing category
*
* @param object category
* @param int page current page
*/
function output_edit_single_table($category, $page=1) {
global $USER;
$publishoptions[0] = get_string("no");
$publishoptions[1] = get_string("yes");
$strupdate = get_string('update');
unset ($edittable);
$edittable->head = array ($this->str->parent, $this->str->category, $this->str->categoryinfo, $this->str->publish, $this->str->action);
$edittable->width = 200;
$edittable->data[] = array();
$edittable->tablealign = 'center';
/// Each section below adds a data cell to the table row
$viableparents = $this->categorystrings;
$this->set_viable_parents($viableparents, $category);
$viableparents = array(0=>$this->str->top) + $viableparents;
$edittable->align['parent'] = "left";
$edittable->wrap['parent'] = "nowrap";
$row['parent'] = choose_from_menu ($viableparents, "updateparent", "{$category->parent}", "", "", "", true);
$edittable->align['category'] = "left";
$edittable->wrap['category'] = "nowrap";
$row['category'] = '<input type="text" name="updatename" value="' . $category->name . '" size="15" />';
$edittable->align['info'] = "left";
$edittable->wrap['info'] = "nowrap";
$row['info'] = '<input type="text" name="updateinfo" value="' . $category->info . '" size="50" />';
$edittable->align['publish'] = "left";
$edittable->wrap['publish'] = "nowrap";
$selected = (boolean)$category->publish ? 1 : 0;
$row['publish'] = choose_from_menu ($publishoptions, "updatepublish", $selected, "", "", "", true);
$edittable->align['action'] = "left";
$edittable->wrap['action'] = "nowrap";
$row['action'] = '<input type="submit" value="' . $strupdate . '" />';
$edittable->data[] = $row;
// wrap the table in a form and output it
echo '<p><form action="category.php" method="post">';
echo "<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
echo '<input type="hidden" name="id" value="'. $this->course->id . '" />';
echo '<input type="hidden" name="updateid" value="' . $category->id . '" />';
echo "<input type=\"hidden\" name=\"page\" value=\"$page\" />";
print_table($edittable);
echo '</form></p>';
}
/**
* Creates an array of "full-path" category strings
* Structure:
* key => string
* where key is the category id, and string contains the name of all ancestors as well as the particular category name
* E.g. '123'=>'Language / English / Grammar / Modal Verbs"
*
* @param array $categories an array containing categories arranged in a tree structure
*/
function expanded_category_strings($categories, $parent=null) {
$prefix = is_null($parent) ? '' : "$parent / ";
$categorystrings = array();
foreach ($categories as $key => $category) {
$expandedname = "$prefix$category->name";
$categorystrings[$key] = $expandedname;
if (isset($category->children)) {
$categorystrings = $categorystrings + $this->expanded_category_strings($category->children, $expandedname);
}
}
return $categorystrings;
}
/**
* Arranges the categories into a hierarchical tree
*
* If a category has children, it's "children" property holds an array of children
* The questioncount for each category is also calculated
*
* @param array records a flat list of the categories
* @return array categorytree a hierarchical list of the categories
*/
function arrange_categories($records) {
//todo: get the question count for all records with one sql statement: select category, count(*) from quiz_questions group by category
$levels = array();
// build a levels array, which places each record according to it's depth from the top level
$parents = array(0);
while (!empty($parents)) {
$children = array();
foreach ($records as $record) {
if (in_array($record->parent, $parents)) {
$children[] = $record->id;
}
}
if (!empty($children)) {
$levels[] = $children;
}
$parents = $children;
}
// if there is no hierarchy (e.g., if all records have parent == 0), set level[0] to these keys
if (empty($levels)) {
$levels[0] = array_keys($records);
}
// build a hierarchical array that depicts the parent-child relationships of the categories
$categorytree = array();
for ($index = count($levels) - 1; $index >= 0; $index--) {
foreach($levels[$index] as $key) {
$parentkey = $records[$key]->parent;
if (!($records[$key]->questioncount = count_records('quiz_questions', 'category', $records[$key]->id, 'hidden', 0, 'parent', '0'))) {
$records[$key]->questioncount = 0;
}
if ($parentkey == 0) {
$categorytree[$key] = $records[$key];
} else {
$records[$parentkey]->children[$key] = $records[$key];
}
}
}
return $categorytree;
}
/**
* Sets the viable parents
*
* Viable parents are any except for the category itself, or any of it's descendants
* The parentstrings parameter is passed by reference and changed by this function.
*
* @param array parentstrings a list of parentstrings
* @param object category
*/
function set_viable_parents(&$parentstrings, $category) {
unset($parentstrings[$category->id]);
if (isset($category->children)) {
foreach ($category->children as $child) {
$this->set_viable_parents($parentstrings, $child);
}
}
}
/**
* Gets quiz categories
*
* @param int parent - if given, restrict records to those with this parent id.
* @param string sort - [[sortfield [,sortfield]] {ASC|DESC}]
* @return array categories
*/
function get_quiz_categories($parent=null, $sort="sortorder ASC") {
if (is_null($parent)) {
$categories = get_records('quiz_categories', 'course', "{$this->course->id}", $sort);
} else {
$select = "parent = '$parent' AND course = '{$this->course->id}'";
$categories = get_records_select('quiz_categories', $select, $sort);
}
return $categories;
}
/**
* Deletes an existing quiz category
*
* @param int deletecat id of category to delete
* @param int destcategoryid id of category which will inherit the orphans of deletecat
*/
function delete_category($deletecat, $destcategoryid = null) {
global $USER;
if (!$category = get_record("quiz_categories", "id", $deletecat)) { // security
error("No such category $deletecat!", "category.php?id={$this->course->id}");
}
if (!is_null($destcategoryid)) { // Need to move some questions before deleting the category
if (!$category2 = get_record("quiz_categories", "id", $destcategoryid)) { // security
error("No such category $destcategoryid!", "category.php?id={$this->course->id}");
}
if (! set_field('quiz_questions', 'category', $category2, 'category', $category1)) {
error("Error while moving questions from category '$category->name' to '$category2->name'", "category.php?id={$this->course->id}");
}
} else {
// todo: delete any hidden questions that are not actually in use any more
if ($count = count_records("quiz_questions", "category", $category->id)) {
$vars->name = $category->name;
$vars->count = $count;
print_simple_box(get_string("categorymove", "quiz", $vars), "center");
$this->initialize();
$categorystrings = $this->categorystrings;
unset ($categorystrings[$category->id]);
echo "<p><div align=\"center\"><form action=\"category.php\" method=\"get\">";
echo "<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
echo "<input type=\"hidden\" name=\"id\" value=\"{$this->course->id}\" />";
echo "<input type=\"hidden\" name=\"delete\" value=\"$category->id\" />";
choose_from_menu($categorystrings, "confirm", "", "");
echo "<input type=\"submit\" value=\"". get_string("categorymoveto", "quiz") . "\" />";
echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->str->cancel}\" />";
echo "</form></div></p>";
print_footer($this->course);
exit;
}
}
delete_records("quiz_categories", "id", $category->id);
/// Send the children categories to live with their grandparent
if ($childcats = get_records("quiz_categories", "parent", $category->id)) {
foreach ($childcats as $childcat) {
if (! set_field("quiz_categories", "parent", $category->parent, "id", $childcat->id)) {
error("Could not update a child category!", "category.php?id={$this->course->id}");
}
}
}
/// Finally delete the category itself
if (delete_records("quiz_categories", "id", $category->id)) {
notify(get_string("categorydeleted", "quiz", $category->name), 'green');
}
}
/**
* Moves a category up or down in the display order
*
* @param string direction up|down
* @param int categoryid id of category to move
*/
function move_category_up_down ($direction, $categoryid) {
/// Move a category up or down
$swapcategory = NULL;
$movecategory = NULL;
if ($direction == 'up') {
if ($movecategory = get_record("quiz_categories", "id", $categoryid)) {
$categories = $this->get_quiz_categories("$movecategory->parent", 'parent, sortorder, name');
foreach ($categories as $category) {
if ($category->id == $movecategory->id) {
break;
}
$swapcategory = $category;
}
}
}
if ($direction == 'down') {
if ($movecategory = get_record("quiz_categories", "id", $categoryid)) {
$categories = $this->get_quiz_categories("$movecategory->parent", 'parent, sortorder, name');
$choosenext = false;
foreach ($categories as $category) {
if ($choosenext) {
$swapcategory = $category;
break;
}
if ($category->id == $movecategory->id) {
$choosenext = true;
}
}
}
}
if ($swapcategory and $movecategory) { // Renumber everything for robustness
$count=0;
foreach ($categories as $category) {
$count++;
if ($category->id == $swapcategory->id) {
$category = $movecategory;
} else if ($category->id == $movecategory->id) {
$category = $swapcategory;
}
if (! set_field("quiz_categories", "sortorder", $count, "id", $category->id)) {
notify("Could not update that category!");
}
}
}
}
/**
* Changes the parent of a category
*
* @param int categoryid
* @param int parentid
*/
function move_category($categoryid, $parentid) {
/// Move a category to a new parent
if ($tempcat = get_record("quiz_categories", "id", $categoryid)) {
if ($tempcat->parent != $parentid) {
if (! set_field("quiz_categories", "parent", $parentid, "id", $tempcat->id)) {
notify("Could not update that category!");
}
}
}
}
/**
* Changes the published status of a category
*
* @param boolean publish
* @param int categoryid
*/
function publish_category($publish, $categoryid) {
/// Hide or publish a category
$publish = ($publish == false) ? 0 : 1;
$tempcat = get_record("quiz_categories", "id", $categoryid);
if ($tempcat) {
if (! set_field("quiz_categories", "publish", $publish, "id", $tempcat->id)) {
notify("Could not update that category!");
}
}
}
/**
* Creates a new category with given params
*
* @param int $newparent id of the parent category
* @param string $newcategory the name for the new category
* @param string $newinfo the info field for the new category
* @param int $newpublish whether to publish the category
* @param int $newcourse the id of the associated course
*/
function add_category($newparent, $newcategory, $newinfo, $newpublish, $newcourse) {
if ($newparent) {
// first check that the parent category is in the correct course
if(!(get_field('quiz_categories', 'course', 'id', $newparent) == $newcourse)) {
return false;
}
}
$cat = NULL;
$cat->parent = $newparent;
$cat->name = $newcategory;
$cat->info = $newinfo;
$cat->publish = $newpublish;
$cat->course = $newcourse;
$cat->sortorder = 999;
$cat->stamp = make_unique_id_code();
if (!insert_record("quiz_categories", $cat)) {
error("Could not insert the new quiz category '$newcategory'", "category.php?id={$newcourse}");
} else {
notify(get_string("categoryadded", "quiz", $newcategory), 'green');
}
}
/**
* Updates an existing category with given params
*
* @param int updateid
* @param int updateparent
* @param string updatename
* @param string updateinfo
* @param int updatepublish
* @param int courseid the id of the associated course
*/
function update_category($updateid, $updateparent, $updatename, $updateinfo, $updatepublish, $courseid) {
$cat = NULL;
$cat->id = $updateid;
$cat->parent = $updateparent;
$cat->name = $updatename;
$cat->info = $updateinfo;
$cat->publish = $updatepublish;
if (!update_record("quiz_categories", $cat)) {
error("Could not update the category '$updatename'", "category.php?id={$courseid}");
} else {
notify(get_string("categoryupdated", 'quiz'), 'green');
}
}
}
?>

View file

@ -64,43 +64,6 @@ define('QUIZ_REVIEW_SOLUTIONS', 16*4161); // Show solutions
// the 6th bit is as yet unused // the 6th bit is as yet unused
/**#@-*/ /**#@-*/
/**#@+
* The different types of events that can create question states
*/
define('QUIZ_EVENTOPEN', '0');
define('QUIZ_EVENTNAVIGATE', '1');
define('QUIZ_EVENTSAVE', '2');
define('QUIZ_EVENTGRADE', '3');
define('QUIZ_EVENTDUPLICATEGRADE', '4');
define('QUIZ_EVENTVALIDATE', '5');
define('QUIZ_EVENTCLOSE', '6');
define('QUIZ_EVENTSUBMIT', '7');
/**#@-*/
/**#@+
* The defined question types
*
* @todo It would be nicer to have a fully automatic plug-in system
*/
define("SHORTANSWER", "1");
define("TRUEFALSE", "2");
define("MULTICHOICE", "3");
define("RANDOM", "4");
define("MATCH", "5");
define("RANDOMSAMATCH", "6");
define("DESCRIPTION", "7");
define("NUMERICAL", "8");
define("MULTIANSWER", "9");
define("CALCULATED", "10");
define("RQP", "11");
define("ESSAY", "12");
/**#@-*/
define("QUIZ_MAX_NUMBER_ANSWERS", "10");
define("QUIZ_CATEGORIES_SORTORDER", "999");
/** /**
* If start and end date for the quiz are more than this many seconds apart * If start and end date for the quiz are more than this many seconds apart
* they will be represented by two separate events in the calendar * they will be represented by two separate events in the calendar

View file

@ -34,18 +34,12 @@
* @package quiz * @package quiz
*/ */
require_once("../../config.php"); require_once("../../config.php");
require_once("editlib.php"); require_once($CFG->dirroot.'/mod/quiz/editlib.php');
require_login(); require_login();
$courseid = optional_param('courseid'); $courseid = optional_param('courseid');
$quizid = optional_param('quizid'); $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'");
}
$strquizzes = get_string('modulenameplural', 'quiz'); $strquizzes = get_string('modulenameplural', 'quiz');
$strquiz = get_string('modulename', 'quiz'); $strquiz = get_string('modulename', 'quiz');
@ -129,12 +123,6 @@ if (self.name == 'editquestion') {
$modform->grades = quiz_get_all_question_grades($modform); $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 /// 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 if (isset($_REQUEST['up']) and confirm_sesskey()) { /// Move the given question up a slot
@ -250,86 +238,10 @@ if (self.name == 'editquestion') {
} }
} }
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 if (isset($_REQUEST['delete']) and confirm_sesskey()) { /// Remove a question from the quiz
quiz_delete_quiz_question($_REQUEST['delete'], $modform); quiz_delete_quiz_question($_REQUEST['delete'], $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()) { if (isset($_REQUEST['savechanges']) and confirm_sesskey()) {
/// We need to save the new ordering (if given) and the new grades /// We need to save the new ordering (if given) and the new grades
$oldquestions = explode(",", $modform->questions); // the questions in the old order $oldquestions = explode(",", $modform->questions); // the questions in the old order
@ -371,22 +283,10 @@ if (self.name == 'editquestion') {
} }
} }
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'])) { if(isset($_REQUEST['showbreaks'])) {
$SESSION->quiz_showbreaks = optional_param('showbreaks', 0, PARAM_BOOL); $SESSION->quiz_showbreaks = optional_param('showbreaks', 0, PARAM_BOOL);
$SESSION->quiz_reordertool = optional_param('reordertool', 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 /// 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'])) { 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'])) {
@ -399,12 +299,6 @@ if (self.name == 'editquestion') {
$category = quiz_get_default_category($course->id); $category = quiz_get_default_category($course->id);
$modform->category = $category->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)) { if (!isset($SESSION->quiz_showbreaks)) {
$SESSION->quiz_showbreaks = ($CFG->quiz_questionsperpage < 2) ? 0 : 1; $SESSION->quiz_showbreaks = ($CFG->quiz_questionsperpage < 2) ? 0 : 1;
} }
@ -498,18 +392,7 @@ if (self.name == 'editquestion') {
echo '</td><td valign="top" width="50%">'; echo '</td><td valign="top" width="50%">';
} }
// non-quiz-specific column require($CFG->dirroot.'/question/showbank.php');
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();
echo '</td></tr>'; echo '</td></tr>';
echo '</table>'; echo '</table>';

View file

@ -12,33 +12,6 @@
require_once("locallib.php"); require_once("locallib.php");
/**
* Array of question types names translated to the user's language
*
* The $QUIZ_QUESTION_TYPE array holds the names of all the question types that the user should
* be able to create directly. Some internal question types like random questions are excluded.
* The complete list of question types can be found in {@link $QUIZ_QTYPES}.
*/
$QUIZ_QUESTION_TYPE = array ( MULTICHOICE => get_string("multichoice", "quiz"),
TRUEFALSE => get_string("truefalse", "quiz"),
SHORTANSWER => get_string("shortanswer", "quiz"),
NUMERICAL => get_string("numerical", "quiz"),
CALCULATED => get_string("calculated", "quiz"),
MATCH => get_string("match", "quiz"),
DESCRIPTION => get_string("description", "quiz"),
RANDOMSAMATCH => get_string("randomsamatch", "quiz"),
MULTIANSWER => get_string("multianswer", "quiz"),
ESSAY => get_string("essay", "quiz")
);
// add remote question types
if ($rqp_types = get_records('quiz_rqp_types')) {
foreach($rqp_types as $type) {
$QUIZ_QUESTION_TYPE[100+$type->id] = $type->name;
}
}
/** /**
* Delete a question from a quiz * Delete a question from a quiz
* *
@ -286,10 +259,10 @@ function quiz_print_question_list($quiz, $allowdelete=true, $showbreaks=true, $r
$context = $quiz->id ? '&amp;contextquiz='.$quiz->id : ''; $context = $quiz->id ? '&amp;contextquiz='.$quiz->id : '';
$quiz_id = $quiz->id ? '&amp;quizid=' . $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)\"> echo "<a title=\"$strpreview\" href=\"javascript:void();\" onClick=\"openpopup('/question/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>"; <img src=\"$CFG->pixpath/t/preview.gif\" border=\"0\" alt=\"$strpreview\" /></a>";
if ($canedit) { if ($canedit) {
echo "<a title=\"$stredit\" href=\"question.php?id=$qnum$context\"> echo "<a title=\"$stredit\" href=\"$CFG->wwwroot/question/question.php?id=$qnum$context\">
<img src=\"$CFG->pixpath/t/edit.gif\" border=\"0\" alt=\"$stredit\" /></a>"; <img src=\"$CFG->pixpath/t/edit.gif\" border=\"0\" alt=\"$stredit\" /></a>";
} }
if ($allowdelete) { if ($allowdelete) {
@ -360,269 +333,4 @@ function quiz_print_question_list($quiz, $allowdelete=true, $showbreaks=true, $r
return $sumgrade; return $sumgrade;
} }
function quiz_print_category_form($course, $current, $recurse=1, $showhidden=false) {
/// Prints a form to choose categories
/// Make sure the default category exists for this course
if (!$categories = get_records("quiz_categories", "course", $course->id, "id ASC")) {
if (!$category = quiz_get_default_category($course->id)) {
notify("Error creating a default category!");
}
}
/// Get all the existing categories now
if (!$categories = get_records_select("quiz_categories", "course = '{$course->id}' OR publish = '1'", "parent, sortorder, name ASC")) {
notify("Could not find any question categories!");
return false; // Something is really wrong
}
$categories = add_indented_names($categories);
foreach ($categories as $key => $category) {
if ($catcourse = get_record("course", "id", $category->course)) {
if ($category->publish && $category->course != $course->id) {
$category->indentedname .= " ($catcourse->shortname)";
}
$catmenu[$category->id] = $category->indentedname;
}
}
$strcategory = get_string("category", "quiz");
$strshow = get_string("show", "quiz");
$streditcats = get_string("editcategories", "quiz");
echo "<table width=\"100%\"><tr><td width=\"20\" nowrap=\"nowrap\">";
echo "<b>$strcategory:</b>&nbsp;";
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 "<input type=\"hidden\" name=\"id\" value=\"$course->id\" />";
echo "<input type=\"submit\" value=\"$streditcats\" />";
echo "</form>";
echo '</td></tr></table>';
echo '<form method="post" action="edit.php" name="displayoptions">';
echo '<table><tr><td>';
echo '<input type="hidden" name="recurse" value="0" />';
echo '<input type="checkbox" name="recurse" value="1"';
if ($recurse) {
echo ' checked="checked"';
}
echo ' onchange="document.displayoptions.submit(); return true;" />';
print_string('recurse', 'quiz');
// hide-feature
echo '<br />';
echo '<input type="hidden" name="showhidden" value="0" />';
echo '<input type="checkbox" name="showhidden"';
if ($showhidden) {
echo ' checked="checked"';
}
echo ' onchange="document.displayoptions.submit(); return true;" />';
print_string('showhidden', 'quiz');
echo '</td><noscript><td valign="center">';
echo ' <input type="submit" value="'. get_string('go') .'" />';
echo '</td></noscript></tr></table></form>';
}
/**
* Prints the table of questions in a category with interactions
*
* @param object $course The course object
* @param int $categoryid The id of the question category to be displayed
* @param int $quizid The quiz id if we are in the context of a particular quiz, 0 otherwise
* @param int $recurse This is 1 if subcategories should be included, 0 otherwise
* @param int $page The number of the page to be displayed
* @param int $perpage Number of questions to show per page
* @param boolean $showhidden True if also hidden questions should be displayed
*/
function quiz_print_cat_question_list($course, $categoryid, $quizid,
$recurse=1, $page, $perpage, $showhidden=false, $sortorder='qtype, name ASC') {
global $QUIZ_QUESTION_TYPE, $USER, $CFG;
$strcategory = get_string("category", "quiz");
$strquestion = get_string("question", "quiz");
$straddquestions = get_string("addquestions", "quiz");
$strimportquestions = get_string("importquestions", "quiz");
$strexportquestions = get_string("exportquestions", "quiz");
$strnoquestions = get_string("noquestions", "quiz");
$strselect = get_string("select", "quiz");
$strselectall = get_string("selectall", "quiz");
$strselectnone = get_string("selectnone", "quiz");
$strcreatenewquestion = get_string("createnewquestion", "quiz");
$strquestionname = get_string("questionname", "quiz");
$strdelete = get_string("delete");
$stredit = get_string("edit");
$straction = get_string("action");
$strrestore = get_string('restore');
$straddtoquiz = get_string("addtoquiz", "quiz");
$strtype = get_string("type", "quiz");
$strcreatemultiple = get_string("createmultiple", "quiz");
$strpreview = get_string("preview","quiz");
if (!$categoryid) {
echo "<p align=\"center\"><b>";
print_string("selectcategoryabove", "quiz");
echo "</b></p>";
if ($quizid) {
echo "<p>";
print_string("addingquestions", "quiz");
echo "</p>";
}
return;
}
if (!$category = get_record("quiz_categories", "id", "$categoryid")) {
notify("Category not found!");
return;
}
echo "<center>";
echo format_text($category->info, FORMAT_MOODLE);
echo '<table><tr>';
// check if editing of this category is allowed
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",
"", "choose", "", "", false, "self");
echo '</td><td width="10" valign="top" align="right">';
helpbutton("questiontypes", $strcreatenewquestion, "quiz");
echo '</td></tr>';
}
else {
echo '<tr><td>';
print_string("publishedit","quiz");
echo '</td></tr>';
}
echo '<tr><td colspan="3" align="right"><font size="2">';
if (isteacheredit($category->course)) {
echo '<a href="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>";
helpbutton("export", $strexportquestions, "quiz");
echo '</font></td></tr>';
echo '</table>';
echo '</center>';
$categorylist = ($recurse) ? quiz_categorylist($category->id) : $category->id;
// hide-feature
$showhidden = $showhidden ? '' : " AND hidden = '0'";
if (!$totalnumber = count_records_select('quiz_questions', "category IN ($categorylist) AND parent = '0' $showhidden")) {
echo "<p align=\"center\">";
print_string("noquestions", "quiz");
echo "</p>";
return;
}
if (!$questions = get_records_select('quiz_questions', "category IN ($categorylist) AND parent = '0' $showhidden", $sortorder, '*', $page*$perpage, $perpage)) {
// There are no questions on the requested page.
$page = 0;
if (!$questions = get_records_select('quiz_questions', "category IN ($categorylist) AND parent = '0' $showhidden", $sortorder, '*', 0, $perpage)) {
// There are no questions at all
echo "<p align=\"center\">";
print_string("noquestions", "quiz");
echo "</p>";
return;
}
}
print_paging_bar($totalnumber, $page, $perpage,
"edit.php?perpage=$perpage&amp;");
$canedit = isteacheredit($category->course);
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 id="categoryquestions" cellspacing="0"><tr>';
$actionwidth = $canedit ? 95 : 70;
echo "<th width=\"$actionwidth\" nowrap=\"nowrap\" class=\"header\">$straction</th>";
$sortoptions = array('name, qtype ASC' => get_string("sortalpha", "quiz"),
'qtype, name ASC' => get_string("sorttypealpha", "quiz"),
'id ASC' => get_string("sortage", "quiz"));
$orderselect = choose_from_menu ($sortoptions, 'sortorder', $sortorder, false, 'this.form.submit();', '0', true);
$orderselect .= '<noscript><input type="submit" value="'.get_string("sortsubmit", "quiz").'" /></noscript>';
echo "<th width=\"100%\" align=\"left\" nowrap=\"nowrap\" class=\"header\">$strquestionname $orderselect</th>
<th nowrap=\"nowrap\" class=\"header\">$strtype</th>";
echo "</tr>\n";
foreach ($questions as $question) {
if ($question->qtype == RANDOM) {
//continue;
}
echo "<tr>\n<td nowrap=\"nowrap\">\n";
if ($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
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
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
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
src=\"$CFG->pixpath/t/delete.gif\" border=\"0\" alt=\"$strdelete\" /></a>";
}
}
echo "&nbsp;<input title=\"$strselect\" type=\"checkbox\" name=\"q$question->id\" value=\"1\" />";
echo "</td>\n";
if ($question->hidden) {
echo '<td class="dimmed_text">'.$question->name."</td>\n";
} else {
echo "<td>".$question->name."</td>\n";
}
echo "<td align=\"center\">\n";
quiz_print_question_icon($question, $canedit);
echo "</td>\n";
echo "</tr>\n";
}
echo '<tr><td colspan="3">';
print_paging_bar($totalnumber, $page, $perpage, "edit.php?perpage=$perpage&amp;");
echo "</td></tr></table>\n";
print_simple_box_end();
echo '<table class="quiz-edit-selected"><tr><td colspan="2">';
echo '<a href="javascript:select_all_in(\'TABLE\', null, \'categoryquestions\');">'.$strselectall.'</a> /'.
' <a href="javascript:deselect_all_in(\'TABLE\', null, \'categoryquestions\');">'.$strselectnone.'</a>'.
'</td><td align="right"><b>&nbsp;'.get_string('withselected', 'quiz').':</b></td></tr><tr><td>';
if ($quizid) {
echo "<input type=\"submit\" name=\"add\" value=\"<< $straddtoquiz\" />\n";
echo '</td><td>';
}
if ($canedit) {
echo '<input type="submit" name="deleteselected" value="'.$strdelete."\" /></td><td>\n";
echo '<input type="submit" name="move" value="'.get_string('moveto', 'quiz')."\" />\n";
quiz_category_select_menu($course->id, false, true, $category->id);
}
echo "</td></tr></table>";
if ($quizid) {
for ($i=1;$i<=10; $i++) {
$randomcount[$i] = $i;
}
echo '<br />';
print_string('addrandom', 'quiz',
choose_from_menu($randomcount, 'randomcount', '1', '', '', '', true));
echo '<input type="hidden" name="recurse" value="'.$recurse.'" />';
echo "<input type=\"hidden\" name=\"categoryid\" value=\"$category->id\" />";
echo ' <input type="submit" name="addrandom" value="'. get_string('add') .'" />';
helpbutton('random', get_string('random', 'quiz'), 'quiz');
}
echo "</form>\n";
}
?> ?>

View file

@ -11,7 +11,7 @@
require_once("../../config.php"); require_once("../../config.php");
require_once("locallib.php"); // TODO: this should not need locallib.php require_once("locallib.php"); // TODO: this should not need locallib.php
require_once('questionlib.php'); require_once($CFG->libdir.'/questionlib.php');
$categoryid = optional_param('category',0, PARAM_INT); $categoryid = optional_param('category',0, PARAM_INT);
$courseid = required_param('courseid',PARAM_INT); $courseid = required_param('courseid',PARAM_INT);
@ -70,8 +70,7 @@
include('tabs.php'); include('tabs.php');
} else { } else {
print_header_simple($strexportquestions, '', print_header_simple($strexportquestions, '',
"<a href=\"index.php?id=$course->id\">".get_string('modulenameplural', 'quiz').'</a>'. '<a href="edit.php">'.get_string('editquestions', 'quiz').'</a>'.
'-> <a href="edit.php">'.get_string('editquestions', 'quiz').'</a>'.
' -> '.$strexportquestions); ' -> '.$strexportquestions);
} }

View file

@ -11,7 +11,7 @@
require_once("../../config.php"); require_once("../../config.php");
require_once("locallib.php"); // TODO: this should not need locallib.php require_once("locallib.php"); // TODO: this should not need locallib.php
require_once('questionlib.php'); require_once($CFG->libdir.'/questionlib.php');
$categoryid = optional_param('category', 0, PARAM_INT); $categoryid = optional_param('category', 0, PARAM_INT);
$courseid = optional_param('course', 0, PARAM_INT); $courseid = optional_param('course', 0, PARAM_INT);

View file

@ -20,7 +20,7 @@
* Include those library functions that are also used by core Moodle or other modules * Include those library functions that are also used by core Moodle or other modules
*/ */
require_once("$CFG->dirroot/mod/quiz/lib.php"); require_once("$CFG->dirroot/mod/quiz/lib.php");
require_once("$CFG->dirroot/mod/quiz/questionlib.php"); require_once($CFG->libdir.'/questionlib.php');
/// CONSTANTS /////////////////////////////////////////////////////////////////// /// CONSTANTS ///////////////////////////////////////////////////////////////////
@ -491,7 +491,7 @@ function quiz_get_question_review($quiz, $question) {
$strpreview = get_string('previewquestion', 'quiz'); $strpreview = get_string('previewquestion', 'quiz');
$context = $quiz->id ? '&amp;contextquiz='.$quiz->id : ''; $context = $quiz->id ? '&amp;contextquiz='.$quiz->id : '';
$quiz_id = $quiz->id ? '&amp;quizid=' . $quiz->id : ''; $quiz_id = $quiz->id ? '&amp;quizid=' . $quiz->id : '';
return "<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)\"> return "<a title=\"$strpreview\" href=\"javascript:void();\" onClick=\"openpopup('/question/preview.php?id=$qnum$quiz_id','$strpreview','scrollbars=yes,resizable=yes,width=700,height=480', false)\">
<img src=\"../../pix/t/preview.gif\" border=\"0\" alt=\"$strpreview\" /></a>"; <img src=\"../../pix/t/preview.gif\" border=\"0\" alt=\"$strpreview\" /></a>";
} }

View file

@ -1,229 +0,0 @@
<?php // $Id$
/**
* 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
* information is stored in the session as an array of subsequent states rather
* than in the database.
* @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
*/
require_once("../../config.php");
require_once("locallib.php");
$id = required_param('id', PARAM_INT); // question id
// if no quiz id is specified then a dummy quiz with default options is used
$quizid = optional_param('quizid', 0, PARAM_INT);
// Test if we are continuing an attempt at a question
$continue = optional_param('continue', 0, PARAM_BOOL);
// Check for any of the submit buttons
$fillcorrect = optional_param('fillcorrect', 0, PARAM_BOOL);
$markall = optional_param('markall', 0, PARAM_BOOL);
$finishattempt = optional_param('finishattempt', 0, PARAM_BOOL);
$back = optional_param('back', 0, PARAM_BOOL);
$startagain = optional_param('startagain', 0, PARAM_BOOL);
// We are always continuing an attempt if a submit button was pressed with the
// exception of the start again button
if ($fillcorrect || $markall || $finishattempt || $back) {
$continue = true;
} else if ($startagain) {
$continue = false;
}
require_login();
if (!isteacherinanycourse()) {
error('This page is for teachers only');
}
if (!$continue) {
// Start a new attempt; delete the old session
unset($SESSION->quizpreview);
// 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 .
'&amp;continue=1');
}
if (empty($quizid)) {
// get a sample quiz to be used as a skeleton
// this should really be done properly by instantiating a quiz object
if (!$quiz = get_records('quiz')) {
error('You have to create at least one quiz before using this preview');
}
$quiz = array_values($quiz);
$quiz = $quiz[0];
// set everything to the default values
foreach($quiz as $field => $value) {
$quizfield = "quiz_".$field;
if(isset($CFG->$quizfield)) {
$quiz->$field = $CFG->$quizfield;
}
else {
$quiz->$field = 0;
}
}
} else if (!$quiz = get_record('quiz', 'id', $quizid)) {
error("Quiz id $quizid does not exist");
}
// Load the question information
if (!$questions = get_records('quiz_questions', 'id', $id)) {
error('Could not load question');
}
if ($maxgrade = get_field('quiz_question_instances', 'grade', 'quiz', $quiz->id, 'question', $id)) {
$questions[$id]->maxgrade = $maxgrade;
} else {
$questions[$id]->maxgrade = $questions[$id]->defaultgrade;
}
$quiz->id = 0; // just for safety
$quiz->questions = $id;
if (!$category = get_record("quiz_categories", "id", $questions[$id]->category)) {
error("This question doesn't belong to a valid category!");
}
if (!isteacher($category->course) and !$category->publish) {
error("You can't preview these questions!");
}
$quiz->course = $category->course;
// Load the question type specific information
if (!quiz_get_question_options($questions)) {
error(get_string('newattemptfail', 'quiz'));
}
// Create a dummy quiz attempt
$attempt = quiz_create_attempt($quiz, 0);
$attempt->id = 0;
// Restore the history of question sessions from the moodle session or create
// new sessions. Make $states a reference to the states array in the moodle
// session.
if (isset($SESSION->quizpreview->states) and $SESSION->quizpreview->questionid
== $id) {
// Reload the question session history from the moodle session
$states =& $SESSION->quizpreview->states;
$historylength = count($states) - 1;
if ($back && $historylength > 0) {
// Go back one step in the history
unset($states[$historylength]);
$historylength--;
}
} else {
// Record the question id in the moodle session
$SESSION->quizpreview->questionid = $id;
// Create an empty session for the question
if (!$newstates =
quiz_get_states($questions, $quiz, $attempt)) {
error(get_string('newattemptfail', 'quiz'));
}
$SESSION->quizpreview->states = array($newstates);
$states =& $SESSION->quizpreview->states;
$historylength = 0;
}
if (!$fillcorrect && !$back && ($form = data_submitted())) {
$form = (array)$form;
$submitted = true;
// Create a new item in the history of question states (don't simplify!)
$states[$historylength + 1] = array();
$states[$historylength + 1][$id] = clone($states[$historylength][$id]);
$historylength++;
$curstate =& $states[$historylength][$id];
// Process the responses
unset($form['id']);
unset($form['quizid']);
unset($form['continue']);
unset($form['markall']);
unset($form['finishattempt']);
unset($form['back']);
unset($form['startagain']);
$event = $finishattempt ? QUIZ_EVENTCLOSE : ($markall ? QUIZ_EVENTGRADE : QUIZ_EVENTSAVE);
if ($actions = quiz_extract_responses($questions, $form, $event)) {
$actions[$id]->timestamp = 0; // We do not care about timelimits here
quiz_process_responses($questions[$id], $states[$historylength][$id], $actions[$id], $quiz, $attempt);
if (QUIZ_EVENTGRADE != $curstate->event && QUIZ_EVENTCLOSE != $curstate->event) {
// Update the current state rather than creating a new one
$historylength--;
unset($states[$historylength]);
$states = array_values($states);
$curstate =& $states[$historylength][$id];
}
}
} else {
$submitted = false;
$curstate =& $states[$historylength][$id];
}
$options = quiz_get_renderoptions($quiz, $curstate);
// Fill in the correct responses (unless the question is in readonly mode)
if ($fillcorrect && !$options->readonly) {
$curstate->responses = $QUIZ_QTYPES[$questions[$id]->qtype]
->get_correct_responses($questions[$id], $curstate);
}
$strpreview = get_string('previewquestion', 'quiz');
print_header($strpreview);
print_heading($strpreview);
echo '<p align="center">' . get_string('modulename', 'quiz') . ': ';
if (empty($quizid)) {
echo '[' . get_string('default', 'quiz') . ']';
} else {
p($quiz->name);
}
echo '<br />'.get_string('question', 'quiz').': ';
p($questions[$id]->name);
echo "</p>\n";
$number = 1;
echo "<form method=\"post\" action=\"preview.php\" autocomplete=\"off\">\n";
echo "<input type=\"hidden\" name=\"id\" value=\"$id\" />\n";
echo "<input type=\"hidden\" name=\"quizid\" value=\"$quizid\" />\n";
echo "<input type=\"hidden\" name=\"continue\" value=\"1\" />\n";
quiz_print_quiz_question($questions[$id], $curstate, $number, $quiz, $options);
echo '<br />';
echo '<center>';
// Print the mark and finish attempt buttons
echo '<input name="markall" type="submit" value="' . get_string('markall',
'quiz') . "\" />\n";
echo '<input name="finishattempt" type="submit" value="' .
get_string('finishattempt', 'quiz') . "\" />\n";
echo '<br />';
echo '<br />';
// Print the fill correct button (unless the question is in readonly mode)
if (!$options->readonly) {
echo '<input name="fillcorrect" type="submit" value="' .
get_string('fillcorrect', 'quiz') . "\" />\n";
}
// Print the navigation buttons
if ($historylength > 0) {
echo '<input name="back" type="submit" value="' . get_string('previous',
'quiz') . "\" />\n";
}
// Print the start again button
echo '<input name="startagain" type="submit" value="' .
get_string('startagain', 'quiz') . "\" />\n";
// Print the close window button
echo '<input type="button" onclick="window.close()" value="' .
get_string('closepreview', 'quiz') . "\" />";
echo '</center>';
echo '</form>';
print_footer();
?>

View file

@ -1,352 +0,0 @@
<?php // $Id$
/*
* Page for editing questions
*
* This page shows the question editing form or processes the following actions:
* - create new question (category, qtype)
* - edit question (id, contextquiz (optional))
* - delete question from quiz (delete, sesskey)
* - delete question (in two steps)
* - 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)
* @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
*/
require_once("../../config.php");
require_once("locallib.php");
require_once($CFG->libdir.'/filelib.php');
$id = optional_param('id'); // question id
$qtype = optional_param('qtype');
$category = optional_param('category');
// a qtype > 99 means a remote question
if ($qtype > 99) {
$typeid = $qtype - 100;
$qtype = RQP;
}
$contextquiz = optional_param('contextquiz'); // the quiz from which this question is being edited
if (isset($_REQUEST['cancel'])) {
redirect("edit.php");
}
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');
}
if ($id) {
if (! $question = get_record("quiz_questions", "id", $id)) {
error("This question doesn't exist");
}
if (!empty($category)) {
$question->category = $category;
}
if (! $category = get_record("quiz_categories", "id", $question->category)) {
error("This question doesn't belong to a valid category!");
}
if (! $course = get_record("course", "id", $category->course)) {
error("This question category doesn't belong to a valid course!");
}
$qtype = $question->qtype;
} else if ($category) { // only for creating new questions
if (! $category = get_record("quiz_categories", "id", $category)) {
error("This wasn't a valid category!");
}
if (! $course = get_record("course", "id", $category->course)) {
error("This category doesn't belong to a valid course!");
}
$question->category = $category->id;
$question->qtype = $qtype;
} else {
error("Must specify question id or category");
}
if (empty($qtype)) {
error("No question type was specified!");
} else if (!isset($QUIZ_QTYPES[$qtype])) {
error("Could not find question type: '$qtype'");
}
require_login($course->id, false);
if (!isteacheredit($course->id)) {
error("You can't modify these questions!");
}
$strquizzes = get_string('modulenameplural', 'quiz');
$streditingquestion = get_string('editingquestion', 'quiz');
if (isset($SESSION->modform->instance)) {
$strediting = '<a href="edit.php">'.get_string('editingquiz', 'quiz').'</a> -> '.
$streditingquestion;
} else {
$strediting = '<a href="edit.php?courseid='.$course->id.'">'.
get_string("editquestions", "quiz").'</a> -> '.$streditingquestion;
}
print_header_simple("$streditingquestion", "", $strediting);
if (isset($_REQUEST['delete'])) {
if (isset($confirm) and confirm_sesskey()) {
if ($confirm == md5($delete)) {
if (record_exists('quiz_question_instances', 'question', $question->id) or
record_exists('quiz_states', 'originalquestion', $question->id)) {
if (!set_field('quiz_questions', 'hidden', 1, 'id', $delete)) {
error('Was not able to hide question');
}
} else {
if (!delete_records("quiz_questions", "id", $question->id)) {
error("An error occurred trying to delete question (id $question->id)");
}
if (!delete_records("quiz_questions", "parent", $question->id)) {
error("An error occurred trying to delete question (id $question->id)");
}
}
redirect("edit.php");
} else {
error("Confirmation string was incorrect");
}
} else {
if ($quiznames = quizzes_question_used($id)) {
$a->questionname = $question->name;
$a->quiznames = implode(', ', $quiznames);
notify(get_string('questioninuse', 'quiz', $a));
}
notice_yesno(get_string("deletequestioncheck", "quiz", $question->name),
"question.php?sesskey=$USER->sesskey&amp;id=$question->id&amp;delete=$delete&amp;confirm=".md5($delete), "edit.php");
}
print_footer($course);
exit;
}
if ($form = data_submitted() and confirm_sesskey()) {
if (isset($form->versioning) && isset($question->id) and false) { // disable versioning until it is fixed.
// use new code that handles whether to overwrite or copy a question
// and keeps track of the versions in the quiz_question_version table
// $replaceinquiz is an array with the ids of all quizzes in which
// the teacher has chosen to replace the old version
$replaceinquiz = array();
foreach($form as $key => $val) {
if ($tmp = quiz_parse_fieldname($key, 'q')) {
if ($tmp['mode'] == 'replace') {
$replaceinquiz[$tmp['id']] = $tmp['id'];
unset($form->$key);
}
}
}
// $quizlist is an array with the ids of quizzes which use this question
$quizlist = array();
if ($instances = get_records('quiz_question_instances', 'question', $question->id)) {
foreach($instances as $instance) {
$quizlist[$instance->quiz] = $instance->quiz;
}
}
if (isset($form->makecopy)) { // explicitly requested copies should be unhidden
$question->hidden = 0;
}
// Logic to determine whether old version should be overwritten
$makecopy = isset($form->makecopy) || (!$form->id); unset($form->makecopy);
if ($makecopy) {
$replaceold = false;
} else {
// this should be improved to exclude teacher preview responses and empty responses
// the current code leaves many unneeded questions in the database
$hasresponses = record_exists('quiz_states', 'question', $form->id) or
record_exists('quiz_states', 'originalquestion', $form->id);
$replaceinall = ($quizlist == $replaceinquiz); // question is being replaced in all quizzes
$replaceold = !$hasresponses && $replaceinall;
}
if (!$replaceold) { // create a new question
$oldquestionid = $question->id;
if (!$makecopy) {
if (!set_field("quiz_questions", 'hidden', 1, 'id', $question->id)) {
error("Could not hide question!");
}
}
unset($question->id);
}
unset($makecopy, $hasresponses, $replaceinall, $replaceold);
$question = $QUIZ_QTYPES[$qtype]->save_question($question, $form, $course);
if(!isset($question->id)) {
error("Failed to save the question!");
}
if(isset($oldquestionid)) {
// create version entries for different quizzes
$version = new object();
$version->oldquestion = $oldquestionid;
$version->newquestion = $question->id;
$version->userid = $USER->id;
$version->timestamp = time();
foreach($replaceinquiz as $qid) {
$version->quiz = $qid;
if(!insert_record("quiz_question_versions", $version)) {
error("Could not store version information of question $oldquestionid in quiz $qid!");
}
}
/// now update the question references in the quizzes
if (!empty($replaceinquiz) and $quizzes = get_records_list("quiz", "id", implode(',', $replaceinquiz))) {
foreach($quizzes as $quiz) {
$questionlist = ",$quiz->questions,"; // a little hack with the commas here. not nice but effective
$questionlist = str_replace(",$oldquestionid,", ",$question->id,", $questionlist);
$questionlist = substr($questionlist, 1, -1); // and get rid of the surrounding commas again
if (!set_field("quiz", 'questions', $questionlist, 'id', $quiz->id)) {
error("Could not update questionlist in quiz $quiz->id!");
}
// the quiz_question_instances table needs to be updated too (aah, the joys of duplication :)
if (!set_field('quiz_question_instances', 'question', $question->id, 'quiz', $quiz->id, 'question', $oldquestionid)) {
error("Could not update question instance!");
}
if (isset($SESSION->modform) && (int)$SESSION->modform->instance === (int)$quiz->id) {
$SESSION->modform->questions = $questionlist;
$SESSION->modform->grades[$question->id] = $SESSION->modform->grades[$oldquestionid];
unset($SESSION->modform->grades[$oldquestionid]);
}
}
// change question in attempts
if ($attempts = get_records_list('quiz_attempts', 'quiz', implode(',', $replaceinquiz))) {
foreach ($attempts as $attempt) {
// replace question id in $attempt->layout
$questionlist = ",$attempt->layout,"; // a little hack with the commas here. not nice but effective
$questionlist = str_replace(",$oldquestionid,", ",$question->id,", $questionlist);
$questionlist = substr($questionlist, 1, -1); // and get rid of the surrounding commas again
if (!set_field('quiz_attempts', 'layout', $questionlist, 'id', $attempt->id)) {
error("Could not update layout in attempt $attempt->id!");
}
// set originalquestion in states
set_field('quiz_states', 'originalquestion', $oldquestionid, 'attempt', $attempt->uniqueid, 'question', $question->id, 'originalquestion', '0');
// replace question id in states
set_field('quiz_states', 'question', $question->id, 'attempt', $attempt->uniqueid, 'question', $oldquestionid);
// replace question id in sessions
set_field('question_sessions', 'questionid', $question->id, 'attemptid', $attempt->uniqueid, 'questionid', $oldquestionid);
}
// Now do anything question-type specific that is required to replace the question
// For example questions that use the quiz_answers table to hold part of their question will
// have to recode the answer ids in the states
$QUIZ_QTYPES[$question->qtype]->change_states_question($oldquestionid, $question, $attempts);
}
}
}
} else {
// use the old code which simply overwrites old versions
// it is also used for creating new questions
$question = $QUIZ_QTYPES[$qtype]->save_question($question, $form, $course);
$replaceinquiz = 'all';
}
if (empty($question->errors) && $QUIZ_QTYPES[$qtype]->finished_edit_wizard($form)) {
// DISABLED AUTOMATIC REGRADING
// Automagically regrade all attempts (and states) in the affected quizzes
//if (!empty($replaceinquiz)) {
// $QUIZ_QTYPES[$question->qtype]->get_question_options($question);
// quiz_regrade_question_in_quizzes($question, $replaceinquiz);
//}
redirect("edit.php");
}
}
$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;
$neggrade = -$grade;
$gradeoptions["$grade"] = "$percentage %";
$gradeoptionsfull["$grade"] = "$percentage %";
$gradeoptionsfull["$neggrade"] = -$percentage." %";
}
$gradeoptionsfull["0"] = $gradeoptions["0"] = get_string("none");
arsort($gradeoptions, SORT_NUMERIC);
arsort($gradeoptionsfull, SORT_NUMERIC);
if (!$categories = quiz_get_category_menu($course->id, false)) {
error("No categories!");
}
make_upload_directory("$course->id"); // Just in case
$coursefiles = get_directory_list("$CFG->dataroot/$course->id", $CFG->moddata);
foreach ($coursefiles as $filename) {
if (mimeinfo("icon", $filename) == "image.gif") {
$images["$filename"] = $filename;
}
}
// Print the question editing form
if (empty($question->id)) {
$question->id = "";
}
if (empty($question->name)) {
$question->name = "";
}
if (empty($question->questiontext)) {
$question->questiontext = "";
}
if (empty($question->image)) {
$question->image = "";
}
if (!isset($question->penalty)) {
$question->penalty = 0.1;
}
if (!isset($question->defaultgrade)) {
$question->defaultgrade = 1;
}
// Set up some Richtext editing if necessary
if ($usehtmleditor = can_use_richtext_editor()) {
$defaultformat = FORMAT_HTML;
} else {
$defaultformat = FORMAT_MOODLE;
}
if (isset($question->errors)) {
$err = $question->errors;
}
echo '<br />';
print_simple_box_start('center');
require_once('questiontypes/'.$QUIZ_QTYPES[$qtype]->name().'/editquestion.php');
print_simple_box_end();
if ($usehtmleditor) {
use_html_editor('questiontext');
}
print_footer($course);
?>

File diff suppressed because it is too large Load diff

View file

@ -89,8 +89,8 @@ class quiz_report extends quiz_default_report {
} }
$sql .= ' WHERE qa.quiz = '.$quiz->id. // ULPGC ecastro $sql .= ' WHERE qa.quiz = '.$quiz->id. // ULPGC ecastro
' AND ( qa.sumgrades >= '.$scorelimit.' ) '; ' AND ( qa.sumgrades >= '.$scorelimit.' ) ';
// ^^^^^^ es posible seleccionar aquí TODOS los quizzes, como quiere Jussi, // ^^^^^^ es posible seleccionar aqu<EFBFBD> TODOS los quizzes, como quiere Jussi,
// pero habría que llevar la cuenta ed cada quiz para restaura las preguntas (quizquestions, states) // pero habr<EFBFBD>a que llevar la cuenta ed cada quiz para restaura las preguntas (quizquestions, states)
/// Fetch the attempts /// Fetch the attempts
$attempts = get_records_sql($sql); $attempts = get_records_sql($sql);
@ -309,7 +309,7 @@ class quiz_report extends quiz_default_report {
$q = $questions[$qnum]; $q = $questions[$qnum];
$qid = $q['id']; $qid = $q['id'];
$question = get_record('quiz_questions', 'id', $qid); $question = get_record('quiz_questions', 'id', $qid);
$qnumber = " (".link_to_popup_window('/mod/quiz/question.php?id='.$qid,'editquestion', $qid, 450, 550, get_string('edit'), 'none', true ).") "; $qnumber = " (".link_to_popup_window('/question/question.php?id='.$qid,'editquestion', $qid, 450, 550, get_string('edit'), 'none', true ).") ";
$qname = '<div class="qname">'.format_text($question->name." : ", $question->questiontextformat, NULL, $quiz->course).'</div>'; $qname = '<div class="qname">'.format_text($question->name." : ", $question->questiontextformat, NULL, $quiz->course).'</div>';
$qicon = quiz_print_question_icon($question, false, true); $qicon = quiz_print_question_icon($question, false, true);
$qreview = quiz_get_question_review($quiz, $question); $qreview = quiz_get_question_review($quiz, $question);

View file

@ -22,6 +22,7 @@ class quiz_default_report {
} }
function print_header_and_tabs($cm, $course, $quiz, $reportmode="overview"){ function print_header_and_tabs($cm, $course, $quiz, $reportmode="overview"){
global $CFG;
/// Define some strings /// Define some strings
$strquizzes = get_string("modulenameplural", "quiz"); $strquizzes = get_string("modulenameplural", "quiz");
$strquiz = get_string("modulename", "quiz"); $strquiz = get_string("modulename", "quiz");

View file

@ -1538,7 +1538,7 @@
global $CFG; global $CFG;
include($CFG->dirroot.'/mod/quiz/questionlib.php'); include($CFG->dirroot.'/question/lib.php');
$status = true; $status = true;

View file

@ -28,12 +28,12 @@
$row = array(); $row = array();
$inactive = array(); $inactive = array();
$row[] = new tabobject('info', "view.php?q=$quiz->id", get_string('info', 'quiz')); $row[] = new tabobject('info', "$CFG->wwwroot/mod/quiz/view.php?q=$quiz->id", get_string('info', 'quiz'));
$row[] = new tabobject('reports', "report.php?q=$quiz->id", get_string('reports', 'quiz')); $row[] = new tabobject('reports', "$CFG->wwwroot/mod/quiz/report.php?q=$quiz->id", get_string('reports', 'quiz'));
$row[] = new tabobject('preview', "attempt.php?q=$quiz->id", get_string('preview', 'quiz'), get_string('previewquiz', 'quiz', format_string($quiz->name))); $row[] = new tabobject('preview', "$CFG->wwwroot/mod/quiz/attempt.php?q=$quiz->id", get_string('preview', 'quiz'), get_string('previewquiz', 'quiz', format_string($quiz->name)));
if (isteacheredit($course->id)) { if (isteacheredit($course->id)) {
$row[] = new tabobject('edit', "edit.php?quizid=$quiz->id", get_string('edit'), get_string('editquizquestions', 'quiz')); $row[] = new tabobject('edit', "$CFG->wwwroot/mod/quiz/edit.php?quizid=$quiz->id", get_string('edit'), get_string('editquizquestions', 'quiz'));
$row[] = new tabobject('manualgrading', "grading.php?quizid=$quiz->id", get_string("manualgrading", "quiz")); $row[] = new tabobject('manualgrading', "$CFG->wwwroot/mod/quiz/grading.php?quizid=$quiz->id", get_string("manualgrading", "quiz"));
} }
$tabs[] = $row; $tabs[] = $row;
@ -52,7 +52,7 @@
$row = array(); $row = array();
$currenttab = ''; $currenttab = '';
foreach ($reportlist as $report) { foreach ($reportlist as $report) {
$row[] = new tabobject($report, "report.php?q=$quiz->id&amp;mode=$report", $row[] = new tabobject($report, "$CFG->wwwroot/mod/quiz/report.php?q=$quiz->id&amp;mode=$report",
get_string("report$report", "quiz")); get_string("report$report", "quiz"));
if ($report == $mode) { if ($report == $mode) {
$currenttab = $report; $currenttab = $report;
@ -67,10 +67,10 @@
$row = array(); $row = array();
$currenttab = $mode; $currenttab = $mode;
$row[] = new tabobject('editq', "edit.php?quizid=$quiz->id", get_string('questions', 'quiz'), get_string('editquizquestions', 'quiz')); $row[] = new tabobject('editq', "$CFG->wwwroot/mod/quiz/edit.php?quizid=$quiz->id", get_string('questions', 'quiz'), get_string('editquizquestions', 'quiz'));
$row[] = new tabobject('categories', "category.php?id=$course->id", get_string('categories', 'quiz'), get_string('editqcats', 'quiz')); $row[] = new tabobject('categories', "$CFG->wwwroot/question/category.php?id=$course->id", get_string('categories', 'quiz'), get_string('editqcats', 'quiz'));
$row[] = new tabobject('import', "import.php?course=$course->id", get_string('import', 'quiz'), get_string('importquestions', 'quiz')); $row[] = new tabobject('import', "$CFG->wwwroot/mod/quiz/import.php?course=$course->id", get_string('import', 'quiz'), get_string('importquestions', 'quiz'));
$row[] = new tabobject('export', "export.php?courseid=$course->id", get_string('export', 'quiz'), get_string('exportquestions', 'quiz')); $row[] = new tabobject('export', "$CFG->wwwroot/mod/quiz/export.php?courseid=$course->id", get_string('export', 'quiz'), get_string('exportquestions', 'quiz'));
$row[] = new tabobject('update', "$CFG->wwwroot/course/mod.php?update=$cm->id&amp;sesskey=$USER->sesskey", get_string('settings'), get_string('updatesettings')); $row[] = new tabobject('update', "$CFG->wwwroot/course/mod.php?update=$cm->id&amp;sesskey=$USER->sesskey", get_string('settings'), get_string('updatesettings'));
$tabs[] = $row; $tabs[] = $row;