Commit | Line | Data |
---|---|---|
8bdc9cac | 1 | <?php |
ad6226fb | 2 | |
05c38e2b | 3 | function cancel_email_update($userid) { |
4 | unset_user_preference('newemail', $userid); | |
5 | unset_user_preference('newemailkey', $userid); | |
6 | unset_user_preference('newemailattemptsleft', $userid); | |
7 | } | |
8 | ||
9 | function useredit_load_preferences(&$user, $reload=true) { | |
10 | global $USER; | |
14a6b7e1 | 11 | |
05c38e2b | 12 | if (!empty($user->id)) { |
13 | if ($reload and $USER->id == $user->id) { | |
14 | // reload preferences in case it was changed in other session | |
15 | unset($USER->preference); | |
16 | } | |
aa6c1ced | 17 | |
05c38e2b | 18 | if ($preferences = get_user_preferences(null, null, $user->id)) { |
19 | foreach($preferences as $name=>$value) { | |
20 | $user->{'preference_'.$name} = $value; | |
21 | } | |
14a6b7e1 | 22 | } |
23 | } | |
24 | } | |
25 | ||
26 | function useredit_update_user_preference($usernew) { | |
27 | $ua = (array)$usernew; | |
28 | foreach($ua as $key=>$value) { | |
29 | if (strpos($key, 'preference_') === 0) { | |
30 | $name = substr($key, strlen('preference_')); | |
31 | set_user_preference($name, $value, $usernew->id); | |
32 | } | |
33 | } | |
34 | } | |
35 | ||
172dd12c | 36 | function useredit_update_picture(&$usernew, $userform) { |
a5d424df | 37 | global $CFG, $DB; |
9d85247d | 38 | |
14a6b7e1 | 39 | if (isset($usernew->deletepicture) and $usernew->deletepicture) { |
56a1a882 | 40 | $location = make_user_directory($usernew->id, true); |
9d85247d | 41 | @remove_dir($location); |
a5d424df | 42 | $DB->set_field('user', 'picture', 0, array('id'=>$usernew->id)); |
172dd12c | 43 | |
44 | } else if ($userform->get_new_filename('imagefile')) { | |
45 | $usernew->picture = (int)save_profile_image($usernew->id, $userform, 'user', 'imagefile'); | |
46 | $DB->set_field('user', 'picture', $usernew->picture, array('id'=>$usernew->id)); | |
14a6b7e1 | 47 | } |
48 | } | |
49 | ||
50 | function useredit_update_bounces($user, $usernew) { | |
51 | if (!isset($usernew->email)) { | |
52 | //locked field | |
53 | return; | |
d8734783 | 54 | } |
a9457b54 | 55 | if (!isset($user->email) || $user->email !== $usernew->email) { |
14a6b7e1 | 56 | set_bounce_count($usernew,true); |
57 | set_send_count($usernew,true); | |
58 | } | |
59 | } | |
60 | ||
61 | function useredit_update_trackforums($user, $usernew) { | |
62 | global $CFG; | |
63 | if (!isset($usernew->trackforums)) { | |
64 | //locked field | |
65 | return; | |
66 | } | |
a9457b54 | 67 | if ((!isset($user->trackforums) || ($usernew->trackforums != $user->trackforums)) and !$usernew->trackforums) { |
14a6b7e1 | 68 | require_once($CFG->dirroot.'/mod/forum/lib.php'); |
69 | forum_tp_delete_read_records($usernew->id); | |
70 | } | |
71 | } | |
72 | ||
c060fc6a | 73 | function useredit_update_interests($user, $interests) { |
74 | tag_set('user', $user->id, $interests); | |
1e1c51a3 | 75 | } |
76 | ||
8bdc9cac | 77 | function useredit_shared_definition(&$mform, $editoroptions = null) { |
d6ace123 | 78 | global $CFG, $USER, $DB; |
79 | ||
80 | $user = $DB->get_record('user', array('id' => $USER->id)); | |
05c38e2b | 81 | useredit_load_preferences($user, false); |
14a6b7e1 | 82 | |
83 | $strrequired = get_string('required'); | |
d8734783 | 84 | |
c1658cc5 | 85 | $nameordercheck = new object(); |
baacc970 | 86 | $nameordercheck->firstname = 'a'; |
87 | $nameordercheck->lastname = 'b'; | |
88 | if (fullname($nameordercheck) == 'b a' ) { // See MDL-4325 | |
89 | $mform->addElement('text', 'lastname', get_string('lastname'), 'maxlength="100" size="30"'); | |
90 | $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"'); | |
91 | } else { | |
92 | $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"'); | |
93 | $mform->addElement('text', 'lastname', get_string('lastname'), 'maxlength="100" size="30"'); | |
94 | } | |
95 | ||
d8734783 | 96 | $mform->addRule('firstname', $strrequired, 'required', null, 'client'); |
97 | $mform->setType('firstname', PARAM_NOTAGS); | |
98 | ||
d8734783 | 99 | $mform->addRule('lastname', $strrequired, 'required', null, 'client'); |
100 | $mform->setType('lastname', PARAM_NOTAGS); | |
101 | ||
d6ace123 | 102 | // Do not show email field if change confirmation is pending |
775f811a | 103 | if (!empty($CFG->emailchangeconfirmation) and !empty($user->preference_newemail)) { |
2b06294b | 104 | $notice = get_string('auth_emailchangepending', 'auth_email', $user); |
d6ace123 | 105 | $notice .= '<br /><a href="edit.php?cancelemailchange=1&id='.$user->id.'">' |
2b06294b | 106 | . get_string('auth_emailchangecancel', 'auth_email') . '</a>'; |
d6ace123 | 107 | $mform->addElement('static', 'emailpending', get_string('email'), $notice); |
108 | } else { | |
109 | $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="30"'); | |
110 | $mform->addRule('email', $strrequired, 'required', null, 'client'); | |
111 | } | |
d8734783 | 112 | |
113 | $choices = array(); | |
114 | $choices['0'] = get_string('emaildisplayno'); | |
115 | $choices['1'] = get_string('emaildisplayyes'); | |
116 | $choices['2'] = get_string('emaildisplaycourse'); | |
117 | $mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices); | |
e61f8701 | 118 | $mform->setDefault('maildisplay', 2); |
d8734783 | 119 | |
120 | $choices = array(); | |
121 | $choices['0'] = get_string('emailenable'); | |
122 | $choices['1'] = get_string('emaildisable'); | |
123 | $mform->addElement('select', 'emailstop', get_string('emailactive'), $choices); | |
ecdf8d2e | 124 | $mform->setDefault('emailstop', 0); |
d8734783 | 125 | |
126 | $choices = array(); | |
127 | $choices['0'] = get_string('textformat'); | |
128 | $choices['1'] = get_string('htmlformat'); | |
129 | $mform->addElement('select', 'mailformat', get_string('emailformat'), $choices); | |
130 | $mform->setDefault('mailformat', 1); | |
131 | $mform->setAdvanced('mailformat'); | |
132 | ||
133 | if (!empty($CFG->allowusermailcharset)) { | |
ad6226fb | 134 | $choices = array(); |
d8734783 | 135 | $charsets = get_list_of_charsets(); |
136 | if (!empty($CFG->sitemailcharset)) { | |
137 | $choices['0'] = get_string('site').' ('.$CFG->sitemailcharset.')'; | |
138 | } else { | |
9152fc99 | 139 | $choices['0'] = get_string('site').' (UTF-8)'; |
ad6226fb | 140 | } |
d8734783 | 141 | $choices = array_merge($choices, $charsets); |
142 | $mform->addElement('select', 'preference_mailcharset', get_string('emailcharset'), $choices); | |
143 | $mform->setAdvanced('preference_mailcharset'); | |
144 | } | |
145 | ||
146 | $choices = array(); | |
147 | $choices['0'] = get_string('emaildigestoff'); | |
148 | $choices['1'] = get_string('emaildigestcomplete'); | |
149 | $choices['2'] = get_string('emaildigestsubjects'); | |
150 | $mform->addElement('select', 'maildigest', get_string('emaildigest'), $choices); | |
151 | $mform->setDefault('maildigest', 0); | |
152 | $mform->setAdvanced('maildigest'); | |
153 | ||
154 | $choices = array(); | |
155 | $choices['1'] = get_string('autosubscribeyes'); | |
156 | $choices['0'] = get_string('autosubscribeno'); | |
157 | $mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices); | |
e61f8701 | 158 | $mform->setDefault('autosubscribe', 1); |
d8734783 | 159 | $mform->setAdvanced('autosubscribe'); |
160 | ||
161 | if (!empty($CFG->forum_trackreadposts)) { | |
ad6226fb | 162 | $choices = array(); |
d8734783 | 163 | $choices['0'] = get_string('trackforumsno'); |
164 | $choices['1'] = get_string('trackforumsyes'); | |
165 | $mform->addElement('select', 'trackforums', get_string('trackforums'), $choices); | |
166 | $mform->setDefault('trackforums', 0); | |
167 | $mform->setAdvanced('trackforums'); | |
168 | } | |
5ca3c838 | 169 | /* TODO: reimplement editor preferences |
775f811a | 170 | if (!empty($CFG->htmleditor)) { |
ad6226fb | 171 | $choices = array(); |
d8734783 | 172 | $choices['0'] = get_string('texteditor'); |
173 | $choices['1'] = get_string('htmleditor'); | |
174 | $mform->addElement('select', 'htmleditor', get_string('textediting'), $choices); | |
175 | $mform->setDefault('htmleditor', 1); | |
176 | $mform->setAdvanced('htmleditor'); | |
177 | } | |
5ca3c838 | 178 | */ |
d8734783 | 179 | if (empty($CFG->enableajax)) { |
180 | $mform->addElement('static', 'ajaxdisabled', get_string('ajaxuse'), get_string('ajaxno')); | |
181 | $mform->setAdvanced('ajaxdisabled'); | |
182 | } else { | |
ad6226fb | 183 | $choices = array(); |
d8734783 | 184 | $choices['0'] = get_string('ajaxno'); |
185 | $choices['1'] = get_string('ajaxyes'); | |
186 | $mform->addElement('select', 'ajax', get_string('ajaxuse'), $choices); | |
187 | $mform->setDefault('ajax', 0); | |
188 | $mform->setAdvanced('ajax'); | |
189 | } | |
190 | ||
191 | $choices = array(); | |
192 | $choices['0'] = get_string('screenreaderno'); | |
193 | $choices['1'] = get_string('screenreaderyes'); | |
194 | $mform->addElement('select', 'screenreader', get_string('screenreaderuse'), $choices); | |
195 | $mform->setDefault('screenreader', 0); | |
196 | $mform->setAdvanced('screenreader'); | |
197 | ||
a1df2e98 | 198 | $mform->addElement('text', 'city', get_string('city'), 'maxlength="20" size="21"'); |
d8734783 | 199 | $mform->setType('city', PARAM_MULTILANG); |
200 | $mform->addRule('city', $strrequired, 'required', null, 'client'); | |
201 | ||
202 | ||
0aa759b0 | 203 | $choices = get_string_manager()->get_list_of_countries(); |
d8734783 | 204 | $choices= array(''=>get_string('selectacountry').'...') + $choices; |
205 | $mform->addElement('select', 'country', get_string('selectacountry'), $choices); | |
206 | $mform->addRule('country', $strrequired, 'required', null, 'client'); | |
207 | if (!empty($CFG->country)) { | |
208 | $mform->setDefault('country', $CFG->country); | |
209 | } | |
210 | ||
211 | $choices = get_list_of_timezones(); | |
212 | $choices['99'] = get_string('serverlocaltime'); | |
213 | if ($CFG->forcetimezone != 99) { | |
214 | $mform->addElement('static', 'forcedtimezone', get_string('timezone'), $choices[$CFG->forcetimezone]); | |
215 | } else { | |
216 | $mform->addElement('select', 'timezone', get_string('timezone'), $choices); | |
217 | $mform->setDefault('timezone', '99'); | |
218 | } | |
219 | ||
1f96e907 | 220 | $mform->addElement('select', 'lang', get_string('preferredlanguage'), get_string_manager()->get_list_of_translations()); |
ca80f999 | 221 | $mform->setDefault('lang', $CFG->lang); |
d8734783 | 222 | |
223 | if (!empty($CFG->allowuserthemes)) { | |
ad6226fb | 224 | $choices = array(); |
d8734783 | 225 | $choices[''] = get_string('default'); |
226 | $choices += get_list_of_themes(); | |
227 | $mform->addElement('select', 'theme', get_string('preferredtheme'), $choices); | |
228 | $mform->setAdvanced('theme'); | |
229 | } | |
ad6226fb | 230 | |
8bdc9cac SH |
231 | $mform->addElement('editor', 'description_editor', get_string('userdescription'), null, $editoroptions); |
232 | $mform->setType('description_editor', PARAM_CLEANHTML); | |
233 | $mform->setHelpButton('description_editor', array('text2', get_string('helptext'))); | |
ad6226fb | 234 | |
d8734783 | 235 | if (!empty($CFG->gdversion)) { |
236 | $mform->addElement('header', 'moodle_picture', get_string('pictureof'));//TODO: Accessibility fix fieldset legend | |
ad6226fb | 237 | |
d8734783 | 238 | $mform->addElement('static', 'currentpicture', get_string('currentpicture')); |
ad6226fb | 239 | |
d8734783 | 240 | $mform->addElement('checkbox', 'deletepicture', get_string('delete')); |
241 | $mform->setDefault('deletepicture',false); | |
ad6226fb | 242 | |
d8734783 | 243 | $mform->addElement('file', 'imagefile', get_string('newpicture')); |
244 | $mform->setHelpButton('imagefile', array('picture', get_string('helppicture'))); | |
ad6226fb | 245 | |
d8734783 | 246 | $mform->addElement('text', 'imagealt', get_string('imagealt'), 'maxlength="100" size="30"'); |
247 | $mform->setType('imagealt', PARAM_MULTILANG); | |
ad6226fb | 248 | |
d8734783 | 249 | } |
ad6226fb | 250 | |
c060fc6a | 251 | if (!empty($CFG->usetags)) { |
1e1c51a3 | 252 | $mform->addElement('header', 'moodle_interests', get_string('interests')); |
c060fc6a | 253 | $mform->addElement('tags', 'interests', get_string('interestslist'), array('display' => 'noofficial')); |
254 | $mform->setHelpButton('interests', array('interestslist', get_string('helpinterestslist'), false, true, false)); | |
1e1c51a3 | 255 | } |
d6ace123 | 256 | |
d8734783 | 257 | /// Moodle optional fields |
258 | $mform->addElement('header', 'moodle_optional', get_string('optional', 'form')); | |
259 | $mform->setAdvanced('moodle_optional'); | |
ad6226fb | 260 | |
d8734783 | 261 | $mform->addElement('text', 'url', get_string('webpage'), 'maxlength="255" size="50"'); |
262 | $mform->setType('url', PARAM_URL); | |
ad6226fb | 263 | |
d8734783 | 264 | $mform->addElement('text', 'icq', get_string('icqnumber'), 'maxlength="15" size="25"'); |
265 | $mform->setType('icq', PARAM_CLEAN); | |
ad6226fb | 266 | |
d8734783 | 267 | $mform->addElement('text', 'skype', get_string('skypeid'), 'maxlength="50" size="25"'); |
268 | $mform->setType('skype', PARAM_CLEAN); | |
ad6226fb | 269 | |
d8734783 | 270 | $mform->addElement('text', 'aim', get_string('aimid'), 'maxlength="50" size="25"'); |
271 | $mform->setType('aim', PARAM_CLEAN); | |
ad6226fb | 272 | |
d8734783 | 273 | $mform->addElement('text', 'yahoo', get_string('yahooid'), 'maxlength="50" size="25"'); |
274 | $mform->setType('yahoo', PARAM_CLEAN); | |
ad6226fb | 275 | |
d8734783 | 276 | $mform->addElement('text', 'msn', get_string('msnid'), 'maxlength="50" size="25"'); |
277 | $mform->setType('msn', PARAM_CLEAN); | |
ad6226fb | 278 | |
8b9cfac4 | 279 | $mform->addElement('text', 'idnumber', get_string('idnumber'), 'maxlength="255" size="25"'); |
9e7cd813 | 280 | $mform->setType('idnumber', PARAM_CLEAN); |
ad6226fb | 281 | |
d8734783 | 282 | $mform->addElement('text', 'institution', get_string('institution'), 'maxlength="40" size="25"'); |
283 | $mform->setType('institution', PARAM_MULTILANG); | |
ad6226fb | 284 | |
d8734783 | 285 | $mform->addElement('text', 'department', get_string('department'), 'maxlength="30" size="25"'); |
286 | $mform->setType('department', PARAM_MULTILANG); | |
ad6226fb | 287 | |
d8734783 | 288 | $mform->addElement('text', 'phone1', get_string('phone'), 'maxlength="20" size="25"'); |
289 | $mform->setType('phone1', PARAM_CLEAN); | |
ad6226fb | 290 | |
55ac3d6f | 291 | $mform->addElement('text', 'phone2', get_string('phone2'), 'maxlength="20" size="25"'); |
d8734783 | 292 | $mform->setType('phone2', PARAM_CLEAN); |
ad6226fb | 293 | |
d8734783 | 294 | $mform->addElement('text', 'address', get_string('address'), 'maxlength="70" size="25"'); |
295 | $mform->setType('address', PARAM_MULTILANG); | |
d6ace123 | 296 | |
297 | ||
14a6b7e1 | 298 | } |
ad6226fb | 299 | |
aa6c1ced | 300 |