<?php
/*
  $Id: send_gv.php,v 1.1.1.1 2002/11/28 23:21:29 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');

  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_SEND_GV);

  $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><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_contact_us.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>
  <?php
  if ($HTTP_GET_VARS['action'] == 'send') {
  // validate entries
  $error = false;
  if (!tep_validate_email(trim($HTTP_POST_VARS['email']))) {
    $error = true;
    $error_email = ENTRY_EMAIL_ADDRESS_CHECK_ERROR;
  }
  $gv_query = tep_db_query("select amount from gv_customer where customer_id='".$customer_id."'");
  $gv_result = tep_db_fetch_array($gv_query);
  $customer_amount=$gv_result['amount'];
  $gv_amount=trim($HTTP_POST_VARS['amount']);
  if (ereg('[^0-9/.]',$gv_amount)) {
    $error=true; 
    $error_amount = ENTRY_AMOUNT_CHECK_ERROR;
  }
  if ($gv_amount>$customer_amount || $gv_amount==0) {
  $error=true; 
  $error_amount = ENTRY_AMOUNT_CHECK_ERROR;
  }
  if (!$error) {
$gv_amount = (double) $gv_amount;
$gv_query = tep_db_query("select customers_firstname, customers_lastname from ".TABLE_CUSTOMERS." where customers_id='".$customer_id."'");
$gv_result=tep_db_fetch_array($gv_query);
$send_name = $gv_result['customers_firstname'].' '.$gv_result['customers_lastname'];
?>
      <tr>
        <td><form action="<?php echo tep_href_link('send_gv_process.php', '', 'NONSSL'); ?>" method="post"><table border="0" width="100%" cellspacing="0" cellpadding="2">
          <tr>
            <td class="main"><?php echo sprintf(MAIN_MESSAGE,$currencies->format($HTTP_POST_VARS['amount']),$HTTP_POST_VARS['name'],$HTTP_POST_VARS['email'],$HTTP_POST_VARS['name'],$currencies->format($HTTP_POST_VARS['amount']),$send_name); ?></td>
          </tr>
<?php
if ($HTTP_POST_VARS['message']) {
?>
           <tr>
            <td class="main"><?php echo sprintf(PERSONAL_MESSAGE, $gv_result['customers_firstname']); ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo $HTTP_POST_VARS['message']; ?></td>
          </tr>
<?php
}
?>
          <tr>
      
<?php
echo tep_draw_hidden_field('send_name', $send_name)
    .tep_draw_hidden_field('to_name', $HTTP_POST_VARS['name']) 
    .tep_draw_hidden_field('email', $HTTP_POST_VARS['email'])
    .tep_draw_hidden_field('amount', $gv_amount)
    .tep_draw_hidden_field('message', $HTTP_POST_VARS['message']);
?>
            <td align="right"><br><?php echo tep_image_submit('button_send.gif', IMAGE_BUTTON_CONTINUE); ?></td>
          </tr>
        </table></form></td>
      </tr>
<?php
  }
}
?>
      <tr>
        <td><?php echo HEADING_TEXT; ?></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
      <tr>
        <td><form action="<?php echo tep_href_link('send_gv.php', 'action=send', 'NONSSL'); ?>" method="post"><table border="0" width="100%" cellspacing="0" cellpadding="2">
          <tr>
            <td class="main"><?php echo ENTRY_NAME; ?><br><?php echo tep_draw_input_field('name', $HTTP_POST_VARS['name']);?></td>
          </tr>
          <tr>
            <td class="main"><?php echo ENTRY_EMAIL; ?><br><?php echo tep_draw_input_field('email', $HTTP_POST_VARS['email']); if ($error) echo $error_email; ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo ENTRY_AMOUNT; ?><br><?php echo tep_draw_input_field('amount', $gv_amount,'','',false); if ($error) echo $error_amount; ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo ENTRY_MESSAGE; ?><br><?php echo tep_draw_textarea_field('message', 'soft', 40, 4, $HTTP_POST_VARS['message']); ?></td>
          </tr>
          <tr>
            <td class="main" align="right"><br><?php echo tep_image_submit('button_confirm.gif', IMAGE_BUTTON_CONTINUE); ?></td>
          </tr>
        </table></form></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'); ?>
