PageRenderTime 52ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/user/editlib.php

https://bitbucket.org/ceu/moodle_demo
PHP | 302 lines | 239 code | 58 blank | 5 comment | 35 complexity | 6a62fa77da7268721cf5bee2ca0bb437 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, LGPL-2.1
  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. $mform->disabledIf('maildisplay','emailstop');
  100. $choices = array();
  101. $choices['0'] = get_string('emailenable');
  102. $choices['1'] = get_string('emaildisable');
  103. $mform->addElement('select', 'emailstop', get_string('emailactive'), $choices);
  104. $mform->setDefault('emailenable', 1);
  105. $mform->disabledIf('emailstop','maildisplay');
  106. $choices = array();
  107. $choices['0'] = get_string('textformat');
  108. $choices['1'] = get_string('htmlformat');
  109. $mform->addElement('select', 'mailformat', get_string('emailformat'), $choices);
  110. $mform->setDefault('mailformat', 1);
  111. $mform->setAdvanced('mailformat');
  112. if (!empty($CFG->allowusermailcharset)) {
  113. $choices = array();
  114. $charsets = get_list_of_charsets();
  115. if (!empty($CFG->sitemailcharset)) {
  116. $choices['0'] = get_string('site').' ('.$CFG->sitemailcharset.')';
  117. } else {
  118. $choices['0'] = get_string('site').' (UTF-8)';
  119. }
  120. $choices = array_merge($choices, $charsets);
  121. $mform->addElement('select', 'preference_mailcharset', get_string('emailcharset'), $choices);
  122. $mform->setAdvanced('preference_mailcharset');
  123. }
  124. $choices = array();
  125. $choices['0'] = get_string('emaildigestoff');
  126. $choices['1'] = get_string('emaildigestcomplete');
  127. $choices['2'] = get_string('emaildigestsubjects');
  128. $mform->addElement('select', 'maildigest', get_string('emaildigest'), $choices);
  129. $mform->setDefault('maildigest', 0);
  130. $mform->setAdvanced('maildigest');
  131. $choices = array();
  132. $choices['1'] = get_string('autosubscribeyes');
  133. $choices['0'] = get_string('autosubscribeno');
  134. $mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices);
  135. $mform->setDefault('autosubscribe', 1);
  136. $mform->setAdvanced('autosubscribe');
  137. if (!empty($CFG->forum_trackreadposts)) {
  138. $choices = array();
  139. $choices['0'] = get_string('trackforumsno');
  140. $choices['1'] = get_string('trackforumsyes');
  141. $mform->addElement('select', 'trackforums', get_string('trackforums'), $choices);
  142. $mform->setDefault('trackforums', 0);
  143. $mform->setAdvanced('trackforums');
  144. }
  145. if ($CFG->htmleditor) {
  146. $choices = array();
  147. $choices['0'] = get_string('texteditor');
  148. $choices['1'] = get_string('htmleditor');
  149. $mform->addElement('select', 'htmleditor', get_string('textediting'), $choices);
  150. $mform->setDefault('htmleditor', 1);
  151. $mform->setAdvanced('htmleditor');
  152. }
  153. if (empty($CFG->enableajax)) {
  154. $mform->addElement('static', 'ajaxdisabled', get_string('ajaxuse'), get_string('ajaxno'));
  155. $mform->setAdvanced('ajaxdisabled');
  156. } else {
  157. $choices = array();
  158. $choices['0'] = get_string('ajaxno');
  159. $choices['1'] = get_string('ajaxyes');
  160. $mform->addElement('select', 'ajax', get_string('ajaxuse'), $choices);
  161. $mform->setDefault('ajax', 0);
  162. $mform->setAdvanced('ajax');
  163. }
  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');
  170. $mform->addElement('text', 'city', get_string('city'), 'maxlength="20" size="21"');
  171. $mform->setType('city', PARAM_MULTILANG);
  172. $mform->addRule('city', $strrequired, 'required', null, 'client');
  173. $choices = get_list_of_countries();
  174. $choices= array(''=>get_string('selectacountry').'...') + $choices;
  175. $mform->addElement('select', 'country', get_string('selectacountry'), $choices);
  176. $mform->addRule('country', $strrequired, 'required', null, 'client');
  177. if (!empty($CFG->country)) {
  178. $mform->setDefault('country', $CFG->country);
  179. }
  180. $choices = get_list_of_timezones();
  181. $choices['99'] = get_string('serverlocaltime');
  182. if ($CFG->forcetimezone != 99) {
  183. $mform->addElement('static', 'forcedtimezone', get_string('timezone'), $choices[$CFG->forcetimezone]);
  184. } else {
  185. $mform->addElement('select', 'timezone', get_string('timezone'), $choices);
  186. $mform->setDefault('timezone', '99');
  187. }
  188. $mform->addElement('select', 'lang', get_string('preferredlanguage'), get_list_of_languages());
  189. $mform->setDefault('lang', $CFG->lang);
  190. if (!empty($CFG->allowuserthemes)) {
  191. $choices = array();
  192. $choices[''] = get_string('default');
  193. $choices += get_list_of_themes();
  194. $mform->addElement('select', 'theme', get_string('preferredtheme'), $choices);
  195. $mform->setAdvanced('theme');
  196. }
  197. $mform->addElement('htmleditor', 'description', get_string('userdescription'));
  198. $mform->setType('description', PARAM_CLEAN);
  199. $mform->setHelpButton('description', array('text', get_string('helptext')));
  200. if (!empty($CFG->gdversion)) {
  201. $mform->addElement('header', 'moodle_picture', get_string('pictureof'));//TODO: Accessibility fix fieldset legend
  202. $mform->addElement('static', 'currentpicture', get_string('currentpicture'));
  203. $mform->addElement('checkbox', 'deletepicture', get_string('delete'));
  204. $mform->setDefault('deletepicture',false);
  205. $mform->addElement('file', 'imagefile', get_string('newpicture'));
  206. $mform->setHelpButton('imagefile', array('picture', get_string('helppicture')));
  207. $mform->addElement('text', 'imagealt', get_string('imagealt'), 'maxlength="100" size="30"');
  208. $mform->setType('imagealt', PARAM_MULTILANG);
  209. }
  210. if( !empty($CFG->usetags)) {
  211. $mform->addElement('header', 'moodle_interests', get_string('interests'));
  212. $mform->addElement('textarea', 'interests', get_string('interestslist'), 'cols="45" rows="3"');
  213. $mform->setHelpButton('interests', array('interestslist', get_string('helpinterestslist'),
  214. false, true, false));
  215. }
  216. /// Moodle optional fields
  217. $mform->addElement('header', 'moodle_optional', get_string('optional', 'form'));
  218. $mform->setAdvanced('moodle_optional');
  219. $mform->addElement('text', 'url', get_string('webpage'), 'maxlength="255" size="50"');
  220. $mform->setType('url', PARAM_URL);
  221. $mform->addElement('text', 'icq', get_string('icqnumber'), 'maxlength="15" size="25"');
  222. $mform->setType('icq', PARAM_CLEAN);
  223. $mform->addElement('text', 'skype', get_string('skypeid'), 'maxlength="50" size="25"');
  224. $mform->setType('skype', PARAM_CLEAN);
  225. $mform->addElement('text', 'aim', get_string('aimid'), 'maxlength="50" size="25"');
  226. $mform->setType('aim', PARAM_CLEAN);
  227. $mform->addElement('text', 'yahoo', get_string('yahooid'), 'maxlength="50" size="25"');
  228. $mform->setType('yahoo', PARAM_CLEAN);
  229. $mform->addElement('text', 'msn', get_string('msnid'), 'maxlength="50" size="25"');
  230. $mform->setType('msn', PARAM_CLEAN);
  231. $mform->addElement('text', 'idnumber', get_string('idnumber'), 'maxlength="255" size="25"');
  232. $mform->setType('idnumber', PARAM_CLEAN);
  233. $mform->addElement('text', 'institution', get_string('institution'), 'maxlength="40" size="25"');
  234. $mform->setType('institution', PARAM_MULTILANG);
  235. $mform->addElement('text', 'department', get_string('department'), 'maxlength="30" size="25"');
  236. $mform->setType('department', PARAM_MULTILANG);
  237. $mform->addElement('text', 'phone1', get_string('phone'), 'maxlength="20" size="25"');
  238. $mform->setType('phone1', PARAM_CLEAN);
  239. $mform->addElement('text', 'phone2', get_string('phone2'), 'maxlength="20" size="25"');
  240. $mform->setType('phone2', PARAM_CLEAN);
  241. $mform->addElement('text', 'address', get_string('address'), 'maxlength="70" size="25"');
  242. $mform->setType('address', PARAM_MULTILANG);
  243. }
  244. ?>