$courses = array();
foreach ($data as $key => $value) {
if (preg_match('/^c\d+$/', $key)) {
- array_push($courses, substr($key, 1));
+ $courseid = substr($key, 1);
+ array_push($courses, $courseid);
+
+ // check this course's category
+ if ($movingcourse = $DB->get_record('course', array('id'=>$courseid))) {
+ if ($movingcourse->category != $id ) {
+ print_error('coursedoesnotbelongtocategory');
+ }
+ } else {
+ print_error('cannotfindcourse');
+ }
}
}
move_courses($courses, $data->moveto);
/// Hide or show a course
if ((!empty($hide) or !empty($show)) and confirm_sesskey()) {
- require_capability('moodle/course:visibility', $context);
if (!empty($hide)) {
$course = $DB->get_record('course', array('id' => $hide));
$visible = 0;
$course = $DB->get_record('course', array('id' => $show));
$visible = 1;
}
+
if ($course) {
+ $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+ require_capability('moodle/course:visibility', $coursecontext);
if (!$DB->set_field('course', 'visible', $visible, array('id' => $course->id))) {
print_error('errorupdatingcoursevisibility');
}
}
}
if ($swapcourse and $movecourse) {
+ // check course's category
+ if ($movecourse->category != $id) {
+ print_error('coursedoesnotbelongtocategory');
+ }
$DB->set_field('course', 'sortorder', $swapcourse->sortorder, array('id' => $movecourse->id));
$DB->set_field('course', 'sortorder', $movecourse->sortorder, array('id' => $swapcourse->id));
}
$string['cannotedityourprofile'] = 'Sorry, you cannot edit own profile';
$string['cannotfindcomponent'] = 'Cannot find component';
$string['cannotfindcontext'] = 'Could not find context';
+$string['cannotfindcourse'] = 'Cannot find course';
$string['cannotfindcategory'] = 'Cannot find category record from database by ID - $a';
$string['cannotfinddocs'] = 'Cannot find \"$a\" language docs files';
$string['cannotfindgradeitem'] = 'Cannot find grade_item';
$string['couldnotassignrole'] = 'A serious but unspecified error occurred while trying to assign a role to you';
$string['couldnotupdatenoexistinguser'] = 'Cannot update the user - user doesn\'t exist';
$string['countriesphpempty'] = 'Error: The file countries.php in language pack $a is empty or missing.';
+$string['coursedoesnotbelongtocategory'] = 'The course doesn\'t belong to this category';
$string['coursegroupunknown'] = 'Course corresponding to group $a not specified';
$string['courseidnotfound'] = 'Course id doesn\'t exist';
$string['coursemisconf'] = 'Course is misconfigured';