3 require_once('../config.php');
4 require_once($CFG->libdir
.'/adminlib.php');
5 require_once($CFG->dirroot
.'/user/editlib.php');
7 $key = required_param('key', PARAM_ALPHANUM
);
8 $id = required_param('id', PARAM_INT
);
10 if (!$user = get_record('user', 'id', $id)) {
11 error("Unknown user ID");
14 $preferences = get_user_preferences(null, null, $user->id
);
16 $a->fullname
= fullname($user, true);
17 $stremailupdate = get_string('auth_emailupdate', 'auth', $a);
18 print_header(format_string($SITE->fullname
) . ": $stremailupdate", format_string($SITE->fullname
) . ": $stremailupdate");
20 if (empty($preferences['newemailattemptsleft'])) {
21 redirect("$CFG->wwwroot/user/view.php?id=$user->id");
23 } elseif ($preferences['newemailattemptsleft'] < 1) {
24 cancel_email_update($user->id
);
25 $stroutofattempts = get_string('auth_outofnewemailupdateattempts', 'auth');
26 print_box($stroutofattempts, 'center');
28 } elseif ($key == $preferences['newemailkey']) {
29 cancel_email_update($user->id
);
30 $user->email
= $preferences['newemail'];
32 // Detect duplicate before saving
33 if (get_record('user', 'email', addslashes($user->email
))) {
34 $stremailnowexists = get_string('auth_emailnowexists', 'auth');
35 print_box($stremailnowexists, 'center');
36 print_continue("$CFG->wwwroot/user/view.php?id=$user->id");
39 if (!set_field('user', 'email', addslashes($user->email
), 'id', $user->id
)) {
40 error('Error updating user record');
43 events_trigger('user_updated', $user);
44 $a->email
= $user->email
;
45 $stremailupdatesuccess = get_string('auth_emailupdatesuccess', 'auth', $a);
46 print_box($stremailupdatesuccess, 'center');
47 print_continue("$CFG->wwwroot/user/view.php?id=$user->id");
52 $preferences['newemailattemptsleft']--;
53 set_user_preference('newemailattemptsleft', $preferences['newemailattemptsleft'], $user->id
);
54 $strinvalidkey = get_string('auth_invalidnewemailkey', 'auth');
55 print_box($strinvalidkey, 'center');