<?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_this_bigware_10.php'); 
  if (isset($_GET['gv_no'])) {
    $error = true;
    $gv_no = go_db_real_escape_string(stripslashes($_GET['gv_no']));
    $gv_query = go_db_query("select c.coupon_id, c.coupon_amount from " . DB_TBL_COUPONS . " c, " . DB_TBL_COUPON_EMAIL_TRACK . " et where coupon_code = '$gv_no' and c.coupon_id = et.coupon_id");
    if (go_db_num_rows($gv_query) >0) {
      $coupon = go_db_fetch_array($gv_query);
      $redeem_query = go_db_query("select coupon_id from ". DB_TBL_COUPON_REDEEM_TRACK . " where coupon_id = '" . $coupon['coupon_id'] . "'");
      if (go_db_num_rows($redeem_query) == 0 ) { 
        if (!go_session_is_registered('gv_id')) {
          go_session_register('gv_id');
        }
        $gv_id = $coupon['coupon_id'];
        $error = false;
      } else {
        $error = true;
      }
    }
  } else {
    go_forward($GLOBALS[CONFIG_NAME_FILE][main_bigware_29]);
  }
  if ((!$error) && (go_session_is_registered('attendee_id'))) { 
    $gv_query = go_db_query("insert into  " . DB_TBL_COUPON_REDEEM_TRACK . " (coupon_id, attendee_id, redeem_date, redeem_ip) values ('" . $coupon['coupon_id'] . "', '" . $attendee_id . "', now(),'" . $REMOTE_ADDR . "')");
    $gv_update = go_db_query("update " . DB_TBL_COUPONS . " set coupon_active = 'N' where coupon_id = '" . $coupon['coupon_id'] . "'");
    go_gv_member_update($attendee_id, $gv_id);
    go_session_unregister('gv_id');   
  } 
  require(FOLDER_RELATIV_LANGUAGES . $language . '/' . $GLOBALS[CONFIG_NAME_FILE][main_bigware_27]);
    
      if ((go_session_is_registered('attendee_id')) && $voucher_not_redeemed) {
        $gv_id = $coupon['coupon_id'];
        $gv_query = go_db_query("insert into  " . DB_TBL_COUPON_REDEEM_TRACK . " (coupon_id, attendee_id, redeem_date, redeem_ip) values ('" . $coupon['coupon_id'] . "', '" . $attendee_id . "', now(),'" . $REMOTE_ADDR . "')");
        $gv_update = go_db_query("update " . DB_TBL_COUPONS . " set coupon_active = 'N' where coupon_id = '" . $coupon['coupon_id'] . "'");
        go_gv_member_update($attendee_id, $gv_id);
        $error = false;
      } elseif($voucher_not_redeemed) {  
        
        if (!go_session_is_registered('floating_gv_code')) {
            go_session_register('floating_gv_code'); 
          $floating_gv_code = $_GET['gv_no'];
          $gv_error_message = TEXT_NEEDS_TO_LOGIN;
      } else {
        $gv_error_message = TEXT_INVALID_GV;
     }
    } else {
      $gv_error_message = TEXT_INVALID_GV;
    }  
       
  $message = $gv_error_message; 
  
  
    
        if (go_session_is_registered('floating_gv_code')) {
          $gv_query = go_db_query("SELECT c.coupon_id, c.coupon_amount, IF(rt.coupon_id>0, 'true', 'false') AS redeemed FROM ((". DB_TBL_COUPONS ." c) LEFT JOIN ". DB_TBL_COUPON_REDEEM_TRACK." rt USING(coupon_id), ". DB_TBL_COUPON_EMAIL_TRACK ." et) WHERE c.coupon_code = '". $floating_gv_code ."' AND c.coupon_id = et.coupon_id"); 
          if (go_db_num_rows($gv_query) >0) {
            $coupon = go_db_fetch_array($gv_query); 
            if($coupon['coupon_id']>0 && $coupon['redeemed'] == 'false') {
              go_session_unregister('floating_gv_code');
              $gv_query = go_db_query("insert into  " . DB_TBL_COUPON_REDEEM_TRACK . " (coupon_id, attendee_id, redeem_date, redeem_ip) values ('" . $coupon['coupon_id'] . "', '" . $attendee_id . "', now(),'" . $REMOTE_ADDR . "')");
              $gv_update = go_db_query("update " . DB_TBL_COUPONS . " set coupon_active = 'N' where coupon_id = '" . $coupon['coupon_id'] . "'");
              go_gv_member_update($attendee_id, $coupon['coupon_id']);
            }
          }
        } 
    
      if (go_session_is_registered('floating_gv_code')) {
        $gv_query = go_db_query("SELECT c.coupon_id, c.coupon_amount, IF(rt.coupon_id>0, 'true', 'false') AS redeemed FROM ((". DB_TBL_COUPONS ." c) LEFT JOIN ". DB_TBL_COUPON_REDEEM_TRACK." rt USING(coupon_id), ". DB_TBL_COUPON_EMAIL_TRACK ." et) WHERE c.coupon_code = '". $floating_gv_code ."' AND c.coupon_id = et.coupon_id"); 
        if (go_db_num_rows($gv_query) >0) {
          $coupon = go_db_fetch_array($gv_query); 
          if($coupon['coupon_id']>0 && $coupon['redeemed'] == 'false') {
              go_session_unregister('floating_gv_code');
              $gv_query = go_db_query("insert into  " . DB_TBL_COUPON_REDEEM_TRACK . " (coupon_id, attendee_id, redeem_date, redeem_ip) values ('" . $coupon['coupon_id'] . "', '" . $attendee_id . "', now(),'" . $REMOTE_ADDR . "')");
              $gv_update = go_db_query("update " . DB_TBL_COUPONS . " set coupon_active = 'N' where coupon_id = '" . $coupon['coupon_id'] . "'");
              go_gv_member_update($attendee_id, $coupon['coupon_id']);
          }
        }
      }
  
define('TEXT_NEEDS_TO_LOGIN', 'We are sorry but we are unable to process your Gift Voucher claim at this time. You need to login first or create an member with us, if you don\'t already have one, before you can claim your Gift Voucher. Please <a href="' . go_href_link($GLOBALS[CONFIG_NAME_FILE][main_bigware_40],'','SSL').'">click here to login or create an member.</a> ');
    
  $breadcrumb->add(NAVBAR_TITLE); 
  $content = $GLOBALS[CONFIG_SHOW_FILE][main_bigware_27];
  require(FOLDER_RELATIV_TEMPLATES . TEMPLATENAME_MAIN_PAGE);
  
  require(FOLDER_RELATIV_INCLUDES . 'load_this_bigware_3.php'); ?>
?>
