? LICENSE.txt ? multiple_email.test Index: README.txt =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/multiple_email/README.txt,v retrieving revision 1.1 diff -u -p -r1.1 README.txt --- README.txt 16 Dec 2007 17:52:22 -0000 1.1 +++ README.txt 30 Apr 2010 04:23:02 -0000 @@ -31,4 +31,15 @@ Configuration -> Multiple Email Settings straight-forward at this point and are documented in the field descriptions. The module will create a menu item in the Navigation menu called 'My Email -Addresses' that links to the user's email management page. \ No newline at end of file +Addresses' that links to the user's email management page. + +Hooks +----- +hook_multiple_email_register($email) + - $email is the email object that has just been registered + - Use this hook to perform actions when a user registers an email address + (but isn't confirmed yet) + +hook_multiple_email_confirm($email) + - $email is the email object that has just been registered + - Use this hook to perform actions when a user confirms an email address \ No newline at end of file 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:23:02 -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 diff -u -p -r1.1 multiple_email.install --- multiple_email.install 16 Dec 2007 17:52:22 -0000 1.1 +++ multiple_email.install 30 Apr 2010 04:23:02 -0000 @@ -1,55 +1,89 @@ - \ 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 diff -u -p -r1.1 multiple_email.module --- multiple_email.module 16 Dec 2007 17:52:22 -0000 1.1 +++ multiple_email.module 30 Apr 2010 04:23:03 -0000 @@ -1,65 +1,59 @@ - 5, - 'confirm_attempts' => 3, - 'hide_field' => 1, - ); - - // Specify every message type to have its defaults initialized - $messages = array( - 'confirmation', - 'expire' - ); - $parts = array( - 'subject', - 'body', - ); - foreach ($messages as $type) { - foreach ($parts as $part) { - $func = "multiple_email_default_{$part}"; - $vars["{$type}_{$part}"] = $func($type); - } - } - - foreach ($vars as $var=>$default) { - $current = variable_get("multiple_email_$var", $default); - variable_set("multiple_email_$var", $current); - } - - drupal_set_message(t("Multiple Email settings are available under !link", - array( '!link' => l('Administer > Site configuration > Multiple Email Settings ', 'admin/settings/multiple-email/settings' ) ) - )); + // Add each variable and its default value to this array + $vars = array( + 'confirm_deadline' => 5, + 'confirm_attempts' => 3, + 'hide_field' => 1, + ); + + // Specify every message type to have its defaults initialized + $messages = array( + 'confirmation', + 'expire' + ); + $parts = array( + 'subject', + 'body', + ); + foreach ($messages as $type) { + foreach ($parts as $part) { + $func = "multiple_email_default_{$part}"; + $vars["{$type}_{$part}"] = $func($type); + } + } + + foreach ($vars as $var => $default) { + $current = variable_get("multiple_email_$var", $default); + variable_set("multiple_email_$var", $current); + } + + drupal_set_message(t("Multiple Email settings are available under !link", + array( '!link' => l('Administer > Site configuration > Multiple Email Settings ', 'admin/settings/multiple-email/settings' ) ) + )); } /** @@ -67,7 +61,7 @@ function multiple_email_enable() { * */ function multiple_email_perm() { - return array('multiple emails'); + return array('multiple emails', 'administer multiple emails'); } /** @@ -76,55 +70,110 @@ function multiple_email_perm() { * @param boolean $may_cache * @return array */ -function multiple_email_menu($may_cache) { - $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'), - ); - } - return $items; +function multiple_email_menu() { + $items = array(); + + $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; } /** @@ -137,42 +186,31 @@ function multiple_email_menu($may_cache) * @return mixed */ 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 - multiple_email_confirm_email($account->uid, $account->mail); - } - 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. - */ - 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 (multiple_email_find_address($edit['mail'])) { - form_set_error('mail', t('The e-mail address %email is already registered. Have you forgotten your password?', array('%email' => $edit['mail'], '@password' => url('user/password')))); - } - break; - } + switch ($op) { + 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': + 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); + } + break; + case 'delete': + // delete Multiple Emails from the deleting user. + db_query("DELETE FROM {multiple_email} WHERE uid = %d", $account->uid); + break; + } } /** * Implementation of hook_form_alter() - * + * * Remove email field from profile edit -- this will be done in address * management screen, now. * @@ -180,16 +218,34 @@ 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)) { - // 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'] = '
'; - // TODO: Put admin-only fields here for changing primary email - // ... or maybe a separate admin email management interface - } +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 + $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, + ); + } } /** @@ -197,25 +253,24 @@ function multiple_email_form_alter($form * */ function multiple_email_cron() { - $deadline = (int)variable_get('multiple_email_confirm_deadline', 5); - if ($deadline) { - $result = db_query(" - SELECT - e.eid, - e.time_code_generated, - IF(u.mail = e.email, 1, 0) as primary_address - FROM - {multiple_email} e - INNER JOIN {users} u ON (u.uid = e.uid) - WHERE confirmed=0"); - $now = time(); - while ($row = db_fetch_object($result)) { - watchdog('Multiple Email', print_r($row, true)); - if (strtotime("+$deadline days", $row->time_code_generated) <= $now && !$row->primary_address) { - multiple_email_expire_address($row->eid); - } - } - } + $deadline = (int)variable_get('multiple_email_confirm_deadline', 5); + if ($deadline) { + $result = db_query(" + SELECT + e.eid, + e.time_code_generated, + IF(u.mail = e.email, 1, 0) as primary_address + FROM + {multiple_email} e + INNER JOIN {users} u ON (u.uid = e.uid) + WHERE confirmed=0"); + $now = time(); + while ($row = db_fetch_object($result)) { + if (strtotime("+$deadline days", $row->time_code_generated) <= $now && !$row->primary_address) { + multiple_email_expire_address($row->eid); + } + } + } } /** @@ -224,66 +279,66 @@ function multiple_email_cron() { * @ingroup forms */ function multiple_email_admin_settings() { - $form['multiple_email_hide_field'] = array( - '#type' => 'select', - '#title' => t('Hide Email Field'), - '#description' => t('Hides the email field when editing a user'), - '#options' => array('No', 'Yes'), - '#default_value' => variable_get('multiple_email_hide_field', 1), - ); - $form['multiple_email_confirm_attempts'] = array( - '#type' => 'textfield', - '#size' => 4, - '#title' => t('Confirm Attempts'), - '#description' => t('How many times a user enters a confirmation code before a new one is generated. If set to 0, no new codes are sent after the first one.'), - '#default_value' => variable_get('multiple_email_confirm_attempts', 3), - ); - $form['multiple_email_confirm_deadline'] = array( - '#type' => 'textfield', - '#size' => 4, - '#title' => t('Confirm Days'), - '#description' => t('How many days a user has to enter a confirmation code. If 0, emails pending confirmation do not expire.'), - '#default_value' => variable_get('multiple_email_confirm_deadline', 5), - ); - $vars = '!username, !site, !email, !confirm_code, !confirm_url, !confirm_deadline'; - $form['multiple_email_confirmation_subject'] = array( - '#type' => 'textfield', - '#title' => t('Confirmation Email Subject'), - '#description' => t('Customize the subject of the message to be sent when a user adds a new email to their account.') - . '', - '#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' => '
', - ); - $form['code'] = array( - '#type' => 'textfield', - '#title' => t('Confirmation Code'), - '#required' => true, - '#default_value' => $confirm_code, - ); - $form['confirm'] = 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;"), - ); - - return $form; +function multiple_email_confirm_form(&$form_state, $account, $email, $confirm_code) { + $form = array(); + + $form['#redirect'] = 'user/'. $account->uid .'/edit/email-addresses'; + + $form[] = array( + '#type' => 'markup', + '#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)) . '
', + ); + + $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, + '#default_value' => $confirm_code, + ); + + $form['submit'] = array( + '#type' => 'submit', + '#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'); + } + } } /** @@ -87,45 +103,9 @@ function multiple_email_confirm_form($em * @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($user->uid, $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 diff -u -p -r1.1 multiple_email_delete_page.inc --- multiple_email_delete_page.inc 16 Dec 2007 17:52:22 -0000 1.1 +++ multiple_email_delete_page.inc 30 Apr 2010 04:23:03 -0000 @@ -1,39 +1,26 @@ -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'); + /** + * Shows confirmation that you want to delete the specified email address + * + * If the second argument is true, then it will just go ahead and delete. + * + * @param integer $eid + * ID of the email to be deleted + * + * @return string + */ +function multiple_email_delete_page($account, $eid) { + $email = multiple_email_get_address($eid); + + menu_set_active_item('user/'. $account->uid .'/edit/email-addresses'); + return drupal_get_form('multiple_email_delete_form', $account, $email); } /** @@ -42,71 +29,52 @@ function multiple_email_delete_page($eid * @ingroup forms * @see multiple_email_delete_form_validate() * @see multiple_email_delete_form_submit() - * + * * @param object $email * Email object from the database - * + * * @return string */ -function multiple_email_delete_form($email) { - $form['eid'] = array( - '#type' => 'hidden', - '#value' => $email->eid, - ); - $form[]= array( - '#prefix' => '', - '#value' => t("Are you sure you wish to delete the address '%email' from your user account?", array('%email'=>$email->email)), - '#suffix' => '
', - ); - $form['confirm'] = 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; -} +function multiple_email_delete_form(&$form_state, $account, $email) { + $form = array(); + $form['#redirect'] = 'user/'. $account->uid .'/edit/email-addresses'; -/** - * 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'); - } + $form[] = array( + '#type' => 'markup', + '#value' => ''. t("Are you sure you wish to delete the address '%email' from your user account?", array('%email' => $email->email)) .'
' + ); + + $form['email'] = array( + '#type' => 'value', + '#value' => $email, + ); + + $form['account'] = array( + '#type' => 'value', + '#value' => $account, + ); + + $form['submit'] = array( + '#type' => 'submit', + '#value' => 'Delete', + ); + + return $form; } /** * Processes mulitple_email_delete_form_submit - * + * * This is where users-input triggers deletion! * * @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']); - drupal_set_message("The email address '{$email->email}' has been removed from your account."); - drupal_goto('my-email-addresses'); +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."); + $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 diff -u -p -r1.1 multiple_email_primary_page.inc --- multiple_email_primary_page.inc 16 Dec 2007 17:52:22 -0000 1.1 +++ multiple_email_primary_page.inc 30 Apr 2010 04:23:03 -0000 @@ -1,32 +1,21 @@ -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'); + /** + * Renders page to confirm making an address primary + * + * @param integer $eid + */ +function multiple_email_primary_page($account, $eid) { + $email = multiple_email_get_address($eid); + + menu_set_active_item('user/'. $account->uid .'/edit/email-addresses'); + return drupal_get_form('multiple_email_primary_form', $account, $email); } /** @@ -35,57 +24,37 @@ function multiple_email_primary_page($ei * @ingroup forms * @see multiple_email_primary_form_validate() * @see multiple_email_primary_form_submit() - * + * * @param object $email * And email object from the database - * + * * @return array */ -function multiple_email_primary_form($email) { - $form['eid'] = array( - '#type' => 'hidden', - '#value' => $email->eid, - ); - $form[]= array( - '#prefix' => '', - '#value' => "Are you sure you wish to make the address '{$email->email}' your primary email address?", - '#suffix' => '
', - ); - $form['confirm'] = array( - '#type' => 'submit', - '#value' => 'Make Primary', - ); - $url = base_path() . 'my-email-addresses'; - $form['cancel'] = array( - '#type' => 'button', - '#value' => 'Cancel', - '#attributes' => array('onclick'=>"window.location='$url';return false;"), - ); - - return $form; -} +function multiple_email_primary_form(&$form_state, $account, $email) { + $form = array(); + $form['#redirect'] = 'user/'. $account->uid .'/edit/email-addresses'; -/** - * 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'); - } + $form[] = array( + '#type' => 'markup', + '#value' => ''. t("Are you sure you wish to make the address '{$email->email}' your primary email address?") . '
', + ); + + $form['email'] = array( + '#type' => 'value', + '#value' => $email, + ); + + $form['account'] = array( + '#type' => 'value', + '#value' => $account, + ); + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Make Primary'), + ); + + return $form; } /** @@ -94,13 +63,16 @@ function multiple_email_primary_form_val * @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']); - - multiple_email_make_primary($user, $email); - drupal_set_message("'{$email->email}' is now your primary email address."); - drupal_goto('my-email-addresses'); +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($email); + drupal_set_message("'{$email->email}' is now your primary email address."); + $form_state['redirect'] = 'user/'. $account->uid .'/edit/email-addresses'; } -?> \ No newline at end of file