ad6226fb |
1 | <?php //$Id$ |
2 | |
14a6b7e1 |
3 | |
4 | function 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 | |
12 | function 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 | |
22 | function useredit_update_picture(&$usernew, &$userform) { |
a5d424df |
23 | global $CFG, $DB; |
9d85247d |
24 | |
14a6b7e1 |
25 | if (isset($usernew->deletepicture) and $usernew->deletepicture) { |
56a1a882 |
26 | $location = make_user_directory($usernew->id, true); |
9d85247d |
27 | @remove_dir($location); |
a5d424df |
28 | $DB->set_field('user', 'picture', 0, array('id'=>$usernew->id)); |
56a1a882 |
29 | } else if ($usernew->picture = save_profile_image($usernew->id, $userform->get_um(), 'user')) { |
a5d424df |
30 | $DB->set_field('user', 'picture', 1, array('id'=>$usernew->id)); |
14a6b7e1 |
31 | } |
32 | } |
33 | |
34 | function 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 | |
45 | function 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 | |
3d535996 |
57 | function useredit_update_interests($user, $csv_tag_names) { |
58 | tag_set('user', $user->id, explode(',', $csv_tag_names)); |
1e1c51a3 |
59 | } |
60 | |
14a6b7e1 |
61 | function useredit_shared_definition(&$mform) { |
d6ace123 |
62 | global $CFG, $USER, $DB; |
63 | |
64 | $user = $DB->get_record('user', array('id' => $USER->id)); |
65 | useredit_load_preferences($user); |
14a6b7e1 |
66 | |
67 | $strrequired = get_string('required'); |
d8734783 |
68 | |
c1658cc5 |
69 | $nameordercheck = new object(); |
baacc970 |
70 | $nameordercheck->firstname = 'a'; |
71 | $nameordercheck->lastname = 'b'; |
72 | if (fullname($nameordercheck) == 'b a' ) { // See MDL-4325 |
73 | $mform->addElement('text', 'lastname', get_string('lastname'), 'maxlength="100" size="30"'); |
74 | $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"'); |
75 | } else { |
76 | $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"'); |
77 | $mform->addElement('text', 'lastname', get_string('lastname'), 'maxlength="100" size="30"'); |
78 | } |
79 | |
d8734783 |
80 | $mform->addRule('firstname', $strrequired, 'required', null, 'client'); |
81 | $mform->setType('firstname', PARAM_NOTAGS); |
82 | |
d8734783 |
83 | $mform->addRule('lastname', $strrequired, 'required', null, 'client'); |
84 | $mform->setType('lastname', PARAM_NOTAGS); |
85 | |
d6ace123 |
86 | // Do not show email field if change confirmation is pending |
87 | if ($CFG->emailchangeconfirmation && !empty($user->preference_newemail)) { |
88 | $notice = get_string('auth_emailchangepending', 'auth', $user); |
89 | $notice .= '<br /><a href="edit.php?cancelemailchange=1&id='.$user->id.'">' |
90 | . get_string('auth_emailchangecancel', 'auth') . '</a>'; |
91 | $mform->addElement('static', 'emailpending', get_string('email'), $notice); |
92 | } else { |
93 | $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="30"'); |
94 | $mform->addRule('email', $strrequired, 'required', null, 'client'); |
95 | } |
d8734783 |
96 | |
97 | $choices = array(); |
98 | $choices['0'] = get_string('emaildisplayno'); |
99 | $choices['1'] = get_string('emaildisplayyes'); |
100 | $choices['2'] = get_string('emaildisplaycourse'); |
101 | $mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices); |
e61f8701 |
102 | $mform->setDefault('maildisplay', 2); |
d8734783 |
103 | |
104 | $choices = array(); |
105 | $choices['0'] = get_string('emailenable'); |
106 | $choices['1'] = get_string('emaildisable'); |
107 | $mform->addElement('select', 'emailstop', get_string('emailactive'), $choices); |
ecdf8d2e |
108 | $mform->setDefault('emailstop', 0); |
d8734783 |
109 | |
110 | $choices = array(); |
111 | $choices['0'] = get_string('textformat'); |
112 | $choices['1'] = get_string('htmlformat'); |
113 | $mform->addElement('select', 'mailformat', get_string('emailformat'), $choices); |
114 | $mform->setDefault('mailformat', 1); |
115 | $mform->setAdvanced('mailformat'); |
116 | |
117 | if (!empty($CFG->allowusermailcharset)) { |
ad6226fb |
118 | $choices = array(); |
d8734783 |
119 | $charsets = get_list_of_charsets(); |
120 | if (!empty($CFG->sitemailcharset)) { |
121 | $choices['0'] = get_string('site').' ('.$CFG->sitemailcharset.')'; |
122 | } else { |
9152fc99 |
123 | $choices['0'] = get_string('site').' (UTF-8)'; |
ad6226fb |
124 | } |
d8734783 |
125 | $choices = array_merge($choices, $charsets); |
126 | $mform->addElement('select', 'preference_mailcharset', get_string('emailcharset'), $choices); |
127 | $mform->setAdvanced('preference_mailcharset'); |
128 | } |
129 | |
130 | $choices = array(); |
131 | $choices['0'] = get_string('emaildigestoff'); |
132 | $choices['1'] = get_string('emaildigestcomplete'); |
133 | $choices['2'] = get_string('emaildigestsubjects'); |
134 | $mform->addElement('select', 'maildigest', get_string('emaildigest'), $choices); |
135 | $mform->setDefault('maildigest', 0); |
136 | $mform->setAdvanced('maildigest'); |
137 | |
138 | $choices = array(); |
139 | $choices['1'] = get_string('autosubscribeyes'); |
140 | $choices['0'] = get_string('autosubscribeno'); |
141 | $mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices); |
e61f8701 |
142 | $mform->setDefault('autosubscribe', 1); |
d8734783 |
143 | $mform->setAdvanced('autosubscribe'); |
144 | |
145 | if (!empty($CFG->forum_trackreadposts)) { |
ad6226fb |
146 | $choices = array(); |
d8734783 |
147 | $choices['0'] = get_string('trackforumsno'); |
148 | $choices['1'] = get_string('trackforumsyes'); |
149 | $mform->addElement('select', 'trackforums', get_string('trackforums'), $choices); |
150 | $mform->setDefault('trackforums', 0); |
151 | $mform->setAdvanced('trackforums'); |
152 | } |
153 | |
154 | if ($CFG->htmleditor) { |
ad6226fb |
155 | $choices = array(); |
d8734783 |
156 | $choices['0'] = get_string('texteditor'); |
157 | $choices['1'] = get_string('htmleditor'); |
158 | $mform->addElement('select', 'htmleditor', get_string('textediting'), $choices); |
159 | $mform->setDefault('htmleditor', 1); |
160 | $mform->setAdvanced('htmleditor'); |
161 | } |
162 | |
163 | if (empty($CFG->enableajax)) { |
164 | $mform->addElement('static', 'ajaxdisabled', get_string('ajaxuse'), get_string('ajaxno')); |
165 | $mform->setAdvanced('ajaxdisabled'); |
166 | } else { |
ad6226fb |
167 | $choices = array(); |
d8734783 |
168 | $choices['0'] = get_string('ajaxno'); |
169 | $choices['1'] = get_string('ajaxyes'); |
170 | $mform->addElement('select', 'ajax', get_string('ajaxuse'), $choices); |
171 | $mform->setDefault('ajax', 0); |
172 | $mform->setAdvanced('ajax'); |
173 | } |
174 | |
175 | $choices = array(); |
176 | $choices['0'] = get_string('screenreaderno'); |
177 | $choices['1'] = get_string('screenreaderyes'); |
178 | $mform->addElement('select', 'screenreader', get_string('screenreaderuse'), $choices); |
179 | $mform->setDefault('screenreader', 0); |
180 | $mform->setAdvanced('screenreader'); |
181 | |
a1df2e98 |
182 | $mform->addElement('text', 'city', get_string('city'), 'maxlength="20" size="21"'); |
d8734783 |
183 | $mform->setType('city', PARAM_MULTILANG); |
184 | $mform->addRule('city', $strrequired, 'required', null, 'client'); |
185 | |
186 | |
187 | $choices = get_list_of_countries(); |
188 | $choices= array(''=>get_string('selectacountry').'...') + $choices; |
189 | $mform->addElement('select', 'country', get_string('selectacountry'), $choices); |
190 | $mform->addRule('country', $strrequired, 'required', null, 'client'); |
191 | if (!empty($CFG->country)) { |
192 | $mform->setDefault('country', $CFG->country); |
193 | } |
194 | |
195 | $choices = get_list_of_timezones(); |
196 | $choices['99'] = get_string('serverlocaltime'); |
197 | if ($CFG->forcetimezone != 99) { |
198 | $mform->addElement('static', 'forcedtimezone', get_string('timezone'), $choices[$CFG->forcetimezone]); |
199 | } else { |
200 | $mform->addElement('select', 'timezone', get_string('timezone'), $choices); |
201 | $mform->setDefault('timezone', '99'); |
202 | } |
203 | |
ca80f999 |
204 | $mform->addElement('select', 'lang', get_string('preferredlanguage'), get_list_of_languages()); |
205 | $mform->setDefault('lang', $CFG->lang); |
d8734783 |
206 | |
207 | if (!empty($CFG->allowuserthemes)) { |
ad6226fb |
208 | $choices = array(); |
d8734783 |
209 | $choices[''] = get_string('default'); |
210 | $choices += get_list_of_themes(); |
211 | $mform->addElement('select', 'theme', get_string('preferredtheme'), $choices); |
212 | $mform->setAdvanced('theme'); |
213 | } |
ad6226fb |
214 | |
d8734783 |
215 | $mform->addElement('htmleditor', 'description', get_string('userdescription')); |
216 | $mform->setType('description', PARAM_CLEAN); |
217 | $mform->setHelpButton('description', array('text', get_string('helptext'))); |
ad6226fb |
218 | |
d8734783 |
219 | if (!empty($CFG->gdversion)) { |
220 | $mform->addElement('header', 'moodle_picture', get_string('pictureof'));//TODO: Accessibility fix fieldset legend |
ad6226fb |
221 | |
d8734783 |
222 | $mform->addElement('static', 'currentpicture', get_string('currentpicture')); |
ad6226fb |
223 | |
d8734783 |
224 | $mform->addElement('checkbox', 'deletepicture', get_string('delete')); |
225 | $mform->setDefault('deletepicture',false); |
ad6226fb |
226 | |
d8734783 |
227 | $mform->addElement('file', 'imagefile', get_string('newpicture')); |
228 | $mform->setHelpButton('imagefile', array('picture', get_string('helppicture'))); |
ad6226fb |
229 | |
d8734783 |
230 | $mform->addElement('text', 'imagealt', get_string('imagealt'), 'maxlength="100" size="30"'); |
231 | $mform->setType('imagealt', PARAM_MULTILANG); |
ad6226fb |
232 | |
d8734783 |
233 | } |
ad6226fb |
234 | |
f5488402 |
235 | if ( !empty($CFG->usetags) && has_capability('moodle/tag:create', get_context_instance(CONTEXT_SYSTEM)) ) { |
1e1c51a3 |
236 | $mform->addElement('header', 'moodle_interests', get_string('interests')); |
1c54b2bb |
237 | $mform->addElement('textarea', 'interests', get_string('interestslist'), 'cols="45" rows="3"'); |
ab50ec12 |
238 | $mform->setHelpButton('interests', array('interestslist', get_string('helpinterestslist'), |
d6ace123 |
239 | false, true, false)); |
1e1c51a3 |
240 | } |
d6ace123 |
241 | |
d8734783 |
242 | /// Moodle optional fields |
243 | $mform->addElement('header', 'moodle_optional', get_string('optional', 'form')); |
244 | $mform->setAdvanced('moodle_optional'); |
ad6226fb |
245 | |
d8734783 |
246 | $mform->addElement('text', 'url', get_string('webpage'), 'maxlength="255" size="50"'); |
247 | $mform->setType('url', PARAM_URL); |
ad6226fb |
248 | |
d8734783 |
249 | $mform->addElement('text', 'icq', get_string('icqnumber'), 'maxlength="15" size="25"'); |
250 | $mform->setType('icq', PARAM_CLEAN); |
ad6226fb |
251 | |
d8734783 |
252 | $mform->addElement('text', 'skype', get_string('skypeid'), 'maxlength="50" size="25"'); |
253 | $mform->setType('skype', PARAM_CLEAN); |
ad6226fb |
254 | |
d8734783 |
255 | $mform->addElement('text', 'aim', get_string('aimid'), 'maxlength="50" size="25"'); |
256 | $mform->setType('aim', PARAM_CLEAN); |
ad6226fb |
257 | |
d8734783 |
258 | $mform->addElement('text', 'yahoo', get_string('yahooid'), 'maxlength="50" size="25"'); |
259 | $mform->setType('yahoo', PARAM_CLEAN); |
ad6226fb |
260 | |
d8734783 |
261 | $mform->addElement('text', 'msn', get_string('msnid'), 'maxlength="50" size="25"'); |
262 | $mform->setType('msn', PARAM_CLEAN); |
ad6226fb |
263 | |
8b9cfac4 |
264 | $mform->addElement('text', 'idnumber', get_string('idnumber'), 'maxlength="255" size="25"'); |
9e7cd813 |
265 | $mform->setType('idnumber', PARAM_CLEAN); |
ad6226fb |
266 | |
d8734783 |
267 | $mform->addElement('text', 'institution', get_string('institution'), 'maxlength="40" size="25"'); |
268 | $mform->setType('institution', PARAM_MULTILANG); |
ad6226fb |
269 | |
d8734783 |
270 | $mform->addElement('text', 'department', get_string('department'), 'maxlength="30" size="25"'); |
271 | $mform->setType('department', PARAM_MULTILANG); |
ad6226fb |
272 | |
d8734783 |
273 | $mform->addElement('text', 'phone1', get_string('phone'), 'maxlength="20" size="25"'); |
274 | $mform->setType('phone1', PARAM_CLEAN); |
ad6226fb |
275 | |
55ac3d6f |
276 | $mform->addElement('text', 'phone2', get_string('phone2'), 'maxlength="20" size="25"'); |
d8734783 |
277 | $mform->setType('phone2', PARAM_CLEAN); |
ad6226fb |
278 | |
d8734783 |
279 | $mform->addElement('text', 'address', get_string('address'), 'maxlength="70" size="25"'); |
280 | $mform->setType('address', PARAM_MULTILANG); |
d6ace123 |
281 | |
282 | |
14a6b7e1 |
283 | } |
ad6226fb |
284 | |
baacc970 |
285 | ?> |