Fixed a bug in external package validation
[moodle.git] / user / editadvanced_form.php
CommitLineData
ad6226fb 1<?php //$Id$
2
3require_once($CFG->dirroot.'/lib/formslib.php');
4require_once($CFG->dirroot.'/user/profile/lib.php');
5
6class user_editadvanced_form extends moodleform {
7
8 // Define the form
9 function definition () {
10 global $USER, $CFG;
11
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');
16
17 /// Add some extra hidden fields
18 $mform->addElement('hidden', 'id');
19 $mform->addElement('hidden', 'course', $course->id);
20
21 /// Print the required moodle fields first
22 $mform->addElement('header', 'moodle', $strrequired);
23
24 $mform->addElement('text', 'username', get_string('username'), 'size="20"');
25 $mform->addRule('username', $strrequired, 'required', null, 'client');
26 $mform->setType('username', PARAM_RAW);
27
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');
36
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
40
41 $mform->addElement('checkbox', 'preference_auth_forcepasswordchange', get_string('forcepasswordchange'));
42 //TODO: add missing help - user will be forced to change password
43
44 require('edit_form_common.php');
45
46 $this->add_action_buttons(false, get_string('updatemyprofile'));
47 }
48
49 function definition_after_data() {
50 global $USER, $CFG;
51
52 $mform =& $this->_form;
53 $user = get_record('user', 'id', $mform->getElementValue('id'));
54
55 if ($user) {
56
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 }
63
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');
67
68 $email = $mform->getElement('email');
69 if ($email->getValue() == 'root@localhost') {
70 $email->setValue('');
71 }
72 }
73
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 }
83
84 function get_um() {
85 return $this->_upload_manager;
86 }
87}
88
89?>