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) { |
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 | |
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 | |
57 | function useredit_shared_definition(&$mform) { |
58 | global $CFG; |
59 | |
60 | $strrequired = get_string('required'); |
d8734783 |
61 | |
baacc970 |
62 | $nameordercheck->firstname = 'a'; |
63 | $nameordercheck->lastname = 'b'; |
64 | if (fullname($nameordercheck) == 'b a' ) { // See MDL-4325 |
65 | $mform->addElement('text', 'lastname', get_string('lastname'), 'maxlength="100" size="30"'); |
66 | $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"'); |
67 | } else { |
68 | $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"'); |
69 | $mform->addElement('text', 'lastname', get_string('lastname'), 'maxlength="100" size="30"'); |
70 | } |
71 | |
d8734783 |
72 | $mform->addRule('firstname', $strrequired, 'required', null, 'client'); |
73 | $mform->setType('firstname', PARAM_NOTAGS); |
74 | |
d8734783 |
75 | $mform->addRule('lastname', $strrequired, 'required', null, 'client'); |
76 | $mform->setType('lastname', PARAM_NOTAGS); |
77 | |
78 | $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="30"'); |
79 | $mform->addRule('email', $strrequired, 'required', null, 'client'); |
80 | |
81 | $choices = array(); |
82 | $choices['0'] = get_string('emaildisplayno'); |
83 | $choices['1'] = get_string('emaildisplayyes'); |
84 | $choices['2'] = get_string('emaildisplaycourse'); |
85 | $mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices); |
e61f8701 |
86 | $mform->setDefault('maildisplay', 2); |
d8734783 |
87 | |
88 | $choices = array(); |
89 | $choices['0'] = get_string('emailenable'); |
90 | $choices['1'] = get_string('emaildisable'); |
91 | $mform->addElement('select', 'emailstop', get_string('emailactive'), $choices); |
92 | $mform->setDefault('emailenable', 1); |
93 | |
94 | $choices = array(); |
95 | $choices['0'] = get_string('textformat'); |
96 | $choices['1'] = get_string('htmlformat'); |
97 | $mform->addElement('select', 'mailformat', get_string('emailformat'), $choices); |
98 | $mform->setDefault('mailformat', 1); |
99 | $mform->setAdvanced('mailformat'); |
100 | |
101 | if (!empty($CFG->allowusermailcharset)) { |
ad6226fb |
102 | $choices = array(); |
d8734783 |
103 | $charsets = get_list_of_charsets(); |
104 | if (!empty($CFG->sitemailcharset)) { |
105 | $choices['0'] = get_string('site').' ('.$CFG->sitemailcharset.')'; |
106 | } else { |
9152fc99 |
107 | $choices['0'] = get_string('site').' (UTF-8)'; |
ad6226fb |
108 | } |
d8734783 |
109 | $choices = array_merge($choices, $charsets); |
110 | $mform->addElement('select', 'preference_mailcharset', get_string('emailcharset'), $choices); |
111 | $mform->setAdvanced('preference_mailcharset'); |
112 | } |
113 | |
114 | $choices = array(); |
115 | $choices['0'] = get_string('emaildigestoff'); |
116 | $choices['1'] = get_string('emaildigestcomplete'); |
117 | $choices['2'] = get_string('emaildigestsubjects'); |
118 | $mform->addElement('select', 'maildigest', get_string('emaildigest'), $choices); |
119 | $mform->setDefault('maildigest', 0); |
120 | $mform->setAdvanced('maildigest'); |
121 | |
122 | $choices = array(); |
123 | $choices['1'] = get_string('autosubscribeyes'); |
124 | $choices['0'] = get_string('autosubscribeno'); |
125 | $mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices); |
e61f8701 |
126 | $mform->setDefault('autosubscribe', 1); |
d8734783 |
127 | $mform->setAdvanced('autosubscribe'); |
128 | |
129 | if (!empty($CFG->forum_trackreadposts)) { |
ad6226fb |
130 | $choices = array(); |
d8734783 |
131 | $choices['0'] = get_string('trackforumsno'); |
132 | $choices['1'] = get_string('trackforumsyes'); |
133 | $mform->addElement('select', 'trackforums', get_string('trackforums'), $choices); |
134 | $mform->setDefault('trackforums', 0); |
135 | $mform->setAdvanced('trackforums'); |
136 | } |
137 | |
138 | if ($CFG->htmleditor) { |
ad6226fb |
139 | $choices = array(); |
d8734783 |
140 | $choices['0'] = get_string('texteditor'); |
141 | $choices['1'] = get_string('htmleditor'); |
142 | $mform->addElement('select', 'htmleditor', get_string('textediting'), $choices); |
143 | $mform->setDefault('htmleditor', 1); |
144 | $mform->setAdvanced('htmleditor'); |
145 | } |
146 | |
147 | if (empty($CFG->enableajax)) { |
148 | $mform->addElement('static', 'ajaxdisabled', get_string('ajaxuse'), get_string('ajaxno')); |
149 | $mform->setAdvanced('ajaxdisabled'); |
150 | } else { |
ad6226fb |
151 | $choices = array(); |
d8734783 |
152 | $choices['0'] = get_string('ajaxno'); |
153 | $choices['1'] = get_string('ajaxyes'); |
154 | $mform->addElement('select', 'ajax', get_string('ajaxuse'), $choices); |
155 | $mform->setDefault('ajax', 0); |
156 | $mform->setAdvanced('ajax'); |
157 | } |
158 | |
159 | $choices = array(); |
160 | $choices['0'] = get_string('screenreaderno'); |
161 | $choices['1'] = get_string('screenreaderyes'); |
162 | $mform->addElement('select', 'screenreader', get_string('screenreaderuse'), $choices); |
163 | $mform->setDefault('screenreader', 0); |
164 | $mform->setAdvanced('screenreader'); |
165 | |
166 | $mform->addElement('text', 'city', get_string('city'), 'maxlength="100" size="25"'); |
167 | $mform->setType('city', PARAM_MULTILANG); |
168 | $mform->addRule('city', $strrequired, 'required', null, 'client'); |
169 | |
170 | |
171 | $choices = get_list_of_countries(); |
172 | $choices= array(''=>get_string('selectacountry').'...') + $choices; |
173 | $mform->addElement('select', 'country', get_string('selectacountry'), $choices); |
174 | $mform->addRule('country', $strrequired, 'required', null, 'client'); |
175 | if (!empty($CFG->country)) { |
176 | $mform->setDefault('country', $CFG->country); |
177 | } |
178 | |
179 | $choices = get_list_of_timezones(); |
180 | $choices['99'] = get_string('serverlocaltime'); |
181 | if ($CFG->forcetimezone != 99) { |
182 | $mform->addElement('static', 'forcedtimezone', get_string('timezone'), $choices[$CFG->forcetimezone]); |
183 | } else { |
184 | $mform->addElement('select', 'timezone', get_string('timezone'), $choices); |
185 | $mform->setDefault('timezone', '99'); |
186 | } |
187 | |
ca80f999 |
188 | $mform->addElement('select', 'lang', get_string('preferredlanguage'), get_list_of_languages()); |
189 | $mform->setDefault('lang', $CFG->lang); |
d8734783 |
190 | |
191 | if (!empty($CFG->allowuserthemes)) { |
ad6226fb |
192 | $choices = array(); |
d8734783 |
193 | $choices[''] = get_string('default'); |
194 | $choices += get_list_of_themes(); |
195 | $mform->addElement('select', 'theme', get_string('preferredtheme'), $choices); |
196 | $mform->setAdvanced('theme'); |
197 | } |
ad6226fb |
198 | |
d8734783 |
199 | $mform->addElement('htmleditor', 'description', get_string('userdescription')); |
200 | $mform->setType('description', PARAM_CLEAN); |
201 | $mform->setHelpButton('description', array('text', get_string('helptext'))); |
ad6226fb |
202 | |
d8734783 |
203 | if (!empty($CFG->gdversion)) { |
204 | $mform->addElement('header', 'moodle_picture', get_string('pictureof'));//TODO: Accessibility fix fieldset legend |
ad6226fb |
205 | |
d8734783 |
206 | $mform->addElement('static', 'currentpicture', get_string('currentpicture')); |
ad6226fb |
207 | |
d8734783 |
208 | $mform->addElement('checkbox', 'deletepicture', get_string('delete')); |
209 | $mform->setDefault('deletepicture',false); |
ad6226fb |
210 | |
d8734783 |
211 | $mform->addElement('file', 'imagefile', get_string('newpicture')); |
212 | $mform->setHelpButton('imagefile', array('picture', get_string('helppicture'))); |
ad6226fb |
213 | |
d8734783 |
214 | $mform->addElement('text', 'imagealt', get_string('imagealt'), 'maxlength="100" size="30"'); |
215 | $mform->setType('imagealt', PARAM_MULTILANG); |
ad6226fb |
216 | |
d8734783 |
217 | } |
ad6226fb |
218 | |
d8734783 |
219 | /// Moodle optional fields |
220 | $mform->addElement('header', 'moodle_optional', get_string('optional', 'form')); |
221 | $mform->setAdvanced('moodle_optional'); |
ad6226fb |
222 | |
d8734783 |
223 | $mform->addElement('text', 'url', get_string('webpage'), 'maxlength="255" size="50"'); |
224 | $mform->setType('url', PARAM_URL); |
ad6226fb |
225 | |
d8734783 |
226 | $mform->addElement('text', 'icq', get_string('icqnumber'), 'maxlength="15" size="25"'); |
227 | $mform->setType('icq', PARAM_CLEAN); |
ad6226fb |
228 | |
d8734783 |
229 | $mform->addElement('text', 'skype', get_string('skypeid'), 'maxlength="50" size="25"'); |
230 | $mform->setType('skype', PARAM_CLEAN); |
ad6226fb |
231 | |
d8734783 |
232 | $mform->addElement('text', 'aim', get_string('aimid'), 'maxlength="50" size="25"'); |
233 | $mform->setType('aim', PARAM_CLEAN); |
ad6226fb |
234 | |
d8734783 |
235 | $mform->addElement('text', 'yahoo', get_string('yahooid'), 'maxlength="50" size="25"'); |
236 | $mform->setType('yahoo', PARAM_CLEAN); |
ad6226fb |
237 | |
d8734783 |
238 | $mform->addElement('text', 'msn', get_string('msnid'), 'maxlength="50" size="25"'); |
239 | $mform->setType('msn', PARAM_CLEAN); |
ad6226fb |
240 | |
d8734783 |
241 | $mform->addElement('text', 'idnumber', get_string('idnumber'), 'maxlength="64" size="25"'); |
9e7cd813 |
242 | $mform->setType('idnumber', PARAM_CLEAN); |
ad6226fb |
243 | |
d8734783 |
244 | $mform->addElement('text', 'institution', get_string('institution'), 'maxlength="40" size="25"'); |
245 | $mform->setType('institution', PARAM_MULTILANG); |
ad6226fb |
246 | |
d8734783 |
247 | $mform->addElement('text', 'department', get_string('department'), 'maxlength="30" size="25"'); |
248 | $mform->setType('department', PARAM_MULTILANG); |
ad6226fb |
249 | |
d8734783 |
250 | $mform->addElement('text', 'phone1', get_string('phone'), 'maxlength="20" size="25"'); |
251 | $mform->setType('phone1', PARAM_CLEAN); |
ad6226fb |
252 | |
d8734783 |
253 | $mform->addElement('text', 'phone2', get_string('phone'), 'maxlength="20" size="25"'); |
254 | $mform->setType('phone2', PARAM_CLEAN); |
ad6226fb |
255 | |
d8734783 |
256 | $mform->addElement('text', 'address', get_string('address'), 'maxlength="70" size="25"'); |
257 | $mform->setType('address', PARAM_MULTILANG); |
14a6b7e1 |
258 | } |
ad6226fb |
259 | |
baacc970 |
260 | ?> |