Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/course/editcategory_form.php
Go to the documentation of this file.
00001 <?php
00002 if (!defined('MOODLE_INTERNAL')) {
00003     die('Direct access to this script is forbidden.');    
00004 }
00005 
00006 require_once ($CFG->dirroot.'/course/moodleform_mod.php');
00007 class editcategory_form extends moodleform {
00008 
00009     // form definition
00010     function definition() {
00011         global $CFG, $DB;
00012         $mform =& $this->_form;
00013         $category = $this->_customdata['category'];
00014         $editoroptions = $this->_customdata['editoroptions'];
00015 
00016         // get list of categories to use as parents, with site as the first one
00017         $options = array();
00018         if (has_capability('moodle/category:manage', get_system_context()) || $category->parent == 0) {
00019             $options[0] = get_string('top');
00020         }
00021         $parents = array();
00022         if ($category->id) {
00023             // Editing an existing category.
00024             make_categories_list($options, $parents, 'moodle/category:manage', $category->id);
00025             if (empty($options[$category->parent])) {
00026                 $options[$category->parent] = $DB->get_field('course_categories', 'name', array('id'=>$category->parent));
00027             }
00028             $strsubmit = get_string('savechanges');
00029         } else {
00030             // Making a new category
00031             make_categories_list($options, $parents, 'moodle/category:manage');
00032             $strsubmit = get_string('createcategory');
00033         }
00034 
00035         $mform->addElement('select', 'parent', get_string('parentcategory'), $options);
00036         $mform->addElement('text', 'name', get_string('categoryname'), array('size'=>'30'));
00037         $mform->addRule('name', get_string('required'), 'required', null);
00038         $mform->addElement('text', 'idnumber', get_string('idnumbercoursecategory'),'maxlength="100"  size="10"');
00039         $mform->addHelpButton('idnumber', 'idnumbercoursecategory');
00040         $mform->addElement('editor', 'description_editor', get_string('description'), null, $editoroptions);
00041         $mform->setType('description_editor', PARAM_RAW);
00042         if (!empty($CFG->allowcategorythemes)) {
00043             $themes = array(''=>get_string('forceno'));
00044             $allthemes = get_list_of_themes();
00045             foreach ($allthemes as $key=>$theme) {
00046                 if (empty($theme->hidefromselector)) {
00047                     $themes[$key] = get_string('pluginname', 'theme_'.$theme->name);
00048                 }
00049             }
00050             $mform->addElement('select', 'theme', get_string('forcetheme'), $themes);
00051         }
00052 
00053         $mform->addElement('hidden', 'id', 0);
00054         $mform->setType('id', PARAM_INT);
00055         $mform->setDefault('id', $category->id);
00056 
00057         $this->add_action_buttons(true, $strsubmit);
00058     }
00059 
00060     function validation($data, $files) {
00061         global $DB;
00062         $errors = parent::validation($data, $files);
00063         if (!empty($data['idnumber'])) {
00064             if ($existing = $DB->get_record('course_categories', array('idnumber' => $data['idnumber']))) {
00065                 if (!$data['id'] || $existing->id != $data['id']) {
00066                     $errors['idnumber']= get_string('idnumbertaken');
00067                 }
00068             }
00069         }
00070 
00071         return $errors;
00072     }
00073 }
00074 
 All Data Structures Namespaces Files Functions Variables Enumerations