<?php
require('includes/application_top.php');
require(DIR_FS_ADMIN.'includes/classes/order.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_INC . 'xtc_is_shipping_before_payment.inc.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);

      	$order = new order(xtc_db_input($_GET['oID']));
        $heading[] = array('text' => '<b>Re-Nr: ' . $order->info['id'] . ' vom &nbsp;' . xtc_date_short($order->info['date_purchased']) . '</b>');
	
	if($order->info['is_parent'] == 'y'){
		$parent_ebay_query = xtc_db_query("SELECT ebay_id FROM orders WHERE parent_orders_id='".$order->info['id']."'");
		while($parent_ebay = xtc_db_fetch_array($parent_ebay_query)){
			if($parent_ebay['ebay_id'] != '')
				$pEbay[] = $parent_ebay['ebay_id'];
		}
	}else{
		if($order->info['ebay_id'] != '')
			$pEbay[] = $order->info['ebay_id'];
	}
	
	$ebays='<br><b>Ebay-Auktion:</b>';
	for($eb=0;$eb<sizeOf($pEbay);$eb++){
		$ebays .= '<br><a target="_blank" href="'.xtc_get_ebay_link(xtc_get_auction_site($pEbay[$eb])).$pEbay[$eb].'">'.$pEbay[$eb]."</a>";
	}

	// yes accounting
	if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['f_orders_view'] == '1')) {
        	$contents[] = array('align' => 'center', 'text' => '<a href="' . xtc_href_link(FILENAME_ORDERS, xtc_get_all_get_params(array('oID', 'action')) . 'oID=' . $order->info['id'] . '&action=edit') . '">' . xtc_image_button('button_edit.gif', IMAGE_EDIT) . '</a>');
        }
	if ( ($_SESSION['customers_status']['customers_status_id'] == '0') && ($admin_access['f_customers_crm'] == '1')) {
        	$contents[] = array('align' => 'center', 'text' => '<a href="' . xtc_href_link(FILENAME_CUSTOMERS, xtc_get_all_get_params(array('cID', 'action')) . 'cID=' . $order->customer['ID'] . '&action=crm') . '">' . xtc_image_button('button_crm.gif', 'CRM zum Kunden') . '</a>');
        }
	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) ) ){
        		$contents[] = array('align' => 'center', 'text' => '<input class="iButton" type="button" onCLick="window.location.href=\'' . xtc_href_link('otc.php', xtc_get_all_get_params(array('cID', 'action','oID')).'oID='.$order->info['id']) . '\';" value="Warenausgabe" style="width:120px;">');
		}
        }
	
	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){
  			$contents[] = array('align'=>'center','text' => 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']).xtc_image_submit('button_quick_cash.gif','Per Kasse abwickeln').'</form>'
				);
		}
        }
	if(sizeOf($pEbay)>0)
        	$contents[] = array('text' => $ebays);
        
	if($order->info['ebay_no_shippingaddress'] == '1'){
		$contents[] = array('align' => 'left', 'text' => '<p><b>EBAY-API Bug:</b>&nbsp;<font color="#FF0000">Versandadresse wurde von Ebay nicht &uuml;bergeben und wurde durch Rechnungsadresse ersetzt.</font></p><br>');
	}
        $contents[] = array('align' => 'left', 'text' => '<b>Name:</b> '.$order->customer['name']);
        $contents[] = array('align' => 'left', 'text' => '<a href="' . xtc_href_link(FILENAME_ORDERS, 'cID=' . $order->customer['ID']). '"><u>Alle Rechnungen des Kunden</u></a>');

        //$contents[] = array('align' => 'center', 'text' => '');

        $contents[] = array('text' => '<b>Angelegt:</b> ' . xtc_date_short($order->info['date_purchased']));
        if (xtc_not_null($order->info['last_modified']) and $order->info['last_modified'] > 0) $contents[] = array('text' => '<b>Letzte &Auml;nderung:</b>' . ' ' . xtc_date_short($order->info['last_modified']));
        $contents[] = array('text' => '<b>Bezahlart:</b> '  . $order->info['payment_method']);
        // elari added to display product list for selected order
        
	$contents[] = array('text' => '<br><br>' . sizeof($order->products) . ' Products ' );
        for ($i=0; $i<sizeof($order->products); $i++) {
          $contents[] = array('text' => $order->products[$i]['qty'] . '&nbsp;x' . $order->products[$i]['name']);

          if (sizeof($order->products[$i]['attributes']) > 0) {
            for ($j=0; $j<sizeof($order->products[$i]['attributes']); $j++) {
              $contents[] = array('text' => '<small>&nbsp;<i> - ' . $order->products[$i]['attributes'][$j]['option'] . ': ' . $order->products[$i]['attributes'][$j]['value'] . '</i></small></nobr>' );
            }
          }
        }
	
        $contents[] = array('text' => '<br><b>Rechnungsbetrag</b>');
        for ($i=0; $i<sizeof($order->totals); $i++) {
          $contents[] = array('text' => $order->totals[$i]['title'] . ':&nbsp;' . $order->totals[$i]['text']);
        }
        // elari End add display products
       
//        $contents[] = array('text' => '<br><br><b>Rechnungsstatus &auml;ndern</b><br><i>Bei diesem Vorgang werden keine Emails an Kunden versendet.</i>' );
        
    $box = new box;
    header('Content-Type: text/html; charset=iso-8859-1');
    echo $box->infoBox($heading, $contents);
?>
