Should be $COURSE not $course
[moodle-linuxchix.git] / user / editlib.php
blob181c7bb9fd60fec50d720c943575f5b8b81d0765
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 (!isset($user->email) || $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 ((!isset($user->trackforums) || ($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_update_interests($user, $cvs_tag_names)
59 update_item_tags('user', $user->id, $cvs_tag_names);
62 function useredit_shared_definition(&$mform) {
63 global $CFG;
65 $strrequired = get_string('required');
67 $nameordercheck->firstname = 'a';
68 $nameordercheck->lastname = 'b';
69 if (fullname($nameordercheck) == 'b a' ) { // See MDL-4325
70 $mform->addElement('text', 'lastname', get_string('lastname'), 'maxlength="100" size="30"');
71 $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"');
72 } else {
73 $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"');
74 $mform->addElement('text', 'lastname', get_string('lastname'), 'maxlength="100" size="30"');
77 $mform->addRule('firstname', $strrequired, 'required', null, 'client');
78 $mform->setType('firstname', PARAM_NOTAGS);
80 $mform->addRule('lastname', $strrequired, 'required', null, 'client');
81 $mform->setType('lastname', PARAM_NOTAGS);
83 $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="30"');
84 $mform->addRule('email', $strrequired, 'required', null, 'client');
86 $choices = array();
87 $choices['0'] = get_string('emaildisplayno');
88 $choices['1'] = get_string('emaildisplayyes');
89 $choices['2'] = get_string('emaildisplaycourse');
90 $mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices);
91 $mform->setDefault('maildisplay', 2);
93 $choices = array();
94 $choices['0'] = get_string('emailenable');
95 $choices['1'] = get_string('emaildisable');
96 $mform->addElement('select', 'emailstop', get_string('emailactive'), $choices);
97 $mform->setDefault('emailenable', 1);
99 $choices = array();
100 $choices['0'] = get_string('textformat');
101 $choices['1'] = get_string('htmlformat');
102 $mform->addElement('select', 'mailformat', get_string('emailformat'), $choices);
103 $mform->setDefault('mailformat', 1);
104 $mform->setAdvanced('mailformat');
106 if (!empty($CFG->allowusermailcharset)) {
107 $choices = array();
108 $charsets = get_list_of_charsets();
109 if (!empty($CFG->sitemailcharset)) {
110 $choices['0'] = get_string('site').' ('.$CFG->sitemailcharset.')';
111 } else {
112 $choices['0'] = get_string('site').' (UTF-8)';
114 $choices = array_merge($choices, $charsets);
115 $mform->addElement('select', 'preference_mailcharset', get_string('emailcharset'), $choices);
116 $mform->setAdvanced('preference_mailcharset');
119 $choices = array();
120 $choices['0'] = get_string('emaildigestoff');
121 $choices['1'] = get_string('emaildigestcomplete');
122 $choices['2'] = get_string('emaildigestsubjects');
123 $mform->addElement('select', 'maildigest', get_string('emaildigest'), $choices);
124 $mform->setDefault('maildigest', 0);
125 $mform->setAdvanced('maildigest');
127 $choices = array();
128 $choices['1'] = get_string('autosubscribeyes');
129 $choices['0'] = get_string('autosubscribeno');
130 $mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices);
131 $mform->setDefault('autosubscribe', 1);
132 $mform->setAdvanced('autosubscribe');
134 if (!empty($CFG->forum_trackreadposts)) {
135 $choices = array();
136 $choices['0'] = get_string('trackforumsno');
137 $choices['1'] = get_string('trackforumsyes');
138 $mform->addElement('select', 'trackforums', get_string('trackforums'), $choices);
139 $mform->setDefault('trackforums', 0);
140 $mform->setAdvanced('trackforums');
143 if ($CFG->htmleditor) {
144 $choices = array();
145 $choices['0'] = get_string('texteditor');
146 $choices['1'] = get_string('htmleditor');
147 $mform->addElement('select', 'htmleditor', get_string('textediting'), $choices);
148 $mform->setDefault('htmleditor', 1);
149 $mform->setAdvanced('htmleditor');
152 if (empty($CFG->enableajax)) {
153 $mform->addElement('static', 'ajaxdisabled', get_string('ajaxuse'), get_string('ajaxno'));
154 $mform->setAdvanced('ajaxdisabled');
155 } else {
156 $choices = array();
157 $choices['0'] = get_string('ajaxno');
158 $choices['1'] = get_string('ajaxyes');
159 $mform->addElement('select', 'ajax', get_string('ajaxuse'), $choices);
160 $mform->setDefault('ajax', 0);
161 $mform->setAdvanced('ajax');
164 $choices = array();
165 $choices['0'] = get_string('screenreaderno');
166 $choices['1'] = get_string('screenreaderyes');
167 $mform->addElement('select', 'screenreader', get_string('screenreaderuse'), $choices);
168 $mform->setDefault('screenreader', 0);
169 $mform->setAdvanced('screenreader');
171 $mform->addElement('text', 'city', get_string('city'), 'maxlength="100" size="25"');
172 $mform->setType('city', PARAM_MULTILANG);
173 $mform->addRule('city', $strrequired, 'required', null, 'client');
176 $choices = get_list_of_countries();
177 $choices= array(''=>get_string('selectacountry').'...') + $choices;
178 $mform->addElement('select', 'country', get_string('selectacountry'), $choices);
179 $mform->addRule('country', $strrequired, 'required', null, 'client');
180 if (!empty($CFG->country)) {
181 $mform->setDefault('country', $CFG->country);
184 $choices = get_list_of_timezones();
185 $choices['99'] = get_string('serverlocaltime');
186 if ($CFG->forcetimezone != 99) {
187 $mform->addElement('static', 'forcedtimezone', get_string('timezone'), $choices[$CFG->forcetimezone]);
188 } else {
189 $mform->addElement('select', 'timezone', get_string('timezone'), $choices);
190 $mform->setDefault('timezone', '99');
193 $mform->addElement('select', 'lang', get_string('preferredlanguage'), get_list_of_languages());
194 $mform->setDefault('lang', $CFG->lang);
196 if (!empty($CFG->allowuserthemes)) {
197 $choices = array();
198 $choices[''] = get_string('default');
199 $choices += get_list_of_themes();
200 $mform->addElement('select', 'theme', get_string('preferredtheme'), $choices);
201 $mform->setAdvanced('theme');
204 $mform->addElement('htmleditor', 'description', get_string('userdescription'));
205 $mform->setType('description', PARAM_CLEAN);
206 $mform->setHelpButton('description', array('text', get_string('helptext')));
208 if (!empty($CFG->gdversion)) {
209 $mform->addElement('header', 'moodle_picture', get_string('pictureof'));//TODO: Accessibility fix fieldset legend
211 $mform->addElement('static', 'currentpicture', get_string('currentpicture'));
213 $mform->addElement('checkbox', 'deletepicture', get_string('delete'));
214 $mform->setDefault('deletepicture',false);
216 $mform->addElement('file', 'imagefile', get_string('newpicture'));
217 $mform->setHelpButton('imagefile', array('picture', get_string('helppicture')));
219 $mform->addElement('text', 'imagealt', get_string('imagealt'), 'maxlength="100" size="30"');
220 $mform->setType('imagealt', PARAM_MULTILANG);
224 if( !empty($CFG->usetags)) {
225 $mform->addElement('header', 'moodle_interests', get_string('interests'));
226 $mform->addElement('static', 'helptextinterests', '' , get_string('enteryourinterests'));
227 $mform->addElement('textarea', 'interests', get_string('interests'), 'cols="45" rows="3"');
230 /// Moodle optional fields
231 $mform->addElement('header', 'moodle_optional', get_string('optional', 'form'));
232 $mform->setAdvanced('moodle_optional');
234 $mform->addElement('text', 'url', get_string('webpage'), 'maxlength="255" size="50"');
235 $mform->setType('url', PARAM_URL);
237 $mform->addElement('text', 'icq', get_string('icqnumber'), 'maxlength="15" size="25"');
238 $mform->setType('icq', PARAM_CLEAN);
240 $mform->addElement('text', 'skype', get_string('skypeid'), 'maxlength="50" size="25"');
241 $mform->setType('skype', PARAM_CLEAN);
243 $mform->addElement('text', 'aim', get_string('aimid'), 'maxlength="50" size="25"');
244 $mform->setType('aim', PARAM_CLEAN);
246 $mform->addElement('text', 'yahoo', get_string('yahooid'), 'maxlength="50" size="25"');
247 $mform->setType('yahoo', PARAM_CLEAN);
249 $mform->addElement('text', 'msn', get_string('msnid'), 'maxlength="50" size="25"');
250 $mform->setType('msn', PARAM_CLEAN);
252 $mform->addElement('text', 'idnumber', get_string('idnumber'), 'maxlength="64" size="25"');
253 $mform->setType('idnumber', PARAM_CLEAN);
255 $mform->addElement('text', 'institution', get_string('institution'), 'maxlength="40" size="25"');
256 $mform->setType('institution', PARAM_MULTILANG);
258 $mform->addElement('text', 'department', get_string('department'), 'maxlength="30" size="25"');
259 $mform->setType('department', PARAM_MULTILANG);
261 $mform->addElement('text', 'phone1', get_string('phone'), 'maxlength="20" size="25"');
262 $mform->setType('phone1', PARAM_CLEAN);
264 $mform->addElement('text', 'phone2', get_string('phone'), 'maxlength="20" size="25"');
265 $mform->setType('phone2', PARAM_CLEAN);
267 $mform->addElement('text', 'address', get_string('address'), 'maxlength="70" size="25"');
268 $mform->setType('address', PARAM_MULTILANG);