<?php
/*

  osCommRes, Services Oline 
http://www.oscommres.com 
Copyright (c) 2005 osCommRes 

Freeway eCommerce 
http://www.zac-ware.com/freeway 
Copyright (c) 2007 ZacWare

Released under the GNU General Public License 
*/
// Set flag that this is a parent file
	define( '_FEXEC', 1 );
	$command=(isset($HTTP_GET_VARS["command"])?$HTTP_GET_VARS["command"]:'');
	if ($command=="fetch_session_details"){
		require('includes/sms_application_top.php');
		tep_get_last_access_file();
		require(DIR_WS_INCLUDES . 'functions/events_sessions.php');
		require(DIR_WS_LANGUAGES . $language . "/events_browse.php");
		
		/*header("Last-Modified: " . gmdate("D, d M Y H:i:s", time()-10) . " GMT");
		header("Expires: " . gmdate("D, d M Y H:i:s", time() + 5) . " GMT");
		header("Pragma: no-cache");
		header("Cache-Control: max-age=1, s-maxage=1, no-cache, must-revalidate");*/
		$events_id=(isset($HTTP_GET_VARS["events_id"])?(int)$HTTP_GET_VARS["events_id"]:0);
		
	
		// fetch event details
		$events_query=tep_db_query("SELECT " . tep_event_fields_list() . ",ed.events_name,e.events_instructor,e.events_location,e.events_start_time," . 
									"events_start_time as start_time,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,e.events_date_available,ed.events_description,ecd2.events_categories_id,ecd2.events_id from " . 
									TABLE_EVENTS . " e, " . TABLE_EVENTS_DESCRIPTION . " ed,". TABLE_EVENTS_TO_EVENTS_CATEGORIES ." ecd2 where  e.events_id=ecd2.events_id and ed.events_id=ecd2.events_id and e.events_id='" . $events_id  . "' " . EVENTS_CONDITION_STATUS . " and ed.language_id='" . (int)$languages_id . "' order by events_name");

		if (tep_db_num_rows($events_query)<=0) {
			echo TEXT_NO_DETAILS;
			return;
		}
		$events_result=tep_db_fetch_array($events_query);
		// check for the forward reservation period
		if ($events_result['events_forward_period']=='Y'){
			$check_date=date('Y-m-d',tep_dateadd(time(),'day',(int)$events_result['events_forward_length']));
			$add_option=" and start_date<='" . $check_date . "' ";
		}
		$start_option=" and start_date>curdate() ";

		$date_query=tep_db_query("SELECT start_date,sessions_id,recursive_sessions_id from " . TABLE_EVENTS_SESSIONS  .  " where events_id='" . (int)$events_id . "'" . $start_option . $add_option . " and sessions_type!='' order by start_date");
		if (tep_db_num_rows($date_query)<=0) {
			echo TEXT_NO_DETAILS;
			return;
		}
		$prev_recursive=0;
		$recursive_array=array();
		$icnt=0;
		$dates=array();
		while($date_result = tep_db_fetch_array($date_query))
		{
			$details=tep_get_session_details($date_result,$events_result);
			$color="#FF0000";
			if ($details['status']=='R') $color="#000000";
			if ($details['status']=='W')$color="FFA715";
			$dates[] = array(	'id' =>$date_result["sessions_id"],
								'date'=> $date_result['start_date'],
								'type'=> $details['status'],
								'recursive_id'=>$date_result["recursive_sessions_id"],
								'group'=>'',
								'reserved'=>$details["reserved"],
								'waitlist'=>$details["waitlist"],
								'renewal'=>$details["renewal"],
								'bgcolor'=>$color
							);
							
			if ($session_type=='R' && $prev_recursive!=$date_result["recursive_sessions_id"]){
				$prev_recursive=$date_result["recursive_sessions_id"];
				$recursive_array[]=$prev_recursive;
			}
		}
		if ($session_type=='R' && sizeof($recursive_array)>0){
			$result_array=get_gap_dates_array($recursive_array);
			if (sizeof($result_array)>0){
				for ($icnt=0;$icnt<sizeof($result_array);$icnt++){
					$dates[]=array('date'=>$result_array[$icnt],'type'=>'H','group'=>'','bgcolor'=>'','reserved'=>0,'waitlist'=>0,'renewal'=>0,'recursive_id'=>0);
				}
				usort($dates,"user_compare");
			}
		}
		$dates_content=fetch_dates_content($dates);
		echo $dates_content;
		return;
	}
	require('includes/application_top.php');
	require('includes/classes/currencies.php');
	require(DIR_WS_INCLUDES . 'functions/events_sessions.php');
	
	$currencies=new currencies();
	$current_events_category_id=isset($HTTP_GET_VARS['ecID'])?(int)$HTTP_GET_VARS['ecID']:0;
	

	
	$category=array();
	
	if(BROWSE_EVENT_STYLE=='Standard')
		$events_categories_array[] = array('id'=>0,'text'=>'All Event');
	else
		$events_categories_array = array();
	
	$events_categories_array = array_merge($events_categories_array,tep_get_event_category_tree('','',0));


	if($current_events_category_id<=0) $current_events_category_id=(int)$events_categories_array[0]['id'];
	

	if ($current_events_category_id>0) $events_category_option=" and ecd2.events_categories_id='" . $current_events_category_id . "' ";


	$category_query=tep_db_query("SELECT ecd.events_categories_name,ecd2.events_categories_id,ecd2.events_id from " . TABLE_EVENTS_CATEGORIES_DESCRIPTION . " ecd, " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " ecd2, " . TABLE_EVENTS_DESCRIPTION . " ed, " . TABLE_EVENTS . " e " .
									" where e.events_id=ed.events_id and ecd.events_categories_id=ecd2.events_categories_id and ecd2.events_id=ed.events_id and ecd.language_id='" . $languages_id ."' and ed.language_id='" . $languages_id . "' " . EVENTS_CONDITION_STATUS . $events_category_option . " group by ecd2.events_id order by ecd.events_categories_name,ed.events_name");
	$category=array();
	while($category_result=tep_db_fetch_array($category_query)){
		$cat_id=$category_result["events_categories_id"];
		if (!isset($category[$cat_id])){
			$category[$cat_id]=array('name'=>$category_result["events_categories_name"],'events'=>array());
		}
		$category[$cat_id]['events'][]=$category_result["events_id"];
	}

	$events_query=tep_db_query("SELECT " . tep_event_fields_list() . ",ed.events_name,e.events_instructor,e.events_location,e.events_start_time," . 
								"events_start_time as start_time,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,e.events_date_available,ed.events_description,ecd2.events_categories_id,ecd2.events_id from " . 
								TABLE_EVENTS . " e, " . TABLE_EVENTS_DESCRIPTION . " ed,". TABLE_EVENTS_TO_EVENTS_CATEGORIES ." ecd2 where  e.events_id=ecd2.events_id and ed.events_id=ecd2.events_id " . $events_category_option  . EVENTS_CONDITION_STATUS . $events_option ." and ed.language_id='" . (int)$languages_id . "' order by events_name");

	$event_found=false;
	if (tep_db_num_rows($events_query)>0) $event_found=true;
	$events=array();
	if ($event_found)	{
		while($events_result=tep_db_fetch_array($events_query)){
			$events_id=$events_result["events_id"];
			
			$add_option="";

			$session_type=tep_get_session_type($events_id);

			$location_content=fetch_location_content($events_id,$events_result['events_location']);
			$instructor_content=fetch_instructor_content($events_id,$events_result['events_instructor']);
			$event_content=fetch_events_content($events_id,$events_result["events_description"]);
			
			$session=tep_get_first_session($events_result);
			$events[$events_id]=array(	'details'=>$events_result,
										'start'=>'',
										'location'=>$location_content[1],
										'instructor'=>$instructor_content[1],
										'instruct_id'=>$instructor_content[2],
										'instructors_id'=>$instructor_content[3],
										'start'=>$session
									);

			$final_content.=$event_content . $location_content[0] . $instructor_content[0];
		}
	}
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<style type="text/css">
	#pup {position:absolute; visibility:hidden; z-index:200; width:130; }
</style>
<script language="javascript" src="includes/menu.js"></script>
<script language="javascript" src="includes/general.js"></script>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
<script language="javascript" src="includes/popup.js"></script>
<script language="javascript" src="includes/http.js"></script>
<script language="JavaScript">
	var baby=new Array();
	var pevents_id=0;
	baby[1]="";
	var openpopup=0;
	function showpopup(type,events_id)
	{
		// check if popup has already opened
		if (skin.visibility=="visible") return;
		var element=document.getElementById(type+events_id);
		var content;
		if (!element) return;
		if (element.innerHTML=="" && type!='sessiondesc_') return;
		
		content='<table border="0" cellspacing="0" cellpadding="4" class="formArea" width="100%"><tr><td id="popContent" class="main">';

		// if type is session then display message loading
		if (type=='sessiondesc_'){
			content+="<?php echo TEXT_LOADING;?>";
			popwidth=230;
		} else {
			content+=element.innerHTML;
			popwidth=250;
		}

		content+='</div></td></tr></table>';
		baby[1]=content;
		if (baby[1]!=""){
			popup("1","#ffffff");
		}	
		// if needed to get the contents using ajax
		if (type=="sessiondesc_"){
			command="<?php echo tep_href_link(FILENAME_EVENTS_BROWSE);?>?command=fetch_session_details&events_id="+events_id;
			do_get_command(command);
		}
	}
	function do_result(result){
		// assign the result content
		element=document.getElementById("popContent");
		if (element) element.innerHTML=result;
	}
	function chkclick(frm)
	{
			if (document.goto.create_customer.checked==true){	
				frm.action="<?php echo FILENAME_CREATE_ACCOUNT;?>";
			} else {
				frm.action="<?php echo FILENAME_CREATE_ORDER_NEW; ?>";
			}
	}
	function closepopup(){
		do_close();
		kill();
	}
//  End -->

</script>
	<!-- header //-->
	<?php 
	require(DIR_WS_INCLUDES . 'header.php'); ?>
	<!-- header_eof //-->
	<!-- body //-->
<?php echo $final_content; ?>
<table border="0" width="100%" cellspacing="2" cellpadding="2">
	<tr> 
		<!-- body_text //-->	  
		<td width=100% align=left valign="top">
		<table border="0" width="100%" cellspacing="0" cellpadding="0">
			<tr>
				<td class="pageHeading">
					<?php echo TEXT_HEADING_TITLE;?>
				</td>
			</tr>
			<tr>
				<td width="100%">
				<table border="0" width="100%" cellspacing=0 cellpadding="4">
					<tr>
						<td>
							<table border="0" width="100%" cellspacing=0 cellpadding="0">
							<tr>
								<td><?php echo tep_draw_separator('pixel_trans.gif',10,10);?></td>
							</tr>
			<tr>
				<td class="main" colspan="5">
				<?php 
				echo tep_draw_form('goto', FILENAME_EVENTS_BROWSE, '', 'get');
				echo HEADING_TITLE_EVENT . ' ' . tep_draw_pull_down_menu('ecID',$events_categories_array, $current_events_category_id, 'onChange="this.form.submit();"'); 
				if (tep_db_num_rows($events_query)){
					echo '&nbsp;&nbsp;&nbsp;' . tep_draw_checkbox_field('create_customer', '',false,'') . '&nbsp;' . TEXT_CREATE_CUSTOMER;
				}
				echo '</form>&nbsp;&nbsp;';
				?>
			</tr>
			
			<tr>
			<td><?php echo tep_draw_separator('pixel_trans.gif',10,10);?></td>
			</tr>

		<?php 
			if ($event_found){		
			$one_time_display = true;
			$flagth=0;		
			
			while(list($category_id,)=each($category)){
			 if(BROWSE_EVENT_STYLE=='Standard'){		?>

					<tr>
						<td>
						<table border="0" cellpadding="0" cellspacing="0" width="100%"><?php
						if($flagth==0)
						{?>
						<tr class="cell_bg_report_header_new">
							<td width="18%"><?php echo TABLE_HEADING_TITLE_EVENT_CLASSES;?></td>
							<td width="10%"><?php echo TABLE_HEADING_TITLE_EVENT_INSTRUCTOR;?></td>
							<td width="10%" align="left"><?php echo TABLE_HEADING_TITLE_EVENT_INTERVALS;?></td>
							<td width="15%" align="center"><?php echo TABLE_HEADING_TITLE_EVENT_SESSIONS;?></td>
							<td width="10%"><?php echo TABLE_HEADING_TITLE_EVENT_LOCATION;?></td>
							<td width="10%" align="center"><?php echo TABLE_HEADING_TITLE_EVENT_SEATS;?></td>
							<td width="17%" align="center"><?php echo TABLE_HEADING_TITLE_EVENT_FEES;?></td>							
						<tr>
							<tr><?Php
							$flagth=1;
						}?>
								<td class="tableHeading">
									<?php echo '<font color="#0000FF">' . $category[$category_id]['name'] . '</font>';?>
								</td>
							</tr>
						</table>
						</td>
					</tr>
					<tr class="attributes-odd"><td><?php echo tep_draw_separator('pixel_trans.gif',10,10);?></td></tr>
		<?php 
					for ($kcnt=0;$kcnt<sizeof($category[$category_id]['events']);$kcnt++){
						$events_id=$category[$category_id]['events'][$kcnt];
						if (isset($events[$events_id])){
							$event=&$events[$events_id]['details'];
							$events_name=$event["events_name"];
						?>
						<tr>
							<td>
							<table border="0" cellpadding="2" cellspacing="0" width="100%" class="tableArea">
								<tr class="eventInfo" id="<?php echo "row_0" . $events_id;?>">
									<td class="smalltext" width="16%" onMouseOver="javascript:showpopup(<?php echo "'eventdesc_','" . $events_id . "'";?>)" onMouseOut="javascript:kill()"><b><?php echo $events_name;?></b></td>
									<td class="smalltext" valign="top" onMouseOver="javascript:showpopup(<?php echo "'instructor_','" . $events_id . "'";?>)" onMouseOut="javascript:kill()" width="8%"><?php echo $events[$events_id]["instructor"];?></td>
									<td class="smalltext" width="10%" valign="top" align="center"><?php echo tep_get_event_daytext($events_id);?></td>
									<td class="smalltext" width="15%" valign="top" align="center"><?php echo $event["events_start_time"] . "-" . $event["events_end_time"];?></td>
									<td class="smalltext" width="10%" valign="top" onMouseOver="javascript:showpopup(<?php echo "'location_','" . $events_id . "'";?>)" onMouseOut="javascript:kill()" align="center"><?php echo $events[$events_id]['location'];?></td>
									<td class="smalltext" width="10%" valign="top" align="right" align="center"></td>
									<td class="smalltext" width="15%" valign="" align="right" align="center">
										<?php 	$interval=($event["sessions_select_interval"]>0?$event["sessions_select_interval"]:1);
												$fees=$interval*tep_add_tax($event["events_fees"],tep_get_tax_rate($event["events_tax_class_id"]));
												$info=TEXT_FEES_INFO_SINGLE;
												if ($interval>1) $info=TEXT_FEES_INFO;
												echo $currencies->format($fees).sprintf($info,$interval);
										?>
								
									</td>
									
								</tr>
								<tr class="eventInfo" id="<?php echo "row_1" . $events_id;?>">
									<td colspan="3"></td>
									
									<td class="smalltext" valign="top" width="15%" align="center">

									<?php 
										$color="#000000";
										$start_element=$events[$events_id]['start'];
										
										if ($start_element['type']=='W') $color="#FFA715";
										if ($start_element['type']=='R' || $start_element['type']=='W'){
											echo '<div onMouseOver="javascript:showpopup(\'sessiondesc_\',\'' . $events_id . '\');" onMouseOut="javascript:closepopup();">';
											echo '<b>' . TEXT_START_DATE . '</b><font color="' . $color . '" >' . format_date($start_element['date']) . '</font>';
										} else {
											echo '<span class=errorText>' . TEXT_NO_SESSIONS . '<span>';
										}
									?>
									</div>
									</td>
									<td></td>
									<td class="smalltext" valign="top" align="center">
										<?php 	if ($start_element['type']=='R') 
													echo '<b>' . TEXT_SPACES . '</b>' . $start_element['spaces'];
												else if ($start_element['type']=='W')
													echo '<b>' . TEXT_SPACES . '</b>' . $start_element['spaces'];
										?>
									</td>
									<td class="smalltext" align="right" valign="top">
									<?php
									//standard
										if ($start_element['type']=='R' || $start_element['type']=='W'){
											echo tep_draw_form('create_order_'.$events_id,FILENAME_CREATE_ORDER_NEW,'' ,'post','onsubmit="chkclick(this);"');
											echo '<input type="hidden" name="action" value="event_browse">';
											echo '<input type="hidden" name="param_event" value="' . $events_id .'">';
											echo '<input type="hidden" name="param_session" value="' . $start_element['id'] .'">';
											echo tep_image_submit('button_add.gif',IMAGE_RESERVE,'align=absmiddle');
											echo '</form>';
										}
									?>
									</td>
								</tr>
								
							</table>
							</td>
						<tr>
						<tr class="attributes-odd"><td><?php echo tep_draw_separator('pixel_trans.gif',10,10);?></td></tr>
		<?php			}
					}
				}  else { // Customer Style
		$class_name = 'dataTableRowEven';
		for ($kcnt=0;$kcnt<sizeof($category[$category_id]['events']);$kcnt++){
		$class_name = ($class_name=='dataTableRowEven')?'dataTableRowOdd':'dataTableRowEven';
			$events_id=$category[$category_id]['events'][$kcnt];
			if (isset($events[$events_id])){
							$event=&$events[$events_id]['details'];
							$events_name=$event["events_name"];
							
			$events_query=tep_db_query("SELECT " . tep_event_fields_list() . ",ed.events_name,e.events_instructor,e.events_location,e.events_start_time," . 
						"events_start_time as start_time,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,e.events_date_available,ed.events_description,ecd2.events_categories_id,ecd2.events_id from " . 
						TABLE_EVENTS . " e, " . TABLE_EVENTS_DESCRIPTION . " ed,". TABLE_EVENTS_TO_EVENTS_CATEGORIES ." ecd2 where  e.events_id=ecd2.events_id and ed.events_id=ecd2.events_id and e.events_id>=2 and e.events_id<=4 " . EVENTS_CONDITION_STATUS . " and ed.language_id='" . (int)$languages_id . "' order by events_name");

		if (tep_db_num_rows($events_query)<=0) {
			echo TEXT_NO_DETAILS;
		}
		$events_result=tep_db_fetch_array($events_query);
		// check for the forward reservation period
		if ($events_result['events_forward_period']=='Y'){
			$check_date=date('Y-m-d',tep_dateadd(time(),'day',(int)$events_result['events_forward_length']));
			$add_option=" and start_date<='" . $check_date . "' ";
		}
		$start_option=" and start_date>curdate() ";
		if($kcnt==0){
		if($events_id>1){
		$date_query=tep_db_query("SELECT distinct(es.sessions_id) as sessions_id,TIME_FORMAT(e.events_start_time,'%h:%i:%s %p') as events_start_time,TIME_FORMAT(e.events_end_time,'%h:%i:%s %p') as events_end_time,ed.events_name,es.start_date,es.recursive_sessions_id from " . TABLE_EVENTS_SESSIONS  .  " es," . TABLE_EVENTS_DESCRIPTION  .  " ed," . TABLE_EVENTS . " e where es.events_id>=2 and es.events_id<=4 and e.events_id=es.events_id and es.start_date>curdate() and ed.events_id=es.events_id and es.start_date<='2008-10-13' and es.sessions_type!='' order by es.start_date");
		} else{
		$date_query=tep_db_query("SELECT distinct(es.sessions_id) as sessions_id,TIME_FORMAT(e.events_start_time,'%h:%i:%s %p') as events_start_time,TIME_FORMAT(e.events_end_time,'%h:%i:%s %p') as events_end_time,ed.events_name,es.start_date,es.recursive_sessions_id from " . TABLE_EVENTS_SESSIONS  .  " es," . TABLE_EVENTS_DESCRIPTION  .  " ed," . TABLE_EVENTS . " e where es.events_id=".$events_id." and e.events_id=es.events_id and es.start_date>curdate() and ed.events_id=es.events_id and es.start_date<='2008-10-13' and es.sessions_type!='' order by es.start_date");		
		}
		}
		if (tep_db_num_rows($date_query)<=0) {
			echo TEXT_NO_DETAILS;
		}
		$prev_recursive=0;
		$recursive_array=array();
		$icnt=0;
		$dates=array();
		$zee=0;
		while($date_result = tep_db_fetch_array($date_query))
		{
			$details=tep_get_session_details($date_result,$events_result);
			$color="#FF0000";
			if ($details['status']=='R') $color="#000000";
			if ($details['status']=='W')$color="FFA715";
			$dates[] = array(	'id' =>$date_result["sessions_id"],
								'date'=> $date_result['start_date'],
								'type'=> $details['status'],
								'recursive_id'=>$date_result["recursive_sessions_id"],
								'group'=>'',
								'reserved'=>$details["reserved"],
								'waitlist'=>$details["waitlist"],
								'renewal'=>$details["renewal"],
								'bgcolor'=>$color,
								'events_name'=>$date_result['events_name'],
								'start_time'=>$date_result['events_start_time'],
								'end_time'=>$date_result['events_end_time']
							);
			if ($session_type=='R' && $prev_recursive!=$date_result["recursive_sessions_id"]){
				$prev_recursive=$date_result["recursive_sessions_id"];
				$recursive_array[]=$prev_recursive;
			}
			$zee++;
		}

		if ($session_type=='R' && sizeof($recursive_array)>0){
			$result_array=get_gap_dates_array($recursive_array);
		if (sizeof($result_array)>0){
			for ($icnt=0;$icnt<sizeof($result_array);$icnt++){
				$dates[]=array('date'=>$result_array[$icnt],'type'=>'H','group'=>'','bgcolor'=>'','reserved'=>0,'waitlist'=>0,'renewal'=>0,'recursive_id'=>0);
			}
			usort($dates,"user_compare");
		}
		}

		$previous_dates = '';
		$prev_dates='';
		for($i=0,$n=sizeof($dates);$i<$n;$i++){
		$total_dates = "";
		if ($dates[$i]['type']=='R')
			$total_dates = $dates[$i]["reserved"];
		if($dates[$i]['type']=='W')
			$total_dates = $dates[$icnt]["waitlist"];
		if($dates[$i]['type']=='E')
		 	$total_dates = 0;
		$class_name = ($class_name=='dataTableRowEven')?'dataTableRowOdd':'dataTableRowEven';	?>
			<?php if($dates[$i]['date']!=$previous_dates || $previous_dates!=''){ 
			$display_date = '';
			$day_name_query = tep_db_query("SELECT DAYNAME('{$dates[$i]['date']}') as dayname, date_format('{$dates[$i]['date']}','%M %d') as month_date, date_format('{$dates[$i]['date']}','%Y') as year ");
			$day_name_array = tep_db_fetch_array($day_name_query);
			$display_date = '<b style="color:#8D4E06;font-size:16px;">'.$day_name_array['dayname'].'</b> &nbsp;<span style="color:#4E90C4;font-weight:bold; font-size:12px;">'.$day_name_array['month_date'].', '.$day_name_array['year'].'</span>';

			if($one_time_display){	?>
			<?php
			$one_time_display = false;
			} }	?>		
		<?php
		if($prev_dates!=$dates[$i]['date']){ 
		?>		
		<tr valign="middle" style="height:30px; font-family:Verdana, Arial, Helvetica, sans-serif; font-weight:bold;">
			<td  width="30%" nowrap="nowrap" style="font-size:14px;border-bottom:solid 1px #ADADAD; border-top:solid 1px #ADADAD; padding-top:10px;" class="dataTableHeadingContent"><?php echo $display_date; ?></td>
			<td style="border-bottom:solid 1px #ADADAD; border-top:solid 1px #ADADAD; padding-top:10px;" width="15%" class="dataTableHeadingContent"><?php echo TEXT_SIGNED_IN; ?></td>
			<td style="border-bottom:solid 1px #ADADAD; border-top:solid 1px #ADADAD; padding-top:10px;" width="20%" class="dataTableHeadingContent"><?php echo TEXT_EVENT_NAME; ?></td>
			<td style="border-bottom:solid 1px #ADADAD; border-top:solid 1px #ADADAD; padding-top:10px;" width="15%" class="dataTableHeadingContent"><?php echo TEXT_INSTRUCTORS; ?></td>
			<td style="border-bottom:solid 1px #ADADAD; border-top:solid 1px #ADADAD; padding-top:10px;" width="20%" class="dataTableHeadingContent" nowrap="nowrap"><?php echo TEXT_LOCATION; ?></td>
		</tr>
		<?php } ?>
		<tr height="20" valign="middle" style="border-bottom:solid 1px #FF0000;">
		<td colspan="5" width="100%">	
			<table width="100%" cellpadding="5" cellspacing="0" border="0">
<!-- /pre	-->
			<tr class="<?php echo $class_name; ?>">
			<?php //print_r($events[$events_id]); ?>
			<td width="32%" style="color:#8D4E06;" class="main"><?php echo $dates[$i]["start_time"] . "-" . $dates[$i]["end_time"];?></td>
			<td width="15%" nowrap="nowrap" class="main">Sign In (<?php echo $dates[$i]["renewal"].'/'.$total_dates; ?>)</td>
			<td width="20%" nowrap="nowrap" class="main" style="cursor:pointer;" onClick="javascript:location.href='<?php echo tep_href_link(FILENAME_EVENTS_MAINPAGE,'actions=edit_products&p_id='.$events[$events_id]['details']['events_id'].'&c_id='.$events[$events_id]['details']['events_categories_id']);?>';"><?php echo $dates[$i]['events_name']; ?></td>
			<td width="18%" class="main" <?php echo (($events[$events_id]["instructor"]!='')?'style="cursor:pointer;"':'');?> onClick="javascript:location.href='<?php echo (($events[$events_id]["instructor"]!='') ? tep_href_link(FILENAME_INSTRUCTORS,'actions=edit_instructors&instuctors_id='.$events[$events_id]['instructors_id'].'&return=dr') : '');?>';"><?php echo $events[$events_id]["instructor"];?></td>
			<td width="15%" class="main" nowrap="nowrap"><?php echo $events[$events_id]['location'].str_repeat('&nbsp;',10);?>
										<?php
										if ($dates[$i]['type']=='R' || $dates[$i]['type']=='W'){
											echo tep_draw_form('create_order',FILENAME_CREATE_ORDER_NEW,'' ,'post','onsubmit="chkclick(this);"');
											echo '<input type="hidden" name="action" value="event_browse">';
											echo '<input type="hidden" name="param_event" value="' . $events_id .'">';
											echo '<input type="hidden" name="param_session" value="' . $dates[$i]['id'] .'">';
											echo tep_image_submit('button_add.gif',IMAGE_RESERVE,'align=absmiddle');
											echo '</form>';
										}
										?>
			</td>
			</tr>
			</table>
		</td>
		</tr>	
		<?php	
		$previous_dates = $dates[$i]['date'];	
		$prev_dates=$dates[$i]['date'];
		} // Dates For Loop
		
		} // isset Events ID
			} // For Loop	
				
				} // Check for Standard / Customers
				
				} // while	
			} else { // if event found
		?>
			<tr>
				<td class="main">
					<?php echo '<div align=center><Br><Br><br><b>'.TEXT_NO_EVENTS.'</b>'.'</div>';?>
				</td>
			</tr>
		<?php }  // if event found in category
			
		?>
				</table>
				</td>
			</tr>
			</table>
			</td>
			</tr>
		</table>
<!-- body_eof //-->
		</td>
		</table>
	</tr>
</table>
<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); 
	
	
	function tep_get_event_daytext($events_id){
		//$result=array('type'=>'','day'=>'');
		$result_text="";
		
		$recursive_query=tep_db_query("SELECT * from " . TABLE_RECURSIVE_SESSIONS . " where events_id='" . $events_id . "'");
		
		if (tep_db_num_rows($recursive_query)<=0) return $result_text;

		$session_result=tep_db_fetch_array($recursive_query);
		
		$type=$session_result['sessions_type_option'];
	

	     //$days_array=array('1'=>'Sunday','2'=>'Monday','3'=>'Tuesday','4'=>'Wednesday','5'=>'Thursday','6'=>'Friday','7'=>'Saturday');
		$days_array=array('1'=>'Monday','2'=>'Tuesday','3'=>'Wednesday','4'=>'Thursday','5'=>'Friday','6'=>'Saturday','7'=>'Sunday');
		$count_array=array('1'=>'first','2'=>'second','3'=>'third','4'=>'fourth');
		$months_array=array('1'=>'January','2'=>'February','3'=>'March','4'=>'April','5'=>'May','6'=>'June','7'=>'July','8'=>'August','9'=>'September','10'=>'October','11'=>'November','12'=>'December');

		switch($type){
			case 'DD':
				if ($session_result['sessions_type_daily_days']<=1){
					$result_text=TEXT_DAILY_DAY;}
				else
					$result_text=sprintf(TEXT_DAILY_DAYS,$session_result['sessions_type_daily_days']);
				break;
			case 'WW':
				$temp_string=$session_result['sessions_type_weekly_days'];
				$day_string="";
				for ($icnt=0;$icnt<strlen($temp_string);$icnt++){
					if (substr($temp_string,$icnt,1)=='1'){
						if ($day_string!='') $day_string=$day_string . ", ";
							$day_string=$day_string . $days_array[$icnt+1];
						}
					}
				if ($session_result['sessions_type_weekly_weeks']<=1)
					$result_text=sprintf(TEXT_WEEKLY_WEEK,$day_string);
				else
					$result_text=sprintf(TEXT_WEEKLY_WEEKS,$session_result['sessions_type_weekly_weeks'],$day_string);
				break;
			case 'MD':
				if ($session_result['sessions_type_monthly_months']>1)
					$result_text=sprintf(TEXT_MONTHLY_DAYS,$session_result['sessions_type_monthly_months'],$session_result['sessions_type_monthly_days']);
				else
					$result_text=sprintf(TEXT_MONTHLY_DAY,$session_result['sessions_type_monthly_days']);
				break;
			case 'MM':
				if ($session_result['sessions_type_monthly_weekmonths']>1)
					$result_text=sprintf(TEXT_MONTHLY_WEEKS,$session_result['sessions_type_monthly_weekmonths'],$count_array[$session_result['sessions_type_monthly_weeks']],$days_array[$session_result['sessions_type_monthly_weekdays']]);
				else
					$result_text=sprintf(TEXT_MONTHLY_WEEK,$count_array[$session_result['sessions_type_monthly_weeks']],$days_array[$session_result['sessions_type_monthly_weekdays']]);	  
				break;
			case 'YM':
				$result_text=sprintf(TEXT_YEARLY_MONTHS,$months_array[$session_result['sessions_type_yearly_months']],$session_result['sessions_type_yearly_monthdays']);
				break;
	        case 'YY':
				$result_text=sprintf(TEXT_YEARLY_WEEKS,$count_array[$session_result['sessions_type_yearly_weeks']],$days_array[$session_result['sessions_type_yearly_weekdays']],$months_array[$session_result['sessions_type_yearly_weekmonths']]);
				break;
	}
	return $result_text;   
}
function fetch_location_content($events_id,$location_id){
	$result=array();
	$result[0]='<div id="location_' . $events_id .'" style="display:none">';
	$result[1]="";

	$location_query=tep_db_query("SELECT location_name,location_details,location_travel_directions from " . TABLE_EVENTS_LOCATIONS . " where location_id='" . $location_id . "'");
	if (tep_db_num_rows($location_query)>0)	{
		$location_result=tep_db_fetch_array($location_query);
		$result[0].='<table border="0" cellspacing="0" cellpadding="3" width="100%">';
		$result[0].='<tr><td class="smalltext"><b>' . TEXT_LOCATION_NAME . '</b>' . $location_result["location_name"] . '</td></tr>';
		$result[0].='<tr><td class="smalltext"><b>' . TEXT_DETAILS . '</b>' . $location_result["location_details"] . '</td></tr>';
		$result[0].='<tr><td class="smalltext"><b>' . TEXT_DIRECTIONS . '</b>' . $location_result["location_travel_directions"] . '</td></tr>';

		$result[0].='</table>';
		$result[1]=$location_result["location_name"];
	}
	$result[0].="</div>\n";

	return $result;
	

}

function fetch_instructor_content($events_id,$instructor_id){
	$result=array();
	$result[0]='<div id="instructor_' . $events_id .'" style="display:none">';
	$result[1]="";

	$instructor_query=tep_db_query("SELECT i.admin_id, i.instructors_id, concat(a.admin_firstname,' ',a.admin_lastname) as instructors_name,i.instructors_street_address,i.instructors_city,i.instructors_state,i.instructors_postcode,i.instructors_country,i.instructors_description from " . TABLE_INSTRUCTORS . " i, " . TABLE_ADMIN . " a where i.admin_id='" . $instructor_id . "' and i.admin_id=a.admin_id");
	if (tep_db_num_rows($instructor_query)>0)	{
		$instructor_result=tep_db_fetch_array($instructor_query);
		$result[0].='<table border="0" cellspacing="0" cellpadding="2" width="100%">';
		//$result[0].='<tr><td class="main">' . $location_result["instructor_name"] . '</td></tr>';
		//$result[0].='<tr><td class="tableHeading">' . TEXT_DESCRIPTION . '</td></tr>';
		$result[0].='<tr><td class="smalltext"><b>' . TEXT_INSTRUCTOR_NAME . '</b>' . $instructor_result["instructors_name"] . '</td></tr>';
		$result[0].='<tr><td class="smalltext"><b>' . TEXT_DETAILS . '</b>' . $instructor_result["instructors_description"] . '</td></tr>';
		$result[0].='</table>';
		$result[1]=$instructor_result["instructors_name"];
		$result[2]=$instructor_result["instructors_id"];
		$result[3]=$instructor_result["admin_id"];
	}
	$result[0].="</div>\n";

	return $result;
}

function fetch_events_content($events_id,&$description){
	$result='<div id="eventdesc_' . $events_id .'" style="display:none">';
	$result.='<table border="0" cellspacing="0" cellpadding="3" width="100%">';
	//$result.='<tr><td class="tableHeading">' . TEXT_DESCRIPTION . '</td></tr>';
	$result.='<tr><td class="smalltext">' . $description . '</td></tr>';
	$result.='</table>';
	$result.="</div>\n";
	$result.='<div id="sessiondesc_' . $events_id . '" style="display:none">';
	$result.='</div>';
	return $result;
	
}
function fetch_dates_content(&$dates){

	$result.='<table border="0" cellspacing="0" cellpadding="2" width="100%">';
	$result.='<tr><td><table cellspacing="1" cellpadding="1" width="100%">';
	if (sizeof($dates)>0){
		$result.='<tr><td class="smalltext"><b>' . TEXT_DATE  . '</b></td><td class="smalltext"><b>' . TEXT_FREE_SEATS . '</b></td><td class="smallText"><b>' . TEXT_RENEWAL_SEATS . '</b></td></tr>';
		reset($dates);
		$dates=array_slice($dates,0,10);
		for ($icnt=0;$icnt<sizeof($dates);$icnt++){
			if ($dates[$icnt]['type']=='R')
				$result.='<tr><td class="smalltext">' . sprintf("<font color=\"%s\">%s</font>",$dates[$icnt]['bgcolor'],format_date($dates[$icnt]['date'])) . '</td><td class="smalltext">' . $dates[$icnt]["reserved"] . '</td>';
			else if ($dates[$icnt]['type']=='W')
				$result.='<tr><td class="smalltext">' . sprintf("<font color=\"%s\">%s</font>",$dates[$icnt]['bgcolor'],format_date($dates[$icnt]['date'])) . '</td><td class="smalltext">' . $dates[$icnt]["waitlist"] . '</td>';
			else if ($dates[$icnt]['type']=='E')
				$result.='<tr><td class="smalltext">' . sprintf("<font color=\"%s\">%s</font>",$dates[$icnt]['bgcolor'],format_date($dates[$icnt]['date'])) . '</td><td class="smalltext">0</td>';
			else
				$result.='<tr><td class="smalltext">' . format_date($dates[$icnt]['date']) . '</td><td class="smalltext" colspan="2">' . TEXT_HOLIDAY . '</td></tr>';
			if ($dates[$icnt]['type']=='R' || $dates[$icnt]['type']=='W' || $dates[$icnt]['type']=='E')
				$result.='<td class="smallText">' . $dates[$icnt]["renewal"] . '</td></tr>';
		}
	} else {
		$result.='<tr><td class="smalltext">' . TEXT_NO_SESSIONS . '</td></tr>'; 
	}
	$result.='</table></td></tr></table>';
	return $result;
}
function user_compare($a, $b) 
{
    if ($a['date'] == $b['date']) {
        return 0;
    }
    return ($a['date'] < $b['date']) ? -1 : 1;
}

?>