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