diff --git a/admin/settings/courses.php b/admin/settings/courses.php
index 9608e741bfd..d0d7013c464 100644
--- a/admin/settings/courses.php
+++ b/admin/settings/courses.php
@@ -4,10 +4,11 @@
if ($hassiteconfig
or has_capability('moodle/site:backup', $systemcontext)
- or has_capability('moodle/category:update', $systemcontext)) { // speedup for non-admins, add all caps used on this page
+ or has_capability('moodle/category:manage', $systemcontext)
+ or has_capability('moodle/course:create', $systemcontext)) { // speedup for non-admins, add all caps used on this page
-
- $ADMIN->add('courses', new admin_externalpage('coursemgmt', get_string('coursemgmt', 'admin'), $CFG->wwwroot . '/course/index.php?categoryedit=on','moodle/category:update'));
+ $ADMIN->add('courses', new admin_externalpage('coursemgmt', get_string('coursemgmt', 'admin'), $CFG->wwwroot . '/course/index.php?categoryedit=on',
+ array('moodle/category:manage', 'moodle/course:create')));
$ADMIN->add('courses', new admin_enrolment_page());
diff --git a/course/category.php b/course/category.php
index b30cb9fb73f..8bcbfd5acf5 100644
--- a/course/category.php
+++ b/course/category.php
@@ -6,25 +6,23 @@
require_once("../config.php");
require_once("lib.php");
- $id = required_param('id', PARAM_INT); // Category id
- $page = optional_param('page', 0, PARAM_INT); // which page to show
- $perpage = optional_param('perpage', $CFG->coursesperpage, PARAM_INT); // how many per page
+ $id = required_param('id', PARAM_INT); // Category id
+ $page = optional_param('page', 0, PARAM_INT); // which page to show
+ $perpage = optional_param('perpage', $CFG->coursesperpage, PARAM_INT); // how many per page
$categoryedit = optional_param('categoryedit', -1, PARAM_BOOL);
- $hide = optional_param('hide', 0, PARAM_INT);
- $show = optional_param('show', 0, PARAM_INT);
- $moveup = optional_param('moveup', 0, PARAM_INT);
- $movedown = optional_param('movedown', 0, PARAM_INT);
- $moveto = optional_param('moveto', 0, PARAM_INT);
- $rename = optional_param('rename', '', PARAM_TEXT);
- $resort = optional_param('resort', 0, PARAM_BOOL);
- $categorytheme= optional_param('categorytheme', false, PARAM_SAFEDIR);
+ $hide = optional_param('hide', 0, PARAM_INT);
+ $show = optional_param('show', 0, PARAM_INT);
+ $moveup = optional_param('moveup', 0, PARAM_INT);
+ $movedown = optional_param('movedown', 0, PARAM_INT);
+ $moveto = optional_param('moveto', 0, PARAM_INT);
+ $resort = optional_param('resort', 0, PARAM_BOOL);
if ($CFG->forcelogin) {
require_login();
}
if (!$site = get_site()) {
- print_error("siteisnotdefined", 'debug');
+ print_error('siteisnotdefined', 'debug');
}
if (empty($id)) {
@@ -38,45 +36,24 @@
if (!$category = $DB->get_record("course_categories", array("id"=>$id))) {
print_error("unknowcategory");
}
+ if (!$category->visible) {
+ require_capability('moodle/category:viewhiddencategories', $context);
+ }
- if (has_capability('moodle/course:create', $context)) {
+ if (update_category_button($category->id)) {
if ($categoryedit !== -1) {
$USER->categoryediting = $categoryedit;
}
- $navbaritem = update_category_button($category->id);
- $creatorediting = !empty($USER->categoryediting);
- $adminediting = (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and $creatorediting);
-
+ $editingon = !empty($USER->categoryediting);
+ $navbaritem = update_category_button($category->id); // Must call this again after updating the state.
} else {
- if (!$category->visible) {
- print_error('notavailable', 'error');
- }
- $navbaritem = print_course_search("", true, "navbar");
- $adminediting = false;
- $creatorediting = false;
+ $navbaritem = print_course_search('', true, 'navbar');
+ $editingon = false;
}
- if (has_capability('moodle/category:update', $context)) {
- /// Rename the category if requested
- if (!empty($rename) and confirm_sesskey()) {
- if (!$DB->set_field("course_categories", "name", $rename, array("id"=>$category->id))) {
- notify("An error occurred while renaming the category");
- }
- $category->name = $rename;
- //trigger events
- events_trigger('course_category_updated', $category);
- }
-
- /// Set the category theme if requested
- if (($categorytheme !== false) and confirm_sesskey()) {
- $category->theme = $categorytheme;
- if (!$DB->set_field('course_categories', 'theme', $category->theme, array('id'=>$category->id))) {
- notify('An error occurred while setting the theme');
- }
- }
-
+ // Process any category actions.
+ if (has_capability('moodle/category:manage', $context)) {
/// Resort the category if requested
-
if ($resort and confirm_sesskey()) {
if ($courses = get_courses($category->id, "fullname ASC", 'c.id,c.fullname,c.sortorder')) {
$i = 1;
@@ -89,88 +66,75 @@
}
}
- if(! empty($CFG->allowcategorythemes) ){
- if(isset($category->theme)){
- // specifying theme here saves us some dbqs
- theme_setup($category->theme);
- }
+ if(!empty($CFG->allowcategorythemes) && isset($category->theme)) {
+ // specifying theme here saves us some dbqs
+ theme_setup($category->theme);
}
/// Print headings
+ $numcategories = $DB->count_records('course_categories');
- $numcategories = $DB->count_records("course_categories");
-
- $stradministration = get_string("administration");
- $strcategories = get_string("categories");
- $strcategory = get_string("category");
- $strcourses = get_string("courses");
+ $stradministration = get_string('administration');
+ $strcategories = get_string('categories');
+ $strcategory = get_string('category');
+ $strcourses = get_string('courses');
$navlinks = array();
$navlinks[] = array('name' => $strcategories, 'link' => 'index.php', 'type' => 'misc');
$navlinks[] = array('name' => format_string($category->name), 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
- if ($creatorediting) {
- if ($adminediting) {
- // modify this to treat this as an admin page
-
- require_once($CFG->libdir.'/adminlib.php');
- admin_externalpage_setup('coursemgmt');
- admin_externalpage_print_header();
- } else {
- print_header("$site->shortname: $category->name", "$site->fullname: $strcourses", $navigation, "", "", true, $navbaritem);
- }
+ if ($editingon && update_category_button()) {
+ // Integrate into the admin tree only if the user can edit categories at the top level,
+ // otherwise the admin block does not appear to this user, and you get an error.
+ require_once($CFG->libdir.'/adminlib.php');
+ admin_externalpage_setup('coursemgmt');
+ admin_externalpage_print_header();
} else {
- print_header("$site->shortname: $category->name", "$site->fullname: $strcourses", $navigation, "", "", true, $navbaritem);
+ print_header("$site->shortname: $category->name", "$site->fullname: $strcourses", $navigation, '', '', true, $navbaritem);
}
/// Print button to turn editing off
- if ($adminediting) {
+ if ($editingon) {
echo '
'.update_category_button($category->id).'
';
}
/// Print link to roles
-
if (has_capability('moodle/role:assign', $context)) {
echo '';
}
+
/// Print the category selector
-
$displaylist = array();
- $parentlist = array();
-
- make_categories_list($displaylist, $parentlist, "");
+ $notused = array();
+ make_categories_list($displaylist, $notused);
echo '';
popup_form('category.php?id=', $displaylist, 'switchcategory', $category->id, '', '', '', false, 'self', $strcategories.':');
echo '
';
/// Print current category description
- if (!$creatorediting && $category->description) {
+ if (!$editingon && $category->description) {
print_box_start();
echo format_text($category->description); // for multilang filter
print_box_end();
}
-/// Editing functions
-
- if ($creatorediting) {
+/// Process any course actions.
+ if ($editingon) {
/// Move a specified course to a new category
-
if (!empty($moveto) and $data = data_submitted() and confirm_sesskey()) { // Some courses are being moved
-
// user must have category update in both cats to perform this
- require_capability('moodle/category:update', $context);
- require_capability('moodle/category:update', get_context_instance(CONTEXT_COURSECAT, $moveto));
+ require_capability('moodle/category:manage', $context);
+ require_capability('moodle/category:manage', get_context_instance(CONTEXT_COURSECAT, $moveto));
- if (! $destcategory = $DB->get_record("course_categories", array("id"=>$data->moveto))) {
- print_error("cannotfindcategory", '', '', $data->moveto);
+ if (!$destcategory = $DB->get_record('course_categories', array('id' => $data->moveto))) {
+ print_error('cannotfindcategory', '', '', $data->moveto);
}
-
$courses = array();
- foreach ( $data as $key => $value ) {
+ foreach ($data as $key => $value) {
if (preg_match('/^c\d+$/', $key)) {
array_push($courses, substr($key, 1));
}
@@ -179,73 +143,67 @@
}
/// 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));
+ $course = $DB->get_record('course', array('id' => $hide));
$visible = 0;
} else {
- $course = $DB->get_record("course", array("id"=>$show));
+ $course = $DB->get_record('course', array('id' => $show));
$visible = 1;
}
if ($course) {
- if (!$DB->set_field("course", "visible", $visible, array("id"=>$course->id))) {
- notify("Could not update that course!");
+ if (!$DB->set_field('course', 'visible', $visible, array('id' => $course->id))) {
+ print_error('errorupdatingcoursevisibility');
}
}
}
/// Move a course up or down
-
if ((!empty($moveup) or !empty($movedown)) and confirm_sesskey()) {
- require_capability('moodle/category:update', $context);
+ require_capability('moodle/category:manage', $context);
- // ensure the course order has continuous ordering
+ // Ensure the course order has continuous ordering
fix_course_sortorder();
$swapcourse = NULL;
if (!empty($moveup)) {
- if ($movecourse = $DB->get_record('course', array('id'=>$moveup))) {
- $swapcourse = $DB->get_record('course', array('sortorder'=>$movecourse->sortorder-1));
+ if ($movecourse = $DB->get_record('course', array('id' => $moveup))) {
+ $swapcourse = $DB->get_record('course', array('sortorder' => $movecourse->sortorder - 1));
}
} else {
- if ($movecourse = $DB->get_record('course', array('id'=>$movedown))) {
- $swapcourse = $DB->get_record('course', array('sortorder'=>$movecourse->sortorder+1));
+ if ($movecourse = $DB->get_record('course', array('id' => $movedown))) {
+ $swapcourse = $DB->get_record('course', array('sortorder' => $movecourse->sortorder + 1));
}
}
if ($swapcourse and $movecourse) {
- $DB->set_field('course', 'sortorder', $swapcourse->sortorder, array('id'=>$movecourse->id));
- $DB->set_field('course', 'sortorder', $movecourse->sortorder, array('id'=>$swapcourse->id));
+ $DB->set_field('course', 'sortorder', $swapcourse->sortorder, array('id' => $movecourse->id));
+ $DB->set_field('course', 'sortorder', $movecourse->sortorder, array('id' => $swapcourse->id));
}
}
} // End of editing stuff
+ if ($editingon && has_capability('moodle/category:manage', $context)) {
+ echo '';
- if ($creatorediting) {
- echo '
';
- if (has_capability('moodle/category:update', $context)) { // Print button to update this category
- unset($options);
- $options['id'] = $category->id;
- print_single_button('editcategory.php', $options, get_string('editcategorythis'), 'get');
- }
+ // Print button to update this category
+ $options = array('id' => $category->id);
+ print_single_button($CFG->wwwroot.'/course/editcategory.php', $options, get_string('editcategorythis'), 'get');
+
+ // Print button for creating new categories
+ $options = array('parent' => $category->id);
+ print_single_button($CFG->wwwroot.'/course/editcategory.php', $options, get_string('addsubcategory'), 'get');
- if (has_capability('moodle/category:create', $context)) { // Print button for creating new categories
- unset($options);
- $options['categoryadd'] = 1;
- $options['id'] = $id;
- print_single_button('editcategory.php', $options, get_string('addsubcategory'), 'get');
- }
echo '
';
}
/// Print out all the sub-categories
- if ($subcategories = $DB->get_records("course_categories", array("parent"=>$category->id), "sortorder ASC")) {
+ if ($subcategories = $DB->get_records('course_categories', array('parent' => $category->id), 'sortorder ASC')) {
$firstentry = true;
foreach ($subcategories as $subcategory) {
- if ($subcategory->visible or has_capability('moodle/course:create', $context)) {
+ if ($subcategory->visible || has_capability('moodle/category:viewhiddencategories', $context)) {
$subcategorieswereshown = true;
if ($firstentry) {
echo '
';
@@ -253,24 +211,21 @@
echo '';
$firstentry = false;
}
- $catlinkcss = $subcategory->visible ? "" : " class=\"dimmed\" ";
+ $catlinkcss = $subcategory->visible ? '' : ' class="dimmed" ';
echo ''.
format_string($subcategory->name).' ';
}
}
if (!$firstentry) {
- echo " |
";
- echo "
";
+ echo '';
+ echo '
';
}
}
-
/// Print out all the courses
- unset($course); // To avoid unwanted language effects later
-
$courses = get_courses_page($category->id, 'c.sortorder ASC',
- 'c.id,c.sortorder,c.shortname,c.fullname,c.summary,c.visible,c.guest,c.password',
- $totalcount, $page*$perpage, $perpage);
+ 'c.id,c.sortorder,c.shortname,c.fullname,c.summary,c.visible,c.guest,c.password',
+ $totalcount, $page*$perpage, $perpage);
$numcourses = count($courses);
if (!$courses) {
@@ -278,7 +233,7 @@
print_heading(get_string("nocoursesyet"));
}
- } else if ($numcourses <= COURSE_MAX_SUMMARIES_PER_PAGE and !$page and !$creatorediting) {
+ } else if ($numcourses <= COURSE_MAX_SUMMARIES_PER_PAGE and !$page and !$editingon) {
print_box_start('courseboxes');
print_courses($category);
print_box_end();
@@ -286,33 +241,31 @@
} else {
print_paging_bar($totalcount, $page, $perpage, "category.php?id=$category->id&perpage=$perpage&");
- $strcourses = get_string("courses");
- $strselect = get_string("select");
- $stredit = get_string("edit");
- $strdelete = get_string("delete");
- $strbackup = get_string("backup");
- $strrestore = get_string("restore");
- $strmoveup = get_string("moveup");
- $strmovedown = get_string("movedown");
- $strupdate = get_string("update");
- $strhide = get_string("hide");
- $strshow = get_string("show");
- $strsummary = get_string("summary");
- $strsettings = get_string("settings");
- $strassignteachers = get_string("assignteachers");
- $strallowguests = get_string("allowguests");
- $strrequireskey = get_string("requireskey");
+ $strcourses = get_string('courses');
+ $strselect = get_string('select');
+ $stredit = get_string('edit');
+ $strdelete = get_string('delete');
+ $strbackup = get_string('backup');
+ $strrestore = get_string('restore');
+ $strmoveup = get_string('moveup');
+ $strmovedown = get_string('movedown');
+ $strupdate = get_string('update');
+ $strhide = get_string('hide');
+ $strshow = get_string('show');
+ $strsummary = get_string('summary');
+ $strsettings = get_string('settings');
+ $strassignteachers = get_string('assignteachers');
+ $strallowguests = get_string('allowguests');
+ $strrequireskey = get_string('requireskey');
echo '