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