2009-11-01 12:00:47 +00:00
|
|
|
<?php
|
2007-03-28 08:40:32 +00:00
|
|
|
|
2009-11-04 06:14:06 +00:00
|
|
|
/**
|
|
|
|
* Create//edit group form.
|
|
|
|
*
|
|
|
|
* @copyright © 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
|
|
|
|
*/
|
|
|
|
|
2007-03-28 08:40:32 +00:00
|
|
|
require_once($CFG->dirroot.'/lib/formslib.php');
|
|
|
|
|
2007-03-29 08:40:08 +00:00
|
|
|
/// get url variables
|
2007-08-15 23:51:07 +00:00
|
|
|
class group_form extends moodleform {
|
2007-03-28 08:40:32 +00:00
|
|
|
|
|
|
|
// Define the form
|
|
|
|
function definition () {
|
|
|
|
global $USER, $CFG, $COURSE;
|
|
|
|
|
|
|
|
$mform =& $this->_form;
|
2009-11-04 06:14:06 +00:00
|
|
|
$editoroptions = $this->_customdata['editoroptions'];
|
2007-08-14 00:50:00 +00:00
|
|
|
|
2007-03-29 08:40:08 +00:00
|
|
|
$mform->addElement('text','name', get_string('groupname', 'group'),'maxlength="254" size="50"');
|
2007-08-15 23:51:07 +00:00
|
|
|
$mform->addRule('name', get_string('required'), 'required', null, 'client');
|
2007-03-28 08:40:32 +00:00
|
|
|
$mform->setType('name', PARAM_MULTILANG);
|
|
|
|
|
2009-11-04 06:14:06 +00:00
|
|
|
$mform->addElement('editor', 'description_editor', get_string('groupdescription', 'group'), null, $editoroptions);
|
|
|
|
$mform->setType('description_editor', PARAM_RAW);
|
2007-08-14 00:50:00 +00:00
|
|
|
|
2007-04-30 18:03:19 +00:00
|
|
|
$mform->addElement('passwordunmask', 'enrolmentkey', get_string('enrolmentkey', 'group'), 'maxlength="254" size="24"', get_string('enrolmentkey'));
|
2007-03-28 08:40:32 +00:00
|
|
|
$mform->setHelpButton('enrolmentkey', array('groupenrolmentkey', get_string('enrolmentkey', 'group')), true);
|
|
|
|
$mform->setType('enrolmentkey', PARAM_RAW);
|
2007-08-14 00:50:00 +00:00
|
|
|
|
2007-03-28 08:40:32 +00:00
|
|
|
$maxbytes = get_max_upload_file_size($CFG->maxbytes, $COURSE->maxbytes);
|
2007-08-14 00:50:00 +00:00
|
|
|
|
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-08-14 00:50:00 +00:00
|
|
|
|
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);
|
2007-03-28 08:40:32 +00:00
|
|
|
}
|
|
|
|
|
2007-08-14 00:50:00 +00:00
|
|
|
$mform->addElement('hidden','id');
|
|
|
|
$mform->setType('id', PARAM_INT);
|
2007-07-07 14:18:30 +12:00
|
|
|
|
2007-08-14 00:50:00 +00:00
|
|
|
$mform->addElement('hidden','courseid');
|
|
|
|
$mform->setType('courseid', PARAM_INT);
|
2007-03-28 08:40:32 +00:00
|
|
|
|
2007-08-15 23:51:07 +00:00
|
|
|
$this->add_action_buttons();
|
2007-03-28 08:40:32 +00:00
|
|
|
}
|
|
|
|
|
2007-11-23 22:15:07 +00:00
|
|
|
function validation($data, $files) {
|
2008-12-06 21:20:42 +00:00
|
|
|
global $COURSE, $DB, $CFG;
|
2007-08-14 00:50:00 +00:00
|
|
|
|
2007-11-23 22:15:07 +00:00
|
|
|
$errors = parent::validation($data, $files);
|
2007-08-14 00:50:00 +00:00
|
|
|
|
2008-12-29 21:32:20 +00:00
|
|
|
$textlib = textlib_get_instance();
|
|
|
|
|
2008-06-01 17:53:25 +00:00
|
|
|
$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']))) {
|
2008-12-29 21:32:20 +00:00
|
|
|
if ($textlib->strtolower($group->name) != $textlib->strtolower($name)) {
|
2007-08-15 20:33:17 +00:00
|
|
|
if (groups_get_group_by_name($COURSE->id, $name)) {
|
2007-08-15 23:51:07 +00:00
|
|
|
$errors['name'] = get_string('groupnameexists', 'group', $name);
|
2007-08-14 00:50:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-06 21:20:42 +00:00
|
|
|
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)) {
|
2007-08-15 23:51:07 +00:00
|
|
|
$errors['name'] = get_string('groupnameexists', 'group', $name);
|
2007-08-14 00:50:00 +00:00
|
|
|
}
|
|
|
|
|
2007-11-23 22:15:07 +00:00
|
|
|
return $errors;
|
2007-08-14 00:50:00 +00:00
|
|
|
}
|
|
|
|
|
2007-03-28 08:40:32 +00:00
|
|
|
function get_um() {
|
|
|
|
return $this->_upload_manager;
|
|
|
|
}
|
2009-11-04 06:14:06 +00:00
|
|
|
|
|
|
|
function get_editor_options() {
|
|
|
|
return $this->_customdata['editoroptions'];
|
|
|
|
}
|
2007-03-28 08:40:32 +00:00
|
|
|
}
|