2004-10-06 16:52:24 +00:00
|
|
|
<?php // $Id$
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2007-01-25 18:02:48 +00:00
|
|
|
require_once('../config.php');
|
|
|
|
require_once($CFG->libdir.'/gdlib.php');
|
|
|
|
require_once($CFG->dirroot.'/user/edit_form.php');
|
2007-01-26 18:42:47 +00:00
|
|
|
require_once($CFG->dirroot.'/user/editlib.php');
|
2007-01-25 18:02:48 +00:00
|
|
|
require_once($CFG->dirroot.'/user/profile/lib.php');
|
2007-01-05 02:18:53 +00:00
|
|
|
|
2007-01-27 19:56:08 +00:00
|
|
|
httpsrequired();
|
|
|
|
|
2007-03-14 23:37:28 +00:00
|
|
|
$userid = optional_param('id', $USER->id, PARAM_INT); // user id
|
2005-04-04 03:42:01 +00:00
|
|
|
$course = optional_param('course', SITEID, PARAM_INT); // course id (defaults to Site)
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2007-01-25 18:02:48 +00:00
|
|
|
if (!$course = get_record('course', 'id', $course)) {
|
|
|
|
error('Course ID was incorrect');
|
2004-09-25 12:53:35 +00:00
|
|
|
}
|
2004-09-21 11:41:58 +00:00
|
|
|
|
2007-02-15 20:43:00 +00:00
|
|
|
if ($course->id != SITEID) {
|
|
|
|
require_login($course);
|
|
|
|
} else if (!isloggedin()) {
|
2007-02-15 20:46:39 +00:00
|
|
|
if (empty($SESSION->wantsurl)) {
|
|
|
|
$SESSION->wantsurl = $CFG->httpswwwroot.'/edit/user.php';
|
2007-02-15 20:43:00 +00:00
|
|
|
}
|
2007-02-15 20:46:39 +00:00
|
|
|
redirect($CFG->httpswwwroot.'/login/index.php');
|
2007-02-15 20:43:00 +00:00
|
|
|
}
|
2007-01-09 04:59:56 +00:00
|
|
|
|
2007-04-26 21:41:08 +00:00
|
|
|
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
|
|
|
|
$personalcontext = get_context_instance(CONTEXT_USER, $user->id);
|
|
|
|
|
|
|
|
if (isguestuser()) {
|
2007-01-25 18:02:48 +00:00
|
|
|
print_error('guestnoeditprofile');
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
2007-03-14 23:37:28 +00:00
|
|
|
|
|
|
|
if (!$user = get_record('user', 'id', $userid)) {
|
2007-01-25 18:02:48 +00:00
|
|
|
error('User ID was incorrect');
|
2002-09-26 07:03:22 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2007-01-04 03:01:30 +00:00
|
|
|
// remote users cannot be edited
|
|
|
|
if (is_mnet_remote_user($user)) {
|
2007-01-25 18:02:48 +00:00
|
|
|
redirect($CFG->wwwroot . "/user/view.php?course={$course->id}");
|
2007-01-04 03:01:30 +00:00
|
|
|
}
|
|
|
|
|
2007-03-14 23:37:28 +00:00
|
|
|
// check access control
|
2007-04-26 21:41:08 +00:00
|
|
|
if ($user->id == $USER->id) {
|
|
|
|
//editing own profile
|
|
|
|
require_capability('moodle/user:editownprofile', $systemcontext);
|
|
|
|
|
|
|
|
} else {
|
2007-03-14 23:37:28 +00:00
|
|
|
// teachers, parents, etc.
|
|
|
|
require_capability('moodle/user:editprofile', $personalcontext);
|
|
|
|
// no editing of guest user account
|
|
|
|
if (isguestuser($user->id)) {
|
|
|
|
print_error('guestnoeditprofileother');
|
|
|
|
}
|
|
|
|
// no editing of primary admin!
|
|
|
|
$mainadmin = get_admin();
|
|
|
|
if ($user->id == $mainadmin->id) {
|
|
|
|
print_error('adminprimarynoedit');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-26 18:42:47 +00:00
|
|
|
//load user preferences
|
|
|
|
useredit_load_preferences($user);
|
|
|
|
|
|
|
|
//Load custom profile fields data
|
|
|
|
profile_load_data($user);
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2007-01-25 18:02:48 +00:00
|
|
|
//create form
|
|
|
|
$userform = new user_edit_form();
|
2007-01-25 11:03:33 +00:00
|
|
|
$userform->set_data($user);
|
2007-01-05 02:18:53 +00:00
|
|
|
|
2007-01-12 18:52:09 +00:00
|
|
|
if ($usernew = $userform->get_data()) {
|
2007-01-25 18:02:48 +00:00
|
|
|
add_to_log($course->id, 'user', 'update', "view.php?id=$user->id&course=$course->id", '');
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2007-01-25 18:02:48 +00:00
|
|
|
$authplugin = get_auth_plugin($user->auth);
|
2002-08-08 14:17:55 +00:00
|
|
|
|
2007-01-05 02:18:53 +00:00
|
|
|
$usernew->timemodified = time();
|
2004-09-21 11:41:58 +00:00
|
|
|
|
2007-03-22 12:27:52 +00:00
|
|
|
if (!update_record('user', $usernew)) {
|
2007-01-25 18:02:48 +00:00
|
|
|
error('Error updating user record');
|
|
|
|
}
|
2007-01-05 02:18:53 +00:00
|
|
|
|
2007-03-22 12:27:52 +00:00
|
|
|
// pass a true $userold here
|
|
|
|
if (! $authplugin->user_update($user, $userform->get_data(false))) {
|
|
|
|
// auth update failed, rollback for moodle
|
|
|
|
update_record('user', addslashes_object($user));
|
|
|
|
error('Failed to update user data on external auth: '.$usernew->auth.
|
|
|
|
'. See the server logs for more details.');
|
|
|
|
}
|
|
|
|
|
2007-01-25 18:02:48 +00:00
|
|
|
//update preferences
|
2007-01-26 18:42:47 +00:00
|
|
|
useredit_update_user_preference($usernew);
|
2002-06-05 03:15:30 +00:00
|
|
|
|
2007-01-26 18:42:47 +00:00
|
|
|
//update user picture
|
2007-01-25 18:02:48 +00:00
|
|
|
if (!empty($CFG->gdversion) and empty($CFG->disableuserimages)) {
|
2007-01-26 18:42:47 +00:00
|
|
|
useredit_update_picture($usernew, $userform);
|
2003-04-27 14:50:03 +00:00
|
|
|
}
|
2006-05-21 20:21:35 +00:00
|
|
|
|
2007-01-25 18:02:48 +00:00
|
|
|
// update mail bounces
|
2007-01-26 18:42:47 +00:00
|
|
|
useredit_update_bounces($user, $usernew);
|
2002-08-14 01:51:58 +00:00
|
|
|
|
2007-01-26 18:42:47 +00:00
|
|
|
/// update forum track preference
|
|
|
|
useredit_update_trackforums($user, $usernew);
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2007-01-26 18:42:47 +00:00
|
|
|
// save custom profile fields data
|
|
|
|
profile_save_data($usernew);
|
2005-03-20 12:02:14 +00:00
|
|
|
|
2007-03-14 23:37:28 +00:00
|
|
|
if ($USER->id == $user->id) {
|
|
|
|
// Override old $USER session variable if needed
|
|
|
|
$usernew = (array)get_record('user', 'id', $user->id); // reload from db
|
|
|
|
foreach ($usernew as $variable => $value) {
|
|
|
|
$USER->$variable = $value;
|
|
|
|
}
|
2007-01-25 18:18:33 +00:00
|
|
|
}
|
|
|
|
|
2007-03-14 23:37:28 +00:00
|
|
|
redirect("$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id");
|
2003-05-06 15:58:20 +00:00
|
|
|
}
|
|
|
|
|
2004-09-23 03:56:53 +00:00
|
|
|
|
2007-01-25 18:02:48 +00:00
|
|
|
/// Display page header
|
|
|
|
$streditmyprofile = get_string('editmyprofile');
|
|
|
|
$strparticipants = get_string('participants');
|
|
|
|
$userfullname = fullname($user, true);
|
|
|
|
if ($course->id != SITEID) {
|
|
|
|
print_header("$course->shortname: $streditmyprofile", "$course->fullname: $streditmyprofile",
|
|
|
|
"<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a>
|
|
|
|
-> <a href=\"index.php?id=$course->id\">$strparticipants</a>
|
|
|
|
-> <a href=\"view.php?id=$user->id&course=$course->id\">$userfullname</a>
|
|
|
|
-> $streditmyprofile", "");
|
2006-04-16 16:49:28 +00:00
|
|
|
} else {
|
2007-02-28 06:25:22 +00:00
|
|
|
print_header("$course->shortname: $streditmyprofile", $course->fullname,
|
2007-01-25 18:02:48 +00:00
|
|
|
"<a href=\"view.php?id=$user->id&course=$course->id\">$userfullname</a>
|
|
|
|
-> $streditmyprofile", "");
|
2006-04-16 16:49:28 +00:00
|
|
|
}
|
2007-01-25 18:02:48 +00:00
|
|
|
/// Print tabs at the top
|
|
|
|
$showroles = 1;
|
|
|
|
$currenttab = 'editprofile';
|
|
|
|
require('tabs.php');
|
2006-04-16 16:49:28 +00:00
|
|
|
|
2007-01-25 18:02:48 +00:00
|
|
|
/// Finally display THE form
|
2007-01-05 02:18:53 +00:00
|
|
|
$userform->display();
|
2004-09-23 03:56:53 +00:00
|
|
|
|
2007-01-25 18:02:48 +00:00
|
|
|
/// and proper footer
|
|
|
|
print_footer($course);
|
2003-05-06 15:58:20 +00:00
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
?>
|