| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php //$Id: edit_form.php,v 1.24.2.5 2008/10/13 19:38:49 skodak Exp $ 2 3 require_once($CFG->dirroot.'/lib/formslib.php'); 4 5 class user_edit_form extends moodleform { 6 7 // Define the form 8 function definition () { 9 global $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 /// shared fields 25 useredit_shared_definition($mform); 26 27 /// extra settigs 28 $mform->addRule('description', $strrequired, 'required', null, 'client'); 29 if (!empty($CFG->gdversion) and !empty($CFG->disableuserimages)) { 30 $mform->removeElement('deletepicture'); 31 $mform->removeElement('imagefile'); 32 $mform->removeElement('imagealt'); 33 } 34 35 /// Next the customisable profile fields 36 profile_definition($mform); 37 38 $this->add_action_buttons(false, get_string('updatemyprofile')); 39 } 40 41 function definition_after_data() { 42 global $CFG; 43 44 $mform =& $this->_form; 45 $userid = $mform->getElementValue('id'); 46 47 // if language does not exist, use site default lang 48 if ($langsel = $mform->getElementValue('lang')) { 49 $lang = reset($langsel); 50 // missing _utf8 in language, add it before further processing. MDL-11829 MDL-16845 51 if (strpos($lang, '_utf8') === false) { 52 $lang = $lang . '_utf8'; 53 $lang_el =& $mform->getElement('lang'); 54 $lang_el->setValue($lang); 55 } 56 // check lang exists 57 if (!file_exists($CFG->dataroot.'/lang/'.$lang) and 58 !file_exists($CFG->dirroot .'/lang/'.$lang)) { 59 $lang_el =& $mform->getElement('lang'); 60 $lang_el->setValue($CFG->lang); 61 } 62 } 63 64 if ($user = get_record('user', 'id', $userid)) { 65 66 // print picture 67 if (!empty($CFG->gdversion)) { 68 $image_el =& $mform->getElement('currentpicture'); 69 if ($user and $user->picture) { 70 $image_el->setValue(print_user_picture($user, SITEID, $user->picture, 64,true,false,'',true)); 71 } else { 72 $image_el->setValue(get_string('none')); 73 } 74 } 75 76 /// disable fields that are locked by auth plugins 77 $fields = get_user_fieldnames(); 78 $authplugin = get_auth_plugin($user->auth); 79 foreach ($fields as $field) { 80 if (!$mform->elementExists($field)) { 81 continue; 82 } 83 $configvariable = 'field_lock_' . $field; 84 if (isset($authplugin->config->{$configvariable})) { 85 if ($authplugin->config->{$configvariable} === 'locked') { 86 $mform->hardFreeze($field); 87 $mform->setConstant($field, $user->$field); 88 } else if ($authplugin->config->{$configvariable} === 'unlockedifempty' and $user->$field != '') { 89 $mform->hardFreeze($field); 90 $mform->setConstant($field, $user->$field); 91 } 92 } 93 } 94 95 } 96 97 /// Next the customisable profile fields 98 profile_definition_after_data($mform); 99 100 } 101 102 function validation($usernew, $files) { 103 global $CFG; 104 105 $errors = parent::validation($usernew, $files); 106 107 $usernew = (object)$usernew; 108 $user = get_record('user', 'id', $usernew->id); 109 110 // validate email 111 if (!validate_email($usernew->email)) { 112 $errors['email'] = get_string('invalidemail'); 113 } else if (($usernew->email !== $user->email) and record_exists('user', 'email', $usernew->email, 'mnethostid', $CFG->mnet_localhost_id)) { 114 $errors['email'] = get_string('emailexists'); 115 } 116 117 if ($usernew->email === $user->email and over_bounce_threshold($user)) { 118 $errors['email'] = get_string('toomanybounces'); 119 } 120 121 if (!empty($CFG->verifychangedemail) and !isset($errors['email']) and !has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) { 122 $errorstr = email_is_not_allowed($usernew->email); 123 if ($errorstr !== false) { 124 $errors['email'] = $errorstr; 125 } 126 } 127 128 /// Next the customisable profile fields 129 $errors += profile_validation($usernew, $files); 130 131 return $errors; 132 } 133 134 function get_um() { 135 return $this->_upload_manager; 136 } 137 } 138 139 ?>
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 |