coursesperpage, PARAM_INT); // how many per page $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); $categoryedit = optional_param('categoryedit', -1, PARAM_BOOL); // Enables Move/Delete/Hide icons near each category in the list $categoryadd = optional_param('categoryadd', 0, PARAM_BOOL); // Enables the Add Category form $categoryupdate = optional_param('categoryupdate', 0, PARAM_BOOL); // Enables the Edit Category form $resort = optional_param('resort', 0, PARAM_BOOL); if (!$site = get_site()) { print_error("siteisnotdefined"); } if ($categoryadd) { // Show Add category form: if $id is given, it is used as the parent category $strtitle = get_string("addnewcategory"); $context = get_context_instance(CONTEXT_SYSTEM); $category = null; } elseif (!is_null($id) && !$categoryadd) { // Show Edit category form: $id is given as the identifier of the category being edited $strtitle = get_string("editcategorysettings"); $context = get_context_instance(CONTEXT_COURSECAT, $id); if (!$category = $DB->get_record("course_categories", array("id"=>$id))) { print_error("unknowcategory"); } } $mform = new editcategory_form('editcategory.php', compact(array('category', 'id'))); if (!empty($category)) { $mform->set_data($category); } elseif (!is_null($id)) { $data = new stdClass(); $data->parent = $id; $data->categoryadd = 1; $mform->set_data($data); } if ($mform->is_cancelled()){ if (empty($category)) { redirect($CFG->wwwroot .'/course/index.php?categoryedit=on'); } else { redirect($CFG->wwwroot.'/course/category.php?categoryedit=on&id='.$category->id); } } else if (($data = $mform->get_data())) { $newcategory = new stdClass(); $newcategory->name = $data->name; $newcategory->description = $data->description; $newcategory->sortorder = 999; $newcategory->parent = $data->parent; // if $id = 0, the new category will be a top-level category if (!empty($data->theme) && !empty($CFG->allowcategorythemes)) { $newcategory->theme = $data->theme; theme_setup(); } if (empty($category) && has_capability('moodle/category:create', $context)) { // Create a new category if (!$newcategory->id = $DB->insert_record('course_categories', $newcategory)) { notify( "Could not insert the new category '$newcategory->name' "); } else { $newcategory->context = get_context_instance(CONTEXT_COURSECAT, $newcategory->id); mark_context_dirty($newcategory->context->path); redirect('index.php?categoryedit=on'); } } elseif (has_capability('moodle/category:update', $context)) { $newcategory->id = $category->id; if ($newcategory->parent != $category->parent) { $parent_cat = $DB->get_record('course_categories', array('id'=>$newcategory->parent)); move_category($newcategory, $parent_cat); } if (!$DB->update_record('course_categories', $newcategory)) { print_error( "cannotupdatecategory", '', '', $newcategory->name); } else { if ($newcategory->parent == 0) { $redirect_link = 'index.php?categoryedit=on'; } else { $redirect_link = 'category.php?id='.$newcategory->id.'&categoryedit=on'; } fix_course_sortorder(); redirect($redirect_link); } } } // If id is given, but not categoryadd or categoryupdate, we show the category with its list of subcategories if ($id && !$categoryadd && !$categoryupdate && false) { /* TODO implement if ($CFG->forcelogin) { require_login(); } // Determine whether to allow user to see this category 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; } // Resort the category if requested if ($resort and confirm_sesskey()) { if ($courses = get_courses($id, "fullname ASC", 'c.id,c.fullname,c.sortorder')) { // move it off the range $count = $DB->get_record_sql('SELECT MAX(sortorder) AS max, 1 FROM {course} WHERE category=' . $category->id); $count = $count->max + 100; $DB->begin_sql(); foreach ($courses as $course) { $DB->set_field('course', 'sortorder', $count, array('id'=>$course->id)); $count++; } $DB->commit_sql(); fix_course_sortorder($category->id); } } // 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' => $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('categorymgmt'); admin_externalpage_print_header(); } else { print_header("$site->shortname: $category->name", "$site->fullname: $strcategories", $navigation, "", "", true, $navbaritem); } } else { print_header("$site->shortname: $category->name", "$site->fullname: $strcategories", $navigation, "", "", true, $navbaritem); } // Print button to turn editing off if ($adminediting) { echo '
'; } // 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 ''.get_string('subcategories').' |
---|
';
$firstentry = false;
}
$catlinkcss = $subcategory->visible ? "" : " class=\"dimmed\" ";
echo ''.
format_string($subcategory->name).' '; } } if (!$firstentry) { echo " |