Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/user/profile/index_category_form.php
Go to the documentation of this file.
00001 <?php
00002 
00003 if (!defined('MOODLE_INTERNAL')) {
00004     die('Direct access to this script is forbidden.');    
00005 }
00006 
00007 require_once($CFG->dirroot.'/lib/formslib.php');
00008 
00009 class category_form extends moodleform {
00010 
00011     // Define the form
00012     function definition () {
00013         global $USER, $CFG;
00014 
00015         $mform =& $this->_form;
00016 
00017         $strrequired = get_string('required');
00018 
00020         $mform->addElement('hidden', 'id');
00021         $mform->setType('id', PARAM_INT);
00022         $mform->addElement('hidden', 'action', 'editcategory');
00023         $mform->setType('action', PARAM_ACTION);
00024 
00025         $mform->addElement('text', 'name', get_string('profilecategoryname', 'admin'), 'maxlength="255" size="30"');
00026         $mform->setType('name', PARAM_MULTILANG);
00027         $mform->addRule('name', $strrequired, 'required', null, 'client');
00028 
00029         $this->add_action_buttons(true);
00030 
00031     } 
00032 
00034     function validation($data, $files) {
00035         global $CFG, $DB;
00036         $errors = parent::validation($data, $files);
00037 
00038         $data  = (object)$data;
00039 
00040         $duplicate = $DB->record_exists('user_info_category', array('name'=>$data->name));
00041 
00043         if (!empty($data->id)) { // we are editing an existing record
00044             $olddata = $DB->get_record('user_info_category', array('id'=>$data->id));
00045             // name has changed, new name in use, new name in use by another record
00046             $dupfound = (($olddata->name !== $data->name) && $duplicate && ($data->id != $duplicate->id));
00047         }
00048         else { // new profile category
00049             $dupfound = $duplicate;
00050         }
00051 
00052         if ($dupfound ) {
00053             $errors['name'] = get_string('profilecategorynamenotunique', 'admin');
00054         }
00055 
00056         return $errors;
00057     }
00058 }
00059 
00060 
 All Data Structures Namespaces Files Functions Variables Enumerations