show_choose_audience = false;
$this->title = $title;
$this->content = $content;
}
function choose_audience() {
return false;
}
function confirm() {
global $HTTP_GET_VARS;
$newslettersQuery = tep_db_query("select custom from " . TABLE_NEWSLETTERS . " where newsletters_id = '".(int)$HTTP_GET_VARS['nID']."'");
$newsletters = tep_db_fetch_array($newslettersQuery);
$mailToStr = "";
switch ($newsletters['custom'])
{
case '***':
$mail_query = tep_db_query("select customers_email_address from " . TABLE_CUSTOMERS);
while ($mail = tep_db_fetch_array($mail_query))
{
$mailToStr .= $mail['customers_email_address'] . " , ";
$customersArr[] = $mail['customers_email_address'];
}
$mail_query = tep_db_query("select email from " . TABLE_NEWSLETTER_N_CUSTOM);
while ($mail = tep_db_fetch_array($mail_query))
{
if (!in_array($mail['email'], $customersArr))
{
$mailToStr .= $mail['email'] . " , ";
$customersArr[] = $mail['email'];
}
}
$mailToStr = substr($mailToStr, 0, strlen($mailToStr)-4);
break;
case '**D':
$mail_query = tep_db_query("select customers_email_address from " . TABLE_CUSTOMERS . " where customers_newsletter = '1'");
while ($mail = tep_db_fetch_array($mail_query))
{
$customersArr[] = $mail['customers_email_address'];
$mailToStr .= $mail['customers_email_address'] . " , ";
}
$mail_query = tep_db_query("select email from " . TABLE_NEWSLETTER_N_CUSTOM);
while ($mail = tep_db_fetch_array($mail_query))
{
if (!in_array($mail['email'], $customersArr))
{
$mailToStr .= $mail['email'] . " , ";
$customersArr[] = $mail['email'];
}
}
$mailToStr = substr($mailToStr, 0, strlen($mailToStr)-4);
break;
default:
$mailToStr = $newsletters['custom'];
break;
}
$mail_query = tep_db_query("select count(*) as count from " . TABLE_CUSTOMERS . " where customers_newsletter = '1'");
$mail = tep_db_fetch_array($mail_query);
$confirm_string = '
' . "\n" .
' ' . "\n" .
' Customer: '.$mailToStr.' | ' . "\n" .
'
' . "\n" .
' ' . "\n" .
' | ' . tep_draw_separator('pixel_trans.gif', '1', '10') . ' | ' . "\n" .
'
' . "\n" .
' ' . "\n" .
' | ' . $this->title . ' | ' . "\n" .
'
' . "\n" .
' ' . "\n" .
' | ' . tep_draw_separator('pixel_trans.gif', '1', '10') . ' | ' . "\n" .
'
' . "\n" .
' ' . "\n" .
' | ' . nl2br($this->content) . ' | ' . "\n" .
'
' . "\n" .
' ' . "\n" .
' | ' . tep_draw_separator('pixel_trans.gif', '1', '10') . ' | ' . "\n" .
'
' . "\n" .
' ' . "\n" .
' | ' . tep_draw_button(IMAGE_SEND,'mail-closed', tep_href_link(FILENAME_NEWSLETTERS, 'page=' . $HTTP_GET_VARS['page'] . '&nID=' . $HTTP_GET_VARS['nID'] . '&action=confirm_send')).' ' . tep_draw_button(IMAGE_CANCEL,'close',tep_href_link(FILENAME_NEWSLETTERS, 'page=' . $HTTP_GET_VARS['page'] . '&nID=' . $HTTP_GET_VARS['nID'])) . ' | ' . "\n" .
'
' . "\n" .
'
';
return $confirm_string;
}
function send($newsletter_id) {
global $HTTP_GET_VARS;
$mail_query = tep_db_query("select customers_firstname, customers_lastname, customers_email_address from " . TABLE_CUSTOMERS . " where customers_newsletter = '1'");
$mimemessage = new email(array('X-Mailer: osCommerce bulk mailer'));
$mimemessage->add_text($this->content);
$mimemessage->build_message();
$newslettersQuery = tep_db_query("select custom from " . TABLE_NEWSLETTERS . " where newsletters_id = '".(int)$HTTP_GET_VARS['nID']."'");
$newsletters = tep_db_fetch_array($newslettersQuery);
$mailToStr = "";
$customersArr = "";
switch ($newsletters['custom'])
{
case '***':
$mailSQL = "select customers_firstname, customers_lastname, customers_email_address from " . TABLE_CUSTOMERS;
$mail_query = tep_db_query($mailSQL);
while ($mail = tep_db_fetch_array($mail_query))
{
$customersArr[] = $mail['customers_email_address'];
$mimemessage->send($mail['customers_firstname'] . ' ' . $mail['customers_lastname'], $mail['customers_email_address'], '', EMAIL_FROM, $this->title);
}
$mailSQL = "select email from " . TABLE_NEWSLETTER_N_CUSTOM;
$mail_query = tep_db_query($mailSQL);
while ($mail = tep_db_fetch_array($mail_query))
{
if (!in_array($mail['email'], $customersArr))
{
$customersArr[] = $mail['email'];
$mimemessage->send("", $mail['email'], '', EMAIL_FROM, $this->title);
}
}
break;
case '**D':
$mailSQL = "select customers_firstname, customers_lastname, customers_email_address from " . TABLE_CUSTOMERS . " where customers_newsletter = '1'";
$mail_query = tep_db_query($mailSQL);
while ($mail = tep_db_fetch_array($mail_query))
{
$customersArr[] = $mail['customers_email_address'];
$mimemessage->send($mail['customers_firstname'] . ' ' . $mail['customers_lastname'], $mail['customers_email_address'], '', EMAIL_FROM, $this->title);
}
$mailSQL = "select email from " . TABLE_NEWSLETTER_N_CUSTOM;
$mail_query = tep_db_query($mailSQL);
while ($mail = tep_db_fetch_array($mail_query))
{
if (!in_array($mail['email'], $customersArr))
{
$customersArr[] = $mail['email'];
$mimemessage->send("", $mail['email'], '', EMAIL_FROM, $this->title);
}
}
break;
default:
$mailSQL = "select customers_firstname, customers_lastname, customers_email_address from " . TABLE_CUSTOMERS . " where customers_email_address = '".$newsletters['custom']."'";
$mail_query = tep_db_query($mailSQL);
while ($mail = tep_db_fetch_array($mail_query))
{
$mimemessage->send($mail['customers_firstname'] . ' ' . $mail['customers_lastname'], $mail['customers_email_address'], '', EMAIL_FROM, $this->title);
}
break;
}
$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) . "'");
}
}
?>