2009-11-04 08:11:02 +00:00
|
|
|
<?php
|
2007-01-25 00:04:02 +00:00
|
|
|
|
2010-05-13 02:02:05 +00:00
|
|
|
if (!defined('MOODLE_INTERNAL')) {
|
|
|
|
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
|
|
|
|
}
|
|
|
|
|
2007-01-25 00:04:02 +00:00
|
|
|
require_once($CFG->dirroot.'/lib/formslib.php');
|
|
|
|
|
|
|
|
class user_editadvanced_form extends moodleform {
|
|
|
|
|
|
|
|
// Define the form
|
2007-01-26 13:11:06 +00:00
|
|
|
function definition() {
|
2007-01-25 18:02:48 +00:00
|
|
|
global $USER, $CFG, $COURSE;
|
2007-01-25 00:04:02 +00:00
|
|
|
|
|
|
|
$mform =& $this->_form;
|
2009-11-04 06:14:06 +00:00
|
|
|
|
|
|
|
if (is_array($this->_customdata) && array_key_exists('editoroptions', $this->_customdata)) {
|
|
|
|
$editoroptions = $this->_customdata['editoroptions'];
|
|
|
|
} else {
|
|
|
|
$editoroptions = null;
|
|
|
|
}
|
|
|
|
|
2007-10-08 13:55:53 +00:00
|
|
|
//Accessibility: "Required" is bad legend text.
|
|
|
|
$strgeneral = get_string('general');
|
2007-01-25 00:04:02 +00:00
|
|
|
$strrequired = get_string('required');
|
|
|
|
|
|
|
|
/// Add some extra hidden fields
|
|
|
|
$mform->addElement('hidden', 'id');
|
2009-09-26 17:07:08 +00:00
|
|
|
$mform->setType('id', PARAM_INT);
|
2007-01-25 18:02:48 +00:00
|
|
|
$mform->addElement('hidden', 'course', $COURSE->id);
|
2009-09-26 17:07:08 +00:00
|
|
|
$mform->setType('course', PARAM_INT);
|
2007-01-25 00:04:02 +00:00
|
|
|
|
|
|
|
/// Print the required moodle fields first
|
2007-10-08 13:55:53 +00:00
|
|
|
$mform->addElement('header', 'moodle', $strgeneral);
|
2007-01-25 00:04:02 +00:00
|
|
|
|
|
|
|
$mform->addElement('text', 'username', get_string('username'), 'size="20"');
|
|
|
|
$mform->addRule('username', $strrequired, 'required', null, 'client');
|
|
|
|
$mform->setType('username', PARAM_RAW);
|
|
|
|
|
2009-06-19 14:25:56 +00:00
|
|
|
$auths = get_plugin_list('auth');
|
2007-01-25 00:04:02 +00:00
|
|
|
$auth_options = array();
|
2009-06-19 14:25:56 +00:00
|
|
|
foreach ($auths as $auth => $unused) {
|
MDL-22061 converting auths to pluginname and deprecating old method for getting auth names
AMOS START
MOV [auth_castitle,auth_cas],[pluginname,auth_cas]
MOV [auth_dbtitle,auth_db],[pluginname,auth_db]
MOV [auth_emailtitle,auth_email],[pluginname,auth_email]
MOV [auth_fctitle,auth_fc],[pluginname,auth_fc]
MOV [auth_imaptitle,auth_imap],[pluginname,auth_imap]
MOV [auth_ldaptitle,auth_ldap],[pluginname,auth_ldap]
MOV [auth_manualtitle,auth_manul],[pluginname,auth_manul]
MOV [auth_mnettitle,auth_mnet],[pluginname,auth_mnet]
MOV [auth_nntptitle,auth_nntp],[pluginname,auth_nntp]
MOV [auth_nologintitle,auth_nologin],[pluginname,auth_nologin]
MOV [auth_nonetitle,auth_none],[pluginname,auth_none]
MOV [auth_pamtitle,auth_pam],[pluginname,auth_pam]
MOV [auth_pop3title,auth_pop3],[pluginname,auth_pop3]
MOV [auth_radiustitle,auth_radius],[pluginname,auth_radius]
MOV [auth_shibbolethtitle,auth_shibboleth],[pluginname,auth_shibboleth]
MOV [auth_webservicetitle,auth_webservice],[pluginname,auth_webservice]
AMOS END
2010-04-11 21:31:36 +00:00
|
|
|
$auth_options[$auth] = get_string('pluginname', "auth_{$auth}");
|
2007-01-25 00:04:02 +00:00
|
|
|
}
|
|
|
|
$mform->addElement('select', 'auth', get_string('chooseauthmethod','auth'), $auth_options);
|
2010-07-14 08:40:48 +00:00
|
|
|
$mform->addHelpButton('auth', 'chooseauthmethod', 'auth');
|
2007-01-25 00:04:02 +00:00
|
|
|
|
2010-01-14 20:53:06 +00:00
|
|
|
if (!empty($CFG->passwordpolicy)){
|
|
|
|
$mform->addElement('static', 'passwordpolicyinfo', '', print_password_policy());
|
2010-01-06 06:49:16 +00:00
|
|
|
}
|
2007-04-30 18:03:19 +00:00
|
|
|
$mform->addElement('passwordunmask', 'newpassword', get_string('newpassword'), 'size="20"');
|
MDL-21695 Migrating the usage of root help files so far re-worded
AMOS BEGIN
HLP forcepasswordchange.html,[forcepasswordchange_help,core]
HLP interestslist.html,[interestslist_help,core]
HLP newpassword.html,[newpassword_help,core]
HLP permissions.html,[permissions_help,core_role]
HLP picture.html,[newpicture_help,core]
HLP picture.html,[newpicture_help,core_group]
HLP roles.html,[roles_help,core_role]
AMOS END
2010-05-06 21:27:58 +00:00
|
|
|
$mform->addHelpButton('newpassword', 'newpassword');
|
2007-01-25 00:04:02 +00:00
|
|
|
$mform->setType('newpassword', PARAM_RAW);
|
|
|
|
|
2007-09-15 09:42:24 +00:00
|
|
|
$mform->addElement('advcheckbox', 'preference_auth_forcepasswordchange', get_string('forcepasswordchange'));
|
MDL-21695 Migrating the usage of root help files so far re-worded
AMOS BEGIN
HLP forcepasswordchange.html,[forcepasswordchange_help,core]
HLP interestslist.html,[interestslist_help,core]
HLP newpassword.html,[newpassword_help,core]
HLP permissions.html,[permissions_help,core_role]
HLP picture.html,[newpicture_help,core]
HLP picture.html,[newpicture_help,core_group]
HLP roles.html,[roles_help,core_role]
AMOS END
2010-05-06 21:27:58 +00:00
|
|
|
$mform->addHelpButton('preference_auth_forcepasswordchange', 'forcepasswordchange');
|
2007-01-26 18:42:47 +00:00
|
|
|
/// shared fields
|
2009-11-04 06:14:06 +00:00
|
|
|
useredit_shared_definition($mform, $editoroptions);
|
2007-01-25 00:04:02 +00:00
|
|
|
|
2007-01-26 13:11:06 +00:00
|
|
|
/// Next the customisable profile fields
|
|
|
|
profile_definition($mform);
|
|
|
|
|
2007-01-25 00:04:02 +00:00
|
|
|
$this->add_action_buttons(false, get_string('updatemyprofile'));
|
|
|
|
}
|
|
|
|
|
|
|
|
function definition_after_data() {
|
2009-08-20 08:50:22 +00:00
|
|
|
global $USER, $CFG, $DB, $OUTPUT;
|
2007-01-25 00:04:02 +00:00
|
|
|
|
|
|
|
$mform =& $this->_form;
|
2008-04-25 14:43:12 +00:00
|
|
|
if ($userid = $mform->getElementValue('id')) {
|
2008-05-30 22:11:31 +00:00
|
|
|
$user = $DB->get_record('user', array('id'=>$userid));
|
2008-04-25 14:43:12 +00:00
|
|
|
} else {
|
|
|
|
$user = false;
|
|
|
|
}
|
2007-01-25 00:04:02 +00:00
|
|
|
|
2007-04-16 18:30:52 +00:00
|
|
|
// if language does not exist, use site default lang
|
|
|
|
if ($langsel = $mform->getElementValue('lang')) {
|
|
|
|
$lang = reset($langsel);
|
2008-10-10 21:30:07 +00:00
|
|
|
// check lang exists
|
2010-04-14 14:43:51 +00:00
|
|
|
if (!get_string_manager()->translation_exists($lang, false)) {
|
2007-04-16 18:30:52 +00:00
|
|
|
$lang_el =& $mform->getElement('lang');
|
|
|
|
$lang_el->setValue($CFG->lang);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-25 11:03:33 +00:00
|
|
|
// user can not change own auth method
|
|
|
|
if ($userid == $USER->id) {
|
|
|
|
$mform->hardFreeze('auth');
|
|
|
|
$mform->hardFreeze('preference_auth_forcepasswordchange');
|
2007-01-25 00:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// admin must choose some password and supply correct email
|
|
|
|
if (!empty($USER->newadminuser)) {
|
|
|
|
$mform->addRule('newpassword', get_string('required'), 'required', null, 'client');
|
|
|
|
}
|
|
|
|
|
2007-01-25 11:03:33 +00:00
|
|
|
// require password for new users
|
|
|
|
if ($userid == -1) {
|
|
|
|
$mform->addRule('newpassword', get_string('required'), 'required', null, 'client');
|
|
|
|
}
|
|
|
|
|
|
|
|
// print picture
|
2010-12-03 05:26:17 +00:00
|
|
|
if (!empty($CFG->gdversion) and empty($USER->newadminuser)) {
|
2007-03-15 12:42:39 +00:00
|
|
|
$image_el =& $mform->getElement('currentpicture');
|
2007-01-25 11:03:33 +00:00
|
|
|
if ($user and $user->picture) {
|
2009-12-27 19:47:21 +00:00
|
|
|
$image_el->setValue($OUTPUT->user_picture($user, array('courseid'=>SITEID)));
|
2007-01-25 11:03:33 +00:00
|
|
|
} else {
|
|
|
|
$image_el->setValue(get_string('none'));
|
|
|
|
}
|
|
|
|
}
|
2007-01-26 13:11:06 +00:00
|
|
|
|
|
|
|
/// Next the customisable profile fields
|
2009-03-07 20:59:25 +00:00
|
|
|
profile_definition_after_data($mform, $userid);
|
2007-01-25 11:03:33 +00:00
|
|
|
}
|
|
|
|
|
2010-06-06 14:06:30 +00:00
|
|
|
function validation($usernew, $files) {
|
2008-05-30 22:11:31 +00:00
|
|
|
global $CFG, $DB;
|
2007-01-25 11:03:33 +00:00
|
|
|
|
|
|
|
$usernew = (object)$usernew;
|
2010-07-14 08:40:48 +00:00
|
|
|
$usernew->username = trim($usernew->username);
|
|
|
|
|
|
|
|
$user = $DB->get_record('user', array('id'=>$usernew->id));
|
2007-01-26 16:19:33 +00:00
|
|
|
$err = array();
|
|
|
|
|
2007-04-25 19:36:47 +00:00
|
|
|
if (!empty($usernew->newpassword)) {
|
|
|
|
$errmsg = '';//prevent eclipse warning
|
|
|
|
if (!check_password_policy($usernew->newpassword, $errmsg)) {
|
|
|
|
$err['newpassword'] = $errmsg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-26 16:19:33 +00:00
|
|
|
if (empty($usernew->username)) {
|
|
|
|
//might be only whitespace
|
|
|
|
$err['username'] = get_string('required');
|
|
|
|
} else if (!$user or $user->username !== $usernew->username) {
|
2007-01-25 11:03:33 +00:00
|
|
|
//check new username does not exist
|
2008-05-30 22:11:31 +00:00
|
|
|
if ($DB->record_exists('user', array('username'=>$usernew->username, 'mnethostid'=>$CFG->mnet_localhost_id))) {
|
2007-01-25 11:03:33 +00:00
|
|
|
$err['username'] = get_string('usernameexists');
|
|
|
|
}
|
2010-07-14 08:40:48 +00:00
|
|
|
//check allowed characters
|
2007-01-25 11:03:33 +00:00
|
|
|
if ($usernew->username !== moodle_strtolower($usernew->username)) {
|
|
|
|
$err['username'] = get_string('usernamelowercase');
|
2010-06-06 14:06:30 +00:00
|
|
|
} else {
|
|
|
|
if ($usernew->username !== clean_param($usernew->username, PARAM_USERNAME)) {
|
2010-01-14 02:29:26 +00:00
|
|
|
$err['username'] = get_string('invalidusername');
|
2007-01-25 11:03:33 +00:00
|
|
|
}
|
2007-01-25 00:04:02 +00:00
|
|
|
}
|
|
|
|
}
|
2007-01-25 11:03:33 +00:00
|
|
|
|
|
|
|
if (!$user or $user->email !== $usernew->email) {
|
|
|
|
if (!validate_email($usernew->email)) {
|
|
|
|
$err['email'] = get_string('invalidemail');
|
2008-05-30 22:11:31 +00:00
|
|
|
} else if ($DB->record_exists('user', array('email'=>$usernew->email, 'mnethostid'=>$CFG->mnet_localhost_id))) {
|
2007-01-25 11:03:33 +00:00
|
|
|
$err['email'] = get_string('emailexists');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-26 13:11:06 +00:00
|
|
|
/// Next the customisable profile fields
|
2007-12-04 23:53:39 +00:00
|
|
|
$err += profile_validation($usernew, $files);
|
2007-01-26 13:11:06 +00:00
|
|
|
|
2007-01-25 11:03:33 +00:00
|
|
|
if (count($err) == 0){
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return $err;
|
|
|
|
}
|
2007-01-25 00:04:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-04 08:11:02 +00:00
|
|
|
|