|
ZenCart_Documentation
1.5.0
http://www.collinsharper.com
|
00001 <?php 00009 if (!defined('IS_ADMIN_FLAG')) { 00010 die('Illegal Access'); 00011 } 00012 class product_notification { 00013 var $show_choose_audience, $title, $content, $content_html; 00014 00015 function product_notification($title, $content, $content_html, $queryname='') { 00016 $this->show_choose_audience = true; 00017 $this->title = $title; 00018 $this->content = $content; 00019 $this->content_html = $content_html; 00020 } 00021 00022 function choose_audience() { 00023 global $_GET, $db; 00024 00025 $products_array = array(); 00026 $products = $db->Execute("select pd.products_id, pd.products_name 00027 from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd 00028 where pd.language_id = '" . (int)$_SESSION['languages_id'] . "' 00029 and pd.products_id = p.products_id 00030 and p.products_status = '1' 00031 order by pd.products_name"); 00032 00033 while (!$products->EOF) { 00034 $products_array[] = array('id' => $products->fields['products_id'], 00035 'text' => $products->fields['products_name']); 00036 $products->MoveNext(); 00037 } 00038 00039 $choose_audience_string = '<script language="javascript"><!-- 00040 function mover(move) { 00041 if (move == \'remove\') { 00042 for (x=0; x<(document.notifications.products.length); x++) { 00043 if (document.notifications.products.options[x].selected) { 00044 with(document.notifications.elements[\'chosen[]\']) { 00045 options[options.length] = new Option(document.notifications.products.options[x].text,document.notifications.products.options[x].value); 00046 } 00047 document.notifications.products.options[x] = null; 00048 x = -1; 00049 } 00050 } 00051 } 00052 if (move == \'add\') { 00053 for (x=0; x<(document.notifications.elements[\'chosen[]\'].length); x++) { 00054 if (document.notifications.elements[\'chosen[]\'].options[x].selected) { 00055 with(document.notifications.products) { 00056 options[options.length] = new Option(document.notifications.elements[\'chosen[]\'].options[x].text,document.notifications.elements[\'chosen[]\'].options[x].value); 00057 } 00058 document.notifications.elements[\'chosen[]\'].options[x] = null; 00059 x = -1; 00060 } 00061 } 00062 } 00063 return true; 00064 } 00065 00066 function selectAll(FormName, SelectBox) { 00067 temp = "document." + FormName + ".elements[\'" + SelectBox + "\']"; 00068 Source = eval(temp); 00069 00070 for (x=0; x<(Source.length); x++) { 00071 Source.options[x].selected = "true"; 00072 } 00073 00074 if (x<1) { 00075 alert(\'' . JS_PLEASE_SELECT_PRODUCTS . '\'); 00076 return false; 00077 } else { 00078 return true; 00079 } 00080 } 00081 //--></script>'; 00082 00083 $global_button = '<script language="javascript"><!--' . "\n" . 00084 'document.write(\'<input type="button" value="' . BUTTON_GLOBAL . '" style="width: 8em;" onclick="document.location=\\\'' . zen_href_link(FILENAME_NEWSLETTERS, 'page=' . $_GET['page'] . '&nID=' . $_GET['nID'] . '&action=confirm&global=true') . '\\\'">\');' . "\n" . 00085 '//--></script><noscript><a href="' . zen_href_link(FILENAME_NEWSLETTERS, 'page=' . $_GET['page'] . '&nID=' . $_GET['nID'] . '&action=confirm&global=true') . '">[ ' . BUTTON_GLOBAL . ' ]</a></noscript>'; 00086 00087 $cancel_button = '<script language="javascript"><!--' . "\n" . 00088 'document.write(\'<input type="button" value="' . BUTTON_CANCEL . '" style="width: 8em;" onclick="document.location=\\\'' . zen_href_link(FILENAME_NEWSLETTERS, 'page=' . $_GET['page'] . '&nID=' . $_GET['nID']) . '\\\'">\');' . "\n" . 00089 '//--></script><noscript><a href="' . zen_href_link(FILENAME_NEWSLETTERS, 'page=' . $_GET['page'] . '&nID=' . $_GET['nID']) . '">[ ' . BUTTON_CANCEL . ' ]</a></noscript>'; 00090 00091 $choose_audience_string .= '<form name="notifications" action="' . zen_href_link(FILENAME_NEWSLETTERS, 'page=' . $_GET['page'] . '&nID=' . $_GET['nID'] . '&action=confirm') . '" method="post" onSubmit="return selectAll(\'notifications\', \'chosen[]\')"><table border="0" width="100%" cellspacing="0" cellpadding="2">' . "\n" . '<input type="hidden" name="securityToken" value="' . $_SESSION['securityToken'] . '" />' . 00092 ' <tr>' . "\n" . 00093 ' <td align="center" class="main"><b>' . TEXT_PRODUCTS . '</b><br />' . zen_draw_pull_down_menu('products', $products_array, '', 'size="20" style="width: 20em;" multiple') . '</td>' . "\n" . 00094 ' <td align="center" class="main"> <br />' . $global_button . '<br /><br /><br /><input type="button" value="' . BUTTON_SELECT . '" style="width: 8em;" onClick="mover(\'remove\');"><br /><br /><input type="button" value="' . BUTTON_UNSELECT . '" style="width: 8em;" onClick="mover(\'add\');"><br /><br /><br /><input type="submit" value="' . BUTTON_SUBMIT . '" style="width: 8em;"><br /><br />' . $cancel_button . '</td>' . "\n" . 00095 ' <td align="center" class="main"><b>' . TEXT_SELECTED_PRODUCTS . '</b><br />' . zen_draw_pull_down_menu('chosen[]', array(), '', 'size="20" style="width: 20em;" multiple') . '</td>' . "\n" . 00096 ' </tr>' . "\n" . 00097 '</table></form>'; 00098 00099 return $choose_audience_string; 00100 } 00101 00102 function confirm() { 00103 global $_GET, $_POST, $db; 00104 00105 $audience = array(); 00106 00107 if (isset($_GET['global']) && ($_GET['global'] == 'true')) { 00108 $products = $db->Execute("select distinct customers_id 00109 from " . TABLE_PRODUCTS_NOTIFICATIONS); 00110 00111 while (!$products->EOF) { 00112 $audience[$products->fields['customers_id']] = '1'; 00113 $products->MoveNext(); 00114 } 00115 00116 $customers = $db->Execute("select customers_info_id 00117 from " . TABLE_CUSTOMERS_INFO . " 00118 where global_product_notifications = '1'"); 00119 00120 while (!$customers->EOF) { 00121 $audience[$customers->fields['customers_info_id']] = '1'; 00122 $customers->MoveNext(); 00123 } 00124 } else { 00125 $chosen = $_POST['chosen']; 00126 00127 $ids = zen_db_input(implode(',', $chosen)); 00128 00129 $products = $db->Execute("select distinct customers_id 00130 from " . TABLE_PRODUCTS_NOTIFICATIONS . " 00131 where products_id in (" . $ids . ")"); 00132 00133 while (!$products->EOF) { 00134 $audience[$products->fields['customers_id']] = '1'; 00135 $products->MoveNext(); 00136 } 00137 00138 $customers = $db->Execute("select customers_info_id 00139 from " . TABLE_CUSTOMERS_INFO . " 00140 where global_product_notifications = '1'"); 00141 00142 while (!$customers->EOF) { 00143 $audience[$customers->fields['customers_info_id']] = '1'; 00144 $customers->MoveNext(); 00145 } 00146 } 00147 00148 $confirm_string = '<table border="0" cellspacing="0" cellpadding="2">' . "\n" . 00149 ' <tr>' . "\n" . 00150 ' <td class="main"><font color="#ff0000"><b>' . sprintf(TEXT_COUNT_CUSTOMERS, sizeof($audience)) . '</b></font></td>' . "\n" . 00151 ' </tr>' . "\n" . 00152 ' <tr>' . "\n" . 00153 ' <td>' . zen_draw_separator('pixel_trans.gif', '1', '10') . '</td>' . "\n" . 00154 ' </tr>' . "\n" . 00155 ' <tr>' . "\n" . 00156 ' <td class="main"><b>' . $this->title . '</b></td>' . "\n" . 00157 ' </tr>' . "\n" . 00158 ' <tr>' . "\n" . 00159 ' <td>' . zen_draw_separator('pixel_trans.gif', '1', '10') . '<hr /></td>' . "\n" . 00160 ' </tr>' . "\n" . 00161 ' <tr>' . "\n" . 00162 ' <td class="main">' . nl2br($this->content_html) . '</td>' . "\n" . 00163 ' </tr>' . "\n" . 00164 ' <tr>' . "\n" . 00165 ' <td><hr>' . zen_draw_separator('pixel_trans.gif', '1', '10') . '</td>' . "\n" . 00166 ' </tr>' . "\n" . 00167 ' <tr>' . "\n" . 00168 ' <td class="main"><tt>' . nl2br($this->content) . '</tt><hr /></td>' . "\n" . 00169 ' </tr>' . "\n" . 00170 ' <tr>' . "\n" . 00171 ' <td>' . zen_draw_separator('pixel_trans.gif', '1', '10') . '</td>' . "\n" . 00172 ' </tr>' . "\n" . 00173 ' <tr>' . zen_draw_form('confirm', FILENAME_NEWSLETTERS, 'page=' . $_GET['page'] . '&nID=' . $_GET['nID'] . '&action=confirm_send') . "\n" . 00174 ' <td align="right">'; 00175 if (sizeof($audience) > 0) { 00176 if (isset($_GET['global']) && ($_GET['global'] == 'true')) { 00177 $confirm_string .= zen_draw_hidden_field('global', 'true'); 00178 } else { 00179 for ($i = 0, $n = sizeof($chosen); $i < $n; $i++) { 00180 $confirm_string .= zen_draw_hidden_field('chosen[]', $chosen[$i]); 00181 } 00182 } 00183 $confirm_string .= zen_image_submit('button_send.gif', IMAGE_SEND) . ' '; 00184 } 00185 $confirm_string .= '<a href="' . zen_href_link(FILENAME_NEWSLETTERS, 'page=' . $_GET['page'] . '&nID=' . $_GET['nID'] . '&action=send') . '">' . zen_image_button('button_back.gif', IMAGE_BACK) . '</a> <a href="' . zen_href_link(FILENAME_NEWSLETTERS, 'page=' . $_GET['page'] . '&nID=' . $_GET['nID']) . '">' . zen_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a></td>' . "\n" . 00186 ' </tr>' . "\n" . 00187 '</table>'; 00188 00189 return $confirm_string; 00190 } 00191 00192 function send($newsletter_id) { 00193 global $_POST, $db; 00194 00195 $audience = array(); 00196 00197 if (isset($_POST['global']) && ($_POST['global'] == 'true')) { 00198 $products = $db->Execute("select distinct pn.customers_id, c.customers_firstname, 00199 c.customers_lastname, c.customers_email_address 00200 from " . TABLE_CUSTOMERS . " c, " . TABLE_PRODUCTS_NOTIFICATIONS . " pn 00201 where c.customers_id = pn.customers_id"); 00202 00203 while (!$products->EOF) { 00204 $audience[$products->fields['customers_id']] = array('firstname' => $products->fields['customers_firstname'], 00205 'lastname' => $products->fields['customers_lastname'], 00206 'email_address' => $products->fields['customers_email_address']); 00207 $products->MoveNext(); 00208 } 00209 00210 $customers = $db->Execute("select c.customers_id, c.customers_firstname, c.customers_lastname, 00211 c.customers_email_address 00212 from " . TABLE_CUSTOMERS . " c, " . TABLE_CUSTOMERS_INFO . " ci 00213 where c.customers_id = ci.customers_info_id 00214 and ci.global_product_notifications = '1'"); 00215 00216 while (!$customers->EOF) { 00217 $audience[$customers->fields['customers_id']] = array('firstname' => $customers->fields['customers_firstname'], 00218 'lastname' => $customers->fields['customers_lastname'], 00219 'email_address' => $customers->fields['customers_email_address']); 00220 $customers->MoveNext(); 00221 } 00222 } else { //not global==true; instead, process all selected products 00223 $chosen = $_POST['chosen']; 00224 00225 $ids = zen_db_input(implode(',', $chosen)); 00226 00227 $products = $db->Execute("select distinct pn.customers_id, c.customers_firstname, 00228 c.customers_lastname, c.customers_email_address 00229 from " . TABLE_CUSTOMERS . " c, " . TABLE_PRODUCTS_NOTIFICATIONS . " pn 00230 where c.customers_id = pn.customers_id 00231 and pn.products_id in (" . $ids . ")"); 00232 00233 while (!$products->EOF) { 00234 $audience[$products->fields['customers_id']] = array('firstname' => $products->fields['customers_firstname'], 00235 'lastname' => $products->fields['customers_lastname'], 00236 'email_address' => $products->fields['customers_email_address']); 00237 $products->MoveNext(); 00238 } 00239 00240 $customers = $db->Execute("select c.customers_id, c.customers_firstname, c.customers_lastname, 00241 c.customers_email_address 00242 from " . TABLE_CUSTOMERS . " c, " . TABLE_CUSTOMERS_INFO . " ci 00243 where c.customers_id = ci.customers_info_id 00244 and ci.global_product_notifications = '1'"); 00245 00246 while (!$customers->EOF) { 00247 $audience[$customers->fields['customers_id']] = array('firstname' => $customers->fields['customers_firstname'], 00248 'lastname' => $customers->fields['customers_lastname'], 00249 'email_address' => $customers->fields['customers_email_address']); 00250 $customers->MoveNext(); 00251 } 00252 } 00253 00254 00255 //send emails 00256 reset($audience); 00257 $i=0; 00258 while (list($key, $value) = each ($audience)) { 00259 $i++; 00260 $html_msg['EMAIL_FIRST_NAME'] = $value['firstname']; 00261 $html_msg['EMAIL_LAST_NAME'] = $value['lastname']; 00262 $html_msg['EMAIL_MESSAGE_HTML'] = $this->content_html; 00263 zen_mail($value['firstname'] . ' ' . $value['lastname'], $value['email_address'], $this->title, $this->content, STORE_NAME, EMAIL_FROM, $html_msg, 'product_notification',''); 00264 echo zen_image(DIR_WS_ICONS . 'tick.gif', $value['email_address']); 00265 00266 //force output to the screen to show status indicator each time a message is sent... 00267 if (function_exists('ob_flush')) @ob_flush(); 00268 @flush(); 00269 } 00270 00271 $newsletter_id = zen_db_prepare_input($newsletter_id); 00272 $db->Execute("update " . TABLE_NEWSLETTERS . " 00273 set date_sent = now(), status = '1' 00274 where newsletters_id = '" . zen_db_input($newsletter_id) . "'"); 00275 return $i; //return number of records processed whether successful or not 00276 } 00277 }