<?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 
  
  -----------------------------------------------------------------------
  
 ##################################################################################




*/
?>
<?php
require('load_this/load_this_bigware_10.php'); 

if (!go_session_is_registered('attendee_id')) {
	$navigation->set_snapshot();
	go_forward(go_href_link($GLOBALS[CONFIG_NAME_FILE][main_bigware_40], '', 'SSL'));
} 
if ($cart->count_contents() < 1) {
	go_forward(go_href_link($GLOBALS[CONFIG_NAME_FILE][main_bigware_69]));
}

require(FOLDER_RELATIV_LANGUAGES . $language . '/' . $GLOBALS[CONFIG_NAME_FILE][main_bigware_65]);

if (OPTIMIZE_ORDER == 'true'){
	$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) {	  

		$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']);
		} 
		require(FOLDER_RELATIV_CLASSES . $GLOBALS[CONFIG_NAME_FILE_CLASSES][classes_bigware_14]);
		$order = new 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 ($order->content_type == 'virtual') {
	if (!go_session_is_registered('shipping')) go_session_register('shipping');
	$shipping = false;
	if (!go_session_is_registered('sendto')) go_session_register('sendto');
	$sendto = false;
	go_forward(go_href_link($GLOBALS[CONFIG_NAME_FILE][main_bigware_51], '', 'SSL'));
}
$error = false;
$process = false;

if (isset($_POST['action']) && ($_POST['action'] == 'submit')) { 
	if (go_not_null($_POST['firstname']) && go_not_null($_POST['lastname']) && go_not_null($_POST['street_address'])) {
		$process = true;
		if (MEMBER_GENDER == 'true') $gender = go_db_producing_input($_POST['gender']);
		if (MEMBER_COMPANY == 'true') $company = go_db_producing_input($_POST['company']); 
		if (MEMBER_PIVA == 'true') $piva = go_db_producing_input($_POST['piva']);
		if (MEMBER_CF== 'true') $cf = go_db_producing_input($_POST['cf']); 
		$firstname = go_db_producing_input($_POST['firstname']);
		$lastname = go_db_producing_input($_POST['lastname']);
		$street_address = go_db_producing_input($_POST['street_address']);
		$street_address2 = go_db_producing_input($_POST['street_address2']);
		if (MEMBER_SUBURB == 'true') $suburb = go_db_producing_input($_POST['suburb']);
		$postcode = go_db_producing_input($_POST['postcode']);
		$city = go_db_producing_input($_POST['city']);
		$land = go_db_producing_input($_POST['land']);
		if (MEMBER_STATE == 'true') {
			if (isset($_POST['zone_id'])) {
				$zone_id = go_db_producing_input($_POST['zone_id']);
			} else {
				$zone_id = false;
			}
			$state = go_db_producing_input($_POST['state']);
		}
		if (MEMBER_GENDER == 'true') {
			if ( ($gender != 'm') && ($gender != 'f') ) {
				$error = true;
				$messageStack->add('checkout_address', TYPE_IN_GENDER_ERROR);
			}
		}
		if (strlen($firstname) < TYPE_IN_FIRST_NAME_MIN_LENGTH) {
			$error = true;
			$messageStack->add('checkout_address', TYPE_IN_FIRST_NAME_ERROR);
		}
		if (strlen($lastname) < TYPE_IN_LAST_NAME_MIN_LENGTH) {
			$error = true;
			$messageStack->add('checkout_address', TYPE_IN_LAST_NAME_ERROR);
		}
		if (strlen($street_address) < TYPE_IN_STREET_ADDRESS_MIN_LENGTH) {
			$error = true;
			$messageStack->add('checkout_address', TYPE_IN_STREET_ADDRESS_ERROR);
		}
		if (strlen($postcode) < TYPE_IN_POSTCODE_MIN_LENGTH) {
			$error = true;
			$messageStack->add('checkout_address', TYPE_IN_POST_CODE_ERROR);
		}
		if (strlen($city) < TYPE_IN_CITY_MIN_LENGTH) {
			$error = true;
			$messageStack->add('checkout_address', TYPE_IN_CITY_ERROR);
		}
		if (MEMBER_STATE == 'true') {
			$zone_id = 0;
			$check_query = go_db_query("select count(*) as total from " . DB_TBL_ZONES . " where zone_land_id = '" . (int)$land . "'");
			$check = go_db_fetch_array($check_query);
			$entry_state_has_zones = ($check['total'] > 0);
			if ($entry_state_has_zones == true) {
				$zone_query = go_db_query("select distinct zone_id from " . DB_TBL_ZONES . " where zone_land_id = '" . (int)$land . "' and (zone_name like '" . go_db_input($state) . "%' or zone_code like '%" . go_db_input($state) . "%')");
				if (go_db_num_rows($zone_query) == 1) {
					$zone = go_db_fetch_array($zone_query);
					$zone_id = $zone['zone_id'];
				} else {
					$error = true;
					$messageStack->add('checkout_address', TYPE_IN_STATE_ERROR_SELECT);
				}
			} else {
				if (strlen($state) < TYPE_IN_STATE_MIN_LENGTH) {
					$error = true;
					$messageStack->add('checkout_address', TYPE_IN_STATE_ERROR);
				}
			}
		}
		if ( (is_numeric($land) == false) || ($land < 1) ) {
			$error = true;
			$messageStack->add('checkout_address', TYPE_IN_LAND_ERROR);
		}
		if ($error == false) {
			$sql_data_array = array('attendees_id' => $attendee_id,
					'entry_firstname' => $firstname,
					'entry_lastname' => $lastname,
					'entry_street_address' => $street_address,
					'entry_street_address2' => $street_address2,
					'entry_postcode' => $postcode,
					'entry_city' => $city,
					'entry_land_id' => $land);
			if (MEMBER_GENDER == 'true') $sql_data_array['entry_gender'] = $gender;
			if (MEMBER_COMPANY == 'true') $sql_data_array['entry_company'] = $company; 
			if (MEMBER_PIVA == 'true') $sql_data_array['entry_piva'] = $piva;
			if (MEMBER_CF == 'true') $sql_data_array['entry_cf'] = $cf; 

			if (MEMBER_SUBURB == 'true') $sql_data_array['entry_suburb'] = $suburb;
			if (MEMBER_STATE == 'true') {
				if ($zone_id > 0) {
					$sql_data_array['entry_zone_id'] = $zone_id;
					$sql_data_array['entry_state'] = '';
				} else {
					$sql_data_array['entry_zone_id'] = '0';
					$sql_data_array['entry_state'] = $state;
				}
			}
			if (!go_session_is_registered('sendto')) go_session_register('sendto');
			go_db_carry(DB_TBL_DIRECTORY_TO_ADDRESS, $sql_data_array);
			$sendto = go_db_insert_id();
			if (go_session_is_registered('shipping')) go_session_unregister('shipping');
			go_forward(go_href_link($GLOBALS[CONFIG_NAME_FILE][main_bigware_66], '', 'SSL'));
		} 
	} elseif (isset($_POST['address'])) {

		$reset_shipping = false;
		if (go_session_is_registered('sendto')) {
			if ($sendto != $_POST['address']) {
				if (go_session_is_registered('shipping')) {
					$reset_shipping = true;
				}
			}
		} else {
			go_session_register('sendto');
		}
		$sendto = $_POST['address'];
		$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') {
			if ($reset_shipping == true) go_session_unregister('shipping');
			go_forward(go_href_link($GLOBALS[CONFIG_NAME_FILE][main_bigware_66], '', 'SSL'));
		} else {
			go_session_unregister('sendto');
		}
	} else {
		if (!go_session_is_registered('sendto')) go_session_register('sendto');
		$sendto = $attendee_default_address_id;
		go_forward(go_href_link($GLOBALS[CONFIG_NAME_FILE][main_bigware_66], '', 'SSL'));
	}
} 
if (!go_session_is_registered('sendto')) {
	$sendto = $attendee_default_address_id;
}	
include('load_this/preloader_header.php'); 
$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_65], '', 'SSL'));
$addresses_count = go_count_attendee_directory_to_address_entries();
$content = $GLOBALS[CONFIG_SHOW_FILE][main_bigware_65];
$javascript = $content . '.js.php';
require(FOLDER_RELATIV_TEMPLATES . TEMPLATENAME_MAIN_PAGE);
require(FOLDER_RELATIV_INCLUDES . 'load_this_bigware_3.php');
?>
