PageRenderTime 30ms CodeModel.GetById 14ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/admin/module_newsletter.php

https://github.com/tisoft/xtcmodified
PHP | 556 lines | 494 code | 8 blank | 54 comment | 41 complexity | 8a1db7aa17ad0af15dd0273bb0880ced MD5 | raw file
  1<?php
  2  /* --------------------------------------------------------------
  3   $Id$
  4
  5   xtcModified - community made shopping
  6   http://www.xtc-modified.org
  7
  8   Copyright (c) 2010 xtcModified
  9   --------------------------------------------------------------
 10   based on:
 11   (c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
 12   (c) 2002-2003 osCommercecoding standards www.oscommerce.com
 13   (c) 2003 nextcommerce (templates_boxes.php,v 1.14 2003/08/18); www.nextcommerce.org
 14   (c) 2006 xt:Commerce
 15
 16   Released under the GNU General Public License
 17   --------------------------------------------------------------*/
 18
 19  require('includes/application_top.php');
 20
 21  require_once(DIR_FS_CATALOG.DIR_WS_CLASSES.'class.phpmailer.php');
 22  require_once(DIR_FS_INC . 'xtc_php_mail.inc.php');
 23  require_once(DIR_FS_INC . 'xtc_wysiwyg.inc.php');
 24
 25  $action = (isset($_GET['action']) ? $_GET['action'] : '');
 26
 27  if (xtc_not_null($action)) {
 28    switch ($action) {  // actions for datahandling
 29      case 'save': // save newsletter
 30        $id=xtc_db_prepare_input((int)$_POST['ID']);
 31        $status_all=xtc_db_prepare_input($_POST['status_all']);
 32        $newsletter_title = xtc_db_prepare_input($_POST['title']); //DokuMan - 2010-11-13 - set newsletter_title properly
 33        if ($newsletter_title=='')
 34          $newsletter_title='no title';
 35        $customers_status=xtc_get_customers_statuses();
 36        $rzp='';
 37        for ($i=0,$n=sizeof($customers_status);$i<$n; $i++) {
 38          if (xtc_db_prepare_input($_POST['status'][$i])=='yes') {
 39            if ($rzp!='')
 40              $rzp.=',';
 41            $rzp.=$customers_status[$i]['id'];
 42          }
 43        }
 44        if (xtc_db_prepare_input($_POST['status_all'])=='yes')
 45          $rzp.=',all';
 46        $error=false; // reset error flag
 47        if ($error == false) {
 48          $sql_data_array = array('title'=> $newsletter_title,
 49                                  'status' => '0',
 50                                  'bc'=>$rzp,
 51                                  'cc'=>xtc_db_prepare_input($_POST['cc']),
 52                                  'date' => 'now()',
 53                                  'body' => xtc_db_prepare_input($_POST['newsletter_body']));
 54          if ($id!='') {
 55            xtc_db_perform(TABLE_MODULE_NEWSLETTER, $sql_data_array, 'update', "newsletter_id = '" . $id . "'");
 56            // create temp table
 57            xtc_db_query("DROP TABLE IF EXISTS module_newsletter_temp_".$id);
 58            xtc_db_query("CREATE TABLE module_newsletter_temp_".$id."
 59                           (
 60                           id int(11) NOT NULL auto_increment,
 61                           customers_id int(11) NOT NULL default '0',
 62                           customers_status int(11) NOT NULL default '0',
 63                           customers_firstname varchar(64) NOT NULL default '',
 64                           customers_lastname varchar(64) NOT NULL default '',
 65                           customers_email_address text NOT NULL,
 66                           mail_key varchar(32) NOT NULL,
 67                           date datetime NOT NULL default '0000-00-00 00:00:00',
 68                           comment varchar(64) NOT NULL default '',
 69                           PRIMARY KEY  (id)
 70                          )");
 71          } else {
 72            xtc_db_perform(TABLE_MODULE_NEWSLETTER, $sql_data_array);
 73            // create temp table
 74            $id=xtc_db_insert_id();
 75            xtc_db_query("DROP TABLE IF EXISTS module_newsletter_temp_".$id);
 76            xtc_db_query("CREATE TABLE module_newsletter_temp_".$id."
 77                           (
 78                           id int(11) NOT NULL auto_increment,
 79                           customers_id int(11) NOT NULL default '0',
 80                           customers_status int(11) NOT NULL default '0',
 81                           customers_firstname varchar(64) NOT NULL default '',
 82                           customers_lastname varchar(64) NOT NULL default '',
 83                           customers_email_address text NOT NULL,
 84                           mail_key varchar(32) NOT NULL,
 85                           date datetime NOT NULL default '0000-00-00 00:00:00',
 86                           comment varchar(64) NOT NULL default '',
 87                           PRIMARY KEY  (id)
 88                           )");
 89          }
 90          // filling temp table with data!
 91          $flag='';
 92          if (!strpos($rzp,'all'))
 93            $flag='true';
 94          $rzp=str_replace(',all','',$rzp);
 95          $groups=explode(',',$rzp);
 96          $sql_data_array='';
 97          for ($i=0,$n=sizeof($groups);$i<$n;$i++) {
 98            // check if customer wants newsletter
 99            if (xtc_db_prepare_input($_POST['status_all'])=='yes') {
100              $customers_query=xtc_db_query("SELECT
101                                                    customers_id,
102                                                    customers_firstname,
103                                                    customers_lastname,
104                                                    customers_email_address
105                                               FROM ".TABLE_CUSTOMERS."
106                                              WHERE customers_status='".$groups[$i]."'");
107            } else {
108              $customers_query=xtc_db_query("SELECT
109                                                    customers_email_address,
110                                                    customers_id,
111                                                    customers_firstname,
112                                                    customers_lastname,
113                                                    mail_key
114                                               FROM ".TABLE_NEWSLETTER_RECIPIENTS."
115                                              WHERE customers_status='".$groups[$i]."'
116                                                AND mail_status='1'");
117            }
118            while ($customers_data=xtc_db_fetch_array($customers_query)){
119              $sql_data_array=array(
120                                    'customers_id'=>$customers_data['customers_id'],
121                                    'customers_status'=>$groups[$i],
122                                    'customers_firstname'=>$customers_data['customers_firstname'],
123                                    'customers_lastname'=>$customers_data['customers_lastname'],
124                                    'customers_email_address'=>$customers_data['customers_email_address'],
125                                    'mail_key'=>$customers_data['mail_key'],
126                                    'date'=>'now()');
127              xtc_db_perform('module_newsletter_temp_'.$id, $sql_data_array);
128            }
129          }
130          xtc_redirect(xtc_href_link(FILENAME_MODULE_NEWSLETTER));
131        }
132        break;
133
134      case 'delete':
135        xtc_db_query("DELETE FROM ".TABLE_MODULE_NEWSLETTER." WHERE   newsletter_id='".(int)$_GET['ID']."'");
136        xtc_redirect(xtc_href_link(FILENAME_MODULE_NEWSLETTER));
137        break;
138      case 'send':
139        // max email package  -> should be in admin area!
140        $package_size='30';
141        xtc_redirect(xtc_href_link(FILENAME_MODULE_NEWSLETTER,'send=0,'.$package_size.'&ID='.(int)$_GET['ID']));
142    }
143  }
144  // action for sending mails!
145  if (isset($_GET['send'])) {
146    $limits=explode(',',$_GET['send']);
147    $limit_low = $limits['0'];
148    $limit_up = $limits['1'];
149    $limit_query=xtc_db_query("SELECT count(*) as count
150                                 FROM module_newsletter_temp_".(int)$_GET['ID']."
151                              ");
152    $limit_data=xtc_db_fetch_array($limit_query);
153    // select emailrange from db
154    $email_query=xtc_db_query("SELECT
155                                      customers_firstname,
156                                      customers_lastname,
157                                      customers_email_address,
158                                      mail_key ,
159                                      id
160                                FROM  module_newsletter_temp_".(int)$_GET['ID']."
161                                LIMIT ".$limit_low.",".$limit_up);
162
163    $email_data=array();
164    while ($email_query_data=xtc_db_fetch_array($email_query)) {
165      $email_data[]=array('id' => $email_query_data['id'],
166                          'firstname'=>$email_query_data['customers_firstname'],
167                          'lastname'=>$email_query_data['customers_lastname'],
168                          'email'=>$email_query_data['customers_email_address'],
169                          'key'=>$email_query_data['mail_key']);
170    }
171    // ok lets send the mails in package of 30 mails, to prevent php timeout
172    $package_size='30';
173    $break='0';
174    if ($limit_data['count']<$limit_up) {
175      $limit_up=$limit_data['count'];
176      $break='1';
177    }
178    $max_runtime=$limit_up-$limit_low;
179    $newsletters_query=xtc_db_query("SELECT
180                                            title,
181                                            body,
182                                            bc,
183                                            cc
184                                       FROM ".TABLE_MODULE_NEWSLETTER."
185                                     WHERE  newsletter_id='".(int)$_GET['ID']."'");
186    $newsletters_data=xtc_db_fetch_array($newsletters_query);
187    // if ($newsletters_data['cc']!='') {
188    // xtc_php_mail(EMAIL_SUPPORT_ADDRESS,
189    //              EMAIL_SUPPORT_NAME,
190    //              $newsletters_data['cc'],
191    //              '' ,
192    //              '',
193    //              EMAIL_SUPPORT_REPLY_ADDRESS,
194    //              EMAIL_SUPPORT_REPLY_ADDRESS_NAME,
195    //              '',
196    //              '',
197    //              $newsletters_data['title'],
198    //              $newsletters_data['body'],
199    //              $newsletters_data['body']);
200    //              }
201
202    for ($i=1;$i<=$max_runtime;$i++) {
203      // mail
204      $link1 = chr(13).chr(10).chr(13).chr(10).TEXT_NEWSLETTER_REMOVE.chr(13).chr(10).chr(13).chr(10).HTTP_CATALOG_SERVER.DIR_WS_CATALOG.FILENAME_CATALOG_NEWSLETTER.'?action=remove&email='.$email_data[$i-1]['email'].'&key='.$email_data[$i-1]['key'];
205      $link2 = $link2 = '<br /><br /><hr>'.TEXT_NEWSLETTER_REMOVE.'<br /><a href="'.HTTP_CATALOG_SERVER.DIR_WS_CATALOG.FILENAME_CATALOG_NEWSLETTER.'?action=remove&email='.$email_data[$i-1]['email'].'&key='.$email_data[$i-1]['key'].'">' . TEXT_REMOVE_LINK . '</a>';
206      xtc_php_mail(EMAIL_SUPPORT_ADDRESS,
207                   EMAIL_SUPPORT_NAME,
208                   $email_data[$i-1]['email'] ,
209                   $email_data[$i-1]['lastname'] . ' ' . $email_data[$i-1]['firstname'] ,
210                   '',
211                   EMAIL_SUPPORT_REPLY_ADDRESS,
212                   EMAIL_SUPPORT_REPLY_ADDRESS_NAME,
213                   '',
214                   '',
215                   $newsletters_data['title'],
216                   $newsletters_data['body'].$link2,
217                   $newsletters_data['body'].$link1);
218      xtc_db_query("UPDATE module_newsletter_temp_".(int)$_GET['ID']." SET comment='send' WHERE id='".$email_data[$i-1]['id']."'");
219    }
220    if ($break=='1') {
221      // finished
222      $limit1_query=xtc_db_query("SELECT count(*) as count
223                                    FROM module_newsletter_temp_".(int)$_GET['ID']."
224                                   WHERE comment='send'");
225      $limit1_data=xtc_db_fetch_array($limit1_query);
226      if ($limit1_data['count']-$limit_data['count']<=0) {
227        xtc_db_query("UPDATE ".TABLE_MODULE_NEWSLETTER." SET status='1' WHERE newsletter_id='".(int)$_GET['ID']."'");
228        xtc_redirect(xtc_href_link(FILENAME_MODULE_NEWSLETTER));
229      } else {
230        echo '<b>'.$limit1_data['count'].'<b> emails send<br />';
231        echo '<b>'.$limit1_data['count']-$limit_data['count'].'<b> emails left';
232      }
233    } else {
234      $limit_low=$limit_up+1;
235      $limit_up=$limit_low+$package_size;
236      xtc_redirect(xtc_href_link(FILENAME_MODULE_NEWSLETTER,'send='.$limit_low.','.$limit_up.'&ID='.(int)$_GET['ID']));
237    }
238  }
239?>
240<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
241<html <?php echo HTML_PARAMS; ?>>
242  <head>
243    <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $_SESSION['language_charset']; ?>" />
244    <title><?php echo TITLE; ?></title>
245    <link rel="stylesheet" type="text/css" href="includes/stylesheet.css" />
246    <?php
247      if (USE_WYSIWYG=='true') {
248        $query=xtc_db_query("SELECT code FROM ". TABLE_LANGUAGES ." WHERE languages_id='".$_SESSION['languages_id']."'");
249        $data=xtc_db_fetch_array($query);
250        if ($action !='')
251          echo xtc_wysiwyg('newsletter',$data['code']);
252      }
253    ?>
254  </head>
255  <body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
256    <!-- header //-->
257    <?php require(DIR_WS_INCLUDES . 'header.php'); ?>
258    <!-- header_eof //-->
259    <!-- body //-->
260    <table border="0" width="100%" cellspacing="2" cellpadding="2">
261      <tr>
262        <td class="columnLeft2" width="<?php echo BOX_WIDTH; ?>" valign="top">
263          <table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
264            <!-- left_navigation //-->
265            <?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
266            <!-- left_navigation_eof //-->
267          </table>
268        </td>
269        <!-- body_text //-->
270        <td width="100%" valign="top">
271          <table border="0" width="100%" cellspacing="0" cellpadding="0">
272            <tr>
273              <td>
274                <table border="0" width="100%" cellspacing="0" cellpadding="0">
275                  <tr>
276                    <td width="80" rowspan="2"><?php echo xtc_image(DIR_WS_ICONS.'heading_news.gif'); ?></td>
277                    <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
278                  </tr>
279                  <tr>
280                    <td class="main" valign="top">XTC Tools</td>
281                  </tr>
282                </table>
283              </td>
284            </tr>
285            <?php
286            if (isset($_GET['send'])) {
287              //DokuMan - set undefined index
288              ?>
289              <tr>
290                <td>Sending</td>
291              </tr>
292              <?php
293            }
294            ?>
295            <tr>
296              <td>
297                <table width="100%" border="0">
298                  <tr>
299                    <td>
300                      <?php
301                      // Default seite
302                      switch ($action) {
303                        default:
304                          // Get Customers Groups
305                          $customer_group_query=xtc_db_query("SELECT
306                                                                     customers_status_name,
307                                                                     customers_status_id,
308                                                                     customers_status_image
309                                                                FROM ".TABLE_CUSTOMERS_STATUS."
310                                                               WHERE language_id='".$_SESSION['languages_id']."'");
311                          $customer_group=array();
312                          while ($customer_group_data=xtc_db_fetch_array($customer_group_query)) {
313                            // get single users
314                            $group_query=xtc_db_query("SELECT count(*) as count
315                                                         FROM ".TABLE_NEWSLETTER_RECIPIENTS."
316                                                        WHERE mail_status='1' and
317                                                              customers_status='".$customer_group_data['customers_status_id']."'");
318                            $group_data=xtc_db_fetch_array($group_query);
319                            $customer_group[]=array('ID'=>$customer_group_data['customers_status_id'],
320                                                    'NAME'=>$customer_group_data['customers_status_name'],
321                                                    'IMAGE'=>$customer_group_data['customers_status_image'],
322                                                    'USERS'=>$group_data['count']);
323                          }
324
325                          ?>
326                          <br />
327                          <table width="100%" border="0" cellspacing="0" cellpadding="0">
328                            <tr>
329                              <td>
330                                <table border="0" width="100%" cellspacing="0" cellpadding="2">
331                                  <tr class="dataTableHeadingRow">
332                                    <td class="dataTableHeadingContent" width="150" ><?php echo TITLE_CUSTOMERS; ?></td>
333                                    <td class="dataTableHeadingContent"  ><?php echo TITLE_STK; ?></td>
334                                  </tr>
335                                  <?php
336                                  for ($i=0,$n=sizeof($customer_group); $i<$n; $i++) {
337                                    ?>
338                                    <tr>
339                                      <td class="dataTableContent" style="border-bottom: 1px solid; border-color: #f1f1f1;" valign="middle" align="left"><?php echo xtc_image(DIR_WS_ICONS . $customer_group[$i]['IMAGE'], ''); ?><?php echo $customer_group[$i]['NAME']; ?></td>
340                                      <td class="dataTableContent" style="border-bottom: 1px solid; border-color: #f1f1f1;" align="left"><?php echo $customer_group[$i]['USERS']; ?></td>
341                                    </tr>
342                                    <?php
343                                  }
344                                  ?>
345                                </table>
346                              </td>
347                              <td width="30%" align="right" valign="top"">
348                                <?php
349                                echo '<a class="button" href="'.xtc_href_link(FILENAME_MODULE_NEWSLETTER,'action=new').'">'.BUTTON_NEW_NEWSLETTER.'</a>';
350                                ?>
351                              </td>
352                            </tr>
353                          </table>
354                          <br />
355                          <?php
356                          // get data for newsletter overwiev
357                          $newsletters_query=xtc_db_query("SELECT
358                                                                  newsletter_id,date,title
359                                                             FROM ".TABLE_MODULE_NEWSLETTER."
360                                                            WHERE status='0'");
361                          $news_data=array();
362                          while ($newsletters_data=xtc_db_fetch_array($newsletters_query)) {
363                            $news_data[]=array('id' =>$newsletters_data['newsletter_id'],
364                                               'date'=>$newsletters_data['date'],
365                                               'title'=>$newsletters_data['title']);
366                          }
367                          ?>
368                          <table border="0" width="100%" cellspacing="0" cellpadding="2">
369                            <tr class="dataTableHeadingRow">
370                              <td class="dataTableHeadingContent" width="30" ><?php echo TITLE_DATE; ?></td>
371                              <td class="dataTableHeadingContent" width="80%" ><?php echo TITLE_NOT_SEND; ?></td>
372                              <td class="dataTableHeadingContent">&nbsp;</td>
373                            </tr>
374                            <?php
375                            for ($i=0,$n=sizeof($news_data); $i<$n; $i++) {
376                              if ($news_data[$i]['id']!='') {
377                                ?>
378                                <tr>
379                                  <td class="dataTableContent" style="border-bottom: 1px solid; border-color: #f1f1f1;" align="left"><?php echo $news_data[$i]['date']; ?></td>
380                                  <td class="dataTableContent" style="border-bottom: 1px solid; border-color: #f1f1f1;" valign="middle" align="left"><?php echo xtc_image(DIR_WS_CATALOG.'images/icons/arrow.gif'); ?><a href="<?php echo xtc_href_link(FILENAME_MODULE_NEWSLETTER,'ID='.$news_data[$i]['id']); ?>"><b><?php echo $news_data[$i]['title']; ?></b></a></td>
381                                  <td class="dataTableContent" style="border-bottom: 1px solid; border-color: #f1f1f1;" align="left"></td>
382                                </tr>
383                                <?php
384                                if (isset($_GET['ID']) && $_GET['ID']!='' && $_GET['ID']==$news_data[$i]['id']) {
385                                  $total_query=xtc_db_query("SELECT
386                                                                    count(*) as count
387                                                               FROM module_newsletter_temp_".(int)$_GET['ID']."");
388                                  $total_data=xtc_db_fetch_array($total_query);
389                                  ?>
390                                  <tr>
391                                    <td class="dataTableContent_products" style="border-bottom: 1px solid; border-color: #f1f1f1;" align="left"></td>
392                                    <td colspan="2" class="dataTableContent_products" style="border-bottom: 1px solid; border-color: #f1f1f1;" align="left"><?php echo TEXT_SEND_TO.$total_data['count']; ?></td>
393                                  </tr>
394                                  <tr>
395                                    <td class="dataTableContent" valign="top" style="border-bottom: 1px solid; border-color: #999999;" align="left">
396                                      <a class="button" href="<?php echo xtc_href_link(FILENAME_MODULE_NEWSLETTER,'action=delete&ID='.$news_data[$i]['id']); ?>" onclick="return confirm('<?php echo CONFIRM_DELETE; ?>')"><?php echo BUTTON_DELETE.'</a><br />'; ?>
397                                      <a class="button" href="<?php echo xtc_href_link(FILENAME_MODULE_NEWSLETTER,'action=edit&ID='.$news_data[$i]['id']); ?>"><?php echo BUTTON_EDIT.'</a>'; ?>
398                                      <br /><br /><div style="height: 1px; background: Black; margin: 3px 0;"></div>
399                                      <a class="button" href="<?php echo xtc_href_link(FILENAME_MODULE_NEWSLETTER,'action=send&ID='.$news_data[$i]['id']); ?>"><?php echo BUTTON_SEND.'</a>'; ?>
400                                    </td>
401                                    <td colspan="2" class="dataTableContent" style="border-bottom: 1px solid; border-color: #999999; text-align: left;">
402                                      <?php
403                                      // get data
404                                      $newsletters_query=xtc_db_query("SELECT
405                                                                              title,body,cc,bc
406                                                                         FROM ".TABLE_MODULE_NEWSLETTER."
407                                                                        WHERE newsletter_id='".(int)$_GET['ID']."'");
408                                      $newsletters_data=xtc_db_fetch_array($newsletters_query);
409                                      echo TEXT_TITLE.$newsletters_data['title'].'<br />';
410                                      $customers_status=xtc_get_customers_statuses();
411                                      for ($i=0,$n=sizeof($customers_status);$i<$n; $i++) {
412                                        $newsletters_data['bc']=str_replace($customers_status[$i]['id'],$customers_status[$i]['text'],$newsletters_data['bc']);
413                                      }
414                                      echo TEXT_TO.$newsletters_data['bc'].'<br />';
415                                      echo TEXT_CC.$newsletters_data['cc'].'<br /><br />'.TEXT_PREVIEW;
416                                      echo '<table style="border-color: #cccccc; border: 1px solid;" width="100%"><tr><td>'.$newsletters_data['body'].'</td></tr></table>';
417                                      ?>
418                                    </td>
419                                  </tr>
420                                  <?php
421                                }
422                              }
423                            }
424                            ?>
425                          </table>
426                          <br /><br />
427                          <?php
428                          $newsletters_query=xtc_db_query("SELECT
429                                                                  newsletter_id,date,title
430                                                             FROM ".TABLE_MODULE_NEWSLETTER."
431                                                            WHERE status='1'");
432                          $news_data=array();
433                          while ($newsletters_data=xtc_db_fetch_array($newsletters_query)) {
434                            $news_data[]=array('id' => $newsletters_data['newsletter_id'],
435                                               'date'=>$newsletters_data['date'],
436                                               'title'=>$newsletters_data['title']);
437                          }
438                          ?>
439                          <table border="0" width="100%" cellspacing="0" cellpadding="2">
440                            <tr class="dataTableHeadingRow">
441                              <td class="dataTableHeadingContent" width="80%" ><?php echo TITLE_SEND; ?></td>
442                              <td class="dataTableHeadingContent"><?php echo TITLE_ACTION; ?></td>
443                            </tr>
444                            <?php
445                            for ($i=0,$n=sizeof($news_data); $i<$n; $i++) {
446                              if ($news_data[$i]['id']!='') {
447                                ?>
448                                <tr>
449                                  <td class="dataTableContent" style="border-bottom: 1px solid; border-color: #f1f1f1;" valign="middle" align="left"><?php echo $news_data[$i]['date'].'    '; ?><b><?php echo $news_data[$i]['title']; ?></b></td>
450                                  <td class="dataTableContent" style="border-bottom: 1px solid; border-color: #f1f1f1;" align="left">
451                                    <?php /*BOF - Tomcraft - 2009-06-10 - added some missing alternative text on admin icons/*
452                                    /*
453                                    <a href="<?php echo xtc_href_link(FILENAME_MODULE_NEWSLETTER,'action=delete&ID='.$news_data[$i]['id']); ?>" onclick="return confirm('<?php echo CONFIRM_DELETE; ?>')">
454                                    <?php
455                                    echo xtc_image(DIR_WS_ICONS.'delete.gif','Delete','','','style="cursor:pointer" onclick="return confirm(\''.DELETE_ENTRY.'\')"').'  '.TEXT_DELETE.'</a>&nbsp;&nbsp;';
456                                    ?>
457                                    <a href="<?php echo xtc_href_link(FILENAME_MODULE_NEWSLETTER,'action=edit&ID='.$news_data[$i]['id']); ?>">
458                                    <?php echo xtc_image(DIR_WS_ICONS.'icon_edit.gif','Edit','','').'  '.TEXT_EDIT.'</a>'; ?>
459                                   */
460                                    ?>
461                                    <a href="<?php echo xtc_href_link(FILENAME_MODULE_NEWSLETTER,'action=edit&ID='.$news_data[$i]['id']); ?>">
462                                      <?php
463                                      echo xtc_image(DIR_WS_ICONS.'icon_edit.gif', ICON_EDIT,'','').'  '.TEXT_EDIT;
464                                    echo '</a>'; 
465                                    ?>
466                                    <a href="<?php echo xtc_href_link(FILENAME_MODULE_NEWSLETTER,'action=delete&ID='.$news_data[$i]['id']); ?>" onclick="return confirm('<?php echo CONFIRM_DELETE; ?>')">
467                                      <?php
468                                      echo xtc_image(DIR_WS_ICONS.'delete.gif', ICON_DELETE,'','','style="cursor:pointer" onclick="return confirm(\''.DELETE_ENTRY.'\')"').'  '.TEXT_DELETE;
469                                    echo '</a>&nbsp;&nbsp;';
470                                    ?>
471                                    <?php /*EOF - Tomcraft - 2009-06-10 - added some missing alternative text on admin icons*/ ?>
472                                  </td>
473                                </tr>
474                                <?php
475                              }
476                            }
477                            ?>
478                          </table>
479                          <?php
480                          break;       // end default page
481                        case 'edit':
482                          $newsletters_query=xtc_db_query("SELECT title,body,cc,bc FROM ".TABLE_MODULE_NEWSLETTER." WHERE newsletter_id='".(int)$_GET['ID']."'");
483                          $newsletters_data=xtc_db_fetch_array($newsletters_query);
484                        case 'safe':
485                        case 'new':  // action for NEW newsletter!
486                          $customers_status=xtc_get_customers_statuses();
487                          echo xtc_draw_form('edit_newsletter',FILENAME_MODULE_NEWSLETTER,'action=save','post','enctype="multipart/form-data"').xtc_draw_hidden_field('ID',$_GET['ID']);
488                            ?>
489                            <br /><br />
490                            <table class="main" width="100%" border="0">
491                              <tr>
492                                <td width="10%"><?php echo TEXT_TITLE; ?></td>
493                                <td width="90%"><?php echo xtc_draw_input_field('title',isset($newsletters_data['title']) ? $newsletters_data['title'] : '','size=100'); ?></td>
494                              </tr>
495                              <tr>
496                                <td width="10%"><?php echo TEXT_TO; ?></td>
497                                <td width="90%">
498                                  <?php
499                                  for ($i=0,$n=sizeof($customers_status);$i<$n; $i++) {
500                                    $group_query=xtc_db_query("SELECT count(*) as count
501                                                                                   FROM ".TABLE_NEWSLETTER_RECIPIENTS."
502                                                                                  WHERE mail_status='1'
503                                                                                    AND customers_status='".$customers_status[$i]['id']."'");
504                                    $group_data=xtc_db_fetch_array($group_query);
505                                    $group_query=xtc_db_query("SELECT count(*) as count
506                                                                                   FROM ".TABLE_CUSTOMERS."
507                                                                                  WHERE customers_status='".$customers_status[$i]['id']."'");
508                                    $group_data_all=xtc_db_fetch_array($group_query);
509                                    $bc_array = explode(',', isset($newsletters_data['bc']) ? $newsletters_data['bc'] : ''); //DokuMan - set undefined index
510                                    echo xtc_draw_checkbox_field('status['.$i.']','yes', in_array($customers_status[$i]['id'], $bc_array)).' '.$customers_status[$i]['text'].'  <i>(<b>'.$group_data['count'].'</b>'.TEXT_USERS.$group_data_all['count'].TEXT_CUSTOMERS.'<br />';
511                                  }
512                                  echo xtc_draw_checkbox_field('status_all', 'yes',in_array('all', $bc_array)).' <b>'.TEXT_NEWSLETTER_ONLY.'</b>';
513                                  ?>
514                                </td>
515                              </tr>
516                              <tr>
517                                <td width="10%"><?php echo TEXT_CC; ?></td>
518                                <td width="90%">
519                                  <?php
520                                    echo xtc_draw_input_field('cc',isset($newsletters_data['cc']) ? $newsletters_data['cc'] : '','size=100');
521                                  ?>
522                                </td>
523                              </tr>
524                              <tr>
525                                <td width="10%" valign="top"><?php echo TEXT_BODY; ?></td>
526                                <td width="90%">
527                                  <?php
528                                    echo xtc_draw_textarea_field('newsletter_body', 'soft', '150', '45', stripslashes(isset($newsletters_data['body']) ? $newsletters_data['body'] : ''));
529                                  ?>
530                                </td>
531                              </tr>
532                            </table>
533                            <a class="button" onclick="this.blur();" href="<?php echo xtc_href_link(FILENAME_MODULE_NEWSLETTER); ?>"><?php echo BUTTON_BACK; ?></a>
534                            <right><?php echo '<input type="submit" class="button" onclick="this.blur();" value="' . BUTTON_SAVE . '"/>'; ?></right>
535                          </form>
536                          <?php
537                          break;
538                      } // end switch
539                      ?>
540                    </td>
541                  </tr>
542                </table>
543              </td>
544            </tr>
545          </table>
546        </td>
547        <!-- body_text_eof //-->
548      </tr>
549    </table>
550    <!-- body_eof //-->
551    <!-- footer //-->
552    <?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
553    <!-- footer_eof //-->
554  </body>
555</html>
556<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>