2002-10-14 09:07:13 +00:00
|
|
|
<?PHP // $Id$
|
2002-10-06 17:31:46 +00:00
|
|
|
|
2003-01-05 14:19:20 +00:00
|
|
|
require_once("../../config.php");
|
|
|
|
require_once("lib.php");
|
2002-10-14 09:07:13 +00:00
|
|
|
|
|
|
|
require_login();
|
|
|
|
|
2002-12-30 05:10:01 +00:00
|
|
|
if (empty($destination)) {
|
|
|
|
$destination = "";
|
|
|
|
}
|
|
|
|
|
2003-01-02 14:49:23 +00:00
|
|
|
$modform = data_submitted($destination);
|
|
|
|
|
|
|
|
if ($modform and !empty($modform->course)) { // form submitted from mod.html
|
2002-10-14 09:07:13 +00:00
|
|
|
|
2002-12-30 05:10:01 +00:00
|
|
|
if (empty($modform->name) or empty($modform->intro)) {
|
2003-01-05 06:45:20 +00:00
|
|
|
error(get_string("filloutallfields"), $_SERVER["HTTP_REFERER"]);
|
2002-10-14 09:07:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$SESSION->modform = $modform; // Save the form in the current session
|
|
|
|
save_session("SESSION");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (!isset($SESSION->modform)) {
|
|
|
|
error("You have used this page incorrectly!");
|
|
|
|
}
|
|
|
|
|
|
|
|
$modform = $SESSION->modform;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (! $course = get_record("course", "id", $modform->course)) {
|
|
|
|
error("This course doesn't exist");
|
|
|
|
}
|
|
|
|
|
|
|
|
require_login($course->id);
|
|
|
|
|
|
|
|
if (!isteacher($course->id)) {
|
|
|
|
error("You can't modify this course!");
|
|
|
|
}
|
|
|
|
|
2002-12-30 05:10:01 +00:00
|
|
|
if (empty($modform->grades)) { // Construct an array to hold all the grades.
|
2002-10-14 12:21:18 +00:00
|
|
|
$modform->grades = quiz_get_all_question_grades($modform->questions, $modform->instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-14 09:07:13 +00:00
|
|
|
// Now, check for commands on this page and modify variables as necessary
|
|
|
|
|
2002-12-30 05:10:01 +00:00
|
|
|
if (!empty($up)) { /// Move the given question up a slot
|
2002-10-14 09:07:13 +00:00
|
|
|
$questions = explode(",", $modform->questions);
|
|
|
|
if ($questions[0] <> $up) {
|
|
|
|
foreach ($questions as $key => $question) {
|
|
|
|
if ($up == $question) {
|
|
|
|
$swap = $questions[$key-1];
|
|
|
|
$questions[$key-1] = $question;
|
|
|
|
$questions[$key] = $swap;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$modform->questions = implode(",", $questions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-30 05:10:01 +00:00
|
|
|
if (!empty($down)) { /// Move the given question down a slot
|
2002-10-14 09:07:13 +00:00
|
|
|
$questions = explode(",", $modform->questions);
|
|
|
|
if ($questions[count($questions)-1] <> $down) {
|
|
|
|
foreach ($questions as $key => $question) {
|
|
|
|
if ($down == $question) {
|
|
|
|
$swap = $questions[$key+1];
|
|
|
|
$questions[$key+1] = $question;
|
|
|
|
$questions[$key] = $swap;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$modform->questions = implode(",", $questions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-30 05:10:01 +00:00
|
|
|
if (!empty($add)) { /// Add a question to the current quiz
|
2003-01-05 06:45:20 +00:00
|
|
|
$rawquestions = $_POST;
|
2002-12-30 05:10:01 +00:00
|
|
|
if (!empty($modform->questions)) {
|
2002-10-14 15:57:33 +00:00
|
|
|
$questions = explode(",", $modform->questions);
|
|
|
|
}
|
2002-10-14 09:07:13 +00:00
|
|
|
foreach ($rawquestions as $key => $value) { // Parse input for question ids
|
|
|
|
if (substr($key, 0, 1) == "q") {
|
|
|
|
$key = substr($key,1);
|
2002-10-14 15:57:33 +00:00
|
|
|
if ($questions) {
|
|
|
|
foreach ($questions as $question) {
|
|
|
|
if ($question == $key) {
|
|
|
|
continue 2;
|
|
|
|
}
|
2002-10-14 09:07:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$questions[] = $key;
|
2002-10-14 15:57:33 +00:00
|
|
|
$modform->grades[$key] = 1; // default score
|
2002-10-14 09:07:13 +00:00
|
|
|
}
|
|
|
|
}
|
2002-12-30 05:10:01 +00:00
|
|
|
if (!empty($questions)) {
|
2002-10-15 10:04:28 +00:00
|
|
|
$modform->questions = implode(",", $questions);
|
|
|
|
} else {
|
|
|
|
$modform->questions = "";
|
|
|
|
}
|
2002-10-14 09:07:13 +00:00
|
|
|
}
|
|
|
|
|
2002-12-30 05:10:01 +00:00
|
|
|
if (!empty($delete)) { /// Delete a question from the list
|
2002-10-14 09:07:13 +00:00
|
|
|
$questions = explode(",", $modform->questions);
|
|
|
|
foreach ($questions as $key => $question) {
|
|
|
|
if ($question == $delete) {
|
|
|
|
unset($questions[$key]);
|
2002-10-14 12:21:18 +00:00
|
|
|
unset($modform->grades[$question]);
|
2002-10-14 09:07:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$modform->questions = implode(",", $questions);
|
|
|
|
}
|
|
|
|
|
2002-12-30 05:10:01 +00:00
|
|
|
if (!empty($setgrades)) { /// The grades have been updated, so update our internal list
|
2003-01-05 06:45:20 +00:00
|
|
|
$rawgrades = $_POST;
|
2002-10-15 12:54:11 +00:00
|
|
|
unset($modform->grades);
|
2002-10-14 09:07:13 +00:00
|
|
|
foreach ($rawgrades as $key => $value) { // Parse input for question -> grades
|
|
|
|
if (substr($key, 0, 1) == "q") {
|
|
|
|
$key = substr($key,1);
|
2002-10-14 12:21:18 +00:00
|
|
|
$modform->grades[$key] = $value;
|
2002-10-14 09:07:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-30 05:10:01 +00:00
|
|
|
if (!empty($cat)) { //-----------------------------------------------------------
|
2002-10-15 17:32:50 +00:00
|
|
|
$modform->category = $cat;
|
2002-10-14 09:07:13 +00:00
|
|
|
}
|
|
|
|
|
2002-12-30 05:10:01 +00:00
|
|
|
if (empty($modform->category)) {
|
|
|
|
$modform->category = "";
|
|
|
|
}
|
|
|
|
|
2002-10-14 15:57:33 +00:00
|
|
|
$modform->sumgrades = 0;
|
2002-12-30 05:10:01 +00:00
|
|
|
if (!empty($modform->grades)) {
|
2002-10-14 15:57:33 +00:00
|
|
|
foreach ($modform->grades as $grade) {
|
|
|
|
$modform->sumgrades += $grade;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-14 09:07:13 +00:00
|
|
|
$SESSION->modform = $modform;
|
|
|
|
save_session("SESSION");
|
|
|
|
|
|
|
|
|
|
|
|
$strediting = get_string("editingquiz", "quiz");
|
|
|
|
$strname = get_string("name");
|
|
|
|
|
|
|
|
print_header("$course->shortname: $strediting", "$course->shortname: $strediting",
|
|
|
|
"<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> -> $strediting");
|
|
|
|
|
|
|
|
// Print basic page layout.
|
|
|
|
|
|
|
|
echo "<TABLE BORDER=0 WIDTH=\"100%\" CELLPADDING=2 CELLSPACING=0>";
|
2002-10-14 15:57:33 +00:00
|
|
|
echo "<TR><TD WIDTH=50% VALIGN=TOP>";
|
2002-10-14 09:07:13 +00:00
|
|
|
print_simple_box_start("CENTER", "100%", $THEME->body);
|
|
|
|
print_heading($modform->name);
|
2002-10-14 12:21:18 +00:00
|
|
|
quiz_print_question_list($modform->questions, $modform->grades);
|
2002-10-14 09:07:13 +00:00
|
|
|
?>
|
|
|
|
<CENTER>
|
|
|
|
<P> </P>
|
|
|
|
<FORM NAME=theform METHOD=post ACTION=<?=$modform->destination ?>>
|
|
|
|
<INPUT TYPE="hidden" NAME=course VALUE="<? p($modform->course) ?>">
|
|
|
|
<INPUT TYPE="submit" VALUE="<? print_string("savequiz", "quiz") ?>">
|
2002-10-16 09:35:04 +00:00
|
|
|
<INPUT type="submit" name=cancel value="<? print_string("cancel") ?>">
|
2002-10-14 09:07:13 +00:00
|
|
|
</FORM>
|
|
|
|
</CENTER>
|
|
|
|
<?
|
|
|
|
print_simple_box_end();
|
|
|
|
echo "</TD><TD VALIGN=top WIDTH=50%>";
|
|
|
|
print_simple_box_start("CENTER", "100%", $THEME->body);
|
|
|
|
quiz_print_category_form($course, $modform->category);
|
|
|
|
print_simple_box_end();
|
|
|
|
|
|
|
|
print_spacer(5,1);
|
|
|
|
|
|
|
|
print_simple_box_start("CENTER", "100%", $THEME->body);
|
|
|
|
quiz_print_cat_question_list($modform->category);
|
|
|
|
print_simple_box_end();
|
|
|
|
echo "</TD></TR>";
|
|
|
|
echo "</TABLE>";
|
|
|
|
|
|
|
|
print_footer($course);
|
2002-10-06 17:31:46 +00:00
|
|
|
?>
|