Code:
<?php
//
// Email Generator V1.00
//
// This script generates an HTML email from a list of product IDs for
// use in an email campaign.
//
//
//
//
$template_file = "email.tpl.php";
require('includes/application_top.php');
//require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_PRODUCT_INFO);
// Check login
//
// Get the action, either from the form that was posted or from the URL.
//
if (isset($_GET['action'])) {
$action = $_GET['action'];
} else {
$action = $_REQUEST['form']['action'];
}
//
// Perform based on the particular action that was defined.
//
if ($action == "generateemail") {
$form = $_REQUEST['form'];
//
// Clean the product list that the user submitted by removing and carriage returns
// or line feeds. Also replace and commas with spaces and kick out multiple spaces
// from the string. Finally, we trim any spaces from the beginning or end of the
// string and strip out any values that are not numeric (since all of the product
// IDs are numeric).
//
$form['productlist'] = preg_replace("/[\r\n\,]/", " ", $form['productlist']);
$form['productlist'] = preg_replace("/\s+/", " ", $form['productlist']);
$form['productlist'] = trim($form['productlist']);
//
// If the product list was defined, then we split it out into an array at the spaces.
//
if (strlen($form['productlist']) > 0) {
$product_ids = explode(" ", $form['productlist']);
}
//
// If we have product IDs, then we need to get the necessary product information from
// the database. We store the product information from the database into an array for
// reference in the output. For compatability, we use the same functions that are
// used by OScommerce.
//
if (count($product_ids) > 0) {
$sql = "SELECT p.products_id, p.products_status, pd.products_name, pd.products_description,
p.products_model, p.products_quantity, p.products_image, pd.products_url, p.products_price,
p.products_tax_class_id, p.products_date_added, p.products_date_available,
p.manufacturers_id FROM " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd
WHERE p.products_id IN ('".implode("','", $product_ids)."') AND pd.products_id = p.products_id
AND pd.language_id = '" . $languages_id . "'";
$results = $db->Execute($sql);
while (!$results->EOF) {
$product['id'.$row->fields['products_id']] = $row->fields;
$results->MoveNext();
}
unset($sql, $row, $results);
//
// Get the output template information from the file and store the data for
// reference.
//
$fhandle = fopen($template_file, "r");
$content = fread($fhandle, filesize($template_file));
fclose($fhandle);
$lines = preg_split("/[\r\n]/", $content);
if (count($lines) > 0) {
foreach ($lines as $line) {
if (preg_match("/\\$\\$(\S+)/", $line, $matches)) {
$section = strtolower($matches[1]);
} elseif (isset($section)) {
$emailtemp[$section] .= $line."\n";
}
}
}
unset($content, $sections, $section);
$page = 2;
}
$edit = $form;
unset($form, $action);
}
?>
<html>
<head>
<title>Email Generator V1.00</title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<style type="text/css">
<!--
body {
background-color: #FFFFFF;
font-family: tahoma;
font-size: 11px;
}
label {
margin: 3px 0 0 0;
display: block;
width: 130px;
float: left;
padding: 3px 0 0 0;
clear: both;
}
label.required {
font-weight: bold;
}
table {
font-size: 11px;
}
-->
</style>
</head>
<body>
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->
<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
<tr>
<td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
<!-- left_navigation //-->
<?php //require(DIR_WS_INCLUDES . 'column_left.php'); THIS WAS CAUSING ERRORS SO I COMMENTED OUT FOR NOW ?>
<!-- left_navigation_eof //-->
</table></td>
<!-- body_text //-->
<td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td class="pageHeading">Email Generator V1.00</td>
<td class="pageHeading" align="right"><?php echo zen_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
</tr>
</table></td>
</tr>
<tr>
<td>
<?php
//
// The output depends on what page is currently being displayed.
//
if ($page == 2) {
?>
<br>
<b>Results</b><br>
<?php
if (count($product_ids) > 0) {
?>
<table cellpadding="2" cellspacing="0">
<tr style="font-weight: bold;"><td>Product ID</td><td>Status</td><td>Name</td></tr>
<?php
$html_string = $emailtemp['header'];
foreach ($product_ids as $product_id) {
if (isset($product['id'.$product_id])) {
$template_data = $product['id'.$product_id];
$template_data['products_price'] = number_format($template_data['products_price'], 2);
$html_string .= preg_replace("/\<\<(.*?)\>\>/e", "\$template_data['\\1']", $emailtemp['content']);
?>
<tr><td><?=$product_id?></td><td>Found</td><td><?=htmlentities($product['id'.$product_id]['products_name'])?></td></tr>
<?php
} else {
?>
<tr><td><?=$product_id?></td><td>Not Found</td><td>N/A</td></tr>
<?php
}
}
$html_string .= $emailtemp['footer'];
?>
</table>
<?php
}
?>
<br>
<b>HTML Code</b><br>
<form>
<textarea cols="60" rows="10">
<?=htmlentities($html_string)?>
</textarea>
</form>
<br>
<?php
}
?>
Enter the product IDs in the order in which you'd like for them to appear in the email.
<br>
<form method="post" action="generate_email2.php">
<input type="hidden" name="form[action]" value="generateemail">
<label class="required" for="productlist">Product IDs</label><textarea id="productlist" name="form[productlist]" cols="30" rows="5"><?=$edit['productlist']?></textarea>
<br> <br>
<input type="submit" value="Generate">
</form>
</td>
</tr>
</table></td>
</tr>
</table>
<!-- body_eof //-->
<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
<br>
</body>
</html>
<?php
require(DIR_WS_INCLUDES . 'application_bottom.php');
//
// Functions
//
function convertHTMLArray($array)
{
// This function accepts a single-dimensional array, runs through the elements
// and converts special characters to HTML tags.
if (is_array($array)) {
foreach ($array as $key => $val) {
$array[$key] = htmlspecialchars(stripslashes($val));
}
} else {
$array = NULL;
}
return $array;
}
?>
Bookmarks