mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
moved question sort order and paging params to be passed from page to page as get params instead of being saved in session var.
This commit is contained in:
parent
fcdb06c470
commit
b72ff47685
7 changed files with 268 additions and 248 deletions
|
@ -29,71 +29,37 @@
|
||||||
require_once("../../config.php");
|
require_once("../../config.php");
|
||||||
require_once($CFG->dirroot.'/mod/quiz/editlib.php');
|
require_once($CFG->dirroot.'/mod/quiz/editlib.php');
|
||||||
|
|
||||||
require_login();
|
|
||||||
|
|
||||||
$quizid = optional_param('quizid', 0, PARAM_INT);
|
list($thispageurl, $courseid, $cmid, $cm, $quiz, $pagevars) = question_edit_setup(true);
|
||||||
|
|
||||||
|
|
||||||
$strquizzes = get_string('modulenameplural', 'quiz');
|
$strquizzes = get_string('modulenameplural', 'quiz');
|
||||||
$strquiz = get_string('modulename', 'quiz');
|
$strquiz = get_string('modulename', 'quiz');
|
||||||
$streditingquestions = get_string('editquestions', "quiz");
|
$streditingquestions = get_string('editquestions', "quiz");
|
||||||
$streditingquiz = get_string("editinga", "moodle", $strquiz);
|
$streditingquiz = get_string('editinga', 'moodle', $strquiz);
|
||||||
|
|
||||||
if ($modform = data_submitted() and !empty($modform->course)) { // data submitted
|
|
||||||
|
|
||||||
$SESSION->modform = $modform; // Save the form in the current session
|
|
||||||
|
|
||||||
} else if ($quizid) {
|
|
||||||
if (isset($SESSION->modform->id) and $SESSION->modform->id == $quizid) {
|
|
||||||
// modform for this quiz already exists, use it
|
|
||||||
$modform = $SESSION->modform;
|
|
||||||
} else {
|
|
||||||
// create new modform from database
|
|
||||||
if (! $modform = get_record('quiz', 'id', $quizid)) {
|
|
||||||
error("The required quiz doesn't exist");
|
|
||||||
}
|
|
||||||
$modform->instance = $modform->id;
|
|
||||||
$SESSION->modform = $modform; // Save the form in the current session
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (!empty($sortorder)) {
|
|
||||||
// no quiz or course was specified so we need to use the stored modform
|
|
||||||
if (isset($SESSION->modform)) {
|
|
||||||
$modform = $SESSION->modform;
|
|
||||||
} else {
|
|
||||||
error('cmunknown');
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// no quiz or course was specified so we need to use the stored modform
|
|
||||||
if (isset($SESSION->modform)) {
|
|
||||||
$modform = $SESSION->modform;
|
|
||||||
} else {
|
|
||||||
print_error('cmunknown');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the course object and related bits.
|
// Get the course object and related bits.
|
||||||
if (! $course = get_record("course", "id", $modform->course)) {
|
if (! $course = get_record("course", "id", $quiz->course)) {
|
||||||
error("This course doesn't exist");
|
error("This course doesn't exist");
|
||||||
}
|
}
|
||||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $modform->course);
|
$coursecontext = get_context_instance(CONTEXT_COURSE, $quiz->course);
|
||||||
|
$quizcontext = get_context_instance(CONTEXT_MODULE, $quiz->cmid);
|
||||||
|
|
||||||
require_login($course->id, false);
|
require_login($course->id, false);
|
||||||
|
|
||||||
// Get the module and related bits.
|
|
||||||
$cm = get_coursemodule_from_instance('quiz', $modform->instance);
|
|
||||||
$modform->cmid = $cm->id;
|
|
||||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
|
||||||
|
|
||||||
// Log this visit.
|
// Log this visit.
|
||||||
add_to_log($cm->course, 'quiz', 'editquestions',
|
add_to_log($cm->course, 'quiz', 'editquestions',
|
||||||
"view.php?id=$cm->id", "$quizid", $cm->id);
|
"view.php?id=$cm->id", "$quiz->id", $cm->id);
|
||||||
|
|
||||||
require_capability('mod/quiz:manage', $context);
|
require_capability('mod/quiz:manage', $quizcontext);
|
||||||
|
|
||||||
if (isset($modform->instance)
|
if (isset($quiz->instance)
|
||||||
&& empty($modform->grades)) // Construct an array to hold all the grades.
|
&& empty($quiz->grades)){ // Construct an array to hold all the grades.
|
||||||
{
|
$quiz->grades = quiz_get_all_question_grades($quiz);
|
||||||
$modform->grades = quiz_get_all_question_grades($modform);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$SESSION->returnurl = $FULLME;
|
$SESSION->returnurl = $FULLME;
|
||||||
|
@ -102,18 +68,18 @@
|
||||||
|
|
||||||
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
|
||||||
$up = optional_param('up', 0, PARAM_INT);
|
$up = optional_param('up', 0, PARAM_INT);
|
||||||
$questions = explode(",", $modform->questions);
|
$questions = explode(",", $quiz->questions);
|
||||||
if ($up > 0 and isset($questions[$up])) {
|
if ($up > 0 and isset($questions[$up])) {
|
||||||
$prevkey = ($questions[$up-1] == 0) ? $up-2 : $up-1;
|
$prevkey = ($questions[$up-1] == 0) ? $up-2 : $up-1;
|
||||||
$swap = $questions[$prevkey];
|
$swap = $questions[$prevkey];
|
||||||
$questions[$prevkey] = $questions[$up];
|
$questions[$prevkey] = $questions[$up];
|
||||||
$questions[$up] = $swap;
|
$questions[$up] = $swap;
|
||||||
$modform->questions = implode(",", $questions);
|
$quiz->questions = implode(",", $questions);
|
||||||
// Always have a page break at the end
|
// Always have a page break at the end
|
||||||
$modform->questions = $modform->questions . ',0';
|
$quiz->questions = $quiz->questions . ',0';
|
||||||
// Avoid duplicate page breaks
|
// Avoid duplicate page breaks
|
||||||
$modform->questions = str_replace(',0,0', ',0', $modform->questions);
|
$quiz->questions = str_replace(',0,0', ',0', $quiz->questions);
|
||||||
if (!set_field('quiz', 'questions', $modform->questions, 'id', $modform->instance)) {
|
if (!set_field('quiz', 'questions', $quiz->questions, 'id', $quiz->instance)) {
|
||||||
error('Could not save question list');
|
error('Could not save question list');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,29 +87,30 @@
|
||||||
|
|
||||||
if (isset($_REQUEST['down']) and confirm_sesskey()) { /// Move the given question down a slot
|
if (isset($_REQUEST['down']) and confirm_sesskey()) { /// Move the given question down a slot
|
||||||
$down = optional_param('down', 0, PARAM_INT);
|
$down = optional_param('down', 0, PARAM_INT);
|
||||||
$questions = explode(",", $modform->questions);
|
$questions = explode(",", $quiz->questions);
|
||||||
if ($down < count($questions)) {
|
if ($down < count($questions)) {
|
||||||
$nextkey = ($questions[$down+1] == 0) ? $down+2 : $down+1;
|
$nextkey = ($questions[$down+1] == 0) ? $down+2 : $down+1;
|
||||||
$swap = $questions[$nextkey];
|
$swap = $questions[$nextkey];
|
||||||
$questions[$nextkey] = $questions[$down];
|
$questions[$nextkey] = $questions[$down];
|
||||||
$questions[$down] = $swap;
|
$questions[$down] = $swap;
|
||||||
$modform->questions = implode(",", $questions);
|
$quiz->questions = implode(",", $questions);
|
||||||
// Avoid duplicate page breaks
|
// Avoid duplicate page breaks
|
||||||
$modform->questions = str_replace(',0,0', ',0', $modform->questions);
|
$quiz->questions = str_replace(',0,0', ',0', $quiz->questions);
|
||||||
if (!set_field('quiz', 'questions', $modform->questions, 'id', $modform->instance)) {
|
if (!set_field('quiz', 'questions', $quiz->questions, 'id', $quiz->instance)) {
|
||||||
error('Could not save question list');
|
error('Could not save question list');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($_REQUEST['addquestion']) and confirm_sesskey()) { /// Add a single question to the current quiz
|
if (isset($_REQUEST['addquestion']) and confirm_sesskey()) { /// Add a single question to the current quiz
|
||||||
quiz_add_quiz_question($_REQUEST['addquestion'], $modform);
|
quiz_add_quiz_question($_REQUEST['addquestion'], $quiz);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($_REQUEST['add']) and confirm_sesskey()) { /// Add selected questions to the current quiz
|
if (isset($_REQUEST['add']) and confirm_sesskey()) { /// Add selected questions to the current quiz
|
||||||
foreach ($_POST as $key => $value) { // Parse input for question ids
|
foreach ($_POST as $key => $value) { // Parse input for question ids
|
||||||
if (substr($key, 0, 1) == "q") {
|
if (preg_match('!q([0-9]+)!', $key, $matches)) {
|
||||||
quiz_add_quiz_question(substr($key,1), $modform);
|
$key = $matches[1];
|
||||||
|
quiz_add_quiz_question($key, $quiz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,7 +128,7 @@
|
||||||
$random = RANDOM;
|
$random = RANDOM;
|
||||||
if ($existingquestions = get_records_select('question', "qtype = '$random' AND category = '$category->id'")) {
|
if ($existingquestions = get_records_select('question', "qtype = '$random' AND category = '$category->id'")) {
|
||||||
// now remove the ones that are already used in this quiz
|
// now remove the ones that are already used in this quiz
|
||||||
if ($questionids = explode(',', $modform->questions)) {
|
if ($questionids = explode(',', $quiz->questions)) {
|
||||||
foreach ($questionids as $questionid) {
|
foreach ($questionids as $questionid) {
|
||||||
unset($existingquestions[$questionid]);
|
unset($existingquestions[$questionid]);
|
||||||
}
|
}
|
||||||
|
@ -171,7 +138,7 @@
|
||||||
while (($existingquestion = array_pop($existingquestions)) and ($i < $randomcount)) {
|
while (($existingquestion = array_pop($existingquestions)) and ($i < $randomcount)) {
|
||||||
if ($existingquestion->questiontext == $recurse) {
|
if ($existingquestion->questiontext == $recurse) {
|
||||||
// this question has the right recurse property, so use it
|
// this question has the right recurse property, so use it
|
||||||
quiz_add_quiz_question($existingquestion->id, $modform);
|
quiz_add_quiz_question($existingquestion->id, $quiz);
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -198,45 +165,41 @@
|
||||||
if(!isset($question->id)) {
|
if(!isset($question->id)) {
|
||||||
error('Could not insert new random question!');
|
error('Could not insert new random question!');
|
||||||
}
|
}
|
||||||
quiz_add_quiz_question($question->id, $modform);
|
quiz_add_quiz_question($question->id, $quiz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($_REQUEST['repaginate']) and confirm_sesskey()) { /// Re-paginate the quiz
|
if (isset($_REQUEST['repaginate']) and confirm_sesskey()) { /// Re-paginate the quiz
|
||||||
if (isset($_REQUEST['questionsperpage'])) {
|
if (isset($_REQUEST['questionsperpage'])) {
|
||||||
$modform->questionsperpage = required_param('questionsperpage', PARAM_INT);
|
$quiz->questionsperpage = required_param('questionsperpage', PARAM_INT);
|
||||||
if (!set_field('quiz', 'questionsperpage', $modform->questionsperpage, 'id', $modform->id)) {
|
if (!set_field('quiz', 'questionsperpage', $quiz->questionsperpage, 'id', $quiz->id)) {
|
||||||
error('Could not save number of questions per page');
|
error('Could not save number of questions per page');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$modform->questions = quiz_repaginate($modform->questions, $modform->questionsperpage);
|
$quiz->questions = quiz_repaginate($quiz->questions, $quiz->questionsperpage);
|
||||||
if (!set_field('quiz', 'questions', $modform->questions, 'id', $modform->id)) {
|
if (!set_field('quiz', 'questions', $quiz->questions, 'id', $quiz->id)) {
|
||||||
error('Could not save layout');
|
error('Could not save layout');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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'], $quiz);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($_REQUEST['savechanges']) and confirm_sesskey()) {
|
if (isset($_REQUEST['savechanges']) and confirm_sesskey()) {
|
||||||
$savequizid = required_param('savequizid', PARAM_INT);
|
|
||||||
if ($modform->id != $savequizid) {
|
|
||||||
error("Error saving quiz settings, please do not change two quizes from the same browser", $CFG->wwwroot.'/mod/quiz/edit.php?quizid='.$savequizid);
|
|
||||||
}
|
|
||||||
/// 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(",", $quiz->questions); // the questions in the old order
|
||||||
$questions = array(); // for questions in the new order
|
$questions = array(); // for questions in the new order
|
||||||
$rawgrades = $_POST;
|
$rawgrades = $_POST;
|
||||||
unset($modform->grades);
|
unset($quiz->grades);
|
||||||
foreach ($rawgrades as $key => $value) { // Parse input for question -> grades
|
foreach ($rawgrades as $key => $value) { // Parse input for question -> grades
|
||||||
if (substr($key, 0, 1) == "q") {
|
if (preg_match('!q([0-9]+)!', $key, $matches)) {
|
||||||
$key = substr($key,1);
|
$key = $matches[1];
|
||||||
$modform->grades[$key] = $value;
|
$quiz->grades[$key] = $value;
|
||||||
quiz_update_question_instance($modform->grades[$key], $key, $modform->instance);
|
quiz_update_question_instance($quiz->grades[$key], $key, $quiz->instance);
|
||||||
} elseif (substr($key, 0, 1) == "o") { // Parse input for ordering info
|
} elseif (preg_match('!q([0-9]+)!', $key, $matches)) { // Parse input for ordering info
|
||||||
$key = substr($key,1);
|
$key = $matches[1];
|
||||||
$questions[$value] = $oldquestions[$key];
|
$questions[$value] = $oldquestions[$key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -244,21 +207,21 @@
|
||||||
// If ordering info was given, reorder the questions
|
// If ordering info was given, reorder the questions
|
||||||
if ($questions) {
|
if ($questions) {
|
||||||
ksort($questions);
|
ksort($questions);
|
||||||
$modform->questions = implode(",", $questions);
|
$quiz->questions = implode(",", $questions);
|
||||||
// Always have a page break at the end
|
// Always have a page break at the end
|
||||||
$modform->questions = $modform->questions . ',0';
|
$quiz->questions = $quiz->questions . ',0';
|
||||||
// Avoid duplicate page breaks
|
// Avoid duplicate page breaks
|
||||||
while (strpos($modform->questions, ',0,0')) {
|
while (strpos($quiz->questions, ',0,0')) {
|
||||||
$modform->questions = str_replace(',0,0', ',0', $modform->questions);
|
$quiz->questions = str_replace(',0,0', ',0', $quiz->questions);
|
||||||
}
|
}
|
||||||
if (!set_field('quiz', 'questions', $modform->questions, 'id', $modform->instance)) {
|
if (!set_field('quiz', 'questions', $quiz->questions, 'id', $quiz->instance)) {
|
||||||
error('Could not save question list');
|
error('Could not save question list');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If rescaling is required save the new maximum
|
// If rescaling is required save the new maximum
|
||||||
if (isset($_REQUEST['maxgrade'])) {
|
if (isset($_REQUEST['maxgrade'])) {
|
||||||
if (!quiz_set_grade(optional_param('maxgrade', 0), $modform)) {
|
if (!quiz_set_grade(optional_param('maxgrade', 0), $quiz)) {
|
||||||
error('Could not set a new maximum grade for the quiz');
|
error('Could not set a new maximum grade for the quiz');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -271,14 +234,14 @@
|
||||||
|
|
||||||
/// 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['savechanges']) 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['savechanges']) or isset($_REQUEST['delete']) or isset($_REQUEST['repaginate']) or isset($_REQUEST['addrandom']) or isset($_REQUEST['addquestion']) or isset($_REQUEST['up']) or isset($_REQUEST['down']) or isset($_REQUEST['add'])) {
|
||||||
delete_records('quiz_attempts', 'preview', '1', 'quiz', $modform->id);
|
delete_records('quiz_attempts', 'preview', '1', 'quiz', $quiz->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// all commands have been dealt with, now print the page
|
/// all commands have been dealt with, now print the page
|
||||||
|
|
||||||
if (empty($modform->category) or !record_exists('question_categories', 'id', $modform->category)) {
|
if (empty($quiz->category) or !record_exists('question_categories', 'id', $quiz->category)) {
|
||||||
$category = get_default_question_category($course->id);
|
$category = get_default_question_category($course->id);
|
||||||
$modform->category = $category->id;
|
$quiz->category = $category->id;
|
||||||
}
|
}
|
||||||
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;
|
||||||
|
@ -287,17 +250,16 @@
|
||||||
$SESSION->quiz_reordertool = 0;
|
$SESSION->quiz_reordertool = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$SESSION->modform = $modform;
|
|
||||||
|
|
||||||
// Print basic page layout.
|
// Print basic page layout.
|
||||||
|
|
||||||
if (isset($modform->instance) and record_exists_select('quiz_attempts', "quiz = '$modform->instance' AND preview = '0'")){
|
if (isset($quiz->instance) and record_exists_select('quiz_attempts', "quiz = '$quiz->instance' AND preview = '0'")){
|
||||||
// one column layout with table of questions used in this quiz
|
// one column layout with table of questions used in this quiz
|
||||||
$strupdatemodule = has_capability('moodle/course:manageactivities', $coursecontext)
|
$strupdatemodule = has_capability('moodle/course:manageactivities', $coursecontext)
|
||||||
? update_module_button($modform->cmid, $course->id, get_string('modulename', 'quiz'))
|
? update_module_button($cm->id, $course->id, get_string('modulename', 'quiz'))
|
||||||
: "";
|
: "";
|
||||||
$crumbs[] = array('name' => $strquizzes, 'link' => "index.php?id=$course->id", 'type' => 'activity');
|
$crumbs[] = array('name' => $strquizzes, 'link' => "index.php?id=$course->id", 'type' => 'activity');
|
||||||
$crumbs[] = array('name' => format_string($modform->name), 'link' => "view.php?q=$modform->instance", 'type' => 'activityinstance');
|
$crumbs[] = array('name' => format_string($quiz->name), 'link' => "view.php?q=$quiz->instance", 'type' => 'activityinstance');
|
||||||
$crumbs[] = array('name' => $streditingquiz, 'link' => '', 'type' => 'title');
|
$crumbs[] = array('name' => $streditingquiz, 'link' => '', 'type' => 'title');
|
||||||
$navigation = build_navigation($crumbs);
|
$navigation = build_navigation($crumbs);
|
||||||
|
|
||||||
|
@ -306,7 +268,7 @@
|
||||||
|
|
||||||
$currenttab = 'edit';
|
$currenttab = 'edit';
|
||||||
$mode = 'editq';
|
$mode = 'editq';
|
||||||
$quiz = &$modform;
|
|
||||||
include('tabs.php');
|
include('tabs.php');
|
||||||
|
|
||||||
print_box_start();
|
print_box_start();
|
||||||
|
@ -314,15 +276,15 @@
|
||||||
$a->attemptnum = count_records('quiz_attempts', 'quiz', $quiz->id, 'preview', 0);
|
$a->attemptnum = count_records('quiz_attempts', 'quiz', $quiz->id, 'preview', 0);
|
||||||
$a->studentnum = count_records_select('quiz_attempts', "quiz = '$quiz->id' AND preview = '0'", 'COUNT(DISTINCT userid)');
|
$a->studentnum = count_records_select('quiz_attempts', "quiz = '$quiz->id' AND preview = '0'", 'COUNT(DISTINCT userid)');
|
||||||
$a->studentstring = $course->students;
|
$a->studentstring = $course->students;
|
||||||
if (! $cm = get_coursemodule_from_instance("quiz", $modform->instance, $course->id)) {
|
if (! $cm = get_coursemodule_from_instance("quiz", $quiz->instance, $course->id)) {
|
||||||
error("Course Module ID was incorrect");
|
error("Course Module ID was incorrect");
|
||||||
}
|
}
|
||||||
echo "<div class=\"attemptsnotice\">\n";
|
echo "<div class=\"attemptsnotice\">\n";
|
||||||
echo "<a href=\"report.php?mode=overview&id=$cm->id\">".get_string('numattempts', 'quiz', $a)."</a><br />".get_string("attemptsexist","quiz");
|
echo "<a href=\"report.php?mode=overview&id=$cm->id\">".get_string('numattempts', 'quiz', $a)."</a><br />".get_string("attemptsexist","quiz");
|
||||||
echo "</div><br />\n";
|
echo "</div><br />\n";
|
||||||
|
|
||||||
$sumgrades = quiz_print_question_list($modform, false, $SESSION->quiz_showbreaks, $SESSION->quiz_reordertool);
|
$sumgrades = quiz_print_question_list($quiz, $thispageurl, false, $SESSION->quiz_showbreaks, $SESSION->quiz_reordertool);
|
||||||
if (!set_field('quiz', 'sumgrades', $sumgrades, 'id', $modform->instance)) {
|
if (!set_field('quiz', 'sumgrades', $sumgrades, 'id', $quiz->instance)) {
|
||||||
error('Failed to set sumgrades');
|
error('Failed to set sumgrades');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,11 +295,11 @@
|
||||||
|
|
||||||
// two column layout with quiz info in left column
|
// two column layout with quiz info in left column
|
||||||
$strupdatemodule = has_capability('moodle/course:manageactivities', $coursecontext)
|
$strupdatemodule = has_capability('moodle/course:manageactivities', $coursecontext)
|
||||||
? update_module_button($modform->cmid, $course->id, get_string('modulename', 'quiz'))
|
? update_module_button($cm->id, $course->id, get_string('modulename', 'quiz'))
|
||||||
: "";
|
: "";
|
||||||
|
|
||||||
$crumbs[] = array('name' => $strquizzes, 'link' => "index.php?id=$course->id", 'type' => 'activity');
|
$crumbs[] = array('name' => $strquizzes, 'link' => "index.php?id=$course->id", 'type' => 'activity');
|
||||||
$crumbs[] = array('name' => format_string($modform->name), 'link' => "view.php?q=$modform->instance", 'type' => 'activityinstance');
|
$crumbs[] = array('name' => format_string($quiz->name), 'link' => "view.php?q=$quiz->instance", 'type' => 'activityinstance');
|
||||||
$crumbs[] = array('name' => $streditingquiz, 'link' => '', 'type' => 'title');
|
$crumbs[] = array('name' => $streditingquiz, 'link' => '', 'type' => 'title');
|
||||||
$navigation = build_navigation($crumbs);
|
$navigation = build_navigation($crumbs);
|
||||||
|
|
||||||
|
@ -345,7 +307,7 @@
|
||||||
|
|
||||||
$currenttab = 'edit';
|
$currenttab = 'edit';
|
||||||
$mode = 'editq';
|
$mode = 'editq';
|
||||||
$quiz = &$modform;
|
|
||||||
include('tabs.php');
|
include('tabs.php');
|
||||||
|
|
||||||
echo '<table border="0" style="width:100%" cellpadding="2" cellspacing="0">';
|
echo '<table border="0" style="width:100%" cellpadding="2" cellspacing="0">';
|
||||||
|
@ -353,8 +315,8 @@
|
||||||
print_box_start('generalbox quizquestions');
|
print_box_start('generalbox quizquestions');
|
||||||
print_heading(get_string('questionsinthisquiz', 'quiz'), '', 2);
|
print_heading(get_string('questionsinthisquiz', 'quiz'), '', 2);
|
||||||
|
|
||||||
$sumgrades = quiz_print_question_list($modform, true, $SESSION->quiz_showbreaks, $SESSION->quiz_reordertool);
|
$sumgrades = quiz_print_question_list($quiz, $thispageurl, true, $SESSION->quiz_showbreaks, $SESSION->quiz_reordertool);
|
||||||
if (!set_field('quiz', 'sumgrades', $sumgrades, 'id', $modform->instance)) {
|
if (!set_field('quiz', 'sumgrades', $sumgrades, 'id', $quiz->instance)) {
|
||||||
error('Failed to set sumgrades');
|
error('Failed to set sumgrades');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -362,7 +324,7 @@
|
||||||
|
|
||||||
echo '</td><td style="width:50%" valign="top">';
|
echo '</td><td style="width:50%" valign="top">';
|
||||||
|
|
||||||
require($CFG->dirroot.'/question/showbank.php');
|
question_showbank($thispageurl, $cm, $pagevars['qpage'], $pagevars['qperpage'], $pagevars['qsortorder']);
|
||||||
|
|
||||||
echo '</td></tr>';
|
echo '</td></tr>';
|
||||||
echo '</table>';
|
echo '</table>';
|
||||||
|
|
|
@ -15,17 +15,17 @@ require_once("locallib.php");
|
||||||
/**
|
/**
|
||||||
* Delete a question from a quiz
|
* Delete a question from a quiz
|
||||||
*
|
*
|
||||||
* Deletes a question or a pagebreak from a quiz by updating $modform
|
* Deletes a question or a pagebreak from a quiz by updating $quiz
|
||||||
* as well as the quiz, quiz_question_instances
|
* as well as the quiz, quiz_question_instances
|
||||||
* @return boolean false if the question was not in the quiz
|
* @return boolean false if the question was not in the quiz
|
||||||
* @param int $id The id of the question to be deleted
|
* @param int $id The id of the question to be deleted
|
||||||
* @param object $modform The extended quiz object as used by edit.php
|
* @param object $quiz The extended quiz object as used by edit.php
|
||||||
* This is updated by this function
|
* This is updated by this function
|
||||||
*/
|
*/
|
||||||
function quiz_delete_quiz_question($id, &$modform) {
|
function quiz_delete_quiz_question($id, &$quiz) {
|
||||||
// TODO: For the sake of safety check that this question can be deleted
|
// TODO: For the sake of safety check that this question can be deleted
|
||||||
// safely, i.e., that it is not already in use.
|
// safely, i.e., that it is not already in use.
|
||||||
$questions = explode(",", $modform->questions);
|
$questions = explode(",", $quiz->questions);
|
||||||
|
|
||||||
// only do something if this question exists
|
// only do something if this question exists
|
||||||
if (!isset($questions[$id])) {
|
if (!isset($questions[$id])) {
|
||||||
|
@ -39,14 +39,14 @@ function quiz_delete_quiz_question($id, &$modform) {
|
||||||
if ($id == 0 && count($questions) > 1 && $questions[1] == 0) {
|
if ($id == 0 && count($questions) > 1 && $questions[1] == 0) {
|
||||||
unset($questions[1]);
|
unset($questions[1]);
|
||||||
}
|
}
|
||||||
$modform->questions = implode(",", $questions);
|
$quiz->questions = implode(",", $questions);
|
||||||
// Avoid duplicate page breaks
|
// Avoid duplicate page breaks
|
||||||
$modform->questions = str_replace(',0,0', ',0', $modform->questions);
|
$quiz->questions = str_replace(',0,0', ',0', $quiz->questions);
|
||||||
// save new questionlist in database
|
// save new questionlist in database
|
||||||
if (!set_field('quiz', 'questions', $modform->questions, 'id', $modform->instance)) {
|
if (!set_field('quiz', 'questions', $quiz->questions, 'id', $quiz->instance)) {
|
||||||
error('Could not save question list');
|
error('Could not save question list');
|
||||||
}
|
}
|
||||||
delete_records('quiz_question_instances', 'quiz', $modform->instance, 'question', $question);
|
delete_records('quiz_question_instances', 'quiz', $quiz->instance, 'question', $question);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,16 +54,16 @@ function quiz_delete_quiz_question($id, &$modform) {
|
||||||
/**
|
/**
|
||||||
* Add a question to a quiz
|
* Add a question to a quiz
|
||||||
*
|
*
|
||||||
* Adds a question to a quiz by updating $modform as well as the
|
* Adds a question to a quiz by updating $quiz as well as the
|
||||||
* quiz and quiz_question_instances tables. It also adds a page break
|
* quiz and quiz_question_instances tables. It also adds a page break
|
||||||
* if required.
|
* if required.
|
||||||
* @return boolean false if the question was already in the quiz
|
* @return boolean false if the question was already in the quiz
|
||||||
* @param int $id The id of the question to be added
|
* @param int $id The id of the question to be added
|
||||||
* @param object $modform The extended quiz object as used by edit.php
|
* @param object $quiz The extended quiz object as used by edit.php
|
||||||
* This is updated by this function
|
* This is updated by this function
|
||||||
*/
|
*/
|
||||||
function quiz_add_quiz_question($id, &$modform) {
|
function quiz_add_quiz_question($id, &$quiz) {
|
||||||
$questions = explode(",", $modform->questions);
|
$questions = explode(",", $quiz->questions);
|
||||||
|
|
||||||
if (in_array($id, $questions)) {
|
if (in_array($id, $questions)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -75,7 +75,7 @@ function quiz_add_quiz_question($id, &$modform) {
|
||||||
$end = end($breaks);
|
$end = end($breaks);
|
||||||
$last = prev($breaks);
|
$last = prev($breaks);
|
||||||
$last = $last ? $last : -1;
|
$last = $last ? $last : -1;
|
||||||
if (!$modform->questionsperpage or (($end - $last -1) < $modform->questionsperpage)) {
|
if (!$quiz->questionsperpage or (($end - $last -1) < $quiz->questionsperpage)) {
|
||||||
array_pop($questions);
|
array_pop($questions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,15 +85,16 @@ function quiz_add_quiz_question($id, &$modform) {
|
||||||
$questions[] = 0;
|
$questions[] = 0;
|
||||||
|
|
||||||
// Save new questionslist in database
|
// Save new questionslist in database
|
||||||
$modform->questions = implode(",", $questions);
|
$quiz->questions = implode(",", $questions);
|
||||||
if (!set_field('quiz', 'questions', $modform->questions, 'id', $modform->id)) {
|
if (!set_field('quiz', 'questions', $quiz->questions, 'id', $quiz->id)) {
|
||||||
error('Could not save question list');
|
error('Could not save question list');
|
||||||
}
|
}
|
||||||
|
|
||||||
// update question grades
|
// update question grades
|
||||||
$questionrecord = get_record("question", "id", $id);
|
$questionrecord = get_record("question", "id", $id);
|
||||||
$modform->grades[$id] = $questionrecord->defaultgrade;
|
$quiz->grades[$id]
|
||||||
quiz_update_question_instance($modform->grades[$id], $id, $modform->instance);
|
= $questionrecord->defaultgrade;
|
||||||
|
quiz_update_question_instance($quiz->grades[$id], $id, $quiz->instance);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -132,7 +133,7 @@ function quiz_update_question_instance($grade, $questionid, $quizid) {
|
||||||
* @param boolean $showbreaks Indicates whether the page breaks should be displayed
|
* @param boolean $showbreaks Indicates whether the page breaks should be displayed
|
||||||
* @param boolean $showbreaks Indicates whether the reorder tool should be displayed
|
* @param boolean $showbreaks Indicates whether the reorder tool should be displayed
|
||||||
*/
|
*/
|
||||||
function quiz_print_question_list($quiz, $allowdelete=true, $showbreaks=true, $reordertool=false) {
|
function quiz_print_question_list($quiz, $pageurl, $allowdelete=true, $showbreaks=true, $reordertool=false) {
|
||||||
global $USER, $CFG, $QTYPES;
|
global $USER, $CFG, $QTYPES;
|
||||||
|
|
||||||
$strorder = get_string("order");
|
$strorder = get_string("order");
|
||||||
|
@ -178,6 +179,7 @@ function quiz_print_question_list($quiz, $allowdelete=true, $showbreaks=true, $r
|
||||||
echo "<form method=\"post\" action=\"edit.php\">";
|
echo "<form method=\"post\" action=\"edit.php\">";
|
||||||
echo '<fieldset class="invisiblefieldset" style="display: block;">';
|
echo '<fieldset class="invisiblefieldset" style="display: block;">';
|
||||||
echo "<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
|
echo "<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
|
||||||
|
echo $pageurl->hidden_params_out();
|
||||||
|
|
||||||
echo "<table style=\"width:100%;\">\n";
|
echo "<table style=\"width:100%;\">\n";
|
||||||
echo "<tr><th colspan=\"3\" style=\"white-space:nowrap;\" class=\"header\" scope=\"col\">$strorder</th>";
|
echo "<tr><th colspan=\"3\" style=\"white-space:nowrap;\" class=\"header\" scope=\"col\">$strorder</th>";
|
||||||
|
@ -218,15 +220,15 @@ function quiz_print_question_list($quiz, $allowdelete=true, $showbreaks=true, $r
|
||||||
echo '<td><hr /></td>';
|
echo '<td><hr /></td>';
|
||||||
echo '<td style="width:45px;">';
|
echo '<td style="width:45px;">';
|
||||||
if ($count > 1) {
|
if ($count > 1) {
|
||||||
echo "<a title=\"$strmoveup\" href=\"edit.php?up=$count&quizid=$quiz->id&sesskey=$USER->sesskey\"><img
|
echo "<a title=\"$strmoveup\" href=\"".$pageurl->out_action(array('up'=>$count))."\"><img
|
||||||
src=\"$CFG->pixpath/t/up.gif\" class=\"iconsmall\" alt=\"$strmoveup\" /></a>";
|
src=\"$CFG->pixpath/t/up.gif\" class=\"iconsmall\" alt=\"$strmoveup\" /></a>";
|
||||||
}
|
}
|
||||||
echo ' ';
|
echo ' ';
|
||||||
if ($count < $lastindex) {
|
if ($count < $lastindex) {
|
||||||
echo "<a title=\"$strmovedown\" href=\"edit.php?down=$count&quizid=$quiz->id&sesskey=$USER->sesskey\"><img
|
echo "<a title=\"$strmovedown\" href=\"".$pageurl->out_action(array('down'=>$count))."\"><img
|
||||||
src=\"$CFG->pixpath/t/down.gif\" class=\"iconsmall\" alt=\"$strmovedown\" /></a>";
|
src=\"$CFG->pixpath/t/down.gif\" class=\"iconsmall\" alt=\"$strmovedown\" /></a>";
|
||||||
|
|
||||||
echo "<a title=\"$strremove\" href=\"edit.php?delete=$count&quizid=$quiz->id&sesskey=$USER->sesskey\">
|
echo "<a title=\"$strremove\" href=\"".$pageurl->out_action(array('delete'=>$count))."\">
|
||||||
<img src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strremove\" /></a>";
|
<img src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strremove\" /></a>";
|
||||||
}
|
}
|
||||||
echo '</td></tr></table></td>';
|
echo '</td></tr></table></td>';
|
||||||
|
@ -242,13 +244,13 @@ function quiz_print_question_list($quiz, $allowdelete=true, $showbreaks=true, $r
|
||||||
|
|
||||||
echo "<td>";
|
echo "<td>";
|
||||||
if ($count != 0) {
|
if ($count != 0) {
|
||||||
echo "<a title=\"$strmoveup\" href=\"edit.php?up=$count&quizid=$quiz->id&sesskey=$USER->sesskey\"><img
|
echo "<a title=\"$strmoveup\" href=\"".$pageurl->out_action(array('up'=>$count))."\"><img
|
||||||
src=\"$CFG->pixpath/t/up.gif\" class=\"iconsmall\" alt=\"$strmoveup\" /></a>";
|
src=\"$CFG->pixpath/t/up.gif\" class=\"iconsmall\" alt=\"$strmoveup\" /></a>";
|
||||||
}
|
}
|
||||||
echo "</td>";
|
echo "</td>";
|
||||||
echo "<td>";
|
echo "<td>";
|
||||||
if ($count < $lastindex-1) {
|
if ($count < $lastindex-1) {
|
||||||
echo "<a title=\"$strmovedown\" href=\"edit.php?down=$count&quizid=$quiz->id&sesskey=$USER->sesskey\"><img
|
echo "<a title=\"$strmovedown\" href=\"".$pageurl->out_action(array('down'=>$count))."\"><img
|
||||||
src=\"$CFG->pixpath/t/down.gif\" class=\"iconsmall\" alt=\"$strmovedown\" /></a>";
|
src=\"$CFG->pixpath/t/down.gif\" class=\"iconsmall\" alt=\"$strmovedown\" /></a>";
|
||||||
}
|
}
|
||||||
echo "</td>";
|
echo "</td>";
|
||||||
|
@ -283,7 +285,7 @@ function quiz_print_question_list($quiz, $allowdelete=true, $showbreaks=true, $r
|
||||||
<img src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a>";
|
<img src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a>";
|
||||||
}
|
}
|
||||||
if ($allowdelete) {
|
if ($allowdelete) {
|
||||||
echo "<a title=\"$strremove\" href=\"edit.php?delete=$count&quizid=$quiz->id&sesskey=$USER->sesskey\">
|
echo "<a title=\"$strremove\" href=\"".$pageurl->out_action(array('delete'=>$count))."\">
|
||||||
<img src=\"$CFG->pixpath/t/removeright.gif\" class=\"iconsmall\" alt=\"$strremove\" /></a>";
|
<img src=\"$CFG->pixpath/t/removeright.gif\" class=\"iconsmall\" alt=\"$strremove\" /></a>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,7 +313,6 @@ function quiz_print_question_list($quiz, $allowdelete=true, $showbreaks=true, $r
|
||||||
|
|
||||||
echo '<div class="quizquestionlistcontrols"><input type="submit" value="'.get_string('savechanges').'" />';
|
echo '<div class="quizquestionlistcontrols"><input type="submit" value="'.get_string('savechanges').'" />';
|
||||||
echo '<input type="hidden" name="savechanges" value="save" /></div>';
|
echo '<input type="hidden" name="savechanges" value="save" /></div>';
|
||||||
echo '<input type="hidden" name="savequizid" value="'.$quiz->id.'" />'; // ugly hack to prevent modform session "mistakes"
|
|
||||||
|
|
||||||
echo '</fieldset>';
|
echo '</fieldset>';
|
||||||
echo "</form>\n";
|
echo "</form>\n";
|
||||||
|
@ -319,6 +320,7 @@ function quiz_print_question_list($quiz, $allowdelete=true, $showbreaks=true, $r
|
||||||
/// Form to choose to show pagebreaks and to repaginate quiz
|
/// Form to choose to show pagebreaks and to repaginate quiz
|
||||||
echo '<form method="post" action="edit.php" id="showbreaks">';
|
echo '<form method="post" action="edit.php" id="showbreaks">';
|
||||||
echo '<fieldset class="invisiblefieldset">';
|
echo '<fieldset class="invisiblefieldset">';
|
||||||
|
echo $pageurl->hidden_params_out();
|
||||||
echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
|
echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
|
||||||
echo '<input type="hidden" name="showbreaks" value="0" />';
|
echo '<input type="hidden" name="showbreaks" value="0" />';
|
||||||
echo '<input type="checkbox" name="showbreaks" value="1"';
|
echo '<input type="checkbox" name="showbreaks" value="1"';
|
||||||
|
|
|
@ -12,11 +12,16 @@
|
||||||
require_once("editlib.php");
|
require_once("editlib.php");
|
||||||
require_once("category_class.php");
|
require_once("category_class.php");
|
||||||
|
|
||||||
// get values from form
|
|
||||||
|
|
||||||
|
list($thispageurl, $courseid, $cmid, $cm, $module, $pagevars) = question_edit_setup();
|
||||||
|
|
||||||
|
|
||||||
|
// get values from form for actions on this page
|
||||||
$param = new stdClass();
|
$param = new stdClass();
|
||||||
|
|
||||||
$id = required_param('courseid', PARAM_INT); // course id
|
|
||||||
$param->page = optional_param('page', 1, PARAM_INT);
|
$param->page = optional_param('page', 1, PARAM_INT);
|
||||||
|
$thispageurl->param('page', $param->page);
|
||||||
|
|
||||||
$param->moveup = optional_param('moveup', 0, PARAM_INT);
|
$param->moveup = optional_param('moveup', 0, PARAM_INT);
|
||||||
$param->movedown = optional_param('movedown', 0, PARAM_INT);
|
$param->movedown = optional_param('movedown', 0, PARAM_INT);
|
||||||
|
@ -33,35 +38,48 @@
|
||||||
$param->edit = optional_param('edit', 0, PARAM_INT);
|
$param->edit = optional_param('edit', 0, PARAM_INT);
|
||||||
$param->updateid = optional_param('updateid', 0, PARAM_INT);
|
$param->updateid = optional_param('updateid', 0, PARAM_INT);
|
||||||
|
|
||||||
if (! $course = get_record("course", "id", $id)) {
|
if (! $course = get_record("course", "id", $courseid)) {
|
||||||
error("Course ID is incorrect");
|
error("Course ID is incorrect");
|
||||||
}
|
}
|
||||||
|
|
||||||
$context = get_context_instance(CONTEXT_COURSE, $id);
|
$context = get_context_instance(CONTEXT_COURSE, $courseid);
|
||||||
|
|
||||||
require_login($course->id, false);
|
require_login($course->id, false);
|
||||||
require_capability('moodle/question:managecategory', $context);
|
require_capability('moodle/question:managecategory', $context);
|
||||||
|
|
||||||
$qcobject = new question_category_object($param->page);
|
$qcobject = new question_category_object($param->page, $thispageurl);
|
||||||
|
|
||||||
|
$streditingcategories = get_string('editcategories', 'quiz');
|
||||||
if ($qcobject->editlist->process_actions($param->left, $param->right, $param->moveup, $param->movedown)) {
|
if ($qcobject->editlist->process_actions($param->left, $param->right, $param->moveup, $param->movedown)) {
|
||||||
//processing of these actions is handled in the method and page redirects.
|
//processing of these actions is handled in the method and page redirects.
|
||||||
} else if (isset($SESSION->modform->instance) and $quiz = get_record('quiz', 'id', $SESSION->modform->instance)) {
|
} else if ($cm!==null) {
|
||||||
// Page header
|
// Page header
|
||||||
// TODO: generalise this to any activity
|
|
||||||
$strupdatemodule = has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id))
|
$strupdatemodule = has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id))
|
||||||
? update_module_button($SESSION->modform->cmid, $course->id, get_string('modulename', 'quiz'))
|
? update_module_button($cm->id, $course->id, get_string('modulename', $cm->modname))
|
||||||
: "";
|
: "";
|
||||||
print_header_simple(get_string('editcategories', 'quiz'), '',
|
$crumbs = array();
|
||||||
"<a href=\"$CFG->wwwroot/mod/quiz/index.php?id=$course->id\">".get_string('modulenameplural', 'quiz').'</a>'.
|
$crumbs[] = array('name' => get_string('modulenameplural', $cm->modname),
|
||||||
" -> <a href=\"$CFG->wwwroot/mod/quiz/view.php?q=$quiz->id\">".format_string($quiz->name).'</a>'.
|
'link' => "$CFG->wwwroot/mod/{$cm->modname}/index.php?id=$course->id",
|
||||||
' -> '.get_string('editcategories', 'quiz'),
|
'type' => 'activity');
|
||||||
"", "", true, $strupdatemodule);
|
$crumbs[] = array('name' => format_string($module->name),
|
||||||
|
'link' => "$CFG->wwwroot/mod/{$cm->modname}/view.php?cmid={$cm->id}",
|
||||||
|
'type' => 'title');
|
||||||
|
$crumbs[] = array('name' => $streditingcategories, 'link' => '', 'type' => 'title');
|
||||||
|
$navigation = build_navigation($crumbs);
|
||||||
|
print_header_simple($streditingcategories, '', $navigation, "", "", true, $strupdatemodule);
|
||||||
|
|
||||||
|
|
||||||
$currenttab = 'edit';
|
$currenttab = 'edit';
|
||||||
$mode = 'categories';
|
$mode = 'categories';
|
||||||
include($CFG->dirroot.'/mod/quiz/tabs.php');
|
${$cm->modname} = $module;
|
||||||
|
include($CFG->dirroot."/mod/{$cm->modname}/tabs.php");
|
||||||
} else {
|
} else {
|
||||||
print_header_simple(get_string('editcategories', 'quiz'), '', get_string('editcategories', 'quiz'));
|
// Print basic page layout.
|
||||||
|
$crumbs = array();
|
||||||
|
$crumbs[] = array('name' => $streditingcategories, 'link' => '', 'type' => 'title');
|
||||||
|
$navigation = build_navigation($crumbs);
|
||||||
|
|
||||||
|
print_header_simple($streditingcategories, '', $navigation);
|
||||||
|
|
||||||
// print tabs
|
// print tabs
|
||||||
$currenttab = 'categories';
|
$currenttab = 'categories';
|
||||||
|
|
|
@ -13,15 +13,7 @@
|
||||||
require_once("../config.php");
|
require_once("../config.php");
|
||||||
require_once("editlib.php");
|
require_once("editlib.php");
|
||||||
|
|
||||||
require_login();
|
list($thispageurl, $courseid, $cmid, $cm, $module, $pagevars) = question_edit_setup();
|
||||||
|
|
||||||
$courseid = required_param('courseid', PARAM_INT);
|
|
||||||
|
|
||||||
// The optional parameter 'clean' allows us to clear module information,
|
|
||||||
// guaranteeing a module-independent question bank editing interface
|
|
||||||
if (optional_param('clean', false, PARAM_BOOL)) {
|
|
||||||
unset($SESSION->modform);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! $course = get_record("course", "id", $courseid)) {
|
if (! $course = get_record("course", "id", $courseid)) {
|
||||||
error("This course doesn't exist");
|
error("This course doesn't exist");
|
||||||
|
@ -31,39 +23,40 @@
|
||||||
|
|
||||||
$SESSION->returnurl = $FULLME;
|
$SESSION->returnurl = $FULLME;
|
||||||
|
|
||||||
// Print basic page layout.
|
|
||||||
$streditingquestions = get_string('editquestions', "quiz");
|
$streditingquestions = get_string('editquestions', "quiz");
|
||||||
|
if ($cm!==null) {
|
||||||
// TODO: generalise this to any activity
|
|
||||||
$strquizzes = get_string('modulenameplural', 'quiz');
|
|
||||||
$streditingquestions = get_string('editquestions', "quiz");
|
|
||||||
if (isset($SESSION->modform->instance) and $quiz = get_record('quiz', 'id', $SESSION->modform->instance)) {
|
|
||||||
$strupdatemodule = has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id))
|
$strupdatemodule = has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id))
|
||||||
? update_module_button($SESSION->modform->cmid, $course->id, get_string('modulename', 'quiz'))
|
? update_module_button($cm->id, $course->id, get_string('modulename', $cm->modname))
|
||||||
: "";
|
: "";
|
||||||
print_header_simple($streditingquestions, '',
|
$crumbs = array();
|
||||||
"<a href=\"$CFG->wwwroot/mod/quiz/index.php?id=$course->id\">$strquizzes</a>".
|
$crumbs[] = array('name' => get_string('modulenameplural', $cm->modname), 'link' => "$CFG->wwwroot/mod/{$cm->modname}/index.php?id=$course->id", 'type' => 'activity');
|
||||||
" -> <a href=\"$CFG->wwwroot/mod/quiz/view.php?q={$SESSION->modform->instance}\">".format_string($SESSION->modform->name).'</a>'.
|
$crumbs[] = array('name' => format_string($module->name), 'link' => "$CFG->wwwroot/mod/{$cm->modname}/view.php?cmid={$cm->id}", 'type' => 'title');
|
||||||
" -> $streditingquestions",
|
$crumbs[] = array('name' => $streditingquestions, 'link' => '', 'type' => 'title');
|
||||||
"", "", true, $strupdatemodule);
|
$navigation = build_navigation($crumbs);
|
||||||
|
print_header_simple($streditingquestions, '', $navigation, "", "", true, $strupdatemodule);
|
||||||
|
|
||||||
$currenttab = 'edit';
|
$currenttab = 'edit';
|
||||||
$mode = 'questions';
|
$mode = 'questions';
|
||||||
$quiz = &$SESSION->modform;
|
${$cm->modname} = $module;
|
||||||
include($CFG->dirroot.'/mod/quiz/tabs.php');
|
include($CFG->dirroot."/mod/$cm->modname/tabs.php");
|
||||||
} else {
|
} else {
|
||||||
print_header_simple($streditingquestions, '',
|
// Print basic page layout.
|
||||||
"$streditingquestions");
|
$crumbs = array();
|
||||||
|
$crumbs[] = array('name' => $streditingquestions, 'link' => '', 'type' => 'title');
|
||||||
|
$navigation = build_navigation($crumbs);
|
||||||
|
|
||||||
|
print_header_simple($streditingquestions, '', $navigation);
|
||||||
|
|
||||||
// print tabs
|
// print tabs
|
||||||
$currenttab = 'questions';
|
$currenttab = 'questions';
|
||||||
include('tabs.php');
|
include('tabs.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
echo '<table class="boxaligncenter" border="0" cellpadding="2" cellspacing="0">';
|
echo '<table class="boxaligncenter" border="0" cellpadding="2" cellspacing="0">';
|
||||||
echo '<tr><td valign="top">';
|
echo '<tr><td valign="top">';
|
||||||
|
|
||||||
include($CFG->dirroot.'/question/showbank.php');
|
question_showbank($thispageurl, $cm, $pagevars['qpage'], $pagevars['qperpage'], $pagevars['qsortorder']);
|
||||||
|
|
||||||
echo '</td></tr>';
|
echo '</td></tr>';
|
||||||
echo '</table>';
|
echo '</table>';
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php // $Id$
|
<?php // $Id$
|
||||||
/**
|
/**
|
||||||
* Functions used by showbank.php to show question editing interface
|
* Functions used to show question editing interface
|
||||||
*
|
*
|
||||||
* TODO: currently the function question_list still provides controls specific
|
* TODO: currently the function question_list still provides controls specific
|
||||||
* to the quiz module. This needs to be generalised.
|
* to the quiz module. This needs to be generalised.
|
||||||
|
@ -269,20 +269,19 @@ function question_list($course, $pageurl, $categoryid, $cm = null,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print_paging_bar($totalnumber, $page, $perpage,
|
print_paging_bar($totalnumber, $page, $perpage, $pageurl, 'qpage');
|
||||||
"edit.php?courseid={$course->id}&perpage=$perpage&");
|
|
||||||
|
|
||||||
echo '<form method="post" action="edit.php">';
|
echo '<form method="post" action="edit.php">';
|
||||||
echo '<fieldset class="invisiblefieldset" style="display: block;">';
|
echo '<fieldset class="invisiblefieldset" style="display: block;">';
|
||||||
echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
|
echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
|
||||||
echo $pageurl->hidden_params_out();
|
echo $pageurl->hidden_params_out(array('qsortorder'));
|
||||||
echo '<table id="categoryquestions" style="width: 100%"><tr>';
|
echo '<table id="categoryquestions" style="width: 100%"><tr>';
|
||||||
echo "<th style=\"white-space:nowrap;\" class=\"header\" scope=\"col\">$straction</th>";
|
echo "<th style=\"white-space:nowrap;\" class=\"header\" scope=\"col\">$straction</th>";
|
||||||
|
|
||||||
$sortoptions = array('name, qtype ASC' => get_string("sortalpha", "quiz"),
|
$sortoptions = array('name, qtype ASC' => get_string("sortalpha", "quiz"),
|
||||||
'qtype, name ASC' => get_string("sorttypealpha", "quiz"),
|
'qtype, name ASC' => get_string("sorttypealpha", "quiz"),
|
||||||
'id ASC' => get_string("sortage", "quiz"));
|
'id ASC' => get_string("sortage", "quiz"));
|
||||||
$orderselect = choose_from_menu ($sortoptions, 'sortorder', $sortorder, false, 'this.form.submit();', '0', true);
|
$orderselect = choose_from_menu ($sortoptions, 'qsortorder', $sortorder, false, 'this.form.submit();', '0', true);
|
||||||
$orderselect .= '<noscript><div><input type="submit" value="'.get_string("sortsubmit", "quiz").'" /></div></noscript>';
|
$orderselect .= '<noscript><div><input type="submit" value="'.get_string("sortsubmit", "quiz").'" /></div></noscript>';
|
||||||
echo "<th style=\"white-space:nowrap; text-align: left;\" class=\"header\" scope=\"col\">$strquestionname $orderselect</th>
|
echo "<th style=\"white-space:nowrap; text-align: left;\" class=\"header\" scope=\"col\">$strquestionname $orderselect</th>
|
||||||
<th style=\"white-space:nowrap; text-align: right;\" class=\"header\" scope=\"col\">$strtype</th>";
|
<th style=\"white-space:nowrap; text-align: right;\" class=\"header\" scope=\"col\">$strtype</th>";
|
||||||
|
@ -350,14 +349,13 @@ function question_list($course, $pageurl, $categoryid, $cm = null,
|
||||||
}
|
}
|
||||||
echo "</table>\n";
|
echo "</table>\n";
|
||||||
|
|
||||||
$paging = print_paging_bar($totalnumber, $page, $perpage,
|
$paging = print_paging_bar($totalnumber, $page, $perpage, $pageurl, 'qpage',
|
||||||
"edit.php?".$pageurl->get_query_string()."&perpage=$perpage&", 'page',
|
|
||||||
false, true);
|
false, true);
|
||||||
if ($totalnumber > DEFAULT_QUESTIONS_PER_PAGE) {
|
if ($totalnumber > DEFAULT_QUESTIONS_PER_PAGE) {
|
||||||
if ($perpage == DEFAULT_QUESTIONS_PER_PAGE) {
|
if ($perpage == DEFAULT_QUESTIONS_PER_PAGE) {
|
||||||
$showall = '<a href="edit.php?'.$pageurl->get_query_string().'&perpage=1000">'.get_string('showall', 'moodle', $totalnumber).'</a>';
|
$showall = '<a href="edit.php?'.$pageurl->get_query_string(array('qperpage'=>1000)).'">'.get_string('showall', 'moodle', $totalnumber).'</a>';
|
||||||
} else {
|
} else {
|
||||||
$showall = '<a href="edit.php?'.$pageurl->get_query_string().'&perpage=' . DEFAULT_QUESTIONS_PER_PAGE . '">'.get_string('showperpage', 'moodle', DEFAULT_QUESTIONS_PER_PAGE).'</a>';
|
$showall = '<a href="edit.php?'.$pageurl->get_query_string(array('qperpage'=>DEFAULT_QUESTIONS_PER_PAGE)).'">'.get_string('showperpage', 'moodle', DEFAULT_QUESTIONS_PER_PAGE).'</a>';
|
||||||
}
|
}
|
||||||
if ($paging) {
|
if ($paging) {
|
||||||
$paging = substr($paging, 0, strrpos($paging, '</div>'));
|
$paging = substr($paging, 0, strrpos($paging, '</div>'));
|
||||||
|
@ -420,32 +418,9 @@ function question_list($course, $pageurl, $categoryid, $cm = null,
|
||||||
* {@link http://maths.york.ac.uk/serving_maths}
|
* {@link http://maths.york.ac.uk/serving_maths}
|
||||||
* @param moodle_url $pageurl object representing this pages url.
|
* @param moodle_url $pageurl object representing this pages url.
|
||||||
*/
|
*/
|
||||||
function showbank($pageurl, $cm){
|
function question_showbank($pageurl, $cm, $page, $perpage, $sortorder){
|
||||||
global $SESSION, $COURSE;
|
global $SESSION, $COURSE;
|
||||||
$page = optional_param('page', -1, PARAM_INT);
|
|
||||||
$perpage = optional_param('perpage', -1, PARAM_INT);
|
|
||||||
$sortorder = optional_param('sortorder', '');
|
|
||||||
if (preg_match("/[';]/", $sortorder)) {
|
|
||||||
error("Incorrect use of the parameter 'sortorder'");
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($page > -1) {
|
|
||||||
$SESSION->questionpage = $page;
|
|
||||||
} else {
|
|
||||||
$page = isset($SESSION->questionpage) ? $SESSION->questionpage : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($perpage > -1) {
|
|
||||||
$SESSION->questionperpage = $perpage;
|
|
||||||
} else {
|
|
||||||
$perpage = isset($SESSION->questionperpage) ? $SESSION->questionperpage : DEFAULT_QUESTIONS_PER_PAGE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($sortorder) {
|
|
||||||
$SESSION->questionsortorder = $sortorder;
|
|
||||||
} else {
|
|
||||||
$sortorder = isset($SESSION->questionsortorder) ? $SESSION->questionsortorder : 'qtype, name ASC';
|
|
||||||
}
|
|
||||||
$SESSION->fromurl = $pageurl->out();
|
$SESSION->fromurl = $pageurl->out();
|
||||||
|
|
||||||
/// Now, check for commands on this page and modify variables as necessary
|
/// Now, check for commands on this page and modify variables as necessary
|
||||||
|
@ -458,8 +433,8 @@ function showbank($pageurl, $cm){
|
||||||
error(get_string('categorynoedit', 'quiz', $tocategory->name), $pageurl->out());
|
error(get_string('categorynoedit', 'quiz', $tocategory->name), $pageurl->out());
|
||||||
}
|
}
|
||||||
foreach ($_POST as $key => $value) { // Parse input for question ids
|
foreach ($_POST as $key => $value) { // Parse input for question ids
|
||||||
if (substr($key, 0, 1) == "q") {
|
if (preg_match('!q([0-9]+)!', $key, $matches)) {
|
||||||
$key = substr($key,1);
|
$key = $matches[1];
|
||||||
if (!set_field('question', 'category', $tocategory->id, 'id', $key)) {
|
if (!set_field('question', 'category', $tocategory->id, 'id', $key)) {
|
||||||
error('Could not update category field');
|
error('Could not update category field');
|
||||||
}
|
}
|
||||||
|
@ -501,9 +476,8 @@ function showbank($pageurl, $cm){
|
||||||
// an asterix in front of those that are in use
|
// 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
|
$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
|
foreach ($rawquestions as $key => $value) { // Parse input for question ids
|
||||||
if (substr($key, 0, 1) == "q") {
|
if (preg_match('!q([0-9]+)!', $key, $matches)) {
|
||||||
$key = substr($key,1);
|
$key = $matches[1]; $questionlist .= $key.',';
|
||||||
$questionlist .= $key.',';
|
|
||||||
if (record_exists('quiz_question_instances', 'question', $key) or
|
if (record_exists('quiz_question_instances', 'question', $key) or
|
||||||
record_exists('question_states', 'originalquestion', $key)) {
|
record_exists('question_states', 'originalquestion', $key)) {
|
||||||
$questionnames .= '* ';
|
$questionnames .= '* ';
|
||||||
|
@ -586,4 +560,62 @@ function showbank($pageurl, $cm){
|
||||||
|
|
||||||
print_box_end();
|
print_box_end();
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Common setup for all pages for editing questions.
|
||||||
|
* @param boolean $requirecmid require cmid? default false
|
||||||
|
* @param boolean $requirecourseid require courseid, if cmid is not given? default true
|
||||||
|
* @return array $thispageurl, $courseid, $cmid, $cm, $module, $pagevars
|
||||||
|
*/
|
||||||
|
function question_edit_setup($requirecmid = false, $requirecourseid = true){
|
||||||
|
$thispageurl = new moodle_url();
|
||||||
|
if ($requirecmid){
|
||||||
|
$cmid =required_param('cmid', PARAM_INT);
|
||||||
|
} else {
|
||||||
|
$cmid = optional_param('cmid', 0, PARAM_INT);
|
||||||
|
}
|
||||||
|
if ($cmid){
|
||||||
|
list($module, $cm) = get_module_from_cmid($cmid);
|
||||||
|
$courseid = $cm->course;
|
||||||
|
$thispageurl->params(compact('cmid'));
|
||||||
|
} else {
|
||||||
|
$module = null;
|
||||||
|
$cm = null;
|
||||||
|
if ($requirecourseid){
|
||||||
|
$courseid = required_param('courseid', PARAM_INT);
|
||||||
|
} else {
|
||||||
|
$courseid = optional_param('courseid', 0, PARAM_INT);
|
||||||
|
}
|
||||||
|
if ($courseid){
|
||||||
|
$thispageurl->params(compact('courseid'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$pagevars['qpage'] = optional_param('qpage', -1, PARAM_INT);
|
||||||
|
$pagevars['qperpage'] = optional_param('qperpage', -1, PARAM_INT);
|
||||||
|
$pagevars['qsortorder'] = optional_param('qsortorder', '');
|
||||||
|
|
||||||
|
if (preg_match("/[';]/", $pagevars['qsortorder'])) {
|
||||||
|
error("Incorrect use of the parameter 'qsortorder'");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($pagevars['qpage'] > -1) {
|
||||||
|
$thispageurl->param('qpage', $pagevars['qpage']);
|
||||||
|
} else {
|
||||||
|
$pagevars['qpage'] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($pagevars['qperpage'] > -1) {
|
||||||
|
$thispageurl->param('qperpage', $pagevars['qperpage']);
|
||||||
|
} else {
|
||||||
|
$pagevars['qperpage'] = DEFAULT_QUESTIONS_PER_PAGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($pagevars['qsortorder']) {
|
||||||
|
$thispageurl->param('qsortorder', $pagevars['qsortorder']);
|
||||||
|
} else {
|
||||||
|
$pagevars['qsortorder'] = 'qtype, name ASC';
|
||||||
|
}
|
||||||
|
return array($thispageurl, $courseid, $cmid, $cm, $module, $pagevars);
|
||||||
|
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -12,10 +12,11 @@
|
||||||
require_once("../config.php");
|
require_once("../config.php");
|
||||||
require_once( "editlib.php" );
|
require_once( "editlib.php" );
|
||||||
|
|
||||||
// get parameters
|
list($thispageurl, $courseid, $cmid, $cm, $module, $pagevars) = question_edit_setup();
|
||||||
|
|
||||||
$categoryid = optional_param('category',0, PARAM_INT);
|
$categoryid = optional_param('category',0, PARAM_INT);
|
||||||
$cattofile = optional_param('cattofile',0, PARAM_BOOL);
|
$cattofile = optional_param('cattofile',0, PARAM_BOOL);
|
||||||
$courseid = required_param('courseid',PARAM_INT);
|
|
||||||
$exportfilename = optional_param('exportfilename','',PARAM_FILE );
|
$exportfilename = optional_param('exportfilename','',PARAM_FILE );
|
||||||
$format = optional_param('format','', PARAM_FILE );
|
$format = optional_param('format','', PARAM_FILE );
|
||||||
|
|
||||||
|
@ -41,7 +42,7 @@
|
||||||
|
|
||||||
if ($categoryid) { // update category in session variable
|
if ($categoryid) { // update category in session variable
|
||||||
$SESSION->questioncat = $categoryid;
|
$SESSION->questioncat = $categoryid;
|
||||||
} else { // try to get category from modform
|
} else { // try to get category from session
|
||||||
if (isset($SESSION->questioncat)) {
|
if (isset($SESSION->questioncat)) {
|
||||||
$categoryid = $SESSION->questioncat;
|
$categoryid = $SESSION->questioncat;
|
||||||
}
|
}
|
||||||
|
@ -73,20 +74,28 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Header
|
/// Header
|
||||||
if (isset($SESSION->modform->instance) and $quiz = get_record('quiz', 'id', $SESSION->modform->instance)) {
|
if ($cm!==null) {
|
||||||
$strupdatemodule = has_capability('moodle/course:manageactivities', $context)
|
$strupdatemodule = has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id))
|
||||||
? update_module_button($SESSION->modform->cmid, $course->id, $txt->modulename )
|
? update_module_button($cm->id, $course->id, get_string('modulename', $cm->modname))
|
||||||
: "";
|
: "";
|
||||||
print_header_simple($txt->exportquestions, '',
|
$crumbs = array();
|
||||||
"<a href=\"$CFG->wwwroot/mod/quiz/index.php?id=$course->id\">$txt->modulenameplural</a>".
|
$crumbs[] = array('name' => get_string('modulenameplural', $cm->modname), 'link' => "$CFG->wwwroot/mod/{$cm->modname}/index.php?id=$course->id", 'type' => 'activity');
|
||||||
" -> <a href=\"$CFG->wwwroot/mod/quiz/view.php?q=$quiz->id\">".format_string($quiz->name).'</a>'.
|
$crumbs[] = array('name' => format_string($module->name), 'link' => "$CFG->wwwroot/mod/{$cm->modname}/view.php?cmid={$cm->id}", 'type' => 'title');
|
||||||
' -> '.$txt->exportquestions,
|
$crumbs[] = array('name' => $txt->exportquestions, 'link' => '', 'type' => 'title');
|
||||||
"", "", true, $strupdatemodule);
|
$navigation = build_navigation($crumbs);
|
||||||
|
print_header_simple($txt->exportquestions, '', $navigation, "", "", true, $strupdatemodule);
|
||||||
|
|
||||||
$currenttab = 'edit';
|
$currenttab = 'edit';
|
||||||
$mode = 'export';
|
$mode = 'export';
|
||||||
include($CFG->dirroot.'/mod/quiz/tabs.php');
|
${$cm->modname} = $module;
|
||||||
|
include($CFG->dirroot."/mod/$cm->modname/tabs.php");
|
||||||
} else {
|
} else {
|
||||||
print_header_simple($txt->exportquestions, '', $txt->exportquestions);
|
// Print basic page layout.
|
||||||
|
$crumbs = array();
|
||||||
|
$crumbs[] = array('name' => $txt->exportquestions, 'link' => '', 'type' => 'title');
|
||||||
|
$navigation = build_navigation($crumbs);
|
||||||
|
|
||||||
|
print_header_simple($txt->exportquestions, '', $navigation);
|
||||||
// print tabs
|
// print tabs
|
||||||
$currenttab = 'export';
|
$currenttab = 'export';
|
||||||
include('tabs.php');
|
include('tabs.php');
|
||||||
|
@ -116,15 +125,15 @@
|
||||||
$qformat->setCattofile( $cattofile );
|
$qformat->setCattofile( $cattofile );
|
||||||
|
|
||||||
if (! $qformat->exportpreprocess()) { // Do anything before that we need to
|
if (! $qformat->exportpreprocess()) { // Do anything before that we need to
|
||||||
error( $txt->exporterror, "$CFG->wwwroot/question/export.php?courseid={$course->id}&category=$category->id");
|
error( $txt->exporterror, $thispageurl->out(false, array('category'=>$category->id)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $qformat->exportprocess()) { // Process the export data
|
if (! $qformat->exportprocess()) { // Process the export data
|
||||||
error( $txt->exporterror, "$CFG->wwwroot/question/export.php?courseid={$course->id}&category=$category->id");
|
error( $txt->exporterror, $thispageurl->out(false, array('category'=>$category->id)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $qformat->exportpostprocess()) { // In case anything needs to be done after
|
if (! $qformat->exportpostprocess()) { // In case anything needs to be done after
|
||||||
error( $txt->exporterror, "$CFG->wwwroot/question/export.php?courseid={$course->id}&category=$category->id");
|
error( $txt->exporterror, $thispageurl->out(false, array('category'=>$category->id)));
|
||||||
}
|
}
|
||||||
echo "<hr />";
|
echo "<hr />";
|
||||||
|
|
||||||
|
@ -139,7 +148,7 @@
|
||||||
echo "<p><div class=\"boxaligncenter\"><a href=\"$efile\">$txt->download</a></div></p>";
|
echo "<p><div class=\"boxaligncenter\"><a href=\"$efile\">$txt->download</a></div></p>";
|
||||||
echo "<p><div class=\"boxaligncenter\"><font size=\"-1\">$txt->downloadextra</font></div></p>";
|
echo "<p><div class=\"boxaligncenter\"><font size=\"-1\">$txt->downloadextra</font></div></p>";
|
||||||
|
|
||||||
print_continue("edit.php?courseid=$course->id");
|
print_continue("edit.php?".$thispageurl->get_query_string());
|
||||||
print_footer($course);
|
print_footer($course);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
@ -161,8 +170,7 @@
|
||||||
<form enctype="multipart/form-data" method="post" action="export.php">
|
<form enctype="multipart/form-data" method="post" action="export.php">
|
||||||
<fieldset class="invisiblefieldset" style="display: block;">
|
<fieldset class="invisiblefieldset" style="display: block;">
|
||||||
<input type="hidden" name="sesskey" value="<?php echo sesskey(); ?>" />
|
<input type="hidden" name="sesskey" value="<?php echo sesskey(); ?>" />
|
||||||
<input type="hidden" name="courseid" value="<?php echo $course->id; ?>" />
|
<?php echo $thispageurl->hidden_params_out(array(), 3); ?>
|
||||||
|
|
||||||
<table cellpadding="5">
|
<table cellpadding="5">
|
||||||
<tr>
|
<tr>
|
||||||
<td align="right"><?php echo $txt->category; ?>:</td>
|
<td align="right"><?php echo $txt->category; ?>:</td>
|
||||||
|
|
|
@ -14,12 +14,13 @@
|
||||||
require_once($CFG->libdir . '/uploadlib.php');
|
require_once($CFG->libdir . '/uploadlib.php');
|
||||||
require_once($CFG->libdir . '/questionlib.php');
|
require_once($CFG->libdir . '/questionlib.php');
|
||||||
|
|
||||||
|
list($thispageurl, $courseid, $cmid, $cm, $module, $pagevars) = question_edit_setup(false, false);
|
||||||
|
|
||||||
// get parameters
|
// get parameters
|
||||||
$params = new stdClass;
|
$params = new stdClass;
|
||||||
$params->choosefile = optional_param('choosefile','',PARAM_PATH);
|
$params->choosefile = optional_param('choosefile','',PARAM_PATH);
|
||||||
$categoryid = optional_param('category', 0, PARAM_INT);
|
$categoryid = optional_param('category', 0, PARAM_INT);
|
||||||
$catfromfile = optional_param('catfromfile', 0, PARAM_BOOL );
|
$catfromfile = optional_param('catfromfile', 0, PARAM_BOOL );
|
||||||
$courseid = optional_param('courseid', 0, PARAM_INT);
|
|
||||||
$format = optional_param('format','',PARAM_FILE);
|
$format = optional_param('format','',PARAM_FILE);
|
||||||
$params->matchgrades = optional_param('matchgrades','',PARAM_ALPHA);
|
$params->matchgrades = optional_param('matchgrades','',PARAM_ALPHA);
|
||||||
$params->stoponerror = optional_param('stoponerror', 0, PARAM_BOOL);
|
$params->stoponerror = optional_param('stoponerror', 0, PARAM_BOOL);
|
||||||
|
@ -28,7 +29,6 @@
|
||||||
$txt = new stdClass();
|
$txt = new stdClass();
|
||||||
$txt->category = get_string('category','quiz');
|
$txt->category = get_string('category','quiz');
|
||||||
$txt->choosefile = get_string('choosefile','quiz');
|
$txt->choosefile = get_string('choosefile','quiz');
|
||||||
$txt->editingquiz = get_string(isset($SESSION->modform->instance) ? "editingquiz" : "editquestions", "quiz");
|
|
||||||
$txt->file = get_string('file');
|
$txt->file = get_string('file');
|
||||||
$txt->fileformat = get_string('fileformat','quiz');
|
$txt->fileformat = get_string('fileformat','quiz');
|
||||||
$txt->fromfile = get_string('fromfile','quiz');
|
$txt->fromfile = get_string('fromfile','quiz');
|
||||||
|
@ -58,7 +58,7 @@
|
||||||
|
|
||||||
if ($categoryid) { // update category in session variable
|
if ($categoryid) { // update category in session variable
|
||||||
$SESSION->questioncat = $categoryid;
|
$SESSION->questioncat = $categoryid;
|
||||||
} else { // try to get category from modform
|
} else { // try to get category from session
|
||||||
if (isset($SESSION->questioncat)) {
|
if (isset($SESSION->questioncat)) {
|
||||||
$categoryid = $SESSION->questioncat;
|
$categoryid = $SESSION->questioncat;
|
||||||
}
|
}
|
||||||
|
@ -94,20 +94,28 @@
|
||||||
// PAGE HEADER
|
// PAGE HEADER
|
||||||
//==========
|
//==========
|
||||||
|
|
||||||
if (isset($SESSION->modform->instance) and $quiz = get_record('quiz', 'id', $SESSION->modform->instance)) {
|
if ($cm!==null) {
|
||||||
$strupdatemodule = has_capability('moodle/course:manageactivities', $context)
|
$strupdatemodule = has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id))
|
||||||
? update_module_button($SESSION->modform->cmid, $course->id, $txt->modulename)
|
? update_module_button($cm->id, $course->id, get_string('modulename', $cm->modname))
|
||||||
: "";
|
: "";
|
||||||
print_header_simple($txt->importquestions, '',
|
$crumbs = array();
|
||||||
"<a href=\"$CFG->wwwroot/mod/quiz/index.php?id=$course->id\">".$txt->modulenameplural.'</a>'.
|
$crumbs[] = array('name' => get_string('modulenameplural', $cm->modname), 'link' => "$CFG->wwwroot/mod/{$cm->modname}/index.php?id=$course->id", 'type' => 'activity');
|
||||||
" -> <a href=\"$CFG->wwwroot/mod/quiz/view.php?q=$quiz->id\">".format_string($quiz->name).'</a>'.
|
$crumbs[] = array('name' => format_string($module->name), 'link' => "$CFG->wwwroot/mod/{$cm->modname}/view.php?cmid={$cm->id}", 'type' => 'title');
|
||||||
' -> '.$txt->importquestions,
|
$crumbs[] = array('name' => $txt->importquestions, 'link' => '', 'type' => 'title');
|
||||||
"", "", true, $strupdatemodule);
|
$navigation = build_navigation($crumbs);
|
||||||
|
print_header_simple($txt->importquestions, '', $navigation, "", "", true, $strupdatemodule);
|
||||||
|
|
||||||
$currenttab = 'edit';
|
$currenttab = 'edit';
|
||||||
$mode = 'import';
|
$mode = 'import';
|
||||||
include($CFG->dirroot.'/mod/quiz/tabs.php');
|
${$cm->modname} = $module;
|
||||||
|
include($CFG->dirroot."/mod/$cm->modname/tabs.php");
|
||||||
} else {
|
} else {
|
||||||
print_header_simple($txt->importquestions, '', $txt->importquestions);
|
// Print basic page layout.
|
||||||
|
$crumbs = array();
|
||||||
|
$crumbs[] = array('name' => $txt->importquestions, 'link' => '', 'type' => 'title');
|
||||||
|
$navigation = build_navigation($crumbs);
|
||||||
|
|
||||||
|
print_header_simple($txt->importquestions, '', $navigation);
|
||||||
// print tabs
|
// print tabs
|
||||||
$currenttab = 'import';
|
$currenttab = 'import';
|
||||||
include('tabs.php');
|
include('tabs.php');
|
||||||
|
@ -130,8 +138,7 @@
|
||||||
else {
|
else {
|
||||||
notify($txt->uploadproblem);
|
notify($txt->uploadproblem);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// must be upload file
|
// must be upload file
|
||||||
if (empty($_FILES['newfile'])) {
|
if (empty($_FILES['newfile'])) {
|
||||||
notify( $txt->uploadproblem );
|
notify( $txt->uploadproblem );
|
||||||
|
@ -168,24 +175,21 @@
|
||||||
|
|
||||||
// Do anything before that we need to
|
// Do anything before that we need to
|
||||||
if (! $qformat->importpreprocess()) {
|
if (! $qformat->importpreprocess()) {
|
||||||
error( $txt->importerror ,
|
error( $txt->importerror, $thispageurl->out(false, array('category'=>$category->id)));
|
||||||
"$CFG->wwwroot/question/import.php?courseid={$course->id}&category=$category->id");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process the uploaded file
|
// Process the uploaded file
|
||||||
if (! $qformat->importprocess() ) {
|
if (! $qformat->importprocess() ) {
|
||||||
error( $txt->importerror ,
|
error( $txt->importerror, $thispageurl->out(false, array('category'=>$category->id)));
|
||||||
"$CFG->wwwroot/question/import.php?courseid={$course->id}&category=$category->id");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// In case anything needs to be done after
|
// In case anything needs to be done after
|
||||||
if (! $qformat->importpostprocess()) {
|
if (! $qformat->importpostprocess()) {
|
||||||
error( $txt->importerror ,
|
error( $txt->importerror, $thispageurl->out(false, array('category'=>$category->id)));
|
||||||
"$CFG->wwwroot/question/import.php?courseid={$course->id}&category=$category->id");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "<hr />";
|
echo "<hr />";
|
||||||
print_continue("edit.php?courseid=$course->id");
|
print_continue("edit.php?".$thispageurl->get_query_string());
|
||||||
print_footer($course);
|
print_footer($course);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
@ -210,6 +214,7 @@
|
||||||
<form id="form" enctype="multipart/form-data" method="post" action="import.php">
|
<form id="form" enctype="multipart/form-data" method="post" action="import.php">
|
||||||
<fieldset class="invisiblefieldset" style="display: block;">
|
<fieldset class="invisiblefieldset" style="display: block;">
|
||||||
<input type="hidden" name="sesskey" value="<?php echo sesskey(); ?>" />
|
<input type="hidden" name="sesskey" value="<?php echo sesskey(); ?>" />
|
||||||
|
<?php echo $thispageurl->hidden_params_out(array(), 3); ?>
|
||||||
<?php print_simple_box_start("center"); ?>
|
<?php print_simple_box_start("center"); ?>
|
||||||
<table cellpadding="5">
|
<table cellpadding="5">
|
||||||
<tr>
|
<tr>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue