MDL-8857
[moodle-linuxchix.git] / user / edit.php
blob10b5461cf7a3d74eceda3a6293f8d369e4f3a0b1
1 <?php // $Id$
3 require_once('../config.php');
4 require_once($CFG->libdir.'/gdlib.php');
5 require_once($CFG->dirroot.'/user/edit_form.php');
6 require_once($CFG->dirroot.'/user/editlib.php');
7 require_once($CFG->dirroot.'/user/profile/lib.php');
9 httpsrequired();
11 $course = optional_param('course', SITEID, PARAM_INT); // course id (defaults to Site)
13 if (!$course = get_record('course', 'id', $course)) {
14 error('Course ID was incorrect');
17 if ($course->id != SITEID) {
18 require_login($course);
19 } else if (!isloggedin()) {
20 if (empty($SESSION->wantsurl)) {
21 $SESSION->wantsurl = $CFG->httpswwwroot.'/edit/user.php';
23 redirect($CFG->httpswwwroot.'/login/index.php');
26 if (isguest()) { //TODO: add proper capability to edit own profile and change password too
27 print_error('guestnoeditprofile');
29 if (!$user = get_record('user', 'id', $USER->id)) {
30 error('User ID was incorrect');
33 // remote users cannot be edited
34 if (is_mnet_remote_user($user)) {
35 redirect($CFG->wwwroot . "/user/view.php?course={$course->id}");
38 //load user preferences
39 useredit_load_preferences($user);
41 //Load custom profile fields data
42 profile_load_data($user);
44 //create form
45 $userform = new user_edit_form();
46 $userform->set_data($user);
48 if ($usernew = $userform->get_data()) {
49 add_to_log($course->id, 'user', 'update', "view.php?id=$user->id&course=$course->id", '');
51 $authplugin = get_auth_plugin($user->auth);
53 $usernew->timemodified = time();
55 if (update_record('user', $usernew)) {
56 if (method_exists($authplugin, 'user_update')){
57 // pass a true $userold here
58 if (! $authplugin->user_update($user, $userform->get_data(false))) {
59 // auth update failed, rollback for moodle
60 update_record('user', addslashes_object($user));
61 error('Failed to update user data on external auth: '.$usernew->auth.
62 '. See the server logs for more details.');
65 } else {
66 error('Error updating user record');
69 //update preferences
70 useredit_update_user_preference($usernew);
72 //update user picture
73 if (!empty($CFG->gdversion) and empty($CFG->disableuserimages)) {
74 useredit_update_picture($usernew, $userform);
77 // update mail bounces
78 useredit_update_bounces($user, $usernew);
80 /// update forum track preference
81 useredit_update_trackforums($user, $usernew);
83 // save custom profile fields data
84 profile_save_data($usernew);
86 // Override old $USER session variable
87 $usernew = (array)get_record('user', 'id', $usernew->id); // reload from db
88 foreach ($usernew as $variable => $value) {
89 $USER->$variable = $value;
92 redirect("$CFG->wwwroot/user/view.php?id=$USER->id&course=$course->id");
96 /// Display page header
97 $streditmyprofile = get_string('editmyprofile');
98 $strparticipants = get_string('participants');
99 $userfullname = fullname($user, true);
100 if ($course->id != SITEID) {
101 print_header("$course->shortname: $streditmyprofile", "$course->fullname: $streditmyprofile",
102 "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a>
103 -> <a href=\"index.php?id=$course->id\">$strparticipants</a>
104 -> <a href=\"view.php?id=$user->id&amp;course=$course->id\">$userfullname</a>
105 -> $streditmyprofile", "");
106 } else {
107 print_header("$course->shortname: $streditmyprofile", $course->fullname,
108 "<a href=\"view.php?id=$user->id&amp;course=$course->id\">$userfullname</a>
109 -> $streditmyprofile", "");
111 /// Print tabs at the top
112 $showroles = 1;
113 $currenttab = 'editprofile';
114 require('tabs.php');
116 /// Finally display THE form
117 $userform->display();
119 /// and proper footer
120 print_footer($course);