2004-09-12 12:21:27 +00:00
< ? php // $Id$
2003-08-07 16:01:31 +00:00
// For most people, just lists the course categories
// Allows the admin to create, delete and rename course categories
2001-11-22 06:23:56 +00:00
2004-05-30 00:33:45 +00:00
require_once ( " ../config.php " );
require_once ( " lib.php " );
2001-11-22 06:23:56 +00:00
2006-08-18 07:27:05 +00:00
$categoryedit = optional_param ( 'categoryedit' , - 1 , PARAM_BOOL );
2006-04-11 20:39:30 +00:00
$delete = optional_param ( 'delete' , 0 , PARAM_INT );
$hide = optional_param ( 'hide' , 0 , PARAM_INT );
$show = optional_param ( 'show' , 0 , PARAM_INT );
$move = optional_param ( 'move' , 0 , PARAM_INT );
$moveto = optional_param ( 'moveto' , - 1 , PARAM_INT );
$moveup = optional_param ( 'moveup' , 0 , PARAM_INT );
$movedown = optional_param ( 'movedown' , 0 , PARAM_INT );
2008-05-13 21:52:38 +00:00
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
if ( $CFG -> forcelogin ) {
require_login ();
}
2005-06-14 09:21:09 +00:00
2003-08-07 16:01:31 +00:00
if ( ! $site = get_site ()) {
2008-05-07 06:02:51 +00:00
print_error ( 'siteisnotdefined' , 'debug' );
2003-08-07 16:01:31 +00:00
}
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
$systemcontext = get_context_instance ( CONTEXT_SYSTEM );
2004-01-14 08:27:40 +00:00
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
if ( update_category_button ()) {
2006-08-18 07:27:05 +00:00
if ( $categoryedit !== - 1 ) {
$USER -> categoryediting = $categoryedit ;
2003-08-07 16:01:31 +00:00
}
2006-04-11 20:39:30 +00:00
$adminediting = ! empty ( $USER -> categoryediting );
} else {
$adminediting = false ;
2003-08-07 16:01:31 +00:00
}
2007-04-18 04:54:47 +00:00
$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' );
2003-08-07 16:01:31 +00:00
/// Unless it's an editing admin, just print the regular listing of courses/categories
if ( ! $adminediting ) {
2007-04-18 04:54:47 +00:00
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
/// Print form for creating new categories
2008-06-01 18:17:38 +00:00
$countcategories = $DB -> count_records ( 'course_categories' );
2003-08-07 16:01:31 +00:00
2008-06-01 18:17:38 +00:00
if ( $countcategories > 1 || ( $countcategories == 1 && $DB -> count_records ( 'course' ) > 200 )) {
2007-02-05 07:27:07 +00:00
$strcourses = get_string ( 'courses' );
$strcategories = get_string ( 'categories' );
2007-08-23 15:08:14 +00:00
$navlinks = array ();
$navlinks [] = array ( 'name' => $strcategories , 'link' => '' , 'type' => 'misc' );
$navigation = build_navigation ( $navlinks );
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
print_header ( " $site->shortname : $strcategories " , $strcourses , $navigation , '' , '' , true , update_category_button ());
2004-02-20 12:56:17 +00:00
print_heading ( $strcategories );
2007-10-22 09:21:11 +00:00
echo skip_main_destination ();
2007-01-10 08:35:45 +00:00
print_box_start ( 'categorybox' );
2003-08-07 16:01:31 +00:00
print_whole_category_list ();
2007-01-10 08:35:45 +00:00
print_box_end ();
2003-08-11 09:45:50 +00:00
print_course_search ();
2003-08-07 16:01:31 +00:00
} else {
2007-02-05 07:27:07 +00:00
$strfulllistofcourses = get_string ( 'fulllistofcourses' );
2007-08-17 19:09:11 +00:00
print_header ( " $site->shortname : $strfulllistofcourses " , $strfulllistofcourses ,
build_navigation ( array ( array ( 'name' => $strfulllistofcourses , 'link' => '' , 'type' => 'misc' ))),
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
'' , '' , true , update_category_button ());
2007-10-22 09:21:11 +00:00
echo skip_main_destination ();
2007-02-14 04:22:24 +00:00
print_box_start ( 'courseboxes' );
2007-02-14 04:56:26 +00:00
print_courses ( 0 );
2007-02-14 04:22:24 +00:00
print_box_end ();
2003-08-07 16:01:31 +00:00
}
2003-08-22 12:15:35 +00:00
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
echo '<div class="buttons">' ;
if ( has_capability ( 'moodle/course:create' , $systemcontext )) {
/// Print link to create a new course
2007-03-30 15:36:52 +00:00
/// Get the 1st available category
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
$options = array ( 'category' => $CFG -> defaultrequestcategory );
2007-03-30 15:36:52 +00:00
print_single_button ( 'edit.php' , $options , get_string ( 'addnewcourse' ), 'get' );
2003-08-22 12:15:35 +00:00
}
2008-12-05 08:56:54 +00:00
print_course_request_buttons ( $systemcontext );
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
echo '</div>' ;
2003-08-07 16:01:31 +00:00
print_footer ();
exit ;
}
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
/// Everything else is editing on mode.
2003-08-07 16:01:31 +00:00
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
/// Delete a category.
2008-05-13 21:52:38 +00:00
if ( ! empty ( $delete ) and confirm_sesskey ()) {
2008-06-01 18:17:38 +00:00
if ( ! $deletecat = $DB -> get_record ( 'course_categories' , array ( 'id' => $delete ))) {
2008-09-25 02:09:49 +00:00
print_error ( 'invalidcategoryid' );
2008-05-13 21:52:38 +00:00
}
$context = get_context_instance ( CONTEXT_COURSECAT , $delete );
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
require_capability ( 'moodle/category:manage' , $context );
require_capability ( 'moodle/category:manage' , get_category_or_system_context ( $deletecat -> parent ));
2007-08-17 19:09:11 +00:00
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
$heading = get_string ( 'deletecategory' , '' , format_string ( $deletecat -> name ));
require_once ( 'delete_category_form.php' );
2008-05-13 21:52:38 +00:00
$mform = new delete_category_form ( null , $deletecat );
$mform -> set_data ( array ( 'delete' => $delete ));
2007-08-17 19:09:11 +00:00
2008-05-13 21:52:38 +00:00
if ( $mform -> is_cancelled ()) {
redirect ( 'index.php' );
2007-08-17 19:09:11 +00:00
2008-06-09 16:53:30 +00:00
} else if ( ! $data = $mform -> get_data ()) {
2008-05-13 21:52:38 +00:00
require_once ( $CFG -> libdir . '/questionlib.php' );
print_category_edit_header ();
print_heading ( $heading );
$mform -> display ();
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
admin_externalpage_print_footer ();
2008-05-13 21:52:38 +00:00
exit ();
2003-08-07 16:01:31 +00:00
}
2008-05-13 21:52:38 +00:00
print_category_edit_header ();
print_heading ( $heading );
if ( $data -> fulldelete ) {
category_delete_full ( $deletecat , true );
} else {
category_delete_move ( $deletecat , $data -> newparent , true );
}
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
// If we deleted $CFG->defaultrequestcategory, make it point somewhere else.
if ( $delete == $CFG -> defaultrequestcategory ) {
2008-12-09 23:55:47 +00:00
set_config ( 'defaultrequestcategory' , $DB -> get_field ( 'course_categories' , 'MIN(id)' , array ( 'parent' => 0 )));
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
}
2008-05-13 21:52:38 +00:00
print_continue ( 'index.php' );
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
admin_externalpage_print_footer ();
2008-05-13 21:52:38 +00:00
die ;
2002-09-09 11:48:11 +00:00
}
2002-09-09 12:37:34 +00:00
2008-05-13 21:52:38 +00:00
/// Print headings
print_category_edit_header ();
print_heading ( $strcategories );
2003-08-07 16:01:31 +00:00
/// Create a default category if necessary
if ( ! $categories = get_categories ()) { /// No category yet!
// Try and make one
2008-06-01 18:17:38 +00:00
$tempcat = new object ();
2007-02-05 07:27:07 +00:00
$tempcat -> name = get_string ( 'miscellaneous' );
2008-06-01 18:17:38 +00:00
if ( ! $tempcat -> id = $DB -> insert_record ( 'course_categories' , $tempcat )) {
2008-05-07 06:02:51 +00:00
print_error ( 'cannotsetupcategory' );
2003-08-07 16:01:31 +00:00
}
2007-09-19 07:50:05 +00:00
$tempcat -> context = get_context_instance ( CONTEXT_COURSECAT , $tempcat -> id );
mark_context_dirty ( '/' . SYSCONTEXTID );
2003-08-07 16:01:31 +00:00
}
/// Move a category to a new parent if required
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
if ( ! empty ( $move ) and ( $moveto >= 0 ) and confirm_sesskey ()) {
if ( $cattomove = $DB -> get_record ( 'course_categories' , array ( 'id' => $move ))) {
require_capability ( 'moodle/category:manage' , get_category_or_system_context ( $cattomove -> parent ));
if ( $cattomove -> parent != $moveto ) {
$newparent = $DB -> get_record ( 'course_categories' , array ( 'id' => $moveto ));
require_capability ( 'moodle/category:manage' , get_category_or_system_context ( $moveto ));
if ( ! move_category ( $cattomove , $newparent )) {
print_error ( 'cannotupdatecategory' , '' , '' , format_string ( $cattomove -> name ));
2007-08-17 19:09:11 +00:00
}
2003-08-07 16:01:31 +00:00
}
}
}
2007-08-17 19:09:11 +00:00
/// Hide or show a category
2005-06-14 09:21:09 +00:00
if (( ! empty ( $hide ) or ! empty ( $show )) and confirm_sesskey ()) {
if ( ! empty ( $hide )) {
2008-06-01 18:17:38 +00:00
$tempcat = $DB -> get_record ( 'course_categories' , array ( 'id' => $hide ));
2003-08-07 16:01:31 +00:00
$visible = 0 ;
} else {
2008-06-01 18:17:38 +00:00
$tempcat = $DB -> get_record ( 'course_categories' , array ( 'id' => $show ));
2003-08-07 16:01:31 +00:00
$visible = 1 ;
}
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
require_capability ( 'moodle/category:manage' , get_category_or_system_context ( $tempcat -> parent ));
2003-08-07 16:01:31 +00:00
if ( $tempcat ) {
2008-06-01 18:17:38 +00:00
if ( ! $DB -> set_field ( 'course_categories' , 'visible' , $visible , array ( 'id' => $tempcat -> id ))) {
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
print_error ( 'cannotupdatecategory' , '' , '' , format_string ( $tempcat -> name ));
2003-08-07 16:01:31 +00:00
}
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
if ( ! $DB -> set_field ( 'course' , 'visible' , $visible , array ( 'category' => $tempcat -> id ))) {
print_error ( 'cannotshowhidecoursesincategory' , '' , '' , format_string ( $tempcat -> name ));
2003-08-07 16:01:31 +00:00
}
}
}
/// Move a category up or down
2005-06-14 09:21:09 +00:00
if (( ! empty ( $moveup ) or ! empty ( $movedown )) and confirm_sesskey ()) {
2008-06-16 14:25:53 +00:00
fix_course_sortorder ();
2003-08-07 16:01:31 +00:00
$swapcategory = NULL ;
2005-06-14 09:21:09 +00:00
if ( ! empty ( $moveup )) {
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
require_capability ( 'moodle/category:manage' , get_context_instance ( CONTEXT_COURSECAT , $moveup ));
2008-06-01 18:17:38 +00:00
if ( $movecategory = $DB -> get_record ( 'course_categories' , array ( 'id' => $moveup ))) {
2008-06-16 14:25:53 +00:00
if ( $swapcategory = $DB -> get_records_select ( 'course_categories' , " sortorder<? AND parent=? " , array ( $movecategory -> sortorder , $movecategory -> parent ), 'sortorder ASC' , '*' , 0 , 1 )) {
$swapcategory = reset ( $swapcategory );
2003-08-07 16:01:31 +00:00
}
}
2008-06-16 14:25:53 +00:00
} else {
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
require_capability ( 'moodle/category:manage' , get_context_instance ( CONTEXT_COURSECAT , $movedown ));
2008-06-01 18:17:38 +00:00
if ( $movecategory = $DB -> get_record ( 'course_categories' , array ( 'id' => $movedown ))) {
2008-06-16 14:25:53 +00:00
if ( $swapcategory = $DB -> get_records_select ( 'course_categories' , " sortorder>? AND parent=? " , array ( $movecategory -> sortorder , $movecategory -> parent ), 'sortorder ASC' , '*' , 0 , 1 )) {
$swapcategory = reset ( $swapcategory );
2003-08-07 16:01:31 +00:00
}
}
}
2008-06-16 14:25:53 +00:00
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 ));
2003-08-07 16:01:31 +00:00
}
2008-06-16 14:25:53 +00:00
// finally reorder courses
fix_course_sortorder ();
}
2007-08-17 19:09:11 +00:00
2003-08-07 16:01:31 +00:00
/// Print out the categories with all the knobs
2007-02-05 07:27:07 +00:00
$strcategories = get_string ( 'categories' );
$strcourses = get_string ( 'courses' );
$strmovecategoryto = get_string ( 'movecategoryto' );
$stredit = get_string ( 'edit' );
2003-08-07 16:01:31 +00:00
$displaylist = array ();
$parentlist = array ();
2007-02-05 07:27:07 +00:00
$displaylist [ 0 ] = get_string ( 'top' );
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
make_categories_list ( $displaylist , $parentlist );
2003-08-07 16:01:31 +00:00
2007-04-18 04:54:47 +00:00
echo '<table class="generalbox editcourse boxaligncenter"><tr class="header">' ;
2007-02-05 07:27:07 +00:00
echo '<th class="header" scope="col">' . $strcategories . '</th>' ;
echo '<th class="header" scope="col">' . $strcourses . '</th>' ;
echo '<th class="header" scope="col">' . $stredit . '</th>' ;
echo '<th class="header" scope="col">' . $strmovecategoryto . '</th>' ;
echo '</tr>' ;
2003-08-07 16:01:31 +00:00
print_category_edit ( NULL , $displaylist , $parentlist );
2007-02-05 07:27:07 +00:00
echo '</table>' ;
2003-08-07 16:01:31 +00:00
2007-04-02 13:46:01 +00:00
echo '<div class="buttons">' ;
2008-05-13 21:52:38 +00:00
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
if ( has_capability ( 'moodle/course:create' , $systemcontext )) {
// print create course link to first category
$options = array ();
$options = array ( 'category' => $CFG -> defaultrequestcategory );
print_single_button ( 'edit.php' , $options , get_string ( 'addnewcourse' ), 'get' );
2006-08-08 05:13:06 +00:00
}
2007-08-17 19:09:11 +00:00
2007-10-09 12:53:24 +00:00
// Print button for creating new categories
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
if ( has_capability ( 'moodle/category:manage' , $systemcontext )) {
$options = array ();
$options [ 'parent' ] = 0 ;
2007-10-09 12:53:24 +00:00
print_single_button ( 'editcategory.php' , $options , get_string ( 'addnewcategory' ), 'get' );
}
2008-12-05 08:56:54 +00:00
print_course_request_buttons ( $systemcontext );
2007-04-02 13:46:01 +00:00
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
admin_externalpage_print_footer ();
2003-08-07 16:01:31 +00:00
function print_category_edit ( $category , $displaylist , $parentslist , $depth =- 1 , $up = false , $down = false ) {
/// Recursive function to print all the categories ready for editing
2005-01-25 14:03:43 +00:00
global $CFG , $USER ;
2003-08-07 16:01:31 +00:00
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
static $str = NULL ;
2007-08-17 19:09:11 +00:00
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
if ( is_null ( $str )) {
$str = new stdClass ;
2007-10-09 12:53:24 +00:00
$str -> edit = get_string ( 'edit' );
2007-02-05 07:27:07 +00:00
$str -> delete = get_string ( 'delete' );
$str -> moveup = get_string ( 'moveup' );
$str -> movedown = get_string ( 'movedown' );
$str -> edit = get_string ( 'editthiscategory' );
$str -> hide = get_string ( 'hide' );
$str -> show = get_string ( 'show' );
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
$str -> spacer = '<img src="' . $CFG -> wwwroot . '/pix/spacer.gif" class="iconsmall" alt="" /> ' ;
2003-08-07 16:01:31 +00:00
}
2007-08-17 19:09:11 +00:00
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
if ( ! empty ( $category )) {
2007-02-05 07:27:07 +00:00
2007-09-19 07:27:31 +00:00
if ( ! isset ( $category -> context )) {
$category -> context = get_context_instance ( CONTEXT_COURSECAT , $category -> id );
}
2007-08-17 19:09:11 +00:00
2007-02-05 07:27:07 +00:00
echo '<tr><td align="left" class="name">' ;
2003-08-07 16:01:31 +00:00
for ( $i = 0 ; $i < $depth ; $i ++ ) {
2007-02-05 07:27:07 +00:00
echo ' ' ;
2003-08-07 16:01:31 +00:00
}
2007-02-05 07:27:07 +00:00
$linkcss = $category -> visible ? '' : ' class="dimmed" ' ;
echo '<a ' . $linkcss . ' title="' . $str -> edit . '" ' .
' href="category.php?id=' . $category -> id . '&categoryedit=on&sesskey=' . sesskey () . '">' .
2007-02-28 06:25:22 +00:00
format_string ( $category -> name ) . '</a>' ;
2007-02-05 07:27:07 +00:00
echo '</td>' ;
2003-08-07 16:01:31 +00:00
2007-02-05 07:27:07 +00:00
echo '<td class="count">' . $category -> coursecount . '</td>' ;
2003-08-07 16:01:31 +00:00
2007-02-05 07:27:07 +00:00
echo '<td class="icons">' ; /// Print little icons
2003-08-07 16:01:31 +00:00
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
if ( has_capability ( 'moodle/category:manage' , $category -> context )) {
echo '<a title="' . $str -> edit . '" href="editcategory.php?id=' . $category -> id . '"><img' .
2007-10-09 12:53:24 +00:00
' src="' . $CFG -> pixpath . '/t/edit.gif" class="iconsmall" alt="' . $str -> edit . '" /></a> ' ;
2007-02-05 07:27:07 +00:00
echo '<a title="' . $str -> delete . '" href="index.php?delete=' . $category -> id . '&sesskey=' . sesskey () . '"><img' .
' src="' . $CFG -> pixpath . '/t/delete.gif" class="iconsmall" alt="' . $str -> delete . '" /></a> ' ;
2007-08-17 19:09:11 +00:00
2006-09-20 20:31:09 +00:00
if ( ! empty ( $category -> visible )) {
2007-02-05 07:27:07 +00:00
echo '<a title="' . $str -> hide . '" href="index.php?hide=' . $category -> id . '&sesskey=' . sesskey () . '"><img' .
' src="' . $CFG -> pixpath . '/t/hide.gif" class="iconsmall" alt="' . $str -> hide . '" /></a> ' ;
2006-09-20 20:31:09 +00:00
} else {
2007-02-05 07:27:07 +00:00
echo '<a title="' . $str -> show . '" href="index.php?show=' . $category -> id . '&sesskey=' . sesskey () . '"><img' .
' src="' . $CFG -> pixpath . '/t/show.gif" class="iconsmall" alt="' . $str -> show . '" /></a> ' ;
2006-09-20 20:31:09 +00:00
}
2003-08-07 16:01:31 +00:00
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
if ( $up ) {
echo '<a title="' . $str -> moveup . '" href="index.php?moveup=' . $category -> id . '&sesskey=' . sesskey () . '"><img' .
' src="' . $CFG -> pixpath . '/t/up.gif" class="iconsmall" alt="' . $str -> moveup . '" /></a> ' ;
} else {
echo $str -> spacer ;
}
if ( $down ) {
echo '<a title="' . $str -> movedown . '" href="index.php?movedown=' . $category -> id . '&sesskey=' . sesskey () . '"><img' .
' src="' . $CFG -> pixpath . '/t/down.gif" class="iconsmall" alt="' . $str -> movedown . '" /></a> ' ;
} else {
echo $str -> spacer ;
}
2003-08-07 16:01:31 +00:00
}
2007-02-05 07:27:07 +00:00
echo '</td>' ;
2003-08-07 16:01:31 +00:00
2007-02-05 07:27:07 +00:00
echo '<td align="left">' ;
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
if ( has_capability ( 'moodle/category:manage' , $category -> context )) {
$tempdisplaylist = $displaylist ;
unset ( $tempdisplaylist [ $category -> id ]);
foreach ( $parentslist as $key => $parents ) {
if ( in_array ( $category -> id , $parents )) {
unset ( $tempdisplaylist [ $key ]);
}
2003-08-07 16:01:31 +00:00
}
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
popup_form ( " index.php?move= $category->id &sesskey= $USER->sesskey &moveto= " , $tempdisplaylist , " moveform $category->id " , $category -> parent , '' , '' , '' , false );
2003-08-07 16:01:31 +00:00
}
2007-02-05 07:27:07 +00:00
echo '</td>' ;
echo '</tr>' ;
2003-07-30 13:02:45 +00:00
} else {
2007-02-05 07:27:07 +00:00
$category -> id = '0' ;
2003-07-30 13:02:45 +00:00
}
2001-11-22 06:23:56 +00:00
2003-08-07 16:01:31 +00:00
if ( $categories = get_categories ( $category -> id )) { // Print all the children recursively
$countcats = count ( $categories );
$count = 0 ;
$first = true ;
$last = false ;
foreach ( $categories as $cat ) {
$count ++ ;
if ( $count == $countcats ) {
$last = true ;
}
$up = $first ? false : true ;
$down = $last ? false : true ;
$first = false ;
2001-11-22 06:23:56 +00:00
2007-08-17 19:09:11 +00:00
print_category_edit ( $cat , $displaylist , $parentslist , $depth + 1 , $up , $down );
2003-08-07 16:01:31 +00:00
}
}
}
2008-05-13 21:52:38 +00:00
function print_category_edit_header () {
global $CFG ;
2008-05-21 12:47:35 +00:00
global $SITE ;
2008-05-13 21:52:38 +00:00
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
require_once ( $CFG -> libdir . '/adminlib.php' );
2008-12-11 09:21:41 +00:00
admin_externalpage_setup ( 'coursemgmt' , update_category_button ());
course categories: Fix many bugs with category editing and permissions. Clean up code.
Bugs: MDL-17479, MDL-16426, MDL-16063, MDL-16013, MDL-15658, MDL-15556, MDL-15161, MDL-14925, MDL-13742, MDL-11557.
* Simplify category editing permissions to just moodle/category:manage and moodle/category:seehiddencategories.
* Enforce those correctly. (Note MDL 17502 is still outstanding.)
* Don't screw up category sort order when you just edit name or description.
* Niceties like where redirects go when you cancel or submit forms.
* Make sure a global course creator can see the site admin block.
* Don't allow a category to be made the child of one of its children!
* General code cleanup to bring key files more in line with best pracitice.
Apologies for the fact it is one big patch, rather than a series of smaller patches. However, categoryedit.php, category.php and index.php where in pretty bad shape and needed significant cleaning up. categoryedit.php, in particular, was almost completely rewritten.
Merged from MOODLE_19_STABLE.
2008-12-04 08:53:10 +00:00
admin_externalpage_print_header ();
2008-05-13 21:52:38 +00:00
}
2003-08-07 16:01:31 +00:00
?>