<?php
/*
	osCommerce, Open Source E-Commerce Solutions 
	http://www.oscommerce.com 
	
	Copyright (c) 2003 osCommerce 

	osConcert, Online Seat Booking 
  	https://www.osconcert.com

  	Copyright (c) 2026 osConcert

	Released under the GNU General Public License
*/

// Set flag that this is a parent file
  define( '_FEXEC', 1 );
	
  require('includes/application_top.php');
  require(DIR_WS_CLASSES . 'order.php');	
	
	
// if the customer is not logged on, redirect them to the shopping cart page
  if (!$FSESSION->is_registered('customer_id')) 
  {
    tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));
  }
	$order_id = tep_db_prepare_input($FREQUEST->getvalue('order_id','int',0));
	
	if(!is_numeric($order_id) || $order_id == 0)
	{
		tep_redirect(tep_href_link(FILENAME_DEFAULT));
	}
	$customer_number_query = tep_db_query("select customers_id from " . TABLE_ORDERS . " where orders_id = '". tep_db_input(tep_db_prepare_input($order_id)) . "'");
	$customer_number = tep_db_fetch_array($customer_number_query);

	if ($customer_number['customers_id'] != $FSESSION->customer_id) 
	{
		tep_redirect(tep_href_link(FILENAME_DEFAULT));
	}
	
	tep_verify_coupons($order_id );
  require(DIR_WS_LANGUAGES . $FSESSION->language . '/' . FILENAME_CHECKOUT_SUCCESS);
	
  $payment=tep_db_prepare_input($FREQUEST->getvalue('payment'));
 
		
		$orders_query = tep_db_query("select * from " . TABLE_ORDERS . " where customers_id = '" . (int)$FSESSION->customer_id . "' order by date_purchased desc limit 1");
		$orders = tep_db_fetch_array($orders_query);
		
		$customers_name=$orders['customers_name'];
		$billing_name=$orders['billing_name'];
		//$orders['customers_email_address'];
		//$orders['payment_method'];
		//$orders['date_purchased'];
		//$orders['shipping_method'];
		
		$products_array = array();
		$products_query = tep_db_query("select * from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$orders['orders_id'] . "' order by products_model,products_id");
		while ($products = tep_db_fetch_array($products_query)) {

			$products_array[] = array(	'id' => $products['products_id'],
										'qty' => $products['products_quantity'],
										'price' => $products['final_price'],
										'seat' => $products['products_name'],
										'date' => $products['products_model'],
										'type' => $products['events_type'],
										'sku' => $products['products_sku'],
										'categories_name' => $products['categories_name'],
										'concert_date' => $products['concert_date'],
										'concert_venue' => $products['concert_venue'],
										'concert_time' => $products['concert_time'],
										'is_printable' => $products['is_printable'],
										'events_id' => $products['events_id'],
										);
		}


	
	$order_total_query=tep_db_query("select value from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$orders['orders_id'] . "' and class='ot_total'");
	$order_total_result=tep_db_fetch_array($order_total_query);
	$order_total_amount=substr($order_total_result['value'],0, -2);

	
	// if (CR_ACTIVE=="True"){$order=$_GET['order_id'];
	// include("cr_dbadd.php");}
	
	$check_customer_query = tep_db_query("select guest_account from " . TABLE_CUSTOMERS . " where customers_id = '" . (int)$FSESSION->customer_id . "'");
      $check_customer = tep_db_fetch_array($check_customer_query);
	  $guest=$check_customer['guest_account'];
	  
	//unset PWA cookie
	if ($_COOKIE['customer_is_guest'])
	{
	setcookie ("customer_is_guest", "", time() - 2592000);
	}
	
	$breadcrumb->add(NAVBAR_TITLE_1);
  $breadcrumb->add(NAVBAR_TITLE_2);
	
  $content = CONTENT_CHECKOUT_SUCCESS;
  //$javascript = 'popup_window.js';
  require(DIR_WS_TEMPLATES . TEMPLATE_NAME . '/' . TEMPLATENAME_MAIN_PAGE);
  
   //if ((PWA_LOGOFF=='true')&&($guest==1)) {
   if ($guest==1){

  // Allow guest to download ICS for this order after logout
  $FSESSION->set('guest_last_order_id', (int)$orders['orders_id']);

  $cart->reset(true);

  $FSESSION->set('temp_customer_id', $_SESSION['customer_id']);
  $FSESSION->remove('customer_id');
		 $FSESSION->remove('customer_default_address_id');
		 $FSESSION->remove('customer_first_name');
		 $FSESSION->remove('customer_country_id');
		 $FSESSION->remove('customer_zone_id');
		 $FSESSION->remove('comments');
		 if ($FSESSION->is_registered("customer_auto_name"))
		 $FSESSION->remove('customer_auto_name');
		// ICW - logout -> unregister GIFT VOUCHER sessions - Thanks Fredrik
		 $FSESSION->remove('gv_id');
		 $FSESSION->remove('cc_id');
		 }//end customer is guest

//echo '<pre>';
//print_r($_SESSION);
  require(DIR_WS_INCLUDES . 'application_bottom.php');
  

?>
