| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php //$Id: editadvanced_form.php,v 1.14.2.5 2008/10/10 21:27:42 stronk7 Exp $ 2 3 require_once($CFG->dirroot.'/lib/formslib.php'); 4 5 class user_editadvanced_form extends moodleform { 6 7 // Define the form 8 function definition() { 9 global $USER, $CFG, $COURSE; 10 11 $mform =& $this->_form; 12 $this->set_upload_manager(new upload_manager('imagefile', false, false, null, false, 0, true, true, false)); 13 //Accessibility: "Required" is bad legend text. 14 $strgeneral = get_string('general'); 15 $strrequired = get_string('required'); 16 17 /// Add some extra hidden fields 18 $mform->addElement('hidden', 'id'); 19 $mform->addElement('hidden', 'course', $COURSE->id); 20 21 /// Print the required moodle fields first 22 $mform->addElement('header', 'moodle', $strgeneral); 23 24 $mform->addElement('text', 'username', get_string('username'), 'size="20"'); 25 $mform->addRule('username', $strrequired, 'required', null, 'client'); 26 $mform->setType('username', PARAM_RAW); 27 28 $modules = get_list_of_plugins('auth'); 29 $auth_options = array(); 30 foreach ($modules as $module) { 31 $auth_options[$module] = get_string("auth_$module"."title", "auth"); 32 } 33 $mform->addElement('select', 'auth', get_string('chooseauthmethod','auth'), $auth_options); 34 $mform->setHelpButton('auth', array('authchange', get_string('chooseauthmethod','auth'))); 35 $mform->setAdvanced('auth'); 36 37 $mform->addElement('passwordunmask', 'newpassword', get_string('newpassword'), 'size="20"'); 38 $mform->setHelpButton('newpassword',array('newpassword', get_string('leavetokeep'))); 39 $mform->setType('newpassword', PARAM_RAW); 40 41 $mform->addElement('advcheckbox', 'preference_auth_forcepasswordchange', get_string('forcepasswordchange')); 42 $mform->setHelpButton('preference_auth_forcepasswordchange',array('forcepasswordchange', get_string('forcepasswordchange'))); 43 /// shared fields 44 useredit_shared_definition($mform); 45 46 /// Next the customisable profile fields 47 profile_definition($mform); 48 49 $this->add_action_buttons(false, get_string('updatemyprofile')); 50 } 51 52 function definition_after_data() { 53 global $USER, $CFG; 54 55 $mform =& $this->_form; 56 if ($userid = $mform->getElementValue('id')) { 57 $user = get_record('user', 'id', $userid); 58 } else { 59 $user = false; 60 } 61 62 // if language does not exist, use site default lang 63 if ($langsel = $mform->getElementValue('lang')) { 64 $lang = reset($langsel); 65 // missing _utf8 in language, add it before further processing. MDL-11829 MDL-16845 66 if (strpos($lang, '_utf8') === false) { 67 $lang = $lang . '_utf8'; 68 $lang_el =& $mform->getElement('lang'); 69 $lang_el->setValue($lang); 70 } 71 // check lang exists 72 if (!file_exists($CFG->dataroot.'/lang/'.$lang) and 73 !file_exists($CFG->dirroot .'/lang/'.$lang)) { 74 $lang_el =& $mform->getElement('lang'); 75 $lang_el->setValue($CFG->lang); 76 } 77 } 78 79 // user can not change own auth method 80 if ($userid == $USER->id) { 81 $mform->hardFreeze('auth'); 82 $mform->hardFreeze('preference_auth_forcepasswordchange'); 83 } 84 85 // admin must choose some password and supply correct email 86 if (!empty($USER->newadminuser)) { 87 $mform->addRule('newpassword', get_string('required'), 'required', null, 'client'); 88 89 $email_el =& $mform->getElement('email'); 90 if ($email_el->getValue() == 'root@localhost') { 91 $email_el->setValue(''); 92 } 93 } 94 95 // require password for new users 96 if ($userid == -1) { 97 $mform->addRule('newpassword', get_string('required'), 'required', null, 'client'); 98 } 99 100 // print picture 101 if (!empty($CFG->gdversion)) { 102 $image_el =& $mform->getElement('currentpicture'); 103 if ($user and $user->picture) { 104 $image_el->setValue(print_user_picture($user, SITEID, $user->picture, 64, true, false, '', true)); 105 } else { 106 $image_el->setValue(get_string('none')); 107 } 108 } 109 110 /// Next the customisable profile fields 111 profile_definition_after_data($mform); 112 } 113 114 function validation($usernew, $files) { 115 global $CFG; 116 117 $usernew = (object)$usernew; 118 $usernew->username = trim($usernew->username); 119 120 $user = get_record('user', 'id', $usernew->id); 121 $err = array(); 122 123 if (!empty($usernew->newpassword)) { 124 $errmsg = '';//prevent eclipse warning 125 if (!check_password_policy($usernew->newpassword, $errmsg)) { 126 $err['newpassword'] = $errmsg; 127 } 128 } 129 130 if (empty($usernew->username)) { 131 //might be only whitespace 132 $err['username'] = get_string('required'); 133 } else if (!$user or $user->username !== $usernew->username) { 134 //check new username does not exist 135 if (record_exists('user', 'username', $usernew->username, 'mnethostid', $CFG->mnet_localhost_id)) { 136 $err['username'] = get_string('usernameexists'); 137 } 138 //check allowed characters 139 if ($usernew->username !== moodle_strtolower($usernew->username)) { 140 $err['username'] = get_string('usernamelowercase'); 141 } else { 142 if (empty($CFG->extendedusernamechars)) { 143 $string = eregi_replace("[^(-\.[:alnum:])]", '', $usernew->username); 144 if ($usernew->username !== $string) { 145 $err['username'] = get_string('alphanumerical'); 146 } 147 } 148 } 149 } 150 151 if (!$user or $user->email !== $usernew->email) { 152 if (!validate_email($usernew->email)) { 153 $err['email'] = get_string('invalidemail'); 154 } else if (record_exists('user', 'email', $usernew->email, 'mnethostid', $CFG->mnet_localhost_id)) { 155 $err['email'] = get_string('emailexists'); 156 } 157 } 158 159 /// Next the customisable profile fields 160 $err += profile_validation($usernew, $files); 161 162 if (count($err) == 0){ 163 return true; 164 } else { 165 return $err; 166 } 167 } 168 169 function get_um() { 170 return $this->_upload_manager; 171 } 172 } 173 174 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |