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)
|
2008-07-05 14:28:13 +00:00
|
|
|
$cancelemailchange = optional_param('cancelemailchange', false, PARAM_INT); // course id (defaults to Site)
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2008-05-30 22:11:31 +00:00
|
|
|
if (!$course = $DB->get_record('course', array('id'=>$course))) {
|
2008-06-13 07:07:45 +00:00
|
|
|
print_error('invalidcourseid');
|
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)) {
|
2008-01-18 17:13:56 +00:00
|
|
|
$SESSION->wantsurl = $CFG->httpswwwroot.'/user/edit.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-09-03 08:36:31 +00:00
|
|
|
// Guest can not edit
|
2007-04-26 21:41:08 +00:00
|
|
|
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
|
|
|
|
2007-09-03 08:36:31 +00:00
|
|
|
// The user profile we are editing
|
2008-05-30 22:11:31 +00:00
|
|
|
if (!$user = $DB->get_record('user', array('id'=>$userid))) {
|
2008-06-13 07:07:45 +00:00
|
|
|
print_error('invaliduserid');
|
2002-09-26 07:03:22 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2007-09-03 08:36:31 +00:00
|
|
|
// Guest can not be edited
|
2008-07-05 14:28:13 +00:00
|
|
|
if (isguestuser($user)) {
|
2007-09-03 08:36:31 +00:00
|
|
|
print_error('guestnoeditprofile');
|
|
|
|
}
|
|
|
|
|
|
|
|
// User interests separated by commas
|
2007-07-31 08:09:46 +00:00
|
|
|
if (!empty($CFG->usetags)) {
|
|
|
|
require_once($CFG->dirroot.'/tag/lib.php');
|
2008-02-26 12:46:51 +00:00
|
|
|
$user->interests = tag_get_tags_csv('user', $user->id, TAG_RETURN_TEXT);
|
2007-07-31 08:09:46 +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
|
|
|
}
|
|
|
|
|
2008-01-09 16:46:21 +00:00
|
|
|
if ($course->id == SITEID) {
|
|
|
|
$coursecontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context
|
|
|
|
} else {
|
|
|
|
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); // Course context
|
|
|
|
}
|
2007-09-16 09:21:29 +00:00
|
|
|
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
|
|
|
|
$personalcontext = get_context_instance(CONTEXT_USER, $user->id);
|
|
|
|
|
2007-03-14 23:37:28 +00:00
|
|
|
// check access control
|
2007-04-26 21:41:08 +00:00
|
|
|
if ($user->id == $USER->id) {
|
2007-12-15 16:57:20 +00:00
|
|
|
//editing own profile - require_login() MUST NOT be used here, it would result in infinite loop!
|
|
|
|
if (!has_capability('moodle/user:editownprofile', $systemcontext)) {
|
2008-06-13 07:07:45 +00:00
|
|
|
print_error('cannotedityourprofile');
|
2007-12-15 16:57:20 +00:00
|
|
|
}
|
2007-04-26 21:41:08 +00:00
|
|
|
|
|
|
|
} 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!
|
2008-01-26 17:00:03 +00:00
|
|
|
if (is_primary_admin($user->id)) {
|
2007-03-14 23:37:28 +00:00
|
|
|
print_error('adminprimarynoedit');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-05 14:52:39 +00:00
|
|
|
if ($user->deleted) {
|
|
|
|
print_header();
|
|
|
|
print_heading(get_string('userdeleted'));
|
|
|
|
print_footer($course);
|
|
|
|
die;
|
|
|
|
}
|
|
|
|
|
2008-07-05 22:46:31 +00:00
|
|
|
// Process email change cancellation
|
|
|
|
if ($cancelemailchange) {
|
|
|
|
cancel_email_update($user->id);
|
|
|
|
}
|
|
|
|
|
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-08-17 19:09:11 +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
|
|
|
|
2008-07-05 14:28:13 +00:00
|
|
|
$email_changed = false;
|
|
|
|
|
2008-06-09 16:53:30 +00:00
|
|
|
if ($usernew = $userform->get_data()) {
|
2007-07-31 08:09:46 +00:00
|
|
|
|
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
|
|
|
|
2008-07-05 14:28:13 +00:00
|
|
|
$email_changed_html = '';
|
|
|
|
|
|
|
|
if ($CFG->emailchangeconfirmation) {
|
|
|
|
// Handle change of email carefully for non-trusted users
|
|
|
|
if ($user->email != $usernew->email && !has_capability('moodle/user:update', $systemcontext)) {
|
|
|
|
$a = new stdClass();
|
|
|
|
$a->newemail = $usernew->preference_newemail = $usernew->email;
|
|
|
|
$usernew->preference_newemailkey = random_string(20);
|
|
|
|
$usernew->preference_newemailattemptsleft = 3;
|
|
|
|
$a->oldemail = $usernew->email = $user->email;
|
|
|
|
|
|
|
|
$email_changed_html = print_box(get_string('auth_changingemailaddress', 'auth', $a), 'generalbox', 'notice', true);
|
|
|
|
$email_changed_html .= print_continue("$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id", true);
|
|
|
|
$email_changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2008-05-30 22:11:31 +00:00
|
|
|
if (!$DB->update_record('user', $usernew)) {
|
2008-06-13 07:07:45 +00:00
|
|
|
print_error('cannotupdateprofile');
|
2007-01-25 18:02:48 +00:00
|
|
|
}
|
2007-01-05 02:18:53 +00:00
|
|
|
|
2007-03-22 12:27:52 +00:00
|
|
|
// pass a true $userold here
|
2008-06-09 16:53:30 +00:00
|
|
|
if (! $authplugin->user_update($user, $userform->get_data())) {
|
2007-03-22 12:27:52 +00:00
|
|
|
// auth update failed, rollback for moodle
|
2008-05-30 22:11:31 +00:00
|
|
|
$DB->update_record('user', $user);
|
2008-06-13 07:07:45 +00:00
|
|
|
print_error('cannotupdateprofile');
|
2007-03-22 12:27:52 +00:00
|
|
|
}
|
|
|
|
|
2007-01-25 18:02:48 +00:00
|
|
|
//update preferences
|
2007-01-26 18:42:47 +00:00
|
|
|
useredit_update_user_preference($usernew);
|
2007-08-17 19:09:11 +00:00
|
|
|
|
2007-07-31 08:09:46 +00:00
|
|
|
//update interests
|
|
|
|
if (!empty($CFG->usetags)) {
|
|
|
|
useredit_update_interests($usernew, $usernew->interests);
|
|
|
|
}
|
2007-08-17 19:09:11 +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
|
|
|
|
2008-07-05 14:28:13 +00:00
|
|
|
// If email was changed, send confirmation email now
|
|
|
|
if ($email_changed && $CFG->emailchangeconfirmation) {
|
|
|
|
$temp_user = fullclone($user);
|
|
|
|
$temp_user->email = $usernew->preference_newemail;
|
2008-07-10 08:07:55 +00:00
|
|
|
$temp_user->emailstop = NULL;
|
2008-07-05 14:28:13 +00:00
|
|
|
|
|
|
|
$a = new stdClass();
|
|
|
|
$a->url = $CFG->wwwroot . '/user/emailupdate.php?key=' . $usernew->preference_newemailkey . '&id=' . $user->id;
|
|
|
|
$a->site = $SITE->fullname;
|
|
|
|
$a->fullname = fullname($user, true);
|
|
|
|
|
|
|
|
$emailupdatemessage = get_string('auth_emailupdatemessage', 'auth', $a);
|
|
|
|
$emailupdatetitle = get_string('auth_emailupdatetitle', 'auth', $a);
|
|
|
|
|
2008-07-10 08:07:55 +00:00
|
|
|
if (!$mail_results = email_to_user($temp_user, get_admin(), $emailupdatetitle, $emailupdatemessage)) {
|
2008-07-05 14:28:13 +00:00
|
|
|
die("could not send email!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-06 17:57:06 +00:00
|
|
|
// reload from db
|
|
|
|
$usernew = $DB->get_record('user', array('id'=>$user->id));
|
|
|
|
events_trigger('user_updated', $usernew);
|
|
|
|
|
2007-03-14 23:37:28 +00:00
|
|
|
if ($USER->id == $user->id) {
|
|
|
|
// Override old $USER session variable if needed
|
2008-07-06 17:57:06 +00:00
|
|
|
foreach ((array)$usernew as $variable => $value) {
|
2007-03-14 23:37:28 +00:00
|
|
|
$USER->$variable = $value;
|
|
|
|
}
|
2007-01-25 18:18:33 +00:00
|
|
|
}
|
2008-07-05 14:28:13 +00:00
|
|
|
|
|
|
|
if (!$email_changed || !$CFG->emailchangeconfirmation) {
|
|
|
|
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);
|
2007-08-17 19:09:11 +00:00
|
|
|
|
|
|
|
$navlinks = array();
|
2008-01-09 16:46:21 +00:00
|
|
|
if (has_capability('moodle/course:viewparticipants', $coursecontext) || has_capability('moodle/site:viewparticipants', $systemcontext)) {
|
|
|
|
$navlinks[] = array('name' => $strparticipants, 'link' => "index.php?id=$course->id", 'type' => 'misc');
|
|
|
|
}
|
2007-08-17 19:09:11 +00:00
|
|
|
$navlinks[] = array('name' => $userfullname,
|
|
|
|
'link' => "view.php?id=$user->id&course=$course->id",
|
|
|
|
'type' => 'misc');
|
|
|
|
$navlinks[] = array('name' => $streditmyprofile, 'link' => null, 'type' => 'misc');
|
|
|
|
$navigation = build_navigation($navlinks);
|
|
|
|
print_header("$course->shortname: $streditmyprofile", $course->fullname, $navigation, "");
|
|
|
|
|
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
|
|
|
|
2008-07-05 14:28:13 +00:00
|
|
|
if ($email_changed) {
|
|
|
|
echo $email_changed_html;
|
|
|
|
} else {
|
|
|
|
/// Finally display THE form
|
|
|
|
$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
|
|
|
?>
|