<?php
/*
  $Id: checkout_success.php,v 1.6 2003/02/15 21:01:06 wilt Exp $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2002 osCommerce

  Released under the GNU General Public License
*/

  require('includes/application_top.php');
// if the customer is not logged on, redirect them to the shopping cart page
  if (!tep_session_is_registered('customer_id')) {
    tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));
  }


  if ($HTTP_GET_VARS['action'] == 'update') {

    $notify_string = '';
    if (tep_session_is_registered('customer_id')) {
      $notify_string .= 'action=notify&';
      $notify = $HTTP_POST_VARS['notify'];
      if (!is_array($notify)) $notify = array($notify);
      for ($i=0, $n=sizeof($notify); $i<$n; $i++) {
        $notify_string .= 'notify[]=' . $notify[$i] . '&';
      }
      if (strlen($notify_string) > 0) $notify_string = substr($notify_string, 0, -1);
    }

    tep_redirect(tep_href_link(FILENAME_DEFAULT, $notify_string, 'SSL'));
  }

  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_CHECKOUT_SUCCESS);
  $paypalipn_query = tep_db_query("select o.orders_status,p.* from " . TABLE_ORDERS . " o LEFT JOIN paypalipn_txn p on p.item_number = o.orders_id AND o.customers_id = '" . $customer_id . "' order by o.date_purchased desc limit 1");
  $paypalipn = tep_db_fetch_array($paypalipn_query);

  if ($paypalipn['ipn_result']=='VERIFIED') {
    if ($paypalipn['payment_status']=='Completed') {
      $NAVBAR_TITLE_2 = PAYPAL_NAVBAR_TITLE_2_OK;
      $HEADING_TITLE = PAYPAL_HEADING_TITLE_OK;
      $TEXT_SUCCESS = PAYPAL_TEXT_SUCCESS_OK;
    } else if ($paypalipn['payment_status']=='Pending') {
      $NAVBAR_TITLE_2 = PAYPAL_NAVBAR_TITLE_2_PENDING;
      $HEADING_TITLE = PAYPAL_HEADING_TITLE_PENDING;
      $TEXT_SUCCESS = PAYPAL_TEXT_SUCCESS_PENDING;
    };
    $cart->reset(TRUE);
  } else if ($paypalipn['ipn_result']=='INVALID') {
    $NAVBAR_TITLE_2 = PAYPAL_NAVBAR_TITLE_2_FAILED;
    $HEADING_TITLE = PAYPAL_HEADING_TITLE_FAILED;
    $TEXT_SUCCESS = PAYPAL_TEXT_SUCCESS_FAILED;
  } else if ($paypalipn['orders_status']==99999) {
      $NAVBAR_TITLE_2 = PAYPAL_NAVBAR_TITLE_2_PENDING;
      $HEADING_TITLE = PAYPAL_HEADING_TITLE_PENDING;
      $TEXT_SUCCESS = PAYPAL_TEXT_SUCCESS_PENDING;
  } else {
    $NAVBAR_TITLE_2 = NAVBAR_TITLE_2;
    $HEADING_TITLE = HEADING_TITLE;
    $TEXT_SUCCESS = TEXT_SUCCESS;
  };

  $breadcrumb->add($NAVBAR_TITLE_1);
  $breadcrumb->add($NAVBAR_TITLE_2);

  if (tep_session_is_registered('customer_id')) {
    $global_query = tep_db_query("select global_product_notifications from " . TABLE_CUSTOMERS_INFO . " where customers_info_id = '" . $customer_id . "'");
    $global = tep_db_fetch_array($global_query);

    if ($global['global_product_notifications'] != '1') {
      $orders_query = tep_db_query("select orders_id from " . TABLE_ORDERS . " where customers_id = '" . $customer_id . "' order by date_purchased desc limit 1");
      $orders = tep_db_fetch_array($orders_query);

      $products_array = array();
      $products_query = tep_db_query("select products_id, products_name from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . $orders['orders_id'] . "' order by products_name");
      while ($products = tep_db_fetch_array($products_query)) {
        $products_array[] = array('id' => $products['products_id'],
                                  'text' => $products['products_name']);
      }
    }
  }
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<LINK href="images/favicon.ico" rel="shortcut icon">
<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="780" cellspacing="0" cellpadding="0">
  <tr>
    <td width="186" valign="top" background="images/tableback.gif"><table border="0" width="186" 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"><form name="order" <?php echo 'action="' . tep_href_link(FILENAME_CHECKOUT_SUCCESS, 'action=update', 'SSL') . '"'; ?> method="post"><table border="0" width="100%" cellspacing="0" cellpadding="0">
    <TR>
<TD><br>
                <table border="0" cellpadding="0" cellspacing="5">
        <!--DWLayoutTable-->
        <tr>
          <TD height="4" COLSPAN=3 valign="top"> <IMG SRC="images/product info/template1_03.gif" WIDTH=424 HEIGHT=4 ALT=""></TD>
        </tr>
        <tr>
          <TD width="21" height="18" valign="top"> <IMG SRC="images/product info/template1_05.gif" WIDTH=21 HEIGHT=18 ALT=""></TD>
          <TD width="383" valign="top" background="images/product info/template1_06.gif" ALT="" class="productinfo"><?php echo HEADING_TITLE; ?></TD>
          <TD width="20" valign="top"> <IMG SRC="images/product info/template1_07.gif" WIDTH=20 HEIGHT=18 ALT=""></TD>
        </tr>
        <tr>
          <TD height="7" COLSPAN=3 valign="top"> <IMG SRC="images/product info/template1_08.gif" WIDTH=424 HEIGHT=7 ALT=""></TD>
        </tr>
      </table></td></tr>
      <tr>
        <td><table border="0" width="450" cellspacing="4" cellpadding="2">
          <tr>

            <td valign="top" class="main"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?><div align="center" class="pageHeading"></div></td></tr>
              </table></td>
      </tr>
            <TR>
            <TD class=main>
                    <TABLE cellSpacing=0 cellPadding=0 width=450 align=left
                        border=0>
                    <TBODY>
                    <TR>
                    <TD vAlign=top width=7 rowSpan=4></TD>
                    <TD vAlign=top width=495 colSpan=3 height=8></TD></TR>
                    <TR>
                    <TD vAlign=top width=5></TD>
                    <TD width=484>
                        <TABLE cellSpacing=0 cellPadding=2
                              width="100%" border=0 class="contents">
                        <TBODY>
                        <TR>
                        <TD class=main>
                           <TABLE cellSpacing=0 cellPadding=2 border=0 width="100%">
                           <TBODY>
                           <TR>
                           <TD class=main>
                           <tr><td valign="top" class="main">
            <br><?php echo TEXT_SUCCESS; ?><br><br>
<?php
  if (tep_session_is_registered('customer_id')) {
    if ($global['global_product_notifications'] != '1') {
      echo TEXT_NOTIFY_PRODUCTS . '<br><p class="productsNotifications">';
       $products_displayed = array();
         for ($i=0, $n=sizeof($products_array); $i<$n; $i++) {
           if (!in_array($products_array[$i]['id'], $products_displayed)) {
        echo tep_draw_checkbox_field('notify[]', $products_array[$i]['id']) . ' ' . $products_array[$i]['text'] . '<br>';
  $products_displayed[] = $products_array[$i]['id'];
    }
      }
      echo '</p>';
    } else {
      echo TEXT_SEE_ORDERS . '<br><br>' . TEXT_CONTACT_STORE_OWNER;
    }
  }
?>
            <h4><?php echo TEXT_THANKS_FOR_SHOPPING; ?></h4></td>
          </tr>

      </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD>

                            <TD vAlign=top width=6></TD>
                        <TR>
                            <TD vAlign=top width=495 colSpan=3 height=18></TD></TR>
                              </TBODY></TABLE></TD></TR>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
<?php require('add_checkout_success.php'); //ORDER TOTAL CLASS/GV SYSTEM ?>
      <tr>
        <td align="right" class="main" width="500"><?php echo tep_image_submit('button_continue.gif', IMAGE_BUTTON_CONTINUE); ?></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="0">
          <tr>
            <td width="25%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
              <tr>
                <td width="50%"><?php echo tep_draw_separator('pixel_silver.gif', '1', '5'); ?></td>
                <td width="50%" align="right"><?php echo tep_draw_separator('pixel_silver.gif', '100%', '1'); ?></td>
              </tr>
            </table></td>
            <td width="25%"><?php echo tep_draw_separator('pixel_silver.gif', '100%', '1'); ?></td>
            <td width="25%"><?php echo tep_draw_separator('pixel_silver.gif', '100%', '1'); ?></td>
            <td width="25%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
              <tr>
                <td width="50%"><?php echo tep_draw_separator('pixel_silver.gif', '100%', '1'); ?></td>
                <td width="50%"><?php echo tep_image(DIR_WS_IMAGES . 'checkout_bullet.gif'); ?></td>
              </tr>
            </table></td>
          </tr>
          <tr>
            <td align="center" width="25%" class="checkoutBarFrom"><?php echo CHECKOUT_BAR_DELIVERY; ?></td>
            <td align="center" width="25%" class="checkoutBarFrom"><?php echo CHECKOUT_BAR_PAYMENT; ?></td>
            <td align="center" width="25%" class="checkoutBarFrom"><?php echo CHECKOUT_BAR_CONFIRMATION; ?></td>
            <td align="center" width="25%" class="checkoutBarCurrent"><?php echo CHECKOUT_BAR_FINISHED; ?></td>
          </tr>
        </table></td>
      </tr>
<?php if (DOWNLOAD_ENABLED == 'true') include(DIR_WS_MODULES . 'downloads.php'); ?>
    </table></form></td>
<!-- body_text_eof //-->
    <td width="138" valign="top" background="images/tableback1.gif"><table border="0" width="138" 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 //-->

</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>