<?php
/*
  $Id: checkout_confirmation.php,v 1.2 2003/09/24 15:34:25 wilt Exp $

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

  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License
*/

  require('includes/application_top.php');

   if (preg_match('/alternative/i',strtolower($_SERVER['HTTP_REFERER']))){
                 foreach ($_SESSION as $key => $val) {
                  //print $key.' => '.$val.' - ';print_r($val);echo "<br>";
                  $_POST[$key] = $val;
                  }
   }

$cot_gv = $_POST['cot_gv'];

// if the customer is not logged on, redirect them to the login page
  if (!tep_session_is_registered('customer_id')) {
    $navigation->set_snapshot(array('mode' => 'SSL', 'page' => FILENAME_CHECKOUT_PAYMENT));
    tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
  }

// if there is nothing in the customers cart, redirect them to the shopping cart page
  if ($cart->count_contents() < 1) {
    tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));
  }

// avoid hack attempts during the checkout procedure by checking the internal cartID
  if (isset($cart->cartID) && tep_session_is_registered('cartID')) {
    if ($cart->cartID != $cartID) {
      tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
    }
  }

// if no shipping method has been selected, redirect the customer to the shipping method selection page
  if (!tep_session_is_registered('shipping')) {
    tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
  }

  if (!tep_session_is_registered('payment')) tep_session_register('payment');
  if (isset($_POST['payment'])) $payment = $_POST['payment'];

  if (!tep_session_is_registered('comments')) tep_session_register('comments');
  if (tep_not_null($_POST['comments'])) {
    $comments = tep_db_prepare_input($_POST['comments']);
  }

if (!isset($_SESSION['kvit_name'])) $_SESSION['kvit_name'] = $_POST['kvit_name'];
if (!isset($_SESSION['kvit_address'])) $_SESSION['kvit_address'] = $_POST['kvit_address'];

if (!isset($_SESSION['qiwi_telephone'])) $_SESSION['qiwi_telephone'] = $_POST['qiwi_telephone'];
if (!isset($_SESSION['aviso_telephone'])) $_SESSION['aviso_telephone'] = $_POST['aviso_telephone'];

if (!isset($_SESSION['s_name'])) $_SESSION['s_name'] = $_POST['s_name'];
if (!isset($_SESSION['s_inn'])) $_SESSION['s_inn'] = $_POST['s_inn'];
if (!isset($_SESSION['s_kpp'])) $_SESSION['s_kpp'] = $_POST['s_kpp'];
if (!isset($_SESSION['s_ogrn'])) $_SESSION['s_ogrn'] = $_POST['s_ogrn'];
if (!isset($_SESSION['s_okpo'])) $_SESSION['s_okpo'] = $_POST['s_okpo'];
if (!isset($_SESSION['s_rs'])) $_SESSION['s_rs'] = $_POST['s_rs'];
if (!isset($_SESSION['s_bank_name'])) $_SESSION['s_bank_name'] = $_POST['s_bank_name'];
if (!isset($_SESSION['s_bik'])) $_SESSION['s_bik'] = $_POST['s_bik'];
if (!isset($_SESSION['s_ks'])) $_SESSION['s_ks'] = $_POST['s_ks'];
if (!isset($_SESSION['s_address'])) $_SESSION['s_address'] = $_POST['s_address'];
if (!isset($_SESSION['s_yur_address'])) $_SESSION['s_yur_address'] = $_POST['s_yur_address'];
if (!isset($_SESSION['s_fakt_address'])) $_SESSION['s_fakt_address'] = $_POST['s_fakt_address'];
if (!isset($_SESSION['s_telephone'])) $_SESSION['s_telephone'] = $_POST['s_telephone'];
if (!isset($_SESSION['s_fax'])) $_SESSION['s_fax'] = $_POST['s_fax'];
if (!isset($_SESSION['s_email'])) $_SESSION['s_email'] = $_POST['s_email'];
if (!isset($_SESSION['s_director'])) $_SESSION['s_director'] = $_POST['s_director'];
if (!isset($_SESSION['s_accountant'])) $_SESSION['s_accountant'] = $_POST['s_accountant'];

// load the selected payment module
  require(DIR_WS_CLASSES . 'payment.php');
//  if ($credit_covers) $payment=''; //ICW added for CREDIT CLASS
  $payment_modules = new payment($payment);
//ICW ADDED FOR CREDIT CLASS SYSTEM
  require(DIR_WS_CLASSES . 'order_total.php');

  require(DIR_WS_CLASSES . 'order.php');
  $order = new order;

  $payment_modules->update_status();
//ICW ADDED FOR CREDIT CLASS SYSTEM
  $order_total_modules = new order_total;
//ICW ADDED FOR CREDIT CLASS SYSTEM
  $order_total_modules->collect_posts();
//ICW ADDED FOR CREDIT CLASS SYSTEM
  $order_total_modules->pre_confirmation_check();

// ICW CREDIT CLASS Amended Line
//  if ( ( is_array($payment_modules->modules) && (sizeof($payment_modules->modules) > 1) && !is_object($$payment) ) || (is_object($$payment) && ($$payment->enabled == false)) ) {
  if ( (is_array($payment_modules->modules)) && (sizeof($payment_modules->modules) > 1) && (!is_object($$payment)) && (!$credit_covers) ) {
    tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode(ERROR_NO_PAYMENT_MODULE_SELECTED), 'SSL'));
  }

  if (is_array($payment_modules->modules)) {
    $payment_modules->pre_confirmation_check();
  }

// load the selected shipping module
  require(DIR_WS_CLASSES . 'shipping.php');
  $shipping_modules = new shipping($shipping);
//ICW Credit class amendment Lines below repositioned
//  require(DIR_WS_CLASSES . 'order_total.php');
//  $order_total_modules = new order_total;

// Stock Check
  $any_out_of_stock = false;
  if (STOCK_CHECK == 'true') {
    for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
      if (tep_check_stock($order->products[$i]['id'], $order->products[$i]['qty'])) {
        $any_out_of_stock = true;
      }
    }
    // Out of Stock
    if ( (STOCK_ALLOW_CHECKOUT != 'true') && ($any_out_of_stock == true) ) {
      tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));
    }
  }

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

  $breadcrumb->add(NAVBAR_TITLE_1, tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
  $breadcrumb->add(NAVBAR_TITLE_2);

  $content = CONTENT_CHECKOUT_CONFIRMATION;

  require(DIR_WS_TEMPLATES . TEMPLATE_NAME . '/' . TEMPLATENAME_MAIN_PAGE);

  require(DIR_WS_INCLUDES . 'application_bottom.php');
?>
