Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/group/group_form.php
Go to the documentation of this file.
00001 <?php
00002 
00013 defined('MOODLE_INTERNAL') || die;
00014 
00015 require_once($CFG->dirroot.'/lib/formslib.php');
00016 
00018 class group_form extends moodleform {
00019 
00020     // Define the form
00021     function definition () {
00022         global $USER, $CFG, $COURSE;
00023 
00024         $mform =& $this->_form;
00025         $editoroptions = $this->_customdata['editoroptions'];
00026 
00027         $mform->addElement('text','name', get_string('groupname', 'group'),'maxlength="254" size="50"');
00028         $mform->addRule('name', get_string('required'), 'required', null, 'client');
00029         $mform->setType('name', PARAM_MULTILANG);
00030 
00031         $mform->addElement('editor', 'description_editor', get_string('groupdescription', 'group'), null, $editoroptions);
00032         $mform->setType('description_editor', PARAM_RAW);
00033 
00034         $mform->addElement('passwordunmask', 'enrolmentkey', get_string('enrolmentkey', 'group'), 'maxlength="254" size="24"', get_string('enrolmentkey', 'group'));
00035         $mform->addHelpButton('enrolmentkey', 'enrolmentkey', 'group');
00036         $mform->setType('enrolmentkey', PARAM_RAW);
00037 
00038         if (!empty($CFG->gdversion)) {
00039             $options = array(get_string('no'), get_string('yes'));
00040             $mform->addElement('select', 'hidepicture', get_string('hidepicture'), $options);
00041 
00042             $mform->addElement('filepicker', 'imagefile', get_string('newpicture', 'group'));
00043             $mform->addHelpButton('imagefile', 'newpicture', 'group');
00044         }
00045 
00046         $mform->addElement('hidden','id');
00047         $mform->setType('id', PARAM_INT);
00048 
00049         $mform->addElement('hidden','courseid');
00050         $mform->setType('courseid', PARAM_INT);
00051 
00052         $this->add_action_buttons();
00053     }
00054 
00055     function validation($data, $files) {
00056         global $COURSE, $DB, $CFG;
00057 
00058         $errors = parent::validation($data, $files);
00059 
00060         $textlib = textlib_get_instance();
00061 
00062         $name = trim($data['name']);
00063         if ($data['id'] and $group = $DB->get_record('groups', array('id'=>$data['id']))) {
00064             if ($textlib->strtolower($group->name) != $textlib->strtolower($name)) {
00065                 if (groups_get_group_by_name($COURSE->id,  $name)) {
00066                     $errors['name'] = get_string('groupnameexists', 'group', $name);
00067                 }
00068             }
00069 
00070             if (!empty($CFG->groupenrolmentkeypolicy) and $data['enrolmentkey'] != '' and $group->enrolmentkey !== $data['enrolmentkey']) {
00071                 // enforce password policy only if changing password
00072                 $errmsg = '';
00073                 if (!check_password_policy($data['enrolmentkey'], $errmsg)) {
00074                     $errors['enrolmentkey'] = $errmsg;
00075                 }
00076             }
00077 
00078         } else if (groups_get_group_by_name($COURSE->id, $name)) {
00079             $errors['name'] = get_string('groupnameexists', 'group', $name);
00080         }
00081 
00082         return $errors;
00083     }
00084 
00085     function get_editor_options() {
00086         return $this->_customdata['editoroptions'];
00087     }
00088 }
 All Data Structures Namespaces Files Functions Variables Enumerations