MDL-10286 Updated overlib.js (2 years diff!) and enabled overlib for HTML feedback...
[moodle-pu.git] / user / edit.php
blob7fa95dcd29dd892156ef89a54038116e1fe6b086
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 $userid = optional_param('id', $USER->id, PARAM_INT); // user id
12 $course = optional_param('course', SITEID, PARAM_INT); // course id (defaults to Site)
14 if (!$course = get_record('course', 'id', $course)) {
15 error('Course ID was incorrect');
18 if ($course->id != SITEID) {
19 require_login($course);
20 } else if (!isloggedin()) {
21 if (empty($SESSION->wantsurl)) {
22 $SESSION->wantsurl = $CFG->httpswwwroot.'/edit/user.php';
24 redirect($CFG->httpswwwroot.'/login/index.php');
27 $systemcontext = get_context_instance(CONTEXT_SYSTEM);
28 $personalcontext = get_context_instance(CONTEXT_USER, $user->id);
30 if (isguestuser()) {
31 print_error('guestnoeditprofile');
34 if (!$user = get_record('user', 'id', $userid)) {
35 error('User ID was incorrect');
38 // remote users cannot be edited
39 if (is_mnet_remote_user($user)) {
40 redirect($CFG->wwwroot . "/user/view.php?course={$course->id}");
43 // check access control
44 if ($user->id == $USER->id) {
45 //editing own profile
46 require_capability('moodle/user:editownprofile', $systemcontext);
48 } else {
49 // teachers, parents, etc.
50 require_capability('moodle/user:editprofile', $personalcontext);
51 // no editing of guest user account
52 if (isguestuser($user->id)) {
53 print_error('guestnoeditprofileother');
55 // no editing of primary admin!
56 $mainadmin = get_admin();
57 if ($user->id == $mainadmin->id) {
58 print_error('adminprimarynoedit');
62 //load user preferences
63 useredit_load_preferences($user);
65 //Load custom profile fields data
66 profile_load_data($user);
68 //create form
69 $userform = new user_edit_form();
70 $userform->set_data($user);
72 if ($usernew = $userform->get_data()) {
73 add_to_log($course->id, 'user', 'update', "view.php?id=$user->id&course=$course->id", '');
75 $authplugin = get_auth_plugin($user->auth);
77 $usernew->timemodified = time();
79 if (!update_record('user', $usernew)) {
80 error('Error updating user record');
83 // pass a true $userold here
84 if (! $authplugin->user_update($user, $userform->get_data(false))) {
85 // auth update failed, rollback for moodle
86 update_record('user', addslashes_object($user));
87 error('Failed to update user data on external auth: '.$user->auth.
88 '. See the server logs for more details.');
91 //update preferences
92 useredit_update_user_preference($usernew);
94 //update user picture
95 if (!empty($CFG->gdversion) and empty($CFG->disableuserimages)) {
96 useredit_update_picture($usernew, $userform);
99 // update mail bounces
100 useredit_update_bounces($user, $usernew);
102 /// update forum track preference
103 useredit_update_trackforums($user, $usernew);
105 // save custom profile fields data
106 profile_save_data($usernew);
108 if ($USER->id == $user->id) {
109 // Override old $USER session variable if needed
110 $usernew = (array)get_record('user', 'id', $user->id); // reload from db
111 foreach ($usernew as $variable => $value) {
112 $USER->$variable = $value;
115 events_trigger('user_updated', $usernew);
116 redirect("$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id");
120 /// Display page header
121 $streditmyprofile = get_string('editmyprofile');
122 $strparticipants = get_string('participants');
123 $userfullname = fullname($user, true);
124 if ($course->id != SITEID) {
125 print_header("$course->shortname: $streditmyprofile", "$course->fullname: $streditmyprofile",
126 "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a>
127 -> <a href=\"index.php?id=$course->id\">$strparticipants</a>
128 -> <a href=\"view.php?id=$user->id&amp;course=$course->id\">$userfullname</a>
129 -> $streditmyprofile", "");
130 } else {
131 print_header("$course->shortname: $streditmyprofile", $course->fullname,
132 "<a href=\"view.php?id=$user->id&amp;course=$course->id\">$userfullname</a>
133 -> $streditmyprofile", "");
135 /// Print tabs at the top
136 $showroles = 1;
137 $currenttab = 'editprofile';
138 require('tabs.php');
140 /// Finally display THE form
141 $userform->display();
143 /// and proper footer
144 print_footer($course);