diff --git a/lang/en/quiz.php b/lang/en/quiz.php index 7d3abf86b35..5acb098e58a 100644 --- a/lang/en/quiz.php +++ b/lang/en/quiz.php @@ -7,7 +7,7 @@ $string['modulenameplural'] = "Quizzes"; $string['addselectedtoquiz'] = "Add selected to quiz"; $string['alwaysavailable'] = "Always available"; -$string['alreadysubmitted'] = "Perhaps you already submitted this attempt"; +$string['alreadysubmitted'] = "It is likely that you have already submitted this attempt"; $string['answer'] = "Answer"; $string['answerhowmany'] = "One or multiple answers?"; $string['answersingleyes'] = "One answer only"; @@ -18,12 +18,16 @@ $string['attemptlast'] = "Last attempt"; $string['attempts'] = "Attempts"; $string['attemptsallowed'] = "Attempts allowed"; $string['attemptsunlimited'] = "Unlimited attempts"; +$string['backtoquiz'] = "Back to quiz editing"; $string['bestgrade'] = "Best grade"; -$string['categories'] = "Categories"; -$string['category'] = "Category"; $string['casesensitive'] = "Case sensitivity"; $string['caseyes'] = "Yes, case must match"; $string['caseno'] = "No, case is unimportant"; +$string['categories'] = "Categories"; +$string['category'] = "Category"; +$string['categoryinfo'] = "Category info"; +$string['categorymove'] = "The category '\$a->name' contains \$a->count questions. Please choose another category to move them to."; +$string['categorymoveto'] = "Move them to this category"; $string['choice'] = "Choice"; $string['choices'] = "Available choices"; $string['correctanswer'] = "Correct answer"; @@ -53,7 +57,9 @@ $string['multichoice'] = "Multiple Choice"; $string['noanswers'] = "No answers were selected!"; $string['nomoreattempts'] = "No more attempts are allowed"; $string['noquestions'] = "No questions have been added yet"; +$string['publish'] = "Publish"; $string['question'] = "Question"; +$string['questions'] = "Questions"; $string['questionname'] = "Question name"; $string['quizavailable'] = "The quiz is available until: \$a"; $string['quizclose'] = "Close the quiz"; @@ -79,5 +85,6 @@ $string['timetaken'] = "Time taken"; $string['timecompleted'] = "Completed"; $string['true'] = "True"; $string['truefalse'] = "True/False"; +$string['type'] = "Type"; $string['viewallanswers'] = "View \$a completed quizzes"; $string['yourfinalgradeis'] = "Your final grade for this quiz is \$a"; diff --git a/lib/moodlelib.php b/lib/moodlelib.php index e32c493fddb..ac7dcc33a23 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -681,7 +681,7 @@ function optional_variable(&$var, $default=0) { /// DATABASE HANDLING //////////////////////////////////////////////// -function execute_sql($command) { +function execute_sql($command, $feedback=true) { // Completely general global $db; @@ -689,10 +689,14 @@ function execute_sql($command) { $result = $db->Execute("$command"); if ($result) { - echo "
".get_string("success")."
"; + if ($feedback) { + echo "".get_string("success")."
"; + } return true; } else { - echo "".get_string("error")."
"; + if ($feedback) { + echo "".get_string("error")."
"; + } return false; } } diff --git a/mod/quiz/category.php b/mod/quiz/category.php index b3ce80f42d3..4de75c88b10 100644 --- a/mod/quiz/category.php +++ b/mod/quiz/category.php @@ -1,4 +1,175 @@ id); + + if (!isteacher($course->id)) { + error("Only teachers can use this page!"); + } + + +/// Print headings + + $strcategory = get_string("category", "quiz"); + $strcategoryinfo = get_string("categoryinfo", "quiz"); + $strquestions = get_string("questions", "quiz"); + $strpublish = get_string("publish", "quiz"); + $strdelete = get_string("delete"); + $straction = get_string("action"); + $stradd = get_string("add"); + $strcancel = get_string("cancel"); + $strsavechanges = get_string("savechanges"); + $strbacktoquiz = get_string("backtoquiz", "quiz"); + + $streditingquiz = get_string("editingquiz", "quiz"); + $streditcategories = get_string("editcategories", "quiz"); + + print_header("$course->shortname: $streditcategories", "$course->shortname: $streditcategories", + "wwwroot/course/view.php?id=$course->id\">$course->shortname + -> $streditingquiz -> $streditcategories"); + + +/// Delete category if the user wants to delete it + + if (isset($delete) and !isset($cancel)) { + if (!$category = get_record("quiz_categories", "id", $delete)) { // security + error("No such category $delete!"); + } + + if (isset($confirm)) { // Need to move some questions before deleting the category + if (!$category2 = get_record("quiz_categories", "id", $confirm)) { // security + error("No such category $confirm!"); + } + if (! execute_sql("UPDATE quiz_questions SET category = '$category2->id' WHERE category = '$category->id'", false)) { + error("Error while moving questions from category '$category->name' to '$category2->name'"); + } + + } else { + if ($count = count_records("quiz_questions", "category", $category->id)) { + $vars->name = $category->name; + $vars->count = $count; + print_simple_box(get_string("categorymove", "quiz", $vars), "CENTER"); + $categories = quiz_get_category_menu($course->id); + unset($categories[$category->id]); + echo "$text
"; } -function quiz_print_question($number, $questionid, $grade, $courseid, +function quiz_print_question_icon($question) { +// Prints a question icon + switch ($question->type) { + case SHORTANSWER: + echo "$feedback[0]
"); } if ($correct) { - $correctanswers = implode(",", $correct); + $correctanswers = implode(", ", $correct); quiz_print_correctanswer($correctanswers); } break; @@ -445,12 +459,17 @@ function quiz_get_default_category($courseid) { return $category; } +function quiz_get_category_menu($courseid, $published=false) { + if ($published) { + $publish = "OR publish = '1'"; + } + return get_records_sql_menu("SELECT id,name FROM quiz_categories WHERE course='$courseid' $publish ORDER by name ASC"); +} + function quiz_print_category_form($course, $current) { // Prints a form to choose categories - if (!$categories = get_records_sql_menu("SELECT id,name FROM quiz_categories - WHERE course='$course->id' OR publish = '1' - ORDER by name ASC")) { + if (!$categories = quiz_get_category_menu($course->id, true)) { if (!$category = quiz_get_default_category($course->id)) { notify("Error creating a default category!"); return false; @@ -533,6 +552,7 @@ function quiz_print_question_list($questionlist, $grades) { $strmoveup = get_string("moveup"); $strmovedown = get_string("movedown"); $strsavegrades = get_string("savegrades", "quiz"); + $strtype = get_string("type", "quiz"); for ($i=10; $i>=0; $i--) { $gradesmenu[$i] = $i; @@ -542,7 +562,7 @@ function quiz_print_question_list($questionlist, $grades) { $total = count($order); echo "