Skip to content

Commit

Permalink
"MDL-14129, fix print_error call"
Browse files Browse the repository at this point in the history
  • Loading branch information
dongsheng committed May 23, 2008
1 parent ee95802 commit ec60b8e
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 89 deletions.
18 changes: 9 additions & 9 deletions mod/data/comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@


if (! $record = get_record('data_records', 'id', $rid)) {
print_error('Record ID is incorrect');
print_error('invalidrecord', 'data');
}
if (! $data = get_record('data', 'id', $record->dataid)) {
print_error('Data ID is incorrect');
print_error('invalidid', 'data');
}
if (! $course = get_record('course', 'id', $data->course)) {
print_error('Course is misconfigured');
print_error('coursemisconf');
}
if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
print_error('Course Module ID was incorrect');
print_error('invalidcoursemodule');
}

require_login($course->id, false, $cm);
Expand All @@ -33,13 +33,13 @@

if ($commentid) {
if (! $comment = get_record('data_comments', 'id', $commentid)) {
print_error('Comment ID is misconfigured');
print_error('commentmisconf');
}
if ($comment->recordid != $record->id) {
print_error('Comment ID is misconfigured');
print_error('commentmisconf');
}
if (!has_capability('mod/data:managecomments', $context) && $comment->userid != $USER->id) {
print_error('Comment is not yours to edit!');
print_error('cannoteditcomment');
}
} else {
$comment = false;
Expand Down Expand Up @@ -81,7 +81,7 @@
if (insert_record('data_comments',$newcomment)) {
redirect('view.php?rid='.$record->id.'&page='.$page);
} else {
print_error('Error while saving comment.');
print_error('cannotsavecomment');
}

break;
Expand All @@ -100,7 +100,7 @@
if (update_record('data_comments',$updatedcomment)) {
redirect('view.php?rid='.$record->id.'&page='.$page);
} else {
print_error('Error while saving comment.');
print_error('cannotsavecomment');
}
break;

Expand Down
14 changes: 7 additions & 7 deletions mod/data/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,24 @@

if ($id) {
if (! $cm = get_coursemodule_from_id('data', $id)) {
print_error('Course Module ID was incorrect');
print_error('invalidcoursemodule');
}
if (! $course = get_record('course', 'id', $cm->course)) {
print_error('Course is misconfigured');
print_error('coursemisconf');
}
if (! $data = get_record('data', 'id', $cm->instance)) {
print_error('Course module is incorrect');
print_error('invalidcoursemodule');
}

} else {
if (! $data = get_record('data', 'id', $d)) {
print_error('Data ID is incorrect');
print_error('invalidid', 'data');
}
if (! $course = get_record('course', 'id', $data->course)) {
print_error('Course is misconfigured');
print_error('coursemisconf');
}
if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
print_error('Course Module ID was incorrect');
print_error('invalidcoursemodule');
}
}

Expand Down Expand Up @@ -180,7 +180,7 @@
} else { /// Add some new records

if (!data_user_can_add_entry($data, $currentgroup, $groupmode)) {
print_error('Can not add entries!');
print_error('cannotadd', 'data');
}

/// Check if maximum number of entry as specified by this database is reached
Expand Down
2 changes: 1 addition & 1 deletion mod/data/field/file/field.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function update_content($recordid, $value, $name) {
$oldcontent->fieldid = $this->field->id;
$oldcontent->recordid = $recordid;
if ($oldcontent->id = insert_record('data_content', $oldcontent)) {
print_error('Could not make an empty record!');
print_error('cannotinsertempty', 'data');
}
}

Expand Down
24 changes: 12 additions & 12 deletions mod/data/field/latlong/kml.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,41 @@

if ($rid) {
if (! $record = get_record('data_records', 'id', $rid)) {
print_error('Record ID is incorrect');
print_error('invalidrecord', 'data');
}
if (! $data = get_record('data', 'id', $record->dataid)) {
print_error('Data ID is incorrect');
print_error('invalidid', 'data');
}
if (! $course = get_record('course', 'id', $data->course)) {
print_error('Course is misconfigured');
print_error('coursemisconf');
}
if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
print_error('Course Module ID was incorrect');
print_error('invalidcoursemodule');
}
if (! $field = get_record('data_fields', 'id', $fieldid)) {
print_error('Field ID is incorrect');
print_error('invalidfieldid', 'data');
}
if (! $field->type == 'latlong') { // Make sure we're looking at a latlong data type!
print_error('Field ID is incorrect');
print_error('invalidfieldtype', 'data');
}
if (! $content = get_record('data_content', 'fieldid', $fieldid, 'recordid', $rid)) {
print_error('Field content not found');
print_error('nofieldcontent', 'data');
}
} else { // We must have $d
if (! $data = get_record('data', 'id', $d)) {
print_error('Data ID is incorrect');
print_error('invalidid', 'data');
}
if (! $course = get_record('course', 'id', $data->course)) {
print_error('Course is misconfigured');
print_error('coursemisconf');
}
if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
print_error('Course Module ID was incorrect');
print_error('invalidcoursemodule');
}
if (! $field = get_record('data_fields', 'id', $fieldid)) {
print_error('Field ID is incorrect');
print_error('invalidfieldid', 'data');
}
if (! $field->type == 'latlong') { // Make sure we're looking at a latlong data type!
print_error('Field ID is incorrect');
print_error('invalidfieldtype', 'data');
}
$record = NULL;
}
Expand Down
12 changes: 6 additions & 6 deletions mod/data/import.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,24 @@

if ($id) {
if (! $cm = get_coursemodule_from_id('data', $id)) {
print_error('Course Module ID was incorrect');
print_error('invalidcoursemodule');
}
if (! $course = get_record('course', 'id', $cm->course)) {
print_error('Course is misconfigured');
print_error('coursemisconf');
}
if (! $data = get_record('data', 'id', $cm->instance)) {
print_error('Course module is incorrect');
print_error('invalidcoursemodule');
}

} else {
if (! $data = get_record('data', 'id', $d)) {
print_error('Data ID is incorrect');
print_error('invalidid', 'data');
}
if (! $course = get_record('course', 'id', $data->course)) {
print_error('Course is misconfigured');
print_error('coursemisconf');
}
if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
print_error('Course Module ID was incorrect');
print_error('coursemisconf');
}
}

Expand Down
2 changes: 1 addition & 1 deletion mod/data/pagelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class page_data extends page_generic_activity {

function init_quick($data) {
if(empty($data->pageid)) {
print_error('Cannot quickly initialize page: empty course id');
print_error('invalidcourseid');
}
$this->activityname = 'data';
parent::init_quick($data);
Expand Down
51 changes: 26 additions & 25 deletions mod/data/preset.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,26 @@

if ($id) {
if (! $cm = get_coursemodule_from_id('data', $id)) {
print_error('Course Module ID was incorrect');
print_error('invalidcoursemodule');
}
if (! $course = get_record('course', 'id', $cm->course)) {
print_error('Course is misconfigured');
print_error('coursemisconf');
}
if (! $data = get_record('data', 'id', $cm->instance)) {
print_error('Module Incorrect');
print_error('invalidid', 'data');
}
} else if ($d) {
if (! $data = get_record('data', 'id', $d)) {
print_error('Database ID Incorrect');
print_error('invalidid', 'data');
}
if (! $course = get_record('course', 'id', $data->course)) {
print_error('Course is misconfigured');
print_error('coursemisconf');
}
if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
print_error('Course Module ID was incorrect');
print_error('invalidcoursemodule');
}
} else {
print_error('Parameter missing');
print_error('missingparameter');
}

// fill in missing properties needed for updating of instance
Expand All @@ -53,15 +53,15 @@
$data->instance = $cm->instance;

if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('Could not find context');
print_error('cannotfindcontext');
}

require_login($course->id, false, $cm);

require_capability('mod/data:managetemplates', $context);

if ($userid && ($userid != $USER->id) && !has_capability('mod/data:viewalluserpresets', $context)) {
print_error('You are not allowed to access presets from other users');
print_error('cannotaccesspresentsother', 'data');
}

/* Need sesskey security check here for import instruction */
Expand All @@ -76,13 +76,13 @@
/***************** Deleting *****************/
case 'confirmdelete' :
if (!confirm_sesskey()) { // GET request ok here
print_error("Sesskey Invalid");
print_error('invalidsesskey');
}

if ($userid > 0 and ($userid == $USER->id || has_capability('mod/data:manageuserpresets', $context))) {
//ok can delete
} else {
print_error("Invalid request");
print_error('invalidrequest');
}

$path = data_preset_path($course, $userid, $shortname);
Expand All @@ -105,19 +105,19 @@

case 'delete' :
if (!data_submitted() and !confirm_sesskey()) {
print_error("Invalid request");
print_error('invalidrequest');
}

if ($userid > 0 and ($userid == $USER->id || has_capability('mod/data:manageuserpresets', $context))) {
//ok can delete
} else {
print_error("Invalid request");
print_error('invalidrequest');
}

$presetpath = data_preset_path($course, $userid, $shortname);

if (!clean_preset($presetpath)) {
print_error("Error deleting a preset!");
print_error('cannotdeletepreset', 'data');
}
@rmdir($presetpath);

Expand All @@ -130,7 +130,7 @@
/***************** Importing *****************/
case 'importpreset' :
if (!data_submitted() or !confirm_sesskey()) {
print_error("Invalid request");
print_error('invalidrequest');
}

$pimporter = new PresetImporter($course, $cm, $data, $userid, $shortname);
Expand All @@ -143,18 +143,18 @@
/* Imports a zip file. */
case 'importzip' :
if (!data_submitted() or !confirm_sesskey()) {
print_error("Invalid request");
print_error('invalidrequest');
}

if (!make_upload_directory('temp/data/'.$USER->id)) {
print_error("Can't Create Directory");
print_error('nopermissiontomkdir');
}

$presetfile = $CFG->dataroot.'/temp/data/'.$USER->id;
clean_preset($presetfile);

if (!unzip_file($CFG->dataroot."/$course->id/$file", $presetfile, false)) {
print_error("Can't unzip file");
print_error('cannotunzipfile');
}

$pimporter = new PresetImporter($course, $cm, $data, -$USER->id, $shortname);
Expand All @@ -166,7 +166,7 @@

case 'finishimport':
if (!data_submitted() or !confirm_sesskey()) {
print_error("Invalid request");
print_error('invalidrequest');
}

$pimporter = new PresetImporter($course, $cm, $data, $userid, $shortname);
Expand All @@ -185,7 +185,7 @@
/* Exports as a zip file ready for download. */
case 'export':
if (!data_submitted() or !confirm_sesskey()) {
print_error("Invalid request");
print_error('invalidrequest');
}

echo '<div style="text-align:center">';
Expand All @@ -197,15 +197,16 @@
make_upload_directory("$course->id/moddata/data/$data->id");

/* now just move the zip into this folder to allow a nice download */
if (!rename($file, $perminantfile)) print_error("Can't move zip");
if (!rename($file, $perminantfile))
print_error('cannotmovezip');
echo "<a href='$CFG->wwwroot/file.php/$course->id/moddata/data/$data->id/preset.zip'>".get_string('download', 'data')."</a>";
echo '</div>';
break;

/***************** Exporting *****************/
case 'save1':
if (!data_submitted() or !confirm_sesskey()) {
print_error("Invalid request");
print_error('invalidrequest');
}

$strcontinue = get_string('continue');
Expand All @@ -227,7 +228,7 @@

case 'save2':
if (!data_submitted() or !confirm_sesskey()) {
print_error("Invalid request");
print_error('invalidrequest');
}

$strcontinue = get_string('continue');
Expand Down Expand Up @@ -263,7 +264,7 @@

case 'save3':
if (!data_submitted() or !confirm_sesskey()) {
print_error("Invalid request");
print_error('invalidrequest');
}

$name = optional_param('name', $data->name, PARAM_FILE);
Expand All @@ -274,7 +275,7 @@

$file = data_presets_export($course, $cm, $data);
if (!unzip_file($file, $CFG->dataroot.$presetdirectory, false)) {
print_error("Can't unzip to the preset directory");
print_error('cannotunziptopreset', 'data');
}
notify(get_string('savesuccess', 'data'), 'notifysuccess');
break;
Expand Down
Loading

0 comments on commit ec60b8e

Please sign in to comment.