adding some strings
[moodle-linuxchix.git] / user / editadvanced.php
blob0c9c22cddd298abca8f9e856908167bdc545f7d5
1 <?php // $Id$
3 require_once('../config.php');
4 require_once($CFG->libdir.'/gdlib.php');
5 require_once($CFG->libdir.'/adminlib.php');
6 require_once($CFG->dirroot.'/user/editadvanced_form.php');
7 require_once($CFG->dirroot.'/user/editlib.php');
8 require_once($CFG->dirroot.'/user/profile/lib.php');
10 httpsrequired();
12 $id = optional_param('id', $USER->id, PARAM_INT); // user id; -1 if creating new user
13 $course = optional_param('course', SITEID, PARAM_INT); // course id (defaults to Site)
15 if (!$course = get_record('course', 'id', $course)) {
16 error('Course ID was incorrect');
18 require_login($course->id);
20 if ($id == -1) {
21 // creating new user
22 require_capability('moodle/user:create', get_context_instance(CONTEXT_SYSTEM));
23 $user = new object();
24 $user->id = -1;
25 $user->auth = 'manual';
26 $user->confirmed = 1;
27 } else {
28 // editing existing user
29 require_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM));
30 if (!$user = get_record('user', 'id', $id)) {
31 error('User ID was incorrect');
35 // remote users cannot be edited
36 if ($user->id != -1 and is_mnet_remote_user($user)) {
37 redirect($CFG->wwwroot . "/user/view.php?id=$id&course={$course->id}");
40 $mainadmin = get_admin();
41 if ($user->id != $USER->id and $user->id == $mainadmin->id) { // Can't edit primary admin
42 print_error('adminprimarynoedit');
45 if (isguestuser($user->id)) { // the real guest user can not be edited
46 print_error('guestnoeditprofileother');
49 //load user preferences
50 useredit_load_preferences($user);
52 //Load custom profile fields data
53 profile_load_data($user);
55 //create form
56 $userform = new user_editadvanced_form();
57 $userform->set_data($user);
59 if ($usernew = $userform->get_data()) {
60 add_to_log($course->id, 'user', 'update', "view.php?id=$user->id&course=$course->id", '');
62 if (empty($usernew->auth)) {
63 //user editing self
64 $authplugin = get_auth_plugin($user->auth);
65 unset($usernew->auth); //can not change/remove
66 } else {
67 $authplugin = get_auth_plugin($usernew->auth);
70 $usernew->username = trim($usernew->username);
71 $usernew->timemodified = time();
73 if ($usernew->id == -1) {
74 //TODO check out if it makes sense to create account with this auth plugin and what to do with the password
75 unset($usernew->id);
76 $usernew->mnethostid = $CFG->mnet_localhost_id; // always local user
77 $usernew->confirmed = 1;
78 $usernew->password = hash_internal_user_password($usernew->newpassword);
79 if (!$usernew->id = insert_record('user', $usernew)) {
80 error('Error creating user record');
82 } else {
83 if (!update_record('user', $usernew)) {
84 error('Error updating user record');
86 // pass a true $userold here
87 if (! $authplugin->user_update($user, $userform->get_data(false))) {
88 // auth update failed, rollback for moodle
89 update_record('user', addslashes_object($user));
90 error('Failed to update user data on external auth: '.$user->auth.
91 '. See the server logs for more details.');
94 //set new password if specified
95 if (!empty($usernew->newpassword)) {
96 if ($authplugin->can_change_password()) {
97 if (!$authplugin->user_update_password($usernew, $usernew->newpassword)){
98 error('Failed to update password on external auth: ' . $usernew->auth .
99 '. See the server logs for more details.');
104 // MDL-9983
105 events_trigger('user_updated', $usernew);
108 //update preferences
109 useredit_update_user_preference($usernew);
111 //update user picture
112 if (!empty($CFG->gdversion)) {
113 useredit_update_picture($usernew, $userform);
116 // update mail bounces
117 useredit_update_bounces($user, $usernew);
119 /// update forum track preference
120 useredit_update_trackforums($user, $usernew);
122 // save custom profile fields data
123 profile_save_data($usernew);
125 if ($user->id == $USER->id) {
126 // Override old $USER session variable
127 $usernew = (array)get_record('user', 'id', $usernew->id); // reload from db
128 foreach ($usernew as $variable => $value) {
129 $USER->$variable = $value;
131 if (!empty($USER->newadminuser)) {
132 unset($USER->newadminuser);
133 // redirect to admin/ to continue with installation
134 redirect("$CFG->wwwroot/$CFG->admin/");
135 } else {
136 redirect("$CFG->wwwroot/user/view.php?id=$USER->id&course=$course->id");
138 } else {
139 redirect("$CFG->wwwroot/$CFG->admin/user.php");
141 //never reached
145 /// Display page header
146 if ($user->id == -1 or ($user->id != $USER->id)) {
147 if ($user->id == -1) {
148 admin_externalpage_setup('addnewuser');
149 admin_externalpage_print_header();
150 } else {
151 admin_externalpage_setup('editusers');
152 admin_externalpage_print_header();
153 $userfullname = fullname($user, true);
154 print_heading($userfullname);
156 } else if (!empty($USER->newadminuser)) {
157 $strprimaryadminsetup = get_string('primaryadminsetup');
158 print_header($strprimaryadminsetup, $strprimaryadminsetup);
159 print_simple_box(get_string('configintroadmin', 'admin'), 'center', '50%');
160 echo '<br />';
161 } else {
162 $streditmyprofile = get_string('editmyprofile');
163 $strparticipants = get_string('participants');
164 $strnewuser = get_string('newuser');
165 $userfullname = fullname($user, true);
166 if ($course->id != SITEID) {
167 print_header("$course->shortname: $streditmyprofile", "$course->fullname: $streditmyprofile",
168 "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a>
169 -> <a href=\"index.php?id=$course->id\">$strparticipants</a>
170 -> <a href=\"view.php?id=$user->id&amp;course=$course->id\">$userfullname</a>
171 -> $streditmyprofile", "");
172 } else {
173 print_header("$course->shortname: $streditmyprofile", $course->fullname,
174 "<a href=\"view.php?id=$user->id&amp;course=$course->id\">$userfullname</a>
175 -> $streditmyprofile", "");
177 /// Print tabs at the top
178 $showroles = 1;
179 $currenttab = 'editprofile';
180 require('tabs.php');
183 /// Finally display THE form
184 $userform->display();
186 /// and proper footer
187 if (!empty($USER->newadminuser)) {
188 print_footer('none');
189 } else {
190 print_footer($course);