[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/user/ -> emailupdate.php (source)

   1  <?php // $Id: emailupdate.php,v 1.28 2008/02/26 06:43:54 nicolasconnault Exp $
   2  
   3  require_once ('../config.php');
   4  require_once($CFG->libdir.'/adminlib.php');
   5  require_once($CFG->dirroot.'/user/editlib.php');
   6  
   7  $key = required_param('key', PARAM_ALPHANUM);
   8  $id  = required_param('id', PARAM_INT);
   9  
  10  if (!$user = get_record('user', 'id', $id)) {
  11      error("Unknown user ID");
  12  }
  13  
  14  $preferences = get_user_preferences(null, null, $user->id);
  15  $a = new stdClass();
  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");
  19  
  20  if (empty($preferences['newemailattemptsleft'])) {
  21      redirect("$CFG->wwwroot/user/view.php?id=$user->id");
  22  
  23  } elseif ($preferences['newemailattemptsleft'] < 1) {
  24      cancel_email_update($user->id);
  25      $stroutofattempts = get_string('auth_outofnewemailupdateattempts', 'auth');
  26      print_box($stroutofattempts, 'center');
  27  
  28  } elseif ($key == $preferences['newemailkey']) {
  29      cancel_email_update($user->id);
  30      $user->email = $preferences['newemail'];
  31  
  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");
  37      } else {
  38          // update user email
  39          if (!set_field('user', 'email', addslashes($user->email), 'id', $user->id)) {
  40              error('Error updating user record');
  41  
  42          } else {
  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");
  48          }
  49      }
  50  
  51  } else {
  52      $preferences['newemailattemptsleft']--;
  53      set_user_preference('newemailattemptsleft', $preferences['newemailattemptsleft'], $user->id);
  54      $strinvalidkey = get_string('auth_invalidnewemailkey', 'auth');
  55      print_box($strinvalidkey, 'center');
  56  }
  57  
  58  print_footer('none');


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7