<?php
/* --------------------------------------------------------------
   $Id: orders_tab.php,v 1.1.1.1 2008/10/27 07:55:53 cvs Exp $

   XT-Commerce - community made shopping
   http://www.xt-commerce.com

   Copyright (c) 2003 XT-Commerce
   --------------------------------------------------------------
   based on:
   (c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
   (c) 2002-2003 osCommerce(orders.php,v 1.109 2003/05/28); www.oscommerce.com
   (c) 2003	 nextcommerce (orders.php,v 1.19 2003/08/24); www.nextcommerce.org

   Released under the GNU General Public Licensekic
   --------------------------------------------------------------
   Third Party contribution:
   OSC German Banktransfer v0.85a       	Autor:	Dominik Guder <osc@guder.org>
   Customers Status v3.x  (c) 2002-2003 Copyright Elari elari@free.fr | www.unlockgsm.com/dload-osc/ | CVS : http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/elari/?sortby=date#dirlist

   credit card encryption functions for the catalog module
   BMC 2003 for the CC CVV Module

   Released under the GNU General Public License
   --------------------------------------------------------------*/
$order = new order($_GET['oID']);

$order_array = array('info'=>$order->info,
			'products'=>$order->products,
			'totals'=>$order->totals,
			'billing'=>$order->billing,
			'customer'=>$order->customer,
			'delivery'=>$order->delivery
);  
$smarty->assign('order',$order_array);


$smarty->assign('ENTRY_TELEPHONE',ENTRY_TELEPHONE);
$smarty->assign('ENTRY_EMAIL_ADDRESS',ENTRY_EMAIL_ADDRESS);
$smarty->assign('ENTRY_CUSTOMERS_VAT_ID',ENTRY_CUSTOMERS_VAT_ID);
$smarty->assign('ENTRY_LANGUAGE',ENTRY_LANGUAGE);
$smarty->assign('ENTRY_PAYMENT_METHOD',ENTRY_PAYMENT_METHOD);
$smarty->assign('ENTRY_CREDIT_CARD_TYPE',ENTRY_CREDIT_CARD_TYPE);
$smarty->assign('ENTRY_CREDIT_CARD_OWNER',ENTRY_CREDIT_CARD_OWNER);
$smarty->assign('ENTRY_CREDIT_CARD_NUMBER',ENTRY_CREDIT_CARD_NUMBER);
$smarty->assign('ENTRY_CREDIT_CARD_EXPIRES',ENTRY_CREDIT_CARD_EXPIRES);
$smarty->assign('TEXT_BANK_NAME',TEXT_BANK_NAME);
$smarty->assign('TEXT_BANK_BLZ',TEXT_BANK_BLZ);
$smarty->assign('TEXT_BANK_NUMBER',TEXT_BANK_NUMBER);
$smarty->assign('TEXT_BANK_OWNER',TEXT_BANK_OWNER);
$smarty->assign('TEXT_BANK_STATUS',TEXT_BANK_STATUS);
$smarty->assign('TEXT_BANK_ERRORCODE',TEXT_BANK_ERRORCODE);
$smarty->assign('TEXT_BANK_PRZ',TEXT_BANK_PRZ);
$smarty->assign('TEXT_BANK_FAX',TEXT_BANK_FAX);
$smarty->assign('TABLE_HEADING_PRODUCTS',TABLE_HEADING_PRODUCTS);
$smarty->assign('TABLE_HEADING_PRODUCTS_MODEL',TABLE_HEADING_PRODUCTS_MODEL);
$smarty->assign('TABLE_HEADING_DATE_ADDED',TABLE_HEADING_DATE_ADDED);
$smarty->assign('TABLE_HEADING_CUSTOMER_NOTIFIED',TABLE_HEADING_CUSTOMER_NOTIFIED);
$smarty->assign('TABLE_HEADING_STATUS',TABLE_HEADING_STATUS);
$smarty->assign('TABLE_HEADING_COMMENTS',TABLE_HEADING_COMMENTS);
$smarty->assign('TEXT_NO_ORDER_HISTORY',TEXT_NO_ORDER_HISTORY);


switch($_GET['tab']){
	default:
		$smarty->assign('tab','info');
		// memoquery
		$memo_query=xtc_db_query("SELECT count(*) as count FROM ".TABLE_CUSTOMERS_MEMO." where customers_id='".$order->customer['ID']."'");
		$memo_count=xtc_db_fetch_array($memo_query);
		
		// yes accounting
		if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['popup_memo'] == '1')) {
			$smarty->assign('memos',$memo_count['count']);
			$smarty->assign('memos_link','<a style="cursor:hand" onClick="window.open(\''.xtc_href_link(FILENAME_POPUP_MEMO,'ID='.$order->customer['ID']).'\', \'popup\', \'scrollbars=yes, width='.EXT_POPUP_WIDTH.', height='.EXT_POPUP_HEIGHT.'\');">('.DISPLAY_MEMOS.')</a>');
		}
		// yes accounting
		if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['ebay_mail_frame'] == '1')) {
			$smarty->assign('mail_popup_link','<a href="#" onClick="javascript:window.open(\''. xtc_href_link('ebay_mail_frame.php','email='.$order->customer['email_address'].'&box=reply').'\',\'popup\',\'width='. EXT_POPUP_WIDTH.',height='. EXT_POPUP_HEIGHT.', scrollbars=yes,resizable=yes\');">');
		}
		// begin modification for banktransfer
		$banktransfer_query = xtc_db_query("select banktransfer_prz, banktransfer_status, banktransfer_owner, banktransfer_number, banktransfer_bankname, banktransfer_blz, banktransfer_fax from banktransfer where orders_id = '" . xtc_db_input($_GET['oID']) . "'");
		if(xtc_db_num_rows($banktransfer_query)){
			$banktransfer = xtc_db_fetch_array($banktransfer_query);
			$smarty->assign('banktransfer',$banktransfer);
			switch ($banktransfer['banktransfer_status']) {
		          case 1: $error_val = TEXT_BANK_ERROR_1; break;
		          case 2: $error_val = TEXT_BANK_ERROR_2; break;
		          case 3: $error_val = TEXT_BANK_ERROR_3; break;
		          case 4: $error_val = TEXT_BANK_ERROR_4; break;
		          case 5: $error_val = TEXT_BANK_ERROR_5; break;
		          case 8: $error_val = TEXT_BANK_ERROR_8; break;
		          case 9: $error_val = TEXT_BANK_ERROR_9; break;
			}
			$smarty->assign('error_val',$error_val);
		}
		// end modification for banktransfer
		
		// BMC CC Mod Start
		if ($order->info['cc_number'] != '0000000000000000') {
		  if ( strtolower(CC_ENC) == 'true' ) {
		    $key = changeme;
		    $cipher_data = $order->info['cc_number'];
		    $order->info['cc_number'] = changedataout($cipher_data,$key);
		  }
		}
		// BMC CC Mod End
		


		// KOMBINIERT-INFO
		if($order->info['combined_orders_id'] > 0) {
			$smarty->assign('combined_orders_link',xtc_href_link(FILENAME_ORDERS,'oID='.$order->info['combined_orders_id'].'&action=edit'));
		}

		$combined_array = $order->get_combined_orders();
		if(sizeOf($combined_array)>0){
	  		$smarty->assign('combined_child_orders',$combined_array);
		}
		
		$feedbacks = array();
		if(sizeOf($combined_array)>0){
			foreach($combined_array as $cok=>$cov){
				$feedback_query = xtc_db_query("SELECT ef.CommentingUser,ef.ItemNumber,ef.CommentType,ef.CommentText,ef.TimeOfComment,ef.status FROM ebay_transactions et LEFT JOIN ebay_feedback ef ON ef.ItemNumber=et.ebayid AND ef.TransactionID=et.transactionid WHERE et.orders_id='".$cov['orders_id']."'");
				if(xtc_db_num_rows($feedback_query)){
					$feedback = xtc_db_fetch_array($feedback_query);
					if($feedback['ItemNumber'] != '')
						$feedbacks[] = $feedback;
				}
			}
			$smarty->assign('FEEDBACKS',$feedbacks);
		}else{
			if($order->info['ebay_id'] != ''){
				$feedback_query = xtc_db_query("SELECT ef.CommentingUser,ef.ItemNumber,ef.CommentType,ef.CommentText,ef.TimeOfComment,ef.status FROM ebay_transactions et LEFT JOIN ebay_feedback ef ON ef.ItemNumber=et.ebayid AND ef.TransactionID=et.transactionid WHERE et.orders_id='".$order->info['id']."'");
				if(xtc_db_num_rows($feedback_query)){
					$feedback = xtc_db_fetch_array($feedback_query);
					if($feedback['ItemNumber'] != '')
						$feedbacks[] = $feedback;
				}
				$smarty->assign('FEEDBACKS',$feedbacks);
				$smarty->assign('EBAY_LINK','<a target="_blank" href="'.xtc_get_ebay_link(xtc_get_auction_site($order->info['ebay_id'])).$order->info['ebay_id'].'">'.$order->info['ebay_id'].'</a>');

			}
		}

		define('TABLE_PAYPAL','paypal');
		define('FILENAME_PAYPAL','paypal.php');
		if ($order->info['payment_method']=='paypal_ipn' or $order->info['payment_method']=='paypal_directpayment' or $order->info['payment_method']=='paypal' or $order->info['payment_method']=='paypalexpress') {
			require('../includes/classes/paypal_checkout.php');
			require('includes/classes/class.paypal.php');
			$paypal = new paypal_admin();
			$smarty->assign('PAYPAL_NOTE',$paypal->admin_notification((int)$_GET['oID']));
		}


		

		// ALTES KOMBINIEREN HANDLING
		if($order->info['is_parent'] == 'y') {
	  		$smarty->assign('child_orders',$order->get_child_orders());
		}

		if($order->info['parent_orders_id'] > 0) {
	  		// yes accounting
			if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['f_orders_view'] == '1')) {
				$smarty->assign('parent_orders_link',xtc_href_link(FILENAME_ORDERS,'oID='.$order->info['parent_orders_id'].'&action=edit'));
			}
		}

		$javascript_string = '';		
		$reclamations = array();
		for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) {
			$product_collies = xtc_get_product_collies($order->products[$i]['id']);
			if(sizeOf($product_collies)>0){
				foreach($product_collies as $k=>$collie){
					$reclamation_query = xtc_db_query("SELECT rp.products_quantity,r.reclamations_type,r.reclamations_status, r.reclamations_id,date_format(r.date_created,'%d.%m.%y') as datum FROM reclamations_products rp,reclamations r WHERE r.orders_id='".$order->info['id']."' and rp.products_id='".$collie['collie_products_id']."' and rp.reclamations_id=r.reclamations_id");
					while( $reclamation = xtc_db_fetch_array($reclamation_query) ){
						$reclamations[ $order->products[$i]['id'] ]= true;
					}
				}
			}else{
				$reclamation_query = xtc_db_query("SELECT rp.products_quantity,r.reclamations_type,r.reclamations_status, r.reclamations_id,date_format(r.date_created,'%d.%m.%y') as datum FROM reclamations_products rp,reclamations r WHERE r.orders_id='".$order->info['id']."' and rp.products_id='".$order->products[$i]['id']."' and rp.reclamations_id=r.reclamations_id");
				while( $reclamation = xtc_db_fetch_array($reclamation_query) ){
					$reclamations[ $order->products[$i]['id'] ]= true;
				}
			}
		}

		$products_total_sum = 0;
		$sum_netto = 0;
		$weight_total = 0;
		$products = array();
		$products_date_available = $order->get_products_date_available();		
		$xtPrice = new xtcPrice($order->info['currency'],$order->info['status']);
		for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) {
			$product = array();
			$products_total_sum += $order->products[$i]['qty'];
			$product['collies'] = xtc_get_product_collies($order->products[$i]['id']);
			$product['collies_rowspan'] = sizeOf($product['collies']);
			$product['name'] = $order->products[$i]['name'];
			$product['model'] = $order->products[$i]['model'];
			$product['id'] = $order->products[$i]['id'];
			if($products_date_available[$product['id']])
				$product['date_available'] = $products_date_available[$product['id']];
			else
				$product['date_available'] = false;
			if(sizeOf($product['collies'])>0){
				$product['name'] = '<b>[C]</b>&nbsp;'.$product['name'];
				foreach($product['collies'] as $k=>$collie){
					if(STOCK_ALLOW_CHECKOUT != 'true'){
						// SERIAL NUMBERS
						if( xtc_products_has_serial($collie['collie_products_id']) ){
							$serials = xtc_get_orders_products_serial_numbers($collie['collie_products_id'],$order->products[$i]['opID']);
							if(sizeOf($serials)>0){
								$product['collies'][$k]['serials'] = $serials;
							}
						}
					}
					if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['orders_edit_products_serials'] == '1')) {
						$link = xtc_href_link('orders_edit_products_serials.php',xtc_get_all_get_params(array('action','opID','pID')).'opID='.$order->products[$i]['opID'].'&pID='.$collie['collie_products_id']);
						$product['collies'][$k]['serials_edit_link'] = $link;
					}
					
					// ARTIKELNR DER COLLIS
					$art_nr_query = xtc_db_query("SELECT products_model FROM products WHERE products_id='".$collie['collie_products_id']."'");
					$art_nr = xtc_db_fetch_array($art_nr_query);
					if(xtc_not_null($art_nr['products_model']))
						$product['collies'][$k]['model'] = xtc_db_prepare_input($art_nr['products_model']);
					$product['collies'][$k]['name'] = xtc_get_products_name($collie['collie_products_id']);
					$product['collies'][$k]['order_qty'] = $collie['quantity']*$order->products[$i]['qty'];
				}
			}

			if(STOCK_ALLOW_CHECKOUT != 'true'){
				// SERIAL NUMBERS
				if( xtc_products_has_serial($order->products[$i]['id']) ){
					$serials = xtc_get_orders_products_serial_numbers($order->products[$i]['id'],$order->products[$i]['opID']);
					if(sizeOf($serials)>0){
						$product['serials'] = $serials;
					}
				}
			}
			if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['orders_edit_products_serials'] == '1')) {
				$link = xtc_href_link('orders_edit_products_serials.php',xtc_get_all_get_params(array('action','opID','pID')).'opID='.$order->products[$i]['opID'].'&pID='.$order->products[$i]['id']);
				$product['serials_edit_link'] = $link;
			}

			if($reclamations[ $order->products[$i]['id'] ]){
				$product['reclamation_link'] = xtc_image('images/icon_status_red.gif','Reklamation zum Produkt existiert.');
				//$product['reclamation_link'] = '<a href="#" onClick="showRec('.$order->products[$i]['id'].');">'.xtc_image('images/icon_status_red.gif','Reklamation zum Produkt').'</a>';
			}

			$product['weight'] = xtc_get_ext_products_weight($order->products[$i]['id']);
			$product['weight_total'] = $product['weight']*$order->products[$i]['qty'];
			$weight_total += $product['weight']*$order->products[$i]['qty'];
		
			$product['volume'] = xtc_get_volumina($order->products[$i]['id']);
			$product['volume_total'] = $product['volume']*$order->products[$i]['qty'];
			$volume_total += $product['volume']*$order->products[$i]['qty'];

			$product['price'] = $xtPrice->xtcFormat($order->products[$i]['final_price'], true);
			$product['single_price'] = $xtPrice->xtcFormat($order->products[$i]['final_price']/$order->products[$i]['qty'], true);
			$product['edit_link'] = xtc_href_link('categories.php','pID='.$order->products[$i]['id'].'&cPath='.xtc_get_product_path($order->products[$i]['id']).'&action=new_product');
			$product['qty'] = $order->products[$i]['qty'];
			$products[] = $product;
		}
		$smarty->assign('PAYMENT_METHOD',xtc_get_payment_method_title($order->info['payment_method']));
		
		$smarty->assign('products',$products);
		$smarty->assign('weight_total',$weight_total);
		$smarty->assign('sum_netto',format_price($sum_netto,1,$order->info['currency'],0,0));
		
		// das muss kundengruppenabh. sein
		$export_note = xtc_get_customers_status_export_note($order->info['status'],$_SESSION['languages_id']);
		if($export_note != '')
			$smarty->assign('notax',$export_note);
			
		// yes accounting
		if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['orders_split'] == '1')) {
			// ORDERSPLIT bedingung
			if( $products_total_sum > 1 and $order->info['is_parent'] != 'y' and $order->info['parent_orders_id'] < 1 and ($order->info['orders_status'] == ORDERS_STATUS_UPSELLING or $order->info['orders_status'] == ORDERS_STATUS_BEZAHLT or $order->info['orders_status'] == 1 or $order->info['orders_status'] == 2)) { 
				$smarty->assign('orders_split_link',xtc_href_link('orders_split.php','oID='.$order->info['id']));
			} 
		}

		// VERSANDSPERRE BEDINGUNG
		if( $order->info['orders_status'] == 1 or $order->info['orders_status'] == 2 or $order->info['orders_status'] == ORDERS_STATUS_UPSELLING or $order->info['orders_status'] == ORDERS_STATUS_BEZAHLT){
			if($order->info['block_shipping'] == 0){
				$smarty->assign('set_block_shipping_link',xtc_href_link('orders.php',xtc_get_all_get_params(array('action')).'action=set_block_shipping'));
				$smarty->assign('set_block_shipping_button',"<input type='button' onClick='really_block_shipping(\"".$order->info['id']."\");' value='Versandsperre' title='Zeitweise vom Versand ausschliessen' class='iButton' style='width:160px'>");
			}else{
				$smarty->assign('set_unblock_shipping_link',xtc_href_link('orders.php',xtc_get_all_get_params(array('action')).'action=set_unblock_shipping'));
				$smarty->assign('set_unblock_shipping_button',"<input type='button' onClick='really_unblock_ship(\"".$order->info['id']."\");' title='Versandsperre aufheben' value='Versandsperre aufheben' class='iButton' style='width:160px'>");
			}
		}
		
		// MAHNSPERRE BEDINGUNG
		if( $order->info['orders_status'] == 1 or $order->info['orders_status'] == 2 or $order->info['orders_status'] == ORDERS_STATUS_UPSELLING or $order->info['orders_status'] == ORDERS_STATUS_VERSENDET){
			$is_warn_query = xtc_db_query("SELECT warning_span FROM orders WHERE orders_id='".$order->info['id']."'");
			$is_warn = xtc_db_fetch_array($is_warn_query);
			if($is_warn['warning_span'] == 0){
				if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['ebayapi_warnings'] == '1')) {
					$smarty->assign('set_no_warn_span_link',xtc_href_link('orders.php',xtc_get_all_get_params(array('action')).'action=set_no_warn_span'));
					$smarty->assign('set_no_warn_span_button',"<input type='button' onClick='really_nowarn_span(\"".$order->info['id']."\");' value='Mahnwesen Ausschluss' title='Zeitweise vom Mahnwesen ausschliessen' class='iButton' style='width:160px;'>");
				}
			}else{
				if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['ebayapi_warnings'] == '1')) {
					$smarty->assign('unset_no_warn_span_link',xtc_href_link('orders.php',xtc_get_all_get_params(array('action')).'action=unset_no_warn_span'));
					$smarty->assign('unset_no_warn_span_button',"<input type='button' onClick='really_unset_nowarn(\"".$order->info['id']."\");' value='In Mahnwesen' title='Wieder ins Mahnwesen integrieren' class='iButton' style='width:160px;'>");
					$smarty->assign('warning_span',$is_warn['warning_span']);
				}
			}		
			$warn_query = xtc_db_query("SELECT action,DATE_FORMAT(warning_date,'%d.%m.%Y.') as wd FROM ebay_warning_history WHERE orders_id='".$order->info['id']."'");
			if(xtc_db_num_rows($warn_query) > 0) {
				$warnings = array();
				while($warn = xtc_db_fetch_array($warn_query)){
					$warnings[] = $warn;
				}
				$smarty->assign('warnings',$warnings);
			}
		}

		/* * * * HERMES ADDON * * * * */
		if ( in_array( 'Hermes',$VERSENDER ) ){
			function get_hermes_artikelname($hermes_id) {
				$nummern_query = xtc_db_query("SELECT pd.products_name FROM products_description pd,storage_numbers sn WHERE pd.products_id=sn.products_id && pd.language_id='".$_SESSION['languages_id']."' && sn.nummer='".$hermes_id."'");
				$nummern = xtc_db_fetch_array($nummern_query);
				return $nummern['products_name'];
			}
			function get_hermes_buchungscode($code) {
				switch($code){
					case '1': return array('text'=>"Auftrag wurde fuer die Verarbeitung freigegeben",'color'=>'#FFFFFF'); break;
					case '2': return array('text'=>"Artikel wird ausgeliefert",'color'=>'#FFFFFF'); break;
					case '3': return array('text'=>"Artikel ist nicht verfuegbar (ausverkauft)",'color'=>'#FFAAAA'); break;
					case '13': return array('text'=>"Kundenretoure",'color'=>'#AAAAAA'); break;
					case '18': return array('text'=>"Annahmeverweigerung (unzustellbar oder vom Kunden nicht entgegengenommen)",'color'=>'#AAAAAA'); break;
					case '15': return array('text'=>"Stornierung der Auslieferung aufgrund von Problemen im Lager (beschaedigte Ware o. ae.) ",'color'=>'#FFAAAA'); break;
					case '20': return array('text'=>"Auftrag wurde erfolgreich importiert",'color'=>'#FFFFFF'); break;
					case '4': return array('text'=>" Artikel ist nicht verfuegbar, wird aber nachgeliefert",'color'=>'#00FF00'); break;
					case '5': return array('text'=>" Nachlieferungs-Artikel ist im Lager eingetroffen und wird ausgeliefert",'color'=>'#00FF00'); break;
					case '6': return array('text'=>" Nachlieferung kann doch nicht erfolgen, Auftrag wird storniert",'color'=>'#FFAAAA'); break;
					case '16': return array('text'=>"Stornierung der Auslieferung eines Nachlieferungs-Artikels aufgrund von Problemen im Lager (beschaedigte Ware o.ae.)",'color'=>'#FFAAAA'); break;
				}
			}
			
			// t_dispos
			$hermes_query = xtc_db_query("SELECT date_saved,i_booktype,i_itemno FROM hermes_status_dispos WHERE orders_id='".$order->info['id']."'");
			$hermes_num = xtc_db_num_rows($hermes_query);
			if($hermes_num > 0) {
				$hermes_array = array();
				$counter = 0;
				while($hermes = xtc_db_fetch_array($hermes_query)){
					$code = get_hermes_buchungscode($hermes['i_booktype']);
					$hermes_array[] = array('trclass'=>((is_int( ($counter/2) ) )?"dataTableRow":"dataTableRowSelected"),
						'date_saved'=>$hermes['date_saved'],
		            'text'=>$code['text'],
		            'artikelname'=>get_hermes_artikelname($hermes['i_itemno']));
					$counter++;
				}
				$smarty->assign('hermes_array',$hermes_array);
			}
		
			// t_orderstat
			$hermes_query = xtc_db_query("SELECT s_itemname,d_create,i_delivery,i_carrier,i_packunit,i_shipment_id FROM hermes_status_orderstat WHERE orders_id='".$order->info['id']."'");
			$hermes_num = xtc_db_num_rows($hermes_query);
			if($hermes_num > 0) {
				$hermes_stat_array = array();
				$counter = 0;
				while($hermes = xtc_db_fetch_array($hermes_query)){
					$hermes_stat_array[] = array('trclass'=>( (is_int( ($counter/2) ) )?"dataTableRow":"dataTableRowSelected"),
		            'd_create'=>$hermes['d_create'],
		            'i_delivery'=>$hermes['i_delivery'],
		            'i_packunit'=>$hermes['i_packunit'],
		            's_itemname'=>$hermes['s_itemname'],
		            'i_carrier'=>$hermes['i_carrier'],
		            'i_shipment_id'=>$hermes['i_shipment_id']);
					$counter++;
				}
			}
		}
		/* * * * end hermes * * */

		// yes accounting
		if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['f_orders_rueckstand'] == '1')) {
			if($order->info['orders_status'] == ORDERS_STATUS_UPSELLING or $order->info['orders_status'] == ORDERS_STATUS_BEZAHLT or $order->info['orders_status'] == '1' or $order->info['orders_status'] == '2'){
				if($order->info['rueckstand'] != 1){
					$smarty->assign('rueckstand_allow',1);
				}
			}
		}
		      	
		if($order->info['orders_status'] != ORDERS_STATUS_STORNIERT){
			$smarty->assign('recla_ext_storno_link',xtc_href_link('orders_storno.php','ext_storno=1&oID='.$order->info['id']));
		}

		$smarty->assign('orders_status_name',xtc_get_orders_status_name($order->info['orders_status']));

		$smarty->assign('edit_mode',1);

		
		// ACTIONS
		if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['orders_update'] == '1')) {
			$smarty->assign('orders_update_link',xtc_href_link('orders_update.php','oID='.$order->info['id']));
		}



		if($order->info['rueckstand'] == 1){
			if($order->info['orders_status'] == ORDERS_STATUS_UPSELLING or $order->info['orders_status'] == ORDERS_STATUS_BEZAHLT or $order->info['orders_status'] == '1' or $order->info['orders_status'] == '2'){
				$smarty->assign('rueckstand',1);
				if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['f_orders_rueckstand'] == '1')) {
					$smarty->assign('rueckstand_delete_link','<a href="javascript:really_unset_rueckstand(\''.$order->info['id'].'\');">'.xtc_image('images/icons/cross.gif','Rueckstandsmarkierung dieser Rechnung entfernen').'</a>');
				}
			}
		}

		$defaultuser_query = xtc_db_query('SELECT customers_id,customers_status FROM customers WHERE customers_lastname="__KASSE__"');
		if(xtc_db_num_rows($defaultuser_query)<1 && !$_GET['redirect']) {
			$messageStack->add_session('Der User Kasse existiert nicht, bitte kontaktieren Sie den Administrator.','error');
		}else{
			$defaultuser = xtc_db_fetch_array($defaultuser_query);
		}
		$kasseuser = $defaultuser['customers_id'];
		if($order->customer['ID'] != $kasseuser){
			$smarty->assign('crm_edit_link',xtc_href_link('customers.php','action=edit&cID='.$order->customer['ID']));
		}

		// KASSE ADDON
		if($order->is_kasse()){
			$kasse = $order->get_kasse_data();
			if( $kasse['branches_id'] > 0){
				$kasse['filiale'] = xtc_get_branch_title($kasse['branches_id']);
			}else{
				$kasse['filiale'] = 'Standard';
			}
			$smarty->assign('kasse',$kasse);
			if( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['f_switch_kasse_payment'] == '1')){
				$smarty->assign('change_kasse_paymode_link',xtc_href_link('orders.php',xtc_get_all_get_params(array('action')).'action=change_kasse_paymode'));
			}
		}
		$smarty->assign('order_set_rueckstand_link',xtc_href_link( 'orders.php',xtc_get_all_get_params(array('action')).'action=set_rueckstand' ));
		$smarty->assign('order_unset_rueckstand_link',xtc_href_link( 'orders.php',xtc_get_all_get_params(array('action')).'action=unset_rueckstand' ));
		$smarty->assign('order_email_link',xtc_href_link( 'orders.php',xtc_get_all_get_params(array('action')).'action=email&cID='.$order->customer['ID'] ));
		$smarty->assign('order_email_packing_link',xtc_href_link( 'orders.php',xtc_get_all_get_params(array('action')).'action=email_packing&cID='.$order->customer['ID'] ));


		// INSEL PLZ
		$insel_plz_array = explode(',',SHIPPING_POSTCODES_GERMANY_SPECIAL);
		if($order->delivery['country'] == 'Germany' and in_array($order->delivery['postcode'],$insel_plz_array)){
			$smarty->assign('insel_plz',1);
		}

		// yes accounting
		if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['f_orders_email'] == '1')) {
			$smarty->assign('order_email_allow',1);
		}

		// yes accounting
		if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['print_order'] == '1')) {
			$smarty->assign('order_print_allow',1);
			$smarty->assign('print_order_link',xtc_href_link(FILENAME_PRINT_ORDER,'oID='.$order->info['id']));
			$smarty->assign('print_order_admin_link',xtc_href_link(FILENAME_PRINT_ORDER,'oID='.$order->info['id'].'&adminprint=1'));
		}

		// yes accounting
		if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['print_packingslip'] == '1')) {
			$smarty->assign('order_print_packingslip_allow',1);
			$smarty->assign('order_print_packingslip_link',xtc_href_link(FILENAME_PRINT_PACKINGSLIP,'oID='.$order->info['id']));
		}

		// yes accounting
		if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['otc'] == '1')) {
			// BEDINGUNG warenausgabe
			if( $order->info['orders_status'] == ORDERS_STATUS_BEZAHLT or ( xtc_is_shipping_before_payment($order->info['payment_method']) and ($order->info['orders_status'] == 1 or $order->info['orders_status'] == 2 or $order->info['orders_status'] == ORDERS_STATUS_UPSELLING ) ) ){
				$smarty->assign('warenausgabe_allow',1);
				$smarty->assign('warenausgabe_link',xtc_href_link('otc.php','oID='.$order->info['id']));
				$smarty->assign('warenausgabe_button',xtc_image_button('button_warenausgabe.gif',"Warenausgabe"));
			}
		}

		break;
	case 'reclamations':
		$smarty->assign('tab','reclamations');
		// REKLAS
		$reclamations = array();
		$rec_query = xtc_db_query("SELECT reclamations_id,reclamations_status,reclamations_type FROM reclamations WHERE orders_id='".$_GET['oID']."'");
		while( $rec_row = xtc_db_fetch_array($rec_query) ){
			$reclamations[] = array('link'=>xtc_href_link('reclamations.php','action=edit&rID='.$rec_row['reclamations_id']),
				'rID'=>$rec_row['reclamations_id'],
				'reclamations_type_name'=>xtc_get_reclamations_types_name($rec_row['reclamations_type']),
				'reclamations_status_name'=>xtc_get_reclamations_status_name($rec_row['reclamations_status'])
			);
		}
		if(sizeOf($reclamations)>0){
			$smarty->assign('reclamations',$reclamations);
		}
		if(sizeOf($order->costs)>0){
			foreach($order->costs as $ck=>$cost){
				if($cost['reclamations_id'] > 0){
					$order->costs[$ck]['reclamation_link']=xtc_href_link('reclamations.php',xtc_get_all_get_params(array('action')).'action=edit&rID='.$cost['reclamations_id']);
				}
				$order->costs[$ck]['editor'] = xtc_get_editor_name($cost['editor_id']);
			}
			$smarty->assign('order_costs',$order->costs);
		}
		// yes accounting
		if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['f_reclamations_add'] == '1')) {
			if($order->info['orders_status'] != ORDERS_STATUS_STORNIERT){
				if($order->info['select_set'] == '1' and $order->info['select_set_status'] == 0){
		    	}else{
					$reclamations_types = xtc_get_reclamations_types();
					foreach($reclamations_types as $rec_key => $reclamation_type) {
						$reclamations_types[$rec_key]['link'] = xtc_href_link('reclamations.php','action=addorder&type='.$reclamation_type['id'].'&oID='.$order->info['id']);
					}
					$smarty->assign('reclamations_types',$reclamations_types);
		    	}
			}else{
					$smarty->assign('reclamations_error_storno',1);
			}
			$smarty->assign('rueckerstattung_link',xtc_href_link('rueckerstattungen.php','action=add&oID='.$order->info['id']));
		}else{
			$smarty->assign('rueckerstattung_not_allowed',1);
		}
		break;
	case 'stammdaten':
		$smarty->assign('tab','stammdaten');
		// STAMMDATEN
		$defaultuser_query = xtc_db_query('SELECT customers_id,customers_status FROM customers WHERE customers_lastname="__KASSE__"');
		if(xtc_db_num_rows($defaultuser_query)<1 && !$_GET['redirect']) {
			$messageStack->add_session('Der User Kasse existiert nicht, bitte kontaktieren Sie den Administrator.','error');
		}else{
			$defaultuser = xtc_db_fetch_array($defaultuser_query);
		}
		$kasseuser = $defaultuser['customers_id'];
		if($order->customer['ID'] != $kasseuser){
			$smarty->assign('crm_edit_link',xtc_href_link('customers.php','action=edit&cID='.$order->customer['ID']));
		}
		$customers_query = xtc_db_query("select c.block_warnings,c.block_warnings_span,c.block_warnings_dayspan,c.block_warnings_date, c.mobile,c.customers_vat_id,c.kto_nummer,c.kto_inhaber,c.kto_blz,c.kto_bank,c.customers_ebay_userid,c.customers_id,c.customers_cid, c.customers_gender, c.customers_firstname, c.customers_lastname, c.customers_dob, c.customers_email_address, a.entry_company, a.entry_street_address, a.entry_suburb, a.entry_postcode, a.entry_city, a.entry_state, a.entry_zone_id, a.entry_country_id, c.customers_telephone, c.customers_fax, c.customers_newsletter, c.customers_default_address_id from " . TABLE_CUSTOMERS . " c left join " . TABLE_ADDRESS_BOOK . " a on c.customers_default_address_id = a.address_book_id where a.customers_id = c.customers_id and c.customers_id = '" . $order->customer['ID'] . "'");
		$customers = xtc_db_fetch_array($customers_query);
		$customers['country_name'] = xtc_get_country_name($customers['entry_country_id']);
		$cInfo = new objectInfo($customers);
		$smarty->assign('cInfo',$customers);

		break;
	case 'rueckerstattungen':
		$smarty->assign('tab','rueckerstattungen');
		// RUECKERSTATTUNGEN
		if(sizeOf($order->rueckerstattungen)>0){
			$rueckerstattungen=array();
			foreach($order->rueckerstattungen as $ck=>$rueck){
				$rueck['link'] = xtc_href_link('rueckerstattungen.php',xtc_get_all_get_params(array('action','rID','status')).'action=edit&rID='.$rueck['id']);
				if($rueck['reclamations_id'] > 0){ 
					$rueck['reclamation_link'] = xtc_href_link('reclamations.php',xtc_get_all_get_params(array('action')).'action=edit&rID='.$rueck['reclamations_id']);
				}
				$rueck['editor'] = xtc_get_editor_name($rueck['editor_id']);
				$rueckerstattungen[] = $rueck;
			}
			$smarty->assign('order_rueckerstattungen',$rueckerstattungen);
		} // end rueck

		break;
	case 'retouren':
		$smarty->assign('tab','retouren');
		// RETOUREN	
		$retouren_query = xtc_db_query("SELECT * FROM retouren WHERE orders_id='".$order->info['id']."'");
		$retouren_num = xtc_db_num_rows($retouren_query);
		if($retouren_num > 0){
			$order_retouren = array();
			while($retoure = xtc_db_fetch_array($retouren_query)){
				$retoure['link'] = xtc_href_link('retoure.php',xtc_get_all_get_params(array('action','rID')).'action=edit&rID='.$retoure['retoure_id']);
				if($retoure['reclamations_id'] > 0){ 
					$retoure['reclamation_link'] = xtc_href_link('reclamations.php',xtc_get_all_get_params(array('action')).'action=edit&rID='.$retoure['reclamations_id']);
				}
				$retoure['retoure_status_name'] = xtc_get_retoure_status_name($retoure['retoure_status']);
				$order_retouren[] = $retoure;
			}
			$smarty->assign('order_retouren',$order_retouren);
		} // end if retouren > 1
		break;
	case 'history':
		$smarty->assign('tab','history');
		// HISTORY	
		$orders_history_query = xtc_db_query("select orders_status_id, date_added, customer_notified, comments,editor_id from " . TABLE_ORDERS_STATUS_HISTORY . " where orders_id = '" . xtc_db_input($order->info['id']) . "' order by date_added DESC");
		if (xtc_db_num_rows($orders_history_query)) {
			$history_array = array();
			while ($orders_history = xtc_db_fetch_array($orders_history_query)) {
				if ($orders_history['customer_notified'] == '1') {
					$orders_history['notified_icon'] = xtc_image(DIR_WS_ICONS . 'tick.gif', ICON_TICK);
				} else {
					$orders_history['notified_icon'] = xtc_image(DIR_WS_ICONS . 'cross.gif', ICON_CROSS);
				}
				$orders_history['status_name'] = xtc_get_orders_status_name($orders_history['orders_status_id']);
				//$orders_history['status_name'] = $orders_status_array[$orders_history['orders_status_id']];
				$orders_history['comments'] = nl2br(xtc_db_output($orders_history['comments']));
				$orders_history['editor'] = xtc_get_editor_name($orders_history['editor_id']);
				$history_array[] = $orders_history; 
			}
			$smarty->assign('history_array',$history_array);
		}
		break;
	case 'payments':
		$smarty->assign('tab','payments');

		// PAYMENTS	
		$payment_query = xtc_db_query("SELECT ip.buchungstag,ip.betrag,po.created FROM incoming_payments ip, payment_orders po WHERE ip.id=po.payment_id and po.orders_id='".$order->info['id']."'");
		$payment_orders = false;
		if(xtc_db_num_rows($payment_query) > 0){
			$payment_array = array();
			while($payment = xtc_db_fetch_array($payment_query)) {
				$payment_array[] = $payment;
			}
			$smarty->assign('payment_array',$payment_array);
		}
		break;
}
header('Content-Type: text/html; charset=iso-8859-1');
echo $smarty->fetch('orders_tab.html');
?>
