MDL-8096 - user edit form splitting, refactoring, cleanup and fixing - work in progre...
[moodle.git] / user / editadvanced_form.php
1 <?php //$Id$
3 require_once($CFG->dirroot.'/lib/formslib.php');
4 require_once($CFG->dirroot.'/user/profile/lib.php');
6 class user_editadvanced_form extends moodleform {
8     // Define the form
9     function definition () {
10         global $USER, $CFG;
12         $mform =& $this->_form;
13         $course = $this->_customdata;
14         $this->set_upload_manager(new upload_manager('imagefile', false, false, null, false, 0, true, true, false));
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', $strrequired);
24         $mform->addElement('text', 'username', get_string('username'), 'size="20"');
25         $mform->addRule('username', $strrequired, 'required', null, 'client');
26         $mform->setType('username', PARAM_RAW);
28         $modules = get_list_of_plugins('auth');
29         $auth_options = array();
30         foreach ($modules as $module) {
31             $auth_options[$module] = get_string("auth_$module"."title", "auth");
32         }
33         $mform->addElement('select', 'auth', get_string('chooseauthmethod','auth'), $auth_options);
34         $mform->setHelpButton('auth', array('authchange', get_string('chooseauthmethod','auth')));
35         $mform->setAdvanced('auth');
37         $mform->addElement('text', 'newpassword', get_string('newpassword'), 'size="20"');
38         $mform->setType('newpassword', PARAM_RAW);
39         //TODO: add missing help - empty means no change
41         $mform->addElement('checkbox', 'preference_auth_forcepasswordchange', get_string('forcepasswordchange'));
42         //TODO: add missing help - user will be forced to change password
44         require('edit_form_common.php');
46         $this->add_action_buttons(false, get_string('updatemyprofile'));
47     }
49     function definition_after_data() {
50         global $USER, $CFG;
52         $mform =& $this->_form;
53         $user = get_record('user', 'id', $mform->getElementValue('id'));
55         if ($user) {
57             // user can not change own auth method
58             if ($user->id == $USER->id) {
59                 $mform->hardFreeze('auth');
60                 $mform->hardFreeze('preference_auth_forcepasswordchange');
61             }
62         }
64         // admin must choose some password and supply correct email
65         if (!empty($USER->newadminuser)) {
66             $mform->addRule('newpassword', get_string('required'), 'required', null, 'client');
68             $email = $mform->getElement('email');
69             if ($email->getValue() == 'root@localhost') {
70                 $email->setValue('');
71             }
72         }
74         if (!empty($CFG->gdversion)) {
75             $image = $mform->getElement('currentpicture');
76             if ($user) {
77                 $image->setValue(print_user_picture($user->id, SITEID, $user->picture, 64, true, false, '', true));
78             } else {
79                 $image->setValue(print_user_picture(0, SITEID, 0, 64, true, false, '', true));
80             }
81         }
82     }
84     function get_um() {
85         return $this->_upload_manager;
86     }
87 }
89 ?>