<?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
?>

	<?php
		$history_query_raw = 	"select o.orders_id, o.date_purchased, op.products_id, op.products_tax, op.products_name, op.events_type,sum(op.final_price) as session_rate,op.products_tax,s.events_id,time_format(e.events_start_time,'%h:%i %p') as events_start_time, time_format(e.events_end_time,'%h:%i %p') as events_end_time from " . 
								TABLE_ORDERS . " o, " . TABLE_EVENTS_SESSIONS . " s, " . TABLE_EVENTS . " e, " . TABLE_ORDERS_PRODUCTS . " op where o.customers_id = '" . (int)$customer_id . "' and op.products_type='E' and op.events_type!='' and op.events_type!='C' and op.products_id=s.sessions_id and o.orders_id=op.orders_id and s.events_id=e.events_id group by o.orders_id order by o.date_purchased desc";
		
		$customer_query=tep_db_query("SELECT customers_type from " . TABLE_CUSTOMERS . " where customers_id='" . $customer_id ."'");
		if ($customer_result=tep_db_fetch_array($customer_query))
			$customers_type=$customer_result['customers_type'];

		$history_query=tep_db_query($history_query_raw);
		$rows=0;
		if (tep_db_num_rows($history_query)){
			while ($history = tep_db_fetch_array($history_query)) {
				$rows++;
	?>
	<tr>
		<td>
				<table border="0" width=100% cellspacing="0" cellpadding="2">
					<tr>
						<td class="main">
						<?php 
							echo '<b>' . TEXT_EVENT_NAME . '</b><a href="' . tep_href_link(FILENAME_EVENTS_INVITE_FRIEND,tep_get_all_get_params() . 'eID=' . $history["events_id"] . '&path=ACR','SSL') . '"> ' . $history['products_name'] . '&nbsp;' . tep_image(DIR_WS_ICONS . 'invite.gif',IMAGE_INVITE_FRIEND,24,24,'align=absmiddle') . '</a>';
						?>
						</td>
	      				<td class="main" width=100>
						<?php
							echo '<b>' . TEXT_ORDER_ID . '</b>&nbsp;' .$history['orders_id'];
						?>
						</td>
					</tr>
					<tr>
						<td class="main" valign="top"><?php echo '<b>' . TEXT_FEES . '</b> ' . $currencies->display_price($history['session_rate'],$history['products_tax']); ?></td>
					</tr>
			</table>
	  </td>
	</tr>
	<tr>
<script language="JavaScript">
	function NavigatePage(button_name,frm){
		if (button_name=='withdraw')
			frm.action="<?php echo addslashes(tep_href_link(FILENAME_WITHDRAW_RESERVATIONS,'','SSL'));?>";
		
		frm.submit();
	}
</script>
		<td>
			<table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
            	<tr class="infoBoxContents">
              		<td>
						<table border="0" width="100%" cellspacing="0" cellpadding="0">
                			<tr>
							<tr><td class="main" valign="top"><?php echo '<b>' . TEXT_RESERVATION_DATE . '</b>'; ?></td></tr>
							<tr><td>
								<table border="0" cellspacing="0" cellpadding="0">
								<?php 
									echo tep_draw_form('move_reservation_' . $rows,tep_href_link(FILENAME_MOVE_RESERVATIONS,'','SSL'));
									echo tep_draw_hidden_field('events_id',$history['events_id']);
									echo tep_draw_hidden_field('orders_id',$history['orders_id']);
									$date_query=tep_db_query("SELECT s.start_date,op.orders_products_id,op.events_type,op.waitlist_type from " . TABLE_EVENTS_SESSIONS . " s, "  . TABLE_ORDERS_PRODUCTS . " op where op.orders_id='" . $history['orders_id'] . "' and s.events_id='" . $history['events_id'] . "' and op.products_id=s.sessions_id order by s.start_date");
									$date_string="";
									$cnt=0;
									$check_count=0;
									while($date_result=tep_db_fetch_array($date_query)){ 
								?>
									<tr>
									<td class="main" valign="top" align="left" width=100><?php echo format_date($date_result['start_date']);?></td>
									<td class="main" valign="top" align="left" width=200><?php echo $history['events_start_time'] . '-' . $history['events_end_time'];?></td>
									<td class="main" valign="top" align="left" width=200>
									<?php 
										switch($date_result['events_type']){
											case 'R':
												if ($date_result['waitlist_type']=='P') echo TEXT_PENDING;
												else echo TEXT_RESERVED;
												break;
											case 'W':
												echo TEXT_WAITLIST;
												switch($date_result['waitlist_type']){
													case 'V':
														echo ' - ' . TEXT_VIP;
														break;
													case 'F':
														echo ' - ' . TEXT_FIRSTCOME;
														break;
													case 'C':
														echo ' - ' . TEXT_CUSTOM;
												}
												break;
											case 'F':
												echo TEXT_REFUND;
												$check_count++;
												break;
											case 'T':
												echo TEXT_WITHDRAWN;
												$check_count++;
												break;
										}
									?>
									</td>
									</tr>
							<?php
									if ($date_result['events_type']=='R' || $date_result['events_type']=='W')
										echo tep_draw_hidden_field('orders_products_id[]',$date_result['orders_products_id']);
									$cnt++;
								}
							?>
								</table>
								</td>
							</tr>
							<td class="main" valign="top" align=right>
							<?php 
								if ($cnt!=$check_count && $customers_type=='V') 
								{
									echo '<span style="cursor:hand" onClick="javascript:NavigatePage(' . "'withdraw',document.move_reservation_" . $rows . ')">' . tep_template_image_button('button_withdraw.gif',SMALL_IMAGE_BUTTON_WITHDRAW) . '</span>&nbsp';
									echo '<span style="cursor:hand" onClick="javascript:NavigatePage(' . "'move',document.move_reservation_" . $rows . ')">' . tep_template_image_button('button_move.gif',IMAGE_BUTTON_MOVE_RESERVATION) . '</span>';
								}
								echo '</form>';
							?></td>
							</tr>
						</table></td>
					</tr>
			</table>
		</td>
		</tr>
		<tr>
		  <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
		</tr>
	<?php
		}
	} else {
	?>
		<table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
			<tr class="infoBoxContents">
				<td><table border="0" width="100%" cellspacing="2" cellpadding="4">
					<tr>
						<td class="main"><?php echo TEXT_NO_RESERVATIONS; ?></td>
					</tr>
				</table></td>
			</tr>
		</table>
	<?php
	}
	?>
		</td>
	</tr>
	<?php
	// BOF: Lango Added for template MOD
	if (MAIN_TABLE_BORDER == 'yes'){
	table_image_border_bottom();
	}
	// EOF: Lango Added for template MOD
	?>
	<tr>
		<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
	</tr>
	<tr>
		<td><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 width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
						<td><?php echo '<a href="' . tep_href_link(FILENAME_ACCOUNT, '', 'SSL') . '">' . tep_template_image_button('button_back.gif', IMAGE_BUTTON_BACK) . '</a>'; ?></td>
						<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
					</tr>
				</table></td>
			</tr>
		</table></td>
	</tr>
</table>
