function update(&$class, $eventID, $paramsArray)
 {
     global $db;
     // check if account is subscribed
     $customers = $db->Execute("SELECT customers_email_address FROM " . TABLE_CUSTOMERS . " WHERE customers_id = " . (int) $_SESSION['customer_id'] . " LIMIT 1;");
     $subscriptions = $db->Execute("SELECT * FROM " . TABLE_BACK_IN_STOCK . " WHERE email='" . $customers->fields['customers_email_address'] . "'");
     if ($subscriptions->RecordCount() > 0) {
         $products_subscribed = array();
         //Create array of subscribed products
         while ($subscriptions->EOF) {
             $products_subscribed[] = $subscriptions->fields['product_id'];
             $subscriptions->MoveNext();
         }
         //get products in cart
         $products = $_SESSION['cart']->get_products();
         for ($i = 0, $n = sizeof($products); $i < $n; $i++) {
             if (in_array($products[$i]['id'], $products_subscribed)) {
                 $bis_prod_subscription = $db->Execute("SELECT * FROM " . TABLE_BACK_IN_STOCK . " WHERE email='" . $customers->fields['customers_email_address'] . "' AND product_id=" . (int) $products[$i]['id']);
                 $bis_id = $bis_prod_subscription->fields['nis_id'];
                 back_in_stock_subscription(array('sub_active' => 0, 'bis_id => ' . (int) $bis_id . ', purch_date => NOW()'), 'modify');
             }
         }
     }
 }
Пример #2
0
 * @copyright Copyright 2003-2014 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 */
$subcriptions = false;
$action = zen_db_prepare_input($_POST['action']);
if (is_array($_POST['bis_id'])) {
    switch ($action) {
        case "stop":
            foreach (zen_db_prepare_input($_POST['bis_id']) as $sub_id) {
                $modify_subscription = array('bis_id' => $sub_id, 'sub_active' => 0, 'spam' => 1);
                back_in_stock_subscription($modify_subscription, "modify");
            }
            break;
        case "delete":
            back_in_stock_subscription(array('bis_id' => $bis_id), "delete");
            break;
    }
    $bis_id_info = $db->Execute("SELECT * FROM " . TABLE_BACK_IN_STOCK . " WHERE bis_id='" . zen_db_prepare_input($_POST['bis_id'][0]) . "' AND sub_active=1");
    if ($bis_id_info->RecordCount() > 0) {
        $subcriptions = true;
        $email_info = $db->Execute("SELECT * FROM " . TABLE_BACK_IN_STOCK . " WHERE email LIKE '" . $bis_id_info->fields['email'] . "' AND sub_active=1");
    } else {
        $subcriptions = false;
    }
} else {
    if ((int) $_GET['bis_id'] > 0) {
        $bis_id_info = $db->Execute("SELECT * FROM " . TABLE_BACK_IN_STOCK . " WHERE bis_id='" . (int) $_GET['bis_id'] . "' AND sub_active=1");
        if ($bis_id_info->RecordCount() > 0) {
            $subcriptions = true;
            $email_info = $db->Execute("SELECT * FROM " . TABLE_BACK_IN_STOCK . " WHERE email LIKE '" . $bis_id_info->fields['email'] . "' AND sub_active=1");
//let's add this in case someone someday wants to add an observer.
$zco_notifier->notify('NOTIFY_HEADER_START_SUBSCRIBE_BACK_IN_STOCK');
$language_page_directory = DIR_WS_LANGUAGES . $_SESSION['language'] . '/';
require DIR_WS_MODULES . zen_get_module_directory('require_languages.php');
$error = false;
$name = zen_db_prepare_input($_POST['customer_name']);
$email_address = zen_db_prepare_input($_POST['email']);
$empty = isset($_POST['should_be_empty']) ? zen_db_prepare_input($_POST['should_be_empty']) : '';
$product_id = zen_db_prepare_input($_POST['product_id']);
//Validate the email address
$zc_validate_email = zen_validate_email($email_address);
if ($zc_validate_email && $empty == '' && $product_id != '') {
    $bis['email'] = $email_address;
    $bis['name'] = $name;
    $bis['product_id'] = $product_id;
    $returned_results = back_in_stock_subscription($bis, "add");
    if ($returned_results === "Subscribed") {
        echo '<p class="messageStackSuccess">' . BACK_IN_STOCK_SUCCESS . '</p>';
    } else {
        echo '<p class="messageStackError">' . $returned_results . '</p>';
    }
} else {
    $error = true;
    if (empty($name)) {
        echo '<p class="messageStackError">' . BACK_IN_STOCK_NAME_ERROR . '</p>';
    }
    if ($zc_validate_email == false) {
        echo '<p class="messageStackError">' . BACK_IN_STOCK_EMAIL_ADDRESS_ERROR . '</p>';
    }
    if ($product_id == '') {
        echo '<p class="messageStackError">' . BACK_IN_STOCK_NO_PRODUCT_ERROR . '</p>';
Пример #4
0
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;
        }
    }
}