MDL-22388 Added some checks to kill these scripts dead with an unequivocal notice...
[moodle.git] / group / group_form.php
1 <?php
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  */
13 if (!defined('MOODLE_INTERNAL')) {
14     die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page
15 }
17 require_once($CFG->dirroot.'/lib/formslib.php');
19 /// get url variables
20 class group_form extends moodleform {
22     // Define the form
23     function definition () {
24         global $USER, $CFG, $COURSE;
26         $mform =& $this->_form;
27         $editoroptions = $this->_customdata['editoroptions'];
29         $mform->addElement('text','name', get_string('groupname', 'group'),'maxlength="254" size="50"');
30         $mform->addRule('name', get_string('required'), 'required', null, 'client');
31         $mform->setType('name', PARAM_MULTILANG);
33         $mform->addElement('editor', 'description_editor', get_string('groupdescription', 'group'), null, $editoroptions);
34         $mform->setType('description_editor', PARAM_RAW);
36         $mform->addElement('passwordunmask', 'enrolmentkey', get_string('enrolmentkey', 'group'), 'maxlength="254" size="24"', get_string('enrolmentkey'));
37         $mform->setHelpButton('enrolmentkey', array('groupenrolmentkey', get_string('enrolmentkey', 'group')), true);
38         $mform->setType('enrolmentkey', PARAM_RAW);
40         $maxbytes = get_max_upload_file_size($CFG->maxbytes, $COURSE->maxbytes);
42         if (!empty($CFG->gdversion) and $maxbytes) {
43             $options = array(get_string('no'), get_string('yes'));
44             $mform->addElement('select', 'hidepicture', get_string('hidepicture'), $options);
46             $mform->addElement('file', 'imagefile', get_string('newpicture', 'group'));
47             $mform->addHelpButton('imagefile', 'newpicture', 'group');
48         }
50         $mform->addElement('hidden','id');
51         $mform->setType('id', PARAM_INT);
53         $mform->addElement('hidden','courseid');
54         $mform->setType('courseid', PARAM_INT);
56         $this->add_action_buttons();
57     }
59     function validation($data, $files) {
60         global $COURSE, $DB, $CFG;
62         $errors = parent::validation($data, $files);
64         $textlib = textlib_get_instance();
66         $name = trim($data['name']);
67         if ($data['id'] and $group = $DB->get_record('groups', array('id'=>$data['id']))) {
68             if ($textlib->strtolower($group->name) != $textlib->strtolower($name)) {
69                 if (groups_get_group_by_name($COURSE->id,  $name)) {
70                     $errors['name'] = get_string('groupnameexists', 'group', $name);
71                 }
72             }
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             }
82         } else if (groups_get_group_by_name($COURSE->id, $name)) {
83             $errors['name'] = get_string('groupnameexists', 'group', $name);
84         }
86         return $errors;
87     }
89     function get_um() {
90         return $this->_upload_manager;
91     }
93     function get_editor_options() {
94         return $this->_customdata['editoroptions'];
95     }
96 }