moodle/group/group_form.php

93 lines
3.3 KiB
PHP
Raw Normal View History

<?php
/**
* Create//edit group form.
*
* @copyright &copy; 2006 The Open University
* @author N.D.Freear AT open.ac.uk
* @author J.White AT open.ac.uk
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package groups
*/
require_once($CFG->dirroot.'/lib/formslib.php');
2007-03-29 08:40:08 +00:00
/// get url variables
class group_form extends moodleform {
// Define the form
function definition () {
global $USER, $CFG, $COURSE;
$mform =& $this->_form;
$editoroptions = $this->_customdata['editoroptions'];
2007-03-29 08:40:08 +00:00
$mform->addElement('text','name', get_string('groupname', 'group'),'maxlength="254" size="50"');
$mform->addRule('name', get_string('required'), 'required', null, 'client');
$mform->setType('name', PARAM_MULTILANG);
$mform->addElement('editor', 'description_editor', get_string('groupdescription', 'group'), null, $editoroptions);
$mform->setType('description_editor', PARAM_RAW);
$mform->addElement('passwordunmask', 'enrolmentkey', get_string('enrolmentkey', 'group'), 'maxlength="254" size="24"', get_string('enrolmentkey'));
$mform->setHelpButton('enrolmentkey', array('groupenrolmentkey', get_string('enrolmentkey', 'group')), true);
$mform->setType('enrolmentkey', PARAM_RAW);
$maxbytes = get_max_upload_file_size($CFG->maxbytes, $COURSE->maxbytes);
2007-03-29 08:40:08 +00:00
if (!empty($CFG->gdversion) and $maxbytes) {
2007-04-04 01:43:31 +00:00
$options = array(get_string('no'), get_string('yes'));
$mform->addElement('select', 'hidepicture', get_string('hidepicture'), $options);
2007-03-29 08:40:08 +00:00
$mform->addElement('file', 'imagefile', get_string('newpicture', 'group'));
$mform->setHelpButton('imagefile', array ('picture', get_string('helppicture')), true);
}
$mform->addElement('hidden','id');
$mform->setType('id', PARAM_INT);
2007-07-07 14:18:30 +12:00
$mform->addElement('hidden','courseid');
$mform->setType('courseid', PARAM_INT);
$this->add_action_buttons();
}
function validation($data, $files) {
global $COURSE, $DB, $CFG;
$errors = parent::validation($data, $files);
$textlib = textlib_get_instance();
$name = trim($data['name']);
2008-06-01 13:09:04 +00:00
if ($data['id'] and $group = $DB->get_record('groups', array('id'=>$data['id']))) {
if ($textlib->strtolower($group->name) != $textlib->strtolower($name)) {
if (groups_get_group_by_name($COURSE->id, $name)) {
$errors['name'] = get_string('groupnameexists', 'group', $name);
}
}
if (!empty($CFG->enrol_manual_usepasswordpolicy) and $data['enrolmentkey'] != '' and $group->enrolmentkey !== $data['enrolmentkey']) {
// enforce password policy only if changing password
$errmsg = '';
if (!check_password_policy($data['enrolmentkey'], $errmsg)) {
$errors['enrolmentkey'] = $errmsg;
}
}
2007-08-16 15:52:52 +00:00
} else if (groups_get_group_by_name($COURSE->id, $name)) {
$errors['name'] = get_string('groupnameexists', 'group', $name);
}
return $errors;
}
function get_um() {
return $this->_upload_manager;
}
function get_editor_options() {
return $this->_customdata['editoroptions'];
}
}