3 require_once($CFG->dirroot
.'/lib/formslib.php');
6 class grouping_form
extends moodleform
{
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) {
33 $errors = parent
::validation($data, $files);
35 $name = trim(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);