function back_in_stock_send($product_id = 0, $bis_id = 0, $preview = true) { global $db; cleanse_back_in_stock_subscriptions(); if ($product_id != 0) { $addtl_where = ' AND product_id=' . $product_id; } else { $addtl_where = ''; } if ($bis_id != 0) { $addtl_where .= ' AND bis_id=' . $bis_id; } // Find all Items in notifications $bis_emails = array(); $now = time(); $bis_products = $db->Execute("SELECT p.products_id, pd.products_name, b.product_id, b.last_sent, b.email, b.name, b.bis_id, b.active_til_purch, b.sub_active FROM " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_BACK_IN_STOCK . " b WHERE p.products_id = pd.products_id AND p.products_id = b.product_id AND p.products_quantity > 0 AND sub_active=1 " . $addtl_where); while (!$bis_products->EOF) { echo 'Back in stock: ' . $bis_products->fields['products_name'] . "\n" . "<br/>"; $your_date = strtotime($bis_products->fields['last_sent']); $datediff = $now - $your_date; $days_since = floor($datediff / (60 * 60 * 24)); if (BACK_IN_STOCK_DAYS_WAITING > $days_since && BACK_IN_STOCK_DAYS_WAITING != '0') { $bis_products->MoveNext(); } $bis_emails[] = array('email' => $bis_products->fields['email'], 'name' => stripslashes($bis_products->fields['name']), 'product_id' => $bis_products->fields['product_id'], 'bis_id' => $bis_products->fields['bis_id'], 'active_til_purch' => $bis_products->fields['active_til_purch']); $bis_products->MoveNext(); } $counted = 0; if (!$preview) { foreach ($bis_emails as $emails) { if ($emails['email'] == '') { continue; } if ($counted >= (int) BACK_IN_STOCK_MAX_EMAILS_PER_BATCH && BACK_IN_STOCK_MAX_EMAILS_PER_BATCH != '0') { break; } $customers_name = stripslashes($emails['name']); $customers_email = $emails['email']; $html_message = array(); $html_message['CUSTOMERS_NAME'] = $customers_name; $html_message['PRODUCT_NAME'] = strip_tags(zen_get_products_name($emails['product_id'])); $html_message['SPAM_LINK'] = HTTPS_SERVER . DIR_WS_HTTPS_CATALOG . 'index.php?main_page=back_in_stock&bis_id=' . $emails['bis_id']; $html_message['TOP_MESSAGE'] = BACK_IN_STOCK_MAIL_TOP . $html_message['PRODUCT_NAME'] . "\n" . "\n" . BACK_IN_STOCK_MAIL_AVAILABLE; if (BACK_IN_STOCK_DESC_IN_EMAIL == 1) { $html_message['PRODUCT_DESCRIPTION'] = zen_get_products_description($emails['product_id']); } else { $html_message['PRODUCT_DESCRIPTION'] = " "; } $html_message['PRODUCT_IMAGE'] = zen_get_products_image($emails['product_id'], LARGE_IMAGE_WIDTH, LARGE_IMAGE_HEIGHT); $html_message['PRODUCT_LINK'] = zen_href_link('product_info', 'products_id=' . $emails['product_id']); $html_message['BOTTOM_MESSAGE'] = BACK_IN_STOCK_MAIL_BOTTOM; $email_text = BACK_IN_STOCK_MAIL_GREETING . $customers_name . ',' . "\n" . "\n" . $html_message['TOP_MESSAGE'] . "\n" . "\n" . $html_message['PRODUCT_NAME'] . "\n" . $html_message['PRODUCT_DESCRIPTION'] . "\n" . $html_message['PRODUCT_LINK'] . "\n" . "\n" . $html_message['BOTTOM_MESSAGE'] . "\n" . "\n" . BACK_IN_STOCK_MAIL_CANCEL . "\n" . $html_message['SPAM_LINK'] . "\n"; $counted++; zen_mail($customers_name, $customers_email, $html_message['PRODUCT_NAME'] . BACK_IN_STOCK_MAIL_BACK . STORE_NAME, $email_text, STORE_NAME, EMAIL_FROM, $html_message, 'back_in_stock_notification'); if (BACK_IN_STOCK_SEND_ADMIN_EMAIL == 'true') { zen_mail('', BACK_IN_STOCK_ADMIN_EMAIL, $html_message['PRODUCT_NAME'] . BACK_IN_STOCK_MAIL_BACK . STORE_NAME, $email_text, STORE_NAME, EMAIL_FROM, $html_message, 'back_in_stock_notification'); } echo BACK_IN_STOCK_MAIL_SENT . $customers_email . "\n" . "<br/>"; $modify_subscription = array('bis_id' => $emails['bis_id'], 'sub_active' => $emails['active_til_purch'], 'last_sent' => "NOW()"); back_in_stock_subscription($modify_subscription, "modify"); } ?> <br/> Processed <?php echo $counted; ?> Notifications <?php if ($counted == (int) BACK_IN_STOCK_MAX_EMAILS_PER_BATCH) { echo BACK_IN_STOCK_MAIL_MANY; } } if ($preview) { ?> <br/>Preview:</br> <table> <tr> <th>Customers Name</th> <th>Customers Email</th> <th>Product</th> </tr> <?php foreach ($bis_emails as $emails) { if ($counted >= (int) BACK_IN_STOCK_MAX_EMAILS_PER_BATCH && BACK_IN_STOCK_MAX_EMAILS_PER_BATCH != '0') { break; } $counted++; ?> <tr> <td><?php echo stripslashes($emails['name']); ?> </td> <td><?php echo $emails['email']; ?> </td> <td><?php echo zen_get_products_name($emails['product_id']); ?> </td> </tr> <?php } ?> </table> <br/> You can Process <?php echo $counted; ?> Notifications by clicking: <?php echo '<a href="' . zen_href_link("cron/send_back_in_stock_notifications.php", zen_get_all_get_params(array('preview')), 'NONSSL', true, true, true) . '">' . 'HERE' . '</a>'; echo "\n" . '<br/>'; if ($counted == (int) BACK_IN_STOCK_MAX_EMAILS_PER_BATCH) { echo BACK_IN_STOCK_MAIL_MANY; } } }
<?php /* * * @package ajax_back_in_stock * @copyright Copyright 2003-2015 ZenCart.Codes a Pro-Webs Company * @copyright Copyright 2003-2015 Zen Cart Development Team * @copyright Portions Copyright 2003 osCommerce * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0 * @filename clean_back_instock.php * @file created 2015-07-30 11:53:19 PM * */ require '../includes/configure.php'; ini_set('include_path', DIR_FS_CATALOG . PATH_SEPARATOR . ini_get('include_path')); chdir(DIR_FS_CATALOG); require_once 'includes/application_top.php'; cleanse_back_in_stock_subscriptions();