calendar/lib: calendar_set_filters() use pre-fetched context and course recs
[moodle-pu.git] / group / group_form.php
blob727540d6efa8cef37937eb5ace3b45ac4e84b509
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) {
46 global $COURSE;
48 $errors = array();
50 $name = 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 if (count($errors) > 0) {
63 return $errors;
64 } else {
65 return true;
69 function get_um() {
70 return $this->_upload_manager;