Bumping version for 1.8.10 release (note new convention for numbering)
[moodle.git] / user / editlib.php
blobcb4e5d84e5f8fae07881f197a883f8479c93cfa6
1 <?php //$Id$
4 function cancel_email_update($userid) {
5 unset_user_preference('newemail', $userid);
6 unset_user_preference('newemailkey', $userid);
7 unset_user_preference('newemailattemptsleft', $userid);
10 function useredit_load_preferences(&$user, $reload=true) {
11 global $USER;
13 if (!empty($user->id)) {
14 if ($reload and $USER->id == $user->id) {
15 // reload preferences in case it was changed in other session
16 unset($USER->preference);
19 if ($preferences = get_user_preferences(null, null, $user->id)) {
20 foreach($preferences as $name=>$value) {
21 $user->{'preference_'.$name} = $value;
27 function useredit_update_user_preference($usernew) {
28 $ua = (array)$usernew;
29 foreach($ua as $key=>$value) {
30 if (strpos($key, 'preference_') === 0) {
31 $name = substr($key, strlen('preference_'));
32 set_user_preference($name, $value, $usernew->id);
37 function useredit_update_picture(&$usernew, &$userform) {
38 global $CFG;
40 if (isset($usernew->deletepicture) and $usernew->deletepicture) {
41 $location = make_user_directory($usernew->id, true);
42 @remove_dir($location);
43 set_field('user', 'picture', 0, 'id', $usernew->id);
44 } else if ($usernew->picture = save_profile_image($usernew->id, $userform->get_um(), 'user')) {
45 set_field('user', 'picture', 1, 'id', $usernew->id);
49 function useredit_update_bounces($user, $usernew) {
50 if (!isset($usernew->email)) {
51 //locked field
52 return;
54 if (!isset($user->email) || $user->email !== $usernew->email) {
55 set_bounce_count($usernew,true);
56 set_send_count($usernew,true);
60 function useredit_update_trackforums($user, $usernew) {
61 global $CFG;
62 if (!isset($usernew->trackforums)) {
63 //locked field
64 return;
66 if ((!isset($user->trackforums) || ($usernew->trackforums != $user->trackforums)) and !$usernew->trackforums) {
67 require_once($CFG->dirroot.'/mod/forum/lib.php');
68 forum_tp_delete_read_records($usernew->id);
72 function useredit_shared_definition(&$mform) {
73 global $CFG, $USER;
75 $user = get_record('user', 'id', $USER->id);
76 useredit_load_preferences($user, false);
78 $strrequired = get_string('required');
80 $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"');
81 $mform->addRule('firstname', $strrequired, 'required', null, 'client');
82 $mform->setType('firstname', PARAM_NOTAGS);
84 $mform->addElement('text', 'lastname', get_string('lastname'), 'maxlength="100" size="30"');
85 $mform->addRule('lastname', $strrequired, 'required', null, 'client');
86 $mform->setType('lastname', PARAM_NOTAGS);
88 // Do not show email field if change confirmation is pending
89 if ($CFG->emailchangeconfirmation && !empty($user->preference_newemail)) {
90 $notice = get_string('auth_emailchangepending', 'auth', $user);
91 $notice .= '<br /><a href="edit.php?cancelemailchange=1&amp;id='.$user->id.'">'
92 . get_string('auth_emailchangecancel', 'auth') . '</a>';
93 $mform->addElement('static', 'emailpending', get_string('email'), $notice);
94 } else {
95 $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="30"');
96 $mform->addRule('email', $strrequired, 'required', null, 'client');
100 $choices = array();
101 $choices['0'] = get_string('emaildisplayno');
102 $choices['1'] = get_string('emaildisplayyes');
103 $choices['2'] = get_string('emaildisplaycourse');
104 $mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices);
105 $mform->setDefault('maildisplay', 2);
107 $choices = array();
108 $choices['0'] = get_string('emailenable');
109 $choices['1'] = get_string('emaildisable');
110 $mform->addElement('select', 'emailstop', get_string('emailactive'), $choices);
111 $mform->setDefault('emailenable', 1);
113 $choices = array();
114 $choices['0'] = get_string('textformat');
115 $choices['1'] = get_string('htmlformat');
116 $mform->addElement('select', 'mailformat', get_string('emailformat'), $choices);
117 $mform->setDefault('mailformat', 1);
118 $mform->setAdvanced('mailformat');
120 if (!empty($CFG->allowusermailcharset)) {
121 $choices = array();
122 $charsets = get_list_of_charsets();
123 if (!empty($CFG->sitemailcharset)) {
124 $choices['0'] = get_string('site').' ('.$CFG->sitemailcharset.')';
125 } else {
126 $choices['0'] = get_string('site').' (UTF-8)';
128 $choices = array_merge($choices, $charsets);
129 $mform->addElement('select', 'preference_mailcharset', get_string('emailcharset'), $choices);
130 $mform->setAdvanced('preference_mailcharset');
133 $choices = array();
134 $choices['0'] = get_string('emaildigestoff');
135 $choices['1'] = get_string('emaildigestcomplete');
136 $choices['2'] = get_string('emaildigestsubjects');
137 $mform->addElement('select', 'maildigest', get_string('emaildigest'), $choices);
138 $mform->setDefault('maildigest', 0);
139 $mform->setAdvanced('maildigest');
141 $choices = array();
142 $choices['1'] = get_string('autosubscribeyes');
143 $choices['0'] = get_string('autosubscribeno');
144 $mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices);
145 $mform->setDefault('autosubscribe', 1);
146 $mform->setAdvanced('autosubscribe');
148 if (!empty($CFG->forum_trackreadposts)) {
149 $choices = array();
150 $choices['0'] = get_string('trackforumsno');
151 $choices['1'] = get_string('trackforumsyes');
152 $mform->addElement('select', 'trackforums', get_string('trackforums'), $choices);
153 $mform->setDefault('trackforums', 0);
154 $mform->setAdvanced('trackforums');
157 if ($CFG->htmleditor) {
158 $choices = array();
159 $choices['0'] = get_string('texteditor');
160 $choices['1'] = get_string('htmleditor');
161 $mform->addElement('select', 'htmleditor', get_string('textediting'), $choices);
162 $mform->setDefault('htmleditor', 1);
163 $mform->setAdvanced('htmleditor');
166 if (empty($CFG->enableajax)) {
167 $mform->addElement('static', 'ajaxdisabled', get_string('ajaxuse'), get_string('ajaxno'));
168 $mform->setAdvanced('ajaxdisabled');
169 } else {
170 $choices = array();
171 $choices['0'] = get_string('ajaxno');
172 $choices['1'] = get_string('ajaxyes');
173 $mform->addElement('select', 'ajax', get_string('ajaxuse'), $choices);
174 $mform->setDefault('ajax', 0);
175 $mform->setAdvanced('ajax');
178 $choices = array();
179 $choices['0'] = get_string('screenreaderno');
180 $choices['1'] = get_string('screenreaderyes');
181 $mform->addElement('select', 'screenreader', get_string('screenreaderuse'), $choices);
182 $mform->setDefault('screenreader', 0);
183 $mform->setAdvanced('screenreader');
185 $mform->addElement('text', 'city', get_string('city'), 'maxlength="100" size="25"');
186 $mform->setType('city', PARAM_MULTILANG);
187 $mform->addRule('city', $strrequired, 'required', null, 'client');
190 $choices = get_list_of_countries();
191 $choices= array(''=>get_string('selectacountry').'...') + $choices;
192 $mform->addElement('select', 'country', get_string('selectacountry'), $choices);
193 $mform->addRule('country', $strrequired, 'required', null, 'client');
194 if (!empty($CFG->country)) {
195 $mform->setDefault('country', $CFG->country);
198 $choices = get_list_of_timezones();
199 $choices['99'] = get_string('serverlocaltime');
200 if ($CFG->forcetimezone != 99) {
201 $mform->addElement('static', 'forcedtimezone', get_string('timezone'), $choices[$CFG->forcetimezone]);
202 } else {
203 $mform->addElement('select', 'timezone', get_string('timezone'), $choices);
204 $mform->setDefault('timezone', '99');
207 $mform->addElement('select', 'lang', get_string('preferredlanguage'), get_list_of_languages());
208 $mform->setDefault('lang', $CFG->lang);
210 if (!empty($CFG->allowuserthemes)) {
211 $choices = array();
212 $choices[''] = get_string('default');
213 $choices += get_list_of_themes();
214 $mform->addElement('select', 'theme', get_string('preferredtheme'), $choices);
215 $mform->setAdvanced('theme');
218 $mform->addElement('htmleditor', 'description', get_string('userdescription'));
219 $mform->setType('description', PARAM_CLEAN);
220 $mform->setHelpButton('description', array('text', get_string('helptext')));
222 if (!empty($CFG->gdversion)) {
223 $mform->addElement('header', 'moodle_picture', get_string('pictureof'));//TODO: Accessibility fix fieldset legend
225 $mform->addElement('static', 'currentpicture', get_string('currentpicture'));
227 $mform->addElement('checkbox', 'deletepicture', get_string('delete'));
228 $mform->setDefault('deletepicture',false);
230 $mform->addElement('file', 'imagefile', get_string('newpicture'));
231 $mform->setHelpButton('imagefile', array('picture', get_string('helppicture')));
233 $mform->addElement('text', 'imagealt', get_string('imagealt'), 'maxlength="100" size="30"');
234 $mform->setType('imagealt', PARAM_MULTILANG);
238 /// Moodle optional fields
239 $mform->addElement('header', 'moodle_optional', get_string('optional', 'form'));
240 $mform->setAdvanced('moodle_optional');
242 $mform->addElement('text', 'url', get_string('webpage'), 'maxlength="255" size="50"');
243 $mform->setType('url', PARAM_URL);
245 $mform->addElement('text', 'icq', get_string('icqnumber'), 'maxlength="15" size="25"');
246 $mform->setType('icq', PARAM_CLEAN);
248 $mform->addElement('text', 'skype', get_string('skypeid'), 'maxlength="50" size="25"');
249 $mform->setType('skype', PARAM_CLEAN);
251 $mform->addElement('text', 'aim', get_string('aimid'), 'maxlength="50" size="25"');
252 $mform->setType('aim', PARAM_CLEAN);
254 $mform->addElement('text', 'yahoo', get_string('yahooid'), 'maxlength="50" size="25"');
255 $mform->setType('yahoo', PARAM_CLEAN);
257 $mform->addElement('text', 'msn', get_string('msnid'), 'maxlength="50" size="25"');
258 $mform->setType('msn', PARAM_CLEAN);
260 $mform->addElement('text', 'idnumber', get_string('idnumber'), 'maxlength="64" size="25"');
261 $mform->setType('idnumber', PARAM_CLEAN);
263 $mform->addElement('text', 'institution', get_string('institution'), 'maxlength="40" size="25"');
264 $mform->setType('institution', PARAM_MULTILANG);
266 $mform->addElement('text', 'department', get_string('department'), 'maxlength="30" size="25"');
267 $mform->setType('department', PARAM_MULTILANG);
269 $mform->addElement('text', 'phone1', get_string('phone'), 'maxlength="20" size="25"');
270 $mform->setType('phone1', PARAM_CLEAN);
272 $mform->addElement('text', 'phone2', get_string('phone'), 'maxlength="20" size="25"');
273 $mform->setType('phone2', PARAM_CLEAN);
275 $mform->addElement('text', 'address', get_string('address'), 'maxlength="70" size="25"');
276 $mform->setType('address', PARAM_MULTILANG);