<?php
function xtc_get_packingslip_html_for_pdf($order,$smarty,$template,$lagerplaetze=false){
		$order_query_check = xtc_db_query("SELECT
							customers_id
							FROM ".TABLE_ORDERS."
							WHERE orders_id='".$order->info['id']."'");
							
		$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']);
		$smarty->assign('cID',$order->customer['ID']);
		if(BARCODE_PACKINGSLIP_ACTIVE == 'True'){
			$img_path = xtc_generate_packingslip_barcode($order->info['id'],DIR_FS_ADMIN.'exportdata/');
			$smarty->assign('BARCODE','<img src="'.HTTP_SERVER.'admin/exportdata/BARCODE_'.$img_path.'" border="0">');
		}
		// 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='".$order->info['id']."'");
		}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='".$order->info['id']."' && 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']);
			}
			$collies = xtc_get_product_collies($order_data_values['products_id']);
			// show product collis
			$product_colli_array = false;
			if(sizeOf($collies)>0){
				$product_colli_array = array();
				foreach($collies as $ck=>$cv){
					$product_colli_array[] = array( 'pID'=>$cv['collie_products_id'],'qty'=>($cv['quantity']*$order_data_values['products_quantity']),'name'=>xtc_get_products_name( $cv['collie_products_id'] ) );
				}
			}
			if($lagerplaetze){
				$storages = array();
				if(sizeOf($collies)>0){
					foreach($collies as $ck=>$collie){
						$storage_query = xtc_db_query("SELECT s.name,sp.storage_place,sn.nummer FROM storage_products sp LEFT JOIN storage_numbers sn USING(storage_id,products_id),storages s WHERE sp.products_id='".$collie['collie_products_id']."' and sp.storage_id=s.id");
						while($storage = xtc_db_fetch_array($storage_query)){
							$storage['name'] = '(Colli aus pID '.$collie['collie_products_id'].') '.$storage['name'];
							$storages[] = xtc_db_prepare_input($storage);
						}
					}
				}else{
					$storage_query = xtc_db_query("SELECT s.name,sp.storage_place,sn.nummer FROM storage_products sp LEFT JOIN storage_numbers sn USING(storage_id,products_id),storages s WHERE sp.products_id='".$order_data_values['products_id']."' and sp.storage_id=s.id");
					while($storage = xtc_db_fetch_array($storage_query)){
						$storages[] = xtc_db_prepare_input($storage);
					}
				}
			}else{
				$storages = false;
			}
			
			$order_data[]=array(
				'COLLIES'=>$product_colli_array,
				'PRODUCTS_STORAGES'=>$storages,
				'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']);
		}
		
		// 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',$order->info['id']);

		$ebay_seller = xtc_get_orders_ebay_seller($order->info['id']);
		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') {
			if(is_file(DIR_FS_CATALOG.'lang/'.$_SESSION['language'].'/modules/payment/'.$order->info['payment_method'].'.php')){
				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'));
			}else{
				$payment_method = $order->info['payment_method'];
			}
			$smarty->assign('PAYMENT_METHOD',$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);
		$pdf_html=$smarty->fetch($template);
		return $pdf_html;
}
?>
