<?php
/*
	 
	
Freeway eCommerce
http://www.openfreeway.org
Copyright (c) 2007 ZacWare
	
	Released under the GNU General Public License
*/
////
// Return true if the events category has subcategories
// TABLES: events_categories
// use condition in all event status checking 
// Check to ensure this file is included in Freeway!
defined('_FEXEC') or die();
//set_time_limit(30);
//italy functions to get date and time of deadlines, time limit etc
//get the topmost category and grab any deadline date, you can
//get it as YMD or DMY or however
function deadline_date($the_product_id, $switch = '%Y-%m-%d'){
   $cat_string = italy_get_product_path($the_product_id); 
   $pieces = split("_", $cat_string);
   //$pieces[0] is the top cat_id
   if ($pieces[0] && is_numeric ($pieces[0])){
     
   					$italy_query=tep_db_query("select date_format(categories_deadline,'".$switch."') 
					                          as date_deadline  from " . TABLE_CATEGORIES . " 
											  where categories_id='" . tep_db_input($pieces[0]) . "'");
					if(tep_db_num_rows($italy_query)>0) {
							$italy_result=tep_db_fetch_array($italy_query);
							return $italy_result['date_deadline'];
						}else{
						     return 0;
						}
   
   
   }else{
     return 0;
   }
   }
function deadline($the_product_id){
   $cat_string = italy_get_product_path($the_product_id); 
   $pieces = split("_", $cat_string);
   //$pieces[0] is the top cat_id
   if ($pieces[0] && is_numeric ($pieces[0])){
     
   					$italy_query=tep_db_query("select categories_deadline
					                          as date_deadline  from " . TABLE_CATEGORIES . " 
											  where categories_id='" . tep_db_input($pieces[0]) . "'");
					if(tep_db_num_rows($italy_query)>0) {
							$italy_result=tep_db_fetch_array($italy_query);
							return $italy_result['date_deadline'];
						}else{
						     return 0;
						}
   
   
   }else{
     return 0;
   }
   }
   
   function reminder($the_product_id){
   $cat_string = italy_get_product_path($the_product_id); 
   $pieces = split("_", $cat_string);
   //$pieces[0] is the top cat_id
   if ($pieces[0] && is_numeric ($pieces[0])){
     
   					$italy_query=tep_db_query("select categories_xsms_reminder
					                          as categories_reminder  from " . TABLE_CATEGORIES . " 
											  where categories_id='" . tep_db_input($pieces[0]) . "'");
					if(tep_db_num_rows($italy_query)>0) {
							$italy_result=tep_db_fetch_array($italy_query);
							return $italy_result['categories_reminder'];
						}else{
						     return 0;
						}
   
   
   }else{
     return 0;
   }
   }
   
   function orders_xsms($the_product_id){
   global $italy_result;
   $cat_string = italy_get_product_path($the_product_id); 
   $pieces = split("_", $cat_string);
   //$pieces[0] is the top cat_id
   if ($pieces[0] && is_numeric ($pieces[0])){
     
   					$italy_query=tep_db_query("select categories_xsms_title, categories_xsms_email, categories_xsms_call_centre, categories_xsms_signature, categories_xsms_payment from " . TABLE_CATEGORIES . "  where categories_id='" . tep_db_input($pieces[0]) . "'");
					if(tep_db_num_rows($italy_query)>0) {
							$italy_result=tep_db_fetch_array($italy_query);
							return $italy_result;
						}else{
						     return 0;
						}
   
   
   }else{
     return 0;
   }
   }
function deadline_time($the_product_id){
   $cat_string = italy_get_product_path($the_product_id); 
   $pieces = split("_", $cat_string);
   //$pieces[0] is the top cat_id
   if ($pieces[0] && is_numeric ($pieces[0])){
     
   					$italy_query=tep_db_query("select date_format(categories_deadline,'%H:%i') 
					                          as time_deadline  from " . TABLE_CATEGORIES . " 
											  where categories_id='" . tep_db_input($pieces[0]) . "'");
					if(tep_db_num_rows($italy_query)>0) {
							$italy_result=tep_db_fetch_array($italy_query);
							return $italy_result['time_deadline'];
						}else{
						     return 0;
						}
   
   
   }else{
     return 0;
   }
   }
function time_limit($the_product_id){
   $cat_string = italy_get_product_path($the_product_id); 
   $pieces = split("_", $cat_string);
   //$pieces[0] is the top cat_id
   if ($pieces[0] && is_numeric ($pieces[0])){
     
   					$italy_query=tep_db_query("select categories_time_limit 
					                          as time_deadline  from " . TABLE_CATEGORIES . " 
											  where categories_id='" . tep_db_input($pieces[0]) . "'");
					if(tep_db_num_rows($italy_query)>0) {
							$italy_result=tep_db_fetch_array($italy_query);
							return $italy_result['time_deadline'];
						}else{
						     return 0;
						}
   
   
   }else{
     return 0;
   }
   }
   
   function time_limit_datetime($the_product_id){
   $cat_string = italy_get_product_path($the_product_id); 
   $pieces = split("_", $cat_string);
   //$pieces[0] is the top cat_id
   if ($pieces[0] && is_numeric ($pieces[0])){
     
   					$italy_query=tep_db_query("select categories_time_limit_datetime 
					                          as time_deadline  from " . TABLE_CATEGORIES . " 
											  where categories_id='" . tep_db_input($pieces[0]) . "'");
					if(tep_db_num_rows($italy_query)>0) {
							$italy_result=tep_db_fetch_array($italy_query);
							return $italy_result['time_deadline'];
						}else{
						     return 0;
						}
   
   
   }else{
     return 0;
   }
   }
   
   
   
   function manual_time_limit($the_product_id){
   $cat_string = italy_get_product_path($the_product_id); 
   $pieces = split("_", $cat_string);
   //$pieces[0] is the top cat_id
   if ($pieces[0] && is_numeric ($pieces[0])){
     
   					$italy_query=tep_db_query("select categories_time_limit_datetime 
					                          as time_deadline  from " . TABLE_CATEGORIES . " 
											  where categories_id='" . tep_db_input($pieces[0]) . "'");
					if(tep_db_num_rows($italy_query)>0) {
							$italy_result=tep_db_fetch_array($italy_query);
							return $italy_result['time_deadline'];
						}else{
						     return 0;
						}
   
   
   }else{
     return 0;
   }
   }
function orders_deadline_date($the_order_id, $switch = '%Y-%m-%d'){
     
   					$italy_query=tep_db_query("select date_format(orders_deadline,'".$switch."') 
					                          as date_deadline  from " . TABLE_ORDERS . " 
											  where orders_id='" . tep_db_input($the_order_id) . "'");
					if(tep_db_num_rows($italy_query)>0) {
							$italy_result=tep_db_fetch_array($italy_query);
							return $italy_result['date_deadline'];
						}else{
						     return 0;
						}
   
   }
function orders_deadline_time($the_order_id){
  
     
   					$italy_query=tep_db_query("select date_format(orders_deadline,'%H:%i') 
					                          as time_deadline  from " . TABLE_ORDERS . " 
											  where orders_id='"  . tep_db_input($the_order_id) . "'");
					if(tep_db_num_rows($italy_query)>0) {
							$italy_result=tep_db_fetch_array($italy_query);
							return $italy_result['time_deadline'];
						}else{
						     return 0;
						}
   }
   
function orders_time_limit_date($the_order_id, $switch = '%Y-%m-%d'){
     
   					$italy_query=tep_db_query("select date_format(orders_time_limit,'".$switch."') 
					                          as date_deadline  from " . TABLE_ORDERS . " 
											  where orders_id='" . tep_db_input($the_order_id) . "'");
					if(tep_db_num_rows($italy_query)>0) {
							$italy_result=tep_db_fetch_array($italy_query);
							return $italy_result['date_deadline'];
						}else{
						     return 0;
						}
   
   }
function orders_time_limit_time($the_order_id){
  
     
   					$italy_query=tep_db_query("select date_format(orders_time_limit,'%H:%i') 
					                          as time_deadline  from " . TABLE_ORDERS . " 
											  where orders_id='"  . tep_db_input($the_order_id) . "'");
					if(tep_db_num_rows($italy_query)>0) {
							$italy_result=tep_db_fetch_array($italy_query);
							return $italy_result['time_deadline'];
						}else{
						     return 0;
						}
   }
function orders_deadline($the_order_id){
    					$italy_query=tep_db_query("select orders_deadline
					                               from " . TABLE_ORDERS . " 
											       where orders_id='"  . tep_db_input($the_order_id) . "'");
					if(tep_db_num_rows($italy_query)>0) {
				        	$italy_result=tep_db_fetch_array($italy_query);
							if( $italy_result['orders_deadline'] <  time()){
						//	$result = $italy_result['orders_deadline'] . '  '.getServerDate());
							return true;
						}else{
						     return false;
						}
						}
						}
 function italy_order_expired ($the_order_id){
    					$italy_query=tep_db_query("select orders_time_limit
					                               from " . TABLE_ORDERS . " 
											       where orders_id='"  . tep_db_input($the_order_id) . "'");
					if(tep_db_num_rows($italy_query)>0) {
							if($italy_result['orders_time_limit'] > 0 && $italy_result['orders_time_limit'] <  date('Y-m-d H:i:s',time())){
							return true;
						}else{
						     return false;
						}
						}
						}
   function italy_ga_check_process_restock($product_id, $prod_quantity, $prod_type){
$result = array();
//take the product id, find the cPath, explode it and then run a check to see if any cat has a GA setting
$ga_path_array = array();
$ga_path_array = explode('_', ga_get_product_path($product_id));//n.b. tep_get_product path requires products_status=1 
$max = sizeof($ga_path_array);
if ($max >0){
	for ($i=0; $i<$max; $i++) {
##
// looping through the ga path array to find the categories that the quantity needs to be applied to.
		 $category_ga_query = tep_db_query("select categories_GA,categories_quantity_remaining from " . TABLE_CATEGORIES . " where categories_id = '" . $ga_path_array[$i]. "' limit 1");
   			 if (tep_db_num_rows($category_ga_query)) { 
			  $category_ga = tep_db_fetch_array($category_ga_query);
			 	if ( $category_ga['categories_GA'] == 2){
					$quantity_left_ga=(($category_ga['categories_quantity_remaining'])+($prod_quantity));
					 //update the master quantity
					 	tep_db_query("update " . TABLE_CATEGORIES . " set categories_quantity_remaining = '" .(($category_ga['categories_quantity_remaining'])+($prod_quantity)) . "' where categories_id = '" . $ga_path_array[$i] . "'");
			
					
			//get all the sub_cats
			//$new_cat_array = ga_get_children($ga_path_array[$i]);	
			//add in this one
			//$new_cat_array[]=$ga_path_array[$i];
			
					//OK so now we have updated the category what happens if master quantity is now positive but the products were previously turned off as it had reached zero
					/* the following block commented out Oct 2015 as not needed for the moment - be advised it is untested
					 if($quantity_left_ga > 0){
					 	//master ticket quantity positive
						//get all products in the and sub categories category and turn them back on
						//as this is working in a bottom up mode it will not turn on products in a lower category
						//e.g. if mixed seating and GA ticket being restocked is in a category directly under the top then
						//siblign categories wil be missed
						
						 $products_ga_query=tep_db_query("select products_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where categories_id  = '" . $ga_path_array[$i] . "'");
							  while($products_ga = tep_db_fetch_array($products_ga_query)){							  	
								tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '1' where products_id = '" . $products_ga['products_id'] . "' and products_quantity > 0");
																						}
						//the above will only do the categories above the product being restocked - how about this:
												// (there must be an easier way?)
						//use ga_get_product_path to get cPath
						$the_cpath = ga_get_product_path($product_id);
						//get top category form cPath
						$pieces = explode('_', $the_cpath);
						$the_top_category = $pieces[0];
						//use ga_get_children for an array of sub cats
						$the_whole_show = ga_get_children($the_top_category);
						//add in the top one
						$the_whole_show[] = $the_top_category;
						//traverse that array and run the update
						$max_size = sizeof($the_whole_show);
						if ($max_size >0){
							for ($ix=0; $ix<$max_size; $ix++) {
							    	$products_ga_query2 = tep_db_query("select products_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where categories_id  = '" . $the_whole_show[$ix] . "'");
							  while($products_ga2 = tep_db_fetch_array($products_ga_query2)){							  	
								tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '1' where products_id = '" . $products_ga2['products_id'] . "' and products_quantity > 0");
																						}
							
							}
							}
						
																						} 
					*/		  										
							    	
					}
					
					elseif(($prod_type=='G' && $category_ga['categories_GA'] == 1))
														{
	
					$quantity_left_ga=(($category_ga['categories_quantity_remaining'])+($prod_quantity));
					 //update the master quantity
					 	tep_db_query("update " . TABLE_CATEGORIES . " set categories_quantity_remaining = '" .(($category_ga['categories_quantity_remaining'])+($prod_quantity)) . "' where categories_id = '" .  $ga_path_array[$i] . "'");
					//OK so now we have updated the category what happens if master quantity >0 - reset products
					 if($quantity_left_ga > 0){
					 	tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '1' where products_id = '" . $product_id . "' and products_quantity > 0");
																						
							  					}
					 }
																				
														
														}
##												
																			}
													}
								}
								
								
 function italy_add_sql($_cPath=0){
 
 global $FSESSION, $_SESSION, $cPath;
 
		 $sql_to_add = " c.parent_id = '0' ";
		
		if ($FSESSION->is_registered('restrict_view')){
				$sql_to_add = "   (c.categories_id = '".$_SESSION['restrict_view']."') ";
		}
		
		elseif ($_cPath) {	 
				$cat_paths = preg_split('/_/', $cPath);
				$top_cat = $cat_paths[0];
				$sql_to_add = " (c.categories_id = '$top_cat') ";
				}
				
				return $sql_to_add;
 }
 
 function italy_number_crunch($to, $country=''){


       // 1 Trim whitespace
           $to = trim($to);
       // 2 Trim (0) as used in UK
         //    $to = str_replace("(0)","",$to);
       // 2a Trim + symbol & any other non-numeric
           $to = preg_replace('/[^0-9]/s', '', $to);


       return $to;
}
 
 // function italy_number_crunch($to, $country=''){
 
 // ///////////////////////////////////////////////////////////////////
		
		// // fetch country code by passing country
		// //we need to try and check numbers to see if they are Italian
		// //italian numbers start with a 3 and are 9 or 10 characters long
		// // 1 Trim whitespace
			// $to = trim($to);
		// // 2 Trim (0) as used in UK
          	// $to = str_replace("(0)","",$to);
		// // 2a Trim + symbol & any other non-numeric
            // $to = preg_replace('/[^0-9]/s', '', $to);
		// //  3 remove all leading zeroes
		    // $to += 0;
		// // 4 Check for 39 if number longer than 10
			// if(strlen($to)>10 &&  substr($to,0,2)=="39"){
			// //do nothing
			// }
			// // now we guess if 10 or less and starts with a 3 then add 39 to the start as it 'may' be Italian
			// elseif(strlen($to)<11 && substr($to,0,1)=="3"){
			// //add 39
				// $to = '39'.$to;
			// } 
			// //this should have trapped all Italian numbers 
			// //now check first two digits against country code - if not matched then add it in
			
						  // $country_query=tep_db_query("SELECT country_code from " . TABLE_COUNTRIES . " where countries_name='" . tep_db_input($country) . "'");
			// $country_result=tep_db_fetch_array($country_query);
			// if ($country_result["country_code"]!="" && italy_startsWith($to,$country_result["country_code"]) == 0){
			   
			     	// $to=$country_result["country_code"] . $to;}
			
			
			
		    // // end number crunching
			
		
		// return $to;
 // }
 
 function italy_startsWith($haystack, $needle)
{
     $length = strlen($needle);
     return (substr($haystack, 0, $length) === $needle);
}
  function italy_mail($to_name, $to_email_address, $email_subject, $email_text, $from_email_name, $from_email_address) {
    		$result=false;
		if ($default==false && (int)EMAIL_ACTIVATE!=1) return $result;
    // Instantiate a new mail object
	$message = new email(array('X-Mailer: osConcert'));
    // Build the text version
    $text = strip_tags($email_text);
      $message->add_text($text);
    
    // Send message
    $message->build_message();
    $message->send($to_name, $to_email_address, $from_email_name, $from_email_address, $email_subject);
  }
  
  function italy_cron_order($order_id){
  //builds a non-html order list for the timeout email, based on the accounts_history_info code
  global $order;
  $order_information='';
  ##### order totals
     for ($i=0, $n=sizeof($order->totals); $i<$n; $i++) {
     $order_information .= '<tr><td class="main" align="right" width="100%">' . $order->totals[$i]['title'] . '</td><td class="main" align="right">' . $order->totals[$i]['text'] . '</td>
	 </tr>';
  }
  ##### product lines
  	$products_name="";
	$products = array();
	$products_names_p="";
	$pre_qty="";
	$pre_name="";
	$qty_p = "";
	$pre_sign="";
	$first_event = true;
	$first_event_id = 0;
	$jj=0;
	$attendees_name="";
     $order_is_printable = 0;
	for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) {
	    		
	
		$order_is_printable = $order_is_printable + $order->products[$i]['is_printable'];
		$products_names_p="";
		$qty_p = "";
		$sign_p="";
		$model="";
		$attendees_name="";
		
		if($order->products[$i]['element_type']=="E"){
		 $model="";
		if($order->products[$i]['model'])
		{
		  if($order->products[$i]['model']!=""){
			 $model.=format_date($order->products[$i]['model']) . ",";
		  }
		 
		 }
		}	
		if(($pre_name!=$order->products[$i]['name']) && ($order->products[$i]['element_type']=="E")){
				$products_names_p = $order->products[$i]['name'] ;
				$pre_name=$order->products[$i]['name'];	
				$qty_p=$order->products[$i]['qty'];
				$pre_qty=$order->products[$i]['qty']; 
				$sign_p="X";
				$pre_sign="X";
		 }else if($order->products[$i]['element_type']=="V"){
		  $products_names_p = $order->products[$i]['name'];
		  $qty_p=$order->products[$i]['qty'];
		  $sign_p="X";
			  if($order->products[$i]['model'])
				$model= " , " . $order->products[$i]['model'];
		  }else if($order->products[$i]['element_type']=="S"){ 
		  $products_names_p = $order->products[$i]['name'];
		  $qty_p=$order->products[$i]['qty'];  
		  $sign_p="X"; 
			 // if($order->products[$i]['model'])
				//$model= " , " . $order->products[$i]['model'];
		  }else if($order->products[$i]['element_type']=="P"){ 
		  $products_names_p = $order->products[$i]['name'];
		  $qty_p=$order->products[$i]['qty'];
		  $sign_p="X";
			  if($order->products[$i]['model'])
				$model= " , " . $order->products[$i]['model'];
		  }
		$rax_total=tep_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']) * $order->products[$i]['qty'];
		$sku = $order->products[$i]['sku'];
		$event_id = 0;
		if($order->products[$i]['element_type']=='E'){
			$event_id = $order->products[$i]['event_id'];
			if($first_event){ 
				$first_event_id = $order->products[$i]['event_id'];
				$first_event = false;
			}
		} 
		$products[] = array( "qty" => $qty_p,
							 "sign"  => $sign_p,
							 "id" => $order->products[$i]['id'],
							 "products_type" => $order->products[$i]['element_type'],
							 "p_name"	 => $products_names_p,
							 "event_id" => $event_id,
							 "p_attributes1" => $products_ordered_attributes1, 
							 "p_attributes" => $products_ordered_attributes,
							 "model" => $model,
							 "sku" => $sku,
							 "categories_name" => $heading_name,
							 "concert_venue" => $heading_venue,
							 "concert_date" => $heading_date,
							 "concert_time" => $heading_time,
							 "row_total"=>$rax_total
						   ); 
	  }
		$session_dates = "";
		$event_id = $first_event_id;
		$date = array(); 
		
		$events_row_total = array();
	
		for ($i = 0, $n = sizeof($products); $i < $n; $i++) { 
			if(($products[$i]['products_type']=="E")){
				if($event_id!=$products[$i]['event_id']){
					$event_id=$products[$i]['event_id'];
					$session_dates = "";
				}
				$session_dates .= $products[$i]['model'];
				$date[$products[$i]['event_id']] = substr($session_dates,0,-1); 
				$events_row_total[$products[$i]['event_id']] += $products[$i]['row_total'];	
			} 
		} 
		$date_keys = array_keys($date);
		$date_keys_length = count($date_keys);
		for($i=0;$i<$date_keys_length;$i++){
			$final_date='';
			$var_date = $date[$date_keys[$i]];
			$date_split = split(',',$var_date);
			$date_split_count = count($date_split);
			
			for($j=0;$j<$date_split_count;$j++){
				$final_date .= $date_split[$j] .',';
				$m=$j+1;
			    if($m%4==0)	$final_date = substr($final_date,0,-1) . '<br>      ';
			}
			$date[$date_keys[$i]] = substr($final_date,0,-1);
		}
		$event_id = 0;
		 $dis_time_format="";	
		if(defined('TIME_FORMAT')) $dis_time_format=TIME_FORMAT;
		for ($i = 0, $n = sizeof($products); $i < $n; $i++) {
	   		 if($products[$i]['products_type']=="P"){
				$row_total= $products[$i]['row_total'];			
				$date=$products[$i]['model'];
			}else if($products[$i]['products_type']=="S"){
			    $row_total= $products[$i]['row_total'];
				   if($products[$i]['model']!="")
				    $date=$products[$i]['model'];	
			}else if($products[$i]['products_type']=="V"){
			    $row_total= $products[$i]['row_total'];
				   if($products[$i]['model']!="")
				   $date=$products[$i]['model'];
			}
			if($event_id!=$products[$i]['event_id'] || $products[$i]['products_type']!='E'){
				if($products[$i]['products_type']=='E'){
					$row_total = $events_row_total[$products[$i]['event_id']];
					if( ($products[$i]['qty'])>1 ){
						$attendees_name="";
						$attendee_sql = "select distinct customers_firstname,customers_lastname from ".TABLE_CUSTOMERS ." c, ".TABLE_CUSTOMERS_TO_CUSTOMERS ." ctc where ctc.customer_id=c.customers_id and ctc.orders_id='".$FREQUEST->getvalue('order_id','int','0')."'";
						$attendee_query=tep_db_query($attendee_sql);
						while($attendee_result=tep_db_fetch_array($attendee_query)){
							$attendees_name.=$attendee_result['customers_firstname'].' '.$attendee_result['customers_lastname'].',';
						}
				}
			}	 
			$model = "";
			if(($products[$i]['products_type']=="S")){
			   if($products[$i]['model']!="")
			     $model = $products[$i]['model'];
				 $attendees_name=""; 	
		    }if(($products[$i]['products_type']=="P")){
			     if($products[$i]['model']!="")
			       $model = $products[$i]['model'];	 
				   $attendees_name=""; 	
			}
		    if( ($products[$i]['products_type']=="E") && ($products[$i]['qty'])>1 ) {
						if ($attendees_name!=""){
								//$start_name=strpos($attendees_name,',',1);
								//$attendees_name=substr($attendees_name,$start_name+1,-1);
								$attendees_name='<br>' .'<small>' . '<b>' . TEXT_ATTENDEES . '</b>' . '</small>' . '<br>'.tep_draw_separator('pixel_trans.gif',35,1) .'-'.substr($attendees_name,0,-1);
						}
			}
			$discount=(isset($order->products[$i]['discount_whole_text']) && $order->products[$i]['discount_whole_text']!='')?'<br>' . $order->products[$i]['discount_whole_text']:'';
			$event_id = $products[$i]['event_id'];
			$heading_name = $order->products[$i]['categories_name'];
			$heading_venue = $order->products[$i]['concert_venue'];
			$heading_date = $order->products[$i]['concert_date'];
			$heading_time = $order->products[$i]['concert_time'];
			
		$order_information .=  '          <tr>' . "\n" .
         '<td class="main" align="right" valign="top" width="30">' . 
		 $products[$i]['qty'] . "  " . $products[$i]['sign'] .' </td>'  .
         '<td class="main" valign="top">' .
		 $heading_name . ' - ' . 
		 $products[$i]['p_name'] . ' - ' .
		 $heading_date  . ' - ' .
		 $heading_venue . ' <br> ' .
		 //$model .  ' - ' .
		 //$heading_time . 
		 $discount;

   
   if (isset($order->products[$i]['resources']) && (sizeof($order->products[$i]['resources']) > 0)) {
	    for ($j = 0, $k = sizeof($order->products[$i]['resources']); $j < $k; $j++) {
	    		if($order->products[$i]['resources'][$j]['end_date'] && $order->products[$i]['resources'][$j]['end_time']){
	    			$str_time=strtotime($order->products[$i]['resources'][$j]['end_date'].' '.$order->products[$i]['resources'][$j]['end_time'])+60;
					$order->products[$i]['resources'][$j]['end_date']=date('Y-m-d',$str_time);	    		
					$order->products[$i]['resources'][$j]['end_time']=date('h:i A',$str_time);
	    		}
				
			$stime="";
			$etime="";
			$stime=date("h:i A",strtotime($order->products[$i]['resources'][$j]['start_time']));
			$etime=date("h:i A",strtotime($order->products[$i]['resources'][$j]['end_time']));
				if($dis_time_format!="") {
					if($dis_time_format=='24')
						$stime=date("H:i",strtotime($order->products[$i]['resources'][$j]['start_time']));
				}
				if($dis_time_format!="") {
					if($dis_time_format=='24')
						$etime=date("H:i",strtotime($order->products[$i]['resources'][$j]['end_time']));
				}
		$order_information .= '<br><nobr><small> <i> -  '.TEXT_START_DATE.': ' . format_date($order->products[$i]['resources'][$j]['start_date']) . '  ' .$stime  .  '<br><nobr>  - ' . TEXT_END_DATE .': '. format_date($order->products[$i]['resources'][$j]['end_date']) . '   ' .$etime . (($order->products[$i]['resources'][$j]['resource_name'])?'   <br> <nobr>  -  '.TEXT_RESOURCE_NAME.' ' . $order->products[$i]['resources'][$j]['resource_name']:'');
            echo '</i></small></nobr>';
		}
    }
    if ( (isset($order->products[$i]['attributes'])) && (sizeof($order->products[$i]['attributes']) > 0) ) {
      for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) {
       if($order->products[$i]['attributes'][$j]['option'] && $order->products[$i]['attributes'][$j]['value'])  $order_information .=  '<br><nobr><small> <i> - ' . $order->products[$i]['attributes'][$j]['option'] . ': ' . $order->products[$i]['attributes'][$j]['value'] . '</i></small></nobr>';
       if($order->products[$i]['attributes'][$j]['price'])  $order_information .=  '<small> <i> - ' . $currencies->format(tep_add_tax($order->products[$i]['attributes'][$j]['price'],$order->products[$i]['tax'])) . '</i></small>';
	  }
    } 
			//cartzone dont like SKU
	if($order->products[$i]['sku']!="")//echo "<BR>" . HEADING_SKU . $order->products[$i]['sku'];
    echo '</span></td>' . "\n";
    if (sizeof($order->info['tax_groups']) > 1) {
      $order_information .=  '<td class="main" valign="top" align="right">' . tep_display_tax_value($order->products[$i]['tax']) . '%</td>' . "\n";
    }
  //  echo '     <td class="main" align="right" valign="top">    ' . $currencies->format($row_total, true, $order->info['currency'], $order->info['currency_value']) . '</td></tr>' . "\n" ;
  }
  }
  
  
  return $order_information;
  
  
  }
  
    function italy_get_product_path($products_id) {

    $cPath = '';	



    $category_query = tep_db_query("select p2c.categories_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = '" . (int)$products_id . "'  and p.products_id = p2c.products_id limit 1");

    if (tep_db_num_rows($category_query)) {

      $category = tep_db_fetch_array($category_query);



      $categories = array();

      tep_get_parent_categories($categories, $category['categories_id']);



      $categories = array_reverse($categories);



      $cPath = implode('_', $categories);



      if (tep_not_null($cPath)) $cPath .= '_';

      $cPath .= $category['categories_id'];

    }



    return $cPath;

  }
?>