From 29c1bb159a5eb042845ad6ec612b1fb3d718570c Mon Sep 17 00:00:00 2001 From: dongsheng Date: Wed, 25 Jun 2008 14:52:39 +0000 Subject: [PATCH] "MDL-14129, fix print_error" --- lang/en_utf8/data.php | 8 ++++++-- mod/data/field.php | 16 ++++++++-------- mod/data/index.php | 2 +- mod/data/lib.php | 22 ++++++++++++---------- mod/data/preset.php | 3 +-- mod/data/templates.php | 12 ++++++------ mod/data/view.php | 20 ++++++++++---------- 7 files changed, 44 insertions(+), 39 deletions(-) diff --git a/lang/en_utf8/data.php b/lang/en_utf8/data.php index c8ab73383e..a8103df10b 100644 --- a/lang/en_utf8/data.php +++ b/lang/en_utf8/data.php @@ -124,6 +124,7 @@ $string['forcelinkname'] = 'Forced name for the link'; $string['foundrecords'] = 'Found records: $a->num/$a->max (reseturl\">Reset filters)'; $string['foundnorecords'] = 'No records found (reseturl\">Reset filters)'; $string['fromfile'] = 'Import from zip file'; +$string['generateerror'] = 'Not all files generated!'; $string['guestrate'] = 'Guests are not allowed to rate entries.'; $string['header'] = 'Header'; $string['headeraddtemplate'] = 'Defines the interface when editing entries'; @@ -136,14 +137,14 @@ $string['headersingletemplate'] = 'Defines browsing interface for a single entry $string['importsuccess'] = 'The preset has been successfully applied.'; $string['insufficiententries'] = 'more entries needed to view this database'; $string['intro'] = 'Introduction'; +$string['invalidaccess'] = 'This page was not accessed correctly'; $string['invalidfieldname'] = 'Please choose another name for this field'; $string['invalidfieldid'] = 'Field ID is incorrect'; $string['invalidfieldtype'] = 'Field Type is incorrect'; $string['invalidid'] = 'Incorrect data ID'; -$string['invaliddata'] = 'Incorrect data'; $string['invalidrecord'] = 'Incorrect record'; $string['invalidratedata'] = 'Incorrect submitted ratings data'; -$string['invalidaccess'] = 'This page was not accessed correctly'; +$string['invildpreset'] = '$a is not a preset.'; $string['invalidurl'] = 'The URL you just entered is not valid'; $string['jstemplate'] = 'Javascript template'; $string['latitude'] = 'Latitude'; @@ -160,6 +161,8 @@ $string['maxentries'] = 'Maximum entries'; $string['maxsize'] = 'Maximum size'; $string['menu'] = 'Menu'; $string['menuchoose'] = 'Choose...'; +$string['missingfield'] = 'Programmer error: You must specify field and/or data when defining field class. '; +$string['missingdata'] = 'Data id or object must be provided to field class'; $string['modulename'] = 'Database'; $string['modulenameplural'] = 'Databases'; $string['more'] = 'More'; @@ -260,6 +263,7 @@ $string['type'] = 'Field type'; $string['undefinedprocessactionmethod'] = 'No action method defined in Data_Preset to handle action \"$a\".'; $string['unsupportedexport'] = '($a->fieldtype) cannot be exported.'; $string['updatefield'] = 'Update an existing field'; +$string['updatingerror'] = 'There was an error updating the database'; $string['uploadfile'] = 'Upload file'; $string['uploadrecords'] = 'Upload entries from a file'; $string['url'] = 'Url'; diff --git a/mod/data/field.php b/mod/data/field.php index ba68976288..7ba49e9bd7 100755 --- a/mod/data/field.php +++ b/mod/data/field.php @@ -42,24 +42,24 @@ if ($id) { if (! $cm = get_coursemodule_from_id('data', $id)) { - error('Course Module ID was incorrect'); + print_error('invalidcoursemodule'); } if (! $course = $DB->get_record('course', array('id'=>$cm->course))) { - error('Course is misconfigured'); + print_error('coursemisconf'); } if (! $data = $DB->get_record('data', array('id'=>$cm->instance))) { - error('Course module is incorrect'); + print_error('invalidcoursemodule'); } } else { if (! $data = $DB->get_record('data', array('id'=>$d))) { - error('Data ID is incorrect'); + print_error('invalidid', 'data'); } if (! $course = $DB->get_record('course', array('id'=>$data->course))) { - error('Course is misconfigured'); + print_error('invalidcoursemodule'); } if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) { - error('Course Module ID was incorrect'); + print_error('invalidcoursemodule'); } } @@ -169,7 +169,7 @@ $rec->defaultsort = 0; $rec->defaultsortdir = 0; if (!$DB->update_record('data', $rec)) { - error('There was an error updating the database'); + print_error('updatingerror', 'data'); } } @@ -206,7 +206,7 @@ if ($DB->update_record('data', $rec)) { redirect($CFG->wwwroot.'/mod/data/field.php?d='.$data->id, get_string('changessaved'), 2); } else { - error('There was an error updating the database'); + print_error('updatingerror', 'data'); } exit; } diff --git a/mod/data/index.php b/mod/data/index.php index e52c54e22d..f4e325bc3a 100755 --- a/mod/data/index.php +++ b/mod/data/index.php @@ -28,7 +28,7 @@ $id = required_param('id', PARAM_INT); // course if (!$course = $DB->get_record('course', array('id'=>$id))) { - error("Course ID is incorrect"); + print_error('invalidcourseid'); } require_course_login($course); diff --git a/mod/data/lib.php b/mod/data/lib.php index abd2248c3f..d88748c401 100755 --- a/mod/data/lib.php +++ b/mod/data/lib.php @@ -52,18 +52,18 @@ class data_field_base { // Base class for Database Field Types (see field/*/ global $DB; if (empty($field) && empty($data)) { - error('Programmer error: You must specify field and/or data when defining field class. '); + print_error('missingfield', 'data'); } if (!empty($field)) { if (is_object($field)) { $this->field = $field; // Programmer knows what they are doing, we hope } else if (!$this->field = $DB->get_record('data_fields', array('id'=>$field))) { - error('Bad field ID encountered: '.$field); + print_error('invalidfieldid', 'data'); } if (empty($data)) { if (!$this->data = $DB->get_record('data', array('id'=>$this->field->dataid))) { - error('Bad data ID encountered in field data'); + print_error('invalidid', 'data'); } } } @@ -73,10 +73,10 @@ class data_field_base { // Base class for Database Field Types (see field/*/ if (is_object($data)) { $this->data = $data; // Programmer knows what they are doing, we hope } else if (!$this->data = $DB->get_record('data', array('id'=>$data))) { - error('Bad data ID encountered: '.$data); + print_error('invalidid', 'data'); } } else { // No way to define it! - error('Data id or object must be provided to field class'); + print_error('missingdata', 'data'); } } @@ -1766,7 +1766,7 @@ function data_user_can_add_entry($data, $currentgroup, $groupmode) { global $USER; if (!$cm = get_coursemodule_from_instance('data', $data->id)) { - error('Course Module ID was incorrect'); + print_error('invalidcoursemodule'); } $context = get_context_instance(CONTEXT_MODULE, $cm->id); @@ -1842,7 +1842,7 @@ class PresetImporter { global $CFG, $DB; if (!is_directory_a_preset($this->folder)) { - error("$this->userid/$this->shortname Not a preset"); + print_error('invildpreset', 'data', '', $this->userid.'/'.$this->shortname); } /* Grab XML */ @@ -1916,7 +1916,7 @@ class PresetImporter { function import_options() { if (!confirm_sesskey()) { - error("Sesskey Invalid"); + print_error('invalidsesskey'); } $strblank = get_string('blank', 'data'); @@ -1968,7 +1968,7 @@ class PresetImporter { echo "

$strwarning

"; } else if (empty($newfields)) { - error("New preset has no defined fields!"); + print_error('nodefinedfields', 'data'); } echo '
'; @@ -1993,7 +1993,9 @@ class PresetImporter { $cid = optional_param("field_$nid", -1, PARAM_INT); if ($cid == -1) continue; - if (array_key_exists($cid, $preservedfields)) error("Not an injective map"); + if (array_key_exists($cid, $preservedfields)){ + print_error('notinjectivemap', 'data'); + } else $preservedfields[$cid] = true; } diff --git a/mod/data/preset.php b/mod/data/preset.php index 156f222cab..78e02748c4 100644 --- a/mod/data/preset.php +++ b/mod/data/preset.php @@ -475,8 +475,7 @@ function data_presets_export($course, $cm, $data) { // Check if all files have been generated if (! is_directory_a_preset($exportdir)) { - error('Not all files generated!'); - // should be migrated to print_error() + print_error('generateerror', 'data'); } $filelist = array( diff --git a/mod/data/templates.php b/mod/data/templates.php index a2519e8c4d..ad3c0b4150 100755 --- a/mod/data/templates.php +++ b/mod/data/templates.php @@ -32,24 +32,24 @@ if ($id) { if (! $cm = get_coursemodule_from_id('data', $id)) { - error('Course Module ID was incorrect'); + print_error('invalidcoursemodule'); } if (! $course = $DB->get_record('course', array('id'=>$cm->course))) { - error('Course is misconfigured'); + print_error('coursemisconf'); } if (! $data = $DB->get_record('data', array('id'=>$cm->instance))) { - error('Course module is incorrect'); + print_error('invalidcoursemodule'); } } else { if (! $data = $DB->get_record('data', array('id'=>$d))) { - error('Data ID is incorrect'); + print_error('invalidid', 'data'); } if (! $course = $DB->get_record('course', array('id'=>$data->course))) { - error('Course is misconfigured'); + print_error('coursemisconf'); } if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) { - error('Course Module ID was incorrect'); + print_error('invalidcoursemodule'); } } diff --git a/mod/data/view.php b/mod/data/view.php index 9a5652fe0a..d9d750cb58 100755 --- a/mod/data/view.php +++ b/mod/data/view.php @@ -44,38 +44,38 @@ if ($id) { if (! $cm = get_coursemodule_from_id('data', $id)) { - error('Course Module ID was incorrect'); + print_error('invalidcoursemodule'); } if (! $course = $DB->get_record('course', array('id'=>$cm->course))) { - error('Course is misconfigured'); + print_error('coursemisconf'); } if (! $data = $DB->get_record('data', array('id'=>$cm->instance))) { - error('Course module is incorrect'); + print_error('invalidcoursemodule'); } $record = NULL; } else if ($rid) { if (! $record = $DB->get_record('data_records', array('id'=>$rid))) { - error('Record ID is incorrect'); + print_error('invalidrecord', 'data'); } if (! $data = $DB->get_record('data', array('id'=>$record->dataid))) { - error('Data ID is incorrect'); + print_error('invalidid', 'data'); } if (! $course = $DB->get_record('course', array('id'=>$data->course))) { - error('Course is misconfigured'); + print_error('coursemisconf'); } if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) { - error('Course Module ID was incorrect'); + print_error('invalidcoursemodule'); } } else { // We must have $d if (! $data = $DB->get_record('data', array('id'=>$d))) { - error('Data ID is incorrect'); + print_error('invalidid', 'data'); } if (! $course = $DB->get_record('course', array('id'=>$data->course))) { - error('Course is misconfigured'); + print_error('coursemisconf'); } if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) { - error('Course Module ID was incorrect'); + print_error('invalidcoursemodule'); } $record = NULL; } -- 2.39.5