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

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

  Copyrightvermerke d�rfen 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 gro�e 
  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
class order {
	var $info, $totals, $items, $attendee, $delivery;
	function order($order_id) {
		$this->info = array();
		$this->totals = array();
		$this->items = array();
		$this->attendee = array();
		$this->delivery = array();
		$this->query($order_id);
	}
	function query($order_id) { 
		$order_query = go_db_query("select attendees_id, attendees_group_id,attendees_name, attendees_company, attendees_street_address, attendees_street_address2, attendees_suburb, attendees_city, ".
				"attendees_postcode, attendees_state, attendees_land, attendees_telephone, attendees_email_address, ".
				"attendees_form_of_address_id, delivery_name, delivery_company, delivery_street_address, delivery_street_address2, delivery_suburb, ".
				"delivery_city, delivery_postcode, delivery_state, delivery_land, delivery_form_of_address_id, ".
				"billing_name, billing_company, billing_piva, billing_cf, billing_street_address, billing_street_address2, billing_suburb, ".
				"billing_city, billing_postcode, billing_state, billing_land, billing_form_of_address_id, payment_method, ".
				"cc_type, cc_owner, cc_number, cc_code, cc_expires, currency, currency_value, date_purchased, orders_status, ".
				"last_modified, shipping_method, shipping_class from " . DB_TBL_ORDERS . " where orders_id = '" . (int)$order_id . "'"); 
		$order = go_db_fetch_array($order_query);
		$totals_query = go_db_query("select title, text, value, class from " . DB_TBL_ORDERS_TOTAL . " where orders_id = '" . (int)$order_id . "' order by sort_order");
		while ($totals = go_db_fetch_array($totals_query)) {
			$this->totals[] = array('title' => $totals['title'],
					'text' => $totals['text'],
					'value' => $totals['value'],
					'class' => $totals['class']);
		}
		$this->info = array('currency' => $order['currency'],
				'currency_value' => $order['currency_value'],
				'payment_method' => $order['payment_method'],
				'cc_type' => $order['cc_type'],
				'cc_owner' => $order['cc_owner'],
				'cc_number' => $order['cc_number'],
				'cc_code' => $order['cc_code'],
				'cc_expires' => $order['cc_expires'],
				'date_purchased' => $order['date_purchased'],
				'orders_status' => $order['orders_status'],
				'last_modified' => $order['last_modified'],
				'shipping_method' => $order['shipping_method'],
				'shipping_class' => $order['shipping_class']);
		$this->attendee = array('id' => $order['attendees_id'],
				'group_id' => $order['attendees_group_id'],
				'name' => $order['attendees_name'],
				'company' => $order['attendees_company'],
				'street_address' => $order['attendees_street_address'],
				'street_address2' => $order['attendees_street_address2'],
				'suburb' => $order['attendees_suburb'],
				'city' => $order['attendees_city'],
				'postcode' => $order['attendees_postcode'],
				'state' => $order['attendees_state'],
				'land' => $order['attendees_land'],
				'format_id' => $order['attendees_form_of_address_id'],
				'telephone' => $order['attendees_telephone'],
				'email_address' => $order['attendees_email_address']);
		$this->delivery = array('name' => $order['delivery_name'],
				'company' => $order['delivery_company'],
				'street_address' => $order['delivery_street_address'],
				'street_address2' => $order['delivery_street_address2'],
				'suburb' => $order['delivery_suburb'],
				'city' => $order['delivery_city'],
				'postcode' => $order['delivery_postcode'],
				'state' => $order['delivery_state'],
				'land' => $order['delivery_land'],
				'format_id' => $order['delivery_form_of_address_id'],
				'email_address' => $order['attendees_email_address']);
		$this->billing = array('name' => $order['billing_name'],
				'company' => $order['billing_company'],
				'street_address' => $order['billing_street_address'],
				'street_address2' => $order['billing_street_address2'],
				'suburb' => $order['billing_suburb'],
				'city' => $order['billing_city'],
				'postcode' => $order['billing_postcode'],
				'state' => $order['billing_state'],
				'land' => $order['billing_land'], 
				'piva' => $order['billing_piva'], 
				'cf' => $order['billing_cf'],  
				'format_id' => $order['billing_form_of_address_id']);
		$index = 0;
		$orders_items_query = go_db_query("select orders_items_id, items_name, items_model, items_price, items_basis_price, items_price_option, items_tax, items_quantity, items_laenge,items_breite, final_price, items_price_option_comment, items_display_opt_price from " . DB_TBL_ORDERS_ITEMS . " where orders_id = '" . (int)$order_id . "' order by items_name");
		while ($orders_items = go_db_fetch_array($orders_items_query)) {
			$this->items[$index] = array('qty' => $orders_items['items_quantity'],
					'laenge' => $orders_items['items_laenge'],
					'breite' => $orders_items['items_breite'],
					'name' => $orders_items['items_name'],
					'model' => $orders_items['items_model'],
					'tax' => $orders_items['items_tax'],
					'price' => $orders_items['items_price'],
					'items_basis_price' => $orders_items['items_basis_price'],
					'items_price_option' => $orders_items['items_price_option'],
					'final_price' => $orders_items['final_price'],
					'orders_items_id' => $orders_items['orders_items_id'],
					'items_price_option_comment' => $orders_items['items_price_option_comment'],
					'items_display_opt_price' => $orders_items['items_display_opt_price']);
			$subindex = 0;
			if (KONFIGURATOR=='true'){
				if (file_exists(FOLDER_ABSOLUT_CATALOG . 'modules/konfigurator')) {
					include(FOLDER_ABSOLUT_CATALOG . 'modules/konfigurator/configmain/class_this/class_bigware_9.php');
				}
				else{

					$characteristics_options_query = go_db_query("select distinct items_options_conf from " . DB_TBL_ORDERS_ITEMS_CHARACTERISTICS_CONF . " where orders_id = '" . (int)$order_id . "' and orders_items_id = '" . (int)$orders_items['orders_items_id'] . "'");
					$characteristics_options_num = go_db_num_rows($characteristics_options_query);
					for ($ao=0;$ao<$characteristics_options_num;$ao++){
						$characteristics_query = go_db_query("select items_options_conf, items_options_conf_values, options_conf_values_price, price_prefix from " . DB_TBL_ORDERS_ITEMS_CHARACTERISTICS_CONF . " where orders_id = '" . (int)$order_id . "' and orders_items_id = '" . (int)$orders_items['orders_items_id'] . "' and items_options_conf='".mysqli_result($characteristics_options_query,$ao,'items_options_conf')."'");

						if (go_db_num_rows($characteristics_query)>1) {
							$a=0;
							while ($characteristics = go_db_fetch_array($characteristics_query)) {
								$this->items[$index]['characteristics'][$subindex][$a] = array('option' => $characteristics['items_options_conf'],
										'value' => $characteristics['items_options_conf_values'],
										'prefix' => $characteristics['price_prefix'],
										'price' => $characteristics['options_conf_values_price']);
								$a++;
							}//while 
						}//if
						elseif (go_db_num_rows($characteristics_query)){
							while ($characteristics = go_db_fetch_array($characteristics_query)) {
								$this->items[$index]['characteristics'][$subindex] = array('option' => $characteristics['items_options_conf'],
										'value' => $characteristics['items_options_conf_values'],
										'prefix' => $characteristics['price_prefix'],
										'price' => $characteristics['options_conf_values_price']);

							}//while 
						} $subindex++;
					}//for ao

				}
			}//konfigurator
			else {
				$characteristics_query = go_db_query("select items_options, items_options_values, options_values_price, price_prefix from " . DB_TBL_ORDERS_ITEMS_CHARACTERISTICS . " where orders_id = '" . (int)$order_id . "' and orders_items_id = '" . (int)$orders_items['orders_items_id'] . "'");
				if (go_db_num_rows($characteristics_query)) {
					while ($characteristics = go_db_fetch_array($characteristics_query)) {
						$this->items[$index]['characteristics'][$subindex] = array('option' => $characteristics['items_options'],
								'value' => $characteristics['items_options_values'],
								'prefix' => $characteristics['price_prefix'],
								'price' => $characteristics['options_values_price']);
						$subindex++;
					}
				}

			}//not konfigurator



			$index++;
		}
	}
}
?>
