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.
This commit is contained in:
tjhunt
2008-12-04 08:53:10 +00:00
parent 4faace3781
commit 8ed5dd63ee
18 changed files with 501 additions and 721 deletions
+19 -9
View File
@@ -6,15 +6,24 @@ class editcategory_form extends moodleform {
function definition() {
global $CFG;
$mform =& $this->_form;
$category = $this->_customdata;
// get list of categories to use as parents, with site as the first one
$options = array(get_string('top'));
$parents = array();
make_categories_list($options, $parents);
if ($category->id) {
// Editing an existing category.
make_categories_list($options, $parents, 'moodle/category:manage', $category->id);
$strsubmit = get_string('savechanges');
} else {
// Making a new category
make_categories_list($options, $parents, 'moodle/category:manage');
$strsubmit = get_string('createcategory');
}
$mform->addElement('select', 'parent', get_string('parentcategory'), $options);
$mform->addElement('text', 'name', get_string('categoryname'), array('size'=>'30'));
$mform->addRule('name', get_string('required'), 'required', null);
$mform->addElement('text', 'name', get_string('categoryname'), array('size'=>'30'));
$mform->addRule('name', get_string('required'), 'required', null);
$mform->addElement('htmleditor', 'description', get_string('description'));
$mform->setType('description', PARAM_RAW);
if (!empty($CFG->allowcategorythemes)) {
@@ -24,11 +33,12 @@ class editcategory_form extends moodleform {
$mform->addElement('select', 'theme', get_string('forcetheme'), $themes);
}
$mform->setHelpButton('description', array('writing', 'richtext2'), false, 'editorhelpbutton');
$mform->addElement('hidden', 'id', null);
$mform->addElement('hidden', 'categoryadd', 0);
$mform->addElement('hidden', 'id', 0);
$mform->setType('id', PARAM_INT);
$this->add_action_buttons(true, get_string('savechanges'));
$mform->setDefault('id', $category->id);
$this->add_action_buttons(true, $strsubmit);
}
}
?>