[ Index ]
 

Code source de osCommerce 2.2ms2-060817

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/catalog/admin/includes/modules/newsletters/ -> product_notification.php (source)

   1  <?php
   2  /*
   3    $Id: product_notification.php,v 1.7 2003/06/30 11:02:48 hpdl Exp $
   4  
   5    osCommerce, Open Source E-Commerce Solutions
   6    http://www.oscommerce.com
   7  
   8    Copyright (c) 2002 osCommerce
   9  
  10    Released under the GNU General Public License
  11  */
  12  
  13    class product_notification {
  14      var $show_choose_audience, $title, $content;
  15  
  16      function product_notification($title, $content) {
  17        $this->show_choose_audience = true;
  18        $this->title = $title;
  19        $this->content = $content;
  20      }
  21  
  22      function choose_audience() {
  23        global $HTTP_GET_VARS, $languages_id;
  24  
  25        $products_array = array();
  26        $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");
  27        while ($products = tep_db_fetch_array($products_query)) {
  28          $products_array[] = array('id' => $products['products_id'],
  29                                    'text' => $products['products_name']);
  30        }
  31  
  32  $choose_audience_string = '<script language="javascript"><!--
  33  function mover(move) {
  34    if (move == \'remove\') {
  35      for (x=0; x<(document.notifications.products.length); x++) {
  36        if (document.notifications.products.options[x].selected) {
  37          with(document.notifications.elements[\'chosen[]\']) {
  38            options[options.length] = new Option(document.notifications.products.options[x].text,document.notifications.products.options[x].value);
  39          }
  40          document.notifications.products.options[x] = null;
  41          x = -1;
  42        }
  43      }
  44    }
  45    if (move == \'add\') {
  46      for (x=0; x<(document.notifications.elements[\'chosen[]\'].length); x++) {
  47        if (document.notifications.elements[\'chosen[]\'].options[x].selected) {
  48          with(document.notifications.products) {
  49            options[options.length] = new Option(document.notifications.elements[\'chosen[]\'].options[x].text,document.notifications.elements[\'chosen[]\'].options[x].value);
  50          }
  51          document.notifications.elements[\'chosen[]\'].options[x] = null;
  52          x = -1;
  53        }
  54      }
  55    }
  56    return true;
  57  }
  58  
  59  function selectAll(FormName, SelectBox) {
  60    temp = "document." + FormName + ".elements[\'" + SelectBox + "\']";
  61    Source = eval(temp);
  62  
  63    for (x=0; x<(Source.length); x++) {
  64      Source.options[x].selected = "true";
  65    }
  66  
  67    if (x<1) {
  68      alert(\'' . JS_PLEASE_SELECT_PRODUCTS . '\');
  69      return false;
  70    } else {
  71      return true;
  72    }
  73  }
  74  //--></script>';
  75  
  76        $global_button = '<script language="javascript"><!--' . "\n" .
  77                         'document.write(\'<input type="button" value="' . BUTTON_GLOBAL . '" style="width: 8em;" onclick="document.location=\\\'' . tep_href_link(FILENAME_NEWSLETTERS, 'page=' . $HTTP_GET_VARS['page'] . '&nID=' . $HTTP_GET_VARS['nID'] . '&action=confirm&global=true') . '\\\'">\');' . "\n" .
  78                         '//--></script><noscript><a href="' . tep_href_link(FILENAME_NEWSLETTERS, 'page=' . $HTTP_GET_VARS['page'] . '&nID=' . $HTTP_GET_VARS['nID'] . '&action=confirm&global=true') . '">[ ' . BUTTON_GLOBAL . ' ]</a></noscript>';
  79  
  80        $cancel_button = '<script language="javascript"><!--' . "\n" .
  81                         'document.write(\'<input type="button" value="' . BUTTON_CANCEL . '" style="width: 8em;" onclick="document.location=\\\'' . tep_href_link(FILENAME_NEWSLETTERS, 'page=' . $HTTP_GET_VARS['page'] . '&nID=' . $HTTP_GET_VARS['nID']) . '\\\'">\');' . "\n" .
  82                         '//--></script><noscript><a href="' . tep_href_link(FILENAME_NEWSLETTERS, 'page=' . $HTTP_GET_VARS['page'] . '&nID=' . $HTTP_GET_VARS['nID']) . '">[ ' . BUTTON_CANCEL . ' ]</a></noscript>';
  83  
  84        $choose_audience_string .= '<form name="notifications" action="' . tep_href_link(FILENAME_NEWSLETTERS, 'page=' . $HTTP_GET_VARS['page'] . '&nID=' . $HTTP_GET_VARS['nID'] . '&action=confirm') . '" method="post" onSubmit="return selectAll(\'notifications\', \'chosen[]\')"><table border="0" width="100%" cellspacing="0" cellpadding="2">' . "\n" .
  85                                   '  <tr>' . "\n" .
  86                                   '    <td align="center" class="main"><b>' . TEXT_PRODUCTS . '</b><br>' . tep_draw_pull_down_menu('products', $products_array, '', 'size="20" style="width: 20em;" multiple') . '</td>' . "\n" .
  87                                   '    <td align="center" class="main">&nbsp;<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" .
  88                                   '    <td align="center" class="main"><b>' . TEXT_SELECTED_PRODUCTS . '</b><br>' . tep_draw_pull_down_menu('chosen[]', array(), '', 'size="20" style="width: 20em;" multiple') . '</td>' . "\n" .
  89                                   '  </tr>' . "\n" .
  90                                   '</table></form>';
  91  
  92        return $choose_audience_string;
  93      }
  94  
  95      function confirm() {
  96        global $HTTP_GET_VARS, $HTTP_POST_VARS;
  97  
  98        $audience = array();
  99  
 100        if (isset($HTTP_GET_VARS['global']) && ($HTTP_GET_VARS['global'] == 'true')) {
 101          $products_query = tep_db_query("select distinct customers_id from " . TABLE_PRODUCTS_NOTIFICATIONS);
 102          while ($products = tep_db_fetch_array($products_query)) {
 103            $audience[$products['customers_id']] = '1';
 104          }
 105  
 106          $customers_query = tep_db_query("select customers_info_id from " . TABLE_CUSTOMERS_INFO . " where global_product_notifications = '1'");
 107          while ($customers = tep_db_fetch_array($customers_query)) {
 108            $audience[$customers['customers_info_id']] = '1';
 109          }
 110        } else {
 111          $chosen = $HTTP_POST_VARS['chosen'];
 112  
 113          $ids = implode(',', $chosen);
 114  
 115          $products_query = tep_db_query("select distinct customers_id from " . TABLE_PRODUCTS_NOTIFICATIONS . " where products_id in (" . $ids . ")");
 116          while ($products = tep_db_fetch_array($products_query)) {
 117            $audience[$products['customers_id']] = '1';
 118          }
 119  
 120          $customers_query = tep_db_query("select customers_info_id from " . TABLE_CUSTOMERS_INFO . " where global_product_notifications = '1'");
 121          while ($customers = tep_db_fetch_array($customers_query)) {
 122            $audience[$customers['customers_info_id']] = '1';
 123          }
 124        }
 125  
 126        $confirm_string = '<table border="0" cellspacing="0" cellpadding="2">' . "\n" .
 127                          '  <tr>' . "\n" .
 128                          '    <td class="main"><font color="#ff0000"><b>' . sprintf(TEXT_COUNT_CUSTOMERS, sizeof($audience)) . '</b></font></td>' . "\n" .
 129                          '  </tr>' . "\n" .
 130                          '  <tr>' . "\n" .
 131                          '    <td>' . tep_draw_separator('pixel_trans.gif', '1', '10') . '</td>' . "\n" .
 132                          '  </tr>' . "\n" .
 133                          '  <tr>' . "\n" .
 134                          '    <td class="main"><b>' . $this->title . '</b></td>' . "\n" .
 135                          '  </tr>' . "\n" .
 136                          '  <tr>' . "\n" .
 137                          '    <td>' . tep_draw_separator('pixel_trans.gif', '1', '10') . '</td>' . "\n" .
 138                          '  </tr>' . "\n" .
 139                          '  <tr>' . "\n" .
 140                          '    <td class="main"><tt>' . nl2br($this->content) . '</tt></td>' . "\n" .
 141                          '  </tr>' . "\n" .
 142                          '  <tr>' . "\n" .
 143                          '    <td>' . tep_draw_separator('pixel_trans.gif', '1', '10') . '</td>' . "\n" .
 144                          '  </tr>' . "\n" .
 145                          '  <tr>' . tep_draw_form('confirm', FILENAME_NEWSLETTERS, 'page=' . $HTTP_GET_VARS['page'] . '&nID=' . $HTTP_GET_VARS['nID'] . '&action=confirm_send') . "\n" .
 146                          '    <td align="right">';
 147        if (sizeof($audience) > 0) {
 148          if (isset($HTTP_GET_VARS['global']) && ($HTTP_GET_VARS['global'] == 'true')) {
 149            $confirm_string .= tep_draw_hidden_field('global', 'true');
 150          } else {
 151            for ($i = 0, $n = sizeof($chosen); $i < $n; $i++) {
 152              $confirm_string .= tep_draw_hidden_field('chosen[]', $chosen[$i]);
 153            }
 154          }
 155          $confirm_string .= tep_image_submit('button_send.gif', IMAGE_SEND) . ' ';
 156        }
 157        $confirm_string .= '<a href="' . tep_href_link(FILENAME_NEWSLETTERS, 'page=' . $HTTP_GET_VARS['page'] . '&nID=' . $HTTP_GET_VARS['nID'] . '&action=send') . '">' . tep_image_button('button_back.gif', IMAGE_BACK) . '</a> <a href="' . tep_href_link(FILENAME_NEWSLETTERS, 'page=' . $HTTP_GET_VARS['page'] . '&nID=' . $HTTP_GET_VARS['nID']) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a></td>' . "\n" .
 158                           '  </tr>' . "\n" .
 159                           '</table>';
 160  
 161        return $confirm_string;
 162      }
 163  
 164      function send($newsletter_id) {
 165        global $HTTP_POST_VARS;
 166  
 167        $audience = array();
 168  
 169        if (isset($HTTP_POST_VARS['global']) && ($HTTP_POST_VARS['global'] == 'true')) {
 170          $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");
 171          while ($products = tep_db_fetch_array($products_query)) {
 172            $audience[$products['customers_id']] = array('firstname' => $products['customers_firstname'],
 173                                                         'lastname' => $products['customers_lastname'],
 174                                                         'email_address' => $products['customers_email_address']);
 175          }
 176  
 177          $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'");
 178          while ($customers = tep_db_fetch_array($customers_query)) {
 179            $audience[$customers['customers_id']] = array('firstname' => $customers['customers_firstname'],
 180                                                          'lastname' => $customers['customers_lastname'],
 181                                                          'email_address' => $customers['customers_email_address']);
 182          }
 183        } else {
 184          $chosen = $HTTP_POST_VARS['chosen'];
 185  
 186          $ids = implode(',', $chosen);
 187  
 188          $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 . ")");
 189          while ($products = tep_db_fetch_array($products_query)) {
 190            $audience[$products['customers_id']] = array('firstname' => $products['customers_firstname'],
 191                                                         'lastname' => $products['customers_lastname'],
 192                                                         'email_address' => $products['customers_email_address']);
 193          }
 194  
 195          $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'");
 196          while ($customers = tep_db_fetch_array($customers_query)) {
 197            $audience[$customers['customers_id']] = array('firstname' => $customers['customers_firstname'],
 198                                                          'lastname' => $customers['customers_lastname'],
 199                                                          'email_address' => $customers['customers_email_address']);
 200          }
 201        }
 202  
 203        $mimemessage = new email(array('X-Mailer: osCommerce bulk mailer'));
 204        $mimemessage->add_text($this->content);
 205        $mimemessage->build_message();
 206  
 207        reset($audience);
 208        while (list($key, $value) = each ($audience)) {
 209          $mimemessage->send($value['firstname'] . ' ' . $value['lastname'], $value['email_address'], '', EMAIL_FROM, $this->title);
 210        }
 211  
 212        $newsletter_id = tep_db_prepare_input($newsletter_id);
 213        tep_db_query("update " . TABLE_NEWSLETTERS . " set date_sent = now(), status = '1' where newsletters_id = '" . tep_db_input($newsletter_id) . "'");
 214      }
 215    }
 216  ?>


Généré le : Mon Nov 26 19:48:25 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics