2009-09-25 05:24:13 +00:00
< ? php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* For most people , just lists the course categories
* Allows the admin to create , delete and rename course categories
*
* @ copyright 1999 Martin Dougiamas http :// dougiamas . com
* @ license http :// www . gnu . org / copyleft / gpl . html GNU GPL v3 or later
* @ package course
*/
require_once ( " ../config.php " );
require_once ( " lib.php " );
$categoryedit = optional_param ( 'categoryedit' , - 1 , PARAM_BOOL );
$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 );
2009-11-01 09:10:09 +00:00
$site = get_site ();
2003-08-07 16:01:31 +00:00
2009-09-25 05:24:13 +00:00
$systemcontext = get_context_instance ( CONTEXT_SYSTEM );
2004-01-14 08:27:40 +00:00
2010-01-16 15:39:56 +00:00
$PAGE -> set_url ( '/course/index.php' );
2009-09-25 05:24:13 +00:00
$PAGE -> set_context ( $systemcontext );
2009-05-07 08:55:10 +00:00
2009-09-25 05:24:13 +00:00
if ( can_edit_in_category ()) {
if ( $categoryedit !== - 1 ) {
$USER -> editing = $categoryedit ;
}
require_login ();
$adminediting = $PAGE -> user_is_editing ();
} else {
if ( $CFG -> forcelogin ) {
2009-07-20 08:57:18 +00:00
require_login ();
2003-08-07 16:01:31 +00:00
}
2009-09-25 05:24:13 +00:00
$adminediting = false ;
}
2003-08-07 16:01:31 +00:00
2009-09-25 05:24:13 +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' );
2007-04-18 04:54:47 +00:00
2003-08-07 16:01:31 +00:00
/// Unless it's an editing admin, just print the regular listing of courses/categories
2009-09-25 05:24:13 +00:00
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' );
$PAGE -> navbar -> add ( $strcategories );
$PAGE -> set_title ( " $site->shortname : $strcategories " );
$PAGE -> set_heading ( $strcourses );
$PAGE -> set_button ( update_category_button ());
echo $OUTPUT -> header ();
echo $OUTPUT -> heading ( $strcategories );
echo $OUTPUT -> skip_link_target ();
echo $OUTPUT -> box_start ( 'categorybox' );
print_whole_category_list ();
echo $OUTPUT -> box_end ();
print_course_search ();
} else {
$PAGE -> navbar -> add ( $strfulllistofcourses );
$PAGE -> set_title ( " $site->shortname : $strfulllistofcourses " );
$PAGE -> set_heading ( $strfulllistofcourses );
$PAGE -> set_button ( update_category_button ());
echo $OUTPUT -> header ();
echo $OUTPUT -> skip_link_target ();
echo $OUTPUT -> box_start ( 'courseboxes' );
print_courses ( 0 );
echo $OUTPUT -> box_end ();
}
2003-08-22 12:15:35 +00:00
2009-09-25 05:24:13 +00:00
echo $OUTPUT -> container_start ( 'buttons' );
if ( has_capability ( 'moodle/course:create' , $systemcontext )) {
/// Print link to create a new course
/// Get the 1st available category
$options = array ( 'category' => $CFG -> defaultrequestcategory );
2010-01-03 15:46:14 +00:00
echo $OUTPUT -> single_button ( new moodle_url ( 'edit.php' , $options ), get_string ( 'addnewcourse' ), 'get' );
2003-08-07 16:01:31 +00:00
}
2009-09-25 05:24:13 +00:00
print_course_request_buttons ( $systemcontext );
echo $OUTPUT -> container_end ();
echo $OUTPUT -> 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.
2009-09-25 05:24:13 +00:00
require_once ( $CFG -> libdir . '/adminlib.php' );
admin_externalpage_setup ( 'coursemgmt' );
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.
2009-09-25 05:24:13 +00:00
if ( ! empty ( $delete ) and confirm_sesskey ()) {
if ( ! $deletecat = $DB -> get_record ( 'course_categories' , array ( 'id' => $delete ))) {
print_error ( 'invalidcategoryid' );
}
$context = get_context_instance ( CONTEXT_COURSECAT , $delete );
require_capability ( 'moodle/category:manage' , $context );
require_capability ( 'moodle/category:manage' , get_category_or_system_context ( $deletecat -> parent ));
$heading = get_string ( 'deletecategory' , format_string ( $deletecat -> name ));
require_once ( 'delete_category_form.php' );
$mform = new delete_category_form ( null , $deletecat );
$mform -> set_data ( array ( 'delete' => $delete ));
if ( $mform -> is_cancelled ()) {
redirect ( 'index.php' );
2008-05-13 21:52:38 +00:00
2009-09-25 05:24:13 +00:00
} else if ( ! $data = $mform -> get_data ()) {
require_once ( $CFG -> libdir . '/questionlib.php' );
2009-07-20 03:28:50 +00:00
admin_externalpage_print_header ();
2009-08-06 08:15:43 +00:00
echo $OUTPUT -> heading ( $heading );
2009-09-25 05:24:13 +00:00
$mform -> display ();
echo $OUTPUT -> footer ();
exit ();
}
2008-05-13 21:52:38 +00:00
2009-09-25 05:24:13 +00:00
admin_externalpage_print_header ();
echo $OUTPUT -> heading ( $heading );
2009-08-10 04:53:59 +00:00
2009-09-25 05:24:13 +00:00
if ( $data -> fulldelete ) {
$deletedcourses = category_delete_full ( $deletecat , true );
2009-08-10 04:53:59 +00:00
2009-09-25 05:24:13 +00:00
foreach ( $deletedcourses as $course ) {
echo $OUTPUT -> notification ( get_string ( 'coursedeleted' , '' , $course -> shortname ), 'notifysuccess' );
2008-05-13 21:52:38 +00:00
}
2009-09-25 05:24:13 +00:00
echo $OUTPUT -> notification ( get_string ( 'coursecategorydeleted' , '' , format_string ( $deletecat -> name )), 'notifysuccess' );
2008-05-13 21:52:38 +00:00
2009-09-25 05:24:13 +00:00
} else {
category_delete_move ( $deletecat , $data -> newparent , true );
}
2008-05-13 21:52:38 +00:00
2009-09-25 05:24:13 +00:00
// If we deleted $CFG->defaultrequestcategory, make it point somewhere else.
if ( $delete == $CFG -> defaultrequestcategory ) {
set_config ( 'defaultrequestcategory' , $DB -> get_field ( 'course_categories' , 'MIN(id)' , array ( 'parent' => 0 )));
2002-09-09 11:48:11 +00:00
}
2002-09-09 12:37:34 +00:00
2009-09-25 05:24:13 +00:00
echo $OUTPUT -> continue_button ( 'index.php' );
echo $OUTPUT -> footer ();
die ;
}
2003-08-07 16:01:31 +00:00
/// Create a default category if necessary
2009-09-25 05:24:13 +00:00
if ( ! $categories = get_categories ()) { /// No category yet!
// Try and make one
$tempcat = new object ();
$tempcat -> name = get_string ( 'miscellaneous' );
$tempcat -> id = $DB -> insert_record ( 'course_categories' , $tempcat );
$tempcat -> context = get_context_instance ( CONTEXT_COURSECAT , $tempcat -> id );
mark_context_dirty ( '/' . SYSCONTEXTID );
fix_course_sortorder (); // Required to build course_categories.depth and .path.
}
2003-08-07 16:01:31 +00:00
/// Move a category to a new parent if required
2009-09-25 05:24:13 +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 ));
move_category ( $cattomove , $newparent );
2003-08-07 16:01:31 +00:00
}
}
2009-09-25 05:24:13 +00:00
}
2003-08-07 16:01:31 +00:00
2007-08-17 19:09:11 +00:00
/// Hide or show a category
2009-09-25 05:24:13 +00:00
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 ;
}
require_capability ( 'moodle/category:manage' , get_category_or_system_context ( $tempcat -> parent ));
if ( $tempcat ) {
$DB -> set_field ( 'course_categories' , 'visible' , $visible , array ( 'id' => $tempcat -> id ));
$DB -> set_field ( 'course' , 'visible' , $visible , array ( 'category' => $tempcat -> id ));
2003-08-07 16:01:31 +00:00
}
2009-09-25 05:24:13 +00:00
}
2003-08-07 16:01:31 +00:00
/// Move a category up or down
2009-09-25 05:24:13 +00:00
if (( ! empty ( $moveup ) or ! empty ( $movedown )) and confirm_sesskey ()) {
fix_course_sortorder ();
$swapcategory = NULL ;
if ( ! empty ( $moveup )) {
require_capability ( 'moodle/category:manage' , get_context_instance ( CONTEXT_COURSECAT , $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 );
2003-08-07 16:01:31 +00:00
}
}
2009-09-25 05:24:13 +00:00
} else {
require_capability ( 'moodle/category:manage' , get_context_instance ( CONTEXT_COURSECAT , $movedown ));
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 );
}
2003-08-07 16:01:31 +00:00
}
2009-09-25 05:24:13 +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 ));
2008-06-16 14:25:53 +00:00
}
2007-08-17 19:09:11 +00:00
2009-09-25 05:24:13 +00:00
// finally reorder courses
fix_course_sortorder ();
}
2009-07-04 14:23:49 +00:00
/// Print headings
2009-09-25 05:24:13 +00:00
admin_externalpage_print_header ();
echo $OUTPUT -> heading ( $strcategories );
2009-07-04 14:23:49 +00:00
2003-08-07 16:01:31 +00:00
/// Print out the categories with all the knobs
2009-09-25 05:24:13 +00:00
$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 '<table class="generalbox editcourse boxaligncenter"><tr class="header">' ;
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>' ;
print_category_edit ( NULL , $displaylist , $parentlist );
echo '</table>' ;
echo '<div class="buttons">' ;
if ( has_capability ( 'moodle/course:create' , $systemcontext )) {
// print create course link to first category
$options = array ( 'category' => $CFG -> defaultrequestcategory );
2010-01-03 15:46:14 +00:00
echo $OUTPUT -> single_button ( new moodle_url ( 'edit.php' , $options ), get_string ( 'addnewcourse' ), 'get' );
2009-09-25 05:24:13 +00:00
}
2007-08-17 19:09:11 +00:00
2009-09-25 05:24:13 +00:00
// Print button for creating new categories
if ( has_capability ( 'moodle/category:manage' , $systemcontext )) {
2010-01-03 15:46:14 +00:00
$options = array ( 'parent' => 0 );
echo $OUTPUT -> single_button ( new moodle_url ( 'editcategory.php' , $options ), get_string ( 'addnewcategory' ), 'get' );
2009-09-25 05:24:13 +00:00
}
2007-10-09 12:53:24 +00:00
2009-09-25 05:24:13 +00:00
print_course_request_buttons ( $systemcontext );
echo '</div>' ;
2007-04-02 13:46:01 +00:00
2009-09-25 05:24:13 +00:00
echo $OUTPUT -> 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
2009-07-02 10:53:31 +00:00
global $CFG , $USER , $OUTPUT ;
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' .
2009-12-16 21:50:45 +00:00
' src="' . $OUTPUT -> pix_url ( 't/edit' ) . '" class="iconsmall" alt="' . $str -> edit . '" /></a> ' ;
2007-10-09 12:53:24 +00:00
2007-02-05 07:27:07 +00:00
echo '<a title="' . $str -> delete . '" href="index.php?delete=' . $category -> id . '&sesskey=' . sesskey () . '"><img' .
2009-12-16 21:50:45 +00:00
' src="' . $OUTPUT -> pix_url ( 't/delete' ) . '" 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' .
2009-12-16 21:50:45 +00:00
' src="' . $OUTPUT -> pix_url ( 't/hide' ) . '" 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' .
2009-12-16 21:50:45 +00:00
' src="' . $OUTPUT -> pix_url ( 't/show' ) . '" 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' .
2009-12-16 21:50:45 +00:00
' src="' . $OUTPUT -> pix_url ( 't/up' ) . '" class="iconsmall" alt="' . $str -> moveup . '" /></a> ' ;
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
} else {
echo $str -> spacer ;
}
if ( $down ) {
echo '<a title="' . $str -> movedown . '" href="index.php?movedown=' . $category -> id . '&sesskey=' . sesskey () . '"><img' .
2009-12-16 21:50:45 +00:00
' src="' . $OUTPUT -> pix_url ( 't/down' ) . '" class="iconsmall" alt="' . $str -> movedown . '" /></a> ' ;
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
} 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
}
2010-02-10 09:37:50 +00:00
$popupurl = new moodle_url ( " index.php?move= $category->id &sesskey= " . sesskey ());
$select = new single_select ( $popupurl , 'moveto' , $tempdisplaylist , $category -> parent , null , " moveform $category->id " );
echo $OUTPUT -> render ( $select );
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
}
}
2009-09-25 05:24:13 +00:00
}