|
ZenCart_Documentation
1.5.0
http://www.collinsharper.com
|
00001 <?php 00009 if (!defined('IS_ADMIN_FLAG')) { 00010 die('Illegal Access'); 00011 } 00012 class newsletter { 00013 var $show_choose_audience, $title, $content, $content_html, $queryname; 00014 00015 function newsletter($title, $content, $content_html, $queryname='') { 00016 $this->show_choose_audience = true; 00017 // $this->show_choose_audience = (count(get_audiences_list('newsletters')) > 1 ); //if only 1 list of newsletters, don't offer selection 00018 $this->title = $title; 00019 $this->content = $content; 00020 $this->content_html = $content_html; 00021 $this->query_name = $queryname; 00022 } 00023 00024 function choose_audience() { 00025 global $_GET; 00026 00027 $choose_audience_string = '<form name="audience" action="' . zen_href_link(FILENAME_NEWSLETTERS, 'page=' . $_GET['page'] . '&nID=' . $_GET['nID'] . '&action=confirm') .'" method="post" onsubmit="return check_form(audience);">' . 00028 '<input type="hidden" name="securityToken" value="' . $_SESSION['securityToken'] . '" />' . 00029 ' <table border="0" cellspacing="0" cellpadding="2">' . "\n" . 00030 ' <tr>' . "\n" . 00031 '<td class="main">' . TEXT_PLEASE_SELECT_AUDIENCE .'<br />' . 00032 '' . zen_draw_pull_down_menu('audience_selected', get_audiences_list('newsletters'), $this->query_name) . '</td>' . 00033 ' </tr>' . "\n" . 00034 ' <tr>' . "\n" . 00035 ' <td colspan="2" align="right">' . zen_image_submit('button_select.gif', IMAGE_SELECT) . '</td>' . 00036 ' </tr>' . "\n" . 00037 '</table></form>'; 00038 00039 return $choose_audience_string; 00040 } 00041 00042 00043 function confirm() { 00044 global $_GET, $_POST, $db; 00045 00046 if ($_POST['audience_selected']) { 00047 $this->query_name=$_POST['audience_selected']; 00048 if (is_array($_POST['audience_selected'])) $this->query_name=$_POST['audience_selected']['text']; 00049 } 00050 00051 $query_array = get_audience_sql_query($this->query_name, 'newsletters'); 00052 $mail = $db->Execute($query_array['query_string'] ); 00053 $confirm_string = '<table border="0" cellspacing="0" cellpadding="2">' . "\n" . 00054 ' <tr>' . "\n" . 00055 ' <td class="main"><font color="#ff0000"><b>' . sprintf(TEXT_COUNT_CUSTOMERS, $mail->RecordCount() ) . '</b></font></td>' . "\n" . 00056 ' </tr>' . "\n" . 00057 ' <tr>' . "\n" . 00058 ' <td>' . zen_draw_separator('pixel_trans.gif', '1', '10') . '</td>' . "\n" . 00059 ' </tr>' . "\n" . 00060 ' <tr>' . "\n" . 00061 ' <td class="main"><b>' . $this->title . '</b></td>' . "\n" . 00062 ' </tr>' . "\n" . 00063 ' <tr>' . "\n" . 00064 ' <td>' . zen_draw_separator('pixel_trans.gif', '1', '10') . '<hr /></td>' . "\n" . 00065 ' </tr>' . "\n" . 00066 ' <tr>' . "\n" . 00067 ' <td>' . nl2br($this->content_html) . '</td>' . "\n" . 00068 ' </tr>' . "\n" . 00069 ' <tr>' . "\n" . 00070 ' <td><hr>' . zen_draw_separator('pixel_trans.gif', '1', '10') . '</td>' . "\n" . 00071 ' </tr>' . "\n" . 00072 ' <tr>' . "\n" . 00073 ' <td class="main"><tt>' . nl2br($this->content) . '</tt><hr /></td>' . "\n" . 00074 ' </tr>' . "\n" . 00075 ' <tr>' . "\n" . 00076 ' <td>' . zen_draw_separator('pixel_trans.gif', '1', '10') . '</td>' . "\n" . 00077 ' </tr>' . "\n" . 00078 ' <tr>' . "\n" . 00079 '<form name="ready_to_send" action="' . zen_href_link(FILENAME_NEWSLETTERS, 'page=' . $_GET['page'] . '&nID=' . $_GET['nID'] . '&action=confirm_send') .'" method="post" >' . 00080 '<input type="hidden" name="securityToken" value="' . $_SESSION['securityToken'] . '" />' . 00081 ' <td align="right"> ' . zen_draw_hidden_field('audience_selected',$this->query_name). 00082 zen_image_submit('button_send_mail.gif', IMAGE_SEND_EMAIL) . 00083 '<a href="' . zen_href_link(FILENAME_NEWSLETTERS, 'page=' . $_GET['page'] . '&nID=' . $_GET['nID']) . '">' . zen_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a></td>' . "\n" . 00084 '</form>' . 00085 ' </tr>' . "\n" . 00086 '</table>'; 00087 00088 return $confirm_string; 00089 } 00090 00091 function send($newsletter_id) { 00092 global $db; 00093 $audience_select = get_audience_sql_query($this->query_name, 'newsletters'); 00094 $audience = $db->Execute($audience_select['query_string']); 00095 $records = $audience->RecordCount(); 00096 if ($records==0) return 0; 00097 $i=0; 00098 00099 while (!$audience->EOF) { 00100 $i++; 00101 $html_msg['EMAIL_FIRST_NAME'] = $audience->fields['customers_firstname']; 00102 $html_msg['EMAIL_LAST_NAME'] = $audience->fields['customers_lastname']; 00103 $html_msg['EMAIL_MESSAGE_HTML'] = $this->content_html; 00104 zen_mail($audience->fields['customers_firstname'] . ' ' . $audience->fields['customers_lastname'], $audience->fields['customers_email_address'], $this->title, $this->content, STORE_NAME, EMAIL_FROM, $html_msg, 'newsletters'); 00105 echo zen_image(DIR_WS_ICONS . 'tick.gif', $audience->fields['customers_email_address']); 00106 00107 //force output to the screen to show status indicator each time a message is sent... 00108 if (function_exists('ob_flush')) @ob_flush(); 00109 @flush(); 00110 00111 $audience->MoveNext(); 00112 } 00113 00114 $newsletter_id = zen_db_prepare_input($newsletter_id); 00115 $db->Execute("update " . TABLE_NEWSLETTERS . " 00116 set date_sent = now(), status = '1' 00117 where newsletters_id = '" . zen_db_input($newsletter_id) . "'"); 00118 return $records; //return number of records processed whether successful or not 00119 } 00120 } 00121 ?>