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

	$ecCat_path="";

	if ($ecPath!="") $ecCat_path.="&ecPath=" . $ecPath;

	echo tep_draw_form("frmView",tep_href_link(FILENAME_EVENTS_VIEW2,$ecCat_path));
	// get initial parameters
	$category_id=(isset($HTTP_POST_VARS['category_id'])?(int)$HTTP_POST_VARS['category_id']:0);
	$post_action=(isset($HTTP_POST_VARS['post_action'])?tep_db_prepare_input($HTTP_POST_VARS['post_action']):"change_cat");
	$server_date=getServerDate();
	
	// check for the selected category
	if ($category_id<=0) $category_id=(int)$current_events_category_id;
	
	
	// if category id is not found try to get the first row category id
	if ($category_id<=0) {
		$first_cat_query=tep_db_query("SELECT events_categories_id from " . TABLE_EVENTS_CATEGORIES_DESCRIPTION . " order by events_categories_name limit 1");
		
		$first_cat_result=tep_db_fetch_array($first_cat_query);
		$category_id=(int)$first_cat_result["events_categories_id"];
	
	}

	
	// creation an filter if category_id is present
	if ($category_id>0) $cat_option=" and ec.events_categories_id='" . $category_id . "'";

	// get the list of events to be displayed
	
	// BOF: Lango Added for template MOD
	if (MAIN_TABLE_BORDER == 'yes'){
	table_image_border_top(false, false, TEXT_HEADING_BROWSE);
	}
	// EOF: Lango Added for template MOD
	
	// select event category details
	$cat_array=array();
	$cat_list_query=tep_db_query("SELECT ecd.events_categories_name,ecd.events_categories_id from " . TABLE_EVENTS_CATEGORIES . " ec, " . 
								TABLE_EVENTS_CATEGORIES_DESCRIPTION . " ecd where ecd.events_categories_id=ec.events_categories_id and ecd.language_id='" . 
								$languages_id . "' order by events_categories_name ");
	
	//$cat_array[]=array('id'=>0,'text'=>"All Categories");
	while($cat_list_result=tep_db_fetch_array($cat_list_query)){
		$cat_array[]=array('id'=>$cat_list_result["events_categories_id"],'text'=>$cat_list_result["events_categories_name"]);
	}

	// fetch all the necessary events
	$event_info_query = tep_db_query("select e.events_id, e.events_fees,e.events_tax_class_id,e.events_image, if(CHAR_LENGTH(ed.events_description)>100,concat(left(ed.events_description,100),'...'),ed.events_description) as events_description,ed.events_name, e.events_date_available, e.events_date_added" .
										" from " . TABLE_EVENTS . " e , " . TABLE_EVENTS_DESCRIPTION . " ed, " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " ec2 where ed.events_id = e.events_id " .
										" and ed.events_id=ec2.events_id and ec2.events_categories_id='" . $category_id . "' " . EVENTS_CONDITION_STATUS . " and ed.language_id = '" . (int)$languages_id . "'");
									
	$cur_templ_path=DIR_WS_TEMPLATES . TEMPLATE_NAME . "/images/";
?>
	<script language="JavaScript">
		function ChangeResult(mode){
			if(mode==3)
			{
				document.frmView.post_action.value="change_cat";
				document.frmView.action="<?php echo tep_href_link(FILENAME_EVENTS_VIEW2);?>";
				}
						document.frmView.submit();			
		}
		
		function ViewPrevious(){
			document.frmPrevious.submit();
		}
	</script>
			
	<table width='100%' border="0" cellspacing="0" cellpadding="0" align="left">
	<tr height="20">
		<td class="main" valign="top">
		<table width='100%' border="0" cellspacing="0" cellpadding="0" align="left">
			<tr class="eventTitleRow">		
				<td valign="middle" align="right" width="120" class="eventTitle"><?php echo TEXT_EVENT_CATEGORY;?></td>
				<td valign="middle" class="eventTitle">
					<?php 
					
						echo tep_draw_pull_down_menu("category_id",$cat_array,$category_id) . '&nbsp;';
						echo '<a href="javascript:ChangeResult(3);">' . tep_template_image_button("button_quick_find.gif",IMAGE_VIEW_DATE,'align=absmiddle') . '</a>';
					?>
				</td>
			</tr>
		</table>
		</td>
	</tr>
	<tr>
			<td><?php echo tep_draw_separator('pixel_trans.gif','1','10');?></td>	
	</tr>
	<tr>
		<td>
		<table border="0" cellpadding="10" cellspacing="0" width="100%">
			<tr>
				<td>
				<table border="0" cellpadding="0" cellspacing="0" width="100%">
					<tr>
						<td class="contentBackCol1" width="5"></td>	
						<td class="contentBackCol2">
						<table border="0" cellpadding="0" cellspacing="0" width="100%">
						<tr>
							<td><?php echo tep_draw_separator('pixel_trans.gif','1','10');?></td>	
						</tr>
								<?php 
									// display the category details
									$cat_query=tep_db_query("SELECT ecd.events_categories_name,ec.events_categories_image,if(CHAR_LENGTH(ecd.events_categories_description)>250,concat(left(ecd.events_categories_description,250),'...'),ecd.events_categories_description) as events_categories_description from " . 
															TABLE_EVENTS_CATEGORIES . " ec, " . TABLE_EVENTS_CATEGORIES_DESCRIPTION . " ecd " .
															" where ecd.events_categories_id='" . $category_id . "' and ecd.language_id='" . $languages_id . "' and ecd.events_categories_id=ec.events_categories_id");
									$cat_info=tep_db_fetch_array($cat_query);
								?>
										<tr height="100">
											<td valign="top">
											<table border="0" cellpadding="2" cellspacing="2" valign="top" width="100%">
												<tr>
													<td valign="top" class="headerBrowse" ><?php echo $cat_info['events_categories_name'];?></td>
												</tr>
												<tr>
													<td valign="top" class="smalltext" >
														<?php 
														echo ($cat_info['events_categories_image']==''?'':tep_image(DIR_WS_IMAGES . $cat_info['events_categories_image'] , $cat_info['events_categories_name'],SMALL_IMAGE_WIDTH,SMALL_IMAGE_HEIGHT,'align=right'));
														echo $cat_info['events_categories_description'];
													?>
													</td>
												</tr>
											</table>						
											</td>
										</tr>
										<tr>
											<td><?php echo tep_draw_separator('pixel_trans.gif',1,20);?></td>
										</tr>
							<?php 
							   $event_count=tep_db_num_rows($event_info_query);
								// iterate with the events
								while($event_info=tep_db_fetch_array($event_info_query)){
									$events_id=$event_info["events_id"];
									$find_sessions_query=tep_db_query("SELECT s.events_id,s.start_date,s.sessions_id from " . TABLE_EVENTS_SESSIONS . " s ".
																	" where "." s.start_date>'" .  $server_date . "' " ." and s.events_id=".$events_id." and s.sessions_type in('R','S') order by s.start_date limit 6");
									// check for some session exists in the event
									$rows_count=tep_db_num_rows($find_sessions_query);
									if ($rows_count>0){
										$detail_link=tep_href_link(FILENAME_SESSION_DETAILS,'events_id=' . $events_id . '&ecPath=' . $ecPath);
							?>							
										<tr>
											<td>
											<table cellpadding="0" cellspacing="4" width="100%" >
												<tr>
													<td align="left" width="100">
													<table cellpadding="0" cellspacing="0" border=0 height="100%" width="100%">
														<tr> 
															<td width="9"><?php echo tep_image($cur_templ_path ."view_col_tl.gif");?></td>
															<td class="viewColTop"></td>
															<td width="9"><?php echo tep_image($cur_templ_path ."view_col_tr.gif");?></td>
														</tr>
														<tr>
															<td class="viewColLeft"></td>
																<td>
																<table cellpadding="2" cellspacing="0" border=0 height="100%" width="100%" class="viewContent">
																	<tr>
																		<td class="eventTitleMedium" align="center" valign="top">
																			<?php echo '<a href="' . $detail_link . '" class="eventTitleMediumLink">' . $event_info['events_name'] . '</a>'; ?>
																		</td>
																	</tr>
																	<tr>
																		 <td class="main" align="center"><?php echo $currencies->display_price($event_info['events_fees'],tep_get_tax_rate($event_info['events_tax_class_id']),'1',true);?></td>
																	</tr>
																	<tr>
																		<td class="eventTitleMedium" nowrap align="left">
																			<?php echo '<a href="' . $detail_link . '" class="eventTitleMediumLink">' . tep_template_image("book_now.gif",TEXT_BOOK_NOW,'','','align=absmiddle') .'&nbsp;&nbsp;'.  TEXT_BOOK_NOW . '</a>';?>
																		</td>
																	</tr>
																</table>
																</td>
															<td class="viewColRight"></td>
														</tr>
														<tr>
															<td width="9"><?php echo tep_image($cur_templ_path ."view_col_bl.gif");?></td>
															<td class="viewColBottom"></td>
															<td width="9"><?php echo tep_image($cur_templ_path ."view_col_br.gif");?></td>
														</tr>
													</table>
													</td>
													<td height="60" valign="top">
													<table cellpadding="0" cellspacing="0" border="0" width="100%" height="100%">
														<tr>
															<td align="left">
															<table cellpadding="0" cellspacing="0" border=0 height="100%" width="100%">
																<tr> 
																	<td width="9"><?php echo tep_image($cur_templ_path ."view_col_tl.gif");?></td>
																	<td class="viewColTop"></td>
																	<td width="9"><?php echo tep_image($cur_templ_path ."view_col_tr.gif");?></td>
																</tr>
																<tr>
																	<td class="viewColLeft"></td>
																		<td class="viewcontent">																																			
						  												   <table cellpadding="2" cellspacing="0" border=0 height="100%" width="100%" class="viewContent">
																			<tr><td class="smallText" valign="top"><?php echo $event_info['events_description']; ?></td></tr>
																			<tr><td class="smallText" valign="middle" >
																				<table border="0" cellpadding=2 cellspacing="0" width="100%">
																					<tr>
																					<td class="main" width="50"><b><?php echo TEXT_DATES;?></b></td>
																					<td>
																					<table border="0" cellpadding=0 cellspacing="0">
																						<tr>
																					<?php
																						// display the sessions
																						$jcnt=1;
																						while($find_sessions_result=tep_db_fetch_array($find_sessions_query)){
																						
																							echo '<td class="viewDate" align="left" width="60"><a href="' . 
																									tep_href_link(FILENAME_SESSION_DETAILS,'ecPath=' . $ecPath . '&events_id=' . $events_id . '&sID=' . $find_sessions_result["sessions_id"])
																									 . '" class="viewDateLink">' .	date("M d" ,strtotime($find_sessions_result["start_date"])) . '</a></td>';
																							$jcnt=$jcnt+1;
																						}
																						
																					?>
																						</tr>
																					</table>
																					</td>
																					</tr>
																				</table>
																				</td>
																			</tr>
																		</table>
																		</td>
																		<td class="viewColRight"></td>
																	</tr>
																	<tr>
																		<td width="9"><?php echo tep_image($cur_templ_path ."view_col_bl.gif");?></td>
																		<td class="viewColBottom"></td>
																		<td width="9"><?php echo tep_image($cur_templ_path ."view_col_br.gif");?></td>
																	</tr>
																</table>
																</td>
															</tr>
														</table>
													</td>
												</tr>
											</table>
										<?php
										} // found session
									}
									if ($event_count==0) echo '<tr><td class="main" align="center">' . TEXT_NO_EVENTS_FOUND . '</td></tr>';
								?>
						  </td>
						</tr>	
						<tr>
						<input type="hidden" name="post_action" value="change_cat">
						</form>
					</table>
					</td>
					<td width="5" class="contentBackCol3"></td>			   
		   </tr>
		</table>
		</td>
	</tr>
	</table>
	</td>
</tr>
<?php // BOF: Lango Added for template MOD
if (MAIN_TABLE_BORDER == 'yes'){
	table_image_border_bottom();
	}
	// EOF: Lango Added for template MOD
	?>		
			
</table>