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) {
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) {
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
));
55 function useredit_update_bounces($user, $usernew) {
56 if (!isset($usernew->email
)) {
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) {
68 if (!isset($usernew->trackforums
)) {
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"');
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('emailchangepending', 'auth', $user);
110 $notice .= '<br /><a href="edit.php?cancelemailchange=1&id='.$user->id
.'">'
111 . get_string('emailchangecancel', 'auth') . '</a>';
112 $mform->addElement('static', 'emailpending', get_string('email'), $notice);
114 $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="30"');
115 $mform->addRule('email', $strrequired, 'required', null, 'client');
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);
126 $choices['0'] = get_string('textformat');
127 $choices['1'] = get_string('htmlformat');
128 $mform->addElement('select', 'mailformat', get_string('emailformat'), $choices);
129 $mform->setDefault('mailformat', 1);
131 if (!empty($CFG->allowusermailcharset
)) {
133 $charsets = get_list_of_charsets();
134 if (!empty($CFG->sitemailcharset
)) {
135 $choices['0'] = get_string('site').' ('.$CFG->sitemailcharset
.')';
137 $choices['0'] = get_string('site').' (UTF-8)';
139 $choices = array_merge($choices, $charsets);
140 $mform->addElement('select', 'preference_mailcharset', get_string('emailcharset'), $choices);
144 $choices['0'] = get_string('emaildigestoff');
145 $choices['1'] = get_string('emaildigestcomplete');
146 $choices['2'] = get_string('emaildigestsubjects');
147 $mform->addElement('select', 'maildigest', get_string('emaildigest'), $choices);
148 $mform->setDefault('maildigest', 0);
151 $choices['1'] = get_string('autosubscribeyes');
152 $choices['0'] = get_string('autosubscribeno');
153 $mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices);
154 $mform->setDefault('autosubscribe', 1);
156 if (!empty($CFG->forum_trackreadposts
)) {
158 $choices['0'] = get_string('trackforumsno');
159 $choices['1'] = get_string('trackforumsyes');
160 $mform->addElement('select', 'trackforums', get_string('trackforums'), $choices);
161 $mform->setDefault('trackforums', 0);
164 $editors = editors_get_enabled();
165 if (count($editors) > 1) {
167 $choices['0'] = get_string('texteditor');
168 $choices['1'] = get_string('htmleditor');
169 $mform->addElement('select', 'htmleditor', get_string('textediting'), $choices);
170 $mform->setDefault('htmleditor', 1);
172 $mform->addElement('hidden', 'htmleditor');
173 $mform->setDefault('htmleditor', 1);
174 $mform->setType('htmleditor', PARAM_INT
);
177 if (empty($CFG->enableajax
)) {
178 $mform->addElement('static', 'ajaxdisabled', get_string('ajaxuse'), get_string('ajaxno'));
181 $choices['0'] = get_string('ajaxno');
182 $choices['1'] = get_string('ajaxyes');
183 $mform->addElement('select', 'ajax', get_string('ajaxuse'), $choices);
184 $mform->setDefault('ajax', 0);
188 $choices['0'] = get_string('screenreaderno');
189 $choices['1'] = get_string('screenreaderyes');
190 $mform->addElement('select', 'screenreader', get_string('screenreaderuse'), $choices);
191 $mform->setDefault('screenreader', 0);
192 $mform->addHelpButton('screenreader', 'screenreaderuse');
194 $mform->addElement('text', 'city', get_string('city'), 'maxlength="120" size="21"');
195 $mform->setType('city', PARAM_MULTILANG
);
196 $mform->addRule('city', $strrequired, 'required', null, 'client');
197 if (!empty($CFG->defaultcity
)) {
198 $mform->setDefault('city', $CFG->defaultcity
);
201 $choices = get_string_manager()->get_list_of_countries();
202 $choices= array(''=>get_string('selectacountry').'...') +
$choices;
203 $mform->addElement('select', 'country', get_string('selectacountry'), $choices);
204 $mform->addRule('country', $strrequired, 'required', null, 'client');
205 if (!empty($CFG->country
)) {
206 $mform->setDefault('country', $CFG->country
);
209 $choices = get_list_of_timezones();
210 $choices['99'] = get_string('serverlocaltime');
211 if ($CFG->forcetimezone
!= 99) {
212 $mform->addElement('static', 'forcedtimezone', get_string('timezone'), $choices[$CFG->forcetimezone
]);
214 $mform->addElement('select', 'timezone', get_string('timezone'), $choices);
215 $mform->setDefault('timezone', '99');
218 $mform->addElement('select', 'lang', get_string('preferredlanguage'), get_string_manager()->get_list_of_translations());
219 $mform->setDefault('lang', $CFG->lang
);
221 if (!empty($CFG->allowuserthemes
)) {
223 $choices[''] = get_string('default');
224 $themes = get_list_of_themes();
225 foreach ($themes as $key=>$theme) {
226 if (empty($theme->hidefromselector
)) {
227 $choices[$key] = $theme->name
;
230 $mform->addElement('select', 'theme', get_string('preferredtheme'), $choices);
233 $mform->addElement('editor', 'description_editor', get_string('userdescription'), null, $editoroptions);
234 $mform->setType('description_editor', PARAM_CLEANHTML
);
235 $mform->addHelpButton('description_editor', 'userdescription');
237 if (!empty($CFG->gdversion
) and empty($USER->newadminuser
)) {
238 $mform->addElement('header', 'moodle_picture', get_string('pictureofuser'));
240 $mform->addElement('static', 'currentpicture', get_string('currentpicture'));
242 $mform->addElement('checkbox', 'deletepicture', get_string('delete'));
243 $mform->setDefault('deletepicture', 0);
245 $mform->addElement('filepicker', 'imagefile', get_string('newpicture'), '', array('maxbytes'=>get_max_upload_file_size($CFG->maxbytes
)));
246 $mform->addHelpButton('imagefile', 'newpicture');
248 $mform->addElement('text', 'imagealt', get_string('imagealt'), 'maxlength="100" size="30"');
249 $mform->setType('imagealt', PARAM_MULTILANG
);
253 if (!empty($CFG->usetags
) and empty($USER->newadminuser
)) {
254 $mform->addElement('header', 'moodle_interests', get_string('interests'));
255 $mform->addElement('tags', 'interests', get_string('interestslist'), array('display' => 'noofficial'));
256 $mform->addHelpButton('interests', 'interestslist');
259 /// Moodle optional fields
260 $mform->addElement('header', 'moodle_optional', get_string('optional', 'form'));
262 $mform->addElement('text', 'url', get_string('webpage'), 'maxlength="255" size="50"');
263 $mform->setType('url', PARAM_URL
);
265 $mform->addElement('text', 'icq', get_string('icqnumber'), 'maxlength="15" size="25"');
266 $mform->setType('icq', PARAM_NOTAGS
);
268 $mform->addElement('text', 'skype', get_string('skypeid'), 'maxlength="50" size="25"');
269 $mform->setType('skype', PARAM_NOTAGS
);
271 $mform->addElement('text', 'aim', get_string('aimid'), 'maxlength="50" size="25"');
272 $mform->setType('aim', PARAM_NOTAGS
);
274 $mform->addElement('text', 'yahoo', get_string('yahooid'), 'maxlength="50" size="25"');
275 $mform->setType('yahoo', PARAM_NOTAGS
);
277 $mform->addElement('text', 'msn', get_string('msnid'), 'maxlength="50" size="25"');
278 $mform->setType('msn', PARAM_NOTAGS
);
280 $mform->addElement('text', 'idnumber', get_string('idnumber'), 'maxlength="255" size="25"');
281 $mform->setType('idnumber', PARAM_NOTAGS
);
283 $mform->addElement('text', 'institution', get_string('institution'), 'maxlength="40" size="25"');
284 $mform->setType('institution', PARAM_MULTILANG
);
286 $mform->addElement('text', 'department', get_string('department'), 'maxlength="30" size="25"');
287 $mform->setType('department', PARAM_MULTILANG
);
289 $mform->addElement('text', 'phone1', get_string('phone'), 'maxlength="20" size="25"');
290 $mform->setType('phone1', PARAM_NOTAGS
);
292 $mform->addElement('text', 'phone2', get_string('phone2'), 'maxlength="20" size="25"');
293 $mform->setType('phone2', PARAM_NOTAGS
);
295 $mform->addElement('text', 'address', get_string('address'), 'maxlength="70" size="25"');
296 $mform->setType('address', PARAM_MULTILANG
);