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); $resort = optional_param('resort', 0, PARAM_BOOL); if (!$site = get_site()) { print_error('siteisnotdefined', 'debug'); } if (empty($id)) { print_error("unknowcategory"); } $PAGE->set_category_by_id($id); $urlparams = array('id' => $id); if ($page) { $urlparams['page'] = $page; } if ($perpage) { $urlparams['perpage'] = $perpage; } $PAGE->set_url('course/category.php', $urlparams); $context = $PAGE->context; $category = $PAGE->category; $canedit = can_edit_in_category($category->id); if ($canedit) { if ($categoryedit !== -1) { $USER->editing = $categoryedit; } require_login(); $editingon = $PAGE->user_is_editing(); } else { if ($CFG->forcelogin) { require_login(); } $editingon = false; } if (!$category->visible) { require_capability('moodle/category:viewhiddencategories', $context); } // 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; foreach ($courses as $course) { $DB->set_field('course', 'sortorder', $category->sortorder+$i, array('id'=>$course->id)); $i++; } fix_course_sortorder(); // should not be needed } } } // 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: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); } $courses = array(); foreach ($data as $key => $value) { if (preg_match('/^c\d+$/', $key)) { array_push($courses, substr($key, 1)); } } 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; } else { $course = $DB->get_record('course', array('id' => $show)); $visible = 1; } if ($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:manage', $context); // 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)); } } else { 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)); } } } // End of editing stuff // Print headings $numcategories = $DB->count_records('course_categories'); $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 ($editingon && can_edit_in_category()) { // 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', '', $urlparams, $CFG->wwwroot . '/course/category.php'); admin_externalpage_print_header(); } else { $navbaritem = print_course_search('', true, 'navbar'); print_header("$site->shortname: $category->name", "$site->fullname: $strcourses", $navigation, '', '', true, $navbaritem); } /// Print link to roles if (has_capability('moodle/role:assign', $context)) { echo '
'; } /// Print the category selector $displaylist = array(); $notused = array(); make_categories_list($displaylist, $notused); echo ''.get_string('subcategories').' |
---|
';
$firstentry = false;
}
$catlinkcss = $subcategory->visible ? '' : ' class="dimmed" ';
echo ''.
format_string($subcategory->name).' '; } } if (!$firstentry) { echo ' |