2009-11-04 08:11:02 +00:00
|
|
|
<?php
|
2010-05-13 02:02:05 +00:00
|
|
|
if (!defined('MOODLE_INTERNAL')) {
|
|
|
|
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
|
|
|
|
}
|
|
|
|
|
2007-10-09 17:22:10 +00:00
|
|
|
require_once ($CFG->dirroot.'/course/moodleform_mod.php');
|
2013-02-21 10:37:52 +11:00
|
|
|
require_once ($CFG->libdir.'/coursecatlib.php');
|
2007-10-09 17:22:10 +00:00
|
|
|
class editcategory_form extends moodleform {
|
|
|
|
|
|
|
|
// form definition
|
|
|
|
function definition() {
|
2010-12-20 17:11:42 +08:00
|
|
|
global $CFG, $DB;
|
2007-10-09 17:22:10 +00:00
|
|
|
$mform =& $this->_form;
|
2009-11-04 06:14:06 +00:00
|
|
|
$category = $this->_customdata['category'];
|
|
|
|
$editoroptions = $this->_customdata['editoroptions'];
|
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
|
|
|
|
2007-10-09 17:22:10 +00:00
|
|
|
// get list of categories to use as parents, with site as the first one
|
2010-12-20 11:03:31 +08:00
|
|
|
$options = array();
|
2013-07-03 14:39:10 +08:00
|
|
|
if (has_capability('moodle/category:manage', context_system::instance()) || $category->parent == 0) {
|
2010-12-20 11:03:31 +08:00
|
|
|
$options[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
|
|
|
if ($category->id) {
|
|
|
|
// Editing an existing category.
|
2013-02-21 10:37:52 +11:00
|
|
|
$options += coursecat::make_categories_list('moodle/category:manage', $category->id);
|
2010-12-20 11:03:31 +08:00
|
|
|
if (empty($options[$category->parent])) {
|
2010-12-20 17:11:42 +08:00
|
|
|
$options[$category->parent] = $DB->get_field('course_categories', 'name', array('id'=>$category->parent));
|
2010-12-20 11:03:31 +08: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
|
|
|
$strsubmit = get_string('savechanges');
|
|
|
|
} else {
|
|
|
|
// Making a new category
|
2013-02-21 10:37:52 +11:00
|
|
|
$options += coursecat::make_categories_list('moodle/category:manage');
|
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
|
|
|
$strsubmit = get_string('createcategory');
|
|
|
|
}
|
|
|
|
|
2007-10-09 17:22:10 +00:00
|
|
|
$mform->addElement('select', 'parent', get_string('parentcategory'), $options);
|
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
|
|
|
$mform->addElement('text', 'name', get_string('categoryname'), array('size'=>'30'));
|
|
|
|
$mform->addRule('name', get_string('required'), 'required', null);
|
2013-04-04 17:22:28 +08:00
|
|
|
$mform->setType('name', PARAM_TEXT);
|
2011-10-07 09:35:17 +01:00
|
|
|
$mform->addElement('text', 'idnumber', get_string('idnumbercoursecategory'),'maxlength="100" size="10"');
|
|
|
|
$mform->addHelpButton('idnumber', 'idnumbercoursecategory');
|
2013-04-04 17:22:28 +08:00
|
|
|
$mform->setType('idnumber', PARAM_RAW);
|
2009-11-04 06:14:06 +00:00
|
|
|
$mform->addElement('editor', 'description_editor', get_string('description'), null, $editoroptions);
|
|
|
|
$mform->setType('description_editor', PARAM_RAW);
|
2007-10-10 04:05:46 +00:00
|
|
|
if (!empty($CFG->allowcategorythemes)) {
|
2010-03-18 06:02:41 +00:00
|
|
|
$themes = array(''=>get_string('forceno'));
|
|
|
|
$allthemes = get_list_of_themes();
|
|
|
|
foreach ($allthemes as $key=>$theme) {
|
2011-08-10 12:56:04 +08:00
|
|
|
if (empty($theme->hidefromselector)) {
|
|
|
|
$themes[$key] = get_string('pluginname', 'theme_'.$theme->name);
|
|
|
|
}
|
2010-03-18 06:02:41 +00:00
|
|
|
}
|
2007-10-09 17:22:10 +00:00
|
|
|
$mform->addElement('select', 'theme', get_string('forcetheme'), $themes);
|
|
|
|
}
|
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
|
|
|
|
|
|
|
$mform->addElement('hidden', 'id', 0);
|
2007-10-09 17:22:10 +00:00
|
|
|
$mform->setType('id', PARAM_INT);
|
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
|
|
|
$mform->setDefault('id', $category->id);
|
|
|
|
|
|
|
|
$this->add_action_buttons(true, $strsubmit);
|
2007-10-09 17:22:10 +00:00
|
|
|
}
|
2011-10-07 09:35:17 +01:00
|
|
|
|
|
|
|
function validation($data, $files) {
|
|
|
|
global $DB;
|
|
|
|
$errors = parent::validation($data, $files);
|
|
|
|
if (!empty($data['idnumber'])) {
|
|
|
|
if ($existing = $DB->get_record('course_categories', array('idnumber' => $data['idnumber']))) {
|
|
|
|
if (!$data['id'] || $existing->id != $data['id']) {
|
|
|
|
$errors['idnumber']= get_string('idnumbertaken');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $errors;
|
|
|
|
}
|
2009-11-04 08:11:02 +00:00
|
|
|
}
|
|
|
|
|