PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/MoodleWebRole/user/editlib.php

#
PHP | 299 lines | 237 code | 57 blank | 5 comment | 35 complexity | a1d8c9ce37b7913789cade9220ba939f MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, LGPL-2.0, GPL-2.0
  1. <?php //$Id: editlib.php,v 1.11.2.12 2009/10/06 19:04:04 skodak Exp $
  2. function cancel_email_update($userid) {
  3. unset_user_preference('newemail', $userid);
  4. unset_user_preference('newemailkey', $userid);
  5. unset_user_preference('newemailattemptsleft', $userid);
  6. }
  7. function useredit_load_preferences(&$user, $reload=true) {
  8. global $USER;
  9. if (!empty($user->id)) {
  10. if ($reload and $USER->id == $user->id) {
  11. // reload preferences in case it was changed in other session
  12. unset($USER->preference);
  13. }
  14. if ($preferences = get_user_preferences(null, null, $user->id)) {
  15. foreach($preferences as $name=>$value) {
  16. $user->{'preference_'.$name} = $value;
  17. }
  18. }
  19. }
  20. }
  21. function useredit_update_user_preference($usernew) {
  22. $ua = (array)$usernew;
  23. foreach($ua as $key=>$value) {
  24. if (strpos($key, 'preference_') === 0) {
  25. $name = substr($key, strlen('preference_'));
  26. set_user_preference($name, stripslashes_recursive($value), $usernew->id);
  27. }
  28. }
  29. }
  30. function useredit_update_picture(&$usernew, &$userform) {
  31. global $CFG;
  32. if (isset($usernew->deletepicture) and $usernew->deletepicture) {
  33. $location = make_user_directory($usernew->id, true);
  34. @remove_dir($location);
  35. set_field('user', 'picture', 0, 'id', $usernew->id);
  36. } else if ($usernew->picture = save_profile_image($usernew->id, $userform->get_um(), 'user')) {
  37. set_field('user', 'picture', 1, 'id', $usernew->id);
  38. }
  39. }
  40. function useredit_update_bounces($user, $usernew) {
  41. if (!isset($usernew->email)) {
  42. //locked field
  43. return;
  44. }
  45. if (!isset($user->email) || $user->email !== stripslashes($usernew->email)) {
  46. set_bounce_count($usernew,true);
  47. set_send_count($usernew,true);
  48. }
  49. }
  50. function useredit_update_trackforums($user, $usernew) {
  51. global $CFG;
  52. if (!isset($usernew->trackforums)) {
  53. //locked field
  54. return;
  55. }
  56. if ((!isset($user->trackforums) || ($usernew->trackforums != $user->trackforums)) and !$usernew->trackforums) {
  57. require_once($CFG->dirroot.'/mod/forum/lib.php');
  58. forum_tp_delete_read_records($usernew->id);
  59. }
  60. }
  61. function useredit_update_interests($user, $csv_tag_names) {
  62. tag_set('user', $user->id, explode(',', $csv_tag_names));
  63. }
  64. function useredit_shared_definition(&$mform) {
  65. global $CFG, $USER;
  66. $user = get_record('user', 'id', $USER->id);
  67. useredit_load_preferences($user, false);
  68. $strrequired = get_string('required');
  69. $nameordercheck = new object();
  70. $nameordercheck->firstname = 'a';
  71. $nameordercheck->lastname = 'b';
  72. if (fullname($nameordercheck) == 'b a' ) { // See MDL-4325
  73. $mform->addElement('text', 'lastname', get_string('lastname'), 'maxlength="100" size="30"');
  74. $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"');
  75. } else {
  76. $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"');
  77. $mform->addElement('text', 'lastname', get_string('lastname'), 'maxlength="100" size="30"');
  78. }
  79. $mform->addRule('firstname', $strrequired, 'required', null, 'client');
  80. $mform->setType('firstname', PARAM_NOTAGS);
  81. $mform->addRule('lastname', $strrequired, 'required', null, 'client');
  82. $mform->setType('lastname', PARAM_NOTAGS);
  83. // Do not show email field if change confirmation is pending
  84. if ($CFG->emailchangeconfirmation && !empty($user->preference_newemail)) {
  85. $notice = get_string('auth_emailchangepending', 'auth', $user);
  86. $notice .= '<br /><a href="edit.php?cancelemailchange=1&amp;id='.$user->id.'">'
  87. . get_string('auth_emailchangecancel', 'auth') . '</a>';
  88. $mform->addElement('static', 'emailpending', get_string('email'), $notice);
  89. } else {
  90. $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="30"');
  91. $mform->addRule('email', $strrequired, 'required', null, 'client');
  92. }
  93. $choices = array();
  94. $choices['0'] = get_string('emaildisplayno');
  95. $choices['1'] = get_string('emaildisplayyes');
  96. $choices['2'] = get_string('emaildisplaycourse');
  97. $mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices);
  98. $mform->setDefault('maildisplay', 2);
  99. $choices = array();
  100. $choices['0'] = get_string('emailenable');
  101. $choices['1'] = get_string('emaildisable');
  102. $mform->addElement('select', 'emailstop', get_string('emailactive'), $choices);
  103. $mform->setDefault('emailenable', 1);
  104. $choices = array();
  105. $choices['0'] = get_string('textformat');
  106. $choices['1'] = get_string('htmlformat');
  107. $mform->addElement('select', 'mailformat', get_string('emailformat'), $choices);
  108. $mform->setDefault('mailformat', 1);
  109. $mform->setAdvanced('mailformat');
  110. if (!empty($CFG->allowusermailcharset)) {
  111. $choices = array();
  112. $charsets = get_list_of_charsets();
  113. if (!empty($CFG->sitemailcharset)) {
  114. $choices['0'] = get_string('site').' ('.$CFG->sitemailcharset.')';
  115. } else {
  116. $choices['0'] = get_string('site').' (UTF-8)';
  117. }
  118. $choices = array_merge($choices, $charsets);
  119. $mform->addElement('select', 'preference_mailcharset', get_string('emailcharset'), $choices);
  120. $mform->setAdvanced('preference_mailcharset');
  121. }
  122. $choices = array();
  123. $choices['0'] = get_string('emaildigestoff');
  124. $choices['1'] = get_string('emaildigestcomplete');
  125. $choices['2'] = get_string('emaildigestsubjects');
  126. $mform->addElement('select', 'maildigest', get_string('emaildigest'), $choices);
  127. $mform->setDefault('maildigest', 0);
  128. $mform->setAdvanced('maildigest');
  129. $choices = array();
  130. $choices['1'] = get_string('autosubscribeyes');
  131. $choices['0'] = get_string('autosubscribeno');
  132. $mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices);
  133. $mform->setDefault('autosubscribe', 1);
  134. $mform->setAdvanced('autosubscribe');
  135. if (!empty($CFG->forum_trackreadposts)) {
  136. $choices = array();
  137. $choices['0'] = get_string('trackforumsno');
  138. $choices['1'] = get_string('trackforumsyes');
  139. $mform->addElement('select', 'trackforums', get_string('trackforums'), $choices);
  140. $mform->setDefault('trackforums', 0);
  141. $mform->setAdvanced('trackforums');
  142. }
  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');
  150. }
  151. if (empty($CFG->enableajax)) {
  152. $mform->addElement('static', 'ajaxdisabled', get_string('ajaxuse'), get_string('ajaxno'));
  153. $mform->setAdvanced('ajaxdisabled');
  154. } else {
  155. $choices = array();
  156. $choices['0'] = get_string('ajaxno');
  157. $choices['1'] = get_string('ajaxyes');
  158. $mform->addElement('select', 'ajax', get_string('ajaxuse'), $choices);
  159. $mform->setDefault('ajax', 0);
  160. $mform->setAdvanced('ajax');
  161. }
  162. $choices = array();
  163. $choices['0'] = get_string('screenreaderno');
  164. $choices['1'] = get_string('screenreaderyes');
  165. $mform->addElement('select', 'screenreader', get_string('screenreaderuse'), $choices);
  166. $mform->setDefault('screenreader', 0);
  167. $mform->setAdvanced('screenreader');
  168. $mform->addElement('text', 'city', get_string('city'), 'maxlength="20" size="21"');
  169. $mform->setType('city', PARAM_MULTILANG);
  170. $mform->addRule('city', $strrequired, 'required', null, 'client');
  171. $choices = get_list_of_countries();
  172. $choices= array(''=>get_string('selectacountry').'...') + $choices;
  173. $mform->addElement('select', 'country', get_string('selectacountry'), $choices);
  174. $mform->addRule('country', $strrequired, 'required', null, 'client');
  175. if (!empty($CFG->country)) {
  176. $mform->setDefault('country', $CFG->country);
  177. }
  178. $choices = get_list_of_timezones();
  179. $choices['99'] = get_string('serverlocaltime');
  180. if ($CFG->forcetimezone != 99) {
  181. $mform->addElement('static', 'forcedtimezone', get_string('timezone'), $choices[$CFG->forcetimezone]);
  182. } else {
  183. $mform->addElement('select', 'timezone', get_string('timezone'), $choices);
  184. $mform->setDefault('timezone', '99');
  185. }
  186. $mform->addElement('select', 'lang', get_string('preferredlanguage'), get_list_of_languages());
  187. $mform->setDefault('lang', $CFG->lang);
  188. if (!empty($CFG->allowuserthemes)) {
  189. $choices = array();
  190. $choices[''] = get_string('default');
  191. $choices += get_list_of_themes();
  192. $mform->addElement('select', 'theme', get_string('preferredtheme'), $choices);
  193. $mform->setAdvanced('theme');
  194. }
  195. $mform->addElement('htmleditor', 'description', get_string('userdescription'));
  196. $mform->setType('description', PARAM_CLEAN);
  197. $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
  200. $mform->addElement('static', 'currentpicture', get_string('currentpicture'));
  201. $mform->addElement('checkbox', 'deletepicture', get_string('delete'));
  202. $mform->setDefault('deletepicture',false);
  203. $mform->addElement('file', 'imagefile', get_string('newpicture'));
  204. $mform->setHelpButton('imagefile', array('picture', get_string('helppicture')));
  205. $mform->addElement('text', 'imagealt', get_string('imagealt'), 'maxlength="100" size="30"');
  206. $mform->setType('imagealt', PARAM_MULTILANG);
  207. }
  208. if( !empty($CFG->usetags)) {
  209. $mform->addElement('header', 'moodle_interests', get_string('interests'));
  210. $mform->addElement('textarea', 'interests', get_string('interestslist'), 'cols="45" rows="3"');
  211. $mform->setHelpButton('interests', array('interestslist', get_string('helpinterestslist'),
  212. false, true, false));
  213. }
  214. /// Moodle optional fields
  215. $mform->addElement('header', 'moodle_optional', get_string('optional', 'form'));
  216. $mform->setAdvanced('moodle_optional');
  217. $mform->addElement('text', 'url', get_string('webpage'), 'maxlength="255" size="50"');
  218. $mform->setType('url', PARAM_URL);
  219. $mform->addElement('text', 'icq', get_string('icqnumber'), 'maxlength="15" size="25"');
  220. $mform->setType('icq', PARAM_CLEAN);
  221. $mform->addElement('text', 'skype', get_string('skypeid'), 'maxlength="50" size="25"');
  222. $mform->setType('skype', PARAM_CLEAN);
  223. $mform->addElement('text', 'aim', get_string('aimid'), 'maxlength="50" size="25"');
  224. $mform->setType('aim', PARAM_CLEAN);
  225. $mform->addElement('text', 'yahoo', get_string('yahooid'), 'maxlength="50" size="25"');
  226. $mform->setType('yahoo', PARAM_CLEAN);
  227. $mform->addElement('text', 'msn', get_string('msnid'), 'maxlength="50" size="25"');
  228. $mform->setType('msn', PARAM_CLEAN);
  229. $mform->addElement('text', 'idnumber', get_string('idnumber'), 'maxlength="255" size="25"');
  230. $mform->setType('idnumber', PARAM_CLEAN);
  231. $mform->addElement('text', 'institution', get_string('institution'), 'maxlength="40" size="25"');
  232. $mform->setType('institution', PARAM_MULTILANG);
  233. $mform->addElement('text', 'department', get_string('department'), 'maxlength="30" size="25"');
  234. $mform->setType('department', PARAM_MULTILANG);
  235. $mform->addElement('text', 'phone1', get_string('phone'), 'maxlength="20" size="25"');
  236. $mform->setType('phone1', PARAM_CLEAN);
  237. $mform->addElement('text', 'phone2', get_string('phone2'), 'maxlength="20" size="25"');
  238. $mform->setType('phone2', PARAM_CLEAN);
  239. $mform->addElement('text', 'address', get_string('address'), 'maxlength="70" size="25"');
  240. $mform->setType('address', PARAM_MULTILANG);
  241. }
  242. ?>