Skip to content

Commit

Permalink
"MDL-14129, fix print_error call under course/, see tracker"
Browse files Browse the repository at this point in the history
  • Loading branch information
dongsheng committed May 7, 2008
1 parent 211c689 commit ba6018a
Show file tree
Hide file tree
Showing 17 changed files with 146 additions and 117 deletions.
10 changes: 5 additions & 5 deletions course/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@
}

if (!$site = get_site()) {
print_error("Site isn't defined!");
print_error("siteisnotdefined", 'debug');
}

if (empty($id)) {
print_error("Category not known!");
print_error("unknowcategory");
}

if (!$context = get_context_instance(CONTEXT_COURSECAT, $id)) {
print_error("Category not known!");
print_error("unknowcategory");
}

if (!$category = get_record("course_categories", "id", $id)) {
print_error("Category not known!");
print_error("unknowcategory");
}

if (has_capability('moodle/course:create', $context)) {
Expand Down Expand Up @@ -170,7 +170,7 @@
require_capability('moodle/category:update', get_context_instance(CONTEXT_COURSECAT, $moveto));

if (! $destcategory = get_record("course_categories", "id", $data->moveto)) {
print_error("Error finding the category");
print_error("cannotfindcategory", '', '', $data->moveto);
}


Expand Down
8 changes: 4 additions & 4 deletions course/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
require_login();

if (!can_delete_course($id)) {
print_error('You do not have the permission to delete this course.');
print_error('cannotdeletecourse');
}

if (!$site = get_site()) {
print_error("Site not found!");
print_error("siteisnotdefined", 'debug');
}

$strdeletecourse = get_string("deletecourse");
$stradministration = get_string("administration");
$strcategories = get_string("categories");

if (! $course = get_record("course", "id", $id)) {
print_error("Course ID was incorrect (can't find it)");
print_error("invalidcourseid");
}

$category = get_record("course_categories", "id", $course->category);
Expand Down Expand Up @@ -49,7 +49,7 @@
}

if ($delete != md5($course->timemodified)) {
print_error("The check variable was wrong - try again");
print_error("invalidmd5");
}

if (!confirm_sesskey()) {
Expand Down
8 changes: 4 additions & 4 deletions course/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

if($id == SITEID){
// don't allow editing of 'site course' using this from
print_error('You cannot edit the site course using this form');
print_error('cannoteditsiteform');
}

if (!$course = get_record('course', 'id', $id)) {
print_error('Course ID was incorrect');
print_error('invalidcourseid');
}
require_login($course->id);
$category = get_record('course_categories', 'id', $course->category);
Expand All @@ -30,12 +30,12 @@
$course = null;
require_login();
if (!$category = get_record('course_categories', 'id', $categoryid)) {
print_error('Category ID was incorrect');
print_error('unknowcategory');
}
require_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $category->id));
} else {
require_login();
print_error('Either course id or category must be specified');
print_error('needcoursecategroyid');
}

/// prepare course
Expand Down
8 changes: 4 additions & 4 deletions course/editcategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
$resort = optional_param('resort', 0, PARAM_BOOL);

if (!$site = get_site()) {
print_error("Site isn't defined!");
print_error("siteisnotdefined");
}

if ($categoryadd) { // Show Add category form: if $id is given, it is used as the parent category
Expand All @@ -33,7 +33,7 @@
$strtitle = get_string("editcategorysettings");
$context = get_context_instance(CONTEXT_COURSECAT, $id);
if (!$category = get_record("course_categories", "id", $id)) {
print_error("Category not known!");
print_error("unknowcategory");
}
}

Expand Down Expand Up @@ -83,7 +83,7 @@
}

if (!update_record('course_categories', $newcategory)) {
print_error( "Could not update the category '$newcategory->name' ");
print_error( "cannotupdatecategory", '', '', $newcategory->name);
} else {
if ($newcategory->parent == 0) {
$redirect_link = 'index.php?categoryedit=on';
Expand Down Expand Up @@ -210,7 +210,7 @@
require_capability('moodle/category:update', get_context_instance(CONTEXT_COURSECAT, $moveto));
if (!$destcategory = get_record("course_categories", "id", $data->moveto)) {
print_error("Error finding the destination category");
pritn_error("unknowcategory");
}
// TODO function to move the category
}
Expand Down
6 changes: 3 additions & 3 deletions course/editsection.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
$id = required_param('id',PARAM_INT); // Week ID

if (! $section = get_record("course_sections", "id", $id)) {
print_error("Course section is incorrect");
print_error("sectionnotexist");
}

if (! $course = get_record("course", "id", $section->course)) {
print_error("Could not find the course!");
print_error("invalidcourseid");
}

require_login($course->id);
Expand All @@ -25,7 +25,7 @@
$timenow = time();

if (! set_field("course_sections", "summary", $form->summary, "id", $section->id)) {
print_error("Could not update the summary!");
print_error("cannotupdatesummary");
}

add_to_log($course->id, "course", "editsection", "editsection.php?id=$section->id", "$section->section");
Expand Down
6 changes: 3 additions & 3 deletions course/importstudents.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
}

if (! $course = get_record("course", "id", $id)) {
print_error("Course ID was incorrect (can't find it)");
print_error("invalidcourseid");
}

require_login($course->id);
Expand Down Expand Up @@ -65,15 +65,15 @@
$addcourse = clean_param($addcourse, PARAM_INT);
set_time_limit(180);
if (!add_to_metacourse($course->id,$addcourse)) {
print_error("Could not add the selected course to this meta course!");
print_error("cannotmetacourse");
}
}
} else if ($remove and !empty($frm->removeselect) and confirm_sesskey()) {
foreach ($frm->removeselect as $removecourse) {
set_time_limit(180);
$removecourse = clean_param($removecourse, PARAM_INT);
if (! remove_from_metacourse($course->id,$removecourse)) {
print_error("Could not remove the selected course from this meta course!");
print_error("cannotremovefrommeta");
}
}
} else if ($showall and confirm_sesskey()) {
Expand Down
8 changes: 4 additions & 4 deletions course/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
$context = $sysctx;

if (!$site = get_site()) {
print_error('Site isn\'t defined!');
print_error('siteisnotdefined', 'debug');
}

if ($CFG->forcelogin) {
Expand Down Expand Up @@ -120,7 +120,7 @@
if ($childcats = get_records('course_categories', 'parent', $deletecat->id)) {
foreach ($childcats as $childcat) {
if (! set_field('course_categories', 'parent', $deletecat->parent, 'id', $childcat->id)) {
print_error('Could not update a child category!', 'index.php');
print_error('cannotupdatesubcate', '', 'index.php');
}
}
}
Expand All @@ -131,7 +131,7 @@
if ($childcourses = get_records('course', 'category', $deletecat->id)) {
foreach ($childcourses as $childcourse) {
if (! set_field('course', 'category', $deletecat->parent, 'id', $childcourse->id)) {
print_error('Could not update a child course!', 'index.php');
print_error('cannotupdatesubcourse', '', 'index.php');
}
}
}
Expand Down Expand Up @@ -163,7 +163,7 @@
unset($tempcat);
$tempcat->name = get_string('miscellaneous');
if (!$tempcat->id = insert_record('course_categories', $tempcat)) {
print_error('Serious error: Could not create a default category!');
print_error('cannotsetupcategory');
}
$tempcat->context = get_context_instance(CONTEXT_COURSECAT, $tempcat->id);
mark_context_dirty('/'.SYSCONTEXTID);
Expand Down
6 changes: 3 additions & 3 deletions course/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
$name = optional_param('name', false, PARAM_RAW); // Course short name

if (!$id and !$name) {
print_error("Must specify course id or short name");
print_error("unspecifycourseid");
}

if ($name) {
if (! $course = get_record("course", "shortname", $name) ) {
print_error("That's an invalid short course name");
print_error("invalidshortname");
}
} else {
if (! $course = get_record("course", "id", $id) ) {
print_error("That's an invalid course id");
print_error("invalidcourseid");
}
}

Expand Down
16 changes: 8 additions & 8 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@ function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modname
}
asort($modnames, SORT_LOCALE_STRING);
} else {
print_error("No modules are installed!");
print_error("nomodules", 'debug');
}

if ($rawmods = get_course_mods($courseid)) {
Expand Down Expand Up @@ -1948,7 +1948,7 @@ function print_my_moodle() {
global $USER, $CFG;

if (empty($USER->id)) {
print_error("It shouldn't be possible to see My Moodle without being logged in.");
print_error('nopermissions', '', '', 'See My Moodle');
}

$courses = get_my_courses($USER->id, 'visible DESC,sortorder ASC', array('summary'));
Expand Down Expand Up @@ -2539,7 +2539,7 @@ function course_in_meta ($course) {
*/
function print_standard_coursemodule_settings($form, $features=null) {
if (! $course = get_record('course', 'id', $form->course)) {
print_error("This course doesn't exist");
print_error("invalidcourseid");
}
print_groupmode_setting($form, $course);
if (!empty($features->groupings)) {
Expand All @@ -2555,12 +2555,12 @@ function print_groupmode_setting($form, $course=NULL) {

if (empty($course)) {
if (! $course = get_record('course', 'id', $form->course)) {
print_error("This course doesn't exist");
print_error("invalidcourseid");
}
}
if ($form->coursemodule) {
if (! $cm = get_record('course_modules', 'id', $form->coursemodule)) {
print_error("This course module doesn't exist");
print_error("cmunknown");
}
$groupmode = groups_get_activity_groupmode($cm);
} else {
Expand Down Expand Up @@ -2588,12 +2588,12 @@ function print_grouping_settings($form, $course=NULL) {

if (empty($course)) {
if (! $course = get_record('course', 'id', $form->course)) {
print_error("This course doesn't exist");
print_error("invalidcourseid");
}
}
if ($form->coursemodule) {
if (! $cm = get_record('course_modules', 'id', $form->coursemodule)) {
print_error("This course module doesn't exist");
print_error("cmunknown");
}
} else {
$cm = null;
Expand Down Expand Up @@ -2627,7 +2627,7 @@ function print_grouping_settings($form, $course=NULL) {
function print_visible_setting($form, $course=NULL) {
if (empty($course)) {
if (! $course = get_record('course', 'id', $form->course)) {
print_error("This course doesn't exist");
print_error("invalidcourseid");
}
}
if ($form->coursemodule) {
Expand Down
4 changes: 2 additions & 2 deletions course/loginas.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
}

if (! $course = get_record('course', 'id', $id)) {
print_error("Course ID was incorrect");
print_error("invalidcourseid");
}

/// User must be logged in
Expand All @@ -65,7 +65,7 @@
require_login($course);
require_capability('moodle/user:loginas', $coursecontext);
if (!has_capability('moodle/course:view', $coursecontext, $userid, false)) {
print_error('This user is not in this course!');
print_error('usernotincourse');
}
if (has_capability('moodle/site:doanything', $coursecontext, $userid, false)) {
print_error('nologinas');
Expand Down
Loading

0 comments on commit ba6018a

Please sign in to comment.