weekly release 1.9.12+
[moodle.git] / group / grouping_form.php
blobc0558be66e083b781ab71307a6c5e7b7b4720e6b
1 <?php //$Id$
3 require_once($CFG->dirroot.'/lib/formslib.php');
5 /// get url variables
6 class grouping_form extends moodleform {
8 // Define the form
9 function definition () {
10 global $USER, $CFG, $COURSE;
12 $mform =& $this->_form;
14 $mform->addElement('text','name', get_string('groupingname', 'group'),'maxlength="254" size="50"');
15 $mform->addRule('name', get_string('required'), 'required', null, 'server');
16 $mform->setType('name', PARAM_MULTILANG);
18 $mform->addElement('htmleditor', 'description', get_string('groupingdescription', 'group'), array('rows'=> '15', 'course' => $COURSE->id, 'cols'=>'45'));
19 $mform->setType('description', PARAM_RAW);
21 $mform->addElement('hidden','id');
22 $mform->setType('id', PARAM_INT);
24 $mform->addElement('hidden', 'courseid');
25 $mform->setType('courseid', PARAM_INT);
27 $this->add_action_buttons();
30 function validation($data, $files) {
31 global $COURSE;
33 $errors = parent::validation($data, $files);
35 $textlib = textlib_get_instance();
37 $name = trim(stripslashes($data['name']));
38 if ($data['id'] and $grouping = get_record('groupings', 'id', $data['id'])) {
39 if ($textlib->strtolower($grouping->name) != $textlib->strtolower($name)) {
40 if (groups_get_grouping_by_name($COURSE->id, $name)) {
41 $errors['name'] = get_string('groupingnameexists', 'group', $name);
45 } else if (groups_get_grouping_by_name($COURSE->id, $name)) {
46 $errors['name'] = get_string('groupingnameexists', 'group', $name);
49 return $errors;