<?php
/*
###################################################################################
  Bigware Shop 2.3
  Release Datum: 23.08.2015
  
  Bigware Shop
  http://www.bigware.de

  Copyright (c) 2015 Bigware LTD
  (c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
  (c) 2015	Bigware LTD

  Copyrightvermerke duerfen nicht entfernt werden.
  ------------------------------------------------------------------------
  Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen
  der GNU General Public License, wie von der Free Software Foundation
  veroeffentlicht, weitergeben und/oder modifizieren, entweder gemaess Version 2 
  der Lizenz oder (nach Ihrer Option) jeder spaeteren Version.
  Die Veroeffentlichung dieses Programms erfolgt in der Hoffnung, dass es Ihnen
  von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE, sogar ohne die
  implizite Garantie der MARKTREIFE oder der VERWENDBARKEIT FUER EINEN
  BESTIMMTEN ZWECK. Details finden Sie in der GNU General Public License.
  
  Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
  Programm erhalten haben. Falls nicht, schreiben Sie an die Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

  Infos:
  ------------------------------------------------------------------------
  Der Bigware Shop wurde vor vielen Jahren bereits aus dem bekannten Shopsystem osCommerce
  weiter- und neuentwickelt.
  Der Bigware Shop legt im hohen Masse Wert auf Bedienerfreundlichkeit, beinhaltet eine leichte
  Installation, viele neue professionelle Werkzeuge und zeichnet sich aus durch eine grosse 
  Community, die bei Problemen weiterhelfen kann.
  
  Der Bigware Shop ist auf jedem System lauffaehig, welches eine PHP Umgebung
  (ab PHP 4.1.3) und mySQL zur Verfuegung stellt und auf Linux basiert.
 
  Hilfe erhalten Sie im Forum auf www.bigware.de 
  
  -----------------------------------------------------------------------
  
 ##################################################################################




*/
?>
<?php
  require('load_this/load_bigware_11.php');
  require(FOLDER_RELATIV_CLASSES . 'class_bigware_1.php');
  $currencies = new currencies();
  if ( ($_GET['action'] == 'send_email_to_user') && ($_POST['attendees_email_address'] || $_POST['email_to']) && (!$_POST['back_x']) ) {
    switch ($_POST['attendees_email_address']) {
      case '***':
        $mail_query = go_db_query("select attendees_firstname, attendees_lastname, attendees_email_address from " . DB_TBL_ATTENDEES);
        $mail_sent_to = TEXT_ALL_ATTENDEES;
        break;
      case '**D':
        $mail_query = go_db_query("select attendees_firstname, attendees_lastname, attendees_email_address from " . DB_TBL_ATTENDEES . " where attendees_newsletter = '1'");
        $mail_sent_to = TEXT_NEWSLETTER_ATTENDEES;
        break;
      default:
        $attendees_email_address = go_db_producing_input($_POST['attendees_email_address']);
        $mail_query = go_db_query("select attendees_firstname, attendees_lastname, attendees_email_address from " . DB_TBL_ATTENDEES . " where attendees_email_address = '" . go_db_input($attendees_email_address) . "'");
        $mail_sent_to = $_POST['attendees_email_address'];
        if ($_POST['email_to']) {
          $mail_sent_to = $_POST['email_to'];
        }
        break;
    }
    $from = go_db_producing_input($_POST['from']);
    $subject = go_db_producing_input($_POST['subject']);
    while ($mail = go_db_fetch_array($mail_query)) {
      $id1 = create_coupon_code($mail['attendees_email_address']);
      $message = $_POST['message'];
      $message .= "\n\n" . TEXT_GV_WORTH  . $currencies->format($_POST['amount']) . "\n\n";
      $message .= TEXT_TO_REDEEM;
      $message .= TEXT_WHICH_IS . $id1 . TEXT_IN_CASE . "\n\n";
      if (SEARCH_ENGINE_FRIENDLY_URLS == 'true') {
        $message .= HTTP_SERVER  . FOLDER_RELATIV_CATALOG . NAME_OF_FILE_CURRENCIES . '/gv_no,'.$id1 . "\n\n"; //Fred bis Zeile 85 einschließlich
      } else {
        $message .= HTTP_SERVER  . FOLDER_RELATIV_CATALOG . NAME_OF_FILE_CURRENCIES . '?gv_no='.$id1 . "\n\n";
      }
      $message .= TEXT_OR_VISIT . HTTP_SERVER  . FOLDER_RELATIV_CATALOG . TEXT_ENTER_CODE; 
      $mimemessage = new email(array('X-Mailer: bigWare bulk mailer')); 
      $mimemessage->add_text($message);
      $mimemessage->build_message();
    
      $mimemessage->send($mail['attendees_firstname'] . ' ' . $mail['attendees_lastname'], $mail['attendees_email_address'], '', $from, $subject); 
      $insert_query = go_db_query("insert into " . DB_TBL_COUPONS . " (coupon_code, coupon_type, coupon_amount, date_created) values ('" . $id1 . "', 'G', '" . $_POST['amount'] . "', now())");
      $insert_id = go_db_insert_id($insert_query);
      $insert_query = go_db_query("insert into " . DB_TBL_COUPON_EMAIL_TRACK . " (coupon_id, attendee_id_sent, sent_firstname, emailed_to, date_sent) values ('" . $insert_id ."', '0', 'Admin', '" . $mail['attendees_email_address'] . "', now() )"); 
    }
    if ($_POST['email_to']) {
      $id1 = create_coupon_code($_POST['email_to']);
      $message = go_db_producing_input($_POST['message']);
      $message .= "\n\n" . TEXT_GV_WORTH  . $currencies->format($_POST['amount']) . "\n\n";
      $message .= TEXT_TO_REDEEM;
      $message .= TEXT_WHICH_IS . $id1 . TEXT_IN_CASE . "\n\n";
      $message .= HTTP_SERVER  . FOLDER_RELATIV_CATALOG . $CONFIG_NAME_FILE[main_bigware_27] . '?gv_no='.$id1 . "\n\n";
      $message .= TEXT_OR_VISIT . HTTP_SERVER  . FOLDER_RELATIV_CATALOG  . TEXT_ENTER_CODE; 
      $mimemessage = new email(array('X-Mailer: bigWare bulk mailer')); 
      $mimemessage->add_text($message);
      $mimemessage->build_message();
      $mimemessage->send('Friend', $_POST['email_to'], '', $from, $subject); 
      $insert_query = go_db_query("insert into " . DB_TBL_COUPONS . " (coupon_code, coupon_type, coupon_amount, date_created) values ('" . $id1 . "', 'G', '" . $_POST['amount'] . "', now())");
      $insert_id = go_db_insert_id($insert_query);
      $insert_query = go_db_query("insert into " . DB_TBL_COUPON_EMAIL_TRACK . " (coupon_id, attendee_id_sent, sent_firstname, emailed_to, date_sent) values ('" . $insert_id ."', '0', 'Admin', '" . $_POST['email_to'] . "', now() )"); 
    }
    go_forward(go_href_link(NAME_OF_FILE_GV_MAIL, 'mail_sent_to=' . urlencode($mail_sent_to)));
  }
  if ( ($_GET['action'] == 'preview') && (!$_POST['attendees_email_address']) && (!$_POST['email_to']) ) {
    $messageStack->add(ERROR_NO_ATTENDEE_SELECTED, 'error');
  }
  if ( ($_GET['action'] == 'preview') && (!$_POST['amount']) ) {
    $messageStack->add(ERROR_NO_AMOUNT_SELECTED, 'error');
  }
  if ($_GET['mail_sent_to']) {
    $messageStack->add(sprintf(NOTICE_EMAIL_SENT_TO, $_GET['mail_sent_to']), 'notice');
  }
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<script language="javascript" src="load_this/menu.js"></script>
<link rel="stylesheet" type="text/css" href="load_this/style.css">
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
<!-- header //-->
<?php require(FOLDER_RELATIV_INCLUDES . 'load_bigware_9.php'); ?>
<!-- header_eof //-->
<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
  <tr>
    <td width="<?php echo FRAME_WIDTH; ?>" valign="top"></td>
<!-- body_text //-->
    <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">
      <tr>
        <td width="100%" class="smallText"><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageGeneralsign"><?php echo ABOVE_TITLE; ?></td>
            <td class="smallText" align="right"></td>
          </tr>
        </table><?php echo ANMERKUNG; ?></td>
      </tr>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
<?php
  if ( ($_GET['action'] == 'preview') && ($_POST['attendees_email_address'] || $_POST['email_to']) ) {
    switch ($_POST['attendees_email_address']) {
      case '***':
        $mail_sent_to = TEXT_ALL_ATTENDEES;
        break;
      case '**D':
        $mail_sent_to = TEXT_NEWSLETTER_ATTENDEES;
        break;
      default:
        $mail_sent_to = $_POST['attendees_email_address'];
        if ($_POST['email_to']) {
          $mail_sent_to = $_POST['email_to'];
        }
        break;
    }
?>
          <tr><?php echo go_fetch_form('mail', NAME_OF_FILE_GV_MAIL, 'action=send_email_to_user'); ?>
            <td><table border="0" width="100%" cellpadding="0" cellspacing="2">
              <tr>
                <td><?php echo go_fetch_dividing_up('tranparentes.gif', '1', '10'); ?></td>
              </tr>
              <tr>
                <td class="smallText"><b><?php echo TEXT_ATTENDEE; ?></b><br><?php echo $mail_sent_to; ?></td>
              </tr>
              <tr>
                <td><?php echo go_fetch_dividing_up('tranparentes.gif', '1', '10'); ?></td>
              </tr>
              <tr>
                <td class="smallText"><b><?php echo TEXT_FROM; ?></b><br><?php echo isohtmlspecialchars(stripslashes($_POST['from'])); ?></td>
              </tr>
              <tr>
                <td><?php echo go_fetch_dividing_up('tranparentes.gif', '1', '10'); ?></td>
              </tr>
              <tr>
                <td class="smallText"><b><?php echo TEXT_SUBJECT; ?></b><br><?php echo isohtmlspecialchars(stripslashes($_POST['subject'])); ?></td>
              </tr>
              <tr>
                <td><?php echo go_fetch_dividing_up('tranparentes.gif', '1', '10'); ?></td>
              </tr>
              <tr>
                <td class="smallText"><b><?php echo TEXT_AMOUNT; ?></b><br><?php echo nl2br(isohtmlspecialchars(stripslashes($_POST['amount']))); ?></td>
              </tr>
              <tr>
                <td><?php echo go_fetch_dividing_up('tranparentes.gif', '1', '10'); ?></td>
              </tr>
              <tr>
                <td class="smallText"><b><?php echo TEXT_MESSAGE; ?></b><br><?php echo nl2br(isohtmlspecialchars(stripslashes($_POST['message']))); ?></td>
              </tr>
              <tr>
                <td><?php echo go_fetch_dividing_up('tranparentes.gif', '1', '10'); ?></td>
              </tr>
              <tr>
                <td>
<?php
 reset($_POST);
    while (list($key, $value) = each($_POST)) {
      if (!is_array($_POST[$key])) {
        echo go_fetch_hidden_field($key, isohtmlspecialchars(stripslashes($value)));
      }
    }
?>
                <table border="0" width="100%" cellpadding="0" cellspacing="2">
                  <tr>
                    <td><?php echo go_picture_submit('button_back.gif', PICTURE_BACK, 'name="back"'); ?></td>
                    <td align="right"><?php echo '<a href="' . go_href_link(NAME_OF_FILE_GV_MAIL) . '">' . go_picture_button('button_cancel.gif', PICTURE_CANCEL) . '</a> ' . go_picture_submit('button_send_mail.gif', PICTURE_SEND_EMAIL); ?></td>
                  </tr>
                </table></td>
              </tr>
            </table></td>
          </form></tr>
<?php
  } else {
?>
          <tr><?php echo go_fetch_form('mail', NAME_OF_FILE_GV_MAIL, 'action=preview'); ?>
            <td><table border="0" cellpadding="0" cellspacing="2">
              <tr>
                <td colspan="2"><?php echo go_fetch_dividing_up('tranparentes.gif', '1', '10'); ?></td>
              </tr>
<?php
    $attendees = array();
    $attendees[] = array('id' => '', 'text' => TEXT_SELECT_ATTENDEE);
    $attendees[] = array('id' => '***', 'text' => TEXT_ALL_ATTENDEES);
    $attendees[] = array('id' => '**D', 'text' => TEXT_NEWSLETTER_ATTENDEES);
    $mail_query = go_db_query("select attendees_email_address, attendees_firstname, attendees_lastname from " . DB_TBL_ATTENDEES . " order by attendees_lastname");
    while($attendees_values = go_db_fetch_array($mail_query)) {
      $attendees[] = array('id' => $attendees_values['attendees_email_address'],
                           'text' => $attendees_values['attendees_lastname'] . ', ' . $attendees_values['attendees_firstname'] . ' (' . $attendees_values['attendees_email_address'] . ')');
    }
?>
              <tr>
                <td class="main"><?php echo TEXT_ATTENDEE; ?></td>
                <td><?php echo go_fetch_pull_down_menu('attendees_email_address', $attendees, $_GET['attendee']);?></td>
              </tr>
              <tr>
                <td colspan="2"><?php echo go_fetch_dividing_up('tranparentes.gif', '1', '10'); ?></td>
              </tr>
               <tr>
                <td class="smallText"><?php echo TEXT_TO; ?></td>
                <td><?php echo go_fetch_inputfeld('email_to'); ?><?php echo '&nbsp;&nbsp;' . TEXT_SINGLE_EMAIL; ?></td>
              </tr>
              <tr>
                <td colspan="2"><?php echo go_fetch_dividing_up('tranparentes.gif', '1', '10'); ?></td>
              </tr>
             <tr>
                <td class="main"><?php echo TEXT_FROM; ?></td>
                <td><?php echo go_fetch_inputfeld('from', EMAIL_FROM); ?></td>
              </tr>
              <tr>
                <td colspan="2"><?php echo go_fetch_dividing_up('tranparentes.gif', '1', '10'); ?></td>
              </tr>
              <tr>
                <td class="main"><?php echo TEXT_SUBJECT; ?></td>
                <td><?php echo go_fetch_inputfeld('subject'); ?></td>
              </tr>
              <tr>
                <td colspan="2"><?php echo go_fetch_dividing_up('tranparentes.gif', '1', '10'); ?></td>
              </tr>
              <tr>
                <td valign="top" class="main"><?php echo TEXT_AMOUNT; ?></td>
                <td><?php echo go_fetch_inputfeld('amount'); ?></td>
              </tr>
              <tr>
                <td colspan="2"><?php echo go_fetch_dividing_up('tranparentes.gif', '1', '10'); ?></td>
              </tr>
              <tr>
                <td valign="top" class="main"><?php echo TEXT_MESSAGE; ?></td>
                <td><?php echo go_fetch_textarea_field('message', 'soft', '60', '15'); ?></td>
              </tr>
              <tr>
                <td colspan="2"><?php echo go_fetch_dividing_up('tranparentes.gif', '1', '10'); ?></td>
              </tr>
              <tr>
                <td colspan="2" align="right"><?php echo go_picture_submit('button_send_mail.gif', PICTURE_SEND_EMAIL); ?></td>
              </tr>
            </table></td>
          </form></tr>
<?php
  }
?>
<!-- body_text_eof //-->
        </table></td>
      </tr>
    </table></td>
  </tr>
</table>
<!-- body_eof //-->
<!-- footer //-->
<?php require(FOLDER_RELATIV_INCLUDES . 'load_bigware_7.php'); ?>
<!-- footer_eof //-->
<br>
</body>
</html>
<?php require(FOLDER_RELATIV_INCLUDES . 'load_bigware_6.php'); ?>
