<?php
/* --------------------------------------------------------------
   $Id: orders.php,v 1.1.1.1 2008/10/27 07:55:52 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
   --------------------------------------------------------------*/

  require('includes/application_top.php');
  
  // wir brauchen den namen
  require(DIR_FS_LANGUAGES.$_SESSION['language'].'/modules/order_total/ot_subtotal_no_tax.php');

#################################### UOS START #######################################
if(MODULE_PAYMENT_UOS_TRANSFER_STATUS == 'True'){
	require_once(DIR_FS_CATALOG.DIR_WS_CLASSES.'class.uos.php');
	$uos = & new uos();
}
#################################### UOS END #######################################


  require_once(DIR_FS_INC . 'xtc_is_shipping_before_payment.inc.php');
  require_once(DIR_FS_INC . 'xtc_get_payment_method_title.inc.php');
  require(DIR_FS_INC.'xtc_get_customers_status_export_note.inc.php');			
  require(DIR_FS_INC.'xtc_get_ebay_link.inc.php');
  require(DIR_FS_INC.'xtc_get_auction_site.inc.php');
  require_once(DIR_FS_CATALOG.DIR_WS_CLASSES.'class.phpmailer.php');
  require_once(DIR_FS_INC . 'xtc_get_orders_ebay_seller.inc.php');
  require_once(DIR_FS_INC . 'xtc_get_ebay_seller_data.inc.php');
  require_once(DIR_FS_INC . 'xtc_php_mail.inc.php');
  require_once(DIR_FS_INC . 'xtc_collis.inc.php');
  require_once(DIR_FS_INC . 'xtc_serials.inc.php');
  require_once(DIR_FS_INC . 'xtc_add_tax.inc.php');
  require_once(DIR_FS_INC . 'changedataout.inc.php');
  require_once(DIR_FS_INC . 'xtc_validate_vatid_status.inc.php');
  require_once(DIR_FS_INC . 'xtc_get_parent_categories.inc.php');
  require_once(DIR_FS_INC . 'xtc_get_product_path.inc.php');
  require_once(DIR_FS_INC . 'xtc_format_price_order.inc.php');

  require (DIR_FS_CATALOG.'includes/classes/shipping.php');
  require (DIR_FS_CATALOG.'inc/xtc_count_shipping_modules.inc.php');
  require_once(DIR_FS_INC . 'xtc_oe_get_tax_rate.inc.php');
  require_once(DIR_FS_INC . 'xtc_oe_get_price_o_tax.inc.php');
  require_once(DIR_FS_INC . 'xtc_oe_get_customers_status.inc.php');
  require_once(DIR_FS_INC . 'xtc_oe_get_price_i_tax.inc.php');
  require_once(DIR_FS_INC . 'xtc_oe_get_allow_tax.inc.php');
  require(DIR_FS_CATALOG.DIR_WS_CLASSES . 'xtcPrice.php');

  // yes accounting  
  $admin_access_query = xtc_db_query("select * from " . TABLE_ADMIN_ACCESS . " where customers_id = '" . $_SESSION['customer_id'] . "'");
  $admin_access = xtc_db_fetch_array($admin_access_query);

  // initiate template engine for mail
 $smarty = new Smarty;
  // dont allow cache
  $smarty->caching = false;
  $smarty->template_dir=DIR_FS_ADMIN.'templates';
  $smarty->compile_dir=DIR_FS_CATALOG.'templates_c';
  $smarty->config_dir=DIR_FS_CATALOG.'lang';
  require(DIR_WS_CLASSES . 'currencies.php');
  include('includes/classes/class.ebaymail.php');
  require(DIR_WS_CLASSES . 'order.php');

  if($_GET['tab']){
  	if(!$_GET['action']){
		include('orders_tab.php');
		exit;
	}
  }

  if($_GET['ajax_payment_filter'] and $_GET['ajax_payment_filter'] == 1){
	include('ajax_orders_payment_methods.php');
	exit;
  }
  
  // yes accounting
  if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['orders'] == '1')) {
  }else{
  	$messageStack->add_session('Keine Berechtigung f&uuml;r Rechnungen ansehen.','error');
  	xtc_redirect(xtc_href_link('index.php',xtc_get_all_get_params(array('action'))));
  }
  

 $currencies = new currencies();

  $orders_statuses = array();
  $orders_status_array = array();
  $orders_status_query = xtc_db_query("select orders_status_id, orders_status_name from " . TABLE_ORDERS_STATUS . " where language_id = '" . $_SESSION['languages_id'] . "' and orders_status_id!='".ORDERS_STATUS_KOMBINIERT."'");
  while ($orders_status = xtc_db_fetch_array($orders_status_query)) {
    $orders_statuses[] = array('id' => $orders_status['orders_status_id'],
                               'text' => $orders_status['orders_status_name']);
    $orders_status_array[$orders_status['orders_status_id']] = $orders_status['orders_status_name'];
  }

#################################### UOS START #######################################
if(MODULE_PAYMENT_UOS_TRANSFER_STATUS == 'True'){
	require("uos_orders_ext.php");
	$reserved = false;
	if ($_GET['oID'] > 0){
	  if($uos->dbTableExists('uos_reserved_orders')){
	  	$reserved_order_query = xtc_db_query('SELECT * FROM uos_reserved_orders WHERE orderid = '.(int)$_GET['oID'].' and booked=0');
	  	$reserved_order = xtc_db_fetch_array($reserved_order_query);
	  	if(!empty($reserved_order)) $reserved = true;
	  }
	}
}
#################################### UOS END #######################################

  if ( $_GET['oID'] ) {
    $oID = xtc_db_prepare_input($_GET['oID']);

    $orders_query = xtc_db_query("select orders_id from " . TABLE_ORDERS . " where orders_id = '" . $oID . "'");
    $order_exists = true;
    if (!xtc_db_num_rows($orders_query)) {
      $order_exists = false;
      $messageStack->add(sprintf(ERROR_ORDER_DOES_NOT_EXIST, $oID), 'error');
    }
  }
  switch ($_GET['action']) {
#################################### UOS START #######################################
	case 'book' :
	  $order_id = xtc_db_prepare_input($_GET['oID']);
	  $tmp_order = new order($order_id, '');

		$modPath = '../includes/modules/payment/';
		$uosModFiles = array(
			'uos_lastschrift_modul.php', 
			'uos_kreditkarte_modul.php', 
			'uos_transfer_modul.php'
		);
		$availableModFiles = array();
		foreach($uosModFiles AS $k => $modFile){
			if (file_exists($modPath.$modFile)) {
				require ($modPath.$modFile);
				$availableModFiles[] = $modFile; 
			}
		}
		
		$_SESSION['uos_error'] = '';
		
		if (in_array($tmp_order->info['payment_method'].'.php', $availableModFiles)) {
	    if($tmp_order->info['payment_method'] == 'uos_lastschrift_modul'){
	      $payment_module = new uos_lastschrift_modul();
	      $secret = MODULE_PAYMENT_UOS_LASTSCHRIFT_KEY;
	      $debug = MODULE_PAYMENT_UOS_LASTSCHRIFT_DEBUG;
	      $debugEmail = MODULE_PAYMENT_UOS_LASTSCHRIFT_DEBUG_EMAIL;
	      $constFilter = 'MODULE_PAYMENT_UOS_LASTSCHRIFT_';
	    }else if($tmp_order->info['payment_method'] == 'uos_kreditkarte_modul'){
	      $payment_module = new uos_kreditkarte_modul();
	      $secret = MODULE_PAYMENT_UOS_KREDITKARTE_KEY;
	      $debug = MODULE_PAYMENT_UOS_KREDITKARTE_DEBUG;
	      $debugEmail = MODULE_PAYMENT_UOS_KREDITKARTE_DEBUG_EMAIL;
	      $constFilter = 'MODULE_PAYMENT_UOS_KREDITKARTE_';
	    }else if($tmp_order->info['payment_method'] == 'uos_transfer_modul'){
	      $payment_module = new uos_transfer_modul();
	      $secret = MODULE_PAYMENT_UOS_TRANSFER_KEY;
	      $debug = MODULE_PAYMENT_UOS_TRANSFER_DEBUG;
	      $debugEmail = MODULE_PAYMENT_UOS_TRANSFER_DEBUG_EMAIL;
	      $constFilter = 'MODULE_PAYMENT_UOS_TRANSFER_';
	    }
		} else {
			$_SESSION['uos_error'] = 'Modul "'.$tmp_order->info['payment_method'].'" not found!';
		}

    if (is_object($payment_module)){
	    if(!empty($reserved_order) && is_numeric($_POST['uos_euro']) && is_numeric($_POST['uos_cent'])){
	      $send['uos_p']            = $reserved_order['projectId'];
	      $send['uos_request']      = 'FINISH';
	      $send['uos_transaction']  = $reserved_order['transactionId'];
	      $send['uos_eu']           = $_POST['uos_euro']*100+$_POST['uos_cent'];
	      $send['uos_chk']          = md5($send['uos_p'].$send['uos_request'].$send['uos_transaction'].$send['uos_eu'].$secret);
	
	      $url = $payment_module->form_action_url;
	      $res = $uos->doUOSRequest($url, $send, array());
	      $res = $uos->parseResult($res);
	      $params = $res['params'];
	      $status = $res['status'];
	
	      $curl_error   = $uos->error;
	      $fullResponse = $uos->response;
	
	      # UOS Debugging
				if ($debug != 'None'){
					$debug_get = $_GET;
					$debug_post = $_POST;
					if (isset($_POST['cus_cc_number'])) $debug_post['cus_cc_number'] = 'XXX';
					if (isset($_POST['cus_cc_cvv'])) 		$debug_post['cus_cc_cvv'] = 'XXX';
					$debug_const = array();
					foreach (get_defined_constants() AS $k => $v){
						if (strpos($k, $constFilter) === false) continue;
						$debug_const[$k] = $v;
					}
					$debug_infos = "Modul Infos: 	\n" . print_r($payment_module, true)."\n\n"
											 . "send: 		    \n" . print_r($send, true)."\n\n"
											 . "Timestamp: 		\n" . date('d.m.Y H:i:s')."\n\n"
											 . "URL: 					\n" . $url."\n\n"
											 . "CURL Result: 	\n" . print_r($res, true)."\n\n"
											 . "CURL Error: 	\n" . print_r($curl_error, true)."\n\n"
											 . "CURL FullRes:	\n" . print_r($fullResponse, true)."\n\n"
											 . "Constants: 		\n" . print_r($debug_const, true)."\n\n"
											 . "GET:					\n" . print_r($debug_get, true)."\n\n"
											 . "POST:					\n" . print_r($debug_post, true)."\n\n"
											 . "SESSION:			\n" . print_r($_SESSION, true)."\n\n";
	        $uos->sendMail($debugEmail, 'ORDERS DEBUGMAIL [CURL]', $debug_infos);
	        }
	
	      // History
	      if($status == 'OK'){
	        // Status setzen
	          xtc_db_query("UPDATE `orders` SET `orders_status` = '".$payment_module->payment_status."' WHERE `orders_id` = '".$_GET['oID']."'");
	        // Reservierte Buchung als gebucht markieren
	        xtc_db_query("UPDATE `uos_reserved_orders` SET `booked` = 1 WHERE `orderid` = '".$_GET['oID']."'");
	
	        // Order History auslesen und neuen Eintrag vornehmen
	        $orderHistoryArray = xtc_db_query("select * from orders_status_history where orders_id='".$order_id."' order by orders_status_history_id DESC");
	        $orderHistory = xtc_db_fetch_array($orderHistoryArray);
	        $orderHistory['customer_notified'] = '1';
	        $orderHistory['date_added'] = date('Y-m-d H:i:s');
	        $orderHistory['comments'] = $payment_module->get_payment_admin_comment($_SESSION['language']).' '.$reserved_order['transactionId'].' ('.$_POST['uos_euro'].','.$_POST['uos_cent'].' '.$_SESSION['currency'].')';
	        if(!empty($status)){
	          $orderHistory['orders_status_id'] = $payment_module->payment_status;
	        }
	        unset($orderHistory['orders_status_history_id']);
	        xtc_db_perform(TABLE_ORDERS_STATUS_HISTORY, $orderHistory);
	
	        // Mail an Kunden verschicken
	        send_billing_mail($_SESSION['language'], $order_id, $orderHistory['comments'], $orderHistory['orders_status_id']);
	        
	      } else if ($status == 'FAIL') {
	        parse_str($params, $output);
	        $_SESSION['uos_error'] .= $output['msg_1'];
	      }
	    }
    }
		xtc_redirect(xtc_href_link(FILENAME_ORDERS, xtc_get_all_get_params(array ('action')).'action=edit'));
		break;
#################################### UOS END #######################################
	case 'ext_search':
		require('orders_ext_search.php'); // produkte suchen
		break;
	case 'ext_search2':
		require('orders_ext_search2.php'); // adresse suchen
		break;
	case 'ext_search3':
		require('orders_ext_search3.php'); // kundengruppe anzeigen
		break;
  	case 'save_kasse_paymode':
		$oID = xtc_db_input($_GET['oID']);
		$order = new order($oID);
		if(!$_POST['paymode']){
			$messageStack->add_session('Keine Bezahlart gew&auml;hlt.','error');
			xtc_redirect(xtc_href_link('orders.php',xtc_get_all_get_params(array('action')).'action=change_kasse_paymode') );
		}
		if(strlen(trim($_POST['comments']) )<2){
			$messageStack->add_session('Kein Kommentar angegeben.','error');
			xtc_redirect(xtc_href_link('orders.php',xtc_get_all_get_params(array('action')).'action=change_kasse_paymode') );
		}
		if($_GET['oID']>0){
			if($_POST['paymode'] != 'bank'){
				xtc_db_query("UPDATE kasse SET paymode='".$_POST['paymode']."' where orders_id='".$_GET['oID']."'");
				$comments = 'Die Bezahlart der Kasse wurde im Nachhinein auf '.$_POST['paymode'].' gesetzt. Kommentar: '.xtc_db_input($_POST['comments']);
				$order->add_history($order->info['orders_status'],$notified=0,$comments);
			}else{
				xtc_db_query("DELETE FROM kasse where orders_id='".$_GET['oID']."'");
				$order->update_orders_status(1);
				$comments = 'Die Bezahlart der Kasse wurde im Nachhinein auf '.$_POST['paymode'].' gesetzt. Aus Kassenstatistik entfernt. Status auf Offen gesetzt. Kommentar: '.xtc_db_input($_POST['comments']);
				$order->add_history(1,$notified=0,$comments);
			}
		}
		$messageStack->add_session('Kassenstatistik ge&auml;ndert.','success');
		xtc_redirect(xtc_href_link('orders.php',xtc_get_all_get_params(array('action')).'action=edit') );
		break;
	case "set_rueckstand":
		$oID = xtc_db_input($_GET['oID']);
		$order = new order($oID);
		xtc_db_query("UPDATE orders SET rueckstand='1', last_modified=now() WHERE orders_id='".$oID."'");
		$comments = 'Rechnung markiert als Rueckstand';
		$order->add_history($order->info['orders_status'],$notified=0,$comments);
		$messageStack->add_session('Die Rechnung Nr '.$oID.' wurde als "Im R&uuml;ckstand" markiert.','success');
		xtc_redirect( xtc_href_link('orders.php',xtc_get_all_get_params(array('action')).'action=edit'));
		break;
	case "unset_rueckstand":
		$oID = xtc_db_input($_GET['oID']);
		$order = new order($oID);
		xtc_db_query("UPDATE orders SET rueckstand='0', last_modified=now() WHERE orders_id='".$oID."'");
		$comments = 'Markierung als Rueckstand wurde entfernt.';
		$order->add_history($order->info['orders_status'],$notified=0,$comments);
		$messageStack->add_session('Die Markierung der Rechnung Nr '.$oID.' als "Im R&uuml;ckstand" wurde entfernt.','success');
		xtc_redirect( xtc_href_link('orders.php',xtc_get_all_get_params(array('action')).'action=edit'));
		break;
	case "set_no_warn_span":
		// ---------------------------------------------------------
		// WIR SCHLIESSEN DIE RECHNUNG FUER X TAGE VOM MAHNWESEN AUS
		// ---------------------------------------------------------
		$oID = xtc_db_input($_GET['oID']);
		$span = xtc_db_input($_GET['span']);
		$order = new order($oID);
		xtc_db_query("UPDATE orders SET no_warning=1,warning_span_date=now(),warning_span='".$span."',last_modified=now() WHERE orders_id='".$oID."'");
		$comments = 'Vom Mahnwesen fuer '.$span.' Tage ausgeschlossen.';
		$order->add_history($order->info['orders_status'],$notified=0,$comments);
		$messageStack->add_session('Die Rechnung Nr '.$oID.' wurde vom Mahnwesen f&uuml;r '.$span.' Tage ausgeschlossen','success');
		xtc_redirect( xtc_href_link('orders.php',xtc_get_all_get_params(array('action','span')).'action=edit'));
		break;
	case "unset_no_warn_span":
		// ---------------------------------------------------------
		// WIR INTEGRIEREN DIE RECHNUNG WIEDER INS MAHNWESEN
		// ---------------------------------------------------------
		$oID = xtc_db_input($_GET['oID']);
		$order = new order($oID);
		xtc_db_query("UPDATE orders SET no_warning=0,warning_span_date='',warning_span='',last_modified=now() WHERE orders_id='".$oID."'");
		$comments = 'Per Hand wieder ins Mahnwesen integriert.';
		$order->add_history($order->info['orders_status'],$notified=0,$comments);
		$messageStack->add_session('Die Rechnung Nr '.$oID.' wurde wieder ins Mahnwesen integriert.','success');
		xtc_redirect( xtc_href_link('orders.php',xtc_get_all_get_params(array('action')).'action=edit'));
		break;
	case "set_block_shipping":
		// ---------------------------------------------------------
		// WIR SCHLIESSEN DIE RECHNUNG FUER X TAGE VOM VERSAND AUS
		// ---------------------------------------------------------
		$oID = xtc_db_input($_GET['oID']);
		$text = xtc_db_input($_GET['text']);
		$order = new order($oID);
		xtc_db_query("UPDATE orders SET block_shipping='1',last_modified=now() WHERE orders_id='".$oID."'");
		$comments = 'Vom Versand ausgeschlossen: '.$text;
		$order->add_history($order->info['orders_status'],$notified=0,$comments);
		$messageStack->add_session('Die Rechnung Nr '.$oID.' wurde vom Versand ausgeschlossen','success');
		xtc_redirect( xtc_href_link('orders.php',xtc_get_all_get_params(array('action')).'action=edit'));
		break;
	case "set_unblock_shipping":
		// ---------------------------------------------------------
		// WIR INTEGRIEREN DIE RECHNUNG WIEDER IN DEN VERSAND
		// ---------------------------------------------------------
		$oID = xtc_db_input($_GET['oID']);
		$order = new order($oID);
		xtc_db_query("UPDATE orders SET block_shipping='0',last_modified=now() WHERE orders_id='".$oID."'");
		$comments = 'Versandsperre aufgehoben.';
		$order->add_history($order->info['orders_status'],$notified=0,$comments);
		$messageStack->add_session('Versandsperre f&uuml;r Rechnung Nr '.$oID.' wieder aufgehoben.','success');
		xtc_redirect( xtc_href_link('orders.php',xtc_get_all_get_params(array('action')).'action=edit'));
		break;
	case 'change_orders':
		// yes accounting
		if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['orders_edit'] == '1')) {
		}else{
			$messageStack->add_session('Keine Berechtigung f&uuml;r &auml;ndern von Rechnungen.','error');
			xtc_redirect(xtc_href_link(FILENAME_ORDERS,xtc_get_all_get_params(array('action'))));
		}
		
		$order_combine = false;

		switch($_POST['list_action']){
			case 'nosend':
				$gesamt = 0;
				$orders = array();
				if(is_array($_POST['statusOID']) && $_GET['cID']>0){
					$ordersID = $_POST['statusOID'];
					$cLINK = '';
					$cID = xtc_db_prepare_input($_GET['cID']);
					$gesamt = sizeOf($ordersID);
					
					foreach($ordersID as $k=>$oID){
						$check_query = xtc_db_query("SELECT orders_status,is_parent,customers_id FROM orders WHERE orders_id='".xtc_db_input($oID)."'");
						$check = xtc_db_fetch_array($check_query);
						
						// VERSANDSPERRE bedingung
						if( ($check['orders_status'] == 1 or $check['orders_status'] == 2 or $check['orders_status'] == ORDERS_STATUS_UPSELLING or $check['orders_status'] == ORDERS_STATUS_BEZAHLT) and $check['is_parent'] != 'y' and $check['customers_id'] == $cID ){
							$orders[] = $oID;
						}
					}
					if(sizeOf($orders) == 0){
						$messageStack->add_session('Es wurde keine Rechnung ausgew&auml;hlt die mit einer Versandsperre belegt werden kann.','error');
						xtc_redirect(xtc_href_link('orders.php',xtc_get_all_get_params(array('action'))));
					}else{
						$text = xtc_db_input($_POST['temp_comment']);
						if(strlen($text)>0){
							foreach($orders as $ko=>$kv) {
								$order = new order($kv);
								xtc_db_query("UPDATE orders SET block_shipping='1',last_modified=now() WHERE orders_id='".$kv."'");
								$messageStack->add_session('Die Rechnung Nr '.$kv.' wurde vom Versand ausgeschlossen','success');
								xtc_db_query("INSERT INTO ".TABLE_ORDERS_STATUS_HISTORY." SET orders_id='".$kv."', orders_status_id='".$order->info['orders_status']."',date_added=now(),customer_notified=0, comments='Vom Versand ausgeschlossen: ".$text."',editor_id='".$_SESSION['customer_id']."'" );
							}
						}else{
							$messageStack->add_session('Es wurde kein Kommentar f&uuml;r die Versandsperre &uuml;bergeben.','error');
							xtc_redirect(xtc_href_link('orders.php',xtc_get_all_get_params(array('action'))));
						}
					}
					xtc_redirect(xtc_href_link('orders.php',xtc_get_all_get_params(array('action'))));
				}else{
					$messageStack->add_session('Es wurde entweder kein Kunde oder keine Rechnungen &uuml;bergeben.','error');
					xtc_redirect(xtc_href_link('orders.php',xtc_get_all_get_params(array('action'))));
				}
				break;
			case 'combine':
				$valide = 0;
				$gesamt = 0;
				if(is_array($_POST['statusOID']) && $_GET['cID']>0){
					$ordersID = $_POST['statusOID'];
					$cLINK = '';
					$cID = xtc_db_prepare_input($_GET['cID']);
					$gesamt = sizeOf($ordersID);
					foreach($ordersID as $k=>$oID){
						$check_query = xtc_db_query("SELECT orders_status,is_parent,customers_id FROM orders WHERE orders_id='".xtc_db_input($oID)."'");
						$check = xtc_db_fetch_array($check_query);
						
						// KOMBINIEREN bedingung
						if( $check['orders_status'] == 1 
								or $check['orders_status'] == 2 
								or $check['orders_status'] == ORDERS_STATUS_UPSELLING  
								or $check['orders_status'] == ORDERS_STATUS_BEZAHLT 
								and $check['is_parent'] != 'y'
								and $check['customers_id'] == $cID ){
							$cLINK .= 'collect_orders_id[]='.$oID.'&';
							$valide++;
						}
					}
					if( $gesamt > 1 and $valide == $gesamt ){
						xtc_redirect(xtc_href_link('combined_orders.php',xtc_get_all_get_params(array('collect_orders_id','action')).$cLINK.'action=edit'));
					}else{
						$messageStack->add_session('Es wurde mind. eine Rechnung ausgew&auml;hlt die nicht kombiniert werden darf.','error');
					}
					xtc_redirect(xtc_href_link('orders.php',xtc_get_all_get_params(array('action'))));
				}else{
					$messageStack->add_session('Es wurde entweder kein Kunde oder keine Rechnungen &uuml;bergeben.','error');
					xtc_redirect(xtc_href_link('orders.php',xtc_get_all_get_params(array('action'))));
				}
				break;
		}
		/*** IST RAUSGENOMMEN WORDEN
		if($order_change){
			$ordersID = xtc_db_prepare_input($_POST['statusOID']);
			$status = xtc_db_prepare_input($_GET['status']);
			$orders_status = xtc_db_prepare_input($_POST['orders_status']);
			if(is_array($ordersID) && count($ordersID)>0){
				foreach($ordersID as $k=>$oID){
					if( xtc_not_null($oID) && $oID > 0 && xtc_not_null($orders_status) && $orders_status > 0) {
						xtc_db_query("UPDATE orders SET orders_status='".$orders_status."',last_modified=now() WHERE orders_id='".$oID."'");
						xtc_db_query("INSERT INTO orders_status_history SET orders_id='".$oID."', orders_status_id='".$orders_status."', date_added='".date('Y-m-d H:i:s')."',customer_notified='n',comments='Ohne Benachrichtigung an den Kunden per Quickedit auf neuen Status gesetzt.',editor_id='".$_SESSION['customer_id']."'");
						$messageStack->add_session('Der Status der Rechnung '.$oID.' wurde ge&auml;ndert.','success');
					}else{
						$messageStack->add_session('Der Status der Rechnung '.$oID.' konnte nicht ge&auml;ndert werden.','error');
					}
				}
			}
			xtc_redirect(xtc_href_link(FILENAME_ORDERS,xtc_get_all_get_params(array('action'))));
		}
		***/
		break;
	case 'email':
		// yes accounting
		if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['f_orders_email'] == '1')) {
		}else{
			$messageStack->add_session('Keine Berechtigung f&uuml;r versenden von Rechnungen per Email.','error');
			xtc_redirect(xtc_href_link(FILENAME_ORDERS,xtc_get_all_get_params(array('action'))));
		}
    		
    		$oID = xtc_db_prepare_input($_GET['oID']);
    		$cID = xtc_db_prepare_input($_GET['cID']);
    		$email_address = xtc_db_prepare_input($_GET['address']);

		$order = new order($oID);
		
		$smarty->assign('address_label_customer',xtc_address_format($order->customer['format_id'], $order->customer, 1, '', '<br>'));
		$smarty->assign('address_label_shipping',xtc_address_format($order->delivery['format_id'], $order->delivery, 1, '', '<br>'));
		$smarty->assign('address_label_payment',xtc_address_format($order->billing['format_id'], $order->billing, 1, '', '<br>'));
		$smarty->assign('csID',$order->customer['csID']);

		$ebay_seller = xtc_get_orders_ebay_seller((int)$_GET['oID']);
		if($ebay_seller != ''){
			$smarty->assign('EBAY_SELLER_DATA',xtc_get_ebay_seller_data($ebay_seller));
			$smarty->assign('EBAY_ID',$order->info['ebay_id']);
		}
		
		if( $order->info['orders_status'] == ORDERS_STATUS_STORNIERT) {
			$smarty->assign('IS_STORNO','1');
		}
		
		// get products data
		if( $order->info['is_parent'] == 'n') {
			$order_query=xtc_db_query("SELECT
						products_id,
						orders_products_id,
						products_model,
						products_name,
						allow_tax,
						products_tax,
						final_price,
						products_quantity
						FROM ".TABLE_ORDERS_PRODUCTS."
						WHERE orders_id='".(int)$_GET['oID']."'");
		}else{
			$order_query=xtc_db_query("SELECT
						op.products_id,
						op.orders_products_id,
						op.products_model,
						op.products_name,
						op.allow_tax,
						op.products_tax,
						op.final_price,
						op.products_quantity
						FROM ".TABLE_ORDERS_PRODUCTS." op, orders o 
						WHERE o.parent_orders_id='".(int)$_GET['oID']."' && op.orders_id=o.orders_id");
		}
		$order_data=array();
		$xtPrice = new xtcPrice($order->info['currency'],$order->info['status']);
		$sum_netto = 0;
		while ($order_data_values = xtc_db_fetch_array($order_query)) {
			$attributes_query=xtc_db_query("SELECT
						products_options,
						products_options_values,
						price_prefix,
						options_values_price
						FROM ".TABLE_ORDERS_PRODUCTS_ATTRIBUTES."
						WHERE orders_products_id='".$order_data_values['orders_products_id']."'");
			$attributes_data='';
			$attributes_model='';
			while ($attributes_data_values = xtc_db_fetch_array($attributes_query)) {
				$attributes_data .='<br>'.$attributes_data_values['products_options'].':'.$attributes_data_values['products_options_values'];	
				$attributes_model .='<br>'.xtc_get_attributes_model($order_data_values['products_id'],$attributes_data_values['products_options_values']);
			}
			
	
			$order_data[]=array(
				'PRODUCTS_MODEL' => $order_data_values['products_model'],
				'PRODUCTS_NAME' => $order_data_values['products_name'],
				'PRODUCTS_ATTRIBUTES' => $attributes_data,
				'PRODUCTS_ATTRIBUTES_MODEL' => $attributes_model,
				'PRODUCTS_PRICE' => $xtPrice->xtcFormat($order_data_values['final_price'], true),
				'PRODUCTS_SINGLE_PRICE' => $xtPrice->xtcFormat($order_data_values['final_price']/$order_data_values['products_quantity'], true),
				'PRODUCTS_TAX' => $tax,
				'PRODUCTS_QTY' => $order_data_values['products_quantity']);
			
			if($order_data_values['allow_tax'] == '1' and $order_data_values['products_tax'] > 0){
				$sum_netto += format_price($order_data_values['final_price'], 0, $order->info['currency'], $order_data_values['allow_tax'], $order_data_values['products_tax']);
			}
		}
	
		// ZEIGE ZWISCHENSUMME NETTOSUMME WENN INCL STEUER
		if($sum_netto > 0){
			$smarty->assign('NETTOSUM',number_format(xtc_round($sum_netto,PRICE_PRECISION),2,',','').' '.$order->info['currency']);
		}
		
		// get order_total data
		$oder_total_query=xtc_db_query("SELECT
				title,
				text,
				class,
				value,
				sort_order
						FROM ".TABLE_ORDERS_TOTAL."
						WHERE orders_id='".$_GET['oID']."'
						ORDER BY sort_order ASC");
		
		$order_total=array();
		
		$notax = 0;
		while ($oder_total_values = xtc_db_fetch_array($oder_total_query)) {
		
			$order_total[]=array(
				'TITLE' => $oder_total_values['title'],
				'CLASS'=> $oder_total_values['class'],
				'VALUE'=> $oder_total_values['value'],
				'TEXT' => $oder_total_values['text']);
			
			if ($oder_total_values['class']='ot_total'){ 
				$total=$oder_total_values['value'];
			}
			if($oder_total_values['class']=='ot_subtotal_no_tax'){
				$notax = 1; // RE OHNE MWST
			}
		}
		// das muss kundengruppenabh. sein
		$export_note = xtc_get_customers_status_export_note($order->info['status'],$_SESSION['languages_id']);
		if($export_note != '')
			$smarty->assign('export_note',$export_note);
		
		// assign language to template for caching
		$smarty->assign('STORE', nl2br(STORE_NAME_ADDRESS));
		$smarty->assign('STORE_WRAP', STORE_WRAP);
		$smarty->assign('BANK', MODULE_PAYMENT_MONEYORDER_PAYTO);
		
		$smarty->assign('language', $_SESSION['language']);
		$smarty->assign('logo_path',HTTP_SERVER.'templates/'.CURRENT_TEMPLATE.'/img/');
		
		$o_ebayid = '';
		if($order->info['is_parent'] == 'y'){
			$all_ebay_query = xtc_db_query("SELECT ebay_id FROM orders WHERE parent_orders_id='".$_GET['oID']."'");
			while($all_ebay = xtc_db_fetch_array($all_ebay_query)){
				$o_ebayid .= $all_ebay['ebay_id'].', ';
			}
			$o_ebayid = substr($o_ebayid,0,(strlen($o_ebayid)-2));
		}else{
			$o_ebayid .= $order->info['ebay_id'];
		}
		if($o_ebayid!=''){
			$o_ebayid = '<p><b>Ebay-Auktion:</b> '.$o_ebayid.'</p>';
		}
		$smarty->assign('oID',$_GET['oID'].$o_ebayid);
		
		/*
		if ($order->info['payment_method']!='' && $order->info['payment_method']!='no_payment') {
			include(DIR_FS_CATALOG.'lang/'.$_SESSION['language'].'/modules/payment/'.$order->info['payment_method'].'.php');
			$payment_method=constant(strtoupper('MODULE_PAYMENT_'.$order->info['payment_method'].'_TEXT_TITLE'));
			$smarty->assign('PAYMENT_METHOD',$payment_method);
		}*/
		$smarty->assign('PAYMENT_METHOD',xtc_get_payment_method_title($order->info['payment_method']));
		$smarty->assign('DATE',xtc_date_long($order->info['date_purchased']));
	  	if($order->info['date_shipping'] > 0)
			$smarty->assign('DATE_SHIPPING',xtc_date_long($order->info['date_shipping']));
		$smarty->assign('order_data', $order_data);
		$smarty->assign('order_total', $order_total);
		
		// dont allow cache
		$smarty->caching = false;
		$smarty->template_dir=DIR_FS_CATALOG.'templates';
		$smarty->compile_dir=DIR_FS_CATALOG.'templates_c';
		$smarty->config_dir=DIR_FS_CATALOG.'lang';
		
		$html_mail=$smarty->fetch(CURRENT_TEMPLATE . '/admin/mail/german/send_order.html');
		
		// **** EMAILCLIENT - ADDON *****
		$dbMail = new DBmail('0');
		$dbMail->save_mail(EMAIL_BILLING_SUBJECT,$email_address,EMAIL_BILLING_REPLY_ADDRESS_NAME,EMAIL_BILLING_REPLY_ADDRESS,$html_mail,date('Y-m-d H:i:s'), $order->info['ebay_id'],$cID,$oID);
		
		xtc_db_query("INSERT INTO orders_status_history SET orders_id='".$order->info['id']."', orders_status_id='".$order->info['orders_status']."', date_added='".date('Y-m-d H:i:s')."', customer_notified='1', comments='Rechnung per Email an ".$email_address." versendet',editor_id='".$_SESSION['customer_id']."'");
		$subject = 'Ihre Rechnung Nr. '.$order->info['id'].(($order->info['ebay_id']!='') ? ' ('.$order->info['ebay_id'].')':'');


		xtc_php_mail(EMAIL_BILLING_REPLY_ADDRESS, EMAIL_BILLING_REPLY_ADDRESS_NAME, $email_address, $email_address, '', EMAIL_BILLING_REPLY_ADDRESS, EMAIL_BILLING_REPLY_ADDRESS_NAME, $path_to_attachement='', $path_to_more_attachements='', $subject, $html_mail,'');
		$messageStack->add_session('Der Kunde erhielt per Email die Rechnung zur Rechnung '.$oID,'success');
		xtc_redirect(xtc_href_link('orders.php','oID='.$oID.'&action=edit'));
		break;
	case 'email_packing':
		// yes accounting
		if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['f_orders_email'] == '1')) {
		}else{
			$messageStack->add_session('Keine Berechtigung f&uuml;r versenden von Lieferscheinen per Email.','error');
			xtc_redirect(xtc_href_link(FILENAME_ORDERS,xtc_get_all_get_params(array('action'))));
		}
    		
    		$oID = xtc_db_prepare_input($_GET['oID']);
    		$cID = xtc_db_prepare_input($_GET['cID']);
    		$email_address = xtc_db_prepare_input($_GET['address']);

		$order = new order($oID);
		$order_query_check = xtc_db_query("SELECT
							customers_id
							FROM ".TABLE_ORDERS."
							WHERE orders_id='".$_GET['oID']."'");
							
		$order_check = xtc_db_fetch_array($order_query_check);
		$smarty->assign('address_label_customer',xtc_address_format($order->customer['format_id'], $order->customer, 1, '', '<br>'));
		$smarty->assign('address_label_shipping',xtc_address_format($order->delivery['format_id'], $order->delivery, 1, '', '<br>'));
		$smarty->assign('address_label_payment',xtc_address_format($order->billing['format_id'], $order->billing, 1, '', '<br>'));
		$smarty->assign('csID',$order->customer['csID']);
		// get products data
		if( $order->info['is_parent'] == 'n') {
			$order_query=xtc_db_query("SELECT
						products_id,
						orders_products_id,
						products_model,
						products_name,
						final_price,
						products_quantity
						FROM ".TABLE_ORDERS_PRODUCTS."
						WHERE orders_id='".$_GET['oID']."'");
		}else{
			$order_query=xtc_db_query("SELECT
						op.products_id,
						op.orders_products_id,
						op.products_model,
						op.products_name,
						op.final_price,
						op.products_quantity
						FROM ".TABLE_ORDERS_PRODUCTS." op, orders o 
						WHERE o.parent_orders_id='".$_GET['oID']."' && op.orders_id=o.orders_id");
		}
		$order_data=array();
		while ($order_data_values = xtc_db_fetch_array($order_query)) {
			$attributes_query=xtc_db_query("SELECT
						products_options,
						products_options_values,
						price_prefix,
						options_values_price
						FROM ".TABLE_ORDERS_PRODUCTS_ATTRIBUTES."
						WHERE orders_products_id='".$order_data_values['orders_products_id']."'");
			$attributes_data='';
			$attributes_model='';
			while ($attributes_data_values = xtc_db_fetch_array($attributes_query)) {
			$attributes_data .='<br>'.$attributes_data_values['products_options'].':'.$attributes_data_values['products_options_values'];	
			$attributes_model .='<br>'.xtc_get_attributes_model($order_data_values['products_id'],$attributes_data_values['products_options_values']);
			}
		$order_data[]=array(
				'PRODUCTS_MODEL' => $order_data_values['products_model'],
				'PRODUCTS_NAME' => $order_data_values['products_name'],
				'PRODUCTS_ATTRIBUTES' => $attributes_data,
				'PRODUCTS_ATTRIBUTES_MODEL' => $attributes_model,
				'PRODUCTS_PRICE' =>  xtc_format_price_order($order_data_values['final_price'],1,$order->info['currency']),
				'PRODUCTS_QTY' => $order_data_values['products_quantity']);
		}
		// get order_total data
		$oder_total_query=xtc_db_query("SELECT
				title,
				text,
				class,
				value,
				sort_order
				FROM ".TABLE_ORDERS_TOTAL."
				WHERE orders_id='".$_GET['oID']."'
				ORDER BY sort_order ASC");
		
		$order_total=array();
		while ($oder_total_values = xtc_db_fetch_array($oder_total_query)) {
		
		$order_total[]=array(
			'TITLE' => $oder_total_values['title'],
			'CLASS'=> $oder_total_values['class'],
			'VALUE'=> $oder_total_values['value'],
			'TEXT' => $oder_total_values['text']);
		if ($oder_total_values['class']='ot_total') $total=$oder_total_values['value'];
		}
		
		// assign language to template for caching
			$smarty->assign('STORE', nl2br(STORE_NAME_ADDRESS));
			$smarty->assign('BANK', MODULE_PAYMENT_MONEYORDER_PAYTO);
		$smarty->assign('language', $_SESSION['language']);
		$smarty->assign('logo_path',HTTP_SERVER  . 'templates/'.CURRENT_TEMPLATE.'/img/');
		$smarty->assign('oID',$_GET['oID']);

		$ebay_seller = xtc_get_orders_ebay_seller((int)$_GET['oID']);
		if($ebay_seller != ''){
			$smarty->assign('EBAY_SELLER_DATA',xtc_get_ebay_seller_data($ebay_seller));
			$smarty->assign('EBAY_ID',$order->info['ebay_id']);
		}
		/*
		if ($order->info['payment_method']!='' && $order->info['payment_method']!='no_payment') {
		include(DIR_FS_CATALOG.'lang/'.$_SESSION['language'].'/modules/payment/'.$order->info['payment_method'].'.php');
			$payment_method=xtc_get_payment_method_title($order->info['payment_method']);
		$smarty->assign('PAYMENT_METHOD',$payment_method);
		}
		*/
		$smarty->assign('PAYMENT_METHOD',xtc_get_payment_method_title($order->info['payment_method']));
		$smarty->assign('DATE',xtc_date_long($order->info['date_purchased']));
	  	if($order->info['date_shipping'] > 0)
			$smarty->assign('DATE_SHIPPING',xtc_date_long($order->info['date_shipping']));
		$smarty->assign('order_data', $order_data);
		$smarty->assign('order_total', $order_total);
		
		// dont allow cache
		$smarty->caching = false;
		
		$smarty->template_dir=DIR_FS_CATALOG.'templates';
		$smarty->compile_dir=DIR_FS_CATALOG.'templates_c';
		$smarty->config_dir=DIR_FS_CATALOG.'lang';
		
		$html_mail=$smarty->fetch(CURRENT_TEMPLATE . '/admin/mail/german/send_packingslip.html');
		
		// **** EMAILCLIENT - ADDON *****
		$dbMail = new DBmail('0');
		$dbMail->save_mail(EMAIL_BILLING_SUBJECT,$email_address,EMAIL_BILLING_REPLY_ADDRESS_NAME,EMAIL_BILLING_REPLY_ADDRESS,$html_mail,date('Y-m-d H:i:s'), $order->info['ebay_id'],$cID,$oID);
		
		xtc_db_query("INSERT INTO orders_status_history SET orders_id='".$order->info['id']."', orders_status_id='".$order->info['orders_status']."', date_added='".date('Y-m-d H:i:s')."', customer_notified='1', comments='Lieferschein per Email an ".$email_address." versendet',editor_id='".$_SESSION['customer_id']."'");
		$subject = 'Ihr Lieferschein fuer Re-Nr. '.$order->info['id'].(($order->info['ebay_id']!='') ? ' ('.$order->info['ebay_id'].')':'');
		xtc_php_mail(EMAIL_BILLING_REPLY_ADDRESS, EMAIL_BILLING_REPLY_ADDRESS_NAME, $email_address, $email_address, '', EMAIL_BILLING_REPLY_ADDRESS, EMAIL_BILLING_REPLY_ADDRESS_NAME, $path_to_attachement='', $path_to_more_attachements='', $subject, $html_mail,'');
		$messageStack->add_session('Der Kunde erhielt per Email den Lieferschein zur Rechnung '.$oID,'success');
		xtc_redirect(xtc_href_link('orders.php','oID='.$oID.'&action=edit'));
		
		break;
		
	case 'deleteconfirm':
		// yes accounting
		if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['f_orders_delete'] == '1')) {
		}else{
			$messageStack->add_session('Keine Berechtigung f&uuml;r versenden von Rechnungen per Email.','error');
			xtc_redirect(xtc_href_link(FILENAME_ORDERS,xtc_get_all_get_params(array('action'))));
		}
      		
      		$oID = xtc_db_prepare_input($_GET['oID']);
		xtc_remove_order($oID, $_POST['restock']);
		xtc_redirect(xtc_href_link(FILENAME_ORDERS, xtc_get_all_get_params(array('oID', 'action'))));
		break;
    	case 'delete':
		// yes accounting
		if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['f_orders_delete'] == '1')) {
		}else{
			$messageStack->add_session('Keine Berechtigung f&uuml;r l&ouml;schen von Rechnungen.','error');
			xtc_redirect(xtc_href_link(FILENAME_ORDERS,xtc_get_all_get_params(array('action'))));
		}
		break;
    	case 'edit':
		// yes accounting
		if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['f_orders_view'] == '1')) {
		}else{
			$messageStack->add_session('Keine Berechtigung f&uuml;r Detailansicht von Rechnungen.','error');
			xtc_redirect(xtc_href_link(FILENAME_ORDERS,xtc_get_all_get_params(array('action'))));
		}
		break;
      		
	// BMC Delete CC info Start
	// Remove CVV Number
    	case 'deleteccinfo':
		// yes accounting
		if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['f_orders_delete_cc'] == '1')) {
		}else{
			$messageStack->add_session('Keine Berechtigung f&uuml;r versenden von Rechnungen per Email.','error');
			xtc_redirect(xtc_href_link(FILENAME_ORDERS,xtc_get_all_get_params(array('action'))));
		}
      		
      		$oID = xtc_db_prepare_input($_GET['oID']);
		xtc_db_query("update " . TABLE_ORDERS . " set cc_cvv = null where orders_id = '" . xtc_db_input($oID) . "'");
		xtc_db_query("update " . TABLE_ORDERS . " set cc_number = '0000000000000000' where orders_id = '" . xtc_db_input($oID) . "'");
		xtc_db_query("update " . TABLE_ORDERS . " set cc_expires = null where orders_id = '" . xtc_db_input($oID) . "'");
		xtc_db_query("update " . TABLE_ORDERS . " set cc_start = null where orders_id = '" . xtc_db_input($oID) . "'");
		xtc_db_query("update " . TABLE_ORDERS . " set cc_issue = null where orders_id = '" . xtc_db_input($oID) . "'");
		
		xtc_redirect(xtc_href_link(FILENAME_ORDERS, 'oID=' . $_GET['oID'] . '&action=edit'));
		break;
		// BMC Delete CC Info End
}
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $_SESSION['language_charset']; ?>">
<title><?php echo TITLE; ?></title>
<script language="javascript"><!--

// PROTOTYPE ONLOAD FUNCTION INIT
var ONLOADPAGE = 'orders';
<?php 
if(!$_GET['action']){?> 
var ONLOADFUNC = "ajax_onload";
var ONLOADFUNCPARAM = false;
<?php }else if($_GET['action'] == 'edit'){?>
var ONLOADFUNC = "ajax_onload_tab";
var ONLOADFUNCPARAM = "info";
<?php } ?>


var lastoID = '';
function setLastoID(value){
	lastoID = value;
}
function getLastoID(){
	return lastoID;
}

function ajax_show_order_details(oID){
  lo = getLastoID();
  if(lo == oID) // klick aufs aktive object
	return true;

  params = 'oID='+oID;
  var myAjax = new Ajax.Request(
    "ajax_order_details.php",
    { 
    	method: 'get', 
	parameters: params,
    	onComplete: show_order_details 
    }
  );
  $('trid_'+oID).className = 'dataTableRowSelected';
  if(lo != '')
	$('trid_'+lo).className = 'dataTableRow';
  setLastoID(oID);
}
function show_order_details( originalRequest ) {
   $('orderdetails').innerHTML = originalRequest.responseText;
}

function rowStyle(aktion,id){
	lo = getLastoID();
	if(lo == id){
		return true;
	}else{
		if(aktion == 'over'){
			$('trid_'+id).className = 'dataTableRowOver';
		}else{
			$('trid_'+id).className = 'dataTableRow';
		}
	}
}
function ajax_onload(){
	id = document.forms['change_orders'].start_oID.value;
	ajax_show_order_details(id);
	rowstyle(id);
}

function ajax_onload_tab(tab){
	ajax_load_tab(tab);
}

function ajax_load_tab(tab){
  params = 'oID=<?php echo $_GET['oID']; ?>&tab='+tab;
  var myAjax = new Ajax.Request(
    "orders.php",
    { 
    	method: 'get', 
	parameters: params,
    	onComplete: show_tab 
    }
  );
  tabs = $('maintab').childNodes;

  for(i=0;i<tabs.length;i++){
	if(tabs[i].id == tab)
		tabs[i].className = 'selected';
	else if(tabs[i].id != 'undefined')
		tabs[i].className = '';
  }
}
function show_tab( originalRequest ) {
   $('ajaxcontentarea').innerHTML = originalRequest.responseText;
}

//-->

//--></script>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
<!-- header //-->
<?php
  require(DIR_WS_INCLUDES . 'header.php');
  
  
  $smarty->assign('orders_status_storniert',ORDERS_STATUS_STORNIERT);
  $smarty->assign('orders_status_versendet',ORDERS_STATUS_VERSENDET);
  $smarty->assign('orders_status_abgeschlossen',ORDERS_STATUS_ABGESCHLOSSEN);
  
	if ( ($_GET['action'] == 'change_kasse_paymode') ) {
    $order = new order($oID);
	if( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['f_switch_kasse_payment'] == '1')){
		$order = new order($oID);
		$order_array = array('customer'=>$order->customer,
			'info'=>$order->info,
			'products'=>$order->products,
			'totals'=>$order->totals
		);  
		$smarty->assign('order',$order_array);
		$smarty->assign('change_kasse_paymode',1);
		$smarty->assign('kasse',$order->get_kasse_data());
		$smarty->assign('change_kasse_paymode_form',xtc_draw_form('kass','orders.php',xtc_get_all_get_params(array('action')).'action=save_kasse_paymode'));
		$paymode_array = array('bar'=>'Bar','ec'=>'EC');
		if( $admin_access['f_kasse_fibu_switch_paymentmethod_moneyorder'] == '1'){
			$paymode_array['bank']='Bank';
		}
		$smarty->assign('paymode_array',$paymode_array);
		$smarty->assign('backlink',xtc_href_link('orders.php',xtc_get_all_get_params(array('action')).'action=edit'));
		$html=$smarty->fetch('orders.html');
	}
  }
  if($_GET['action'] == 'change_kasse_paymode'){
	echo $html;
  }else if ( ($_GET['action'] == 'edit') && ($order_exists) ) {
	$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('tab_link_base','orders.php?'.xtc_get_all_get_params(array('tab')));
	$smarty->assign('select_set_link',xtc_href_link('orders_edit.php',xtc_get_all_get_params(array('edit_action')).'edit_action=select_set'));
	$smarty->assign('backlink','<a href="' . xtc_href_link(FILENAME_ORDERS, xtc_get_all_get_params(array('action'))) . '">' . xtc_image_button('button_back.gif', IMAGE_BACK) . '</a>');
		// 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'>");
			}
		}
	
	if($order->info['orders_status'] != ORDERS_STATUS_STORNIERT){
		if( ($order->info['orders_status'] != ORDERS_STATUS_VERSENDET and $order->info['orders_status'] != ORDERS_STATUS_ABGESCHLOSSEN) or ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['f_orders_edit_after_shipping'] == '1')){
			if($order->info['parent_orders_id']>0){
				// yes accounting
				if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['orders_update'] == '1')) {
					$smarty->assign('no_edit',1);
				}
			}else{
				// yes accounting
				if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['orders_edit'] == '1')) {
					if($order->info['orders_status'] == ORDERS_STATUS_BEZAHLT and $admin_access['f_change_order_if_status_bezahlt'] != '1'){
						$smarty->assign('button_orders_edit','<a href="javascript:alert(\'Rechnung hat Status Bezahlt - Sie haben keine Berechtigung einen Auftrag mit diesem Status zu bearbeiten.\');"><img src="'.DIR_WS_CATALOG.'lang/'.$_SESSION['language'].'/admin/images/buttons/button_edit.gif" border="0"></a>');
					}else{
						$smarty->assign('button_orders_edit','<a href="'.xtc_href_link(FILENAME_ORDERS_EDIT, xtc_get_all_get_params(array('cID')).'cID='.$order->customer['ID']).'"><img src="'.DIR_WS_CATALOG.'lang/'.$_SESSION['language'].'/admin/images/buttons/button_edit.gif" border="0"></a>');
					}
				}
			}
		}else{
			// yes accounting
			if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['orders_edit'] == '1')) {
				$smarty->assign('no_edit',1);
			}
		}
	}else{ // end if not storno
		// yes accounting
		if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['orders_edit'] == '1')) {
			$smarty->assign('no_edit',1);
		}
	}
	// yes accounting
	if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['f_customers_crm'] == '1')) {
		if($order->customer['ID'] != $kasseuser){
			$smarty->assign('crm_link','<a href="'.xtc_href_link(FILENAME_CUSTOMERS, 'cID=' . $order->customer['ID'].'&action=crm').'"><img src="'.DIR_WS_CATALOG.'lang/'.$_SESSION['language'].'/admin/images/buttons/button_crm.gif" border="0"></a>');
		}
	}
	if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['kasse'] == '1')) {
		// BEDINGUNG kasse abwickeln
		if($order->info['orders_status'] == ORDERS_STATUS_UPSELLING or $order->info['orders_status'] == '1' or $order->info['orders_status'] == '2' or $order->info['orders_status'] == ORDERS_STATUS_VERSENDET){
			if($order->info['select_set'] == '1' and $order->info['select_set_products_status'] == 0){
				$smarty->assign('kasse_set_error',1);
			}else{
				$smarty->assign('kasse_form',xtc_draw_form('kasse', 'kasse.php', 'action=choose_order').
					xtc_draw_hidden_field('order','y').
					xtc_draw_hidden_field('step','3').
					xtc_draw_hidden_field('cID',$order->customer['ID']).
					xtc_draw_hidden_field('orders_id[]',$order->info['id']));
			}
		}
	}

	// 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'));
			}
		}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('warning_span',$is_warn['warning_span']);
			}
		}		
	}
	
	$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'] ));

	$smarty->assign('EXT_POPUP_WIDTH',EXT_POPUP_WIDTH);
	$smarty->assign('EXT_POPUP_HEIGHT',EXT_POPUP_HEIGHT);
	$smarty->assign('HTML_PARAMS',HTML_PARAMS);

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

#################################### UOS START #######################################
  if( MODULE_PAYMENT_UOS_TRANSFER_STATUS == 'True' ){
  	require(DIR_FS_LANGUAGES . $_SESSION['language'] . '/admin/uos_orders.php');
  	if (isset($_SESSION['uos_error']) && $_SESSION['uos_error'] != ''){
    		$smarty->assign('UOS_ERROR', '<div style="border: 1px solid #000; background-color: #f00; color: #fff; font-family: verdana; font-size: 12px; padding: 10px">'.$_SESSION['uos_error'].'</div>');
    		unset($_SESSION['uos_error']);
  	}

	if($reserved){
	    // Reservierten Betrag anzeigen
	    $totals_value = $reserved_order['amount'];
	    $totals_euro = (int)($totals_value/100);
	    $totals_cent = sprintf('%02d', ($totals_value-($totals_euro*100)));
	    $price_sum = $order->totals[count($order->totals)-1]['text'];

	    $smarty->assign('UOS_HEADING',BOOKING_HEADING);
	    $smarty->assign('UOS_FORM',xtc_draw_form('status', FILENAME_ORDERS, xtc_get_all_get_params(array('action')) . 'action=book') );
	    $smarty->assign('UOS_INPUT_EURO',xtc_draw_input_field('uos_euro', $totals_euro, 'maxlenght="5" size="5" align="right"'));
	    $smarty->assign('UOS_INPUT_CENT',xtc_draw_input_field('uos_cent', $totals_cent, 'maxlenght="2" size="3"') );
	    $smarty->assign('BUTTON_BOOK',BUTTON_BOOK);
	}
  }
#################################### UOS END #######################################

	$html=$smarty->fetch('orders.html');
	echo $html;
  } elseif ($_GET['action'] == 'custom_action') {
	include('orders_actions.php');
  } else {
	if(TESTSYSTEM == 1){
		include('order_listing.php');
		exit;
	}
	$diff_payments_query = xtc_db_query("SELECT distinct(payment_method) FROM orders");
	$payment_methods = array();
	while($diff_payments = xtc_db_fetch_array($diff_payments_query)){
		$payment_methods[] = $diff_payments['payment_method'];
	}
?>
<table border="0" cellspacing="2" cellpadding="0" width="1000">
<tr>
	<td  class="boxCenter" width="100%" valign="top">
		<table border="0" width="100%" cellspacing="0" cellpadding="0">
      <tr>
        <td width="100%">

<table border="0" width="100%" cellspacing="0" cellpadding="0">
  <tr>
    <td class="pageHeading">Auftr&auml;ge</td>
    <td align="right">
              <?php 
	      // yes accounting
	      if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['f_orders_view'] == '1')) {
              ?>
     		
     		<table border="0" cellpadding="2" cellspacing="0">
              	<?php echo xtc_draw_form('orders', FILENAME_ORDERS, '', 'get'); ?>
     		<tr>
     			<td class="main">Re.-Nr: <?php echo xtc_draw_input_field('oID', '', 'size="12"') . xtc_draw_hidden_field('action', 'edit').xtc_draw_hidden_field(xtc_session_name(), xtc_session_id()); ?></td>
		     	<td class="main" align="right"><input type="image" src="images/icon_arrow_right.gif" border="0"></td>
	     	</tr>
                </form>
	     	</table>
	     	
              <?php
              }
              ?>
    </td>
  </tr>
  <tr>
    <td class="main" valign="top" align="right" colspan="2">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr>
     	<td class="main" align="right">
     		<table border="0" cellpadding="2" cellspacing="0">
     		<tr>
	     	<?php echo xtc_draw_form('status', FILENAME_ORDERS, '', 'get'); ?>
	     	<td class="main"><?php echo HEADING_TITLE_STATUS . ' ' . xtc_draw_pull_down_menu('status', $orders_statuses, (($_GET['status'])?$_GET['status']:ORDERS_STATUS_UPSELLING), 'onChange="this.form.submit();"').xtc_draw_hidden_field(xtc_session_name(), xtc_session_id()); ?></td>
	     	<td class="main" align="right"><input type="image" src="images/icon_arrow_right.gif" border="0"></td>
	     	</tr>
	        </form>
	     	</table>
     	</td>
    </tr>
    </table>
    </td>
</tr>
</table>
<script type="text/javascript" language="JavaScript">
<!--
 function toggle(){return false;}
//--></script>
<script type="text/javascript" language="JavaScript" src="includes/toggle.js"></script>
	
<table border="0" cellspacing="0" cellpadding="1" class="formArea" width="100%">
<script type="text/javascript" language="JavaScript"><!--
 // Hauptfunktionalitaet definieren
 function ShowAll() { toggle("unfold","tr","OS","HeadNone",true); }
 function ShowNone() { toggle("fold","tr","OS","HeadNone",true); toggle("fold","OSHeadTitle"); }

 // Interaktivitaet nur mit DHTML-Browser
 if(toggle()) {
  document.write('<tr><td colspan="7"><table border="0" cellspacing="2" cellpadding="0" width="100%" align="center">');
  // Befehlsfelder erstellen
  document.write(' <tr>');
  document.write('  <td style="cursor:pointer; cursor:hand;" onClick="ShowAll();" class="smallText"><u>Suchmaske einblenden</u><\/td>');
  document.write('  <td align=right style="cursor:pointer; cursor:hand;" onClick="ShowNone();" class="smallText"><u>Suchmaske ausblenden</u><\/td>');
  document.write(' <\/tr>');
  // Statusfelder erstellen
//  document.write(' <tr gid="OSHeadNone" style="display:none; color:#000000;"><th colspan="4">&nbsp;<\/th><\/tr>');
  document.write('<\/table><\/td><\/tr>');
 }
// --></script>
<?php echo xtc_draw_form('status', FILENAME_ORDERS, '', 'get'); ?>
<tr gid="OSBaseDOS">
<td class="smallText"><?php echo xtc_draw_input_field('search_ebayid', $_GET['search_ebayid'], '').xtc_draw_hidden_field(xtc_session_name(), xtc_session_id()).xtc_draw_hidden_field('status',$_GET['status']); ?></td><td class="smallText"><?php echo xtc_draw_input_field('searchbutton1', 'Auktionssuche', 'style="width:160px;"','','submit'); ?></td><td class="smallText"><i>Suche nach Ebaynummer</i></td>
</form>
<td width="50" align="center"><?php echo xtc_draw_separator('pixel_black.gif','1','15'); ?></td>
<?php echo xtc_draw_form('smail', FILENAME_ORDERS, '', 'get'); ?>
<td class="smallText"><?php echo xtc_draw_input_field('search_email', $_GET['search_email'], '').xtc_draw_hidden_field(xtc_session_name(), xtc_session_id()).xtc_draw_hidden_field('status',$_GET['status']); ?></td><td class="smallText"><?php echo xtc_draw_input_field('searchbutton2', 'Emailsuche', 'style="width:160px;"','','submit'); ?></td><td class="smallText"><i>Suche nach Emailadresse</i></td>
</form>
</tr>

<?php echo xtc_draw_form('status', FILENAME_ORDERS, '', 'get'); ?>
<tr gid="OSBaseUnix">
<td class="smallText"><?php echo xtc_draw_input_field('search_ebayuser', $_GET['search_ebayuser'], '').xtc_draw_hidden_field(xtc_session_name(), xtc_session_id()).xtc_draw_hidden_field('status',$_GET['status']); ?></td><td class="smallText"><?php echo xtc_draw_input_field('searchbutton3', 'Ebayusersuche', 'style="width:160px;"','','submit'); ?></td><td class="smallText"><i>Suche nach Ebayuser</i></td>
</form>
<td width="50" align="center"><?php echo xtc_draw_separator('pixel_black.gif','1','15'); ?></td>
<?php echo xtc_draw_form('sname', FILENAME_ORDERS, '', 'get'); ?>
<td class="smallText"><?php echo xtc_draw_input_field('search_user', $_GET['search_user'], '').xtc_draw_hidden_field(xtc_session_name(), xtc_session_id()).xtc_draw_hidden_field('status',$_GET['status']); ?></td><td class="smallText"><?php echo xtc_draw_input_field('searchbutton4', 'Kundensuche', 'style="width:160px;"','','submit'); ?></td><td class="smallText"><i>Suche nach Kundenname</i></td>
</form>
</tr>

<?php echo xtc_draw_form('searchp', FILENAME_ORDERS, '', 'get'); ?>
<tr gid="OSBaseApple">
<td class="smallText"><?php echo xtc_draw_input_field('search_product', $_GET['search_product'], '').xtc_draw_hidden_field(xtc_session_name(), xtc_session_id()).xtc_draw_hidden_field('status',$_GET['status']); ?></td><td class="smallText"><?php echo xtc_draw_input_field('searchbutton5', 'Produktsuche', 'style="width:160px;"','','submit'); ?></td><td class="smallText"><i>Suche nach Artikelname</i></td>
</form>
<td width="50" align="center"><?php echo xtc_draw_separator('pixel_black.gif','1','15'); ?></td>
<?php echo xtc_draw_form('searchprice', FILENAME_ORDERS, '', 'get'); ?>
<td class="smallText"><?php echo xtc_draw_input_field('search_price', $_GET['search_price'], '').xtc_draw_hidden_field(xtc_session_name(), xtc_session_id()).xtc_draw_hidden_field('status',$_GET['status']); ?></td><td class="smallText"><?php echo xtc_draw_input_field('searchbutton6', 'Preissuche', 'style="width:160px;"','','submit'); ?></td><td class="smallText"><i>Suche nach Preis (Format: 0.00)</i></td></tr>
</form>
</tr>

<?php echo xtc_draw_form('searchc', FILENAME_ORDERS, '', 'get'); ?>
<tr gid="OSBaseApple2">
<td class="smallText"><?php echo xtc_draw_input_field('search_company', $_GET['search_company'], '').xtc_draw_hidden_field(xtc_session_name(), xtc_session_id()).xtc_draw_hidden_field('status',$_GET['status']); ?></td><td class="smallText"><?php echo xtc_draw_input_field('searchbutton7', 'Firmensuche', 'style="width:160px;"','','submit'); ?></td><td class="smallText"><i>Suche nach Firmenname</i></td>
</form>
<td width="50" align="center"><?php echo xtc_draw_separator('pixel_black.gif','1','15'); ?></td>
<?php echo xtc_draw_form('search_pid', FILENAME_ORDERS, '', 'get'); ?>
<td class="smallText"><?php echo xtc_draw_input_field('search_pid', $_GET['search_pid'], '').xtc_draw_hidden_field(xtc_session_name(), xtc_session_id()).xtc_draw_hidden_field('status',$_GET['status']); ?></td><td class="smallText"><?php echo xtc_draw_input_field('searchbutton8', 'pID-Suche', 'style="width:160px;"','','submit'); ?></td><td class="smallText"><i>Suche nach Produktnummer (pID)</i></td></tr>
</form>
</tr>

<tr gid="OSBaseWIN2K">
	<td colspan="7" align="center" class="dataTableRowSelected">
		<a href="<?php echo xtc_href_link(FILENAME_ORDERS,'nongerman=1'); ?>"><u>Auslands-Rechnungen; nicht versendet</u></a>
		&nbsp;&nbsp;&nbsp;
		<a href="<?php echo xtc_href_link(FILENAME_ORDERS,'multi=1'); ?>"><u>Ebaybestellungen > 1 Artikel</u></a>
		&nbsp;&nbsp;&nbsp;
		<a href="#" onClick="window.open('orders.php?action=ext_search','popup','width=<?php echo EXT_POPUP_WIDTH; ?>,height=<?php echo EXT_POPUP_HEIGHT; ?>,resizable=yes,scrollbars=yes');"><u>Erw. Re.-produktsuche</u></a>
		&nbsp;&nbsp;&nbsp;
		<a href="#" onClick="window.open('orders.php?action=ext_search2','popup','width=<?php echo EXT_POPUP_WIDTH; ?>,height=<?php echo EXT_POPUP_HEIGHT; ?>,resizable=yes,scrollbars=yes');"><u>Erw. Re-adresssuche</u></a>
		&nbsp;&nbsp;&nbsp;
		<a href="#" onClick="window.open('orders.php?action=ext_search3','popup','width=<?php echo EXT_POPUP_WIDTH; ?>,height=<?php echo EXT_POPUP_HEIGHT; ?>,resizable=yes,scrollbars=yes');"><u>Kundengruppen-Filter</u></a>
		&nbsp;&nbsp;&nbsp;
		<a href="<?php echo xtc_href_link(FILENAME_ORDERS,'netto=1'); ?>"><u>Nettorechnungen</u></a>
	</td>
</tr>
</table>

<script type="text/javascript" language="JavaScript"><!--
 ShowAll();
//--></script>





<script language="javascript">
<!--
function quick_edit() {
	ok = confirm('Rechnung wirklich auf neuen Status setzen?');
	if(ok)
		document.forms['quickedit'].submit();
	else
		return false;
}

function subaction(){
	switch( document.forms['change_orders'].subact.value ){
		case 'combine':
			check_combines();
			break;
		case 'nosend':
			check_nosend();
			break;
	}
}

function check_orders() {
	anz_elem = document.forms['change_orders'].length;
	document.forms['change_orders'].orderaction[0].checked=true;
	klicks = 0;
	for(i=0;i<anz_elem;i++) {
		if(document.forms['change_orders'].elements[i].name == 'statusOID[]') 
			if(document.forms['change_orders'].elements[i].checked == true) 
				klicks++;
	}
	if(klicks > 0) {
		ok = confirm('Ausgewählte Rechnungen wirklich auf neuen Status setzen?');
		if(ok){
			document.forms['change_orders'].submit();
		}else{
			return false;
		}
	}else{
		alert('Sie haben keine Rechnungen gewaehlt');
		return false;
	}
}

function check_storno() {
	anz_elem = document.forms['change_orders'].length;
	klicks = 0;
	oid = '';
	for(i=0;i<anz_elem;i++) {
		if(document.forms['change_orders'].elements[i].name == 'statusOID[]') 
			if(document.forms['change_orders'].elements[i].checked == true) {
				klicks++;
				val = document.forms['change_orders'].elements[i].value;
				oid += 'oID[]='+val+'&';
			}
	}
	if(klicks > 0) {
		ok = confirm('Ausgewählte Rechnungen wirklich Stornieren?');
		if(ok){
			window.location.href='orders_storno.php?action=0&'+oid+'a=0';
		}else{
			return false;
		}
	}else{
		alert('Sie haben keine Rechnungen gewaehlt');
		return false;
	}
}

function check_combines() {
	anz_elem = document.forms['change_orders'].length;
	klicks = 0;
	for(i=0;i<anz_elem;i++) {
		if(document.forms['change_orders'].elements[i].name == 'statusOID[]') 
			if(document.forms['change_orders'].elements[i].checked == true) 
				klicks++;
	}
	if(klicks > 0) {
		ok = confirm('Ausgewaehlte Rechnungen wirklich zusammenfuehren?');
		if(ok){
			document.forms['change_orders'].submit();
		}else{
			return false;
		}
	}else{
		alert('Sie haben keine Rechnungen gewaehlt');
		return false;
	}
}

function check_nosend() {
	anz_elem = document.forms['change_orders'].length;
	klicks = 0;
	for(i=0;i<anz_elem;i++) {
		if(document.forms['change_orders'].elements[i].name == 'statusOID[]') 
			if(document.forms['change_orders'].elements[i].checked == true) 
				klicks++;
	}
	if(klicks > 0) {
		ok = confirm('Ausgewaehlte Rechnungen wirklich vom Versand ausschliessen?');
		if(ok){
			okcom = prompt("Aus welchem Grund werden die Rechnungen vom Versand ausgeschlossen?");
			if(okcom.length > 0){
				document.forms['change_orders'].temp_comment.value = okcom;
				document.forms['change_orders'].submit();
			}else{
				alert('Es muss ein Grund angegeben werden, warum die Rechnungen vom Versand ausgeschlossen werden sollen.');
			}
		}else{
			return false;
		}
	}else{
		alert('Sie haben keine Rechnungen gewaehlt');
		return false;
	}
}

function sum() {
	anz_elem = document.forms['change_orders'].length;
	oids = new Array();
	klicks = 0;
	
	total = 0;
	ship = 0;
	subtotal = 0;
	tax = 0;
	
	sum_total = 0;
	sum_ship = 0;
	sum_subtotal = 0;
	sum_tax = 0;
	
	for(i=0;i<anz_elem;i++) {
		if(document.forms['change_orders'].elements[i].name == 'statusOID[]') 
			if(document.forms['change_orders'].elements[i].checked == true) {
				oids[klicks] = document.forms['change_orders'].elements[i].value;
				klicks++;
			}
	}
	if(oids.length > 0) {
		out = '<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">';
		out += '<html <?php echo HTML_PARAMS; ?>>';
		out += '<head>';
		out += '<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $_SESSION['language_charset']; ?>">';
		out += '<title><?php echo TITLE; ?></title>';
		out += '<link rel=stylesheet type=text/css href=includes/stylesheet.css>';
		out += '</head>';
		out += '<body marginwidth=0 marginheight=0 topmargin=0 bottommargin=0 leftmargin=0 rightmargin=0 bgcolor=#FFFFFF>';
		out += "<table border=0 width=100% bgcolor=#000000 cellpadding=1 cellspacing=1>\r\n";
		out += "<tr bgcolor=#CACACA><th class=main>Re-Nr</th><th class=main>Zwischensumme</th><th class=main>MwSt</th><th class=main>Versand</th><th class=main>Total</th></tr>\r\n";
		for(i=0;i<oids.length;i++){
			act_oid = oids[i];
			eval("el = document.forms['change_orders'].ototal_"+act_oid+";");
			if(el.value > 0){
				total = (el.value*1);
				
				ship = 0;		
				for(b=0;b<20;b++){ // MAX 20 SHIPPINGS PRO ORDER
					eval("el = document.forms['change_orders'].oship_"+act_oid+"_"+b+";");
					if( el )				
						ship += (el.value*1);
				}
				
				eval("el = document.forms['change_orders'].osubtotal_"+act_oid+";");
				subtotal  = (el.value*1);
				
				eval("el = document.forms['change_orders'].otax_"+act_oid+";");
				if(el)
					tax  = (el.value*1);
				else
					tax = 0;
				
				out += "<tr bgcolor=white><td align=right>"+act_oid+"</td><td align=right>"+subtotal.toFixed(2)+"</td><td align=right>"+tax.toFixed(2)+"</td><td align=right>"+ship.toFixed(2)+"</td><td align=right>"+total.toFixed(2)+"</td></tr>\r\n";
				
				sum_total += total;
				sum_ship += ship;
				sum_subtotal += subtotal;
				sum_tax += tax;
			}
		}
		out += "<tr bgcolor=yellow><td align=right class=main><b>Summe:</b></td><td align=right class=main><b>"+sum_subtotal.toFixed(2)+"</b></td><td align=right class=main><b>"+sum_tax.toFixed(2)+"</b></td><td align=right class=main><b>"+sum_ship.toFixed(2)+"</b></td><td align=right class=main><b>"+sum_total.toFixed(2)+"</b></td></tr>\r\n";
		out += "</table>";
		out += "<br><br><div align=center><a href='javascript:window.close();'><u>Fenster schliessen</u></a></div>";
		out += '</body></html>';
		popup = window.open("","pop","width=<?php echo EXT_POPUP_WIDTH; ?>,height=<?php echo EXT_POPUP_HEIGHT; ?>,scrollbars=yes,resizable=yes");
		popup.document.write(out);
	}else{
		alert('Sie haben keine Rechnungen gewaehlt');
		return false;
	}
}
function filterPay(){
	var url = '<?php echo xtc_href_link('orders.php',xtc_get_all_get_params(array('payment_method'))); ?>';
	for(i=0;i<document.forms['change_orders'].length;i++){
		if(document.forms['change_orders'].elements[i].name == 'payment_method[]'){
			method_value = document.forms['change_orders'].elements[i].value;
			if(document.forms['change_orders'].elements[i].checked){
				url += '&payment_method[]='+method_value;
			}
		}
	}
	window.location.href=url;
}
//-->
</script>

        </td>
      </tr>
      <tr>
      	<?php 
        $status_query = xtc_db_query("SELECT os.* FROM orders_status os");
        while($status = xtc_db_fetch_array($status_query)){
	        if( $status['orders_status_id'] != ORDERS_STATUS_KOMBINIERT ) { // nicht kombinierte
			$status_array[] = array('id'=>$status['orders_status_id'],'text'=>$status['orders_status_name']);
        	}
	}

      	echo xtc_draw_form('change_orders',FILENAME_ORDERS,xtc_get_all_get_params(array('action')).'action=change_orders','POST'); ?>
        <td valign=top>
		<table border="0" width="100%" cellspacing="0" cellpadding="0">
		<tr>
			<td valign="top" class="main">
		<?php
		if(sizeOf($payment_methods)>0){
			echo 'Bezahlarten:&nbsp;';
			foreach($payment_methods as $k=>$v){
				if($_GET['payment_method']){
					if(is_array($_GET['payment_method']) and in_array($v,$_GET['payment_method']))	
						$checked = true;
					else
						$checked = false;
				}else{
					$checked = true;
				}
				if($v != '')
					echo xtc_draw_checkbox_field('payment_method[]',$v,$checked).$v.' ';
			}
			echo '<input type="button" value="Filter" onClick="filterPay();">';
		}
		?>
	      <table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr class="dataTableHeadingRow">
                <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_CUSTOMERS; ?></td>
                <td class="dataTableHeadingContent">Ebayuser</td>
                <td class="dataTableHeadingContent">Land</td>
                <td class="dataTableHeadingContent">W&auml;hrung</td>
                <td class="dataTableHeadingContent" align="right"><?php echo 'N°' ; ?></td>
                <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_ORDER_TOTAL; ?></td>
                <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_STATUS; ?></td>
		<?php
		if ($_GET['netto']=='1'){
		?>
                <td class="dataTableHeadingContent" align="right">Bezahlt am</td>
		<?php
		}
		?>
                <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_ACTION; ?>&nbsp;</td>
              </tr>
<?php
    if($_GET['payment_method']){
	$payment_sql = ' and ( ';
	for($i=0;$i<sizeOf($_GET['payment_method']);$i++){
		$payment_sql .= " payment_method='".xtc_db_input($_GET['payment_method'][$i])."' or ";
	}
	$payment_sql = substr($payment_sql,0,(strlen($payment_sql)-3));
	$payment_sql .= ' ) ';
    }else{
	$payment_sql = '';
    }
    if ($_GET['cID']) {
      $cID = xtc_db_prepare_input($_GET['cID']);
      $orders_query_raw = "select distinct o.orders_id,o.customers_country,o.currency from " . TABLE_ORDERS . " o where customers_id = '" . xtc_db_input($cID) . "' ".$payment_sql." order by orders_id DESC";
    } elseif ($_GET['status'] && !$_GET['search_ebayid'] && !$_GET['search_ebayuser'] && !$_GET['search_product'] && !$_GET['search_price'] && !$_GET['search_user'] && !$_GET['search_email'] && !$_GET['search_pid'] && $_GET['nongerman']!='1' && $_GET['multi']!='1' && $_GET['netto']!='1') {
      $status = xtc_db_prepare_input($_GET['status']);
      $orders_query_raw = "select distinct o.orders_id,o.customers_country,o.currency from " . TABLE_ORDERS . " o where o.orders_status = '" . xtc_db_input($status) . "' ".$payment_sql." order by o.orders_id DESC";
    } elseif ($_GET['search_ebayid'] and $_GET['nongerman'] != 1 and $_GET['multi'] != 1 && $_GET['netto']!='1') {
      $orders_query_raw = "select distinct o.orders_id,o.customers_country,o.currency from " . TABLE_ORDERS . " o where o.ebay_id LIKE '%".xtc_db_prepare_input($_GET['search_ebayid'])."%' ".$payment_sql." order by o.orders_id DESC";
    } elseif ($_GET['search_ebayuser'] and $_GET['nongerman'] != 1 and $_GET['multi'] != 1 && $_GET['netto']!='1') {
      $orders_query_raw = "select distinct o.orders_id,o.customers_country,o.currency from " . TABLE_ORDERS . " o, customers c where o.customers_id=c.customers_id and c.customers_ebay_userid LIKE '%".$_GET['search_ebayuser']."%'  ".$payment_sql."  order by o.orders_id DESC";
    } elseif ($_GET['search_product'] and $_GET['nongerman'] != 1 and $_GET['multi'] != 1 && $_GET['netto']!='1') {
      $orders_query_raw = "select distinct o.orders_id,o.customers_country,o.currency from " . TABLE_ORDERS . " o,orders_products op where op.products_name LIKE '%".xtc_db_input($_GET['search_product'])."%' and o.orders_id=op.orders_id  ".$payment_sql."  order by o.orders_id DESC";
    } elseif ($_GET['search_price'] and $_GET['nongerman'] != 1 and $_GET['multi'] != 1 && $_GET['netto']!='1') {
      $orders_query_raw = "select distinct o.orders_id,o.customers_country,o.currency from " . TABLE_ORDERS . " o,orders_total ot where ot.value = '".xtc_db_input($_GET['search_price'])."' and o.orders_id=ot.orders_id and ot.class = 'ot_total'  ".$payment_sql." order by o.orders_id DESC";
    } elseif ($_GET['search_user'] and $_GET['nongerman'] != 1 and $_GET['multi'] != 1 && $_GET['netto']!='1') {
      $orders_query_raw = "select distinct o.orders_id,o.customers_country,o.currency from " . TABLE_ORDERS . " o where o.customers_name like '%".$_GET['search_user']."%' or o.billing_name like '%".$_GET['search_user']."%' or o.delivery_name like '%".$_GET['search_user']."%' ".$payment_sql." order by o.orders_id DESC";
    } elseif ($_GET['search_email'] and $_GET['nongerman'] != 1 and $_GET['multi'] != 1 && $_GET['netto']!='1') {
      $orders_query_raw = "select distinct o.orders_id,o.customers_country,o.currency from " . TABLE_ORDERS . " o where o.customers_email_address LIKE '%".$_GET['search_email']."%' ".$payment_sql." order by o.orders_id DESC";
    } elseif ($_GET['search_company'] and $_GET['nongerman'] != 1 and $_GET['multi'] != 1 && $_GET['netto']!='1') {
      $orders_query_raw = "select distinct o.orders_id,o.customers_country,o.currency from " . TABLE_ORDERS . " o where (o.customers_company LIKE '%".$_GET['search_company']."%' || o.billing_company LIKE '%".$_GET['search_company']."%' || o.delivery_company LIKE '%".$_GET['search_company']."%') ".$payment_sql."  order by o.orders_id DESC";
    } elseif ($_GET['search_pid'] and $_GET['nongerman'] != 1 and $_GET['multi'] != 1 && $_GET['netto']!='1') {
      $orders_query_raw = "select distinct o.orders_id,o.customers_country,o.currency from " . TABLE_ORDERS . " o,orders_products op where op.products_id='".xtc_db_input($_GET['search_pid'])."' and op.orders_id=o.orders_id ".$payment_sql."  order by o.orders_id DESC";
    } elseif ($_GET['nongerman'] and $_GET['multi'] != 1 && $_GET['netto']!='1') {
      // NEUEN STATUS VERSENDET VERWENDEN FUER BEZAHLUNG PER RECHNUNG
      $store_country_name = xtc_get_country_name(STORE_COUNTRY);
      $orders_query_raw = "select distinct o.orders_id,o.customers_country,o.currency from " . TABLE_ORDERS . " o where o.delivery_country != '".$store_country_name."' and (o.orders_status='1' or o.orders_status='2' or o.orders_status='".ORDERS_STATUS_UPSELLING."' or o.orders_status='".ORDERS_STATUS_BEZAHLT."' or o.orders_status='".ORDERS_STATUS_VERSENDET."') ".$payment_sql."  order by o.date_purchased DESC";
    } elseif ( $_GET['multi'] == 1 && $_GET['netto']!='1' ){
      // NEUEN STATUS VERSENDET VERWENDEN FUER BEZAHLUNG PER RECHNUNG
      $orders_query_raw = "select distinct o.orders_id,o.customers_country,o.currency from " . TABLE_ORDERS . " o, orders_products op where o.orders_id = op.orders_id and op.products_quantity > 1 and o.ebay_id != '' and (o.orders_status='1' or o.orders_status='2' or o.orders_status='".ORDERS_STATUS_UPSELLING."' or o.orders_status='".ORDERS_STATUS_BEZAHLT."' or o.orders_status='".ORDERS_STATUS_VERSENDET."') ".$payment_sql."  order by o.date_purchased DESC";
    } else if ($_GET['netto']=='1'){
      // NEUEN STATUS VERSENDET VERWENDEN FUER BEZAHLUNG PER RECHNUNG
      $orders_query_raw = "select distinct o.orders_id,o.customers_country,o.currency from " . TABLE_ORDERS . " o, orders_products op where op.allow_tax = 0 and o.orders_id=op.orders_id and (o.orders_status='1' or o.orders_status='2' or o.orders_status='".ORDERS_STATUS_UPSELLING."' or o.orders_status='".ORDERS_STATUS_BEZAHLT."' or o.orders_status='".ORDERS_STATUS_VERSENDET."' or o.orders_status='".ORDERS_STATUS_ABGESCHLOSSEN."') ".$payment_sql."  order by o.date_purchased DESC";
    } else {
      $orders_query_raw = "select distinct o.orders_id,o.customers_country,o.currency from " . TABLE_ORDERS . " o where o.orders_status = '".ORDERS_STATUS_UPSELLING."' ".$payment_sql."  order by o.orders_id DESC";
    }
    
    $get_payment_method = '';
    if($_GET['payment_method'] and is_array($_GET['payment_method'])){
	foreach($_GET['payment_method'] as $pk=>$pay){
		$get_payment_method .= '&payment_method'.urlencode('[]').'='.$pay;
	}
    }

    $orders_split = new splitPageResults($_GET['page'], MAX_DISPLAY_SEARCH_RESULTS, $orders_query_raw, $orders_query_numrows);
    
    $orders_query = xtc_db_query($orders_query_raw);
    while ($orders = xtc_db_fetch_array($orders_query)) {
      if (((!$_GET['oID']) || ($_GET['oID'] == $orders['orders_id'])) && (!$oInfo)) {
        $oInfo = new objectInfo($orders);
	echo xtc_draw_hidden_field('start_oID',$orders['orders_id']);
      }

	/* link = <a href="<?php echo xtc_href_link(FILENAME_ORDERS, xtc_get_all_get_params(array('oID','payment_method')) . 'oID=' . $orders['orders_id'].$get_payment_method); ?>"*/
        echo '              <tr id="trid_'.$orders['orders_id'].'" class="dataTableRow" onmouseover="rowStyle(\'over\',\''.$orders['orders_id'].'\');" onmouseout="rowStyle(\'out\',\''.$orders['orders_id'].'\');" onClick="ajax_show_order_details(\''.$orders['orders_id'].'\');">' . "\n";
			$shippings = 0;
			$total_sum = 0;
			$order = new order($orders['orders_id']);
			if ($_GET['netto']=='1'){
				$bezahlt_query = xtc_db_query("SELECT date_added FROM orders_status_history WHERE orders_status_id='".ORDERS_STATUS_BEZAHLT."' and orders_id='".$orders['orders_id']."' ORDER BY date_added LIMIT 1");
				$bezahlt = xtc_db_fetch_array($bezahlt_query);
				if($order->info['orders_status'] == ORDERS_STATUS_BEZAHLT or $order->info['orders_status'] == ORDERS_STATUS_VERSENDET or $order->info['orders_status'] == ORDERS_STATUS_ABGESCHLOSSEN)
					$bezahldatum = ($bezahlt['date_added'] != '' and $bezahlt['date_added'] != '0000-00-00 00:00:00') ? strftime('%d.%m.%Y',strtotime($bezahlt['date_added'])) : strftime('%d.%m.%Y',strtotime($order->info['date_purchased']));
				else
					$bezahldatum = '';
			}
?>
                <td class="dataTableContent"><?php echo xtc_draw_checkbox_field('statusOID[]',$orders['orders_id']).'&nbsp;&nbsp;<a href="' . xtc_href_link(FILENAME_ORDERS, xtc_get_all_get_params(array('oID', 'action')) . 'oID=' . $orders['orders_id'] . '&action=edit') . '">' . xtc_image(DIR_WS_ICONS . 'preview.gif', ICON_PREVIEW) . '</a>&nbsp;<a href="'.xtc_href_link(FILENAME_ORDERS, xtc_get_all_get_params(array('oID','payment_method')) . 'oID=' . $orders['orders_id'].$get_payment_method).'">['.$order->customer['ID'].'] ' . $order->customer['name']; ?></a>&nbsp;</td>
		<?php
			for($a=0;$a<sizeOf($order->totals);$a++){
				switch($order->totals[$a]['class']){
					case 'ot_total':
						echo xtc_draw_hidden_field('ototal_'.$orders['orders_id'],$order->totals[$a]['value'] );
						$total_sum = number_format($order->totals[$a]['value'],2,',','');
						break;
					case 'ot_tax':
						echo xtc_draw_hidden_field('otax_'.$orders['orders_id'],$order->totals[$a]['value'] ); 
						break;
					case 'ot_shipping':
						echo xtc_draw_hidden_field('oship_'.$orders['orders_id'].'_'.$shippings,$order->totals[$a]['value'] ); 
						$shippings++;
						break;
					case 'ot_subtotal':
						echo xtc_draw_hidden_field('osubtotal_'.$orders['orders_id'],$order->totals[$a]['value'] ); 
						break;
				}
			}
		$customer_ebay_query = xtc_db_query("SELECT customers_ebay_userid FROM customers WHERE customers_id='".xtc_db_input($order->customer['ID'])."'");
		$customer_ebay = xtc_db_fetch_array($customer_ebay_query);
		
		?>
                <td class="dataTableContent"><?php echo $customer_ebay['customers_ebay_userid']; ?>&nbsp;</td>
                <td class="dataTableContent"><?php echo $orders['customers_country']; ?>&nbsp;</td>
                <td class="dataTableContent"><?php echo $orders['currency']; ?>&nbsp;</td>
              	<td class="dataTableContent" align="right"><?php echo $orders['orders_id'].(($order->info['ebay_id']!='') ? '<br><i>('.$order->info['ebay_id'].')</i>' : '');?></td>
                <td class="dataTableContent" align="right"><?php echo $total_sum; ?>&nbsp;</td>
                <td class="dataTableContent" align="right"><?php echo xtc_get_orders_status_name($order->info['orders_status']); ?>&nbsp;</td>
                <?php if ($_GET['netto']=='1'){ ?>
		<td class="dataTableContent"><?php echo $bezahldatum; ?>&nbsp;</td>
                <?php } ?>
		<td class="dataTableContent" align="right"><?php if ( (is_object($oInfo)) && ($orders['orders_id'] == $oInfo->orders_id) ) { echo xtc_image(DIR_WS_IMAGES . 'icon_arrow_right.gif', ''); } else { echo '<a href="' . xtc_href_link(FILENAME_ORDERS, xtc_get_all_get_params(array('oID')) . 'oID=' . $orders['orders_id']) . '">' . xtc_image(DIR_WS_IMAGES . 'icon_info.gif', IMAGE_ICON_INFO) . '</a>'; } ?>&nbsp;</td>
              </tr>
<?php
    }
?>


              <tr>
                <td colspan="<?php echo ($_GET['netto']=='1') ? '9' : '8'; ?>" class="main"><br>
			<table border="0" width="100%" cellspacing="0" cellpadding="2">
			<tr>
				<?php
				// yes accounting
				if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['orders_storno'] == '1')) {
				?>
				
				<?php if($_GET['status'] != ORDERS_STATUS_STORNIERT) { ?>
				<td class="smallText" align="center" bgcolor="#AAAAAA">
					<b>Ausgew&auml;hlte Rechnung(en) stornieren.</b><br>
					<?php
					echo xtc_draw_input_field('storno','Stornieren','onClick="check_storno();"','','button');
					?>
				</td>
				<?php
				}
				?>
				<?php
				} // end yes accounting
				?>
				<?php	if($_GET['cID'] > 0){	?>
				<?php echo xtc_draw_hidden_field('orderaction','combine',true); ?>
				<td bgcolor="#DDDDDD" class="main" align=center>
					<b>Berechnen der Gesamtsumme</b><br>
					<?php echo xtc_draw_input_field('csum','Berechnen','onClick="sum();"','','button'); ?><br>
					<font size="1">
					Markieren Sie Rechnungen um die Gesamtsumme anzuzeigen.
					</font>
				</td><td width="50%" bgcolor="#AAAAAA" class="main" align="center">
					<?php
					$action_array = array(0=>array('id'=>'','text'=>'Ausgewählte Rechnungen'));
					// yes accounting
					if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['combined_orders'] == '1')) {
						$action_array[] = array('id'=>'combine','text'=>'Rechnungen Kombinieren');
					}
					$action_array[] = array('id'=>'nosend','text'=>'Vom Versand ausschliessen');
					if(sizeOf($action_array)>1){
						echo xtc_draw_hidden_field('temp_comment');
						echo xtc_draw_pull_down_menu('subact',$action_array,'','onChange="subaction();"'); 
					?>
						
						<br>
					
						<table border="0" cellspacing="0">
						<tr bgcolor="#000000">
							<td class="main" align="center"><font color="#FFFFFF"><b>Achtung:</b></td>
						</tr><tr bgcolor="#9c9c9c">
							<td class="smallText">
							Nur Rechnungen die <b>nicht</b> versendet, storniert, kombiniert und <b>nicht</b> selbst kombinierte Rechnungen enthalten k&ouml;nnen kombiniert werden.<br>
							<br><?php echo xtc_draw_separator('pixel_black.gif'); ?><br><br>
							Bei Versandsperren k&ouml;nnen selbstverst&auml;ndlich nur Rechnungen ber&uuml;cksichtigt werden, die den Status <b>Offen, In Bearbeitung, Ebay Upselling</b> oder <b>Bezahlt</b> haben.
							</td>
						</tr>
						</table>
						
						<?php
					}else{
						echo '&nbsp;';
					}
					?>
				</td>
				<?php
				}
				?>
			</form>
			</tr>
			
			<tr>
				<td colspan="4" align=center class="smallText" valign="top">
					<br>
					<?php
					echo $orders_split->display_count($orders_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, $_GET['page'], TEXT_DISPLAY_NUMBER_OF_ORDERS,xtc_get_all_get_params(array('page', 'oID', 'action','payment_method')).$get_payment_method); 
					?>
					<?php 
					echo $orders_split->display_links($orders_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $_GET['page'], xtc_get_all_get_params(array('page', 'oID', 'action','payment_method')).$get_payment_method);
					?>
				</td>
			</tr>
			</table>
        	      <br><br>
		</td>
        </tr>
        </table>
</td>
           
<?php
  $heading = array();
  $contents = array();
  switch ($_GET['action']) {
    case 'delete':
      $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_DELETE_ORDER . '</b>');
      $contents = array('form' => xtc_draw_form('orders', FILENAME_ORDERS, xtc_get_all_get_params(array('oID', 'action')) . 'oID=' . $oInfo->orders_id . '&action=deleteconfirm'));
      $contents[] = array('text' => TEXT_INFO_DELETE_INTRO . '<br><br><b>' . $cInfo->customers_firstname . ' ' . $cInfo->customers_lastname . '</b>');
      $contents[] = array('text' => '<br>' . xtc_draw_checkbox_field('restock') . ' ' . TEXT_INFO_RESTOCK_PRODUCT_QUANTITY);
      $contents[] = array('align' => 'center', 'text' => '<br>' . xtc_image_submit('button_delete.gif', IMAGE_DELETE) . ' <a href="' . xtc_href_link(FILENAME_ORDERS, xtc_get_all_get_params(array('oID', 'action')) . 'oID=' . $oInfo->orders_id) . '">' . xtc_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
      break;
    default:
	echo '            <td width="25%" valign="top">' . "\n";
	echo '<div id="orderdetails" style="z-index:0;position:absolute;width:250px;font-family:arial,helvetica,sans-serif;font-size:10px;"></div>';
	echo '            </td>' . "\n";
	break;
  }

  if ( (xtc_not_null($heading)) && (xtc_not_null($contents)) ) {
    echo '            <td width="25%" valign="top">' . "\n";

    $box = new box;
    echo $box->infoBox($heading, $contents);

    echo '            </td>' . "\n";
  }
?>
          </tr>
        </table></td>
      </tr>
<?php
  }
?>
    </table></td>
<!-- body_text_eof //-->
  </tr>
</table>
<br>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
