<?php
/*
  $Id: gv_redeem.php,v 1.1.1.1 2002/11/28 23:21:30 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 for required session variables
  if (!tep_session_is_registered('gv_no')) {
    tep_session_register('gv_no');
    $gv_no='a';
  }
// if gv number passed in url force login and save it to session variable for later.
// must be an easier way to do this
  if ($gv_no=='a') {
  if (isset($HTTP_GET_VARS['gv_no'])) {
      $gv_no=$HTTP_GET_VARS['gv_no'];
      tep_session_unregister('customer_id');
      tep_session_unregister('customer_country_id');
      tep_session_unregister('customer_zone_id');
      $navigation->set_snapshot();
      tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
  }
  }
  if ($gv_no=='a') $gv_no='';

// and possibly from form post
  if (isset($HTTP_POST_VARS['gv_no'])) {
    $gv_no=$HTTP_POST_VARS['gv_no'];
  }
// Check if user is logged in
 if (!tep_session_is_registered('customer_id')) {
    $navigation->set_snapshot();
    tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
  }
// check for a voucher number in the url or returned here from login with session variable 
  if (isset($gv_no)) {
    $gv_result=true;
    $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_PROCESS));
    } 
  }
  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_GV_REDEEM);

  $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><table border="0" width="100%" cellspacing="0" cellpadding="2">
          <tr>
            <td class="main"><?php echo TEXT_INFORMATION; ?></td>
          </tr>
<?php
// if we get here then either the url gv_no was not set or it was invalid
// so output a message and give user the chance to enter the voucher number
  $message = TEXT_ENTER_GV;
  if (isset($gv_no)) {
    $message = TEXT_INVALID_GV;
  }
?>
          <tr>
            <td class="main"><?php echo $message; ?></td>
          </tr>
          <form method="post" action="<?php echo tep_href_link(FILENAME_GV_REDEEM);?>">
          <tr>
            <td align="center" class="main">
            <?php echo tep_draw_input_field('gv_no');?></td>
          </tr>
          <tr>
            <td align="center" class="main">
            <?php echo tep_image_submit('button_continue.gif',IMAGE_BUTTON_CONTINUE);?></td>
          </tr>
          </form>
        </table></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'); ?>
