Added hooks to qtype import/export
[moodle-linuxchix.git] / user / edit_form.php
blob3b0794b4d9c6267d1c70c37a528216f89c37e77e
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 $strrequired = get_string('required');
15 /// Add some extra hidden fields
16 $mform->addElement('hidden', 'id');
17 $mform->addElement('hidden', 'course', $COURSE->id);
19 /// Print the required moodle fields first
20 $mform->addElement('header', 'moodle', $strrequired);
22 /// shared fields
23 useredit_shared_definition($mform);
25 /// extra settigs
26 $mform->addRule('description', $strrequired, 'required', null, 'client');
27 if (!empty($CFG->gdversion) and !empty($CFG->disableuserimages)) {
28 $mform->removeElement('deletepicture');
29 $mform->removeElement('imagefile');
30 $mform->removeElement('imagealt');
33 /// Next the customisable profile fields
34 profile_definition($mform);
36 $this->add_action_buttons(false, get_string('updatemyprofile'));
39 function definition_after_data() {
40 global $CFG;
42 $mform =& $this->_form;
43 $userid = $mform->getElementValue('id');
45 // if language does not exist, use site default lang
46 if ($langsel = $mform->getElementValue('lang')) {
47 $lang = reset($langsel);
48 if (!file_exists($CFG->dataroot.'/lang/'.$lang) and
49 !file_exists($CFG->dirroot .'/lang/'.$lang)) {
50 $lang_el =& $mform->getElement('lang');
51 $lang_el->setValue($CFG->lang);
55 if ($user = get_record('user', 'id', $userid)) {
57 // print picture
58 if (!empty($CFG->gdversion)) {
59 $image_el =& $mform->getElement('currentpicture');
60 if ($user and $user->picture) {
61 $image_el->setValue(print_user_picture($user->id, SITEID, $user->picture, 64,true,false,'',true));
62 } else {
63 $image_el->setValue(get_string('none'));
67 /// disable fields that are locked by auth plugins
68 $fields = get_user_fieldnames();
69 $freezefields = array();
70 $authplugin = get_auth_plugin($user->auth);
71 foreach ($fields as $field) {
72 if (!$mform->elementExists($field)) {
73 continue;
75 $configvariable = 'field_lock_' . $field;
76 if (isset($authplugin->config->{$configvariable})) {
77 if ($authplugin->config->{$configvariable} === 'locked') {
78 $freezefields[] = $field;
79 } else if ($authplugin->config->{$configvariable} === 'unlockedifempty' and $user->$field != '') {
80 $freezefields[] = $field;
84 $mform->hardFreeze($freezefields);
87 /// Next the customisable profile fields
88 profile_definition_after_data($mform);
92 function validation ($usernew) {
93 global $CFG;
95 $usernew = (object)$usernew;
96 $user = get_record('user', 'id', $usernew->id);
97 $err = array();
99 // validate email
100 if (!validate_email($usernew->email)) {
101 $err['email'] = get_string('invalidemail');
102 } else if (($usernew->email !== $user->email) and record_exists('user', 'email', $usernew->email, 'mnethostid', $CFG->mnet_localhost_id)) {
103 $err['email'] = get_string('emailexists');
106 if ($usernew->email === $user->email and over_bounce_threshold($user)) {
107 $err['email'] = get_string('toomanybounces');
110 /// Next the customisable profile fields
111 $err += profile_validation($usernew);
113 if (count($err) == 0){
114 return true;
115 } else {
116 return $err;
120 function get_um() {
121 return $this->_upload_manager;