Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / group / group_form.php
blob42c6589dac0746a2cb2dfafb99eadf4d74685130
1 <?php //$Id$
3 require_once($CFG->dirroot.'/lib/formslib.php');
5 /// get url variables
6 class group_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('groupname', 'group'),'maxlength="254" size="50"');
15 $mform->addRule('name', get_string('required'), 'required', null, 'client');
16 $mform->setType('name', PARAM_MULTILANG);
18 $mform->addElement('htmleditor', 'description', get_string('groupdescription', 'group'), array('rows'=> '15', 'course' => $COURSE->id, 'cols'=>'45'));
19 $mform->setType('description', PARAM_RAW);
21 $mform->addElement('passwordunmask', 'enrolmentkey', get_string('enrolmentkey', 'group'), 'maxlength="254" size="24"', get_string('enrolmentkey'));
22 $mform->setHelpButton('enrolmentkey', array('groupenrolmentkey', get_string('enrolmentkey', 'group')), true);
23 $mform->setType('enrolmentkey', PARAM_RAW);
25 $maxbytes = get_max_upload_file_size($CFG->maxbytes, $COURSE->maxbytes);
27 if (!empty($CFG->gdversion) and $maxbytes) {
28 $options = array(get_string('no'), get_string('yes'));
29 $mform->addElement('select', 'hidepicture', get_string('hidepicture'), $options);
31 $this->set_upload_manager(new upload_manager('imagefile', false, false, null, false, 0, true, true, false));
32 $mform->addElement('file', 'imagefile', get_string('newpicture', 'group'));
33 $mform->setHelpButton('imagefile', array ('picture', get_string('helppicture')), true);
36 $mform->addElement('hidden','id');
37 $mform->setType('id', PARAM_INT);
39 $mform->addElement('hidden','courseid');
40 $mform->setType('courseid', PARAM_INT);
42 $this->add_action_buttons();
45 function validation($data, $files) {
46 global $COURSE;
48 $errors = parent::validation($data, $files);
50 $name = trim(stripslashes($data['name']));
51 if ($data['id'] and $group = get_record('groups', 'id', $data['id'])) {
52 if ($group->name != $name) {
53 if (groups_get_group_by_name($COURSE->id, $name)) {
54 $errors['name'] = get_string('groupnameexists', 'group', $name);
58 } else if (groups_get_group_by_name($COURSE->id, $name)) {
59 $errors['name'] = get_string('groupnameexists', 'group', $name);
62 return $errors;
65 function get_um() {
66 return $this->_upload_manager;