MDL-11328 Added the missing variable
[moodle-pu.git] / group / grouping_form.php
blob2f2dc039e141f52f5911c42d31d5ea7c11ab5a81
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) {
31 global $COURSE;
33 $errors = array();
35 $name = stripslashes($data['name']);
36 if ($data['id'] and $grouping = get_record('groupings', 'id', $data['id'])) {
37 if ($grouping->name != $name) {
38 if (groups_get_grouping_by_name($COURSE->id, $name)) {
39 $errors['name'] = get_string('groupingnameexists', 'group', $name);
43 } else if (groups_get_grouping_by_name($COURSE->id, $name)) {
44 $errors['name'] = get_string('groupingnameexists', 'group', $name);
47 if (count($errors) > 0) {
48 return $errors;
49 } else {
50 return true;