2 if (!defined('MOODLE_INTERNAL')) {
3 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
6 require_once ($CFG->dirroot
.'/course/moodleform_mod.php');
7 class editcategory_form
extends moodleform
{
10 function definition() {
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
18 if (has_capability('moodle/category:manage', get_system_context()) ||
$category->parent
== 0) {
19 $options[0] = get_string('top');
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
));
28 $strsubmit = get_string('savechanges');
30 // Making a new category
31 make_categories_list($options, $parents, 'moodle/category:manage');
32 $strsubmit = get_string('createcategory');
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] = $theme->name
;
48 $mform->addElement('select', 'theme', get_string('forcetheme'), $themes);
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);