MDL-21695 adding help strings
[moodle.git] / user / emailupdate.php
blobef03f9c10ade43e222b6c8f08e9527a360cb25fa
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * Change a users email address
21 * @copyright 1999 Martin Dougiamas http://dougiamas.com
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 * @package user
26 require_once('../config.php');
27 require_once($CFG->libdir.'/adminlib.php');
28 require_once($CFG->dirroot.'/user/editlib.php');
30 $key = required_param('key', PARAM_ALPHANUM);
31 $id = required_param('id', PARAM_INT);
33 $PAGE->set_url('/user/emailupdate.php', array('id'=>$id, 'key'=>$key));
35 if (!$user = $DB->get_record('user', array('id' => $id))) {
36 print_error('invaliduserid');
39 $preferences = get_user_preferences(null, null, $user->id);
40 $a = new stdClass();
41 $a->fullname = fullname($user, true);
42 $stremailupdate = get_string('auth_emailupdate', 'auth_email', $a);
44 $PAGE->set_title(format_string($SITE->fullname) . ": $stremailupdate");
45 $PAGE->set_heading(format_string($SITE->fullname) . ": $stremailupdate");
47 echo $OUTPUT->header();
49 if (empty($preferences['newemailattemptsleft'])) {
50 redirect("$CFG->wwwroot/user/view.php?id=$user->id");
52 } elseif ($preferences['newemailattemptsleft'] < 1) {
53 cancel_email_update($user->id);
54 $stroutofattempts = get_string('auth_outofnewemailupdateattempts', 'auth_email');
55 echo $OUTPUT->box($stroutofattempts, 'center');
57 } elseif ($key == $preferences['newemailkey']) {
58 $olduser = clone($user);
59 cancel_email_update($user->id);
60 $user->email = $preferences['newemail'];
62 // Detect duplicate before saving
63 if ($DB->get_record('user', array('email' => $user->email))) {
64 $stremailnowexists = get_string('auth_emailnowexists', 'auth_email');
65 echo $OUTPUT->box($stremailnowexists, 'center');
66 echo $OUTPUT->continue_button("$CFG->wwwroot/user/view.php?id=$user->id");
67 } else {
68 // update user email
69 $DB->set_field('user', 'email', $user->email, array('id' => $user->id));
70 $authplugin = get_auth_plugin($user->auth);
71 $authplugin->user_update($olduser, $user);
72 events_trigger('user_updated', $user);
73 $a->email = $user->email;
74 $stremailupdatesuccess = get_string('auth_emailupdatesuccess', 'auth_email', $a);
75 echo $OUTPUT->box($stremailupdatesuccess, 'center');
76 echo $OUTPUT->continue_button("$CFG->wwwroot/user/view.php?id=$user->id");
79 } else {
80 $preferences['newemailattemptsleft']--;
81 set_user_preference('newemailattemptsleft', $preferences['newemailattemptsleft'], $user->id);
82 $strinvalidkey = get_string('auth_invalidnewemailkey', 'auth_email');
83 echo $OUTPUT->box($strinvalidkey, 'center');
86 echo $OUTPUT->footer();