Commit f9b0500f authored by Tim Hunt's avatar Tim Hunt
Browse files

MDL-20636 Quiz editing now works, as does the random question type.

However, all this needs more testing.

Also, a bit of a purge of training whitespace and global .
parent 14936199
......@@ -4796,9 +4796,8 @@ class admin_page_manageqtypes extends admin_externalpage {
$found = false;
$textlib = textlib_get_instance();
require_once($CFG->libdir . '/questionlib.php');
global $QTYPES;
foreach ($QTYPES as $qtype) {
require_once($CFG->dirroot . '/question/engine/bank.php');
foreach (question_bank::get_all_qtypes() as $qtype) {
if (strpos($textlib->strtolower($qtype->local_name()), $query) !== false) {
$found = true;
break;
......
......@@ -130,7 +130,7 @@ function question_type_menu() {
* Sort an array of question type names according to the question type sort order stored in
* config_plugins. Entries for which there is no xxx_sortorder defined will go
* at the end, sorted according to textlib_get_instance()->asort($inarray).
* @param $inarray an array $qtype => $QTYPES[$qtype]->local_name().
* @param $inarray an array $qtypename => $qtype->local_name().
* @param $config get_config('question'), if you happen to have it around, to save one DB query.
* @return array the sorted version of $inarray.
*/
......@@ -431,7 +431,7 @@ function question_category_in_use($categoryid, $recursive = false) {
* @param object $question The question being deleted
*/
function question_delete_question($questionid) {
global $QTYPES, $DB;
global $DB;
$question = $DB->get_record_sql('
SELECT q.*, qc.contextid
......
<?php
function xmldb_local_qedatabase_upgrade($oldversion) {
global $CFG, $DB, $QTYPES;
global $CFG, $DB;
$dbman = $DB->get_manager();
......
......@@ -235,7 +235,7 @@ class quiz_access_manager {
* @param boolean $unfinished whether the button is to continue an existing attempt,
* or start a new one. This affects whether a javascript alert is shown.
*/
public function print_start_attempt_button($canpreview, $buttontext, $unfinished) {
public function print_start_attempt_button($canpreview, $buttontext, $unfinished) {
global $OUTPUT;
$url = $this->_quizobj->start_attempt_url();
......
/** JavaScript for /mod/quiz/edit.php */
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* JavaScript library for the quiz module editing interface.
*
* @package mod
* @subpackage quiz
* @copyright 2008 Olli Savolainen
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// Initialise everything on the quiz edit/order and paging page.
var quiz_edit = {};
......
<?php
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
// Copyright (C) 1999 onwards Martin Dougiamas and others //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details: //
// //
// http://www.gnu.org/copyleft/gpl.html //
// //
///////////////////////////////////////////////////////////////////////////
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Page to edit quizzes
......@@ -43,15 +36,19 @@
* delete Removes a question from the quiz
* savechanges Saves the order and grades for questions in the quiz
*
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package quiz
*//** */
* @package mod
* @subpackage quiz
* @copyright 1999 onwards Martin Dougiamas and others {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once('../../config.php');
require_once($CFG->dirroot . '/mod/quiz/editlib.php');
require_once($CFG->dirroot . '/mod/quiz/addrandomform.php');
require_once($CFG->dirroot . '/question/category_class.php');
/**
* Callback function called from question_list() function
* (which is called from showbank())
......@@ -74,7 +71,7 @@ function module_specific_buttons($cmid, $cmoptions) {
* (which is called from showbank())
*/
function module_specific_controls($totalnumber, $recurse, $category, $cmid, $cmoptions) {
global $QTYPES, $OUTPUT;
global $OUTPUT;
$out = '';
$catcontext = get_context_instance_by_id($category->contextid);
if (has_capability('moodle/question:useall', $catcontext)) {
......@@ -84,7 +81,8 @@ function module_specific_controls($totalnumber, $recurse, $category, $cmid, $cmo
$disabled = '';
}
$randomusablequestions =
$QTYPES['random']->get_usable_questions_from_category($category->id, $recurse, '0');
question_bank::get_qtype('random')->get_available_questions_from_category(
$category->id, $recurse);
$maxrand = count($randomusablequestions);
if ($maxrand > 0) {
for ($i = 1; $i <= min(10, $maxrand); $i++) {
......@@ -120,6 +118,7 @@ $quiz_qbanktool = optional_param('qbanktool', -1, PARAM_BOOL);
list($thispageurl, $contexts, $cmid, $cm, $quiz, $pagevars) =
question_edit_setup('editq', '/mod/quiz/edit.php', true);
$quiz->questions = quiz_clean_layout($quiz->questions);
$defaultcategoryobj = question_make_default_categories($contexts->all());
$defaultcategory = $defaultcategoryobj->id . ',' . $defaultcategoryobj->contextid;
......@@ -164,7 +163,7 @@ add_to_log($cm->course, 'quiz', 'editquestions',
// You need mod/quiz:manage in addition to question capabilities to access this page.
require_capability('mod/quiz:manage', $contexts->lowest());
if (empty($quiz->grades)) { // Construct an array to hold all the grades.
if (empty($quiz->grades)) {
$quiz->grades = quiz_get_all_question_grades($quiz);
}
......@@ -186,13 +185,15 @@ foreach ($params as $key => $value) {
if (($up = optional_param('up', false, PARAM_INT)) && confirm_sesskey()) {
$quiz->questions = quiz_move_question_up($quiz->questions, $up);
quiz_save_new_layout($quiz);
$DB->set_field('quiz', 'questions', $quiz->questions, array('id' => $quiz->id));
quiz_delete_previews($quiz);
redirect($thispageurl);
}
if (($down = optional_param('down', false, PARAM_INT)) && confirm_sesskey()) {
$quiz->questions = quiz_move_question_down($quiz->questions, $down);
quiz_save_new_layout($quiz);
$DB->set_field('quiz', 'questions', $quiz->questions, array('id' => $quiz->id));
quiz_delete_previews($quiz);
redirect($thispageurl);
}
......@@ -200,15 +201,17 @@ if (optional_param('repaginate', false, PARAM_BOOL) && confirm_sesskey()) {
// Re-paginate the quiz
$questionsperpage = optional_param('questionsperpage', $quiz->questionsperpage, PARAM_INT);
$quiz->questions = quiz_repaginate($quiz->questions, $questionsperpage );
quiz_save_new_layout($quiz);
$DB->set_field('quiz', 'questions', $quiz->questions, array('id' => $quiz->id));
quiz_delete_previews($quiz);
redirect($thispageurl);
}
if (($addquestion = optional_param('addquestion', 0, PARAM_INT)) && confirm_sesskey()) {
/// Add a single question to the current quiz
$addonpage = optional_param('addonpage', 0, PARAM_INT);
quiz_add_quiz_question($addquestion, $quiz, $addonpage);
quiz_update_sumgrades($quiz);
quiz_delete_previews($quiz);
quiz_update_sumgrades($quiz);
$thispageurl->param('lastchanged', $addquestion);
redirect($thispageurl);
}
......@@ -216,21 +219,17 @@ if (($addquestion = optional_param('addquestion', 0, PARAM_INT)) && confirm_sess
if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
/// Add selected questions to the current quiz
$rawdata = (array) data_submitted();
foreach ($rawdata as $key => $value) { // Parse input for question ids
foreach ($rawdata as $key => $value) { // Parse input for question ids
if (preg_match('!^q([0-9]+)$!', $key, $matches)) {
$key = $matches[1];
quiz_add_quiz_question($key, $quiz);
}
}
quiz_update_sumgrades($quiz);
quiz_delete_previews($quiz);
quiz_update_sumgrades($quiz);
redirect($thispageurl);
}
$qcobject = new question_category_object($pagevars['cpage'], $thispageurl,
$contexts->having_one_edit_tab_cap('categories'), $defaultcategoryobj->id,
$defaultcategory, null, $contexts->having_cap('moodle/question:add'));
if ((optional_param('addrandom', false, PARAM_BOOL)) && confirm_sesskey()) {
// Add random questions to the quiz
$recurse = optional_param('recurse', 0, PARAM_BOOL);
......@@ -239,8 +238,8 @@ if ((optional_param('addrandom', false, PARAM_BOOL)) && confirm_sesskey()) {
$randomcount = required_param('randomcount', PARAM_INT);
quiz_add_random_questions($quiz, $addonpage, $categoryid, $randomcount, $recurse);
quiz_update_sumgrades($quiz);
quiz_delete_previews($quiz);
quiz_update_sumgrades($quiz);
redirect($thispageurl);
}
......@@ -248,21 +247,24 @@ if (optional_param('addnewpagesafterselected', null, PARAM_CLEAN) && !empty($sel
foreach ($selectedquestionids as $questionid) {
$quiz->questions = quiz_add_page_break_after($quiz->questions, $questionid);
}
quiz_save_new_layout($quiz);
$DB->set_field('quiz', 'questions', $quiz->questions, array('id' => $quiz->id));
quiz_delete_previews($quiz);
redirect($thispageurl);
}
$addpage = optional_param('addpage', false, PARAM_INT);
if ($addpage !== false && confirm_sesskey()) {
$quiz->questions = quiz_add_page_break_at($quiz->questions, $addpage);
quiz_save_new_layout($quiz);
$DB->set_field('quiz', 'questions', $quiz->questions, array('id' => $quiz->id));
quiz_delete_previews($quiz);
redirect($thispageurl);
}
$deleteemptypage = optional_param('deleteemptypage', false, PARAM_INT);
if (($deleteemptypage !== false) && confirm_sesskey()) {
$quiz->questions = quiz_delete_empty_page($quiz->questions, $deleteemptypage);
quiz_save_new_layout($quiz);
$DB->set_field('quiz', 'questions', $quiz->questions, array('id' => $quiz->id));
quiz_delete_previews($quiz);
redirect($thispageurl);
}
......@@ -278,12 +280,15 @@ if (optional_param('quizdeleteselected', false, PARAM_BOOL) && !empty($selectedq
foreach ($selectedquestionids as $questionid) {
quiz_remove_question($quiz, $questionid);
}
quiz_update_sumgrades($quiz);
quiz_delete_previews($quiz);
quiz_update_sumgrades($quiz);
redirect($thispageurl);
}
if (optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) {
$deletepreviews = false;
$recomputesummarks = false;
$oldquestions = explode(',', $quiz->questions); // the questions in the old order
$questions = array(); // for questions in the new order
$rawdata = (array) data_submitted();
......@@ -298,9 +303,9 @@ if (optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) {
/// Parse input for question -> grades
$questionid = $matches[1];
$quiz->grades[$questionid] = clean_param($value, PARAM_FLOAT);
quiz_update_question_instance($quiz->grades[$questionid], $questionid, $quiz->id);
quiz_delete_previews($quiz);
quiz_update_sumgrades($quiz);
quiz_update_question_instance($quiz->grades[$questionid], $questionid, $quiz);
$deletepreviews = true;
$recomputesummarks = true;
} else if (preg_match('!^o(pg)?([0-9]+)$!', $key, $matches)) {
/// Parse input for ordering info
......@@ -317,6 +322,7 @@ if (optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) {
} else {
$questions[$value] = $questionid;
}
$deletepreviews = true;
}
}
......@@ -325,8 +331,8 @@ if (optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) {
ksort($questions);
$questions[] = 0;
$quiz->questions = implode(',', $questions);
quiz_save_new_layout($quiz);
quiz_delete_previews($quiz);
$DB->set_field('quiz', 'questions', $quiz->questions, array('id' => $quiz->id));
$deletepreviews = true;
}
//get a list of questions to move, later to be added in the appropriate
......@@ -350,8 +356,8 @@ if (optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) {
$moveselectedpos = $pagebreakpositions[$moveselectedonpage - 1];
array_splice($questions, $moveselectedpos, 0, $selectedquestionids);
$quiz->questions = implode(',', $questions);
quiz_save_new_layout($quiz);
quiz_delete_previews($quiz);
$DB->set_field('quiz', 'questions', $quiz->questions, array('id' => $quiz->id));
$deletepreviews = true;
}
// If rescaling is required save the new maximum
......@@ -360,6 +366,15 @@ if (optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) {
quiz_set_grade($maxgrade, $quiz);
}
if ($deletepreviews) {
quiz_delete_previews($quiz);
}
if ($recomputesummarks) {
quiz_update_sumgrades($quiz);
quiz_update_all_attempt_sumgrades($quiz);
quiz_update_all_final_grades($quiz);
quiz_update_grades($quiz, 0, true);
}
redirect($thispageurl);
}
......
<?php
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
// Copyright (C) 1999 onwards Martin Dougiamas and others //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details: //
// //
// http://www.gnu.org/copyleft/gpl.html //
// //
///////////////////////////////////////////////////////////////////////////
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Functions used by edit.php to edit quizzes
* This contains functions that are called from within the quiz module only
* Functions that are also called by core Moodle are in {@link lib.php}
* This script also loads the code in {@link questionlib.php} which holds
* the module-indpendent code for handling questions and which in turn
* initialises all the questiontype classes.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package quiz
*//** */
* @package mod
* @subpackage quiz
* @copyright 1999 onwards Martin Dougiamas and others {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
define('NUM_QS_TO_SHOW_IN_RANDOM', 3);
/**
......@@ -141,15 +142,16 @@ function quiz_add_quiz_question($id, $quiz, $page = 0) {
$quiz->questions = implode(',', $questions);
$DB->set_field('quiz', 'questions', $quiz->questions, array('id' => $quiz->id));
// update question grades
$quiz->grades[$id] = $DB->get_field('question', 'defaultgrade', array('id' => $id));
quiz_update_question_instance($quiz->grades[$id], $id, $quiz->instance);
return true;
// Add the new question instance.
$instance = new stdClass;
$instance->quiz = $quiz->id;
$instance->question = $id;
$instance->grade = $DB->get_field('question', 'defaultmark', array('id' => $id));
$DB->insert_record('quiz_question_instances', $instance);
}
function quiz_add_random_questions($quiz, $addonpage, $categoryid, $number, $includesubcategories) {
global $DB, $QTYPES;
global $DB;
$category = $DB->get_record('question_categories', array('id' => $categoryid));
if (!$category) {
......@@ -163,7 +165,7 @@ function quiz_add_random_questions($quiz, $addonpage, $categoryid, $number, $inc
// not used by any quiz.
if ($existingquestions = $DB->get_records_sql(
"SELECT q.id,q.qtype FROM {question} q
WHERE qtype = '" . RANDOM . "'
WHERE qtype = 'random'
AND category = ?
AND " . $DB->sql_compare_text('questiontext') . " = ?
AND NOT EXISTS (SELECT * FROM {quiz_question_instances} WHERE question = q.id)
......@@ -181,14 +183,14 @@ function quiz_add_random_questions($quiz, $addonpage, $categoryid, $number, $inc
// More random questions are needed, create them.
$form->questiontext = array('text' => $includesubcategories, 'format' => 0);
$form->defaultgrade = 1;
$form->defaultmark = 1;
$form->hidden = 1;
for ($i = 0; $i < $number; $i += 1) {
$form->category = $category->id . ',' . $category->contextid;
$form->stamp = make_unique_id_code(); // Set the unique code (not to be changed)
$question = new stdClass;
$question->qtype = RANDOM;
$question = $QTYPES[RANDOM]->save_question($question, $form);
$question->qtype = 'random';
$question = question_bank::get_qtype('random')->save_question($question, $form);
if (!isset($question->id)) {
print_error('cannotinsertrandomquestion', 'quiz');
}
......@@ -248,23 +250,29 @@ function quiz_save_new_layout($quiz) {
*
* 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) {
global $DB;
if ($instance = $DB->get_record('quiz_question_instances', array('quiz' => $quizid, 'question' => $questionid))) {
$instance->grade = $grade;
return $DB->update_record('quiz_question_instances', $instance);
} else {
unset($instance);
$instance->quiz = $quizid;
$instance->question = $questionid;
$instance->grade = $grade;
return $DB->insert_record('quiz_question_instances', $instance);
function quiz_update_question_instance($grade, $questionid, $quiz) {
$instance = $DB->get_record('quiz_question_instances', array('quiz' => $quizid,
'question' => $questionid));
$slot = quiz_get_slot_for_question($quiz, $questionid);
if (!$instance || !$slot) {
throw new coding_exception('Attempt to change the grade of a quesion not in the quiz.');
}
if (abs($grade - $instance->grade) < 1e-7) {
// Grade has not changed. Nothing to do.
return;
}
$instance->grade = $grade;
$DB->update_record('quiz_question_instances', $instance);
question_engine::set_max_mark_in_attempts(new quibaid_for_quiz($quiz->id),
$slot, $grade);
}
// Private function used by the following two.
......@@ -330,7 +338,7 @@ function quiz_move_question_down($layout, $questionid) {
*/
function quiz_print_question_list($quiz, $pageurl, $allowdelete, $reordertool,
$quiz_qbanktool, $hasattempts, $defaultcategoryobj) {
global $USER, $CFG, $QTYPES, $DB, $OUTPUT;
global $USER, $CFG, $DB, $OUTPUT;
$strorder = get_string('order');
$strquestionname = get_string('questionname', 'quiz');
$strgrade = get_string('grade');
......@@ -351,11 +359,12 @@ function quiz_print_question_list($quiz, $pageurl, $allowdelete, $reordertool,
if ($quiz->questions) {
list($usql, $params) = $DB->get_in_or_equal(explode(',', $quiz->questions));
$questions = $DB->get_records_sql("SELECT q.*,c.contextid
FROM {question} q,
{question_categories} c
WHERE q.id $usql
AND q.category = c.id", $params);
$params[] = $quiz->id;
$questions = $DB->get_records_sql("SELECT q.*, qc.contextid, qqi.grade as maxmark
FROM {question} q
JOIN {question_categories} qc ON qc.id = q.category
JOIN {quiz_question_instances} qqi ON qqi.question = q.id
WHERE q.id $usql AND qqi.quiz = ?", $params);
} else {
$questions = array();
}
......@@ -429,20 +438,15 @@ function quiz_print_question_list($quiz, $pageurl, $allowdelete, $reordertool,
$qno = 1;
//the current question (includes questions and descriptions)
$questioncount = 0;
//the ordinal of current element in the layout
//(includes page breaks, questions and descriptions)
$count = 0;
//the current page number in iteration
$pagecount = 0;
$sumgrade = 0;
$pageopen = false;
$returnurl = str_replace($CFG->wwwroot, '', $pageurl->out(false));
$questiontotalcount = count($order);
foreach ($order as $i => $qnum) {
foreach ($order as $count => $qnum) {
$reordercheckbox = '';
$reordercheckboxlabel = '';
......@@ -451,10 +455,22 @@ function quiz_print_question_list($quiz, $pageurl, $allowdelete, $reordertool,
if ($qnum && empty($questions[$qnum])) {
continue;
}
// If the questiontype is missing change the question type
if ($qnum && !array_key_exists($questions[$qnum]->qtype, $QTYPES)) {
if ($qnum && !array_key_exists($qnum, $questions)) {
$fakequestion = new stdClass();
$fakequestion->id = 0;
$fakequestion->qtype = 'missingtype';
$fakequestion->name = get_string('deletedquestion', 'qtype_missingtype');
$fakequestion->questiontext = '<p>' . get_string('deletedquestion', 'qtype_missing') . '</p>';
$fakequestion->length = 0;
$questions[$qnum] = $fakequestion;
$quiz->grades[$qnum] = 0;
} else if ($qnum and question_bank::qtype_exists($questions[$qnum]->qtype)) {
$questions[$qnum]->qtype = 'missingtype';
}
if ($qnum != 0 || ($qnum == 0 && !$pageopen)) {
//this is either a question or a page break after another
// (no page is currently open)
......@@ -466,7 +482,7 @@ function quiz_print_question_list($quiz, $pageurl, $allowdelete, $reordertool,
'</span><div class="pagecontent">';
$pageopen = true;
}
if ($qnum == 0 && $i < $questiontotalcount) {
if ($qnum == 0 && $count < $questiontotalcount) {
// This is the second successive page break. Tell the user the page is empty.
echo '<div class="pagestatus">';
print_string('noquestionsonpage', 'quiz');
......@@ -474,7 +490,7 @@ function quiz_print_question_list($quiz, $pageurl, $allowdelete, $reordertool,
if ($allowdelete) {
echo '<div class="quizpagedelete">';
echo '<a title="' . get_string('removeemptypage', 'quiz') . '" href="' .
$pageurl->out(true, array('deleteemptypage' => $i - 1, 'sesskey'=>sesskey())) .
$pageurl->out(true, array('deleteemptypage' => $count - 1, 'sesskey'=>sesskey())) .
'"><img src="' . $OUTPUT->pix_url('t/delete') . '" ' .
'class="iconsmall" alt="' . $strremove . '" /></a>';
echo '</div>';
......@@ -551,7 +567,7 @@ function quiz_print_question_list($quiz, $pageurl, $allowdelete, $reordertool,
" alt=\"$strmovedown\" /></a>";
}
}
if ($allowdelete && question_has_capability_on($question, 'use', $question->category)) {
if ($allowdelete && (empty($question->id) || question_has_capability_on($question, 'use', $question->category))) {
// remove from quiz, not question delete.
if (!$hasattempts) {
echo "<a title=\"$strremove\" href=\"" .
......@@ -625,19 +641,15 @@ function quiz_print_question_list($quiz, $pageurl, $allowdelete, $reordertool,
</div>
<?php
/* Display question end */
$count++;
$sumgrade += $quiz->grades[$qnum];
}
}
//a page break: end the existing page.
if ($qnum == 0) {
if ($pageopen) {
if (!$reordertool && !($quiz->shufflequestions && $i < $questiontotalcount - 1)) {
if (!$reordertool && !($quiz->shufflequestions && $count < $questiontotalcount - 1)) {
quiz_print_pagecontrols($quiz, $pageurl, $pagecount,
$hasattempts, $defaultcategoryobj);
} else if ($i < $questiontotalcount - 1) {
} else if ($count < $questiontotalcount - 1) {
//do not include the last page break for reordering
//to avoid creating a new extra page in the end
echo '<input type="hidden" name="opg' . $pagecount . '" size="2" value="' .
...