Added LinuxChix theme
[moodle-linuxchix.git] / user / edit_form.php
blob9f96fd902aebadfae40a24f404d590dbc82e4edb
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 // print picture
60 if (!empty($CFG->gdversion)) {
61 $image_el =& $mform->getElement('currentpicture');
62 if ($user and $user->picture) {
63 $image_el->setValue(print_user_picture($user, SITEID, $user->picture, 64,true,false,'',true));
64 } else {
65 $image_el->setValue(get_string('none'));
69 /// disable fields that are locked by auth plugins
70 $fields = get_user_fieldnames();
71 $freezefields = array();
72 $authplugin = get_auth_plugin($user->auth);
73 foreach ($fields as $field) {
74 if (!$mform->elementExists($field)) {
75 continue;
77 $configvariable = 'field_lock_' . $field;
78 if (isset($authplugin->config->{$configvariable})) {
79 if ($authplugin->config->{$configvariable} === 'locked') {
80 $freezefields[] = $field;
81 } else if ($authplugin->config->{$configvariable} === 'unlockedifempty' and $user->$field != '') {
82 $freezefields[] = $field;
86 $mform->hardFreeze($freezefields);
89 /// Next the customisable profile fields
90 profile_definition_after_data($mform);
94 function validation($usernew, $files) {
95 global $CFG;
97 $errors = parent::validation($usernew, $files);
99 $usernew = (object)$usernew;
100 $user = get_record('user', 'id', $usernew->id);
102 // validate email
103 if (!validate_email($usernew->email)) {
104 $errors['email'] = get_string('invalidemail');
105 } else if (($usernew->email !== $user->email) and record_exists('user', 'email', $usernew->email, 'mnethostid', $CFG->mnet_localhost_id)) {
106 $errors['email'] = get_string('emailexists');
109 if ($usernew->email === $user->email and over_bounce_threshold($user)) {
110 $errors['email'] = get_string('toomanybounces');
113 /// Next the customisable profile fields
114 $errors += profile_validation($usernew, $files);
116 return $errors;
119 function get_um() {
120 return $this->_upload_manager;