MDL-22388 Added some checks to kill these scripts dead with an unequivocal notice...
[moodle.git] / group / group_form.php
CommitLineData
4ca6cfbf 1<?php
77e90955 2
8bdc9cac
SH
3/**
4 * Create//edit group form.
5 *
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
11 */
12
bfebaf64
MD
13if (!defined('MOODLE_INTERNAL')) {
14 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
15}
16
77e90955 17require_once($CFG->dirroot.'/lib/formslib.php');
18
80efbf98 19/// get url variables
ddff2fa8 20class group_form extends moodleform {
77e90955 21
22 // Define the form
23 function definition () {
24 global $USER, $CFG, $COURSE;
25
77e90955 26 $mform =& $this->_form;
8bdc9cac 27 $editoroptions = $this->_customdata['editoroptions'];
2524b0f2 28
80efbf98 29 $mform->addElement('text','name', get_string('groupname', 'group'),'maxlength="254" size="50"');
ddff2fa8 30 $mform->addRule('name', get_string('required'), 'required', null, 'client');
77e90955 31 $mform->setType('name', PARAM_MULTILANG);
32
8bdc9cac
SH
33 $mform->addElement('editor', 'description_editor', get_string('groupdescription', 'group'), null, $editoroptions);
34 $mform->setType('description_editor', PARAM_RAW);
2524b0f2 35
54bb33eb 36 $mform->addElement('passwordunmask', 'enrolmentkey', get_string('enrolmentkey', 'group'), 'maxlength="254" size="24"', get_string('enrolmentkey'));
77e90955 37 $mform->setHelpButton('enrolmentkey', array('groupenrolmentkey', get_string('enrolmentkey', 'group')), true);
38 $mform->setType('enrolmentkey', PARAM_RAW);
2524b0f2 39
77e90955 40 $maxbytes = get_max_upload_file_size($CFG->maxbytes, $COURSE->maxbytes);
2524b0f2 41
80efbf98 42 if (!empty($CFG->gdversion) and $maxbytes) {
f595adf5 43 $options = array(get_string('no'), get_string('yes'));
44 $mform->addElement('select', 'hidepicture', get_string('hidepicture'), $options);
2524b0f2 45
80efbf98 46 $mform->addElement('file', 'imagefile', get_string('newpicture', 'group'));
27d1a27c 47 $mform->addHelpButton('imagefile', 'newpicture', 'group');
77e90955 48 }
49
2524b0f2 50 $mform->addElement('hidden','id');
51 $mform->setType('id', PARAM_INT);
08103c93 52
2524b0f2 53 $mform->addElement('hidden','courseid');
54 $mform->setType('courseid', PARAM_INT);
77e90955 55
ddff2fa8 56 $this->add_action_buttons();
77e90955 57 }
58
a78890d5 59 function validation($data, $files) {
82672532 60 global $COURSE, $DB, $CFG;
2524b0f2 61
a78890d5 62 $errors = parent::validation($data, $files);
2524b0f2 63
9e1bb310 64 $textlib = textlib_get_instance();
65
32648682 66 $name = trim($data['name']);
dfdaabd6 67 if ($data['id'] and $group = $DB->get_record('groups', array('id'=>$data['id']))) {
9e1bb310 68 if ($textlib->strtolower($group->name) != $textlib->strtolower($name)) {
c4e953e6 69 if (groups_get_group_by_name($COURSE->id, $name)) {
ddff2fa8 70 $errors['name'] = get_string('groupnameexists', 'group', $name);
2524b0f2 71 }
72 }
73
82672532 74 if (!empty($CFG->enrol_manual_usepasswordpolicy) and $data['enrolmentkey'] != '' and $group->enrolmentkey !== $data['enrolmentkey']) {
75 // enforce password policy only if changing password
76 $errmsg = '';
77 if (!check_password_policy($data['enrolmentkey'], $errmsg)) {
78 $errors['enrolmentkey'] = $errmsg;
79 }
80 }
81
178f9658 82 } else if (groups_get_group_by_name($COURSE->id, $name)) {
ddff2fa8 83 $errors['name'] = get_string('groupnameexists', 'group', $name);
2524b0f2 84 }
85
a78890d5 86 return $errors;
2524b0f2 87 }
88
77e90955 89 function get_um() {
90 return $this->_upload_manager;
91 }
8bdc9cac
SH
92
93 function get_editor_options() {
94 return $this->_customdata['editoroptions'];
95 }
77e90955 96}