Minor fixes for XHTML compliance
[pfb-moodle.git] / user / editlib.php
blob4a8ce73db3cbd40b8a9e0cca6f5ade3702a4bcae
1 <?php //$Id$
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;
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);
22 function useredit_update_picture(&$usernew, &$userform) {
23 global $CFG;
25 if (isset($usernew->deletepicture) and $usernew->deletepicture) {
26 $location = $CFG->dataroot.'/users/'.$usernew->id;
27 @remove_dir($location);
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);
34 function useredit_update_bounces($user, $usernew) {
35 if (!isset($usernew->email)) {
36 //locked field
37 return;
39 if ($user->email !== $usernew->email) {
40 set_bounce_count($usernew,true);
41 set_send_count($usernew,true);
45 function useredit_update_trackforums($user, $usernew) {
46 global $CFG;
47 if (!isset($usernew->trackforums)) {
48 //locked field
49 return;
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);
57 function useredit_shared_definition(&$mform) {
58 global $CFG;
60 $strrequired = get_string('required');
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);
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);
70 $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="30"');
71 $mform->addRule('email', $strrequired, 'required', null, 'client');
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);
78 $mform->setDefault('maildisplay', 2);
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);
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');
93 if (!empty($CFG->allowusermailcharset)) {
94 $choices = array();
95 $charsets = get_list_of_charsets();
96 if (!empty($CFG->sitemailcharset)) {
97 $choices['0'] = get_string('site').' ('.$CFG->sitemailcharset.')';
98 } else {
99 $choices['0'] = get_string('site').' (UTF-8)';
101 $choices = array_merge($choices, $charsets);
102 $mform->addElement('select', 'preference_mailcharset', get_string('emailcharset'), $choices);
103 $mform->setAdvanced('preference_mailcharset');
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');
114 $choices = array();
115 $choices['1'] = get_string('autosubscribeyes');
116 $choices['0'] = get_string('autosubscribeno');
117 $mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices);
118 $mform->setDefault('autosubscribe', 1);
119 $mform->setAdvanced('autosubscribe');
121 if (!empty($CFG->forum_trackreadposts)) {
122 $choices = array();
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');
130 if ($CFG->htmleditor) {
131 $choices = array();
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');
139 if (empty($CFG->enableajax)) {
140 $mform->addElement('static', 'ajaxdisabled', get_string('ajaxuse'), get_string('ajaxno'));
141 $mform->setAdvanced('ajaxdisabled');
142 } else {
143 $choices = array();
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');
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');
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');
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);
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');
180 $choices = array();
181 if ($choices = get_list_of_languages()) {
182 $mform->addElement('select', 'lang', get_string('preferredlanguage'), $choices);
183 $mform->setDefault('lang', $CFG->lang);
186 if (!empty($CFG->allowuserthemes)) {
187 $choices = array();
188 $choices[''] = get_string('default');
189 $choices += get_list_of_themes();
190 $mform->addElement('select', 'theme', get_string('preferredtheme'), $choices);
191 $mform->setAdvanced('theme');
194 $mform->addElement('htmleditor', 'description', get_string('userdescription'));
195 $mform->setType('description', PARAM_CLEAN);
196 $mform->setHelpButton('description', array('text', get_string('helptext')));
198 if (!empty($CFG->gdversion)) {
199 $mform->addElement('header', 'moodle_picture', get_string('pictureof'));//TODO: Accessibility fix fieldset legend
201 $mform->addElement('static', 'currentpicture', get_string('currentpicture'));
203 $mform->addElement('checkbox', 'deletepicture', get_string('delete'));
204 $mform->setDefault('deletepicture',false);
206 $mform->addElement('file', 'imagefile', get_string('newpicture'));
207 $mform->setHelpButton('imagefile', array('picture', get_string('helppicture')));
209 $mform->addElement('text', 'imagealt', get_string('imagealt'), 'maxlength="100" size="30"');
210 $mform->setType('imagealt', PARAM_MULTILANG);
214 /// Moodle optional fields
215 $mform->addElement('header', 'moodle_optional', get_string('optional', 'form'));
216 $mform->setAdvanced('moodle_optional');
218 $mform->addElement('text', 'url', get_string('webpage'), 'maxlength="255" size="50"');
219 $mform->setType('url', PARAM_URL);
221 $mform->addElement('text', 'icq', get_string('icqnumber'), 'maxlength="15" size="25"');
222 $mform->setType('icq', PARAM_CLEAN);
224 $mform->addElement('text', 'skype', get_string('skypeid'), 'maxlength="50" size="25"');
225 $mform->setType('skype', PARAM_CLEAN);
227 $mform->addElement('text', 'aim', get_string('aimid'), 'maxlength="50" size="25"');
228 $mform->setType('aim', PARAM_CLEAN);
230 $mform->addElement('text', 'yahoo', get_string('yahooid'), 'maxlength="50" size="25"');
231 $mform->setType('yahoo', PARAM_CLEAN);
233 $mform->addElement('text', 'msn', get_string('msnid'), 'maxlength="50" size="25"');
234 $mform->setType('msn', PARAM_CLEAN);
236 $mform->addElement('text', 'idnumber', get_string('idnumber'), 'maxlength="64" size="25"');
237 $mform->setType('idnumber', PARAM_CLEAN);
239 $mform->addElement('text', 'institution', get_string('institution'), 'maxlength="40" size="25"');
240 $mform->setType('institution', PARAM_MULTILANG);
242 $mform->addElement('text', 'department', get_string('department'), 'maxlength="30" size="25"');
243 $mform->setType('department', PARAM_MULTILANG);
245 $mform->addElement('text', 'phone1', get_string('phone'), 'maxlength="20" size="25"');
246 $mform->setType('phone1', PARAM_CLEAN);
248 $mform->addElement('text', 'phone2', get_string('phone'), 'maxlength="20" size="25"');
249 $mform->setType('phone2', PARAM_CLEAN);
251 $mform->addElement('text', 'address', get_string('address'), 'maxlength="70" size="25"');
252 $mform->setType('address', PARAM_MULTILANG);