Bumping version for 1.8.10 release (note new convention for numbering)
[moodle.git] / user / edit_form.php
blob085c5a80f4d66f0b0dccd07898dfa6e04e67ad5f
1 <?php //$Id$
3 require_once($CFG->dirroot.'/lib/formslib.php');
5 class user_edit_form extends moodleform {
7 // Define the form
8 function definition () {
9 global $CFG, $COURSE;
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');
17 /// Add some extra hidden fields
18 $mform->addElement('hidden', 'id');
19 $mform->addElement('hidden', 'course', $COURSE->id);
21 /// Print the required moodle fields first
22 $mform->addElement('header', 'moodle', $strgeneral);
24 /// shared fields
25 useredit_shared_definition($mform);
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');
35 /// Next the customisable profile fields
36 profile_definition($mform);
38 $this->add_action_buttons(false, get_string('updatemyprofile'));
41 function definition_after_data() {
42 global $CFG;
44 $mform =& $this->_form;
45 $userid = $mform->getElementValue('id');
47 // if language does not exist, use site default lang
48 if ($langsel = $mform->getElementValue('lang')) {
49 $lang = reset($langsel);
50 if (!file_exists($CFG->dataroot.'/lang/'.$lang) and
51 !file_exists($CFG->dirroot .'/lang/'.$lang)) {
52 $lang_el =& $mform->getElement('lang');
53 $lang_el->setValue($CFG->lang);
57 if ($user = get_record('user', 'id', $userid)) {
59 // remove description - this must be here because
60 if (empty($user->description) && !empty($CFG->profilesforenrolledusersonly) && !record_exists('role_assignments', 'userid', $user->id)) {
61 if ($mform->elementExists('description')) {
62 $mform->removeElement('description');
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->id, SITEID, $user->picture, 64,true,false,'',true));
71 } else {
72 $image_el->setValue(get_string('none'));
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;
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);
95 /// Next the customisable profile fields
96 profile_definition_after_data($mform, $user->id);
98 } else {
99 profile_definition_after_data($mform, 0);
103 function validation ($usernew) {
104 global $CFG;
106 $usernew = (object)$usernew;
107 $user = get_record('user', 'id', $usernew->id);
108 $err = array();
110 // validate email
111 if (!validate_email($usernew->email)) {
112 $err['email'] = get_string('invalidemail');
113 } else if ((stripslashes($usernew->email) !== $user->email) and record_exists('user', 'email', $usernew->email, 'mnethostid', $CFG->mnet_localhost_id)) {
114 $err['email'] = get_string('emailexists');
117 if ($usernew->email === $user->email and over_bounce_threshold($user)) {
118 $err['email'] = get_string('toomanybounces');
121 /// Next the customisable profile fields
122 $err += profile_validation($usernew);
124 if (count($err) == 0){
125 return true;
126 } else {
127 return $err;
131 function get_um() {
132 return $this->_upload_manager;