]> git.mjollnir.org Git - moodle.git/commitdiff
"MDL-14129, fix print_error"
authordongsheng <dongsheng>
Tue, 10 Jun 2008 06:27:38 +0000 (06:27 +0000)
committerdongsheng <dongsheng>
Tue, 10 Jun 2008 06:27:38 +0000 (06:27 +0000)
12 files changed:
mod/quiz/attempt.php
mod/quiz/comment.php
mod/quiz/editlib.php
mod/quiz/grade.php
mod/quiz/index.php
mod/quiz/pagelib.php
mod/quiz/quizfile.php
mod/quiz/report.php
mod/quiz/review.php
mod/quiz/reviewquestion.php
mod/quiz/tabs.php
mod/quiz/view.php

index 307e20af77f0b07c52ef425f35291be4e6b0369e..e2784245bb7176c4d9a6a7f8d174ba3faca17b88 100644 (file)
 
     if ($id) {
         if (! $cm = get_coursemodule_from_id('quiz', $id)) {
-            print_error("There is no coursemodule with id $id");
+            print_error('invalidcoursemodule');
         }
         if (! $course = $DB->get_record('course', array('id' => $cm->course))) {
-            print_error("Course is misconfigured");
+            print_error("coursemisconf");
         }
         if (! $quiz = $DB->get_record('quiz', array('id' => $cm->instance))) {
-            print_error("The quiz with id $cm->instance corresponding to this coursemodule $id is missing");
+            print_error('invalidcoursemodule');
         }
     } else {
         if (! $quiz = $DB->get_record('quiz', array('id' => $q))) {
-            print_error("There is no quiz with id $q");
+            print_error('invalidcoursemodule');
         }
         if (! $course = $DB->get_record('course', array('id' => $quiz->course))) {
-            print_error("The course with id $quiz->course that the quiz with id $q belongs to is missing");
+            print_error('invalidcourseid');
         }
         if (! $cm = get_coursemodule_from_instance("quiz", $quiz->id, $course->id)) {
-            print_error("The course module for the quiz with id $q is missing");
+            print_error('invalidcoursemodule');
         }
     }
 
 
 /// Restore the question sessions to their most recent states creating new sessions where required.
     if (!$states = get_question_states($questions, $quiz, $attempt, $lastattemptid)) {
-        print_error('Could not restore question sessions');
+        print_error('cannotrestore', 'quiz');
     }
 
 /// If we are starting a new attempt, save all the newly created states.
index 535995d6103b79321506d49b2068f14b984df603..b800d7b5fefb610cedc0cd7b6d0deee892504d7c 100644 (file)
     $questionid =required_param('question', PARAM_INT); // question id
 
     if (! $attempt = $DB->get_record('quiz_attempts', array('uniqueid' => $attemptid))) {
-        print_error('No such attempt ID exists');
+        print_error('invalidattemptid', 'quiz');
     }
     if (! $quiz = $DB->get_record('quiz', array('id' => $attempt->quiz))) {
-        print_error('Course module is incorrect');
+        print_error('invalidcoursemodule');
     }
     if (! $course = $DB->get_record('course', array('id' => $quiz->course))) {
-        print_error('Course is misconfigured');
+        print_error('coursemisconf');
     }
 
     // Teachers are only allowed to comment and grade on closed attempts
     if (!($attempt->timefinish > 0)) {
-        print_error('Attempt has not closed yet');
+        print_error('attemptclosed', 'quiz');
     }
 
     $cm = get_coursemodule_from_instance('quiz', $quiz->id);
@@ -36,7 +36,7 @@
 
     // Load question
     if (! $question = $DB->get_record('question', array('id' => $questionid))) {
-        print_error('Question for this session is missing');
+        print_error('questionmissing', 'quiz');
     }
     $question->maxgrade = $DB->get_field('quiz_question_instances', 'grade', array('quiz' => $quiz->id, 'question' => $question->id));
     // Some of the questions code is optimised to work with several questions
@@ -45,7 +45,7 @@
     $questions[$key] = &$question;
     // Add additional questiontype specific information to the question objects.
     if (!get_question_options($questions)) {
-        print_error("Unable to load questiontype specific question information");
+        print_error('cannotloadtypeinfo', 'quiz');
     }
 
     // Load state
index 22812863daf155b71c13286736f3987370d7f101..aeee04b52e1bffd041574a1766b4fc4d00b042a7 100644 (file)
@@ -44,7 +44,7 @@ function quiz_delete_quiz_question($id, &$quiz) {
     $quiz->questions = str_replace(',0,0', ',0', $quiz->questions);
     // save new questionlist in database
     if (!$DB->set_field('quiz', 'questions', $quiz->questions, array('id' => $quiz->instance))) {
-        print_error('Could not save question list');
+        print_error('cannotsavequestion', 'quiz');
     }
     $DB->delete_records('quiz_question_instances', array('quiz' => $quiz->instance, 'question', $question));
     return true;
@@ -88,7 +88,7 @@ function quiz_add_quiz_question($id, &$quiz) {
     // Save new questionslist in database
     $quiz->questions = implode(",", $questions);
     if (!$DB->set_field('quiz', 'questions', $quiz->questions, array('id' => $quiz->id))) {
-        print_error('Could not save question list');
+        print_error('cannotsavequestion', 'quiz');
     }
 
     // update question grades
index e2751a1f98e66c3b98e3271ca9aa9acc0f82051a..4eba8d71dc1ca1179d533467beeb3bb7e7ee99ca 100644 (file)
@@ -5,15 +5,15 @@
     $id   = required_param('id', PARAM_INT);          // Course module ID
 
     if (! $cm = get_coursemodule_from_id('quiz', $id)) {
-        print_error('Course Module ID was incorrect');
+        print_error('invalidcoursemodule');
     }
 
     if (! $quiz = $DB->get_record('quiz', array('id' => $cm->instance))) {
-        print_error('quiz ID was incorrect');
+        print_error('invalidquizid');
     }
 
     if (! $course = $DB->get_record('course', array('id' => $quiz->course))) {
-        print_error('Course is misconfigured');
+        print_error('coursemisconf');
     }
 
     require_login($course->id, false, $cm);
index 7bafe05f1fb1924a052cc6e6c0fbacc194db6cad..70174227c173b71181166b9dfb7cf1ab64c8b6d0 100644 (file)
@@ -11,7 +11,7 @@
 
     $id = required_param('id', PARAM_INT);
     if (!$course = $DB->get_record('course', array('id' => $id))) {
-        print_error("Course ID is incorrect");
+        print_error('invalidcourseid');
     }
     $coursecontext = get_context_instance(CONTEXT_COURSE, $id);
     require_login($course->id);
index 698dd341870deb1554b4d0fc1b24a9ee505cd0c7..fc2c59e372942590a60252c1e86629f4b7be76b9 100644 (file)
@@ -20,7 +20,7 @@ class page_quiz extends page_generic_activity {
 
     function init_quick($data) {
         if(empty($data->pageid)) {
-            print_error('Cannot quickly initialize page: empty course id');
+            print_error('cannotinitpage', '', '', null);
         }
         $this->activityname = 'quiz';
         parent::init_quick($data);
index 1296c75fa5cb012a8abf8818f0114c862f2cc74c..03c0188802cd8890fca8e55e8aaf32147310377f 100644 (file)
     $relativepath = get_file_argument('quizfile.php');
 
     if (!$relativepath) {
-        print_error('No valid arguments supplied or incorrect server configuration');
+        print_error('invalidargorconf');
     }
 
     // extract relative path components
     $args = explode('/', trim($relativepath, '/'));
     if (count($args) < 3) { // always at least category, question and path
-        print_error('No valid arguments supplied');
+        print_error('invalidarguments');
     }
 
     $quizid       = (int)array_shift($args);
     $relativepath = implode ('/', $args);
 
     if (!($question = $DB->get_record('question', array('id' => $questionid)))) {
-        print_error('No valid arguments supplied');
+        print_error('invalidarguments');
     }
 
     if (!($questioncategory = $DB->get_record('question_categories', array('id' => $question->category)))) {
-        print_error('No valid arguments supplied');
+        print_error('invalidarguments');
     }
 
     /////////////////////////////////////
@@ -48,7 +48,7 @@
         if ($questioncategory->publish) {
             require_login();
             if (!isteacherinanycourse()) {
-              print_error('No valid arguments supplied');
+                print_error('invalidarguments');
             }
         } else {
             require_login($questioncategory->course);
         }
     } else {
         if (!($quiz = $DB->get_record('quiz', array('id' => $quizid)))) {
-            print_error('No valid arguments supplied');
+            print_error('invalidarguments');
         }
         if (!($course = $DB->get_record('course', array('id' => $quiz->course)))) {
-            print_error('No valid arguments supplied');
+            print_error('invalidarguments');
         }
         require_login($course->id);
 
@@ -71,7 +71,7 @@
         //    and ! ($quiz->review  &&  time() > $quiz->timeclose)
         //        || !quiz_get_user_attempts($quiz->id, $USER->id) )
         //{
-        //    print_error("Logged-in user is not allowed to view this quiz");
+        //    print_error('noview', 'quiz');
         //}
 
         ///////////////////////////////////////////////////
         // For now, let's not worry about this.  The following check doesn't
         // work for randomly selected questions and it gets complicated
         //if (!in_array($question->id, explode(',', $quiz->questions), FALSE)) {
-        //    print_error("Specified question is not on the specified quiz");
+        //    print_error('specificquestionnotonquiz', 'quiz');
         //}
     }
 
     // Have the question check whether it uses this file or not
     if (!$QTYPES[$question->qtype]->uses_quizfile($question,
                                                        $relativepath)) {
-        print_error("The specified file path is not on the specified question");
+        print_error('specificapathnotonquestion', 'quiz');
     }
 
 
index b7f30e66eb2c6f149e7560ed3d340119c7bd2d0c..e53d68865f156e1fd503aa89505584fe8a227d7f 100644 (file)
 
     if ($id) {
         if (! $cm = get_coursemodule_from_id('quiz', $id)) {
-            print_error("There is no coursemodule with id $id");
+            print_error('invalidcoursemodule');
         }
 
         if (! $course = $DB->get_record('course', array('id' => $cm->course))) {
-            print_error("Course is misconfigured");
+            print_error('coursemisconf');
         }
 
         if (! $quiz = $DB->get_record('quiz', array('id' => $cm->instance))) {
-            print_error("The quiz with id $cm->instance corresponding to this coursemodule $id is missing");
+            print_error('invalidcoursemodule');
         }
 
     } else {
         if (! $quiz = $DB->get_record('quiz', array('id' => $q))) {
-            print_error("There is no quiz with id $q");
+            print_error('invalidquizid', 'quiz');
         }
         if (! $course = $DB->get_record('course', array('id' => $quiz->course))) {
-            print_error("The course with id $quiz->course that the quiz with id $q belongs to is missing");
+            print_error('invalidcourseid');
         }
         if (! $cm = get_coursemodule_from_instance("quiz", $quiz->id, $course->id)) {
-            print_error("The course module for the quiz with id $q is missing");
+            print_error('invalidcoursemodule');
         }
     }
 
@@ -62,7 +62,7 @@
     $mode = clean_param($mode, PARAM_SAFEDIR);
 
     if (! is_readable("report/$mode/report.php")) {
-        print_error("Report not known ($mode)");
+        print_error('reportnotfound', 'quiz', '', $mode);
     }
 
     include("report/default.php");  // Parent class
@@ -71,7 +71,7 @@
     $report = new quiz_report();
 
     if (! $report->display($quiz, $cm, $course)) {             // Run the report!
-        print_error("Error occurred during pre-processing!");
+        print_error("preprocesserror", 'quiz');
     }
 
 /// Print footer
index 185706f9ee92d48aa1695fffffd0d31c9ecfb3f4..91b8216f94de47b5ef3ec470e12f6697fb9880d8 100644 (file)
     $showall = optional_param('showall', 0, PARAM_BOOL);
 
     if (!$attempt = quiz_load_attempt($attemptid)) {
-        print_error("No such attempt ID exists");
+        print_error('invalidattemptid', 'quiz');
     }
     if (! $quiz = $DB->get_record('quiz', array('id' => $attempt->quiz))) {
-        print_error("The quiz with id $attempt->quiz belonging to attempt $attempt is missing");
+        print_error('invalidquizid', 'quiz');
     }
     if (! $course = $DB->get_record('course', array('id' => $quiz->course))) {
-        print_error("The course with id $quiz->course that the quiz with id $quiz->id belongs to is missing");
+        print_error("invalidcoursemodule");
     }
     if (! $cm = get_coursemodule_from_instance("quiz", $quiz->id, $course->id)) {
-        print_error("The course module for the quiz with id $quiz->id is missing");
+        print_error("invalidcoursemodule");
     }
 
 /// Check login and get contexts.
@@ -81,7 +81,7 @@
 
 /// Restore the question sessions to their most recent states creating new sessions where required.
     if (!$states = get_question_states($questions, $quiz, $attempt)) {
-        print_error('Could not restore question sessions');
+        print_error('cannotrestore', 'quiz');
     }
 
 /// Work out appropriate title.
index 4ba52588d68f5a5477ca47974ae4300bbfe570a0..bf0342fc2b196abfc6138f02d9d5cd1ffc8f5d3e 100644 (file)
 
     if ($stateid) {
         if (! $state = $DB->get_record('question_states', array('id' => $stateid))) {
-            print_error('Invalid state id');
+            print_error('invalidstateid', 'quiz');
         }
         if (! $attempt = $DB->get_record('quiz_attempts', array('uniqueid' => $state->attempt))) {
-            print_error('No such attempt ID exists');
+            print_error('invalidattemptid', 'quiz');
         }
     } elseif ($attemptid) {
         if (! $attempt = $DB->get_record('quiz_attempts', array('id' => $attemptid))) {
-            print_error('No such attempt ID exists');
+            print_error('invalidattemptid', 'quiz');
         }
         if (! $neweststateid = $DB->get_field('question_sessions', 'newest', array('attemptid' => $attempt->uniqueid, 'questionid' => $questionid))) {
             // newest_state not set, probably because this is an old attempt from the old quiz module code
             if (! $state = $DB->get_record('question_states', array('question' => $questionid, 'attempt' => $attempt->uniqueid))) {
-                print_error('Invalid question id');
+                print_error('invalidquestionid', 'quiz');
             }
         } else {
             if (! $state = $DB->get_record('question_states', array('id' => $neweststateid))) {
-                print_error('Invalid state id');
+                print_error('invalidstateid', 'quiz');
             }
         }
     } else {
-        print_error('Parameter missing');
+        print_error('missingparameter');
     }
     if (! $question = $DB->get_record('question', array('id' => $state->question))) {
-        print_error('Question for this state is missing');
+        print_error('questionmissing', 'quiz');
     }
     if (! $quiz = $DB->get_record('quiz', array('id' => $attempt->quiz))) {
-        print_error('Course module is incorrect');
+        print_error('invalidcoursemodule');
     }
     if (! $course = $DB->get_record('course', array('id' => $quiz->course))) {
-        print_error('Course is misconfigured');
+        print_error('coursemisconf');
     }
     if (! $cm = get_coursemodule_from_instance('quiz', $quiz->id, $course->id)) {
-        print_error('Course Module ID was incorrect');
+        print_error('invalidcoursemodule');
     }
 
     require_login($course->id, false, $cm);
@@ -77,7 +77,7 @@
             }
         }
         if ($attempt->userid != $USER->id) {
-            print_error('This is not your attempt!');
+            print_error('notyourattempt', 'quiz');
         }
     }
 
     $questions[$key] = &$question;
     // Add additional questiontype specific information to the question objects.
     if (!get_question_options($questions)) {
-        print_error("Unable to load questiontype specific question information");
+        print_error('cannotloadtypeinfo', 'quiz');
     }
 
     $session = $DB->get_record('question_sessions', array('attemptid' => $attempt->uniqueid, 'questionid' => $question->id));
index 096f61c6baa7566e7412fe6a67c1e671cbfe3a21..4b72032f16b4e6b0a834ce3f38331b284393edaf 100644 (file)
@@ -8,7 +8,7 @@
  */
 
 if (empty($quiz)) {
-    print_error('You cannot call this script in that way');
+    print_error('cannotcallscript');
 }
 if (!isset($currenttab)) {
     $currenttab = '';
index 87a6176723c238c6452557a28f3fd9769623e38d..c1261e2c83754e2c92141d1f730ef2312020c0f2 100644 (file)
 
     if ($id) {
         if (! $cm = get_coursemodule_from_id('quiz', $id)) {
-            print_error("There is no coursemodule with id $id");
+            print_error('invalidcoursemodule');
         }
         if (! $course = $DB->get_record('course', array('id' => $cm->course))) {
-            print_error("Course is misconfigured");
+            print_error('coursemisconf');
         }
         if (! $quiz = $DB->get_record('quiz', array('id' => $cm->instance))) {
-            print_error("The quiz with id $cm->instance corresponding to this coursemodule $id is missing");
+            print_error('invalidcoursemodule');
         }
     } else {
         if (! $quiz = $DB->get_record('quiz', array('id' => $q))) {
-            print_error("There is no quiz with id $q");
+            print_error('invalidquizid', 'quiz');
         }
         if (! $course = $DB->get_record('course', array('id' => $quiz->course))) {
-            print_error("The course with id $quiz->course that the quiz with id $q belongs to is missing");
+            print_error('invalidcourseid');
         }
         if (! $cm = get_coursemodule_from_instance("quiz", $quiz->id, $course->id)) {
-            print_error("The course module for the quiz with id $q is missing");
+            print_error('invalidcoursemodule');
         }
     }