forcelogin) { require_login(); } if (has_capability('moodle/category:update', $sysctx)) { if ($categoryedit !== -1) { $USER->categoryediting = $categoryedit; } $adminediting = !empty($USER->categoryediting); } else { $adminediting = false; } $stradministration = get_string('administration'); $strcategories = get_string('categories'); $strcategory = get_string('category'); $strcourses = get_string('courses'); $stredit = get_string('edit'); $strdelete = get_string('delete'); $straction = get_string('action'); /// Unless it's an editing admin, just print the regular listing of courses/categories if (!$adminediting) { /// Print form for creating new categories $countcategories = $DB->count_records('course_categories'); if ($countcategories > 1 || ($countcategories == 1 && $DB->count_records('course') > 200)) { $strcourses = get_string('courses'); $strcategories = get_string('categories'); $navlinks = array(); $navlinks[] = array('name'=>$strcategories,'link'=>'','type'=>'misc'); $navigation = build_navigation($navlinks); print_header("$site->shortname: $strcategories", $strcourses, $navigation, '', '', true, update_categories_button()); print_heading($strcategories); echo skip_main_destination(); print_box_start('categorybox'); print_whole_category_list(); print_box_end(); print_course_search(); } else { $strfulllistofcourses = get_string('fulllistofcourses'); print_header("$site->shortname: $strfulllistofcourses", $strfulllistofcourses, build_navigation(array(array('name'=>$strfulllistofcourses, 'link'=>'','type'=>'misc'))), '', '', true, update_categories_button()); echo skip_main_destination(); print_box_start('courseboxes'); print_courses(0); print_box_end(); } /// I am not sure this context in the next has_capability call is correct. if (isloggedin() and !isguest() and !has_capability('moodle/course:create', $sysctx) and $CFG->enablecourserequests) { // Print link to request a new course print_single_button('request.php', NULL, get_string('courserequest'), 'get'); } if (has_capability('moodle/course:create', $sysctx)) { // Print link to create a new course /// Get the 1st available category $options = array('category' => $DB->get_field('course_categories', 'id', array('parent'=>'0'))); print_single_button('edit.php', $options, get_string('addnewcourse'), 'get'); } if (has_capability('moodle/site:approvecourse', $sysctx) and !empty($CFG->enablecourserequests)) { print_single_button('pending.php',NULL, get_string('coursespending'),'get'); } print_footer(); exit; } /// From now on is all the admin/course creator functions /// Delete a category if necessary if (!empty($delete) and confirm_sesskey()) { require_once('delete_category_form.php'); if (!$deletecat = $DB->get_record('course_categories', array('id'=>$delete))) { print_error('invalidcategoryid'); } $heading = get_string('deletecategory', '', format_string($deletecat->name)); $context = get_context_instance(CONTEXT_COURSECAT, $delete); require_capability('moodle/category:delete', $context); $mform = new delete_category_form(null, $deletecat); $mform->set_data(array('delete'=>$delete)); if ($mform->is_cancelled()) { redirect('index.php'); } else if (!$data= $mform->get_data()) { require_once($CFG->libdir . '/questionlib.php'); print_category_edit_header(); print_heading($heading); print_box(get_string('deletecategorycheck2'), 'generalbox boxwidthnormal boxaligncenter'); if (question_context_has_any_questions($context)) { print_box(get_string('deletecoursecategorywithquestions', 'question'), 'generalbox boxwidthnormal boxaligncenter'); } $mform->display(); print_footer(); exit(); } print_category_edit_header(); print_heading($heading); if ($data->fulldelete) { category_delete_full($deletecat, true); } else { category_delete_move($deletecat, $data->newparent, true); } print_continue('index.php'); print_footer(); die; } /// Print headings print_category_edit_header(); print_heading($strcategories); /// Create a default category if necessary if (!$categories = get_categories()) { /// No category yet! // Try and make one $tempcat = new object(); $tempcat->name = get_string('miscellaneous'); if (!$tempcat->id = $DB->insert_record('course_categories', $tempcat)) { print_error('cannotsetupcategory'); } $tempcat->context = get_context_instance(CONTEXT_COURSECAT, $tempcat->id); mark_context_dirty('/'.SYSCONTEXTID); } /// Move a category to a new parent if required if (!empty($move) and ($moveto>=0) and confirm_sesskey()) { if ($tempcat = $DB->get_record('course_categories', array('id'=>$move))) { if ($tempcat->parent != $moveto) { $newp = $DB->get_record('course_categories', array('id'=>$moveto)); if (! move_category($tempcat, $newp)) { notify('Could not update that category!'); } } } } /// Hide or show a category if ((!empty($hide) or !empty($show)) and confirm_sesskey()) { if (!empty($hide)) { $tempcat = $DB->get_record('course_categories', array('id'=>$hide)); $visible = 0; } else { $tempcat = $DB->get_record('course_categories', array('id'=>$show)); $visible = 1; } if ($tempcat) { if (!$DB->set_field('course_categories', 'visible', $visible, array('id'=>$tempcat->id))) { notify('Could not update that category!'); } if (!$DB->set_field('course', 'visible', $visible, array('category'=>$tempcat->id))) { notify('Could not hide/show any courses in this category !'); } } } /// Move a category up or down if ((!empty($moveup) or !empty($movedown)) and confirm_sesskey()) { fix_course_sortorder(); $swapcategory = NULL; if (!empty($moveup)) { if ($movecategory = $DB->get_record('course_categories', array('id'=>$moveup))) { if ($swapcategory = $DB->get_records_select('course_categories', "sortorder AND parent=?", array($movecategory->sortorder, $movecategory->parent), 'sortorder ASC', '*', 0, 1)) { $swapcategory = reset($swapcategory); } } } else { if ($movecategory = $DB->get_record('course_categories', array('id'=>$movedown))) { if ($swapcategory = $DB->get_records_select('course_categories', "sortorder>? AND parent=?", array($movecategory->sortorder, $movecategory->parent), 'sortorder ASC', '*', 0, 1)) { $swapcategory = reset($swapcategory); } } } if ($swapcategory and $movecategory) { $DB->set_field('course_categories', 'sortorder', $swapcategory->sortorder, array('id'=>$movecategory->id)); $DB->set_field('course_categories', 'sortorder', $movecategory->sortorder, array('id'=>$swapcategory->id)); } // finally reorder courses fix_course_sortorder(); } /// This should not be needed anymore //fix_course_sortorder(); /// Print out the categories with all the knobs $strcategories = get_string('categories'); $strcourses = get_string('courses'); $strmovecategoryto = get_string('movecategoryto'); $stredit = get_string('edit'); $displaylist = array(); $parentlist = array(); $displaylist[0] = get_string('top'); make_categories_list($displaylist, $parentlist, ''); echo '
'.$strcategories.' | '; echo ''.$strcourses.' | '; echo ''.$stredit.' | '; echo ''.$strmovecategoryto.' | '; echo '
---|