Merge branch 'm22_MDL-34994' of git://github.com/danmarsden/moodle into MOODLE_22_STABLE
[moodle.git] / group / group_form.php
blob65de0c84fa2b8cf735bdd357db0b5e1d3484cbf7
1 <?php
3 /**
4 * Create//edit group form.
6 * @copyright &copy; 2006 The Open University
7 * @author N.D.Freear AT open.ac.uk
8 * @author J.White AT open.ac.uk
9 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
10 * @package groups
13 defined('MOODLE_INTERNAL') || die;
15 require_once($CFG->dirroot.'/lib/formslib.php');
17 /// get url variables
18 class group_form extends moodleform {
20 // Define the form
21 function definition () {
22 global $USER, $CFG, $COURSE;
24 $mform =& $this->_form;
25 $editoroptions = $this->_customdata['editoroptions'];
27 $mform->addElement('text','name', get_string('groupname', 'group'),'maxlength="254" size="50"');
28 $mform->addRule('name', get_string('required'), 'required', null, 'client');
29 $mform->setType('name', PARAM_MULTILANG);
31 $mform->addElement('editor', 'description_editor', get_string('groupdescription', 'group'), null, $editoroptions);
32 $mform->setType('description_editor', PARAM_RAW);
34 $mform->addElement('passwordunmask', 'enrolmentkey', get_string('enrolmentkey', 'group'), 'maxlength="254" size="24"', get_string('enrolmentkey', 'group'));
35 $mform->addHelpButton('enrolmentkey', 'enrolmentkey', 'group');
36 $mform->setType('enrolmentkey', PARAM_RAW);
38 if (!empty($CFG->gdversion)) {
39 $options = array(get_string('no'), get_string('yes'));
40 $mform->addElement('select', 'hidepicture', get_string('hidepicture'), $options);
42 $mform->addElement('filepicker', 'imagefile', get_string('newpicture', 'group'));
43 $mform->addHelpButton('imagefile', 'newpicture', 'group');
46 $mform->addElement('hidden','id');
47 $mform->setType('id', PARAM_INT);
49 $mform->addElement('hidden','courseid');
50 $mform->setType('courseid', PARAM_INT);
52 $this->add_action_buttons();
55 function validation($data, $files) {
56 global $COURSE, $DB, $CFG;
58 $errors = parent::validation($data, $files);
60 $textlib = textlib_get_instance();
62 $name = trim($data['name']);
63 if ($data['id'] and $group = $DB->get_record('groups', array('id'=>$data['id']))) {
64 if ($textlib->strtolower($group->name) != $textlib->strtolower($name)) {
65 if (groups_get_group_by_name($COURSE->id, $name)) {
66 $errors['name'] = get_string('groupnameexists', 'group', $name);
70 if (!empty($CFG->groupenrolmentkeypolicy) and $data['enrolmentkey'] != '' and $group->enrolmentkey !== $data['enrolmentkey']) {
71 // enforce password policy only if changing password
72 $errmsg = '';
73 if (!check_password_policy($data['enrolmentkey'], $errmsg)) {
74 $errors['enrolmentkey'] = $errmsg;
78 } else if (groups_get_group_by_name($COURSE->id, $name)) {
79 $errors['name'] = get_string('groupnameexists', 'group', $name);
82 return $errors;
85 function get_editor_options() {
86 return $this->_customdata['editoroptions'];