|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00012 if (!defined('MOODLE_INTERNAL')) { 00013 die('Direct access to this script is forbidden.'); 00014 } 00015 00016 require_once($CFG->dirroot.'/lib/formslib.php'); 00017 00019 class grouping_form extends moodleform { 00020 00021 // Define the form 00022 function definition () { 00023 global $USER, $CFG, $COURSE; 00024 00025 $mform =& $this->_form; 00026 $editoroptions = $this->_customdata['editoroptions']; 00027 00028 $mform->addElement('text','name', get_string('groupingname', 'group'),'maxlength="254" size="50"'); 00029 $mform->addRule('name', get_string('required'), 'required', null, 'server'); 00030 $mform->setType('name', PARAM_MULTILANG); 00031 00032 $mform->addElement('editor', 'description_editor', get_string('groupingdescription', 'group'), null, $editoroptions); 00033 $mform->setType('description_editor', PARAM_RAW); 00034 00035 $mform->addElement('hidden','id'); 00036 $mform->setType('id', PARAM_INT); 00037 00038 $mform->addElement('hidden', 'courseid'); 00039 $mform->setType('courseid', PARAM_INT); 00040 00041 $this->add_action_buttons(); 00042 } 00043 00044 function validation($data, $files) { 00045 global $COURSE, $DB; 00046 00047 $errors = parent::validation($data, $files); 00048 00049 $textlib = textlib_get_instance(); 00050 00051 $name = trim($data['name']); 00052 if ($data['id'] and $grouping = $DB->get_record('groupings', array('id'=>$data['id']))) { 00053 if ($textlib->strtolower($grouping->name) != $textlib->strtolower($name)) { 00054 if (groups_get_grouping_by_name($COURSE->id, $name)) { 00055 $errors['name'] = get_string('groupingnameexists', 'group', $name); 00056 } 00057 } 00058 00059 } else if (groups_get_grouping_by_name($COURSE->id, $name)) { 00060 $errors['name'] = get_string('groupingnameexists', 'group', $name); 00061 } 00062 00063 return $errors; 00064 } 00065 00066 }