diff --git a/README.md b/README.md index e2b811b..b821db3 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,22 @@ -# email-archive-manager -Plugin: Email Archive history viewer and manager +# Email Archive Manager plugin for Zen Cart + +Allows you to view emails sent by your shopping cart. Requires the `Email Archiving Active?` flag in Admin > Configuration > Email to be set to `true`. + +See `install.txt` for installation instructions. + +### New files: +`YOUR_ADMIN/email_archive_manager.php` +`YOUR_ADMIN/includes/extra_datafiles/email_archive_manager_defines.php` +`YOUR_ADMIN/includes/functions/extra_functions/reg_email_archive_manager.php` +`YOUR_ADMIN/includes/languages/english/email_archive_manager.php` + + +### Credits: +By Frank Koehl +- Additional coding support by DrByte +- Additional coding support by That Software Guy (www.thatsoftwareguy.com) +- Additional coding support by TwitchToo +- Code development sponsored by Destination ImagiNation, Inc. www.destinationimagination.org + + + diff --git a/admin/email_archive_manager.php b/admin/email_archive_manager.php new file mode 100644 index 0000000..f6c036b --- /dev/null +++ b/admin/email_archive_manager.php @@ -0,0 +1,506 @@ +Execute("select * from " . TABLE_EMAIL_ARCHIVE . " where archive_id = " . $_GET['archive_id']); + $email = new objectInfo($email_sql->fields); + // resend the message + // we use 'xml_record' to block out the HTML content. + zen_mail($email->email_to_name, $email->email_to_address, zen_output_string_protected($email->email_subject), $email->email_text, $email->email_from_name, $email->email_from_address, array(), 'xml_record'); + $messageStack->add_session(sprintf(SUCCESS_EMAIL_RESENT, $email->archive_id, $email->email_to_address), 'success'); + zen_redirect(zen_href_link(FILENAME_EMAIL_HISTORY)); + } + if ($action == 'delete') { + $db->Execute("delete from " . TABLE_EMAIL_ARCHIVE . " + where archive_id = '" . (int)$_GET['archive_id'] . "'"); + zen_redirect(zen_href_link(FILENAME_EMAIL_HISTORY)); + } + if ($action == 'trim_confirm') { + $age = $_GET['email_age']; + if ($age == '1_months') { + $cutoff_date = '1 MONTH'; + } + if ($age == '6_months') { + $cutoff_date = '6 MONTH'; + } + elseif ($age == '1_year') { + $cutoff_date = '12 MONTH'; + } + $db->Execute("DELETE FROM " . TABLE_EMAIL_ARCHIVE . " WHERE + date_sent <= DATE_SUB(NOW(), INTERVAL " . $cutoff_date . ")"); + $db->Execute("OPTIMIZE TABLE " . TABLE_EMAIL_ARCHIVE); + $messageStack->add_session(sprintf(SUCCESS_TRIM_ARCHIVE, $cutoff_date), 'success'); + zen_redirect(zen_href_link(FILENAME_EMAIL_HISTORY, '', 'NONSSL')); + } + $email_module = $db->Execute("SELECT DISTINCT module + FROM " . TABLE_EMAIL_ARCHIVE . " + ORDER BY module ASC"); + $email_module_array[] = array('id' => 1, + 'text' => TEXT_ALL_MODULES); + while (!$email_module->EOF) { + $email_module_array[] = array('id' => $email_module->fields['module'], + 'text' => $email_module->fields['module']); + $email_module->MoveNext(); + } + $search_sd = ((isset($_GET['start_date']) && zen_not_null($_GET['start_date'])) ? true : false); + $search_ed = ((isset($_GET['end_date']) && zen_not_null($_GET['end_date'])) ? true : false); + $search_text = ((isset($_GET['text']) && zen_not_null($_GET['text'])) ? true : false); + $search_module = ((isset($_GET['module']) && zen_not_null($_GET['module']) && $_GET['module'] != 1) ? true : false); + if ($search_sd) { + $sd_raw = zen_date_raw($_GET['start_date']); + } + if ($search_ed) { + $ed_raw = zen_date_raw($_GET['end_date']); + } +?> + +> + + + +<?php echo TITLE; ?> + + + + + + + + + + + + + + + + + '1.5.6') { ?> + + + + + + + + + + + + + +
+ + + + + +Execute("select * from " . TABLE_EMAIL_ARCHIVE . " + where archive_id = '" . $_GET['archive_id'] . "'"); + + $text_content = nl2br(zen_output_string_protected($this_email->fields['email_text'])); + if ($action=='prev_html') { + $html_safe = html_email_is_safe($this_email->fields['email_from_address'], $this_email->fields['module']); + if ($allow_html && $html_safe) { + $html_content = $this_email->fields['email_html']; + } else { + // Switch to text + $html_content = '' . HEADING_TEXT_INSTEAD . '

' . $text_content; + } + } +?> + + + + + + + + + + + + + + + +
+ + + +
fields['archive_id']; ?>
+ + + + + + + + + + + + + + + + +
fields['email_from_name'] . ' [' . $this_email->fields['email_from_address'] . ']'; ?>
fields['email_to_name'] . ' [' . $this_email->fields['email_to_address'] . ']'; ?>
fields['date_sent']); ?>
fields['email_subject']); ?>
+ + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + + +
+

+

+ +



+ + + + + + + + + + + + + + + + + + + + +
' . HEADING_TITLE . ''; ?>
' . TEXT_TRIM_ARCHIVE . ''; ?>
+ + + + + + +
+ + + + + + +
+ '; ?> + +
+ '; ?> + +
+ + + + + + +
'; + echo zen_draw_input_field('text'); + if (isset($_GET['text']) && zen_not_null($_GET['text'])) { + $keywords = zen_db_input(zen_db_prepare_input($_GET['text'])); + echo '
' . HEADING_SEARCH_TEXT_FILTER . $keywords; + } + ?>
'; + echo zen_draw_pull_down_menu('module', $email_module_array, (isset($_GET['module']) ? $_GET['module'] : '')); + ?>
+ + + + + + + + + +
+ + + + + +Execute("select customers_id from " . TABLE_CUSTOMERS . " + where customers_email_address like '" . $archive->email_to_address . "'"); + if ($customer->RecordCount() == 1) { + $mail_button = '' . SEND_NEW_EMAIL . ''; + } + else { + $mail_button = '' . SEND_NEW_EMAIL . ''; + } + + $heading[] = array('text' => '' . TEXT_ARCHIVE_ID . $archive->archive_id . '  -  ' . zen_datetime_short($archive->date_sent) . ''); + $contents[] = array('align' => 'center', 'text' => $mail_button . '

' . ' ' . IMAGE_ICON_RESEND . ''); + // Delete button + $contents[] = array('align' => 'center', 'text' => '' . IMAGE_ICON_DELETE . ''); + $contents[] = array('align' => 'center', 'text' => '' . IMAGE_ICON_TEXT . ''); + if ($archive->email_html != '') { + // For outbound messages only + $html_safe = html_email_is_safe($archive->email_from_address, $archive->module); + if ($allow_html && $html_safe) { + $contents[] = array('align' => 'center', 'text' => '' . IMAGE_ICON_HTML . ''); + } + } + $contents[] = array('text' => '
' . zen_draw_separator()); + $contents[] = array('text' => '
' . TEXT_EMAIL_MODULE . ''. $archive->module); + $contents[] = array('text' => '' . TEXT_EMAIL_FROM . '' . $archive->email_from_name . ' [' . $archive->email_from_address . ']'); + $contents[] = array('text' => '
' . TEXT_EMAIL_TO . ''. $archive->email_to_name . ' [' . $archive->email_to_address . ']'); + $contents[] = array('text' => '' . TEXT_EMAIL_DATE_SENT . '' . $archive->date_sent); + $contents[] = array('text' => '' . TEXT_EMAIL_SUBJECT . '' . zen_output_string_protected($archive->email_subject)); + $contents[] = array('text' => '
' . TEXT_EMAIL_EXCERPT . ''); + + $contents[] = array('text' => '
' . nl2br(substr(zen_output_string_protected($archive->email_text), 0, MESSAGE_SIZE_LIMIT)) . MESSAGE_LIMIT_BREAK); + } + + // display sidebox + if (zen_not_null($heading) && zen_not_null($contents) && $isForDisplay) { +?> + + + + +
+ + + + + + + += '" . $sd_raw . "' "; + + if ($search_ed) { + if ($search_sd) $archive_search .= "and "; + $archive_search .= "date_sent <= DATE_ADD('" . $ed_raw . "', INTERVAL 1 DAY) "; + } + + if ($search_text) { + if ($search_sd || $search_ed) $archive_search .= "and "; + + $keywords = zen_db_input(zen_db_prepare_input($_GET['text'])); + $archive_search .= "(email_to_address like '%" . $keywords . "%' or email_subject like '%" . $keywords . "%' or email_html like '%" . $keywords . "%' or email_text like '%" . $keywords . "%' or email_to_name like '%" . $keywords . "%') "; + } + + if ($search_module) { + if ($search_sd || $search_ed || $search_text) { + $archive_search .= "and "; + } + $archive_search .= "module = '" . $_GET['module'] . "' "; + } + + $archive_search .= "order by archive_id desc"; + + $email_split = new splitPageResults($_GET['page'], MAX_DISPLAY_SEARCH_RESULTS_ORDERS, $archive_search, $email_query_numrows); + + // DEBUG + //echo '
' . $archive_search . '
'; + $email_archive = $db->Execute($archive_search); + + while (!$email_archive->EOF) { + + if ((!isset($_GET['archive_id']) || (isset($_GET['archive_id']) && ($_GET['archive_id'] == $email_archive->fields['archive_id']))) && !isset($archive)) { + $archive = new objectInfo($email_archive->fields); + } + + if (isset($archive) && is_object($archive) && ($email_archive->fields['archive_id'] == $archive->archive_id) && $isForDisplay) { + echo ' ' . "\n"; + } else { + echo ' ' . "\n"; + } + +?> + + + + + + +MoveNext(); + } +?> + + + + +
fields['date_sent']); ?>fields['email_to_name']; ?>fields['email_to_address']; ?>fields['email_subject']), 0, SUBJECT_SIZE_LIMIT);?> + fields['email_subject']) > SUBJECT_SIZE_LIMIT) echo MESSAGE_LIMIT_BREAK; ?>fields['archive_id'] == $archive->archive_id) && $isForDisplay) { + echo zen_image(DIR_WS_IMAGES . 'icon_arrow_right.gif', ''); + } + else { + if ($email_archive->fields['email_html'] != '') { + echo TABLE_FORMAT_HTML; + } + else { + echo TABLE_FORMAT_TEXT; + } + } + ?>
display_count($email_query_numrows, MAX_DISPLAY_SEARCH_RESULTS_ORDERS, $_GET['page'], TEXT_DISPLAY_NUMBER_OF_EMAILS); ?>display_links($email_query_numrows, MAX_DISPLAY_SEARCH_RESULTS_ORDERS, MAX_DISPLAY_PAGE_LINKS, $_GET['page'], zen_get_all_get_params(array('archive_id', 'page'))); ?>
+ + + +
+infoBox($heading, $contents); +?> +
+ + + + + + + + diff --git a/admin/includes/extra_datafiles/email_archive_manager_defines.php b/admin/includes/extra_datafiles/email_archive_manager_defines.php new file mode 100644 index 0000000..61d7995 --- /dev/null +++ b/admin/includes/extra_datafiles/email_archive_manager_defines.php @@ -0,0 +1,7 @@ +%d to %d (of %d emails)'); +define('TEXT_EMAIL_MODULE', 'Module: '); +define('TEXT_EMAIL_TO', 'To: '); +define('TEXT_EMAIL_FROM', 'From: '); +define('TEXT_EMAIL_DATE_SENT', 'Sent: '); +define('TEXT_EMAIL_SUBJECT', 'Subject: '); +define('TEXT_EMAIL_EXCERPT', 'Message Excerpt:'); +define('TEXT_EMAIL_NUMBER', 'Email #'); + +define('RADIO_1_MONTH', ' 1 month'); +define('RADIO_6_MONTHS', ' 6 months'); +define('RADIO_1_YEAR', ' 12 months'); +define('TEXT_RESEND_PREFIX','Resend: '); +define('TRIM_CONFIRM_WARNING', 'Warning: This will permanently remove e-mail from the archive.
Are you sure?'); +define('POPUP_CONFIRM_RESEND', 'Are you sure you want to resend this message?'); +define('POPUP_CONFIRM_DELETE', 'Are you sure you want to delete this message?'); +define('SUCCESS_TRIM_ARCHIVE', 'Success: E-mail older than %s has been removed'); +define('SUCCESS_EMAIL_RESENT', 'Success: E-mail #%s has been resent to %s'); + +define('IMAGE_ICON_HTML', ' View HTML Message '); +define('IMAGE_ICON_TEXT', ' View Text Message '); +define('IMAGE_ICON_RESEND', ' Resend Message '); +define('IMAGE_ICON_EMAIL', ' Email Recipient '); +define('IMAGE_ICON_DELETE', ' Delete Message '); + +define('SEND_NEW_EMAIL', 'Send New Email'); +define('BUTTON_SEARCH', 'Search Archive'); +define('BUTTON_TRIM_CONFIRM', 'Delete e-mail'); +define('BUTTON_CANCEL', 'Cancel'); diff --git a/install.txt b/install.txt new file mode 100644 index 0000000..c4499ae --- /dev/null +++ b/install.txt @@ -0,0 +1,27 @@ +Email Archive Manager Install instructions + + +- Search for e-mails using any combination of date range, embodied text, or e-mail module. +- Printer-friendly display of email, including header information. +- Resend messages to the original recipient, with complete original headers +- One-click link to begin composing email to the recipient of the selected e-mail, both through the Zen web mail interface and a standard mailto link +- Trim archive database (to control size) at increments of 1, 6, or 12 months or messages can be deleted one at a time. + + + +***** DEVELOPERS START ***** + +Note: Always backup your shop files and database before making changes. + + +Installation: + +1. Download the package and unzip to a temp directory. + +2. Copy the contents of entire "admin" folder to the (renamed) admin folder of your shop, using the existing folder structure as a guide for where to put the new files. The files are already arranged in the appropriate structure, and there are *no* overwrites! + +3. You'll find "E-mail Archive Manager" under "Tools" in the Admin. You may need to assign it to additional user profiles, depending on who you wish to allow permission to use it. + +4. By default, email archiving is turned OFF; to start archiving emails, you must turn it ON under + Admin > Configuration > Email Options > Email Archiving Active? +