Merge branch 'wip-MDL-24355-MOODLE_19_STABLE' of git://github.com/andyjdavis/moodle...
[moodle.git] / course / editcategory_form.php
blob24f40f28798d0344e5961573466af0ff53453748
1 <?php
2 require_once ($CFG->dirroot.'/course/moodleform_mod.php');
3 class editcategory_form extends moodleform {
5 // form definition
6 function definition() {
7 global $CFG;
8 $mform =& $this->_form;
9 $category = $this->_customdata;
11 // get list of categories to use as parents, with site as the first one
12 $options = array();
13 if (has_capability('moodle/category:manage', get_system_context()) || $category->parent == 0) {
14 $options[0] = get_string('top');
16 $parents = array();
17 if ($category->id) {
18 // Editing an existing category.
19 make_categories_list($options, $parents, 'moodle/category:manage', $category->id);
20 if (empty($options[$category->parent])) {
21 $options[$category->parent] = get_field('course_categories', 'name', 'id', $category->parent);
23 $strsubmit = get_string('savechanges');
24 } else {
25 // Making a new category
26 make_categories_list($options, $parents, 'moodle/category:manage');
27 $strsubmit = get_string('createcategory');
30 $mform->addElement('select', 'parent', get_string('parentcategory'), $options);
31 $mform->addElement('text', 'name', get_string('categoryname'), array('size'=>'30'));
32 $mform->addRule('name', get_string('required'), 'required', null);
33 $mform->addElement('htmleditor', 'description', get_string('description'));
34 $mform->setType('description', PARAM_RAW);
35 if (!empty($CFG->allowcategorythemes)) {
36 $themes=array();
37 $themes[''] = get_string('forceno');
38 $themes += get_list_of_themes();
39 $mform->addElement('select', 'theme', get_string('forcetheme'), $themes);
41 $mform->setHelpButton('description', array('writing', 'richtext'), false, 'editorhelpbutton');
43 $mform->addElement('hidden', 'id', 0);
44 $mform->setType('id', PARAM_INT);
45 $mform->setDefault('id', $category->id);
47 $this->add_action_buttons(true, $strsubmit);