2009-11-04 11:58:30 +00:00
|
|
|
<?php
|
2011-02-21 16:13:25 +00:00
|
|
|
// 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/>.
|
|
|
|
|
2008-11-20 06:59:11 +00:00
|
|
|
/**
|
|
|
|
* Fallback page of /mod/quiz/edit.php add random question dialog,
|
|
|
|
* for users who do not use javascript.
|
|
|
|
*
|
2011-02-21 16:13:25 +00:00
|
|
|
* @package mod
|
|
|
|
* @subpackage quiz
|
|
|
|
* @copyright 2008 Olli Savolainen
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
2008-11-20 06:59:11 +00:00
|
|
|
*/
|
2011-02-21 16:13:25 +00:00
|
|
|
|
|
|
|
|
quiz editing: MDL-17454 first attemtp, and MDL-18554
This is a minimal fix for MDL-18554, I have just added a cancel button and made it work.
The more substantial part of this is MDL-17454, trying to make the quiz editing screen behave appropriately when shuffle questions is on. I am sure Olli will have opinions about this and want to change it further. Rought summary:
* When shufflequestions is off, never restrict manual paging, even if questionsperpage is set.
* When shuffle questions is on:
** Always display the quiz with the defined number of questions per page.
** Remove controls to add things except at the end of the quiz.
** Disable most of the order and paging tab, but still allow the question list to be reordered, in case that helps teachers track which questions they have added.
** Still allow questions to be reordered on the edit tab, but when moving the top question on a page up, reorder with the previous question, rather than moving to the previous page.
* Change the status bar, so that the yellow highlight is reserved for alert information. The more informative stuff is now plain, and moved to under the title. To my mind that associates it more closely with the quiz name. Also it moves Total of grades and Maximum grade closer together.
* JavaScript cleaned up. I learn more about YUI every day.
* Some PHP code clean ups that I forgot to commit separately before making substantive changes.
2009-03-17 09:51:34 +00:00
|
|
|
require_once('../../config.php');
|
|
|
|
require_once($CFG->dirroot . '/mod/quiz/editlib.php');
|
2010-11-22 09:52:42 +00:00
|
|
|
require_once($CFG->dirroot . '/mod/quiz/addrandomform.php');
|
quiz editing: MDL-17454 first attemtp, and MDL-18554
This is a minimal fix for MDL-18554, I have just added a cancel button and made it work.
The more substantial part of this is MDL-17454, trying to make the quiz editing screen behave appropriately when shuffle questions is on. I am sure Olli will have opinions about this and want to change it further. Rought summary:
* When shufflequestions is off, never restrict manual paging, even if questionsperpage is set.
* When shuffle questions is on:
** Always display the quiz with the defined number of questions per page.
** Remove controls to add things except at the end of the quiz.
** Disable most of the order and paging tab, but still allow the question list to be reordered, in case that helps teachers track which questions they have added.
** Still allow questions to be reordered on the edit tab, but when moving the top question on a page up, reorder with the previous question, rather than moving to the previous page.
* Change the status bar, so that the yellow highlight is reserved for alert information. The more informative stuff is now plain, and moved to under the title. To my mind that associates it more closely with the quiz name. Also it moves Total of grades and Maximum grade closer together.
* JavaScript cleaned up. I learn more about YUI every day.
* Some PHP code clean ups that I forgot to commit separately before making substantive changes.
2009-03-17 09:51:34 +00:00
|
|
|
require_once($CFG->dirroot . '/question/category_class.php');
|
2008-11-20 06:59:11 +00:00
|
|
|
|
2010-04-12 13:31:42 +00:00
|
|
|
list($thispageurl, $contexts, $cmid, $cm, $quiz, $pagevars) =
|
|
|
|
question_edit_setup('editq', '/mod/quiz/addrandom.php', true);
|
2008-11-20 06:59:11 +00:00
|
|
|
|
2010-11-22 09:52:42 +00:00
|
|
|
// These params are only passed from page request to request while we stay on
|
2012-05-04 12:40:21 +01:00
|
|
|
// this page otherwise they would go in question_edit_setup.
|
2010-11-22 09:52:42 +00:00
|
|
|
$returnurl = optional_param('returnurl', '', PARAM_LOCALURL);
|
|
|
|
$addonpage = optional_param('addonpage', 0, PARAM_INT);
|
|
|
|
$category = optional_param('category', 0, PARAM_INT);
|
2011-02-11 17:36:30 +00:00
|
|
|
$scrollpos = optional_param('scrollpos', 0, PARAM_INT);
|
2010-11-22 09:52:42 +00:00
|
|
|
|
|
|
|
// Get the course object and related bits.
|
|
|
|
if (!$course = $DB->get_record('course', array('id' => $quiz->course))) {
|
|
|
|
print_error('invalidcourseid');
|
|
|
|
}
|
2012-03-28 13:55:17 +01:00
|
|
|
// You need mod/quiz:manage in addition to question capabilities to access this page.
|
|
|
|
// You also need the moodle/question:useall capability somewhere.
|
2010-11-22 09:52:42 +00:00
|
|
|
require_capability('mod/quiz:manage', $contexts->lowest());
|
2012-03-28 13:55:17 +01:00
|
|
|
if (!$contexts->having_cap('moodle/question:useall')) {
|
|
|
|
print_error('nopermissions', '', '', 'use');
|
|
|
|
}
|
2010-11-22 09:52:42 +00:00
|
|
|
|
|
|
|
$PAGE->set_url($thispageurl);
|
|
|
|
|
|
|
|
if ($returnurl) {
|
|
|
|
$returnurl = new moodle_url($returnurl);
|
|
|
|
} else {
|
|
|
|
$returnurl = new moodle_url('/mod/quiz/edit.php', array('cmid' => $cmid));
|
|
|
|
}
|
2011-02-11 17:36:30 +00:00
|
|
|
if ($scrollpos) {
|
|
|
|
$returnurl->param('scrollpos', $scrollpos);
|
|
|
|
}
|
2010-11-22 09:52:42 +00:00
|
|
|
|
2009-03-17 08:21:37 +00:00
|
|
|
$defaultcategoryobj = question_make_default_categories($contexts->all());
|
2010-11-22 09:52:42 +00:00
|
|
|
$defaultcategory = $defaultcategoryobj->id . ',' . $defaultcategoryobj->contextid;
|
2008-11-20 06:59:11 +00:00
|
|
|
|
2009-03-17 08:21:37 +00:00
|
|
|
$qcobject = new question_category_object(
|
|
|
|
$pagevars['cpage'],
|
|
|
|
$thispageurl,
|
|
|
|
$contexts->having_one_edit_tab_cap('categories'),
|
2010-11-22 09:52:42 +00:00
|
|
|
$defaultcategoryobj->id,
|
2009-03-17 08:21:37 +00:00
|
|
|
$defaultcategory,
|
|
|
|
null,
|
|
|
|
$contexts->having_cap('moodle/question:add'));
|
2008-11-20 06:59:11 +00:00
|
|
|
|
2010-11-22 09:52:42 +00:00
|
|
|
$mform = new quiz_add_random_form(new moodle_url('/mod/quiz/addrandom.php'), $contexts);
|
|
|
|
|
|
|
|
if ($mform->is_cancelled()) {
|
|
|
|
redirect($returnurl);
|
2009-03-17 08:21:37 +00:00
|
|
|
}
|
quiz editing: MDL-17454 first attemtp, and MDL-18554
This is a minimal fix for MDL-18554, I have just added a cancel button and made it work.
The more substantial part of this is MDL-17454, trying to make the quiz editing screen behave appropriately when shuffle questions is on. I am sure Olli will have opinions about this and want to change it further. Rought summary:
* When shufflequestions is off, never restrict manual paging, even if questionsperpage is set.
* When shuffle questions is on:
** Always display the quiz with the defined number of questions per page.
** Remove controls to add things except at the end of the quiz.
** Disable most of the order and paging tab, but still allow the question list to be reordered, in case that helps teachers track which questions they have added.
** Still allow questions to be reordered on the edit tab, but when moving the top question on a page up, reorder with the previous question, rather than moving to the previous page.
* Change the status bar, so that the yellow highlight is reserved for alert information. The more informative stuff is now plain, and moved to under the title. To my mind that associates it more closely with the quiz name. Also it moves Total of grades and Maximum grade closer together.
* JavaScript cleaned up. I learn more about YUI every day.
* Some PHP code clean ups that I forgot to commit separately before making substantive changes.
2009-03-17 09:51:34 +00:00
|
|
|
|
2010-11-22 09:52:42 +00:00
|
|
|
if ($data = $mform->get_data()) {
|
|
|
|
if (!empty($data->existingcategory)) {
|
|
|
|
list($categoryid) = explode(',', $data->category);
|
|
|
|
$includesubcategories = !empty($data->includesubcategories);
|
|
|
|
$returnurl->param('cat', $data->category);
|
2008-11-20 06:59:11 +00:00
|
|
|
|
2010-11-22 09:52:42 +00:00
|
|
|
} else if (!empty($data->newcategory)) {
|
|
|
|
list($parentid, $contextid) = explode(',', $data->parent);
|
|
|
|
$categoryid = $qcobject->add_category($data->parent, $data->name, '', true);
|
|
|
|
$includesubcategories = 0;
|
|
|
|
add_to_log($quiz->course, 'quiz', 'addcategory',
|
|
|
|
'view.php?id=' . $cm->id, $categoryid, $cm->id);
|
|
|
|
$returnurl->param('cat', $categoryid . ',' . $contextid);
|
2009-10-16 03:20:38 +00:00
|
|
|
|
2010-11-22 09:52:42 +00:00
|
|
|
} else {
|
2011-04-04 20:11:29 +01:00
|
|
|
throw new coding_exception(
|
|
|
|
'It seems a form was submitted without any button being pressed???');
|
2010-11-22 09:52:42 +00:00
|
|
|
}
|
2008-11-20 06:59:11 +00:00
|
|
|
|
2010-11-22 09:52:42 +00:00
|
|
|
quiz_add_random_questions($quiz, $addonpage, $categoryid, 1, $includesubcategories);
|
2011-09-21 16:07:09 +01:00
|
|
|
quiz_delete_previews($quiz);
|
|
|
|
quiz_update_sumgrades($quiz);
|
2010-11-22 09:52:42 +00:00
|
|
|
redirect($returnurl);
|
2009-03-17 08:21:37 +00:00
|
|
|
}
|
2008-11-20 06:59:11 +00:00
|
|
|
|
2010-11-22 09:52:42 +00:00
|
|
|
$mform->set_data(array(
|
|
|
|
'addonpage' => $addonpage,
|
|
|
|
'returnurl' => $returnurl,
|
|
|
|
'cmid' => $cm->id,
|
|
|
|
'category' => $category,
|
|
|
|
));
|
|
|
|
|
|
|
|
// Setup $PAGE.
|
|
|
|
$streditingquiz = get_string('editinga', 'moodle', get_string('modulename', 'quiz'));
|
2009-09-07 02:11:54 +00:00
|
|
|
$PAGE->navbar->add($streditingquiz);
|
2009-09-08 01:57:28 +00:00
|
|
|
$PAGE->set_title($streditingquiz);
|
2010-05-21 03:15:48 +00:00
|
|
|
$PAGE->set_heading($course->fullname);
|
2009-09-08 01:57:28 +00:00
|
|
|
echo $OUTPUT->header();
|
2008-11-20 06:59:11 +00:00
|
|
|
|
quiz editing: MDL-17454 first attemtp, and MDL-18554
This is a minimal fix for MDL-18554, I have just added a cancel button and made it work.
The more substantial part of this is MDL-17454, trying to make the quiz editing screen behave appropriately when shuffle questions is on. I am sure Olli will have opinions about this and want to change it further. Rought summary:
* When shufflequestions is off, never restrict manual paging, even if questionsperpage is set.
* When shuffle questions is on:
** Always display the quiz with the defined number of questions per page.
** Remove controls to add things except at the end of the quiz.
** Disable most of the order and paging tab, but still allow the question list to be reordered, in case that helps teachers track which questions they have added.
** Still allow questions to be reordered on the edit tab, but when moving the top question on a page up, reorder with the previous question, rather than moving to the previous page.
* Change the status bar, so that the yellow highlight is reserved for alert information. The more informative stuff is now plain, and moved to under the title. To my mind that associates it more closely with the quiz name. Also it moves Total of grades and Maximum grade closer together.
* JavaScript cleaned up. I learn more about YUI every day.
* Some PHP code clean ups that I forgot to commit separately before making substantive changes.
2009-03-17 09:51:34 +00:00
|
|
|
if (!$quizname = $DB->get_field($cm->modname, 'name', array('id' => $cm->instance))) {
|
2009-03-17 08:21:37 +00:00
|
|
|
print_error('invalidcoursemodule');
|
|
|
|
}
|
2008-11-20 06:59:11 +00:00
|
|
|
|
2013-11-05 18:52:24 +08:00
|
|
|
echo $OUTPUT->heading(get_string('addrandomquestiontoquiz', 'quiz', $quizname), 2);
|
2010-11-22 09:52:42 +00:00
|
|
|
$mform->display();
|
2009-08-06 14:13:48 +00:00
|
|
|
echo $OUTPUT->footer();
|
2009-11-04 11:58:30 +00:00
|
|
|
|