a708a0214965ac686dfa52854ece5610eb738506
[moodle.git] / course / editcategory_form.php
1 <?php
2 if (!defined('MOODLE_INTERNAL')) {
3     die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page
4 }
6 require_once ($CFG->dirroot.'/course/moodleform_mod.php');
7 class editcategory_form extends moodleform {
9     // form definition
10     function definition() {
11         global $CFG, $DB;
12         $mform =& $this->_form;
13         $category = $this->_customdata['category'];
14         $editoroptions = $this->_customdata['editoroptions'];
16         // get list of categories to use as parents, with site as the first one
17         $options = array();
18         if (has_capability('moodle/category:manage', get_system_context()) || $category->parent == 0) {
19             $options[0] = get_string('top');
20         }
21         $parents = array();
22         if ($category->id) {
23             // Editing an existing category.
24             make_categories_list($options, $parents, 'moodle/category:manage', $category->id);
25             if (empty($options[$category->parent])) {
26                 $options[$category->parent] = $DB->get_field('course_categories', 'name', array('id'=>$category->parent));
27             }
28             $strsubmit = get_string('savechanges');
29         } else {
30             // Making a new category
31             make_categories_list($options, $parents, 'moodle/category:manage');
32             $strsubmit = get_string('createcategory');
33         }
35         $mform->addElement('select', 'parent', get_string('parentcategory'), $options);
36         $mform->addElement('text', 'name', get_string('categoryname'), array('size'=>'30'));
37         $mform->addRule('name', get_string('required'), 'required', null);
38         $mform->addElement('editor', 'description_editor', get_string('description'), null, $editoroptions);
39         $mform->setType('description_editor', PARAM_RAW);
40         if (!empty($CFG->allowcategorythemes)) {
41             $themes = array(''=>get_string('forceno'));
42             $allthemes = get_list_of_themes();
43             foreach ($allthemes as $key=>$theme) {
44                 if (empty($theme->hidefromselector)) {
45                     $themes[$key] = get_string('pluginname', 'theme_'.$theme->name);
46                 }
47             }
48             $mform->addElement('select', 'theme', get_string('forcetheme'), $themes);
49         }
51         $mform->addElement('hidden', 'id', 0);
52         $mform->setType('id', PARAM_INT);
53         $mform->setDefault('id', $category->id);
55         $this->add_action_buttons(true, $strsubmit);
56     }
57 }