<?php
/*
  $Id: gv_redeem_process.php,v 1.1.1.1 2002/11/28 23:21:27 wilt Exp $

  The Exchange Project - Community Made Shopping!
  http://www.theexchangeproject.org

  Gift Voucher System v1.0
  Copyright (c) 2001,2002 Ian C Wilson
  http://www.phesis.org

  Released under the GNU General Public License
*/

  require('includes/application_top.php');

// Check if gv_no has been set
  if (!tep_session_is_registered('gv_no')) {
    tep_redirect(tep_href_link(FILENAME_DEFAULT));
  }
// validate again - just in case - paranoia 
    $gv_query=tep_db_query("select gv_amount from ".TABLE_GV_TRACKING." where gv_number='".$gv_no."' and redeem_flag='N'");
    if (tep_db_num_rows($gv_query)==0) {
      tep_redirect(tep_href_link(FILENAME_GV_REDEEM));
    }
// ok success - save the amount - and update the tracking file
  $gv_result=tep_db_fetch_array($gv_query);
  $gv_amount = $gv_result['gv_amount'];
// Things to set
// ip address of claimant
// customer id of claimant
// date 
// redemption flag
  $gv_query=tep_db_query("update ".TABLE_GV_TRACKING." set redeem_flag='Y', ip_address='".$REMOTE_ADDR."', customer_id_redeem='".$customer_id."',date_redeemed=NOW() where gv_number='".$gv_no."'");
// now update customer account with gv_amount
   $gv_query=tep_db_query("select amount from gv_customer where customer_id='".$customer_id."'");
   $customer_gv=false;
   $total_gv_amount=$gv_amount;;
   if ($gv_result=tep_db_fetch_array($gv_query)) {
    $total_gv_amount=$gv_result['amount']+$gv_amount;
    $customer_gv=true;
   }
   if ($customer_gv) {
      // already has gv_amount so update
      $gv_update=tep_db_query("update gv_customer set amount='".$total_gv_amount."' where customer_id='".$customer_id."'");
    } else {
      // no gv_amount so insert
      $gv_insert=tep_db_query("insert into gv_customer (customer_id, amount) values ('".$customer_id."','".$total_gv_amount."')");
    }
    tep_session_unregister('gv_no');
  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_GV_REDEEM_PROCESS);

  $breadcrumb->add(NAVBAR_TITLE_1); 


?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<script language="javascript" src="includes/swapimage.js"></script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<?php
// BOF: WebMakers.com Changed: Header Tag Controller v1.0
// Replaced by header_tags.php
if ( file_exists(DIR_WS_INCLUDES . 'header_tags.php') ) {
  require(DIR_WS_INCLUDES . 'header_tags.php');
} else {
?> 
  <title><?php echo TITLE ?></title>
<?php
}
// EOF: WebMakers.com Changed: Header Tag Controller v1.0
?>
<base href="<?php echo (getenv('HTTPS') == 'on' ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">
<link rel="stylesheet" type="text/css" href="<? echo THEMA_STYLE;?>">
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
<table border="0" width="100%" cellspacing="3" cellpadding="3">
  <tr>
    <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
<!-- left_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
<!-- left_navigation_eof //-->
    </table></td>
<!-- body_text //-->
    <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">
      <tr>
        <td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
            <td align="right"><?php echo tep_image(DIR_WS_IMAGES . 'table_background_specials.gif', HEADING_TITLE, HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
      <tr>
        <td class="main"><?php echo tep_image(DIR_WS_IMAGES . 'table_background_man_on_board.gif', HEADING_TITLE, '0', '0', 'align="left"') . TEXT_SUCCESS; ?></td>
      </tr>
      <tr>
        <td align="right"><br><a href="<?php echo tep_href_link(FILENAME_DEFAULT, '', 'NONSSL'); ?>"><?php echo tep_image_button('button_continue.gif', IMAGE_BUTTON_CONTINUE); ?></a></td>
      </tr>

    </table></td>
<!-- body_text_eof //-->
    <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
<!-- right_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_right.php'); ?>
<!-- right_navigation_eof //-->
    </table></td>
  </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
<br>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
