Output was missing utf8 meta tag.
[moodle-linuxchix.git] / user / edit.php
blob81adcbb434173b41fde0ff4b07d12196664cdd80
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 require_login($course->id);
19 if (isguest()) { //TODO: add proper capability to edit own profile and change password too
20 print_error('guestnoeditprofile');
23 if (!$user = get_record('user', 'id', $USER->id)) {
24 error('User ID was incorrect');
27 // remote users cannot be edited
28 if (is_mnet_remote_user($user)) {
29 redirect($CFG->wwwroot . "/user/view.php?course={$course->id}");
32 //load user preferences
33 useredit_load_preferences($user);
35 //Load custom profile fields data
36 profile_load_data($user);
38 //create form
39 $userform = new user_edit_form();
40 $userform->set_data($user);
42 if ($usernew = $userform->get_data()) {
43 add_to_log($course->id, 'user', 'update', "view.php?id=$user->id&course=$course->id", '');
45 $authplugin = get_auth_plugin($user->auth);
47 $usernew->timemodified = time();
49 if (update_record('user', $usernew)) {
50 if (method_exists($authplugin, 'user_update')){
51 // pass a true $userold here
52 if (! $authplugin->user_update($user, $userform->get_data(false))) {
53 // auth update failed, rollback for moodle
54 update_record('user', addslashes_object($user));
55 error('Failed to update user data on external auth: '.$usernew->auth.
56 '. See the server logs for more details.');
59 } else {
60 error('Error updating user record');
63 //update preferences
64 useredit_update_user_preference($usernew);
66 //update user picture
67 if (!empty($CFG->gdversion) and empty($CFG->disableuserimages)) {
68 useredit_update_picture($usernew, $userform);
71 // update mail bounces
72 useredit_update_bounces($user, $usernew);
74 /// update forum track preference
75 useredit_update_trackforums($user, $usernew);
77 // save custom profile fields data
78 profile_save_data($usernew);
80 // Override old $USER session variable
81 $usernew = (array)get_record('user', 'id', $usernew->id); // reload from db
82 foreach ($usernew as $variable => $value) {
83 $USER->$variable = $value;
86 redirect("$CFG->wwwroot/user/view.php?id=$USER->id&course=$course->id");
90 /// Display page header
91 $streditmyprofile = get_string('editmyprofile');
92 $strparticipants = get_string('participants');
93 $userfullname = fullname($user, true);
94 if ($course->id != SITEID) {
95 print_header("$course->shortname: $streditmyprofile", "$course->fullname: $streditmyprofile",
96 "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a>
97 -> <a href=\"index.php?id=$course->id\">$strparticipants</a>
98 -> <a href=\"view.php?id=$user->id&amp;course=$course->id\">$userfullname</a>
99 -> $streditmyprofile", "");
100 } else {
101 print_header("$course->shortname: $streditmyprofile", "$course->fullname",
102 "<a href=\"view.php?id=$user->id&amp;course=$course->id\">$userfullname</a>
103 -> $streditmyprofile", "");
105 /// Print tabs at the top
106 $showroles = 1;
107 $currenttab = 'editprofile';
108 require('tabs.php');
110 /// Finally display THE form
111 $userform->display();
113 /// and proper footer
114 print_footer($course);