Updated the 19 build version to 20101023
[moodle.git] / user / profile / index_category_form.php
blob314ea9173856bce53291f6befc273603f49a997e
1 <?php //$Id$
3 require_once($CFG->dirroot.'/lib/formslib.php');
5 class category_form extends moodleform {
7 // Define the form
8 function definition () {
9 global $USER, $CFG;
11 $mform =& $this->_form;
13 $strrequired = get_string('required');
15 /// Add some extra hidden fields
16 $mform->addElement('hidden', 'id');
17 $mform->setType('id', PARAM_INT);
18 $mform->addElement('hidden', 'action', 'editcategory');
19 $mform->setType('action', PARAM_ACTION);
21 $mform->addElement('text', 'name', get_string('profilecategoryname', 'admin'), 'maxlength="255" size="30"');
22 $mform->setType('name', PARAM_MULTILANG);
23 $mform->addRule('name', $strrequired, 'required', null, 'client');
25 $this->add_action_buttons(true);
27 } /// End of function
29 /// perform some moodle validation
30 function validation($data, $files) {
31 global $CFG;
32 $errors = parent::validation($data, $files);
34 $data = (object)$data;
36 $duplicate = record_exists('user_info_category', 'name', $data->name);
38 /// Check the name is unique
39 if (!empty($data->id)) { // we are editing an existing record
40 $olddata = get_record('user_info_category', 'id', $data->id);
41 // name has changed, new name in use, new name in use by another record
42 $dupfound = (($olddata->name !== $data->name) && $duplicate && ($data->id != $duplicate->id));
44 else { // new profile category
45 $dupfound = $duplicate;
48 if ($dupfound ) {
49 $errors['name'] = get_string('profilecategorynamenotunique', 'admin');
52 return $errors;