<?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_VIEW3,$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_image, e.events_fees,e.events_tax_class_id, 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_VIEW3);?>";
				}
						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>
				<td valign="middle" align="right" width="300" class="eventTitle">
					
				</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 if ($category_id>0) {
							// select 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>
											<?php 
											 // fetch all the necessary events
					    //$event_info_query = tep_db_query("select e.events_id, e.events_fees, ed.events_name,e.events_tax_class_id, 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 . "'");
						$rows_count=tep_db_num_rows($event_info_query);
								if ($rows_count>0){
						?>
										</tr>
					<tr height="100">
					 <td valign="top">
					  <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>
								  <table border="0" cellpadding="3" cellspacing="2" width="98%" >
								  
									 <tr>
										<td width="30%" class="main">&nbsp;</td>
								   		<td class="main" align="left"><b> <?php  echo TEXT_COST;?> </b></td>
										<?php
										$month=date("n",strtotime($server_date));
										$year=date("Y",strtotime($server_date));
										$month_number=$month;
										for($icnt=1;$icnt<=5;$icnt++)
										{
										 if($month_number>12)
										 {
										 $month_number=1;
										 $year=$year+1;
										 }
										 else
										 {
										 echo '<td class="viewDate" align="left" width="100"><b>' . constant("TEXT_MONTH" . $month_number) . '</b></td>';
										 $month_number=$month_number+1;
										}
										}
										'</tr>';
  									while($events_info_result=tep_db_fetch_array($event_info_query))
									  {
									    $events_id=$events_info_result["events_id"];
										
										$detail_link=tep_href_link(FILENAME_SESSION_DETAILS,'events_id=' . $events_id . '&ecPath=' . $ecPath);
					
										$events_info=array("events_name"=>$events_info_result["events_name"],
										                   "events_date_available"=>$events_info_result["events_date_available"],
										                   "events_fees"=>$events_info_result["events_fees"],
														   "events_tax_class_id"=>$events_info_result["events_tax_class_id"]); 
										 $end_month=$month_number;									  
										$maketime=mktime(0,0,0,$end_month,0,$year);
										$last_day=strftime("%Y-%m-%d",$maketime);
									  echo '<tr><td class="eventTitleMedium" valign="top"><a href="' . $detail_link . '" class="eventTitleMediumLink">' . $events_info["events_name"] .'</a> </td> ' .
									              '<td class="main" valign="top" align="left">' . $currencies->display_price($events_info['events_fees'],tep_get_tax_rate($events_info['events_tax_class_id']),'1',true) .'  </td> ';
										// to fetch the session dates
										$find_sessions_query=tep_db_query("SELECT s.events_id, s.sessions_id, date_format(s.start_date,'%d %b') as start_date ,date_format(s.start_date,'%c') as sample_date ,s.sessions_id from " . TABLE_EVENTS_SESSIONS . " s ".
																	" where  s.events_id=".$events_id." and  s.sessions_type in('R','S')  and s.start_date between '" .  $server_date . "'  and  '". $last_day .    "' order by s.start_date  ");
											unset( $month_array[$sample_date]);
											while($find_sessions_result=tep_db_fetch_array($find_sessions_query))
											{
											$sample_date=$find_sessions_result["sample_date"];
							
											  $month_array[$events_id][$sample_date][]=array("session_date"=>$find_sessions_result["start_date"],"sessions_id"=>$find_sessions_result["sessions_id"]);
											  
											}
												$month_count=$month;
												for($mcnt=1;$mcnt<=6;$mcnt++)
												 {
												   echo  '<td class="main"  align="center">';
												  
													if($month_count>12)
					    						  {
													  $arr_month=1;
													  }
								
													if(isset($month_array[$events_id][$month_count]))
													 {
													 for($arrcnt=0;$arrcnt<=5;$arrcnt++)
													  {
													  echo '<a href="' . tep_href_link(FILENAME_SESSION_DETAILS,'ecPath=' . $ecPath . '&events_id=' . $events_id . '&sID=' . $month_array[$events_id][$month_count][$arrcnt]["sessions_id"])
															. '" class="viewDateLink">' . $month_array[$events_id][$month_count][$arrcnt]["session_date"] . '</a>';
													  echo "<br \>";
													  }
													  echo '</td>';
													 } 
													$month_count=$month_count+1;
												}
												//echo '</td>';
												echo '</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>
				   <?php }
					 }
					 if ($rows_count==0) echo '<tr><td class="main" align="center">' . TEXT_NO_EVENTS_FOUND . '</td></tr>';
					?>
							<tr>
								<td><?php echo tep_draw_separator('pixel_trans.gif',1,15);?></td>
							</tr>
						<tr>
						<input type="hidden" name="month" value="<?php echo $month;?>">
						<input type="hidden" name="year" value="<?php echo $year;?>">
						<input type="hidden" name="check_server_year" value="<?php echo $server_year;?>">
						<input type="hidden" name="current_date" value="<?php echo $server_date;?>">
						<input type="hidden" name="post_action" value="change_cat">
						</form>
						<?php
							// display post data as hidden value
							$page_param=(isset($HTTP_SESSION_VARS["calendar_style"])?$HTTP_SESSION_VARS["calendar_style"]:"day");
							if ($page_param=="month") {
								$page_name=FILENAME_EVENTS_MONTH_VIEW;
							} else if ($page_param=="week"){
								$page_name=FILENAME_EVENTS_WEEK_VIEW;
							} else if ($page_param=="day"){
								$page_name=FILENAME_EVENTS_DAY_VIEW;
							} else {
								$page_name=basename($GLOBALS["PHP_SELF"]);
							}
							echo tep_draw_form("frmPrevious",tep_href_link($page_name,$ecCat_path));
							echo '<input type="hidden" name="temp" value="1">';
								$view_state=(isset($HTTP_SESSION_VARS["VIEW_STATE"])?$HTTP_SESSION_VARS["VIEW_STATE"]:array());
							if (sizeof($view_state)){
							  reset($view_state);
							  while (list($key, $value) = each($view_state)) {
								if (!is_array($view_state[$key])) {
								  echo tep_draw_hidden_field($key, htmlspecialchars(stripslashes($value)));
								}
							  }
							}
							echo '</form>';
							tep_set_session_value("VIEW_STATE",$HTTP_POST_VARS);
							tep_set_session_value("calendar_style","month");
						?>
						
							</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>