[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Form to edit a users profile 19 * 20 * @copyright 1999 Martin Dougiamas http://dougiamas.com 21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 * @package core_user 23 */ 24 25 if (!defined('MOODLE_INTERNAL')) { 26 die('Direct access to this script is forbidden.'); // It must be included from a Moodle page. 27 } 28 29 require_once($CFG->dirroot.'/lib/formslib.php'); 30 31 /** 32 * Class user_edit_form. 33 * 34 * @copyright 1999 Martin Dougiamas http://dougiamas.com 35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 36 */ 37 class user_edit_form extends moodleform { 38 39 /** 40 * Define the form. 41 */ 42 public function definition () { 43 global $CFG, $COURSE, $USER; 44 45 $mform = $this->_form; 46 $editoroptions = null; 47 $filemanageroptions = null; 48 $userid = $USER->id; 49 50 if (is_array($this->_customdata)) { 51 if (array_key_exists('editoroptions', $this->_customdata)) { 52 $editoroptions = $this->_customdata['editoroptions']; 53 } 54 if (array_key_exists('filemanageroptions', $this->_customdata)) { 55 $filemanageroptions = $this->_customdata['filemanageroptions']; 56 } 57 if (array_key_exists('userid', $this->_customdata)) { 58 $userid = $this->_customdata['userid']; 59 } 60 } 61 // Accessibility: "Required" is bad legend text. 62 $strgeneral = get_string('general'); 63 $strrequired = get_string('required'); 64 65 // Add some extra hidden fields. 66 $mform->addElement('hidden', 'id'); 67 $mform->setType('id', PARAM_INT); 68 $mform->addElement('hidden', 'course', $COURSE->id); 69 $mform->setType('course', PARAM_INT); 70 71 // Print the required moodle fields first. 72 $mform->addElement('header', 'moodle', $strgeneral); 73 74 // Shared fields. 75 useredit_shared_definition($mform, $editoroptions, $filemanageroptions); 76 77 // Extra settigs. 78 if (!empty($CFG->disableuserimages)) { 79 $mform->removeElement('deletepicture'); 80 $mform->removeElement('imagefile'); 81 $mform->removeElement('imagealt'); 82 } 83 84 // Next the customisable profile fields. 85 profile_definition($mform, $userid); 86 87 $this->add_action_buttons(false, get_string('updatemyprofile')); 88 } 89 90 /** 91 * Extend the form definition after the data has been parsed. 92 */ 93 public function definition_after_data() { 94 global $CFG, $DB, $OUTPUT; 95 96 $mform = $this->_form; 97 $userid = $mform->getElementValue('id'); 98 99 // If language does not exist, use site default lang. 100 if ($langsel = $mform->getElementValue('lang')) { 101 $lang = reset($langsel); 102 // Check lang exists. 103 if (!get_string_manager()->translation_exists($lang, false)) { 104 $langel =& $mform->getElement('lang'); 105 $langel->setValue($CFG->lang); 106 } 107 } 108 109 if ($user = $DB->get_record('user', array('id' => $userid))) { 110 111 // Remove description. 112 if (empty($user->description) && !empty($CFG->profilesforenrolledusersonly) && !$DB->record_exists('role_assignments', array('userid' => $userid))) { 113 $mform->removeElement('description_editor'); 114 } 115 116 // Print picture. 117 $context = context_user::instance($user->id, MUST_EXIST); 118 $fs = get_file_storage(); 119 $hasuploadedpicture = ($fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.png') || $fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.jpg')); 120 if (!empty($user->picture) && $hasuploadedpicture) { 121 $imagevalue = $OUTPUT->user_picture($user, array('courseid' => SITEID, 'size' => 64)); 122 } else { 123 $imagevalue = get_string('none'); 124 } 125 $imageelement = $mform->getElement('currentpicture'); 126 $imageelement->setValue($imagevalue); 127 128 if ($mform->elementExists('deletepicture') && !$hasuploadedpicture) { 129 $mform->removeElement('deletepicture'); 130 } 131 132 // Disable fields that are locked by auth plugins. 133 $fields = get_user_fieldnames(); 134 $authplugin = get_auth_plugin($user->auth); 135 foreach ($fields as $field) { 136 if (!$mform->elementExists($field)) { 137 continue; 138 } 139 $configvariable = 'field_lock_' . $field; 140 if (isset($authplugin->config->{$configvariable})) { 141 if ($authplugin->config->{$configvariable} === 'locked') { 142 $mform->hardFreeze($field); 143 $mform->setConstant($field, $user->$field); 144 } else if ($authplugin->config->{$configvariable} === 'unlockedifempty' and $user->$field != '') { 145 $mform->hardFreeze($field); 146 $mform->setConstant($field, $user->$field); 147 } 148 } 149 } 150 151 // Next the customisable profile fields. 152 profile_definition_after_data($mform, $user->id); 153 154 } else { 155 profile_definition_after_data($mform, 0); 156 } 157 } 158 159 /** 160 * Validate incoming form data. 161 * @param array $usernew 162 * @param array $files 163 * @return array 164 */ 165 public function validation($usernew, $files) { 166 global $CFG, $DB; 167 168 $errors = parent::validation($usernew, $files); 169 170 $usernew = (object)$usernew; 171 $user = $DB->get_record('user', array('id' => $usernew->id)); 172 173 // Validate email. 174 if (!isset($usernew->email)) { 175 // Mail not confirmed yet. 176 } else if (!validate_email($usernew->email)) { 177 $errors['email'] = get_string('invalidemail'); 178 } else if (($usernew->email !== $user->email) and $DB->record_exists('user', array('email' => $usernew->email, 'mnethostid' => $CFG->mnet_localhost_id))) { 179 $errors['email'] = get_string('emailexists'); 180 } 181 182 if (isset($usernew->email) and $usernew->email === $user->email and over_bounce_threshold($user)) { 183 $errors['email'] = get_string('toomanybounces'); 184 } 185 186 if (isset($usernew->email) and !empty($CFG->verifychangedemail) and !isset($errors['email']) and !has_capability('moodle/user:update', context_system::instance())) { 187 $errorstr = email_is_not_allowed($usernew->email); 188 if ($errorstr !== false) { 189 $errors['email'] = $errorstr; 190 } 191 } 192 193 // Next the customisable profile fields. 194 $errors += profile_validation($usernew, $files); 195 196 return $errors; 197 } 198 } 199 200
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |