<?php
/*
###################################################################################
  Bigware Shop 2.3
  Release Datum: 23.08.2015
  
  Bigware Shop
  http://www.bigware.de

  Copyright (c) 2015 Bigware LTD
  (c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
  (c) 2015	Bigware LTD

  Copyrightvermerke duerfen nicht entfernt werden.
  ------------------------------------------------------------------------
  Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen
  der GNU General Public License, wie von der Free Software Foundation
  veroeffentlicht, weitergeben und/oder modifizieren, entweder gemaess Version 2 
  der Lizenz oder (nach Ihrer Option) jeder spaeteren Version.
  Die Veroeffentlichung dieses Programms erfolgt in der Hoffnung, dass es Ihnen
  von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE, sogar ohne die
  implizite Garantie der MARKTREIFE oder der VERWENDBARKEIT FUER EINEN
  BESTIMMTEN ZWECK. Details finden Sie in der GNU General Public License.
  
  Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
  Programm erhalten haben. Falls nicht, schreiben Sie an die Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

  Infos:
  ------------------------------------------------------------------------
  Der Bigware Shop wurde vor vielen Jahren bereits aus dem bekannten Shopsystem osCommerce
  weiter- und neuentwickelt.
  Der Bigware Shop legt im hohen Masse Wert auf Bedienerfreundlichkeit, beinhaltet eine leichte
  Installation, viele neue professionelle Werkzeuge und zeichnet sich aus durch eine grosse 
  Community, die bei Problemen weiterhelfen kann.
  
  Der Bigware Shop ist auf jedem System lauffaehig, welches eine PHP Umgebung
  (ab PHP 4.1.3) und mySQL zur Verfuegung stellt und auf Linux basiert.
 
  Hilfe erhalten Sie im Forum auf www.bigware.de 
  
  -----------------------------------------------------------------------
  
 ##################################################################################




*/

require('load_this/load_this_bigware_10.php'); 

require(FOLDER_RELATIV_CLASSES . $GLOBALS[CONFIG_NAME_FILE_CLASSES][classes_bigware_8]); 
if (go_get_set_it_up_key_value('CONSTITUENT_SHIPPING_INDVSHIP_STATUS') and $shiptotal) {
	go_session_unregister('shipping');
}  
if (!go_session_is_registered('attendee_id')) {
	$navigation->set_snapshot(); 
	go_forward(go_href_link($GLOBALS[CONFIG_NAME_FILE][main_bigware_40], 'origin=' . $GLOBALS[CONFIG_NAME_FILE][main_bigware_66], 'SSL'));  
} 
if ($cart->count_contents() < 1) {
	go_forward(go_href_link($GLOBALS[CONFIG_NAME_FILE][main_bigware_69]));
} 
if (!go_session_is_registered('sendto')) {
	go_session_register('sendto');
	$sendto = $attendee_default_address_id;
} else { 
	$check_address_query = go_db_query("select count(*) as total from " . DB_TBL_DIRECTORY_TO_ADDRESS . " where attendees_id = '" . (int)$attendee_id . "' and directory_to_address_id = '" . (int)$sendto . "'");
	$check_address = go_db_fetch_array($check_address_query);
	if ($check_address['total'] != '1') {
		$sendto = $attendee_default_address_id;
		if (go_session_is_registered('shipping')) go_session_unregister('shipping'); 
	}
}


if (OPTIMIZE_ORDER == 'true'){

	$check_query = go_db_query("select count(*) as count from temp_serialize where user = '" . $attendee_id . "' AND was = 'get_items'");
	$check = go_db_fetch_array($check_query);
	if ($check['count'] > 0) {	  	

		$my_items_query = go_db_query("SELECT serialize_code FROM temp_serialize WHERE user = '" . $attendee_id . "' AND was = 'get_items'");
		$my_items_result=go_db_fetch_array($my_items_query);    
		//$my_hidden_items = array_in_one_hidden_decode($my_items_result['serialize_code']);
	}  		



	$check_order_query = go_db_query("select count(*) as count from temp_serialize where user = '" . $attendee_id . "' AND was = 'order'");
	$check_order= go_db_fetch_array($check_order_query);
	if ($check_order['count'] < 1) {	


		require(FOLDER_RELATIV_CLASSES . $GLOBALS[CONFIG_NAME_FILE_CLASSES][classes_bigware_14]);
		$order = new order;
		$hidden_order = objekt_encode($order);
		go_db_query("insert into temp_serialize (user, serialize_code, was) values ('" . $attendee_id . "', '" . $hidden_order . "', 'order')");  
	}
	else{
		require(FOLDER_RELATIV_CLASSES . $GLOBALS[CONFIG_NAME_FILE_CLASSES][classes_bigware_14]);
		$my_order_query = go_db_query("SELECT serialize_code FROM temp_serialize WHERE user = '" . $attendee_id . "' AND was = 'order'");
		$my_order_result=go_db_fetch_array($my_order_query);    
		$order = array_in_one_hidden_decode($my_order_result['serialize_code']);	
	}	  
}
else{
	require(FOLDER_RELATIV_CLASSES . $GLOBALS[CONFIG_NAME_FILE_CLASSES][classes_bigware_14]);
	$order = new order;
}

if (!go_session_is_registered('cartID')) go_session_register('cartID');
$cartID = $cart->cartID;     


if ($order->content_type == 'virtual') { 
	if (!go_session_is_registered('shipping')) go_session_register('shipping');
	$shipping = false;
	$sendto = false;
	go_forward(go_href_link($GLOBALS[CONFIG_NAME_FILE][main_bigware_51], '', 'SSL'));
}else{
	if ( !isset($_POST['action']) && ($_POST['action'] != 'process') && ($_POST['iss_download'] != '1')) {
		include('load_this/preloader_header.php');
	}  	
}


$total_weight = $cart->show_weight();
$total_count = $cart->count_contents();  

require(FOLDER_RELATIV_CLASSES . $GLOBALS[CONFIG_NAME_FILE_CLASSES][classes_bigware_18]);
$shipping_modules = new shipping;



if ( defined('CONSTITUENT_SHIPPING_FREE_STATUS') && (CONSTITUENT_SHIPPING_FREE_STATUS == 'true') ) {
	$pass = false;
	switch (CONSTITUENT_SHIPPING_FREE_DESTINATION) {
		case 'national':
			if ($order->delivery['land_id'] == SHOP_LAND) {
				$pass = true;
			}
			break;
		case 'international':
			if ($order->delivery['land_id'] != SHOP_LAND) {
				$pass = true;
			}
			break;
		case 'both':
			$pass = true;
			break;
	}
	$free_shipping = false;
	if ( ($pass == true) && ($order->info['total'] >= CONSTITUENT_SHIPPING_FREE_SHIPPING_OVER) ) {
		$free_shipping = true;
		include(FOLDER_RELATIV_LANGUAGES . $language . '/' . FOLDER_RELATIV_LANG_MODULES_IN_LANG . 'shipping/free.php');
	}
} else {
	$free_shipping = false;
} 

if ( isset($_POST['action']) && ($_POST['action'] == 'process') ) {
	if (!go_session_is_registered('comments')) go_session_register('comments');
	if (go_not_null($_POST['comments'])) {
		$comments = str_replace("\\r\\n", "\r\n", go_db_producing_input($_POST['comments']));
	}
	if (!go_session_is_registered('shipping')) go_session_register('shipping');
	if ( (go_count_shipping_modules() > 0) || ($free_shipping == true) ) {
		if ( (isset($_POST['shipping'])) && (strpos($_POST['shipping'], '_')) ) {
			$shipping = $_POST['shipping'];
			list($module, $method) = explode('_', $shipping);
			if ( is_object($$module) || ($shipping == 'free_free') ) {
				if ($shipping == 'free_free') {
					$quote[0]['methods'][0]['title'] = CONSTITUENT_SHIPPING_FREE_TEXT_TITLE;
					$quote[0]['methods'][0]['cost'] = '0';
				} else {
					$quote = $shipping_modules->quote($method, $module);
				}
				if (isset($quote['error'])) {
					go_session_unregister('shipping');
				} else {
					if ( (isset($quote[0]['methods'][0]['title'])) && (isset($quote[0]['methods'][0]['cost'])) ) {
						$shipping = array('id' => $shipping,
								'title' => (($free_shipping == true && $quote[0]['methods'][0]['id'] !== 'pickup') ?  $quote[0]['methods'][0]['title'] : $quote[0]['module'] . ' (' . $quote[0]['methods'][0]['title'] . ')'),
								'cost' => $quote[0]['methods'][0]['cost']);
								go_forward(go_href_link($GLOBALS[CONFIG_NAME_FILE][main_bigware_51], '', 'SSL'));
					}
				}
			} else {
				go_session_unregister('shipping');
			}
		}
	} else {
		$shipping = false;
		go_forward(go_href_link($GLOBALS[CONFIG_NAME_FILE][main_bigware_51], '', 'SSL'));
	}    
} 
$quotes = $shipping_modules->quote(); 



if ( !go_session_is_registered('shipping') || ( go_session_is_registered('shipping') && ($shipping == false) && (go_count_shipping_modules() > 1) ) ) $shipping = $shipping_modules->cheapest();

go_session_register('shipping');

require(FOLDER_RELATIV_LANGUAGES . $language . '/' . $GLOBALS[CONFIG_NAME_FILE][main_bigware_66]);
$breadcrumb->add(NAVBAR_TITLE_1, go_href_link($GLOBALS[CONFIG_NAME_FILE][main_bigware_66], '', 'SSL'));
$breadcrumb->add(NAVBAR_TITLE_2, go_href_link($GLOBALS[CONFIG_NAME_FILE][main_bigware_66], '', 'SSL'));
$content = $GLOBALS[CONFIG_SHOW_FILE][main_bigware_66];
$javascript = $content . '.js';
require(FOLDER_RELATIV_TEMPLATES . TEMPLATENAME_MAIN_PAGE);
require(FOLDER_RELATIV_INCLUDES . 'load_this_bigware_3.php');
?>
