show_choose_audience = true; $this->title = $title; $this->content = $content; } function choose_audience() { global $HTTP_GET_VARS, $languages_id; $products_array = array(); $products_query = tep_db_query("select pd.products_id, pd.products_name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where pd.language_id = '" . $languages_id . "' and pd.products_id = p.products_id and p.products_status = '1' order by pd.products_name"); while ($products = tep_db_fetch_array($products_query)) { $products_array[] = array('id' => $products['products_id'], 'text' => $products['products_name']); } $choose_audience_string = ''; $global_button = ''; $cancel_button = ''; $choose_audience_string .= '
' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . '
' . TEXT_PRODUCTS . '
' . tep_draw_pull_down_menu('products', $products_array, '', 'size="20" style="width: 20em;" multiple') . '
 
' . $global_button . '









' . $cancel_button . '
' . TEXT_SELECTED_PRODUCTS . '
' . tep_draw_pull_down_menu('chosen[]', array(), '', 'size="20" style="width: 20em;" multiple') . '
'; return $choose_audience_string; } function confirm() { global $HTTP_GET_VARS, $HTTP_POST_VARS; $audience = array(); if (isset($HTTP_GET_VARS['global']) && ($HTTP_GET_VARS['global'] == 'true')) { $products_query = tep_db_query("select distinct customers_id from " . TABLE_PRODUCTS_NOTIFICATIONS); while ($products = tep_db_fetch_array($products_query)) { $audience[$products['customers_id']] = '1'; } $customers_query = tep_db_query("select customers_info_id from " . TABLE_CUSTOMERS_INFO . " where global_product_notifications = '1'"); while ($customers = tep_db_fetch_array($customers_query)) { $audience[$customers['customers_info_id']] = '1'; } } else { $chosen = $HTTP_POST_VARS['chosen']; $ids = implode(',', $chosen); $products_query = tep_db_query("select distinct customers_id from " . TABLE_PRODUCTS_NOTIFICATIONS . " where products_id in (" . $ids . ")"); while ($products = tep_db_fetch_array($products_query)) { $audience[$products['customers_id']] = '1'; } $customers_query = tep_db_query("select customers_info_id from " . TABLE_CUSTOMERS_INFO . " where global_product_notifications = '1'"); while ($customers = tep_db_fetch_array($customers_query)) { $audience[$customers['customers_info_id']] = '1'; } } $confirm_string = '' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . tep_draw_form('confirm', FILENAME_NEWSLETTERS, 'page=' . $HTTP_GET_VARS['page'] . '&nID=' . $HTTP_GET_VARS['nID'] . '&action=confirm_send') . "\n" . ' ' . "\n" . ' ' . "\n" . '
' . sprintf(TEXT_COUNT_CUSTOMERS, sizeof($audience)) . '
' . tep_draw_separator('pixel_trans.gif', '1', '10') . '
' . $this->title . '
' . tep_draw_separator('pixel_trans.gif', '1', '10') . '
' . nl2br($this->content) . '
' . tep_draw_separator('pixel_trans.gif', '1', '10') . '
'; if (sizeof($audience) > 0) { if (isset($HTTP_GET_VARS['global']) && ($HTTP_GET_VARS['global'] == 'true')) { $confirm_string .= tep_draw_hidden_field('global', 'true'); } else { for ($i = 0, $n = sizeof($chosen); $i < $n; $i++) { $confirm_string .= tep_draw_hidden_field('chosen[]', $chosen[$i]); } } $confirm_string .= tep_image_submit('button_send.gif', IMAGE_SEND) . ' '; } $confirm_string .= '' . tep_image_button('button_back.gif', IMAGE_BACK) . ' ' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '
'; return $confirm_string; } function send($newsletter_id) { global $HTTP_POST_VARS; $audience = array(); if (isset($HTTP_POST_VARS['global']) && ($HTTP_POST_VARS['global'] == 'true')) { $products_query = tep_db_query("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 = tep_db_fetch_array($products_query)) { $audience[$products['customers_id']] = array('firstname' => $products['customers_firstname'], 'lastname' => $products['customers_lastname'], 'email_address' => $products['customers_email_address']); } $customers_query = tep_db_query("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 = tep_db_fetch_array($customers_query)) { $audience[$customers['customers_id']] = array('firstname' => $customers['customers_firstname'], 'lastname' => $customers['customers_lastname'], 'email_address' => $customers['customers_email_address']); } } else { $chosen = $HTTP_POST_VARS['chosen']; $ids = implode(',', $chosen); $products_query = tep_db_query("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 = tep_db_fetch_array($products_query)) { $audience[$products['customers_id']] = array('firstname' => $products['customers_firstname'], 'lastname' => $products['customers_lastname'], 'email_address' => $products['customers_email_address']); } $customers_query = tep_db_query("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 = tep_db_fetch_array($customers_query)) { $audience[$customers['customers_id']] = array('firstname' => $customers['customers_firstname'], 'lastname' => $customers['customers_lastname'], 'email_address' => $customers['customers_email_address']); } } $mimemessage = new email(array('X-Mailer: osCommerce bulk mailer')); $mimemessage->add_text($this->content); $mimemessage->build_message(); reset($audience); while (list($key, $value) = each ($audience)) { $mimemessage->send($value['firstname'] . ' ' . $value['lastname'], $value['email_address'], '', EMAIL_FROM, $this->title); } $newsletter_id = tep_db_prepare_input($newsletter_id); tep_db_query("update " . TABLE_NEWSLETTERS . " set date_sent = now(), status = '1' where newsletters_id = '" . tep_db_input($newsletter_id) . "'"); } } ?>