MDL-24471, FILEMANAGER change <button> to <input type="button" />, moodle form may...
[moodle.git] / user / editlib.php
blob70deb235426713e4f135ad95a252ffb25835bdad
1 <?php
3 function cancel_email_update($userid) {
4 unset_user_preference('newemail', $userid);
5 unset_user_preference('newemailkey', $userid);
6 unset_user_preference('newemailattemptsleft', $userid);
9 function useredit_load_preferences(&$user, $reload=true) {
10 global $USER;
12 if (!empty($user->id)) {
13 if ($reload and $USER->id == $user->id) {
14 // reload preferences in case it was changed in other session
15 unset($USER->preference);
18 if ($preferences = get_user_preferences(null, null, $user->id)) {
19 foreach($preferences as $name=>$value) {
20 $user->{'preference_'.$name} = $value;
26 function useredit_update_user_preference($usernew) {
27 $ua = (array)$usernew;
28 foreach($ua as $key=>$value) {
29 if (strpos($key, 'preference_') === 0) {
30 $name = substr($key, strlen('preference_'));
31 set_user_preference($name, $value, $usernew->id);
36 function useredit_update_picture(&$usernew, $userform) {
37 global $CFG, $DB;
38 require_once("$CFG->libdir/gdlib.php");
40 $fs = get_file_storage();
41 $context = get_context_instance(CONTEXT_USER, $usernew->id, MUST_EXIST);
43 if (isset($usernew->deletepicture) and $usernew->deletepicture) {
44 $fs->delete_area_files($context->id, 'user', 'icon'); // drop all areas
45 $DB->set_field('user', 'picture', 0, array('id'=>$usernew->id));
47 } else if ($iconfile = $userform->save_temp_file('imagefile')) {
48 if (process_new_icon($context, 'user', 'icon', 0, $iconfile)) {
49 $DB->set_field('user', 'picture', 1, array('id'=>$usernew->id));
51 @unlink($iconfile);
55 function useredit_update_bounces($user, $usernew) {
56 if (!isset($usernew->email)) {
57 //locked field
58 return;
60 if (!isset($user->email) || $user->email !== $usernew->email) {
61 set_bounce_count($usernew,true);
62 set_send_count($usernew,true);
66 function useredit_update_trackforums($user, $usernew) {
67 global $CFG;
68 if (!isset($usernew->trackforums)) {
69 //locked field
70 return;
72 if ((!isset($user->trackforums) || ($usernew->trackforums != $user->trackforums)) and !$usernew->trackforums) {
73 require_once($CFG->dirroot.'/mod/forum/lib.php');
74 forum_tp_delete_read_records($usernew->id);
78 function useredit_update_interests($user, $interests) {
79 tag_set('user', $user->id, $interests);
82 function useredit_shared_definition(&$mform, $editoroptions = null) {
83 global $CFG, $USER, $DB;
85 $user = $DB->get_record('user', array('id' => $USER->id));
86 useredit_load_preferences($user, false);
88 $strrequired = get_string('required');
90 $nameordercheck = new stdClass();
91 $nameordercheck->firstname = 'a';
92 $nameordercheck->lastname = 'b';
93 if (fullname($nameordercheck) == 'b a' ) { // See MDL-4325
94 $mform->addElement('text', 'lastname', get_string('lastname'), 'maxlength="100" size="30"');
95 $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"');
96 } else {
97 $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"');
98 $mform->addElement('text', 'lastname', get_string('lastname'), 'maxlength="100" size="30"');
101 $mform->addRule('firstname', $strrequired, 'required', null, 'client');
102 $mform->setType('firstname', PARAM_NOTAGS);
104 $mform->addRule('lastname', $strrequired, 'required', null, 'client');
105 $mform->setType('lastname', PARAM_NOTAGS);
107 // Do not show email field if change confirmation is pending
108 if (!empty($CFG->emailchangeconfirmation) and !empty($user->preference_newemail)) {
109 $notice = get_string('auth_emailchangepending', 'auth_email', $user);
110 $notice .= '<br /><a href="edit.php?cancelemailchange=1&amp;id='.$user->id.'">'
111 . get_string('auth_emailchangecancel', 'auth_email') . '</a>';
112 $mform->addElement('static', 'emailpending', get_string('email'), $notice);
113 } else {
114 $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="30"');
115 $mform->addRule('email', $strrequired, 'required', null, 'client');
118 $choices = array();
119 $choices['0'] = get_string('emaildisplayno');
120 $choices['1'] = get_string('emaildisplayyes');
121 $choices['2'] = get_string('emaildisplaycourse');
122 $mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices);
123 $mform->setDefault('maildisplay', 2);
125 $choices = array();
126 $choices['0'] = get_string('emailenable');
127 $choices['1'] = get_string('emaildisable');
128 $mform->addElement('select', 'emailstop', get_string('emailactive'), $choices);
129 $mform->setDefault('emailstop', 0);
131 $choices = array();
132 $choices['0'] = get_string('textformat');
133 $choices['1'] = get_string('htmlformat');
134 $mform->addElement('select', 'mailformat', get_string('emailformat'), $choices);
135 $mform->setDefault('mailformat', 1);
137 if (!empty($CFG->allowusermailcharset)) {
138 $choices = array();
139 $charsets = get_list_of_charsets();
140 if (!empty($CFG->sitemailcharset)) {
141 $choices['0'] = get_string('site').' ('.$CFG->sitemailcharset.')';
142 } else {
143 $choices['0'] = get_string('site').' (UTF-8)';
145 $choices = array_merge($choices, $charsets);
146 $mform->addElement('select', 'preference_mailcharset', get_string('emailcharset'), $choices);
149 $choices = array();
150 $choices['0'] = get_string('emaildigestoff');
151 $choices['1'] = get_string('emaildigestcomplete');
152 $choices['2'] = get_string('emaildigestsubjects');
153 $mform->addElement('select', 'maildigest', get_string('emaildigest'), $choices);
154 $mform->setDefault('maildigest', 0);
156 $choices = array();
157 $choices['1'] = get_string('autosubscribeyes');
158 $choices['0'] = get_string('autosubscribeno');
159 $mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices);
160 $mform->setDefault('autosubscribe', 1);
162 if (!empty($CFG->forum_trackreadposts)) {
163 $choices = array();
164 $choices['0'] = get_string('trackforumsno');
165 $choices['1'] = get_string('trackforumsyes');
166 $mform->addElement('select', 'trackforums', get_string('trackforums'), $choices);
167 $mform->setDefault('trackforums', 0);
170 $editors = editors_get_enabled();
171 if (count($editors) > 1) {
172 $choices = array();
173 $choices['0'] = get_string('texteditor');
174 $choices['1'] = get_string('htmleditor');
175 $mform->addElement('select', 'htmleditor', get_string('textediting'), $choices);
176 $mform->setDefault('htmleditor', 1);
177 } else {
178 $mform->addElement('hidden', 'htmleditor');
179 $mform->setDefault('htmleditor', 1);
180 $mform->setType('htmleditor', PARAM_INT);
183 if (empty($CFG->enableajax)) {
184 $mform->addElement('static', 'ajaxdisabled', get_string('ajaxuse'), get_string('ajaxno'));
185 } else {
186 $choices = array();
187 $choices['0'] = get_string('ajaxno');
188 $choices['1'] = get_string('ajaxyes');
189 $mform->addElement('select', 'ajax', get_string('ajaxuse'), $choices);
190 $mform->setDefault('ajax', 0);
193 $choices = array();
194 $choices['0'] = get_string('screenreaderno');
195 $choices['1'] = get_string('screenreaderyes');
196 $mform->addElement('select', 'screenreader', get_string('screenreaderuse'), $choices);
197 $mform->setDefault('screenreader', 0);
198 $mform->addHelpButton('screenreader', 'screenreaderuse');
200 $mform->addElement('text', 'city', get_string('city'), 'maxlength="120" size="21"');
201 $mform->setType('city', PARAM_MULTILANG);
202 $mform->addRule('city', $strrequired, 'required', null, 'client');
205 $choices = get_string_manager()->get_list_of_countries();
206 $choices= array(''=>get_string('selectacountry').'...') + $choices;
207 $mform->addElement('select', 'country', get_string('selectacountry'), $choices);
208 $mform->addRule('country', $strrequired, 'required', null, 'client');
209 if (!empty($CFG->country)) {
210 $mform->setDefault('country', $CFG->country);
213 $choices = get_list_of_timezones();
214 $choices['99'] = get_string('serverlocaltime');
215 if ($CFG->forcetimezone != 99) {
216 $mform->addElement('static', 'forcedtimezone', get_string('timezone'), $choices[$CFG->forcetimezone]);
217 } else {
218 $mform->addElement('select', 'timezone', get_string('timezone'), $choices);
219 $mform->setDefault('timezone', '99');
222 $mform->addElement('select', 'lang', get_string('preferredlanguage'), get_string_manager()->get_list_of_translations());
223 $mform->setDefault('lang', $CFG->lang);
225 if (!empty($CFG->allowuserthemes)) {
226 $choices = array();
227 $choices[''] = get_string('default');
228 $themes = get_list_of_themes();
229 foreach ($themes as $key=>$theme) {
230 if (empty($theme->hidefromselector)) {
231 $choices[$key] = $theme->name;
234 $mform->addElement('select', 'theme', get_string('preferredtheme'), $choices);
237 $mform->addElement('editor', 'description_editor', get_string('userdescription'), null, $editoroptions);
238 $mform->setType('description_editor', PARAM_CLEANHTML);
239 $mform->addHelpButton('description_editor', 'userdescription');
241 if (!empty($CFG->gdversion)) {
242 $mform->addElement('header', 'moodle_picture', get_string('pictureofuser'));
244 $mform->addElement('static', 'currentpicture', get_string('currentpicture'));
246 $mform->addElement('checkbox', 'deletepicture', get_string('delete'));
247 $mform->setDefault('deletepicture', 0);
249 $mform->addElement('filepicker', 'imagefile', get_string('newpicture'), '', array('maxbytes'=>get_max_upload_file_size($CFG->maxbytes)));
250 $mform->addHelpButton('imagefile', 'newpicture');
252 $mform->addElement('text', 'imagealt', get_string('imagealt'), 'maxlength="100" size="30"');
253 $mform->setType('imagealt', PARAM_MULTILANG);
257 if (!empty($CFG->usetags)) {
258 $mform->addElement('header', 'moodle_interests', get_string('interests'));
259 $mform->addElement('tags', 'interests', get_string('interestslist'), array('display' => 'noofficial'));
260 $mform->addHelpButton('interests', 'interestslist');
263 /// Moodle optional fields
264 $mform->addElement('header', 'moodle_optional', get_string('optional', 'form'));
266 $mform->addElement('text', 'url', get_string('webpage'), 'maxlength="255" size="50"');
267 $mform->setType('url', PARAM_URL);
269 $mform->addElement('text', 'icq', get_string('icqnumber'), 'maxlength="15" size="25"');
270 $mform->setType('icq', PARAM_NOTAGS);
272 $mform->addElement('text', 'skype', get_string('skypeid'), 'maxlength="50" size="25"');
273 $mform->setType('skype', PARAM_NOTAGS);
275 $mform->addElement('text', 'aim', get_string('aimid'), 'maxlength="50" size="25"');
276 $mform->setType('aim', PARAM_NOTAGS);
278 $mform->addElement('text', 'yahoo', get_string('yahooid'), 'maxlength="50" size="25"');
279 $mform->setType('yahoo', PARAM_NOTAGS);
281 $mform->addElement('text', 'msn', get_string('msnid'), 'maxlength="50" size="25"');
282 $mform->setType('msn', PARAM_NOTAGS);
284 $mform->addElement('text', 'idnumber', get_string('idnumber'), 'maxlength="255" size="25"');
285 $mform->setType('idnumber', PARAM_NOTAGS);
287 $mform->addElement('text', 'institution', get_string('institution'), 'maxlength="40" size="25"');
288 $mform->setType('institution', PARAM_MULTILANG);
290 $mform->addElement('text', 'department', get_string('department'), 'maxlength="30" size="25"');
291 $mform->setType('department', PARAM_MULTILANG);
293 $mform->addElement('text', 'phone1', get_string('phone'), 'maxlength="20" size="25"');
294 $mform->setType('phone1', PARAM_NOTAGS);
296 $mform->addElement('text', 'phone2', get_string('phone2'), 'maxlength="20" size="25"');
297 $mform->setType('phone2', PARAM_NOTAGS);
299 $mform->addElement('text', 'address', get_string('address'), 'maxlength="70" size="25"');
300 $mform->setType('address', PARAM_MULTILANG);