<?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']=='confirmrelease' && isset($_GET['gid'])) {
    $gv_query=go_db_query("select release_flag from " . DB_TBL_COUPON_GV_QUEUE . " where unique_id='".$_GET['gid']."'");
    $gv_result=go_db_fetch_array($gv_query);
    if ($gv_result['release_flag']=='N') { 
      $gv_query=go_db_query("select attendee_id, amount from " . DB_TBL_COUPON_GV_QUEUE ." where unique_id='".$_GET['gid']."'");
      if ($gv_resulta=go_db_fetch_array($gv_query)) {
      $gv_amount = $gv_resulta['amount']; 
      $mail_query = go_db_query("select attendees_firstname, attendees_lastname, attendees_email_address from " . DB_TBL_ATTENDEES . " where attendees_id = '" . $gv_resulta['attendee_id'] . "'");
      $mail = go_db_fetch_array($mail_query);
      $message = TEXT_REDEEM_COUPON_MESSAGE_HEADER;
      $message .= sprintf(TEXT_REDEEM_COUPON_MESSAGE_AMOUNT, $currencies->format($gv_amount));
      $message .= TEXT_REDEEM_COUPON_MESSAGE_BODY;
      $message .= TEXT_REDEEM_COUPON_MESSAGE_FOOTER;
      $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'], '', EMAIL_FROM, TEXT_REDEEM_COUPON_SUBJECT );
      $gv_amount=$gv_resulta['amount'];
      $gv_query=go_db_query("select amount from " . DB_TBL_COUPON_GV_ATTENDEE . " where attendee_id='".$gv_resulta['attendee_id']."'");
      $attendee_gv=false;
      $total_gv_amount=0;
      if ($gv_result=go_db_fetch_array($gv_query)) {
        $total_gv_amount=$gv_result['amount'];
        $attendee_gv=true;
      }    
      $total_gv_amount=$total_gv_amount+$gv_amount;
      if ($attendee_gv) {
        $gv_update=go_db_query("update " . DB_TBL_COUPON_GV_ATTENDEE . " set amount='".$total_gv_amount."' where attendee_id='".$gv_resulta['attendee_id']."'");
      } else {
        $gv_insert=go_db_query("insert into " .DB_TBL_COUPON_GV_ATTENDEE . " (attendee_id, amount) values ('".$gv_resulta['attendee_id']."','".$total_gv_amount."')");
      }
        $gv_update=go_db_query("update " . DB_TBL_COUPON_GV_QUEUE . " set release_flag='Y' where unique_id='".$_GET['gid']."'");
      }
    }
  }
?>
<!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="2">
      <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="pageGeneralsign" align="right"><?php echo go_fetch_dividing_up('tranparentes.gif', ABOVE_PICTURE_WIDTH, ABOVE_PICTURE_HEIGHT); ?></td>
          </tr>
        </table><?php echo ANMERKUNG; ?></td>
      </tr>
      <tr>
        <td><table cellpadding="5" border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td valign="top"><table border="0" cellpadding="5" cellspacing="1" style="border-collapse: collapse" width="100%" id="AutoNumber1">
              <tr class="tbUPCountData">
                <td class="tbUPDataInside"><?php echo DB_TBL_ABOVE_ATTENDEES; ?></td>
                <td class="tbUPDataInside" align="center"><?php echo DB_TBL_ABOVE_ORDERS_ID; ?></td>
                <td class="tbUPDataInside" align="right"><?php echo DB_TBL_ABOVE_VOUCHER_VALUE; ?></td>
                <td class="tbUPDataInside" align="right"><?php echo DB_TBL_ABOVE_DATE_PURCHASED; ?></td>
                <td class="tbUPDataInside" align="right"><?php echo DB_TBL_ABOVE_ACTION; ?>&nbsp;</td>
              </tr>
<?php
  $gv_query_raw = "select c.attendees_firstname, c.attendees_lastname, gv.unique_id, gv.date_created, gv.amount, gv.order_id from " . DB_TBL_ATTENDEES . " c, " . DB_TBL_COUPON_GV_QUEUE . " gv where (gv.attendee_id = c.attendees_id and gv.release_flag = 'N')";
  $gv_split = new splitPageResults($_GET['page'], MAX_SHOW_SEARCH_RESULTS, $gv_query_raw, $gv_query_numrows);
  $gv_query = go_db_query($gv_query_raw);
  while ($gv_list = go_db_fetch_array($gv_query)) {
    if (((!$_GET['gid']) || (@$_GET['gid'] == $gv_list['unique_id'])) && (!$gInfo)) {
      $gInfo = new objectInfo($gv_list);
    }
    if ( (is_object($gInfo)) && ($gv_list['unique_id'] == $gInfo->unique_id) ) {
      echo '              <tr class="tbCountDataSelected" onmouseover="this.style.cursor=\'hand\'" onclick="document.location.href=\'' . go_href_link('main_bigware_55.php', go_get_all_get_parameter(array('gid', 'action')) . 'gid=' . $gInfo->unique_id . '&action=change') . '\'">' . "\n";
    } else {
      echo '              <tr class="tbCountData" onmouseover="this.className=\'tbCountDataOver\';this.style.cursor=\'hand\'" onmouseout="this.className=\'tbCountData\'" onclick="document.location.href=\'' . go_href_link('main_bigware_55.php', go_get_all_get_parameter(array('gid', 'action')) . 'gid=' . $gv_list['unique_id']) . '\'">' . "\n";
    }
?>
                <td class="TbInsideData"><?php echo $gv_list['attendees_firstname'] . ' ' . $gv_list['attendees_lastname']; ?></td>
                <td class="TbInsideData" align="center"><?php echo $gv_list['order_id']; ?></td>
                <td class="TbInsideData" align="right"><?php echo $currencies->format($gv_list['amount']); ?></td>
                <td class="TbInsideData" align="right"><?php echo go_datetime_short($gv_list['date_created']); ?></td>
                <td class="TbInsideData" align="right"><?php if ( (is_object($gInfo)) && ($gv_list['unique_id'] == $gInfo->unique_id) ) { echo go_picture(FOLDER_RELATIV_PICTURES . 'icon_arrow_right.gif'); } else { echo '<a href="' . go_href_link(NAME_OF_FILE_GV_QUEUE, 'page=' . $_GET['page'] . '&gid=' . $gv_list['unique_id']) . '">' . go_picture(FOLDER_RELATIV_PICTURES . 'icon_info.gif', PICTURE_ICON_INFO) . '</a>'; } ?>&nbsp;</td>
              </tr>
<?php
  }
?>
              <tr>
                <td colspan="5"><table border="0" width="100%" cellspacing="0" cellpadding="2">
                  <tr>
                    <td class="smallText" valign="top"><?php echo $gv_split->display_count($gv_query_numrows, MAX_SHOW_SEARCH_RESULTS, $_GET['page'], TEXT_SHOW_NUMBER_OF_GIFT_VOUCHERS); ?></td>
                    <td class="smallText" align="right"><?php echo $gv_split->display_links($gv_query_numrows, MAX_SHOW_SEARCH_RESULTS, MAX_SHOW_PAGE_LINKS, $_GET['page']); ?></td>
                  </tr>
                </table></td>
              </tr>
            </table></td>
<?php
  $heading = array();
  $contents = array();
  switch ($_GET['action']) {
    case 'release':
      $heading[] = array('text' => '[' . $gInfo->unique_id . '] ' . go_datetime_short($gInfo->date_created) . ' ' . $currencies->format($gInfo->amount));
      $contents[] = array('align' => 'center', 'text' => '<a href="' . go_href_link('main_bigware_55.php','action=confirmrelease&gid='.$gInfo->unique_id,'NONSSL').'">'.go_picture_button('button_confirm_red.gif', PICTURE_CONFIRM) . '</a> <a href="' . go_href_link('main_bigware_55.php','action=cancel&gid=' . $gInfo->unique_id,'NONSSL') . '">' . go_picture_button('button_cancel.gif', PICTURE_CANCEL) . '</a>');
      break;
    default:
      $heading[] = array('text' => '[' . $gInfo->unique_id . '] ' . go_datetime_short($gInfo->date_created) . ' ' . $currencies->format($gInfo->amount));
      $contents[] = array('align' => 'center','text' => '<a href="' . go_href_link('main_bigware_55.php','action=release&gid=' . $gInfo->unique_id,'NONSSL'). '">' . go_picture_button('button_release.gif', PICTURE_RELEASE) . '</a>');
      break;
   }
  if ( (go_not_null($heading)) && (go_not_null($contents)) ) {
    echo '            <td width="25%" valign="top">' . "\n";
    $frame = new frame;
    echo $frame->infoBox($heading, $contents);
    echo '            </td>' . "\n";
  }
?>
          </tr>
        </table></td>
      </tr>
    </table></td>
<!-- body_text_eof //-->
  </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'); ?>