<?php
/*
	osCommerce, Open Source E-Commerce Solutions 
	http://www.oscommerce.com 
	
	Copyright (c) 2003 osCommerce 
	
	 
	
	Freeway eCommerce 
	http://www.openfreeway.org
	Copyright (c) 2007 ZacWare
	
	osConcert, Online Seat Booking 
  	http://www.osconcert.com

  	Copyright (c) 2009-2013 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));
  }
	//attempted access by non BoxOffice
if(!$_SESSION['customer_country_id']==999 ){exit('..');}

	$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));
	}

	
  if ($FREQUEST->getvalue('action') == 'update') {}

  require(DIR_WS_LANGUAGES . $FSESSION->language . '/bor_checkout_success.php');

  $breadcrumb->add(NAVBAR_TITLE_1);
  //cartzone graeme
  $paypalorderno='';//clear order number
  $paypalipn_query = tep_db_query("select o.orders_status,p.* from " . TABLE_ORDERS . " o LEFT JOIN " . TABLE_PAYPALIPN_TXN . " p on p.item_number = o.orders_id AND o.customers_id = '" . (int)$FSESSION->customer_id . "' order by o.date_purchased desc limit 1");
  $paypalipn = tep_db_fetch_array($paypalipn_query);


    $NAVBAR_TITLE_2 = NAVBAR_TITLE_2; 
    $HEADING_TITLE = HEADING_TITLE; 
    $TEXT_SUCCESS = TEXT_SUCCESS; 
 
  $breadcrumb->add($NAVBAR_TITLE_2);
	
  $payment=tep_db_prepare_input($FREQUEST->getvalue('payment'));
  $global_query = tep_db_query("select global_product_notifications from " . TABLE_CUSTOMERS_INFO . " where customers_info_id = '" . (int)$FSESSION->customer_id . "'");
  $global = tep_db_fetch_array($global_query);
///Payone add orders_status to the next query
	$orders_query = tep_db_query("select orders_status, orders_id,payment_return1,payment_return2,payment_method from " . TABLE_ORDERS . " where orders_id = '" . (int)$FREQUEST->getvalue('order_id') . "' order by date_purchased desc limit 1");
	$orders = tep_db_fetch_array($orders_query);
	$orders_result=$orders;
	


	if ($global['global_product_notifications'] != '1') {
		$orders_query = tep_db_query("select orders_id from " . TABLE_ORDERS . " where customers_id = '" . (int)$FSESSION->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, is_printable, products_model,products_name,products_quantity,categories_name,concert_date,events_type from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$FREQUEST->getvalue('order_id')  . "' and products_type='P' order by products_model,products_id");
		while ($products = tep_db_fetch_array($products_query)) {
		//cartzone
			$products_array[] = array(	'id' => $products['products_id'],
										'qty' => $products['products_quantity'],
										'seat' => $products['products_name'],
										'date' => $products['products_model'],
										'type' => $products['events_type'],
										'categories_name' => $products['categories_name'],
										'concert_date' => $products['concert_date'],
										'is_printable' => $products['is_printable'],
										);
		}
		


	} 		/*CodeReadrAPI*/
	
	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);
  }
	
  $content = BOR_CONTENT_CHECKOUT_SUCCESS;
  $javascript = 'popup_window.js';
  require(DIR_WS_TEMPLATES . TEMPLATE_NAME . '/' . TEMPLATENAME_MAIN_PAGE);
  
  // if ((PWA_LOGOFF=='true')&&($guest==1)) {
	  
		// if(isset($_COOKIE['customer_is_guest'])){
   
		// $cart->reset(true);

		// $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');
		// //ICW - logout -> unregister GIFT VOUCHER sessions  - Thanks Fredrik

		// if ($FREQUEST->cookievalue('osCuser')) setcookie ("osCuser", "", time() - 60*60*24*30,$cookie_path,$cookie_domain);
		// if ($FREQUEST->cookievalue('osCpass')) setcookie ("osCpass", "", time() - 60*60*24*30,$cookie_path,$cookie_domain);
		// if ($FREQUEST->cookievalue('fe_typo_user')) setcookie ("fe_typo_user", "", time() - 60*60*24*30,$cookie_path,$cookie_domain);
		// if ($FREQUEST->cookievalue('be_typo_user')) setcookie ("be_typo_user", "", time() - 60*60*24*30,$cookie_path,$cookie_domain);
		// if ($FREQUEST->cookievalue('bbsessionhash')) setcookie ("bbsessionhash", "", time() - 60*60*24*30,$cookie_path,$cookie_domain);
		// if ($FREQUEST->cookievalue('PHPSESSID')) setcookie ("PHPSESSID", "", time() - 60*60*24*30,$cookie_path,$cookie_domain);
		// if ($FREQUEST->cookievalue('bbuserid')) setcookie ("bbuserid", "", time() - 60*60*24*30,$cookie_path,$cookie_domain);
		// if ($FREQUEST->cookievalue('bbpassword')) setcookie ("bbpassword", "", time() - 60*60*24*30,$cookie_path,$cookie_domain);
		// if ($FREQUEST->cookievalue('customer_is_guest')) setcookie ("customer_is_guest", "", time() - 60*60*24*30,$cookie_path,$cookie_domain);
		// session_destroy();

		// }//end customer is guest
  // }

  require(DIR_WS_INCLUDES . 'application_bottom.php');
  

?>
