<?php 
// Check to ensure this file is included in Freeway!
defined('_FEXEC') or die();
?>
<table border="0" width="100%" cellspacing="0" cellpadding="<?php echo CELLPADDING_SUB; ?>">
<?php
// BOF: Lango Added for template MOD
if (SHOW_HEADING_TITLE_ORIGINAL == 'yes') {
$header_text = '&nbsp;'
//EOF: Lango Added for template MOD
?>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
            <td class="pageHeading" align="right"><?php echo tep_image(DIR_WS_IMAGES . 'table_background_history.gif', HEADING_TITLE, HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
          </tr>
        </table></td>
      </tr>
<?php
// BOF: Lango Added for template MOD
}else{
$header_text = HEADING_TITLE;
}
// EOF: Lango Added for template MOD
	if(!isset($hide_row_top)) {
?>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
<?php
	}
// BOF: Lango Added for template MOD
if (MAIN_TABLE_BORDER == 'yes'){
table_image_border_top(false, false, $header_text);
}
// EOF: Lango Added for template MOD
?><br />
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
          <tr>
            <td class="main" colspan="2"><b><?php echo sprintf(HEADING_ORDER_NUMBER, $HTTP_GET_VARS['order_id']) . ' <small>(' . $order->info['orders_status'] . ')</small>'; ?></b></td>
          </tr>
          <tr>
            <td class="smallText"><?php echo HEADING_ORDER_DATE . ' ' . date(EVENTS_DATE_FORMAT,strtotime($order->info['date_purchased']));//format_date($order->info['date_purchased']); ?></td>
            <td class="smallText" align="right"><?php echo HEADING_ORDER_TOTAL . ' ' . $order->info['total']; ?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="2" class="infoBox">
          <tr class="infoBoxContents">
	  
<?php
  if ($order->delivery != false) {
?>
            <td width="30%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr>
                <td class="main"><b><?php echo HEADING_DELIVERY_ADDRESS; ?></b></td>
              </tr>
              <tr>
                <td class="main"><?php echo tep_address_format($order->delivery['format_id'], $order->delivery, 1, ' ', '<br>'); ?></td>
              </tr>
<?php
    if (tep_not_null($order->info['shipping_method'])) {
?>
              <tr>
                <td class="main"><b><?php echo HEADING_SHIPPING_METHOD; ?></b></td>
              </tr>
              <tr>
                <td class="main"><?php echo $order->info['shipping_method']; ?></td>
              </tr>
<?php
    }
?>
            </table></td>
<?php
  }
?>
            <td width="<?php echo (($order->delivery != false) ? '70%' : '100%'); ?>" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">
              <tr>
                <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
<?php
  if (sizeof($order->info['tax_groups']) > 1) {
?>
                  <tr>
                    <td class="main" colspan="2"><b><?php echo HEADING_PRODUCTS; ?></b></td>
					<td class="main" align="right"><b><?php echo HEADING_TAX; ?></b></td>
                    <td class="main" align="right"><b><?php echo HEADING_TOTAL; ?></b></td>
                  </tr>
<?php
  } else {
?>
                  <tr>
                    <td class="main" colspan="2"><b><?php echo HEADING_PRODUCTS; ?></b></td>
					<td class="main"></td>
                  </tr>
<?php
  }
 // print_r($order->products);
// $total_amt_received=0;
// $total_tax_received=0;

	$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="";

	for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) {
		$products_names_p="";
		$qty_p = "";
		$sign_p="";
		$model="";
		
		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'] . "<br>" . tep_draw_separator('pixel_trans.gif','20','10');
				$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,
							 "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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
			}
			$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='".(int)$HTTP_GET_VARS['order_id']."'";
						$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'];

    echo '          <tr>' . "\n" .
         '            <td class="main" align="right" valign="top" width="30">' . $products[$i]['qty'] . "&nbsp;&nbsp;" . $products[$i]['sign'] .'&nbsp;</td>' . "\n" .
         '            <td class="main" valign="top">' . $products[$i]['p_name'] . $date[$event_id] . $model . $attendees_name . $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']));
				}
			echo '<br><nobr><small>&nbsp;<i> -  '.TEXT_START_DATE.': ' . format_date($order->products[$i]['resources'][$j]['start_date']) . '&nbsp; ' .$stime  .  '<br><nobr>&nbsp; - ' . TEXT_END_DATE .': '. format_date($order->products[$i]['resources'][$j]['end_date']) . ' &nbsp; ' .$etime . (($order->products[$i]['resources'][$j]['resource_name'])?'&nbsp;  <br> <nobr>&nbsp; -  '.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'])  echo '<br><nobr><small>&nbsp;<i> - ' . $order->products[$i]['attributes'][$j]['option'] . ': ' . $order->products[$i]['attributes'][$j]['value'] . '</i></small></nobr>';
       if($order->products[$i]['attributes'][$j]['price'])  echo '<small>&nbsp;<i> - ' . $currencies->format(tep_add_tax($order->products[$i]['attributes'][$j]['price'],$order->products[$i]['tax'])) . '</i></small>';
	  }
    } 
			
	if($order->products[$i]['sku']!="")echo "<BR>" . HEADING_SKU . $order->products[$i]['sku'];
    echo '</td>' . "\n";
    if (sizeof($order->info['tax_groups']) > 1) {
      echo '            <td class="main" valign="top" align="right">' . tep_display_tax_value($order->products[$i]['tax']) . '%</td>' . "\n";
    }

    echo ' &nbsp;&nbsp;&nbsp;&nbsp;<td class="main" align="right" valign="top">&nbsp;&nbsp;&nbsp;&nbsp;' . $currencies->format($row_total, true, $order->info['currency'], $order->info['currency_value']) . '</td></tr>' . "\n" ;
  }
  }
  
?>
                </table></td>
              </tr>
			  
            </table></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
      <tr>
        <td class="main"><b><?php echo HEADING_BILLING_INFORMATION; ?></b></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="2" class="infoBox">
          <tr class="infoBoxContents">
            <td width="40%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr>
                <td class="main"><b><?php echo HEADING_BILLING_ADDRESS; ?></b></td>
              </tr>
              <tr>
                <td class="main"><?php echo tep_address_format($order->billing['format_id'], $order->billing, 1, ' ', '<br>'); ?></td>
              </tr>
              <tr>
                <td class="main"><b><?php echo HEADING_PAYMENT_METHOD; ?></b></td>
              </tr>
              <tr>
                <td class="main"><?php echo $order->info['payment_method']; ?></td>
              </tr>
			   <tr>
		        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
		      </tr>
			  <?php 
			  /* if($order->info['reference_id']!=''){ ?>
              <tr>
                <td class="main"><?php echo '<b>' . TEXT_REFERENCE_ID . '</b>&nbsp;' . $order->info['reference_id']; ?></td>
			  </tr>
			  <?php } 
			 
			 if($order->info['payment_return1']!=''){ ?>
              <tr>
                <td class="main"><?php echo '<b>' . TEXT_RECEIPT_NO . '</b>&nbsp;' . $order->info['payment_return1'];?></td>
			  </tr>
			  <?php } 
			  if($order->info['payment_return2']!=''){ ?>
              <tr>
                <td class="main"><?php echo '<b>' . TEXT_TRANSACTION_NO . '</b>&nbsp;' . $order->info['payment_return2'];?></td>
			  </tr>
			  <?php } */?>
            </table></td>
            <td width="70%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
				<!-- <tr>
					<td class="main" valign="bottom" colspan="2" align="right"><b><?php echo HEADING_ORDER_DETAILS;?></b></td>
				</tr> -->
			<?php

   for ($i=0, $n=sizeof($order->totals); $i<$n; $i++) {
     echo '              <tr>' . "\n" .
         '                <td class="main" align="right" width="100%">' . $order->totals[$i]['title'] . '</td>' . "\n" .
         '                <td class="main" align="right">' . $order->totals[$i]['text'] . '</td>' . "\n" .
         '              </tr>' . "\n";
  } 
?>		
            </table></td>
          </tr>
        </table></td>
      </tr>
     
      <tr>
        <td class="main"><b><?php echo HEADING_ORDER_HISTORY; ?></b></td>
      </tr>
      <tr>
        <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
          <tr class="infoBoxContents">
            <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
<?php
  $statuses_query = tep_db_query("select os.orders_status_name, osh.date_added, osh.comments from " . TABLE_ORDERS_STATUS . " os, " . TABLE_ORDERS_STATUS_HISTORY . " osh where osh.orders_id = '" . (int)$HTTP_GET_VARS['order_id'] . "' and osh.orders_status_id = os.orders_status_id and os.language_id = '" . (int)$languages_id . "' order by osh.date_added");
  while ($statuses = tep_db_fetch_array($statuses_query)) {
    echo '              <tr>' . "\n" .
         '                <td class="main" valign="top" width="70">' . format_date($statuses['date_added']) . '</td>' . "\n" .
         '                <td class="main" valign="top" width="70">' . $statuses['orders_status_name'] . '</td>' . "\n" .
         '                <td class="main" valign="top">' . (empty($statuses['comments']) ? '&nbsp;' : nl2br(tep_output_string($statuses['comments']))) . '</td>' . "\n" .
         '              </tr>' . "\n";
  }
  
?>
            </table></td>
          </tr>
        </table></td>
      </tr>
	  
	  <tr>
	  <td class="main"><b>&nbsp;<?php echo HEADING_IP_ADDRESS; ?></b></td>
	  </tr>
	  <tr><td><table border="0" width="100%">
	  <tr><td class="main"><?php echo $order->info['ip_address'];?></td></tr>
	  
	  
	  </table>
	  </td></tr>
<?php
// BOF: Lango Added for template MOD
if (MAIN_TABLE_BORDER == 'yes'){
table_image_border_bottom();
}
$return=$HTTP_GET_VARS['return'];
// EOF: Lango Added for template MOD
?>
<?php
  $order_status_query = tep_db_query("select orders_status from " . TABLE_ORDERS . " where orders_id = '" . $HTTP_GET_VARS['order_id'] . "'");
  $order_status = tep_db_fetch_array($order_status_query); 	
  if(($order_status['orders_status'])>1){
	  if (DOWNLOAD_ENABLED == 'true') include(DIR_WS_MODULES . 'downloads.php');
  }	  
?>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
      <tr>
        <td colspan="2"><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
          <tr class="infoBoxContents">
            <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
		      <tr>
		        <td align="left" class="main"><?php echo '<a href="' . tep_href_link((($return=='ma' || $return=='hinfo')?FILENAME_ACCOUNT:(($return=='sh')?FILENAME_ACCOUNT_SUBSCRIPTIONS:FILENAME_ACCOUNT_HISTORY)), tep_get_all_get_params(array('order_id')), 'SSL') . '">' . tep_template_image_button('button_back.gif', IMAGE_BUTTON_BACK) . '</a>'; ?></td>
		        <td align="right" class="main"><?php
		        if ($joomla_include==1){
							echo '<a href="javascript:popupWindow(\'' . (ENABLE_SSL == 'true' || ENABLE_SSL==true?HTTPS_SERVER . DIR_WS_HTTPS_CATALOG:HTTP_SERVER . DIR_WS_HTTP_CATALOG) .'freeway/'.  FILENAME_ORDERS_PRINTABLE . '?' . (tep_get_all_get_params(array('order_id','openfile')) . 'order_id=' . $HTTP_GET_VARS['order_id']) .'&joomla_include_yes=1\');">' . tep_template_image_button('button_printorder.gif', IMAGE_BUTTON_PRINT_ORDER) . '</a>';
						} else {
							echo '<a href="javascript:popupWindow(\'' .  (ENABLE_SSL == 'true' || ENABLE_SSL==true?HTTPS_SERVER . DIR_WS_HTTPS_CATALOG:HTTP_SERVER . DIR_WS_HTTP_CATALOG) . FILENAME_ORDERS_PRINTABLE . '?' . (tep_get_all_get_params(array('order_id')) . 'order_id=' . $HTTP_GET_VARS['order_id']) .'&joomla_include_yes=\');">' . tep_template_image_button('button_printorder.gif', IMAGE_BUTTON_PRINT_ORDER) . '</a>'; 
						}
		        ?></td>
		      </tr>
            </table></td>
          </tr>
        </table></td>
      </tr>
    </table>
