Oracle doesn't like ; at the end of execute_sql()
[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) {
23 if (isset($usernew->deletepicture) and $usernew->deletepicture) {
24 //TODO - delete the file
25 set_field('user', 'picture', 0, 'id', $usernew->id);
26 } else if ($usernew->picture = save_profile_image($usernew->id, $userform->get_um(), 'users')) {
27 set_field('user', 'picture', 1, 'id', $usernew->id);
28 }
29}
30
31function useredit_update_bounces($user, $usernew) {
32 if (!isset($usernew->email)) {
33 //locked field
34 return;
d8734783 35 }
14a6b7e1 36 if ($user->email !== $usernew->email) {
37 set_bounce_count($usernew,true);
38 set_send_count($usernew,true);
39 }
40}
41
42function useredit_update_trackforums($user, $usernew) {
43 global $CFG;
44 if (!isset($usernew->trackforums)) {
45 //locked field
46 return;
47 }
48 if (($usernew->trackforums != $user->trackforums) and !$usernew->trackforums) {
49 require_once($CFG->dirroot.'/mod/forum/lib.php');
50 forum_tp_delete_read_records($usernew->id);
51 }
52}
53
54function useredit_shared_definition(&$mform) {
55 global $CFG;
56
57 $strrequired = get_string('required');
d8734783 58
59 $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"');
60 $mform->addRule('firstname', $strrequired, 'required', null, 'client');
61 $mform->setType('firstname', PARAM_NOTAGS);
62
63 $mform->addElement('text', 'lastname', get_string('lastname'), 'maxlength="100" size="30"');
64 $mform->addRule('lastname', $strrequired, 'required', null, 'client');
65 $mform->setType('lastname', PARAM_NOTAGS);
66
67 $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="30"');
68 $mform->addRule('email', $strrequired, 'required', null, 'client');
69
70 $choices = array();
71 $choices['0'] = get_string('emaildisplayno');
72 $choices['1'] = get_string('emaildisplayyes');
73 $choices['2'] = get_string('emaildisplaycourse');
74 $mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices);
e61f8701 75 $mform->setDefault('maildisplay', 2);
d8734783 76
77 $choices = array();
78 $choices['0'] = get_string('emailenable');
79 $choices['1'] = get_string('emaildisable');
80 $mform->addElement('select', 'emailstop', get_string('emailactive'), $choices);
81 $mform->setDefault('emailenable', 1);
82
83 $choices = array();
84 $choices['0'] = get_string('textformat');
85 $choices['1'] = get_string('htmlformat');
86 $mform->addElement('select', 'mailformat', get_string('emailformat'), $choices);
87 $mform->setDefault('mailformat', 1);
88 $mform->setAdvanced('mailformat');
89
90 if (!empty($CFG->allowusermailcharset)) {
ad6226fb 91 $choices = array();
d8734783 92 $charsets = get_list_of_charsets();
93 if (!empty($CFG->sitemailcharset)) {
94 $choices['0'] = get_string('site').' ('.$CFG->sitemailcharset.')';
95 } else {
96 $choices['0'] = get_string('site').' ('.current_charset().')';
ad6226fb 97 }
d8734783 98 $choices = array_merge($choices, $charsets);
99 $mform->addElement('select', 'preference_mailcharset', get_string('emailcharset'), $choices);
100 $mform->setAdvanced('preference_mailcharset');
101 }
102
103 $choices = array();
104 $choices['0'] = get_string('emaildigestoff');
105 $choices['1'] = get_string('emaildigestcomplete');
106 $choices['2'] = get_string('emaildigestsubjects');
107 $mform->addElement('select', 'maildigest', get_string('emaildigest'), $choices);
108 $mform->setDefault('maildigest', 0);
109 $mform->setAdvanced('maildigest');
110
111 $choices = array();
112 $choices['1'] = get_string('autosubscribeyes');
113 $choices['0'] = get_string('autosubscribeno');
114 $mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices);
e61f8701 115 $mform->setDefault('autosubscribe', 1);
d8734783 116 $mform->setAdvanced('autosubscribe');
117
118 if (!empty($CFG->forum_trackreadposts)) {
ad6226fb 119 $choices = array();
d8734783 120 $choices['0'] = get_string('trackforumsno');
121 $choices['1'] = get_string('trackforumsyes');
122 $mform->addElement('select', 'trackforums', get_string('trackforums'), $choices);
123 $mform->setDefault('trackforums', 0);
124 $mform->setAdvanced('trackforums');
125 }
126
127 if ($CFG->htmleditor) {
ad6226fb 128 $choices = array();
d8734783 129 $choices['0'] = get_string('texteditor');
130 $choices['1'] = get_string('htmleditor');
131 $mform->addElement('select', 'htmleditor', get_string('textediting'), $choices);
132 $mform->setDefault('htmleditor', 1);
133 $mform->setAdvanced('htmleditor');
134 }
135
136 if (empty($CFG->enableajax)) {
137 $mform->addElement('static', 'ajaxdisabled', get_string('ajaxuse'), get_string('ajaxno'));
138 $mform->setAdvanced('ajaxdisabled');
139 } else {
ad6226fb 140 $choices = array();
d8734783 141 $choices['0'] = get_string('ajaxno');
142 $choices['1'] = get_string('ajaxyes');
143 $mform->addElement('select', 'ajax', get_string('ajaxuse'), $choices);
144 $mform->setDefault('ajax', 0);
145 $mform->setAdvanced('ajax');
146 }
147
148 $choices = array();
149 $choices['0'] = get_string('screenreaderno');
150 $choices['1'] = get_string('screenreaderyes');
151 $mform->addElement('select', 'screenreader', get_string('screenreaderuse'), $choices);
152 $mform->setDefault('screenreader', 0);
153 $mform->setAdvanced('screenreader');
154
155 $mform->addElement('text', 'city', get_string('city'), 'maxlength="100" size="25"');
156 $mform->setType('city', PARAM_MULTILANG);
157 $mform->addRule('city', $strrequired, 'required', null, 'client');
158
159
160 $choices = get_list_of_countries();
161 $choices= array(''=>get_string('selectacountry').'...') + $choices;
162 $mform->addElement('select', 'country', get_string('selectacountry'), $choices);
163 $mform->addRule('country', $strrequired, 'required', null, 'client');
164 if (!empty($CFG->country)) {
165 $mform->setDefault('country', $CFG->country);
166 }
167
168 $choices = get_list_of_timezones();
169 $choices['99'] = get_string('serverlocaltime');
170 if ($CFG->forcetimezone != 99) {
171 $mform->addElement('static', 'forcedtimezone', get_string('timezone'), $choices[$CFG->forcetimezone]);
172 } else {
173 $mform->addElement('select', 'timezone', get_string('timezone'), $choices);
174 $mform->setDefault('timezone', '99');
175 }
176
177 $choices = array();
178 if ($choices = get_list_of_languages()) {
179 $mform->addElement('select', 'lang', get_string('preferredlanguage'), $choices);
180 $mform->setDefault('lang', $CFG->lang);
181 }
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"');
234 $mform->setType('idnumber', PARAM_RAW);
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?>