From: dongsheng Date: Wed, 21 May 2008 07:53:23 +0000 (+0000) Subject: "MDL-14129, fix print_error call" X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=0be2c85848f1b73b541bd27f0100314a31f1be89;p=moodle.git "MDL-14129, fix print_error call" --- diff --git a/question/category.php b/question/category.php index 366e37cbae..f2a0a0617d 100644 --- a/question/category.php +++ b/question/category.php @@ -48,7 +48,7 @@ } if ($param->delete && ($questionstomove = count_records("question", "category", $param->delete))){ if (!$category = get_record("question_categories", "id", $param->delete)) { // security - print_error("No such category {$param->delete}!", '', $thispageurl->out()); + print_error('nocate', 'question', $thispageurl->out(), $param->delete); } $categorycontext = get_context_instance_by_id($category->contextid); $qcobject->moveform = new question_move_form($thispageurl, diff --git a/question/contextmove.php b/question/contextmove.php index 83e40122fd..d4fede6b3f 100644 --- a/question/contextmove.php +++ b/question/contextmove.php @@ -26,7 +26,7 @@ list($toparent, $contextto) = explode(',', $toparent); if (!empty($toparent)){//not top level category, make it a child of $toparent if (!$toparent = get_record('question_categories', 'id', $toparent)){ - print_error('Invalid category id for parent!', '', $onerrorurl); + print_error('invalidcategoryidforparent', 'question', $onerrorurl); } $contextto = $toparent->contextid; } else { @@ -35,10 +35,10 @@ $toparent->contextid = $contextto; } if (!$cattomove = get_record('question_categories', 'id', $cattomove)){ - print_error('Invalid category id to move!', '', $onerrorurl); + print_error('invalidcategoryidtomove', 'question', $onerrorurl); } if ($cattomove->contextid == $contextto){ - print_error("You shouldn't have got here if you're not moving a category to another context.", '', $onerrorurl); + print_error('contexterror', '', $onerrorurl); } $cattomove->categorylist = question_categorylist($cattomove->id); @@ -130,7 +130,7 @@ case QUESTION_FILEMOVELINKSONLY : break; default : - print_error('Invalid action selected!', '', $onerrorurl); + print_error('invalidaction', '', $onerrorurl); } switch ($urlaction){ //now search and replace urls in questions. @@ -176,11 +176,11 @@ $cat->parent = $toparent->id; //set context of category we are moving and all children also! if (!execute_sql("UPDATE {$CFG->prefix}question_categories SET contextid = {$contextto->id} WHERE id IN ({$cattomove->categorylist})", false)){ - print_error("Could not move the category '$newname' to ".$contexttostring, '', $onerrorurl); + print_error('cannotmovefromto', 'question', $onerrorurl, array($newname, $contexttostring)); } //finally set the new parent id if (!update_record("question_categories", $cat)) { - print_error("Could not update the category '$updatename'", '', $onerrorurl); + print_error('cannotupdatecate', 'question', $onerrorurl, $updatename); } $thispageurl->remove_params('cattomove', 'toparent', 'totop'); redirect($CFG->wwwroot."/question/category.php?".$thispageurl->get_query_string(array('cat'=>"{$cattomove->id},{$contextto->id}"))); diff --git a/question/contextmoveq.php b/question/contextmoveq.php index 9973c6d66b..140f8590a5 100644 --- a/question/contextmoveq.php +++ b/question/contextmoveq.php @@ -42,7 +42,7 @@ if ($cmid){ } $thispageurl->param('courseid', $COURSE->id); } else { - print_error('Need to pass courseid or cmid to this script.'); + print_error('missingcourseorcmid', 'question'); } $contexts = new question_edit_contexts($thiscontext); @@ -70,7 +70,7 @@ foreach (array_keys($questions) as $id){ $questions[$id]->context = get_context_instance_by_id($questions[$id]->contextid); $thisfilesid = get_filesdir_from_context($questions[$id]->context); if ($fromcoursefilesid && $thisfilesid != $fromcoursefilesid){ - print_error('You can\'t use this script to move questions that have files associated with them from different areas.'); + print_error('cannotmovequestion', 'question'); } else { $fromcoursefilesid = $thisfilesid; } @@ -136,7 +136,7 @@ if ($contextmoveform->is_cancelled()){ case QUESTION_FILEDONOTHING : break; default : - print_error('Invalid action selected!', '', $returnurl); + print_error('invalidaction', '', $returnurl); } //now search and replace urls in questions. switch ($urlaction){ @@ -152,7 +152,7 @@ if ($contextmoveform->is_cancelled()){ case QUESTION_FILEDONOTHING : break; default : - print_error('Invalid action selected!', '', $returnurl); + print_error('invalidaction', '', $returnurl); break; } diff --git a/question/editlib.php b/question/editlib.php index b80d7f892d..33d95fcc56 100644 --- a/question/editlib.php +++ b/question/editlib.php @@ -880,12 +880,12 @@ function require_login_in_context($contextorid = null){ } else if ($context && ($context->contextlevel == CONTEXT_MODULE)) { if ($cm = get_record('course_modules','id',$context->instanceid)) { if (!$course = get_record('course', 'id', $cm->course)) { - print_error('Incorrect course.'); + print_error('invalidcourseid'); } require_course_login($course, true, $cm); } else { - print_error('Incorrect course module id.'); + print_error('invalidcoursemodule'); } } else if ($context && ($context->contextlevel == CONTEXT_SYSTEM)) { if (!empty($CFG->forcelogin)) { diff --git a/question/export.php b/question/export.php index c428fa41a1..d96ff93f7a 100644 --- a/question/export.php +++ b/question/export.php @@ -81,7 +81,7 @@ if (! is_readable("format/$from_form->format/format.php")) { - print_error("Format not known ($from_form->format)"); + print_error('unknowformat', '', '', $from_form->format); } // load parent class for import/export diff --git a/question/format/blackboard_6/format.php b/question/format/blackboard_6/format.php index a326da0aad..96c6146dff 100644 --- a/question/format/blackboard_6/format.php +++ b/question/format/blackboard_6/format.php @@ -159,7 +159,7 @@ class qformat_blackboard_6 extends qformat_default { if ($this->check_and_create_import_dir($unique_code)) { if(is_readable($filename)) { if (!copy($filename, "$temp_dir/bboard.zip")) { - print_error("Could not copy backup file"); + print_error('cannotcopybackup', 'question'); } if(unzip_file("$temp_dir/bboard.zip", '', false)) { // assuming that the information is in res0001.dat @@ -178,20 +178,20 @@ class qformat_blackboard_6 extends qformat_default { } } else { - print_error("Could not find question data file in zip"); + print_error('cannotfindquestionfile', 'questioni'); } } else { print "filename: $filename
tempdir: $temp_dir
"; - print_error("Could not unzip file."); + print_error('cannotunzip', 'question'); } } else { - error ("Could not read uploaded file"); + print_error('cannotreaduploadfile'); } } else { - print_error("Could not create temporary directory"); + print_error('cannotcreatetempdir'); } } diff --git a/question/format/coursetestmanager/format.php b/question/format/coursetestmanager/format.php index c75578f30c..14a0923b5d 100755 --- a/question/format/coursetestmanager/format.php +++ b/question/format/coursetestmanager/format.php @@ -43,7 +43,7 @@ class qformat_coursetestmanager extends qformat_default { if ((PHP_OS == "Linux") and !isset($hostname)) { // copy the file to a semi-permanent location if (! $basedir = make_upload_directory("$COURSE->id")) { - print_error("The site administrator needs to fix the file permissions for the data directory"); + print_error('cannotcreateuploaddir'); } if (!isset($hostname_access_error)) { $bname=basename($filename); @@ -101,7 +101,7 @@ class qformat_coursetestmanager extends qformat_default { if (PHP_OS == "WINNT") { // copy the file to a semi-permanent location if (! $basedir = make_upload_directory("$COURSE->id")) { - print_error("The site administrator needs to fix the file permissions for the data directory"); + print_error('cannotcreateuploaddir'); } $bname=basename($filename); $cleanfilename = clean_filename($bname); @@ -124,7 +124,7 @@ class qformat_coursetestmanager extends qformat_default { } // print the intermediary form if (!$categories = question_category_options($COURSE->id, true)) { - print_error("No categories!"); + print_error('nocate', 'debug'); } print_heading_with_help($strimportquestions, "import", "quiz"); print_simple_box_start("center"); @@ -264,7 +264,7 @@ class qformat_coursetestmanager extends qformat_default { $question->createdby = $USER->id; $question->timecreated = time(); if (!$question->id = insert_record("question", $question)) { - print_error("Could not insert new question!"); + print_error('cannotinsertquestion', 'question'); } $this->questionids[] = $question->id; // Now to save all the answers and type-specific options diff --git a/question/format/qti2/format.php b/question/format/qti2/format.php index 0376560738..cfca410330 100644 --- a/question/format/qti2/format.php +++ b/question/format/qti2/format.php @@ -110,7 +110,7 @@ class qformat_qti2 extends qformat_default { function importpreprocess() { global $CFG; - print_error("Sorry, importing this format is not yet implemented!", '', + print_error('cannotimportformat', '', "$CFG->wwwroot/mod/quiz/import.php?category=$category->id"); } @@ -274,13 +274,13 @@ function handle_questions_media(&$questions, $path, $courseid) { $expout = $smarty->fetch('imsmanifest.tpl'); $filepath = $path.'/imsmanifest.xml'; if (empty($expout)) { - print_error("Unkown error - empty imsmanifest.xml"); + print_error('emptyxml', 'question'); } if (!$fh=fopen($filepath,"w")) { - print_error("Cannot open for writing: $filepath"); + print_error('cannotopenforwrit', '', '', $filepath); } if (!fwrite($fh, $expout)) { - print_error("Cannot write exported questions to $filepath"); + print_error('cannotwriteto', 'question', '', $filepath); } fclose($fh); @@ -295,10 +295,10 @@ function handle_questions_media(&$questions, $path, $courseid) { $filepath = $path.'/'.$this->get_assesment_item_id($question) . ".xml"; if (!$fh=fopen($filepath,"w")) { - print_error("Cannot open for writing: $filepath"); + print_error('cannotopenforwrit', '', '', $filepath); } if (!fwrite($fh, $expout)) { - print_error("Cannot write exported questions to $filepath"); + print_error('cannotwriteto', 'question', '', $filepath); } fclose($fh); @@ -332,13 +332,13 @@ function handle_questions_media(&$questions, $path, $courseid) { $this->xml_entitize($result); $this->xml_entitize($submiturl); if (! $this->exportpreprocess(0, $course)) { // Do anything before that we need to - print_error("Error occurred during pre-processing!", '', $redirect); + print_error('errorduringpre', 'question', $redirect); } if (! $this->exportprocess_quiz($quiz, $questions, $result, $submiturl, $course)) { // Process the export data - print_error("Error occurred during processing!", '', $redirect); + print_error('errorduringproc', 'question', $redirect); } if (! $this->exportpostprocess()) { // In case anything needs to be done after - print_error("Error occurred during post-processing!", '', $redirect); + print_error('errorduringpost', 'question', $redirect); } } @@ -675,7 +675,7 @@ function xml_entitize(&$collection) { $path = $CFG->dataroot."/smarty_c"; if (!is_dir($path)) { if (!mkdir($path, $CFG->directorypermissions)) { - print_error("Cannot create path: $path"); + print_error('nopermissiontomkdir'); } } $smarty = new Smarty; diff --git a/question/format/webct/format.php b/question/format/webct/format.php index 85cf161c96..8c82cce178 100644 --- a/question/format/webct/format.php +++ b/question/format/webct/format.php @@ -106,21 +106,21 @@ function qformat_webct_convert_formula($formula) { for ($i = 1 ; $deep ; ++$i) { if (!ereg('^(.*[^[:alnum:]_])?([[:alnum:]_]*([)(])([^)(]*[)(]){'.$i.'})$', $splits[0], $regs)) { - print_error("Parenthesis before ** is not properly started in $splits[0]**"); + print_error("parenthesisinproperstart", 'question', '', $splits[0]); } if ('(' == $regs[3]) { --$deep; } else if (')' == $regs[3]) { ++$deep; } else { - print_error("Impossible character $regs[3] detected as parenthesis character"); + print_error('impossiblechar', 'question', '', $regs[3]); } } $base = $regs[2]; $splits[0] = $regs[1]; } else { - print_error("Bad base before **: $splits[0]**"); + print_error('badbase', 'question', '', $splits[0]); } // Find $exp (similar to above but a little easier) @@ -136,14 +136,14 @@ function qformat_webct_convert_formula($formula) { for ($i = 1 ; $deep ; ++$i) { if (!ereg('^([+-]?[[:alnum:]_]*([)(][^)(]*){'.$i.'}([)(]))(.*)', $splits[1], $regs)) { - print_error("Parenthesis after ** is not properly closed in **$splits[1]"); + print_error("parenthesisinproperclose", 'question', '', $splits[1]); } if (')' == $regs[3]) { --$deep; } else if ('(' == $regs[3]) { ++$deep; } else { - print_error("Impossible character $regs[3] detected as parenthesis character"); + print_error("impossiblechar", 'question'); } } $exp = $regs[1]; diff --git a/question/question.php b/question/question.php index 39fbb7c25d..b66ba7d72a 100644 --- a/question/question.php +++ b/question/question.php @@ -41,7 +41,7 @@ if ($cmid){ $module = null; $cm = null; } else { - print_error('Need to pass courseid or cmid to this script.'); + print_error('missingcourseorcmid', 'question'); } $contexts = new question_edit_contexts($thiscontext); diff --git a/question/tabs.php b/question/tabs.php index 1cd757d29f..3e01c27dca 100644 --- a/question/tabs.php +++ b/question/tabs.php @@ -12,7 +12,7 @@ $currenttab = ''; } if (!isset($COURSE)) { - print_error('No course specified'); + print_error('invalidcourse'); } $tabs = array();