Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/user/emailupdate.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00026 require_once('../config.php');
00027 require_once($CFG->libdir.'/adminlib.php');
00028 require_once($CFG->dirroot.'/user/editlib.php');
00029 
00030 $key = required_param('key', PARAM_ALPHANUM);
00031 $id  = required_param('id', PARAM_INT);
00032 
00033 $PAGE->set_url('/user/emailupdate.php', array('id'=>$id, 'key'=>$key));
00034 $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
00035 
00036 if (!$user = $DB->get_record('user', array('id' => $id))) {
00037     print_error('invaliduserid');
00038 }
00039 
00040 $preferences = get_user_preferences(null, null, $user->id);
00041 $a = new stdClass();
00042 $a->fullname = fullname($user, true);
00043 $stremailupdate = get_string('emailupdate', 'auth', $a);
00044 
00045 $PAGE->set_title(format_string($SITE->fullname) . ": $stremailupdate");
00046 $PAGE->set_heading(format_string($SITE->fullname) . ": $stremailupdate");
00047 
00048 echo $OUTPUT->header();
00049 
00050 if (empty($preferences['newemailattemptsleft'])) {
00051     redirect("$CFG->wwwroot/user/view.php?id=$user->id");
00052 
00053 } elseif ($preferences['newemailattemptsleft'] < 1) {
00054     cancel_email_update($user->id);
00055     $stroutofattempts = get_string('auth_outofnewemailupdateattempts', 'auth');
00056     echo $OUTPUT->box($stroutofattempts, 'center');
00057 
00058 } elseif ($key == $preferences['newemailkey']) {
00059     $olduser = clone($user);
00060     cancel_email_update($user->id);
00061     $user->email = $preferences['newemail'];
00062 
00063     // Detect duplicate before saving
00064     if ($DB->get_record('user', array('email' => $user->email))) {
00065         $stremailnowexists = get_string('emailnowexists', 'auth');
00066         echo $OUTPUT->box($stremailnowexists, 'center');
00067         echo $OUTPUT->continue_button("$CFG->wwwroot/user/view.php?id=$user->id");
00068     } else {
00069         // update user email
00070         $DB->set_field('user', 'email', $user->email, array('id' => $user->id));
00071         $authplugin = get_auth_plugin($user->auth);
00072         $authplugin->user_update($olduser, $user);
00073         events_trigger('user_updated', $user);
00074         $a->email = $user->email;
00075         $stremailupdatesuccess = get_string('emailupdatesuccess', 'auth', $a);
00076         echo $OUTPUT->box($stremailupdatesuccess, 'center');
00077         echo $OUTPUT->continue_button("$CFG->wwwroot/user/view.php?id=$user->id");
00078     }
00079 
00080 } else {
00081     $preferences['newemailattemptsleft']--;
00082     set_user_preference('newemailattemptsleft', $preferences['newemailattemptsleft'], $user->id);
00083     $strinvalidkey = get_string('auth_invalidnewemailkey', 'auth');
00084     echo $OUTPUT->box($strinvalidkey, 'center');
00085 }
00086 
00087 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations