<?php 

// Check to ensure this file is included in Freeway!
defined('_FEXEC') or die();
?>
<table align="left" border="0" width="100%" cellspacing="0" cellpadding="<?php echo CELLPADDING_SUB; ?>">
	<?php if(!isset($hide_row_top)) { ?>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
	 <?php } ?> 
<?php if (MAIN_TABLE_BORDER == 'yes'){
table_image_border_top(true, false, HEADING_TITLE);
} 
// display events with som
function display_events(&$free_list,$title){ 
	global $languages_id,$ecPath,$events_id;
	if (sizeof($free_list)>0){
		echo '<tr><td class="main">' . $title . '</td></tr>';
		echo '<tr><td>' . tep_image(DIR_WS_IMAGES . 'pixel_trans.gif','10','10') . '</td></tr>';
		for($icnt=0;$icnt<sizeof($free_list);$icnt++){
			echo '<tr><td class="main" valign="middle"><a class="blue" href="' . tep_href_link(FILENAME_SESSION_DETAILS,'ecPath=' . $ecPath . '&events_id=' . $free_list[$icnt]["id"]) . '">' . $free_list[$icnt]["name"] . "</a>&nbsp;";
			echo '<a href="' . tep_href_link(FILENAME_SESSION_DETAILS,'ecPath=' . $ecPath . '&events_id=' . $free_list[$icnt]["id"]) . '">' . tep_template_image_button("small_view.gif",IMAGE_VIEW,'align=absmiddle') . '</a></td></tr>';
			echo '<tr><td>' . tep_image(DIR_WS_IMAGES . 'pixel_trans.gif','10','5') . '</td></tr>';
		}
		echo '<tr><td>' . tep_image(DIR_WS_IMAGES . 'pixel_trans.gif','10','10') . '</td></tr>';
	}
}
?> 
	<tr>
		<td>
		<table border="0" width="100%" cellpadding="2" cellspacing="2" align=center >
			<tr>
				<td class="main">
					<?php echo '<b>' . TEXT_EVENT_NAME . '</b>' . tep_get_events_name($events_result["events_id"]);?>
				</td>
			</tr>
			<?php  //echo "result=" . $found_results; 
				if ($found_results=='reserve') {
			?>
			<tr>
				<td class="main"><?php echo TEXT_INFO_AVAILABLE;?></td>
			</tr>
			<?php } else if ($found_results=='waitlist'){ ?>
			<tr>
				<td class="main">
					<table border="0" cellspacing="0" cellpadding="0">
					<?php 
						$free_list=&tep_get_free_events($id_string,'R',array(array('id'=>$events_id)));
						display_events($free_list,TEXT_INFO_OTHER_EVENT);
					?>
					<tr>
						<td class="main"><?php echo TEXT_INFO_CONTINUE_RESERVE;?></td>
					</tr>
					</table>
				</td>
			</tr>
			<?php } else { 
					if(!$total_reservations){
						$total_reservations = tep_get_free_sessions($sessions_id,$sessions_count,'R',$no_attendees);
					}
					$value = split("#", $total_reservations);
					$result=TEXT_INFO_EMPTY;
					$available = $value[1];
					$reservation = $value[0];
					$execpt_seats= $reservation - ($available + $selected_attendees);
					if($execpt_seats<0)	{
						$result = TEXT_PARTLY_FULL . tep_draw_separator('pixel_trans.gif','20','10') . sprintf(TEXT_AVAILABLE_ATTENDEES,($available + $selected_attendees) - $reservation);
			?>
					<tr height="50">
						<td align="center" class="main" valign="top"><?php echo $result;?></td>
					</tr>
					<?php }else if($execpt_seats>=0){?>
					<tr height="50">
						<td align="center" class="main" valign="top"><?php echo TEXT_INFO_EMPTY;?></td>
					</tr>
					<?php } ?>
					<tr>
						<td class="main">
						<table border="0" cellspacing="0" cellpadding="0">
						<?php
							$free_list=&tep_get_free_events('','R',array(array('id'=>$events_id)));
							display_events($free_list,TEXT_INFO_OTHER_PLACE_RESERVE);
						?>
						</table>
						</td>
					</tr>
					<tr>
						<td class="main">
						<table border="0" cellspacing="0" cellpadding="0">
						<?php 
							$free_list[]=array('id'=>$events_id);
							$free_list=&tep_get_free_events('','W',$free_list);
							display_events($free_list,TEXT_INFO_OTHER_PLACE_WAITLIST);
						?>
						</table>
						</td>
					</tr>
			<?php }	?>
		</table>
		</td>
	</tr>
    <?php     
    if ($found_results=='reserve' || $found_results=='waitlist'){ // if found result data		
		echo tep_draw_form("checkout_event",tep_href_link(FILENAME_EVENTS_BOOKING_DETAILS,tep_get_all_get_params()));
	?>
      <tr>
	  	<td>
		<table border="0" width="100%" cellpadding="2" cellspacing="2" align=center>
		    <tr>
				<td width="10"></td>
				<td class="main" align="center">
				<?php echo '<b>' . TEXT_SESSIONS_DATE . '</b>'; ?>
				<?php 
					if ($no_attendees>1) { 
						echo '<td class="main" align="center"><b>' . TEXT_ATTENDEES . '</b></td>';
					}
				?>
				<td class="main" align="center">
				<?php echo '<b>' . TEXT_NOTIFY . '</b>'; ?>
				<td class="main" align="right">
				<?php echo '<b>' . TEXT_FEES . '</b>'; 
				echo tep_draw_hidden_field("old_orders_id",$old_orders_id);
				echo tep_draw_hidden_field("events_id",$events_id);
				echo tep_draw_hidden_field("event_question_type",$question_type);
				echo tep_draw_hidden_field("event_question_value_data",$question_value_data);
				$total=0;
				reset($session_array);
		    	while(list($id,)=each($session_array)) { ?>
		    		<tr>
						<td class="main" align=left width="10">
							<?php 
								if ($session_array[$id]['type']=='R'){
									echo '<input type="hidden" name="session_select_' .  $id . '" value="1">';
								} else {
									if ($events_result["session_gaps"]=='Y'){
										echo tep_draw_checkbox_field("session_select_" . $id,1,true);
									} else {
										echo '<input type="hidden" name="session_select_' .  $id . '" value="1">';
									}
								}
							?>
						</td>
					
					<td class="main" align="center"><?php echo format_date($session_array[$id]['date']);?>
					<?php 
						if ($no_attendees>1) { 
							echo '<td class="main" align="center"><b>' . $no_attendees . '</b></td>';
						}
					?>
					<td class="main" align="center">
					<input type=hidden name="session_id[]" value="<?php echo $id;?>">
					<input type=hidden name="session_type[]" value="<?php echo $session_array[$id]["type"];?>">
					<input type=hidden name="session_group[]" value="<?php echo $session_array[$id]["group"];?>">
					<input type=hidden name="session_date[]" value="<?php echo $session_array[$id]["date"];?>">
		    		<?php  	if ($session_array[$id]['type']=='R'){
								echo '<font class="eventavail">' . TEXT_RESERVED .'</font>';
							} else if ($session_array[$id]['type']=='W'){
								echo '<font color="red">' . TEXT_WAIT_LIST .'</font>';
						    }
							// get price amount for the session date
						
					?>
					<td class="main" align="right">
					<?php 
						// if the session style is single session type display amount for each session
						if ($session_array[$id]['type']=='R' || $events_result['session_style']=='S') {
							$amount=tep_get_events_price($events_result,$session_array[$id]["type"],$session_array[$id]["group"],$session_array[$id]["date"],true);						
							echo $currencies->format($amount * $no_attendees);
							$total+=$amount * $no_attendees;
						} else {
							echo "--";
						}
					?>
					</td>
					<?php
					} // while loop
					if ($events_result['session_style']=='E' && $found_results=='waitlist') {
						$total=tep_add_tax($events_result['waitfee_vip'],tep_get_tax_rate($events_result['events_tax_class_id']));
					?>
					<tr>
						<td class="main" colspan="4" align="right">
							<b><?php echo TEXT_WAITLIST_FEE;?></b>
						</td>
						<td class="main" align="right">
							<?php echo $currencies->format($total);?>
						</td>
					</tr>
					<?php }?>
					<tr>
						<td class="main" colspan="<?php echo ($no_attendees>1?4:3); ?>" align="right">
							<b><?php echo TEXT_TOTAL;?></b>
						</td>
						<td class="main" align="right">
							<?php echo $currencies->format($total);?>
						</td>
					</tr>
		</table>
		</td>
	</tr>
	<?php }?>
	<tr>
		<td>
		<table border="0" cellpadding="0" cellspacing="0" width="100%">
			<tr>
				<td class="main" align="left">
					<?php echo "<a href='" . tep_href_link(FILENAME_SESSION_DETAILS,tep_get_all_get_params()) . "'>" . tep_template_image_button('button_back.gif', IMAGE_BUTTON_BACK) . "</a>&nbsp;";?>
				</td>
				<td class="main" align="right"> 
					<?php echo '<input type="hidden" name="no_attendees" value="' . $no_attendees . '">'; 
					if ($found_results=='reserve' || $found_results=='waitlist') echo tep_template_image_submit('button_continue.gif', IMAGE_BUTTON_CONTINUE,'frameBorder="0"');?>
				</td>
		</tr>
		</table>
		</td>
	</tr>
	</form>
<?php if (MAIN_TABLE_BORDER == 'yes'){
table_image_border_bottom();
} ?>       
</table>