show_choose_audience = true; $this->title = $title; $this->content = $content; $this->content_html = $content_html; } function choose_audience() { global $_GET, $db; $products_array = array(); $products = $db->Execute("select pd.products_id, pd.products_name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where pd.language_id = '" . (int)$_SESSION['languages_id'] . "' and pd.products_id = p.products_id and p.products_status = '1' order by pd.products_name"); while (!$products->EOF) { $products_array[] = array('id' => $products->fields['products_id'], 'text' => $products->fields['products_name']); $products->MoveNext(); } $choose_audience_string = ''; $global_button = ''; $cancel_button = ''; $choose_audience_string .= '
' . "\n" . '' . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . '
' . TEXT_PRODUCTS . '
' . zen_draw_pull_down_menu('products', $products_array, '', 'size="20" style="width: 20em;" multiple') . '
 
' . $global_button . '









' . $cancel_button . '
' . TEXT_SELECTED_PRODUCTS . '
' . zen_draw_pull_down_menu('chosen[]', array(), '', 'size="20" style="width: 20em;" multiple') . '
'; return $choose_audience_string; } function confirm() { global $_GET, $_POST, $db; $audience = array(); if (isset($_GET['global']) && ($_GET['global'] == 'true')) { $products = $db->Execute("select distinct customers_id from " . TABLE_PRODUCTS_NOTIFICATIONS); while (!$products->EOF) { $audience[$products->fields['customers_id']] = '1'; $products->MoveNext(); } $customers = $db->Execute("select customers_info_id from " . TABLE_CUSTOMERS_INFO . " where global_product_notifications = '1'"); while (!$customers->EOF) { $audience[$customers->fields['customers_info_id']] = '1'; $customers->MoveNext(); } } else { $chosen = $_POST['chosen']; $ids = zen_db_input(implode(',', $chosen)); $products = $db->Execute("select distinct customers_id from " . TABLE_PRODUCTS_NOTIFICATIONS . " where products_id in (" . $ids . ")"); while (!$products->EOF) { $audience[$products->fields['customers_id']] = '1'; $products->MoveNext(); } $customers = $db->Execute("select customers_info_id from " . TABLE_CUSTOMERS_INFO . " where global_product_notifications = '1'"); while (!$customers->EOF) { $audience[$customers->fields['customers_info_id']] = '1'; $customers->MoveNext(); } } $confirm_string = '' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . zen_draw_form('confirm', FILENAME_NEWSLETTERS, 'page=' . $_GET['page'] . '&nID=' . $_GET['nID'] . '&action=confirm_send') . "\n" . ' ' . "\n" . ' ' . "\n" . '
' . sprintf(TEXT_COUNT_CUSTOMERS, sizeof($audience)) . '
' . zen_draw_separator('pixel_trans.gif', '1', '10') . '
' . $this->title . '
' . zen_draw_separator('pixel_trans.gif', '1', '10') . '
' . nl2br($this->content_html) . '

' . zen_draw_separator('pixel_trans.gif', '1', '10') . '
' . nl2br($this->content) . '
' . zen_draw_separator('pixel_trans.gif', '1', '10') . '
'; if (sizeof($audience) > 0) { if (isset($_GET['global']) && ($_GET['global'] == 'true')) { $confirm_string .= zen_draw_hidden_field('global', 'true'); } else { for ($i = 0, $n = sizeof($chosen); $i < $n; $i++) { $confirm_string .= zen_draw_hidden_field('chosen[]', $chosen[$i]); } } $confirm_string .= zen_image_submit('button_send.gif', IMAGE_SEND) . ' '; } $confirm_string .= '' . zen_image_button('button_back.gif', IMAGE_BACK) . ' ' . zen_image_button('button_cancel.gif', IMAGE_CANCEL) . '
'; return $confirm_string; } function send($newsletter_id) { global $_POST, $db; $audience = array(); if (isset($_POST['global']) && ($_POST['global'] == 'true')) { $products = $db->Execute("select distinct pn.customers_id, c.customers_firstname, c.customers_lastname, c.customers_email_address from " . TABLE_CUSTOMERS . " c, " . TABLE_PRODUCTS_NOTIFICATIONS . " pn where c.customers_id = pn.customers_id"); while (!$products->EOF) { $audience[$products->fields['customers_id']] = array('firstname' => $products->fields['customers_firstname'], 'lastname' => $products->fields['customers_lastname'], 'email_address' => $products->fields['customers_email_address']); $products->MoveNext(); } $customers = $db->Execute("select c.customers_id, c.customers_firstname, c.customers_lastname, c.customers_email_address from " . TABLE_CUSTOMERS . " c, " . TABLE_CUSTOMERS_INFO . " ci where c.customers_id = ci.customers_info_id and ci.global_product_notifications = '1'"); while (!$customers->EOF) { $audience[$customers->fields['customers_id']] = array('firstname' => $customers->fields['customers_firstname'], 'lastname' => $customers->fields['customers_lastname'], 'email_address' => $customers->fields['customers_email_address']); $customers->MoveNext(); } } else { //not global==true; instead, process all selected products $chosen = $_POST['chosen']; $ids = zen_db_input(implode(',', $chosen)); $products = $db->Execute("select distinct pn.customers_id, c.customers_firstname, c.customers_lastname, c.customers_email_address from " . TABLE_CUSTOMERS . " c, " . TABLE_PRODUCTS_NOTIFICATIONS . " pn where c.customers_id = pn.customers_id and pn.products_id in (" . $ids . ")"); while (!$products->EOF) { $audience[$products->fields['customers_id']] = array('firstname' => $products->fields['customers_firstname'], 'lastname' => $products->fields['customers_lastname'], 'email_address' => $products->fields['customers_email_address']); $products->MoveNext(); } $customers = $db->Execute("select c.customers_id, c.customers_firstname, c.customers_lastname, c.customers_email_address from " . TABLE_CUSTOMERS . " c, " . TABLE_CUSTOMERS_INFO . " ci where c.customers_id = ci.customers_info_id and ci.global_product_notifications = '1'"); while (!$customers->EOF) { $audience[$customers->fields['customers_id']] = array('firstname' => $customers->fields['customers_firstname'], 'lastname' => $customers->fields['customers_lastname'], 'email_address' => $customers->fields['customers_email_address']); $customers->MoveNext(); } } //send emails reset($audience); $i=0; while (list($key, $value) = each ($audience)) { $i++; $html_msg['EMAIL_FIRST_NAME'] = $value['firstname']; $html_msg['EMAIL_LAST_NAME'] = $value['lastname']; $html_msg['EMAIL_MESSAGE_HTML'] = $this->content_html; zen_mail($value['firstname'] . ' ' . $value['lastname'], $value['email_address'], $this->title, $this->content, STORE_NAME, EMAIL_FROM, $html_msg, 'product_notification',''); echo zen_image(DIR_WS_ICONS . 'tick.gif', $value['email_address']); //force output to the screen to show status indicator each time a message is sent... if (function_exists('ob_flush')) @ob_flush(); @flush(); } $newsletter_id = zen_db_prepare_input($newsletter_id); $db->Execute("update " . TABLE_NEWSLETTERS . " set date_sent = now(), status = '1' where newsletters_id = '" . zen_db_input($newsletter_id) . "'"); return $i; //return number of records processed whether successful or not } }