? 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'] = '
'; - $form['account']['mail']['#suffix'] = '
'; - // 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.') - . '
' - . t('Available variables are:') - . $vars, - '#default_value' => variable_get('multiple_email_confirmation_subject', multiple_email_default_subject('confirmation')), - ); - $form['multiple_email_confirmation_body'] = array( - '#type' => 'textarea', - '#title' => t('Confirmation Email Body'), - '#description' => t('Customize the body of the message to be sent when a user adds a new email to their account.') - . '
' - . t('Available variables are:') - . $vars, - '#default_value' => variable_get('multiple_email_confirmation_body', multiple_email_default_body('confirmation')), - ); - $form['multiple_email_expire_subject'] = array( - '#type' => 'textfield', - '#title' => t('Expire Email Subject'), - '#description' => t('Customize the subject of the message to be sent when an unconfirmed email address expires.') - . '
' - . t('Available variables are:') - . $vars, - '#default_value' => variable_get('multiple_email_expire_subject', multiple_email_default_subject('expire')), - ); - $form['multiple_email_expire_body'] = array( - '#type' => 'textarea', - '#title' => t('Expire Email Body'), - '#description' => t('Customize the body of the message to be sent when an unconfirmed email address expires.') - . '
' - . t('Available variables are:') - . $vars, - '#default_value' => variable_get('multiple_email_expire_body', multiple_email_default_body('expire')), - ); - - return system_settings_form($form); + $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.') + . '
' + . t('Available variables are:') + . $vars, + '#default_value' => variable_get('multiple_email_confirmation_subject', multiple_email_default_subject('confirmation')), + ); + $form['multiple_email_confirmation_body'] = array( + '#type' => 'textarea', + '#title' => t('Confirmation Email Body'), + '#description' => t('Customize the body of the message to be sent when a user adds a new email to their account.') + . '
' + . t('Available variables are:') + . $vars, + '#default_value' => variable_get('multiple_email_confirmation_body', multiple_email_default_body('confirmation')), + ); + $form['multiple_email_expire_subject'] = array( + '#type' => 'textfield', + '#title' => t('Expire Email Subject'), + '#description' => t('Customize the subject of the message to be sent when an unconfirmed email address expires.') + . '
' + . t('Available variables are:') + . $vars, + '#default_value' => variable_get('multiple_email_expire_subject', multiple_email_default_subject('expire')), + ); + $form['multiple_email_expire_body'] = array( + '#type' => 'textarea', + '#title' => t('Expire Email Body'), + '#description' => t('Customize the body of the message to be sent when an unconfirmed email address expires.') + . '
' + . t('Available variables are:') + . $vars, + '#default_value' => variable_get('multiple_email_expire_body', multiple_email_default_body('expire')), + ); + + return system_settings_form($form); } /** @@ -292,54 +347,55 @@ 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'])) { - form_set_error('multiple_email_confirm_attempts', 'Confirm attempts must be an number!'); - } - if (!is_numeric($form_values['multiple_email_confirm_deadline'])) { - form_set_error('multiple_email_confirm_deadline', 'Confirm Days must be an number!'); - } +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_state['values']['multiple_email_confirm_deadline'])) { + form_set_error('multiple_email_confirm_deadline', 'Confirm Days must be an number!'); + } } /** * Returns an array of information about the specified user's associated email * addresses. - * - * Index 0 contains an associative array of all the addresses in - * eid=>addresses format. Subsequent indexes are the eid of the address, + * + * Index 0 contains an associative array of all the addresses in + * eid=>addresses format. Subsequent indexes are the eid of the address, * then an object of properties corresponding to columns in the table. * * @param integer $uid * @param array $tablesortHeaders * @return array */ -function multiple_email_load_addresses($uid, $tablesortHeaders = null) { - $results = db_query(" - SELECT - a.eid, - a.uid, - a.email, - a.time_registered, - a.confirmed, - a.confirm_code, - a.time_code_generated, - a.attempts, - IF(a.email = u.mail, 1, 0) AS primary_address - FROM - {multiple_email} a - INNER JOIN {users} u ON (u.uid = a.uid) - WHERE - a.uid = %d" - . ($tablesortHeaders ? ' ' . tablesort_sql($tablesortHeaders) : ''), - $uid - ); - - while ($row = db_fetch_object($results)) { - $addresses[0][] = $row->email; - $addresses[$row->eid] = $row; - } - - return $addresses; +function multiple_email_load_addresses($uid, $tablesortHeaders = NULL) { + $addresses = array(); + $results = db_query(" + SELECT + a.eid, + a.uid, + a.email, + a.time_registered, + a.confirmed, + a.confirm_code, + a.time_code_generated, + a.attempts, + IF(a.email = u.mail, 1, 0) AS primary_address + FROM + {multiple_email} a + INNER JOIN {users} u ON (u.uid = a.uid) + WHERE + a.uid = %d" + . ($tablesortHeaders ? ' ' . tablesort_sql($tablesortHeaders) : ''), + $uid + ); + + while ($row = db_fetch_object($results)) { + $addresses[0][] = $row->email; + $addresses[$row->eid] = $row; + } + + return $addresses; } /** @@ -349,27 +405,27 @@ function multiple_email_load_addresses($ * @return object */ function multiple_email_get_address($eid) { - $result = db_query(" - SELECT - a.eid, - a.uid, - a.email, - a.time_registered, - a.time_registered, - a.confirmed, - a.confirm_code, - a.time_code_generated, - a.attempts, - IF(a.email = u.mail, 1, 0) AS primary_address - FROM - {multiple_email} a - INNER JOIN {users} u ON (u.uid = a.uid) - WHERE - a.eid = %d", - $eid - ); - - return db_fetch_object($result); + $result = db_query(" + SELECT + a.eid, + a.uid, + a.email, + a.time_registered, + a.time_registered, + a.confirmed, + a.confirm_code, + a.time_code_generated, + a.attempts, + IF(a.email = u.mail, 1, 0) AS primary_address + FROM + {multiple_email} a + INNER JOIN {users} u ON (u.uid = a.uid) + WHERE + a.eid = %d", + $eid + ); + + return db_fetch_object($result); } /** @@ -380,21 +436,20 @@ 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; } /** * Adds an unconfirmed email address to the email registry. - * + * * If you specify the 3rd parameter to be true, the email address will be * recorded as having been confirmed. - * + * * Returns the email's eid on success, false on failure. * * @param integer $uid @@ -402,52 +457,55 @@ function multiple_email_find_address($em * @param boolean $confirmed * @return mixed */ -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`) - VALUES - (%d, '%s', %d, %d, '%s', %d)", - $uid, - $email, - time(), - (int)$confirmed, - $code = multiple_email_code(10), - time() - ); - - if ($success !== false) { - $result = db_query("SELECT LAST_INSERT_ID() AS eid"); - $r = db_fetch_array($result); - return $r['eid']; - } else { - return 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`) + VALUES + (%d, '%s', %d, %d, '%s', %d)", + $uid, + $email, + time(), + (int)$confirmed, + $code = multiple_email_code(10), + time() + ); + + 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; + } } /** * Marks an email address as confirmed in the email registry * - * @param integer $uid - * @param string $email + * @param object $email + * Email row object to confirm * @return void */ -function multiple_email_confirm_email($uid, $email) { - watchdog('Multiple Email', "Marking address '$email' confirmed for user $uid", l('edit', "user/$uid")); - db_query(" - UPDATE {multiple_email} SET - confirmed = 1 - WHERE - uid = %d - AND email = '%s'", - $uid, - $email - ); +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")); + db_query(" + UPDATE {multiple_email} SET + confirmed = 1 + WHERE + eid = %d", + $email->eid + ); + $email->confirmed = 1; + module_invoke_all('multiple_email_confirm', $email); } /** * Generates a random string of given length from given characters. - * + * * If no characters are specified, then it uses a-zA-Z0-9. Characters are * specified as a string containing every valid character. Duplicates will * (in theory) increase that character's chances of occurring in the random @@ -458,21 +516,22 @@ function multiple_email_confirm_email($u * @return string */ function multiple_email_code($length, $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUBWXYZ0123456789') { - $cl = strlen($chars) - 1; - $out = ''; - for ($i=0;$i<$length;$i++) - $out .= $chars[rand(0,$cl)]; - return $out; + $cl = strlen($chars) - 1; + $out = ''; + for ($i=0; $i < $length; $i++) { + $out .= $chars[rand(0, $cl)]; + } + return $out; } /** * Deletes specified email from registry - no error checking! - * + * * @param integer $eid * @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); } /** @@ -481,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)); } /** @@ -493,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. @@ -505,13 +589,26 @@ function multiple_email_send_confirmatio * @param integer $eid */ function multiple_email_expire_address($eid) { - $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); - multiple_email_delete_email($eid); - drupal_mail('multiple_email_expire', $account->mail, $subject, $body, variable_get('site_mail', ini_get('sendmail_from'))); - watchdog('Multiple Email', "{$email->email} ({$email->eid}) for {$account->name} ({$account->uid}) has expired and been removed"); + global $language; + + $email = multiple_email_get_address($eid); + $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); + $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']); } /** @@ -524,9 +621,9 @@ function multiple_email_expire_address($ * @return string */ function multiple_email_message_part($part, $type, $account, $email) { - $func = "multiple_email_default_{$part}"; - $setting = variable_get("multiple_email_{$type}_{$part}", $func($type)); - return multiple_email_var_replace($setting, $account, $email); + $func = "multiple_email_default_{$part}"; + $setting = variable_get("multiple_email_{$type}_{$part}", $func($type)); + return multiple_email_var_replace($setting, $account, $email); } /** @@ -536,11 +633,11 @@ function multiple_email_message_part($pa * @return string */ function multiple_email_default_subject($type) { - $subjects = array( - 'confirmation' => 'Confirm your email address at !site', - 'expire' => 'Your email address at !site has expired', - ); - return $subjects[$type]; + $subjects = array( + 'confirmation' => 'Confirm your email address at !site', + 'expire' => 'Your email address at !site has expired', + ); + return $subjects[$type]; } /** @@ -550,13 +647,13 @@ function multiple_email_default_subject( * @return string */ function multiple_email_default_body($type) { - $func = "multiple_email_default_{$type}_body"; - return $func(); + $func = "multiple_email_default_{$type}_body"; + return $func(); } /** * Replaces various tokens with their value - * + * * Valid tokens: * !username (User's username) * !site (Site's name) @@ -571,15 +668,15 @@ function multiple_email_default_body($ty * @return string */ function multiple_email_var_replace($text, $account, $email) { - $vars = array( - '!username' => $account->name, - '!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_deadline' => variable_get('multiple_email_confirm_deadline', 5) . ' days', - ); - return str_ireplace(array_keys($vars), array_values($vars), $text); + $vars = array( + '!username' => $account->name, + '!email' => $email->email, + '!site' => variable_get('site_name', 'our web site'), + '!confirm_code' => $email->confirm_code, + '!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); } /** @@ -589,7 +686,7 @@ function multiple_email_var_replace($tex * @return string */ function multiple_email_default_confirmation_body() { - $message = << \ No newline at end of file + return $message; +} \ 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 diff -u -p -r1.1 multiple_email_add_page.inc --- multiple_email_add_page.inc 16 Dec 2007 17:52:22 -0000 1.1 +++ multiple_email_add_page.inc 30 Apr 2010 04:23:03 -0000 @@ -1,21 +1,19 @@ -uid .'/edit/email-addresses'); + return drupal_get_form('multiple_email_add_form', $account); } /** @@ -24,25 +22,31 @@ function multiple_email_add_page() { * @ingroup forms * @param object $account User object */ -function multiple_email_add_form($account) { - $form['email'] = array( - '#type' => 'textfield', - '#title' => t('Email Address'), - '#required' => true, - ); - $form[] = 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; +function multiple_email_add_form(&$form_state, $account) { + $form['email'] = array( + '#type' => 'textfield', + '#title' => t('Email Address'), + '#required' => TRUE, + ); + + $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'), + ); + + return $form; } /** @@ -51,12 +55,13 @@ 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'])) { - form_set_error('email', t('You must enter a valid email address!')); - } elseif (multiple_email_find_address($form_values['email'])) { - form_set_error('email', t('Entered address is already registered on this site.')); - } +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_state['values']['email'])) { + form_set_error('email', t('Entered address is already registered on this site.')); + } } /** @@ -65,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']))); - } - drupal_goto('my-email-addresses'); +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']))); + } } -?> \ 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 diff -u -p -r1.1 multiple_email_addresses_page.inc --- multiple_email_addresses_page.inc 16 Dec 2007 17:52:22 -0000 1.1 +++ multiple_email_addresses_page.inc 30 Apr 2010 04:23:03 -0000 @@ -1,43 +1,76 @@ - t('Email Address'), - 'field' => 'a.email', - ); - $headers[] = array( - 'data' => t('Confirmed?'), - 'field' => 'a.confirmed', - ); - $headers[] = array( - 'data' => t('Primary Address?'), - 'field' => 'primary_address', - 'sort' => 'desc', - ); - $headers[] = array( - 'data' => t('Remove'), - ); - - $addresses = multiple_email_load_addresses($user->uid, $headers); - unset($addresses[0]); - - $out .= drupal_get_form('multiple_email_addresses_form', $addresses, $headers); - - return $out; + /** + * Renders the page to manage user's email addresses + * + * @return string + */ +function multiple_email_addresses_page($account) { + $addresses = multiple_email_load_addresses($account->uid); + unset($addresses[0]); + + $header[] = array( + 'data' => t('Email Address'), + ); + + $header[] = array( + 'data' => t('Confirmed?'), + ); + $header[] = array( + 'data' => t('Primary Address?'), + ); + + $header[] = array( + 'data' => t('Delete'), + ); + + $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; } /** @@ -48,34 +81,57 @@ function multiple_email_addresses_page() * @param array $addresses * @param array $headers */ -function multiple_email_addresses_form($addresses, $headers) { - $form['#headers'] = $headers; - $form['#columns'] = array('email', 'confirmed', 'primary', 'delete'); - - $form['add']['#value'] = l('Add Email Address', 'my-email-addresses/add'); - - foreach ($addresses as $eid=>$a) { - $aid = "address_$eid"; - $form[$aid]["email_$eid"] = array( - '#value' => $a->email, - ); - $form[$aid]["confirmed_$eid"] = array( - '#value' => $a->confirmed ? 'Yes' : l('Click here to confirm', "my-email-addresses/confirm/$eid"), - ); - $form[$aid]["primary_$eid"] = array( - '#value' => $a->primary_address ? 'Primary' : l('Make Primary', "my-email-addresses/make-primary/$eid"), - ); - $form[$aid]["delete_$eid"] = array( - '#value' => $a->primary_address ? '' : l('X', "my-email-addresses/delete/$eid"), - ); - } - - return $form; +function multiple_email_addresses_($account) { + global $user; + + $addresses = multiple_email_load_addresses($user->uid, $headers); + + unset($addresses[0]); + + $headers[] = array( + 'data' => t('Email Address'), + 'field' => 'a.email', + ); + $headers[] = array( + 'data' => t('Confirmed?'), + 'field' => 'a.confirmed', + ); + $headers[] = array( + 'data' => t('Primary Address?'), + 'field' => 'primary_address', + 'sort' => 'desc', + ); + $headers[] = array( + 'data' => t('Remove'), + ); + + $form['#headers'] = $headers; + $form['#columns'] = array('email', 'confirmed', 'primary', 'delete'); + + $form['add']['#value'] = theme('multiple_email_add_address_link'); + + foreach ($addresses as $eid => $a) { + $aid = "address_$eid"; + $form[$aid]["email_$eid"] = array( + '#value' => $a->email, + ); + $form[$aid]["confirmed_$eid"] = array( + '#value' => $a->confirmed ? 'Yes' : l('Click here to confirm', "my-email-addresses/confirm/$eid"), + ); + $form[$aid]["primary_$eid"] = array( + '#value' => $a->primary_address ? 'Primary' : l('Make Primary', "my-email-addresses/make-primary/$eid"), + ); + $form[$aid]["delete_$eid"] = array( + '#value' => $a->primary_address ? '' : l('X', "my-email-addresses/delete/$eid"), + ); + } + + return $form; } /** * Themes multiple_email_addresses_form - * + * * Basically it builds the table from the data in the form, so you could * present the data in a different format by overriding the theme function. * @@ -84,34 +140,48 @@ 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']); - - $out = ''; - $rows = array(); - // NOTE: Reference $form instead of $member so that $form values are - // updated upon being rendered! - foreach ($form as $aid=>$member) { - if (preg_match('/address_(\d+)/i', $aid, $matches)) { - $row = array(); - $eid = $matches[1]; - foreach ($columns as $c) { - switch ($c) { - // Should simply this since switch isn't used anymore - default: - $row[] = array( - 'data' => drupal_render($form[$aid][$c . '_' . $eid]), - 'class' => "multiple-email-table-$c", - ); - break; - } - } - $rows[] = $row; - } - } - $out .= theme('table', $headers, $rows, array('class'=>'multiple-email-table')); - $out .= drupal_render($form); - return $out; + + $headers = $form['#headers']; + $columns = $form['#columns']; + unset($form['#headers'], $form['#columns']); + + $out = ''; + $rows = array(); + // NOTE: Reference $form instead of $member so that $form values are + // updated upon being rendered! + foreach ($form as $aid => $member) { + if (preg_match('/address_(\d+)/i', $aid, $matches)) { + $row = array(); + $eid = $matches[1]; + foreach ($columns as $c) { + switch ($c) { + // Should simply this since switch isn't used anymore + default: + $row[] = array( + 'data' => drupal_render($form[$aid][$c . '_' . $eid]), + 'class' => "multiple-email-table-$c", + ); + } + } + $rows[] = $row; + } + } + + + $out .= theme('table', $headers, $rows, array('class' => 'multiple-email-table')); + $out .= drupal_render($form); + return $out; } -?> \ No newline at end of file + +/** + * Themes the link to add a new email address + * + * @ingroup themable + * + * @return string + * HTML + */ +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 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 diff -u -p -r1.1 multiple_email_confirm_page.inc --- multiple_email_confirm_page.inc 16 Dec 2007 17:52:22 -0000 1.1 +++ multiple_email_confirm_page.inc 30 Apr 2010 04:23:03 -0000 @@ -1,84 +1,100 @@ -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; + /** + * Renders the page to confirm an email address + * + * If code is passed in on URL, then it will populate that value in the text + * field. + * + * @param integer $eid + * @param string $code + * @return string + */ +function multiple_email_confirm_page($account, $eid, $code = NULL) { + $email = multiple_email_get_address($eid); + + menu_set_active_item('user/'. $account->uid .'/edit/email-addresses'); + return drupal_get_form('multiple_email_confirm_form', $account, $email, $code); } /** * Builds email confirmation form * * @ingroup forms - * + * * @see multiple_email_confirm_form_submit() - * + * * @param object $email * @param string $confirm_code * @return array */ -function multiple_email_confirm_form($email, $confirm_code) { - $form['eid'] = array( - '#type' => 'hidden', - '#value' => $email->eid, - ); - $form[] = array( - '#prefix' => '

', - '#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