[ Index ] |
|
Code source de Zen Cart E-Commerce Shopping Cart 1.3.7.1 |
1 <?php 2 /** 3 * @package admin 4 * @copyright Copyright 2003-2006 Zen Cart Development Team 5 * @copyright Portions Copyright 2003 osCommerce 6 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0 7 * @version $Id: product_notification.php 3009 2006-02-11 15:41:10Z wilt $ 8 */ 9 if (!defined('IS_ADMIN_FLAG')) { 10 die('Illegal Access'); 11 } 12 class product_notification { 13 var $show_choose_audience, $title, $content, $content_html; 14 15 function product_notification($title, $content, $content_html, $queryname='') { 16 $this->show_choose_audience = true; 17 $this->title = $title; 18 $this->content = $content; 19 $this->content_html = $content_html; 20 } 21 22 function choose_audience() { 23 global $_GET, $db; 24 25 $products_array = array(); 26 $products = $db->Execute("select pd.products_id, pd.products_name 27 from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd 28 where pd.language_id = '" . $_SESSION['languages_id'] . "' 29 and pd.products_id = p.products_id 30 and p.products_status = '1' 31 order by pd.products_name"); 32 33 while (!$products->EOF) { 34 $products_array[] = array('id' => $products->fields['products_id'], 35 'text' => $products->fields['products_name']); 36 $products->MoveNext(); 37 } 38 39 $choose_audience_string = '<script language="javascript"><!-- 40 function mover(move) { 41 if (move == \'remove\') { 42 for (x=0; x<(document.notifications.products.length); x++) { 43 if (document.notifications.products.options[x].selected) { 44 with(document.notifications.elements[\'chosen[]\']) { 45 options[options.length] = new Option(document.notifications.products.options[x].text,document.notifications.products.options[x].value); 46 } 47 document.notifications.products.options[x] = null; 48 x = -1; 49 } 50 } 51 } 52 if (move == \'add\') { 53 for (x=0; x<(document.notifications.elements[\'chosen[]\'].length); x++) { 54 if (document.notifications.elements[\'chosen[]\'].options[x].selected) { 55 with(document.notifications.products) { 56 options[options.length] = new Option(document.notifications.elements[\'chosen[]\'].options[x].text,document.notifications.elements[\'chosen[]\'].options[x].value); 57 } 58 document.notifications.elements[\'chosen[]\'].options[x] = null; 59 x = -1; 60 } 61 } 62 } 63 return true; 64 } 65 66 function selectAll(FormName, SelectBox) { 67 temp = "document." + FormName + ".elements[\'" + SelectBox + "\']"; 68 Source = eval(temp); 69 70 for (x=0; x<(Source.length); x++) { 71 Source.options[x].selected = "true"; 72 } 73 74 if (x<1) { 75 alert(\'' . JS_PLEASE_SELECT_PRODUCTS . '\'); 76 return false; 77 } else { 78 return true; 79 } 80 } 81 //--></script>'; 82 83 $global_button = '<script language="javascript"><!--' . "\n" . 84 '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" . 85 '//--></script><noscript><a href="' . zen_href_link(FILENAME_NEWSLETTERS, 'page=' . $_GET['page'] . '&nID=' . $_GET['nID'] . '&action=confirm&global=true') . '">[ ' . BUTTON_GLOBAL . ' ]</a></noscript>'; 86 87 $cancel_button = '<script language="javascript"><!--' . "\n" . 88 '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" . 89 '//--></script><noscript><a href="' . zen_href_link(FILENAME_NEWSLETTERS, 'page=' . $_GET['page'] . '&nID=' . $_GET['nID']) . '">[ ' . BUTTON_CANCEL . ' ]</a></noscript>'; 90 91 $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" . 92 ' <tr>' . "\n" . 93 ' <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" . 94 ' <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" . 95 ' <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" . 96 ' </tr>' . "\n" . 97 '</table></form>'; 98 99 return $choose_audience_string; 100 } 101 102 function confirm() { 103 global $_GET, $_POST, $db; 104 105 $audience = array(); 106 107 if (isset($_GET['global']) && ($_GET['global'] == 'true')) { 108 $products = $db->Execute("select distinct customers_id 109 from " . TABLE_PRODUCTS_NOTIFICATIONS); 110 111 while (!$products->EOF) { 112 $audience[$products->fields['customers_id']] = '1'; 113 $products->MoveNext(); 114 } 115 116 $customers = $db->Execute("select customers_info_id 117 from " . TABLE_CUSTOMERS_INFO . " 118 where global_product_notifications = '1'"); 119 120 while (!$customers->EOF) { 121 $audience[$customers->fields['customers_info_id']] = '1'; 122 $customers->MoveNext(); 123 } 124 } else { 125 $chosen = $_POST['chosen']; 126 127 $ids = implode(',', $chosen); 128 129 $products = $db->Execute("select distinct customers_id 130 from " . TABLE_PRODUCTS_NOTIFICATIONS . " 131 where products_id in (" . $ids . ")"); 132 133 while (!$products->EOF) { 134 $audience[$products->fields['customers_id']] = '1'; 135 $products->MoveNext(); 136 } 137 138 $customers = $db->Execute("select customers_info_id 139 from " . TABLE_CUSTOMERS_INFO . " 140 where global_product_notifications = '1'"); 141 142 while (!$customers->EOF) { 143 $audience[$customers->fields['customers_info_id']] = '1'; 144 $customers->MoveNext(); 145 } 146 } 147 148 $confirm_string = '<table border="0" cellspacing="0" cellpadding="2">' . "\n" . 149 ' <tr>' . "\n" . 150 ' <td class="main"><font color="#ff0000"><b>' . sprintf(TEXT_COUNT_CUSTOMERS, sizeof($audience)) . '</b></font></td>' . "\n" . 151 ' </tr>' . "\n" . 152 ' <tr>' . "\n" . 153 ' <td>' . zen_draw_separator('pixel_trans.gif', '1', '10') . '</td>' . "\n" . 154 ' </tr>' . "\n" . 155 ' <tr>' . "\n" . 156 ' <td class="main"><b>' . $this->title . '</b></td>' . "\n" . 157 ' </tr>' . "\n" . 158 ' <tr>' . "\n" . 159 ' <td>' . zen_draw_separator('pixel_trans.gif', '1', '10') . '<hr /></td>' . "\n" . 160 ' </tr>' . "\n" . 161 ' <tr>' . "\n" . 162 ' <td class="main">' . nl2br($this->content_html) . '</td>' . "\n" . 163 ' </tr>' . "\n" . 164 ' <tr>' . "\n" . 165 ' <td><hr>' . zen_draw_separator('pixel_trans.gif', '1', '10') . '</td>' . "\n" . 166 ' </tr>' . "\n" . 167 ' <tr>' . "\n" . 168 ' <td class="main"><tt>' . nl2br($this->content) . '</tt><hr /></td>' . "\n" . 169 ' </tr>' . "\n" . 170 ' <tr>' . "\n" . 171 ' <td>' . zen_draw_separator('pixel_trans.gif', '1', '10') . '</td>' . "\n" . 172 ' </tr>' . "\n" . 173 ' <tr>' . zen_draw_form('confirm', FILENAME_NEWSLETTERS, 'page=' . $_GET['page'] . '&nID=' . $_GET['nID'] . '&action=confirm_send') . "\n" . 174 ' <td align="right">'; 175 if (sizeof($audience) > 0) { 176 if (isset($_GET['global']) && ($_GET['global'] == 'true')) { 177 $confirm_string .= zen_draw_hidden_field('global', 'true'); 178 } else { 179 for ($i = 0, $n = sizeof($chosen); $i < $n; $i++) { 180 $confirm_string .= zen_draw_hidden_field('chosen[]', $chosen[$i]); 181 } 182 } 183 $confirm_string .= zen_image_submit('button_send.gif', IMAGE_SEND) . ' '; 184 } 185 $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" . 186 ' </tr>' . "\n" . 187 '</table>'; 188 189 return $confirm_string; 190 } 191 192 function send($newsletter_id) { 193 global $_POST, $db; 194 195 $audience = array(); 196 197 if (isset($_POST['global']) && ($_POST['global'] == 'true')) { 198 $products = $db->Execute("select distinct pn.customers_id, c.customers_firstname, 199 c.customers_lastname, c.customers_email_address 200 from " . TABLE_CUSTOMERS . " c, " . TABLE_PRODUCTS_NOTIFICATIONS . " pn 201 where c.customers_id = pn.customers_id"); 202 203 while (!$products->EOF) { 204 $audience[$products->fields['customers_id']] = array('firstname' => $products->fields['customers_firstname'], 205 'lastname' => $products->fields['customers_lastname'], 206 'email_address' => $products->fields['customers_email_address']); 207 $products->MoveNext(); 208 } 209 210 $customers = $db->Execute("select c.customers_id, c.customers_firstname, c.customers_lastname, 211 c.customers_email_address 212 from " . TABLE_CUSTOMERS . " c, " . TABLE_CUSTOMERS_INFO . " ci 213 where c.customers_id = ci.customers_info_id 214 and ci.global_product_notifications = '1'"); 215 216 while (!$customers->EOF) { 217 $audience[$customers->fields['customers_id']] = array('firstname' => $customers->fields['customers_firstname'], 218 'lastname' => $customers->fields['customers_lastname'], 219 'email_address' => $customers['customers_email_address']); 220 $customers->MoveNext(); 221 } 222 } else { //not global==true; instead, process all selected products 223 $chosen = $_POST['chosen']; 224 225 $ids = implode(',', $chosen); 226 227 $products = $db->Execute("select distinct pn.customers_id, c.customers_firstname, 228 c.customers_lastname, c.customers_email_address 229 from " . TABLE_CUSTOMERS . " c, " . TABLE_PRODUCTS_NOTIFICATIONS . " pn 230 where c.customers_id = pn.customers_id 231 and pn.products_id in (" . $ids . ")"); 232 233 while (!$products->EOF) { 234 $audience[$products->fields['customers_id']] = array('firstname' => $products->fields['customers_firstname'], 235 'lastname' => $products->fields['customers_lastname'], 236 'email_address' => $products->fields['customers_email_address']); 237 $products->MoveNext(); 238 } 239 240 $customers = $db->Execute("select c.customers_id, c.customers_firstname, c.customers_lastname, 241 c.customers_email_address 242 from " . TABLE_CUSTOMERS . " c, " . TABLE_CUSTOMERS_INFO . " ci 243 where c.customers_id = ci.customers_info_id 244 and ci.global_product_notifications = '1'"); 245 246 while (!$customers->EOF) { 247 $audience[$customers->fields['customers_id']] = array('firstname' => $customers->fields['customers_firstname'], 248 'lastname' => $customers->fields['customers_lastname'], 249 'email_address' => $customers->fields['customers_email_address']); 250 $customers->MoveNext(); 251 } 252 } 253 254 255 //send emails 256 reset($audience); 257 $i=0; 258 while (list($key, $value) = each ($audience)) { 259 $i++; 260 $html_msg['EMAIL_FIRST_NAME'] = $value['firstname']; 261 $html_msg['EMAIL_LAST_NAME'] = $value['lastname']; 262 $html_msg['EMAIL_MESSAGE_HTML'] = $this->content_html; 263 zen_mail($value['firstname'] . ' ' . $value['lastname'], $value['email_address'], $this->title, $this->content, STORE_NAME, EMAIL_FROM, $html_msg, 'product_notification',''); 264 echo zen_image(DIR_WS_ICONS . 'tick.gif', $value['email_address']); 265 266 //force output to the screen to show status indicator each time a message is sent... 267 if (function_exists('ob_flush')) @ob_flush(); 268 @flush(); 269 } 270 271 $newsletter_id = zen_db_prepare_input($newsletter_id); 272 $db->Execute("update " . TABLE_NEWSLETTERS . " 273 set date_sent = now(), status = '1' 274 where newsletters_id = '" . zen_db_input($newsletter_id) . "'"); 275 return $i; //return number of records processed whether successful or not 276 } 277 } 278 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 16:45:43 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |