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_CLEAN); if ($CFG->forcelogin) { require_login(); } if (!$site = get_site()) { print_error("Site isn't defined!"); } if (empty($id)) { print_error("Category not known!"); } if (!$context = get_context_instance(CONTEXT_COURSECAT, $id)) { print_error("Category not known!"); } if (!$category = get_record("course_categories", "id", $id)) { print_error("Category not known!"); } if (has_capability('moodle/course:create', $context)) { 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); } else { if (!$category->visible) { print_error('notavailable', 'error'); } $navbaritem = print_course_search("", true, "navbar"); $adminediting = false; $creatorediting = false; } if (has_capability('moodle/category:update', $context)) { /// Rename the category if requested if (!empty($rename) and confirm_sesskey()) { $category->name = $rename; if (! set_field("course_categories", "name", $category->name, "id", $category->id)) { notify("An error occurred while renaming the category"); } // MDL-9983 events_trigger('category_updated', $category); } /// Set the category theme if requested if (($categorytheme !== false) and confirm_sesskey()) { $category->theme = $categorytheme; if (! set_field('course_categories', 'theme', $category->theme, 'id', $category->id)) { notify('An error occurred while setting the theme'); } } /// Resort the category if requested if ($resort and confirm_sesskey()) { if ($courses = get_courses($category->id, "fullname ASC", 'c.id,c.fullname,c.sortorder')) { // move it off the range $count = get_record_sql('SELECT MAX(sortorder) AS max, 1 FROM ' . $CFG->prefix . 'course WHERE category=' . $category->id); $count = $count->max + 100; begin_sql(); foreach ($courses as $course) { set_field('course', 'sortorder', $count, 'id', $course->id); $count++; } commit_sql(); fix_course_sortorder($category->id); } } } if(! empty($CFG->allowcategorythemes) ){ if(isset($category->theme)){ // specifying theme here saves us some dbqs theme_setup($category->theme); } } /// Print headings $numcategories = 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 ($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); } } else { print_header("$site->shortname: $category->name", "$site->fullname: $strcourses", $navigation, "", "", true, $navbaritem); } /// Print button to turn editing off if ($adminediting) { 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, ""); echo '
'; popup_form('category.php?id=', $displaylist, 'switchcategory', $category->id, '', '', '', false, 'self', $strcategories.':'); echo '
'; /// Print current category description if (!$creatorediting && $category->description) { print_box_start(); echo format_text($category->description); // for multilang filter print_box_end(); } /// Editing functions if ($creatorediting) { /// 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)); if (! $destcategory = get_record("course_categories", "id", $data->moveto)) { print_error("Error finding the category"); } $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 = get_record("course", "id", $hide); $visible = 0; } else { $course = get_record("course", "id", $show); $visible = 1; } if ($course) { if (! set_field("course", "visible", $visible, "id", $course->id)) { notify("Could not update that course!"); } } } /// Move a course up or down if ((!empty($moveup) or !empty($movedown)) and confirm_sesskey()) { require_capability('moodle/category:update', $context); $movecourse = NULL; $swapcourse = NULL; // ensure the course order has no gaps // and isn't at 0 fix_course_sortorder($category->id); // we are going to need to know the range $max = get_record_sql('SELECT MAX(sortorder) AS max, 1 FROM ' . $CFG->prefix . 'course WHERE category=' . $category->id); $max = $max->max + 100; if (!empty($moveup)) { $movecourse = get_record('course', 'id', $moveup); $swapcourse = get_record('course', 'category', $category->id, 'sortorder', $movecourse->sortorder - 1); } else { $movecourse = get_record('course', 'id', $movedown); $swapcourse = get_record('course', 'category', $category->id, 'sortorder', $movecourse->sortorder + 1); } if ($swapcourse and $movecourse) { // Renumber everything for robustness begin_sql(); if (!( set_field("course", "sortorder", $max, "id", $swapcourse->id) && set_field("course", "sortorder", $swapcourse->sortorder, "id", $movecourse->id) && set_field("course", "sortorder", $movecourse->sortorder, "id", $swapcourse->id) )) { notify("Could not update that course!"); } commit_sql(); } } } // End of editing stuff 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'); } 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 = get_records("course_categories", "parent", $category->id, "sortorder ASC")) { $firstentry = true; foreach ($subcategories as $subcategory) { if ($subcategory->visible or has_capability('moodle/course:create', $context)) { $subcategorieswereshown = true; if ($firstentry) { echo ''; echo ''; echo '
'.get_string('subcategories').'
'; $firstentry = false; } $catlinkcss = $subcategory->visible ? "" : " class=\"dimmed\" "; echo ''. format_string($subcategory->name).'
'; } } if (!$firstentry) { 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.teacher,c.guest,c.password', $totalcount, $page*$perpage, $perpage); $numcourses = count($courses); if (!$courses) { if (empty($subcategorieswereshown)) { print_heading(get_string("nocoursesyet")); } } else if ($numcourses <= COURSE_MAX_SUMMARIES_PER_PAGE and !$page and !$creatorediting) { print_box_start('courseboxes'); print_courses($category); print_box_end(); } 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"); echo '
'; echo ''; echo ''; echo ''; if ($creatorediting) { echo ''; if ($adminediting) { echo ''; } } else { echo ''; } echo ''; $count = 0; $abletomovecourses = false; // for now // Checking if we are at the first or at the last page, to allow courses to // be moved up and down beyond the paging border if ($totalcount > $perpage) { $atfirstpage = ($page == 0); if ($perpage > 0) { $atlastpage = (($page + 1) == ceil($totalcount / $perpage)); } else { $atlastpage = true; } } else { $atfirstpage = true; $atlastpage = true; } foreach ($courses as $acourse) { if (isset($acourse->context)) { $coursecontext = $acourse->context; } else { $coursecontext = get_context_instance(CONTEXT_COURSE, $acourse->id); } $count++; $up = ($count > 1 || !$atfirstpage); $down = ($count < $numcourses || !$atlastpage); $linkcss = $acourse->visible ? "" : ' class="dimmed" '; echo ''; echo ''; if ($creatorediting) { echo "'; echo ''; } else { echo '"; } echo ""; } if ($abletomovecourses) { echo ''; } echo '
'.$strcourses.''.$stredit.''.$strselect.' 
'. format_string($acourse->fullname) .'"; if (has_capability('moodle/course:update', $coursecontext)) { echo ''. ''.$stredit.' '; } // role assignment link if (has_capability('moodle/role:assign', $coursecontext)) { echo''.get_string('assignroles', 'role').''; } if (can_delete_course($acourse->id)) { echo ''. ''.$strdelete.' '; } // MDL-8885, users with no capability to view hidden courses, should not be able to lock themselves out if (has_capability('moodle/course:visibility', $coursecontext) && has_capability('moodle/course:viewhiddencourses', $coursecontext)) { if (!empty($acourse->visible)) { echo ''. ''.$strhide.' '; } else { echo ''. ''.$strshow.' '; } } if (has_capability('moodle/site:backup', $coursecontext)) { echo ''. ''.$strbackup.' '; } if (has_capability('moodle/site:restore', $coursecontext)) { echo ''. ''.$strrestore.' '; } if (has_capability('moodle/category:update', $context)) { if ($up) { echo ''. ''.$strmoveup.' '; } else { echo ' '; } if ($down) { echo ''. ''.$strmovedown.' '; } else { echo ' '; } $abletomovecourses = true; } echo ''; echo ''; echo ''; if (!empty($acourse->guest)) { echo ''.$strallowguests.''; } if (!empty($acourse->password)) { echo ''.$strrequireskey.''; } if (!empty($acourse->summary)) { link_to_popup_window ("/course/info.php?id=$acourse->id", "courseinfo", ''.get_string('info').'', 400, 500, $strsummary); } echo "
'; echo '
'; unset($displaylist[$category->id]); // loop and unset categories the user can't move into foreach ($displaylist as $did=>$dlist) { if (!has_capability('moodle/category:update', get_context_instance(CONTEXT_COURSECAT, $did))) { unset($displaylist[$did]); } } choose_from_menu ($displaylist, "moveto", "", get_string("moveselectedcoursesto"), "javascript: submitFormById('movecourses')"); echo ''; echo '
'; echo '
'; echo '
'; } echo '
'; if (has_capability('moodle/category:update', get_context_instance(CONTEXT_SYSTEM)) and $numcourses > 1) { /// Print button to re-sort courses by name unset($options); $options['id'] = $category->id; $options['resort'] = 'name'; $options['sesskey'] = $USER->sesskey; print_single_button('category.php', $options, get_string('resortcoursesbyname'), 'get'); } if (has_capability('moodle/course:create', $context)) { /// Print button to create a new course unset($options); $options['category'] = $category->id; print_single_button('edit.php', $options, get_string('addnewcourse'), 'get'); } echo '
'; print_course_search(); print_footer(); ?>