? LICENSE.txt
? multiple_email.test
Index: multiple_email.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/multiple_email/multiple_email.info,v
retrieving revision 1.1
diff -u -p -r1.1 multiple_email.info
--- multiple_email.info	16 Dec 2007 17:52:22 -0000	1.1
+++ multiple_email.info	30 Apr 2010 04:12:18 -0000
@@ -1,3 +1,8 @@
 ; $Id: multiple_email.info,v 1.1 2007/12/16 17:52:22 joshbenner Exp $
 name = "Multiple Email Addresses"
-description = "Allows users to have more than one registered email address"
\ No newline at end of file
+description = "Allows users to have more than one registered email address"
+; Information added by drupal.org packaging script on 2008-01-24
+version = "6.x-1.x-dev"
+project = "multiple_email"
+datestamp = "1201133327"
+core=6.x
Index: multiple_email.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/multiple_email/multiple_email.install,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 multiple_email.install
--- multiple_email.install	18 Dec 2007 04:42:22 -0000	1.1.2.1
+++ multiple_email.install	30 Apr 2010 04:12:18 -0000
@@ -10,29 +10,7 @@
   * Implementation of hook_install()
   */
 function multiple_email_install() {
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-      db_query("
-        CREATE TABLE {multiple_email} (
-          eid int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
-          uid int(10) UNSIGNED NOT NULL,
-          email varchar(255) NOT NULL,
-          time_registered int(11) UNSIGNED NOT NULL,
-          confirmed tinyint(1) NOT NULL,
-          confirm_code varchar(255) NOT NULL,
-          time_code_generated int(11) UNSIGNED NOT NULL,
-          attempts tinyint(1) UNSIGNED NOT NULL DEFAULT 0,
-          PRIMARY KEY (eid),
-          INDEX uid (uid),
-          INDEX email (email)
-        )  /*!40100 DEFAULT CHARACTER SET utf8 */;
-      ");
-      break;
-    case 'pgsql':
-      // Someone should write this...?
-      break;
-  }
+  drupal_install_schema('multiple_email');
 
   // Now import current users' emails
   db_query("
@@ -46,12 +24,66 @@ function multiple_email_install() {
     FROM {users}
     WHERE uid != 0
   ");
+  
+  // Make this module of weight 1. May not be necessary.
+  // db_query("UPDATE {system} SET weight = 1 WHERE name = 'multiple_email'");
+  
 }
 
 /**
  * Implementation of hook_uninstall()
  */
 function multiple_email_uninstall() {
-  db_query('DROP TABLE {multiple_email}');
+  drupal_uninstall_schema('multiple_email');
 }
-?>
\ No newline at end of file
+
+function multiple_email_schema() {
+  $schema['multiple_email'] = array(
+    'description' => 'The base table for multiple email.',
+    'fields' => array(
+      'eid' => array(
+        'type' => 'serial',
+        'unsigned' => TRUE,
+        'not null' => TRUE),
+      'uid' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE),
+      'email' => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE),
+      'time_registered' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0),
+      'confirmed' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE),
+      'confirm_code' => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE),
+      'time_code_generated' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0),
+       'attempts' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0)               
+    ),
+    'indexes' => array(
+      'uid' => array('uid'),
+    ),
+    'unique keys' => array(
+      'eid' => array('eid'),
+      'email' => array('email'),
+    ),
+    'primary key' => array('eid'),
+  );
+
+  return $schema;
+}
\ No newline at end of file
Index: multiple_email.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/multiple_email/multiple_email.module,v
retrieving revision 1.1.2.3
diff -u -p -r1.1.2.3 multiple_email.module
--- multiple_email.module	7 Jan 2008 18:14:57 -0000	1.1.2.3
+++ multiple_email.module	30 Apr 2010 04:12:18 -0000
@@ -6,23 +6,14 @@
  * multiple_email module file
  */
 
-// Pull in support files
-$mepath = drupal_get_path('module', 'multiple_email');
-include_once('./' . $mepath . '/multiple_email_addresses_page.inc');
-include_once('./' . $mepath . '/multiple_email_delete_page.inc');
-include_once('./' . $mepath . '/multiple_email_add_page.inc');
-include_once('./' . $mepath . '/multiple_email_confirm_page.inc');
-include_once('./' . $mepath . '/multiple_email_primary_page.inc');
-unset($mepath);
-
 /**
- * Implementation of hook_help().
+ * Implementation of hook_help().u
  */
-function multiple_email_help($section) {
+function multiple_email_help($section, $arg) {
   switch ($section) {
     case 'admin/help#multiple_email':
     case 'admin/help/multiple_email':
-      $path = drupal_get_path('module','multiple_email')."/README.txt";
+      $path = drupal_get_path('module', 'multiple_email') ."/README.txt";
       return filter_filter('process', 2, NULL, file_get_contents($path) );
       break;
   }
@@ -55,7 +46,7 @@ function multiple_email_enable() {
     }
   }
 
-  foreach ($vars as $var=>$default) {
+  foreach ($vars as $var => $default) {
     $current = variable_get("multiple_email_$var", $default);
     variable_set("multiple_email_$var", $current);
   }
@@ -70,7 +61,7 @@ function multiple_email_enable() {
  *
  */
 function multiple_email_perm() {
-  return array('multiple emails');
+  return array('multiple emails', 'administer multiple emails');
 }
 
 /**
@@ -79,57 +70,112 @@ function multiple_email_perm() {
  * @param boolean $may_cache
  * @return array
  */
-function multiple_email_menu($may_cache) {
+function multiple_email_menu() {
   $items = array();
-  if ($may_cache) {
-    $items[] = array(
-      'path' => 'admin/settings/multiple-email',
-      'title' => t('Multiple Email Settings'),
-      'description' => t('Control behavior of the Multiple Email Addresses module'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('multiple_email_admin_settings'),
-      'access' => user_access('administer site configuration'),
-    );
-    $items[] = array(
-      'path' => 'my-email-addresses',
-      'title' => t('My Email Addresses'),
-      'description' => t('Manage the email addresses associated with your account'),
-      'callback' => 'multiple_email_addresses_page',
-      'type' => MENU_NORMAL_ITEM,
-      'access' => user_access('multiple emails'),
-    );
-    $items[] = array(
-      'path' => 'my-email-addresses/add',
-      'title' => t('Add Email Address'),
-      'callback' => 'multiple_email_add_page',
-      'type' => MENU_CALLBACK,
-      'access' => user_access('multiple emails'),
-    );
-    $items[] = array(
-      'path' => 'my-email-addresses/delete',
-      'title' => t('Delete Email Address'),
-      'callback' => 'multiple_email_delete_page',
-      'type' => MENU_CALLBACK,
-      'access' => user_access('multiple emails'),
-    );
-    $items[] = array(
-      'path' => 'my-email-addresses/make-primary',
-      'title' => t('Make Email My Primary Address'),
-      'callback' => 'multiple_email_primary_page',
-      'type' => MENU_CALLBACK,
-      'access' => user_access('multiple emails'),
-    );
-    $items[] = array(
-      'path' => 'my-email-addresses/confirm',
-      'title' => t('Confirm Email Address'),
-      'callback' => 'multiple_email_confirm_page',
-      'type' => MENU_CALLBACK,
-      'access' => user_access('multiple emails'),
-    );
-  }
+
+ $items['admin/settings/multiple-email'] = array(
+    'title' => 'Multiple Email Settings',
+    'description' => 'Control behavior of the Multiple Email Addresses module',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('multiple_email_admin_settings'),
+    'access callback' => user_access('administer site configuration'),
+  );
+  
+  $items['user/%user/edit/email-addresses/view'] = array(
+    'title' => 'View Email Address',
+    'page callback' => 'multiple_email_addresses_page',
+    'page arguments' => array(1, 'email-addresses'),
+    'access callback' => '_multiple_email_access',
+    'access arguments' => array('pages', '', 1),
+    'file' => 'multiple_email_addresses_page.inc',
+    'type' => MENU_CALLBACK,
+  );  
+    
+  $items['user/%user/edit/email-addresses/add'] = array(
+    'title' => 'Add Email Address',
+    'page callback' => 'multiple_email_add_page',
+    'page arguments' => array(1, 'email-addresses'),
+    'access callback' => '_multiple_email_access',
+    'access arguments' => array('pages', '', 1),
+    'file' => 'multiple_email_add_page.inc',
+    'type' => MENU_CALLBACK,
+  );
+
+  $items['user/%user/edit/email-addresses/confirm'] = array(
+    'title' => 'Confirm Email Address',
+    'page callback' => 'multiple_email_confirm_page',
+    'page arguments' => array(1),
+    'access callback' => '_multiple_email_access',
+    'access arguments' => array('confirm', 5, 1),
+    'file' => 'multiple_email_confirm_page.inc',
+    'type' => MENU_CALLBACK,
+  );
+
+  $items['user/%user/edit/email-addresses/primary'] = array(
+    'title' => 'Make Email Primary Address',
+    'page callback' => 'multiple_email_primary_page',
+    'page arguments' => array(1),
+    'access callback' => '_multiple_email_access',
+    'access arguments' => array('primary', 5, 1),
+    'file' => 'multiple_email_primary_page.inc',
+    'type' => MENU_CALLBACK,
+  );
+
+  $items['user/%user/edit/email-addresses/delete'] = array(
+    'title' => 'Delete Email Address',
+    'page callback' => 'multiple_email_delete_page',
+    'page arguments' => array(1),
+    'access callback' => '_multiple_email_access',
+    'access arguments' => array('delete', 5, 1),
+    'file' => 'multiple_email_delete_page.inc',
+    'type' => MENU_CALLBACK,
+  );
+   
   return $items;
 }
 
+function _multiple_email_access($op, $eid = NULL, $account) {
+  global $user;
+  switch($op) {
+    case 'pages':
+      if ((user_access('multiple emails') == TRUE && $account->uid == $user->uid) || user_access('administer multiple emails') == TRUE) {
+        return TRUE;
+      }
+      break;
+    case 'confirm':
+      $email = multiple_email_get_address($eid);
+      if ($email->uid == $account->uid && ((user_access('multiple emails') == TRUE && $account->uid == $user->uid) || (user_access('administer multiple emails') == TRUE))) {
+        return TRUE;
+      }
+      break;
+    case 'primary':
+      $email = multiple_email_get_address($eid);
+      if (($email->primary_address == 0 && $email->uid == $account->uid && ((user_access('multiple emails') == TRUE && $account->uid == $user->uid && $email->confirmed == 1)) || user_access('administer multiple emails'))) {
+        return TRUE;
+      }
+      break;
+    case 'delete':
+      $email = multiple_email_get_address($eid);
+      if ($email->primary_address == 0 && $email->uid == $account->uid && ((user_access('multiple emails') == TRUE && $account->uid == $user->uid) || (user_access('administer multiple emails') == TRUE))) {
+        return TRUE;
+      }
+      break;
+  }
+  return FALSE;
+}
+
+function multiple_email_menu_alter(&$items) {
+    $item = &$items['user/%user_category/edit/email-addresses'];
+    $item = array(
+      'page callback' => 'multiple_email_addresses_page',
+      'page arguments' => array(1, 'email-addresses'),
+      'access callback' => '_multiple_email_access',
+      'access arguments' => array('pages', '', 1),
+      'file' => 'multiple_email_addresses_page.inc',
+      'file path' => drupal_get_path('module', 'multiple_email'),
+    ) + $item;
+}
+
 /**
  * Implementation of hook_user()
  *
@@ -141,47 +187,23 @@ function multiple_email_menu($may_cache)
  */
 function multiple_email_user($op, &$edit, &$account, $category = NULL) {
   switch ($op) {
-    case 'login':
-      if (!$account->login) {
-        // They've never logged in before, so we're assuming their
-        //   email address is confirmed since they were able to login
-        $email = multiple_email_find_address($account->mail);
-        multiple_email_confirm_email($email);
+    case 'categories':
+      return array(array('name' => 'email-addresses', 'title' => 'E-Mail addresses', 'weight' => 100));
+    case 'form':
+      if ($category == 'email-addresses') {
+        $form = array();
+        return $form;     
       }
       break;
     case 'insert':
-      /**
-       * Add user's entered email to the email registry as an
-       * unconfirmed address, to be confirmed upon first successful
-       * login to the web site.
-       */
-      // First check for any other user who tried to register the address
-      if ($email = multiple_email_find_address($edit['mail'])) {
-        // Someone else has it registered, but not confirmed (passed validation), so delete
-        multiple_email_delete_email($email->eid);
+      if (user_access('multiple emails', $account)) {
+        // add the new email address into the Multiple Emails section.
+        $eid = multiple_email_register_email($account->uid, $account->mail);
       }
-      // Register email with new user
-      multiple_email_register_email($account->uid, $edit['mail']);
       break;
     case 'delete':
-      // Cleanup our mess
-      db_query('DELETE FROM {multiple_email} WHERE uid=%d', $account->uid);
-      break;
-    case 'submit':
-      // Do not allow primary address to be changed from account edit
-      unset($edit['mail']);
-      break;
-    case 'validate':
-      // Keep new users from taking registered email addresses
-      if ($edit['form_id'] == 'user_register' && $email = multiple_email_find_address($edit['mail'])) {
-        $owner = user_load(array('uid'=>$email->uid));
-        // Don't put up error message if it is owner's primary, Drupal does that
-        // Also, they can register with an address if it's unconfirmed
-        if ($email->confirmed && $owner->mail != $email->email) {
-          $message = t('The e-mail address %email is already registered. <a href="@password">Have you forgotten your password?</a>', array('%email' => $edit['mail'], '@password' => url('user/password')));
-          form_set_error('mail', $message);
-        }
-      }
+      // delete Multiple Emails from the deleting user.
+      db_query("DELETE FROM {multiple_email} WHERE uid = %d", $account->uid);
       break;
   }
 }
@@ -196,15 +218,33 @@ function multiple_email_user($op, &$edit
  * @param array $form
  * @return array
  */
-function multiple_email_form_alter($form_id, &$form) {
-  if ($form_id == 'user_edit' && variable_get('multiple_email_hide_field', true)) {
+function multiple_email_form_alter(&$form, $form_state, $form_id) {
+  if ($form_id == 'user_profile_form' && variable_get('multiple_email_hide_field', TRUE)) {
     // We can't remove the email field, but bcb_user_user()'s submit op
-    //   hook will catch the mail field and remove it before it's sent
-    //   to the database. So instead, we hide it.
-    $form['account']['mail']['#prefix'] = '<div style="display:none;">';
-    $form['account']['mail']['#suffix'] = '</div>';
-    // TODO: Put admin-only fields here for changing primary email
-    // ... or maybe a separate admin email management interface
+    $form['account']['mail']['#access'] = FALSE;
+  }
+  
+  if ($form_id == 'multiple_email_primary_form' || $form_id == 'multiple_email_delete_form') {
+    // The "Cancel" button action.
+    if (isset($form_state['post']['cancel']) || $form_state['clicked_button']['#name'] == 'cancel') {
+      // Define an path for redirect    
+      drupal_goto('user/'. $form['account']['#value']->uid .'/edit/email-addresses');
+      return;
+    }
+ 
+    // "Submit" button weight
+    $form['submit']['#weight'] = 50;
+ 
+    // "Preview" button weight
+    $form['delete']['#weight'] = 50;
+ 
+    // Add the "Cancel" button
+    $form['cancel'] = array(
+      '#type' => 'submit',
+      '#name' => 'cancel',
+      '#value' => t('Cancel'),
+      '#weight' => $form['submit']['#weight'] + 1,
+    );
   }
 }
 
@@ -219,7 +259,7 @@ function multiple_email_cron() {
       SELECT 
         e.eid,
         e.time_code_generated,
-        IF(u.mail = e.email, 1, 0) as primary_address 
+        IF(u.mail = e.email, 1, 0) as primary_address
       FROM 
         {multiple_email} e
         INNER JOIN {users} u ON (u.uid = e.uid)
@@ -307,11 +347,11 @@ function multiple_email_admin_settings()
  * @param string $form_id
  * @param array $form_values
  */
-function multiple_email_admin_settings_validate($form_id, $form_values) {
-  if (!is_numeric($form_values['multiple_email_confirm_attempts'])) {
+function multiple_email_admin_settings_validate($form, &$form_state) {
+  if (!is_numeric($form_state['values']['multiple_email_confirm_attempts'])) {
     form_set_error('multiple_email_confirm_attempts', 'Confirm attempts must be an number!');
   }
-  if (!is_numeric($form_values['multiple_email_confirm_deadline'])) {
+  if (!is_numeric($form_state['values']['multiple_email_confirm_deadline'])) {
     form_set_error('multiple_email_confirm_deadline', 'Confirm Days must be an number!');
   }
 }
@@ -328,7 +368,8 @@ function multiple_email_admin_settings_v
  * @param array $tablesortHeaders
  * @return array
  */
-function multiple_email_load_addresses($uid, $tablesortHeaders = null) {
+function multiple_email_load_addresses($uid, $tablesortHeaders = NULL) {
+  $addresses = array();
   $results = db_query("
     SELECT
       a.eid,
@@ -395,13 +436,12 @@ function multiple_email_get_address($eid
  * @return mixed
  */
 function multiple_email_find_address($email) {
-  $result = db_query("SELECT eid FROM {multiple_email} WHERE email='%s'", $email);
-  if (db_num_rows($result)) {
-    $r = db_fetch_array($result);
-    return multiple_email_get_address($r['eid']);
-  } else {
-    return false;
+  $result = db_query("SELECT eid FROM {multiple_email} WHERE email = '%s'", $email);
+  while ($row = db_fetch_array($result)) {
+    return multiple_email_get_address($row['eid']);
   }
+
+  return FALSE;
 }
 
 /**
@@ -417,7 +457,7 @@ function multiple_email_find_address($em
  * @param boolean $confirmed
  * @return mixed
  */
-function multiple_email_register_email($uid, $email, $confirmed = false) {
+function multiple_email_register_email($uid, $email, $confirmed = FALSE) {
   $success = db_query("
     INSERT INTO {multiple_email}
       (`uid`,`email`,`time_registered`,`confirmed`,`confirm_code`,`time_code_generated`)
@@ -431,14 +471,15 @@ function multiple_email_register_email($
     time()
   );
 
-  if ($success !== false) {
+  if ($success !== FALSE) {
     $result = db_query("SELECT LAST_INSERT_ID() AS eid");
     $r = db_fetch_array($result);
     $email = multiple_email_get_address($r['eid']);
     module_invoke_all('multiple_email_register', $email);
     return $r['eid'];
-  } else {
-    return false;
+  }
+  else {
+    return FALSE;
   }
 }
 
@@ -450,7 +491,7 @@ function multiple_email_register_email($
  * @return void
  */
 function multiple_email_confirm_email($email) {
-  watchdog('Multiple Email', t("Marking address '!email' confirmed for user !uid", array('!email'=>$email->email,'!uid'=>$email->uid)), l(t('edit'), "user/$uid"));
+  watchdog('Multiple Email', t("Marking address '!email' confirmed for user !uid", array('!email' => $email->email, '!uid' => $email->uid)), l(t('edit'), "user/$uid"));
   db_query("
     UPDATE {multiple_email} SET
       confirmed = 1
@@ -477,8 +518,8 @@ function multiple_email_confirm_email($e
 function multiple_email_code($length, $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUBWXYZ0123456789') {
   $cl = strlen($chars) - 1;
   $out = '';
-  for ($i=0;$i<$length;$i++) {
-    $out .= $chars[rand(0,$cl)];
+  for ($i=0; $i < $length; $i++) {
+    $out .= $chars[rand(0, $cl)];
   }
   return $out;
 }
@@ -490,7 +531,7 @@ function multiple_email_code($length, $c
  * @return mixed
  */
 function multiple_email_delete_email($eid) {
-  return db_query("DELETE FROM {multiple_email} WHERE eid=%d", $eid);
+  return db_query("DELETE FROM {multiple_email} WHERE eid = %d", $eid);
 }
 
 /**
@@ -499,8 +540,10 @@ function multiple_email_delete_email($ei
  * @param object $account
  * @param object $email
  */
-function multiple_email_make_primary($account, $email) {
-  user_save($account, array('mail'=>$email->email));
+function multiple_email_make_primary($email) {
+  $account = new stdClass();
+  $account->uid = $email->uid;
+  user_save($account, array('mail' => $email->email));
 }
 
 /**
@@ -511,11 +554,34 @@ function multiple_email_make_primary($ac
  * @param object $email
  */
 function multiple_email_send_confirmation($account, $email) {
-  $subject = multiple_email_message_part('subject', 'confirmation', $account, $email);
-  $body = multiple_email_message_part('body', 'confirmation', $account, $email);
-  drupal_mail('multiple_email_confirmation', $email->email, $subject, $body, variable_get('site_mail', ini_get('sendmail_from')));
+  global $language;
+
+  $params = array(
+    'headers' => array(),
+    'subject' => multiple_email_message_part('subject', 'confirmation', $account, $email),
+    'body' => multiple_email_message_part('body', 'confirmation', $account, $email)
+  );
+  
+  $from = variable_get('site_mail', ini_get('sendmail_from'));
+  drupal_mail('multiple_email', 'confirmation', $email->email, $language, $params, $from);
 }
 
+function multiple_email_mail($key, &$message, $params) {
+
+  switch ($key) {
+    case 'confirmation':
+      $message['subject'] = $params['subject'];
+      $message['body'][] = $params['body'];
+      $message['headers'] = array_merge($message['headers'], $params['headers']);
+      break;
+  }
+  
+}
+
+
+
+//  drupal_mail($module, $key, $to, $language, $params = array(), $from = NULL, $send = TRUE)
+
 /**
  * Removes the specified address from the user who added it and sends their
  * primary email account a message notifying them about the expiration.
@@ -523,15 +589,28 @@ function multiple_email_send_confirmatio
  * @param integer $eid
  */
 function multiple_email_expire_address($eid) {
+  global $language;
+  
   $email = multiple_email_get_address($eid);
-  $account = user_load(array('uid'=>$email->uid));
-  $subject = multiple_email_message_part('subject', 'expire', $account, $email);
-  $body = multiple_email_message_part('body', 'expire', $account, $email);
+  $account = user_load(array('uid' => $email->uid));
+  $params = array(
+    'subject' => multiple_email_message_part('subject', 'expire', $account, $email),
+    'body' => multiple_email_message_part('body', 'expire', $account, $email)
+  );  
+  
   multiple_email_delete_email($eid);
-  drupal_mail('multiple_email_expire', $account->mail, $subject, $body, variable_get('site_mail', ini_get('sendmail_from')));
+  $form = variable_get('site_mail', ini_get('sendmail_from'));
+  
+  drupal_mail('multiple_email_expire', 'expire_address_mail', $account->mail, $language, $params, $from);
   watchdog('Multiple Email', "{$email->email} ({$email->eid}) for {$account->name} ({$account->uid}) has expired and been removed");
 }
 
+function multiple_email_expire_address_mail($key, &$message, $params) {
+  $message['subject'] = $params['subject'];
+  $message['body'][] = $params['body'];
+  $message['headers'] = array_merge($message['headers'], $params['headers']);
+}
+
 /**
  * Returns the part of the specified email message based on site settings.
  *
@@ -594,7 +673,7 @@ function multiple_email_var_replace($tex
     '!email' => $email->email,
     '!site' => variable_get('site_name', 'our web site'),
     '!confirm_code' => $email->confirm_code,
-    '!confirm_url' => url("my-email-addresses/confirm/{$email->eid}/{$email->confirm_code}", null, null, true),
+    '!confirm_url' => url('user/'. $email->uid . '/edit/email-addresses/confirm/'. $email->eid .'/'. $email->confirm_code, array('absolute' => TRUE)),
     '!confirm_deadline' => variable_get('multiple_email_confirm_deadline', 5) . ' days',
   );
   return str_ireplace(array_keys($vars), array_values($vars), $text);
@@ -645,5 +724,4 @@ specified deadline!
 END_MESSAGE;
 
   return $message;
-}
-?>
\ No newline at end of file
+}
\ No newline at end of file
Index: multiple_email_add_page.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/multiple_email/multiple_email_add_page.inc,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 multiple_email_add_page.inc
--- multiple_email_add_page.inc	18 Dec 2007 04:42:23 -0000	1.1.2.1
+++ multiple_email_add_page.inc	30 Apr 2010 04:12:18 -0000
@@ -11,13 +11,9 @@
   *
   * @return string
   */
-function multiple_email_add_page() {
-  global $user;
-
-  $out = '';
-  $out .= drupal_get_form('multiple_email_add_form', $user);
-
-  return $out;
+function multiple_email_add_page($account) {
+  menu_set_active_item('user/'. $account->uid .'/edit/email-addresses');
+  return drupal_get_form('multiple_email_add_form', $account);
 }
 
 /**
@@ -26,23 +22,29 @@ function multiple_email_add_page() {
  * @ingroup forms
  * @param object $account User object
  */
-function multiple_email_add_form($account) {
+function multiple_email_add_form(&$form_state, $account) {
   $form['email'] = array(
     '#type' => 'textfield',
     '#title' => t('Email Address'),
-    '#required' => true,
+    '#required' => TRUE,
   );
-  $form[] = array(
+  
+  $form['account'] = array(
+    '#type' => 'value',
+    '#value' => $account,
+  );
+  
+  if (user_access('administer multiple emails')) {
+    $form['confirm'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Activate this email.'),
+    );
+  }
+  
+   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Register'),
   );
-  $url = base_path() . 'my-email-addresses';
-  $form[] = array(
-    '#type' => 'button',
-    '#value' => t('Cancel'),
-    '#submit' => false,
-    '#attributes' => array('onclick'=>"window.location='$url';return false;")
-  );
 
   return $form;
 }
@@ -53,10 +55,11 @@ function multiple_email_add_form($accoun
  * @param string $form_id
  * @param array $form_values
  */
-function multiple_email_add_form_validate($form_id, $form_values) {
-  if (!valid_email_address($form_values['email'])) {
+function multiple_email_add_form_validate($form, &$form_state) {
+  if (!valid_email_address($form_state['values']['email'])) {
     form_set_error('email', t('You must enter a valid email address!'));
-  } elseif (multiple_email_find_address($form_values['email'])) {
+  }
+  elseif (multiple_email_find_address($form_state['values']['email'])) {
     form_set_error('email', t('Entered address is already registered on this site.'));
   }
 }
@@ -67,16 +70,22 @@ function multiple_email_add_form_validat
  * @param string $form_id
  * @param array $form_values
  */
-function multiple_email_add_form_submit($form_id, $form_values) {
-  global $user;
-
-  if ($eid = multiple_email_register_email($user->uid, $form_values['email'])) {
-    multiple_email_send_confirmation($user, multiple_email_get_address($eid));
-    drupal_set_message(t("The email address '%email' has been added to your account and is awaiting confirmation.",
-    array('%email'=>$form_values['email'])));
-  } else {
-    drupal_set_message(t("Error attempting to register '%email'", array('%email'=>$form_values['email'])));
+function multiple_email_add_form_submit($form, &$form_state) {
+  $account = $form_state['values']['account'];
+  $eid = multiple_email_register_email($account->uid, $form_state['values']['email']);
+
+  if ($eid) {
+    if(user_access('administer multiple emails') && $form_state['values']['confirm'] == TRUE) {
+      $email = multiple_email_get_address($eid);
+      multiple_email_confirm_email($email);
+      drupal_set_message("The address {$email->email} has been confirmed!");
+    } else {
+      multiple_email_send_confirmation($account, multiple_email_get_address($eid));
+      drupal_set_message(t("The email address '%email' has been added to your account and is awaiting confirmation.",
+      array('%email' => $form_state['values']['email'])));
+    }
+  }
+  else {
+    form_set_error('', t("Error attempting to register '%email'", array('%email' => $form_state['values']['email'])));
   }
-  drupal_goto('my-email-addresses');
 }
-?>
\ No newline at end of file
Index: multiple_email_addresses_page.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/multiple_email/multiple_email_addresses_page.inc,v
retrieving revision 1.1.2.3
diff -u -p -r1.1.2.3 multiple_email_addresses_page.inc
--- multiple_email_addresses_page.inc	23 Jan 2008 15:13:16 -0000	1.1.2.3
+++ multiple_email_addresses_page.inc	30 Apr 2010 04:12:18 -0000
@@ -12,14 +12,65 @@
   *
   * @return string
   */
-function multiple_email_addresses_page() {  
-  global $user;
+function multiple_email_addresses_page($account) {
+  $addresses = multiple_email_load_addresses($account->uid);
+  unset($addresses[0]);
   
-  $out = '';
+  $header[] = array(
+    'data' => t('Email Address'),
+  );
   
-  $out .= drupal_get_form('multiple_email_addresses_form', $user);
+  $header[] = array(
+    'data' => t('Confirmed?'),
+  );
+  $header[] = array(
+    'data' => t('Primary Address?'),
+  );
+
+  $header[] = array(
+    'data' => t('Delete'),
+  );
   
-  return $out;
+  $rows = array();
+  foreach ($addresses as $a) {
+    $tmp = array();
+    
+    // Email Adress
+    $tmp[] = $a->email;
+
+    // Confirm
+    if ($a->confirmed == 1) {
+      $tmp[] = t('yes');
+    }
+    else {
+      $tmp[] = l('Click to confirm', 'user/'. $account->uid .'/edit/email-addresses/confirm/'. $a->eid);
+    }
+
+    // Primary
+    if (($a->primary_address == 0 && $a->confirmed == 1) || (user_access('administer multiple emails') && $a->confirmed == 0)) {
+        $tmp[] = l(t('Set as primary'), 'user/'. $account->uid .'/edit/email-addresses/primary/'. $a->eid);
+    }
+    else {
+       $tmp[] = t('yes');
+    }
+
+    // Remove
+    if ($a->primary_address == 0) {
+      $tmp[] = l(t('Delete'), 'user/'. $account->uid .'/edit/email-addresses/delete/'. $a->eid);
+    }
+    else {
+      $tmp[] = '';
+    }
+    
+    $rows[] = $tmp;
+  }
+  
+  $output = l('Add', 'user/'. $account->uid .'/edit/email-addresses/add');
+  if(count($rows) > 0) {
+    $output .= theme('table', $header, $rows, array('class' => 'multiple-email-table'));
+  }
+  
+  return $output;
 }
 
 /**
@@ -30,8 +81,11 @@ function multiple_email_addresses_page()
  * @param array $addresses
  * @param array $headers
  */
-function multiple_email_addresses_form($account) {
-  $addresses = multiple_email_load_addresses($account->uid, $headers);
+function multiple_email_addresses_($account) {
+  global $user;
+
+  $addresses = multiple_email_load_addresses($user->uid, $headers);
+  
   unset($addresses[0]);
   
   $headers[] = array(
@@ -56,7 +110,7 @@ function multiple_email_addresses_form($
   
   $form['add']['#value'] = theme('multiple_email_add_address_link');
   
-  foreach ($addresses as $eid=>$a) {
+  foreach ($addresses as $eid => $a) {
     $aid = "address_$eid";
     $form[$aid]["email_$eid"] = array(
       '#value' => $a->email,
@@ -71,7 +125,7 @@ function multiple_email_addresses_form($
       '#value' => $a->primary_address ? '' : l('X', "my-email-addresses/delete/$eid"),
     );
   }
-  
+   
   return $form;
 }
 
@@ -86,6 +140,7 @@ function multiple_email_addresses_form($
  * @return string
  */
 function theme_multiple_email_addresses_form($form) {
+
   $headers = $form['#headers'];
   $columns = $form['#columns'];
   unset($form['#headers'], $form['#columns']);
@@ -94,7 +149,7 @@ function theme_multiple_email_addresses_
   $rows = array();
   // NOTE: Reference $form instead of $member so that $form values are
   // updated upon being rendered!
-  foreach ($form as $aid=>$member) {
+  foreach ($form as $aid => $member) {
     if (preg_match('/address_(\d+)/i', $aid, $matches)) {
       $row = array();
       $eid = $matches[1];
@@ -111,7 +166,9 @@ function theme_multiple_email_addresses_
       $rows[] = $row;
     }
   }
-  $out .= theme('table', $headers, $rows, array('class'=>'multiple-email-table'));
+
+  
+  $out .= theme('table', $headers, $rows, array('class' => 'multiple-email-table'));
   $out .= drupal_render($form);
   return $out;
 }
@@ -124,8 +181,7 @@ function theme_multiple_email_addresses_
  * @return string
  *  HTML
  */
-function theme_multiple_email_add_address_link($text = null) {
+function theme_multiple_email_add_address_link($text = NULL) {
   $text = $text ? $text : t('Add Email Address');
   return l($text, 'my-email-addresses/add');
-}
-?>
\ No newline at end of file
+}
\ No newline at end of file
Index: multiple_email_confirm_page.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/multiple_email/multiple_email_confirm_page.inc,v
retrieving revision 1.1.2.2
diff -u -p -r1.1.2.2 multiple_email_confirm_page.inc
--- multiple_email_confirm_page.inc	7 Jan 2008 18:14:57 -0000	1.1.2.2
+++ multiple_email_confirm_page.inc	30 Apr 2010 04:12:18 -0000
@@ -16,29 +16,11 @@
   * @param string $code
   * @return string
   */
-function multiple_email_confirm_page($eid, $code = null) {
-  global $user;
+function multiple_email_confirm_page($account, $eid, $code = NULL) {
+  $email = multiple_email_get_address($eid);
 
-  $out = '';
-
-  if ($email = multiple_email_get_address($eid)) {
-    if ($email->uid != $user->uid) {
-      drupal_set_message(t('Email address not found'));
-      watchdog('Multiple Email', 'Unauthorized attempt to access email ' . $eid . ' by ' . $user->name . ' (' . $user->uid . ')');
-      drupal_goto('my-email-addresses');
-    } elseif ($email->confirmed) {
-      drupal_set_message(t("'%email' is already confirmed!", array('%email'=>$email->email)));
-      drupal_goto('my-email-addresses');
-    } else {
-      $out .= drupal_get_form('multiple_email_confirm_form', $email, $code);
-    }
-  } else {
-    drupal_set_message(t('Email address not found'));
-    watchdog('Multiple Email', 'Error loading email ' . $eid, WATCHDOG_WARNING);
-    drupal_goto('my-email-addresses');
-  }
-
-  return $out;
+  menu_set_active_item('user/'. $account->uid .'/edit/email-addresses');
+  return drupal_get_form('multiple_email_confirm_form', $account, $email, $code);
 }
 
 /**
@@ -52,82 +34,78 @@ function multiple_email_confirm_page($ei
  * @param string $confirm_code
  * @return array
  */
-function multiple_email_confirm_form($email, $confirm_code) {
-  $form['eid'] = array(
-    '#type' => 'hidden',
-    '#value' => $email->eid,
-  );
+function multiple_email_confirm_form(&$form_state, $account, $email, $confirm_code) {
+  $form = array();
+
+  $form['#redirect'] = 'user/'. $account->uid .'/edit/email-addresses';
+
   $form[] = array(
-    '#prefix' => '<p>',
-    '#value' => t("The email address '%email' is awaiting confirmation. You should have received an email at that address with a confirmation code in it. Enter the code below and click confirm.",
-  array('%email'=>$email->email)),
-    '#suffix' => '</p>',
+    '#type' => 'markup',
+    '#value' => '<p>'. t("The email address '%email' is awaiting confirmation. You should have received an email at that address with a confirmation code in it. Enter the code below and click confirm.", array('%email' => $email->email)) . '</p>',
+  );
+
+  $form['email'] = array(
+    '#type' => 'value',
+    '#value' => $email,
   );
+
+  $form['account'] = array(
+    '#type' => 'value',
+    '#value' => $account,
+  );
+
   $form['code'] = array(
     '#type' => 'textfield',
     '#title' => t('Confirmation Code'),
-    '#required' => true,
+    '#required' => TRUE,
     '#default_value' => $confirm_code,
   );
-  $form['confirm'] = array(
+
+  $form['submit'] = array(
     '#type' => 'submit',
-    '#value' => 'Confirm',
-  );
-  $url = base_path() . 'my-email-addresses';
-  $form['cancel'] = array(
-    '#type' => 'button',
-    '#value' => 'Cancel',
-    '#attributes' => array('onclick'=>"window.location='$url'; return false;"),
+    '#value' => t('Confirm'),
   );
 
   return $form;
 }
 
+function multiple_email_confirm_form_validate($form, &$form_state) {
+  $code = trim($form_state['values']['code']);
+  
+  $email = $form_state['values']['email'];
+  $account = $form_state['values']['account'];
+
+  if ($code != '') {
+    $attempts = $email->attempts + 1;
+    $allowed = (int)variable_get('multiple_email_confirm_attempts', 3);
+    db_query("UPDATE {multiple_email} SET attempts = %d WHERE eid = %d", $attempts, $email->eid);
+
+    if ($attempts <= $allowed) {
+      if ($code != $email->confirm_code) {
+        form_set_error('', 'The confirmation code was incorrect');
+      }
+    }
+    else {
+      $email->confirm_code = multiple_email_code(10);
+      db_query("UPDATE {multiple_email} SET confirm_code = '%s', time_code_generated = %d, attempts = 0 WHERE eid = %d", $email->confirm_code, time(), $email->eid);
+      multiple_email_send_confirmation($account->uid, $email);
+
+      // Redirect & Message
+      form_set_error('', 'You have exhausted your allowed attempts at confirming this email address. A new confirmation code has been sent.');
+      drupal_goto('user/'. $account->uid .'/edit/email-addresses');
+    }
+  }
+}
+
 /**
  * Process multiple_email_confirm_form submission
  *
  * @param string $form_id
  * @param array $form_values
  */
-function multiple_email_confirm_form_submit($form_id, $form_values) {
-  global $user;
-
-  if ($email = multiple_email_get_address($form_values['eid'])) {
-    if ($user->uid != $email->uid) {
-      watchdog('Multiple Email', "Attempted unauthorized access to email {$email->eid} by user {$user->name} ({$user->uid})");
-    } elseif ($email->confirmed) {
-      drupal_set_message("'{$email->email}' is already confirmed!");
-    } elseif (trim($form_values['code']) != $email->confirm_code) {
-      $attempts = $email->attempts + 1;
-      $allowed = (int)variable_get('multiple_email_confirm_attempts', 3);
-      if ($allowed && $attempts >= $allowed) {
-        $email->confirm_code = multiple_email_code(10);
-        db_query("
-          UPDATE {multiple_email} SET
-            confirm_code='%s',
-            time_code_generated=%d,
-            attempts=0
-          WHERE
-            eid = %d",
-        $email->confirm_code,
-        time(),
-        $email->eid
-        );
-        multiple_email_send_confirmation($user, $email);
-        drupal_set_message('You have exhausted your allowed attempts at confirming this email address. A new confirmation code has been sent.');
-      } else {
-        db_query("UPDATE {multiple_email} SET attempts=%d WHERE eid=%d", $attempts, $email->eid);
-        drupal_set_message('The confirmation code was incorrect');
-      }
-    } else {
-      // Confirmation successful!
-      multiple_email_confirm_email($email);
-      drupal_set_message("The address '{$email->email}' has been confirmed!");
-      drupal_goto('my-email-addresses');
-    }
-  } else {
-    watchdog('Multiple Email', 'Error loading email ' . $form_values['eid'], WATCHDOG_WARNING);
-  }
-  drupal_goto("my-email-addresses/confirm/{$form_values['eid']}");
+function multiple_email_confirm_form_submit($form, &$form_state) {
+  // Confirmation successful!
+  $email = $form_state['values']['email'];
+  multiple_email_confirm_email($email);
+  drupal_set_message("The address '{$email->email}' has been confirmed!");
 }
-?>
\ No newline at end of file
Index: multiple_email_delete_page.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/multiple_email/multiple_email_delete_page.inc,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 multiple_email_delete_page.inc
--- multiple_email_delete_page.inc	18 Dec 2007 04:42:22 -0000	1.1.2.1
+++ multiple_email_delete_page.inc	30 Apr 2010 04:12:18 -0000
@@ -16,26 +16,11 @@
   *
   * @return string
   */
-function multiple_email_delete_page($eid) {
-  global $user;
+function multiple_email_delete_page($account, $eid) {
+  $email = multiple_email_get_address($eid);
 
-  if ($email = multiple_email_get_address($eid)) {
-    if ($user->uid == $email->uid) {
-      if ($email->primary_address) {
-        drupal_set_message(t('You can not delete your primary email address!'));
-      } else {
-        return drupal_get_form('multiple_email_delete_form', $email);
-      }
-    } else {
-      drupal_set_message(t('Email address not found'));
-      watchdog('Multiple Email', 'Attempted unauthorized access to email ' . $eid . ' by user ' . $user->uid);
-    }
-  } else {
-    drupal_set_message(t('Email address not found'));
-    watchdog('Multiple Email', 'Failed to load address ' . $eid, WATCHDOG_WARNING);
-  }
-
-  drupal_goto('my-email-addresses');
+  menu_set_active_item('user/'. $account->uid .'/edit/email-addresses');
+  return drupal_get_form('multiple_email_delete_form', $account, $email);
 }
 
 /**
@@ -50,54 +35,34 @@ function multiple_email_delete_page($eid
  *
  * @return string
  */
-function multiple_email_delete_form($email) {
-  $form['eid'] = array(
-    '#type' => 'hidden',
-    '#value' => $email->eid,
+function multiple_email_delete_form(&$form_state, $account, $email) {
+  $form = array();
+  $form['#redirect'] = 'user/'. $account->uid .'/edit/email-addresses';
+
+  $form[] = array(
+    '#type' => 'markup',
+    '#value' => '<p>'. t("Are you sure you wish to delete the address '%email' from your user account?", array('%email' => $email->email)) .'</p>'
+  );
+
+  $form['email'] = array(
+    '#type' => 'value',
+    '#value' => $email,
   );
-  $form[]= array(
-    '#prefix' => '<p>',
-    '#value' => t("Are you sure you wish to delete the address '%email' from your user account?", array('%email'=>$email->email)),
-    '#suffix' => '</p>',
+
+  $form['account'] = array(
+    '#type' => 'value',
+    '#value' => $account,
   );
-  $form['confirm'] = array(
+  
+  $form['submit'] = array(
     '#type' => 'submit',
     '#value' => 'Delete',
   );
-  $url = base_path() . 'my-email-addresses';
-  $form['cancel'] = array(
-    '#type' => 'button',
-    '#value' => 'Cancel',
-    '#attributes' => array('onclick'=>"window.location='$url';return false;"),
-  );
 
   return $form;
 }
 
 /**
- * Validates multiple_email_delete_form
- *
- * @param string $form_id
- * @param array $form_values
- */
-function multiple_email_delete_form_validate($form_id, $form_values) {
-  global $user;
-
-  if ($email = multiple_email_get_address($form_values['eid'])) {
-    if ($user->uid != $email->uid) {
-      watchdog('Multiple Email', 'Attempted unauthorized access to email ' . $form_values['eid'] . ' by user ' . $user->uid);
-      drupal_goto('my-email-addresses');
-    } elseif ($email->primary_address) {
-      drupal_set_message('You cannot delete your primary email address!');
-      drupal_goto('my-email-addresses');
-    }
-  } else {
-    watchdog('Multiple Email', 'Invalid eid value: ' . $form_values['eid'], WATCHDOG_WARNING);
-    drupal_goto('my-email-addresses');
-  }
-}
-
-/**
  * Processes mulitple_email_delete_form_submit
  *
  * This is where users-input triggers deletion!
@@ -105,10 +70,11 @@ function multiple_email_delete_form_vali
  * @param string $form_id
  * @param array $form_values
  */
-function multiple_email_delete_form_submit($form_id, $form_values) {
-  $email = multiple_email_get_address($form_values['eid']);
-  multiple_email_delete_email($form_values['eid']);
+function multiple_email_delete_form_submit($form, &$form_state) {
+  $email = $form_state['values']['email'];
+  $account = $form_state['values']['account'];
+  
+  multiple_email_delete_email($email->eid);
   drupal_set_message("The email address '{$email->email}' has been removed from your account.");
-  drupal_goto('my-email-addresses');
+  $form_state['redirect'] = 'user/'. $account->uid .'/edit/email-addresses';
 }
-?>
\ No newline at end of file
Index: multiple_email_primary_page.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/multiple_email/multiple_email_primary_page.inc,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 multiple_email_primary_page.inc
--- multiple_email_primary_page.inc	18 Dec 2007 04:42:22 -0000	1.1.2.1
+++ multiple_email_primary_page.inc	30 Apr 2010 04:12:18 -0000
@@ -11,24 +11,11 @@
   *
   * @param integer $eid
   */
-function multiple_email_primary_page($eid) {
-  global $user;
+function multiple_email_primary_page($account, $eid) {
+  $email = multiple_email_get_address($eid);
 
-  if ($email = multiple_email_get_address($eid)) {
-    if ($user->uid == $email->uid) {
-      if ($email->primary_address) {
-        drupal_set_message("'{$email->email}' is already your primary address!");
-      } else {
-        return drupal_get_form('multiple_email_primary_form', $email);
-      }
-    } else {
-      watchdog('Multiple Email', 'Attempted unauthorized access to email ' . $eid . ' by user ' . $user->uid);
-    }
-  } else {
-    watchdog('Multiple Email', 'Failed to load address ' . $eid, WATCHDOG_WARNING);
-  }
-
-  drupal_goto('my-email-addresses');
+  menu_set_active_item('user/'. $account->uid .'/edit/email-addresses');
+  return drupal_get_form('multiple_email_primary_form', $account, $email);
 }
 
 /**
@@ -43,66 +30,49 @@ function multiple_email_primary_page($ei
  *
  * @return array
  */
-function multiple_email_primary_form($email) {
-  $form['eid'] = array(
-    '#type' => 'hidden',
-    '#value' => $email->eid,
+function multiple_email_primary_form(&$form_state, $account, $email) {
+  $form = array();
+  $form['#redirect'] = 'user/'. $account->uid .'/edit/email-addresses';
+
+  $form[] = array(
+    '#type' => 'markup',
+    '#value' => '<p>'. t("Are you sure you wish to make the address '{$email->email}' your primary email address?") . '</p>',
   );
-  $form[]= array(
-    '#prefix' => '<p>',
-    '#value' => "Are you sure you wish to make the address '{$email->email}' your primary email address?",
-    '#suffix' => '</p>',
+
+  $form['email'] = array(
+    '#type' => 'value',
+    '#value' => $email,
   );
-  $form['confirm'] = array(
-    '#type' => 'submit',
-    '#value' => 'Make Primary',
+
+  $form['account'] = array(
+    '#type' => 'value',
+    '#value' => $account,
   );
-  $url = base_path() . 'my-email-addresses';
-  $form['cancel'] = array(
-    '#type' => 'button',
-    '#value' => 'Cancel',
-    '#attributes' => array('onclick'=>"window.location='$url';return false;"),
+
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Make Primary'),
   );
 
   return $form;
 }
 
 /**
- * Validates multiple_email_primary_form
- *
- * @param string $form_id
- * @param array $form_values
- */
-function multiple_email_primary_form_validate($form_id, $form_values) {
-  global $user;
-
-  if ($email = multiple_email_get_address($form_values['eid'])) {
-    if ($user->uid != $email->uid) {
-      watchdog('Multiple Email', 'Attempted unauthorized access to email ' . $form_values['eid'] . ' by user ' . $user->uid);
-      drupal_goto('my-email-addresses');
-    } elseif ($email->primary_address) {
-      drupal_set_message("'{$email->email}' is already your primary address!");
-      drupal_goto('my-email-addresses');
-    }
-  } else {
-    watchdog('Multiple Email', 'Invalid eid value: ' . $form_values['eid'], WATCHDOG_WARNING);
-    drupal_goto('my-email-addresses');
-  }
-}
-
-/**
  * Processes multiple_email_primary_form submission
  *
  * @param string $form_id
  * @param array $form_values
  */
-function multiple_email_primary_form_submit($form_id, $form_values) {
-  global $user;
-
-  $email = multiple_email_get_address($form_values['eid']);
+function multiple_email_primary_form_submit($form, &$form_state) {
+  $email = $form_state['values']['email'];
+  $account = $form_state['values']['account'];
+  
+  if ($email->confirmed == 0) {
+     // if admin set address as primary, confirm email
+     multiple_email_confirm_email($email);
+  }
 
-  multiple_email_make_primary($user, $email);
+  multiple_email_make_primary($email);
   drupal_set_message("'{$email->email}' is now your primary email address.");
-  drupal_goto('my-email-addresses');
+  $form_state['redirect'] = 'user/'. $account->uid .'/edit/email-addresses';
 }
-?>
\ No newline at end of file
