<?php 


// Check to ensure this file is included in Freeway!
defined('_FEXEC') or die();?>
<div id="spiffycalendar" class="text"></div>
<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_DAY_VIEW,$ecCat_path));
	$category_id=(isset($HTTP_POST_VARS['category_id'])?(int)$HTTP_POST_VARS['category_id']:0);
	$current_date=(isset($HTTP_POST_VARS['current_date'])?tep_db_prepare_input($HTTP_POST_VARS['current_date']):getServerDate());

	$post_action=(isset($HTTP_POST_VARS['post_action'])?tep_db_prepare_input($HTTP_POST_VARS['post_action']):"change_cat");

		if(isset($HTTP_POST_VARS["cur_date"])){
	     $current_date=(isset($HTTP_POST_VARS['cur_date'])?tep_db_prepare_input($HTTP_POST_VARS['cur_date']):'');
		 }
		// TO see Day View
		
		else{
				if ($category_id<=0) $category_id=(int)$current_events_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"];
				}
				if ($category_id>0) $cat_option=" and ec.events_categories_id='" . $category_id . "'";

			   $start_date=date('Y-m-d'); 
		 	   $get_month=date('t',strtotime($start_date));
			   $total_days=($get_month - date('d',strtotime($start_date)));
			   $end_date=date('Y-m-d',tep_dateadd(strtotime($start_date),'day',$total_days));
			   $get_events_query=tep_db_query("SELECT e.events_id,s.start_date,s.sessions_id from " . TABLE_EVENTS_SESSIONS . " s, " . TABLE_EVENTS . " e, " . TABLE_EVENTS_TO_EVENTS_CATEGORIES  . " ec " .
									          " where s.start_date>='" . $start_date . "' and s.start_date<='" . $end_date ."' and s.start_date>='" .  $start_date . "'  and  ec.events_categories_id='$category_id' and s.sessions_type in ('S','R') and e.events_id=s.events_id and ec.events_id=e.events_id order by events_start_time,events_end_time");
		      if(tep_db_num_rows($get_events_query)>0){
	     	  $res=tep_db_fetch_array($get_events_query);
	     	  $current_date=$res['start_date'];
			 
	        }
		}
		
	$server_date=getServerDate();
	//check for category_id from post data or current events_category_id selected or the first category from database
	
	
	if ($category_id<=0) $category_id=(int)$current_events_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"];
	}
	if ($category_id>0) $cat_option=" and ec.events_categories_id='" . $category_id . "'";
	
	

	//if ($category_id>0) $cat_option=" ec.events_categories_id='" . $category_id . "'";

	// determine type of action
	if ($post_action=="view_date") {
		$current_date=tep_db_prepare_input($HTTP_POST_VARS['select_date']);
		
	}else if ($post_action=="nav_left"){
		$current_date=date('Y-m-d',tep_datesub(strtotime($current_date),"day",1));
	} else if ($post_action=="nav_right"){
		$current_date=date('Y-m-d',tep_dateadd(strtotime($current_date),"day",1));
	}
	$navigate_left=true;
	$navigate_right=true;
	// display of left navigation and right navigation buttons	
	if ($current_date<=$server_date) $navigate_left=false;
	$events_ids="";
	$event_found=false;
	// select the events id of category selected
	 
	$find_events_query=tep_db_query("SELECT distinct e.events_id,s.sessions_id from " . TABLE_EVENTS_SESSIONS . " s, " . TABLE_EVENTS . " e, " . TABLE_EVENTS_TO_EVENTS_CATEGORIES  . " ec " .
									" where s.start_date>='" . $current_date . "'" . $cat_option . " and s.start_date>='".$current_date."' and s.sessions_type in ('S','R') and e.events_id=s.events_id and ec.events_id=e.events_id");

	while($find_events_result=tep_db_fetch_array($find_events_query)){
		$events_ids.=$find_events_result["events_id"] . ",";
		$sessions_id=$find_events_result["sessions_id"];
	}
  
	// select the events details
	
	if ($events_ids!=""){ 
		$events_ids=substr($events_ids,0,-1);		
		$event_info_query = tep_db_query("select e.events_id, ed.events_name, e.events_date_available,e.events_date_added,ed.events_description,e.events_image, e.events_tax_class_id, e.events_fees," .
										"e.events_instructor,e.display_instructor,events_start_time as start_time,time_format(e.events_start_time,'%h:%i %p') as events_start_time,time_format(e.events_start_time,'%H:%i') as events_s_time,time_format(e.events_end_time,'%h:%i %p') as events_end_time,time_format(e.events_end_time,'%H:%i') as events_e_time,e.events_location," . 
										"e.events_conditions,sessions_select_interval,e.link_service,e.service_id from " . TABLE_EVENTS . " e, " . TABLE_EVENTS_DESCRIPTION .
										" ed where e.events_id in (" . $events_ids . ") " . EVENTS_CONDITION_STATUS . " and ed.events_id = e.events_id and ed.language_id = '" . (int)$languages_id . "' order by e.events_start_time,e.events_end_time");
		if (tep_db_num_rows($event_info_query)>0) $event_found=true;
		
		// get max date query
		$max_date_query=tep_db_query("SELECT max(start_date) as last_date from " . TABLE_EVENTS_SESSIONS . " where events_id in(" . $events_ids . ")");
		$max_date_result=tep_db_fetch_array($max_date_query);
		if ($current_date>=$max_date_result["last_date"]) $navigate_right=false;
	}

	
	// 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 the list of categories	
	$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"]);
	}
	
?>
	<script language="JavaScript">
		function ChangeResult(mode){
			if (mode==1) {
				document.frmView.post_action.value="nav_left";
			} else if (mode==2) {
				document.frmView.post_action.value="nav_right";
			} else if (mode==3) {
				document.frmView.post_action.value="view_date";				
			} else {
				document.frmView.action="<?php echo tep_href_link(FILENAME_EVENTS_MONTH_VIEW,'','NONSSL',true,false);?>";
				document.frmView.post_action.value="change_cat";
			}
			document.frmView.submit();			
		}
		function ChangeView(mode){
			switch(mode){
				case 1:
					document.frmView.action="<?php echo tep_href_link(FILENAME_EVENTS_DAY_VIEW,$ecCat_path . '&set_view=day');?>";
					break;
				case 2:
					document.frmView.action="<?php echo tep_href_link(FILENAME_EVENTS_WEEK_VIEW,$ecCat_path . '&set_view=week');?>";
					break;
				case 3:
					document.frmView.action="<?php echo tep_href_link(FILENAME_EVENTS_MONTH_VIEW,$ecCat_path . '&set_view=month');?>";
					break;
			}
			document.frmView.submit();
		}
		function ViewPrevious(){
			document.frmPrevious.submit();
		}
	</script>
	<link rel="stylesheet" type="text/css" href="includes/javascript/spiffyCal/spiffyCal_v2_1.css">
	<?php require(DIR_WS_JAVASCRIPT . "spiffyCal/spiffyCal_v2_1.js");?>
	<script language="javascript">
	  var dateSelect = new ctlSpiffyCalendarBox("dateSelect", "frmView", "select_date","btnSelect","<?php echo $current_date;?>",scBTNMODE_CUSTOMBLUE);
	</script>
<?php if (MAIN_TABLE_BORDER == 'yes'){
if(!defined('BOX_HEADING_EVENTS_CATEGORIES'))define('BOX_HEADING_EVENTS_CATEGORIES', 'Events');
	 echo table_image_border_top(false, false, BOX_HEADING_EVENTS_CATEGORIES);
}?>
 <table width='100%' border="0" cellspacing="0" cellpadding="0" align="left"> 
	<tr height="20">
		<td class="main" valign="top" nowrap="nowrap">
		<table width='100%' border="0" cellspacing="0" cellpadding="0" align="left">
		 <!--<tr height="30"><td width="100" valign="middle"  colspan="3" align="left" class="infoBoxHeadingPage">&nbsp;&nbsp;&nbsp;&nbsp; 		&nbsp;<?php //echo tep_template_image('arrow_1.gif','','align=absmiddle') .'  '.BOX_HEADING_EVENTS_CATEGORIES;?></td></tr>-->
			<tr style="height:10"><td></td></tr>
			<tr class="eventTitleRow">
				<td valign="middle" width="120" class="eventTitle" align="right" nowrap="nowrap">&nbsp;&nbsp;<?php echo TEXT_EVENT_CATEGORY;?></td>
				<td valign="middle" class="eventListing-data" nowrap="nowrap">
					<?php echo tep_draw_pull_down_menu("category_id",$cat_array,$category_id) .'&nbsp;';
							echo '<a href="javascript:ChangeResult(4);">' . tep_template_image_button("button_quick_find.gif",IMAGE_VIEW_DATE,'align=absmiddle') . '</a>';
					?>
				</td>
				<td valign="middle" align="right" width="350" class="eventTitle" nowrap="nowrap">
					<?php 
						echo TEXT_VIEWS.' '.tep_template_image_button("button_day_view_selected.gif",IMAGE_DAY_VIEW,'align=absmiddle') . '&nbsp;';
						echo '<a href="javascript:ChangeView(2)">' . tep_template_image_button("button_week_view.gif",IMAGE_WEEK_VIEW,'align=absmiddle') . '</a>&nbsp;';
						echo '<a href="javascript:ChangeView(3)">' . tep_template_image_button("button_month_view.gif",IMAGE_MONTH_VIEW,'align=absmiddle') . '</a>&nbsp;&nbsp;';
					?>
				</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%" class="tab_strip">
				<tr>
					<td class="contentBackCol1" width="5"></td>	
					<td class="contentBackCol2">
					<table border="0" cellpadding="0" cellspacing="0" width="100%">
					<?php if ($category_id>0) {
						// select the current 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="10">
						<td valign="top">
						<table border="0" cellspacing="0" cellpadding="2" valign="top" width="100%">
							<tr>
								<td colspan="2" valign="top" class="headerBrowse" ><?php //echo tep_image(DIR_WS_TEMPLATES . TEMPLATE_NAME . '/images/arrow_1.gif').' '.$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=left'));
									//echo $cat_info['events_categories_description'];
								?> 
								</td>
							</tr>
						</table>
						</td>
					</tr>--> 
					<?php }
					?>
					<!--
					<tr height="20">
						<td valign="top">
						<table border="0" cellspacing="0" cellpadding="2" valign="top" width="100%" >
							<tr class='eventListing-data'>
								<td valign="top" width="20"><?php if ($navigate_left) echo '<a href="javascript:ChangeResult(1);">' . tep_template_image_button("navigate_left.gif",IMAGE_PREVIOUS_DAY) . '</a>';?></td>
								<td valign="middle" align="center">
									<script language="javascript">dateSelect.writeControl(); dateSelect.dateFormat="yyyy-MM-dd";</script>&nbsp;
									<?php //echo '<a href="javascript:ChangeResult(3);">' . tep_template_image_button("button_quick_find.gif",IMAGE_VIEW_DATE,'align=absmiddle') . '</a>';?>
								</td>
							<td valign="top" width="20"><?php //if ($navigate_right) echo '<a href="javascript:ChangeResult(2);">' . tep_template_image_button("navigate_right.gif",IMAGE_NEXT_DAY) . '</a>';?></td>
							</tr>
						</table>
						</td>
					</tr>
					-->
					<tr height="200">
						<td valign="top">
						<table border="0" cellspacing="2" cellpadding="2" valign="top" width="100%">
						<?php 
							if ($event_found) {
								// if events found on current criteria
								while($event_info=tep_db_fetch_array($event_info_query)) {
				
								// Get the session details of event
								$session_query=tep_db_query("SELECT * from " . TABLE_RECURSIVE_SESSIONS . " where events_id='" . $event_info["events_id"] . "'");
								$session_result=tep_db_fetch_array($session_query);
								$event_text=tep_get_event_daytext($session_result);
				
								// Get the location details of event
								if($event_info['link_service']=='L'){
									$location_query=tep_db_query("SELECT location_name,location_details from " . TABLE_EVENTS_LOCATIONS . " where location_id='" . $event_info["events_location"] . "'");
								} else if($event_info['link_service'] == 'S'){
									$location_query=tep_db_query("SELECT sl.service_location_name as location_name,sl.service_location_details as location_details from " . TABLE_SERVICES." s, ".TABLE_SERVICES_LOCATIONS ." sl where  s.service_location=sl.service_location_id and s.service_id='".(int)$event_info["service_id"] ."'");
								}
									if($location_query)$location_info=tep_db_fetch_array($location_query);
				
								// Get the instructor details of event
								$instructor_query=tep_db_query("SELECT concat(admin_firstname,' ',admin_lastname) as instructor_name from " . TABLE_ADMIN . " where admin_id='" . $event_info["events_instructor"] . "'");
								$instructor_info=tep_db_fetch_array($instructor_query);
				
								// calculate event fees
								$interval=($event_info["sessions_select_interval"]>0?$event_info["sessions_select_interval"]:1);
								$fees=$interval*tep_add_tax($event_info["events_fees"],tep_get_tax_rate($event_info["events_tax_class_id"]));
								$info=TEXT_FEES_INFO_SINGLE;
								if ($interval>1) $info=TEXT_FEES_INFO;
								$amount=$currencies->format($fees) . sprintf($info,$interval);
								
								$events_name=tep_get_events_display_text($event_info["events_name"],$event_info["start_time"],$location_info["location_name"]);
						?>
							<tr>
								<Td>
								<table border="0" cellspacing="2" cellpadding="2" valign="top" width="100%">
									<tr>
										<td>
											<?php echo '<a class="headerBrowse" href="' . tep_href_link(FILENAME_SESSION_DETAILS,'events_id=' . $event_info["events_id"] . "&sId=" . $sessions_id . "&" . $ecCat_path) . '">' . $events_name  .'</a>';?>
										</td>
									</tr>
									
									<tr>
										<td valign="top" class="tab_strip">
										<table border="0" cellspacing="0" cellpadding="2" valign="top" width="100%">
											<tr>
												<td colspan="2">
												 <table width="100%" border="0" cellspacing="0" cellpadding="0">
												 <tr>
												   <td valign="top" width="<?php echo SMALL_IMAGE_WIDTH;?>">
													<?php 
															echo '<a href="' . tep_href_link(FILENAME_SESSION_DETAILS,'events_id=' . $event_info["events_id"] . "&sId=" . $sessions_id . "&" . $ecCat_path) . '">';
															if ($event_info['events_image']!=""){
																echo tep_image(DIR_WS_IMAGES . $event_info['events_image'] , $event_info['events_name'],SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT);
															 } else if ($cat_info['events_categories_image']!="") {
																echo tep_image(DIR_WS_IMAGES . $cat_info['events_categories_image'] , $event_info['events_name'],SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT);
															 }
															 echo '</a>';
													?>
												</td>
												<td valign="top" width="250" class="smalltext" colspan="2">
													<?php 
														$text_description=strip_tags($event_info['events_description'],'<p><br><b><i><u>');
														if (strlen($text_description)>250)
															$text_description=substr($text_description,0,250) . "...";
															
														echo $text_description;
													?>
												</td>
											  </tr>
										  	 </table>
										   </td>
										 </tr>
											<tr>
												<td valign="top" class="dataCalendarDay"> 
												 <table border="0" cellpadding="0" cellspacing="6" width="100%">
													<tr>
														<td class="eventTitle" valign="top"><?php echo TEXT_WHEN;?></td>
														<td width="85%" class="eventListing-Data" valign="top"><?php 
														$eve_start_time=strtolower($event_info["events_start_time"]);
														$eve_end_time=strtolower($event_info["events_end_time"]);
														if(defined('TIME_FORMAT')) {
															$dis_time_format=TIME_FORMAT;
															if($dis_time_format=='24') {
																$eve_start_time=strtolower($event_info["events_s_time"]);
																$eve_end_time=strtolower($event_info["events_e_time"]);
															}	
														}	
														echo $event_text . " " . $eve_start_time . " - " . $eve_end_time;?></td>
													</tr>
													<?php //print_r($event_info);
														if (EVENTS_CALENDAR_DISPLAY_NAME == 'event name')
														{ ?>
														<tr>
														<td class="eventTitle" valign="top"><?php echo 'Event Name:';?></td>
														<td class="eventListing-Data" valign="top"><?php echo $event_info["events_name"];?></td>
													</tr>
														<?php 
														} else {
														?>
													<tr>
														<td class="eventTitle" valign="top"><?php echo TEXT_LOCATION;?></td>
														<td class="eventListing-Data" valign="top"><?php echo $location_info["location_name"];?></td>
													</tr>
													<?php }
													 if($event_info['display_instructor']=='Y'){
													?>
													<tr>
														<td class="eventTitle" valign="top"><?php echo TEXT_INSTRUCTOR;?></td>
														<td class="eventListing-Data" valign="top"><?php echo $instructor_info["instructor_name"];?></td>
													</tr>
													<?php } ?>
													<tr>
														<td class="eventTitle" valign="middle"><?php echo TEXT_COST;?>
														<td class="eventListing-Data" valign="middle">
														<?php 	echo $amount;
				
															?>
													</tr>
													<tr>
														<td class="eventTitle" valign="middle" align="Left" colspan="2">
														<?php
																echo '<a href="' .tep_href_link(FILENAME_SESSION_DETAILS,'events_id=' . $event_info["events_id"] . "&sId=" . $sessions_id . "&" . $ecCat_path) . '">';
																echo tep_template_image_button("button_reserve_event.gif",IMAGE_RESERVE_EVENT,'align=absmiddle') . '</a>';
														?>
														</td>
													</tr>
												</table>
												</td>
											</tr>
										</table>
										</td>
									</tr>
								</table>
								</td>
							</tr>
							<tr>
								<td><?php echo tep_draw_separator('pixel_trans.gif',1,10);?></td>
							</tr>	
						<?php }
							}
							if (!$event_found) {
						?>
							<tr>
								<td>
								<table border="0" cellpadding="4" cellspacing="0" class="formArea" width="100%">
									<tr>
										<Td class="main" align="center"><b>No Events found!</b></Td>
									</tr>				
								</table>
								</td>
							</tr>
						<?php } ?>
						</table>
						</td>
					</tr>
					<tr>
						<td class="main" valign="top">
						<table width='100%' border="0" cellspacing="0" cellpadding="2" align="left">
							<tr>
								<td width="10"></td>
								
							</tr>
						</table>
						</td>
					</tr>
					</table>
					</td>
					<td class="contentBackCol3" width="5"></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
?>
<input type="hidden" name="start_date" value="<?php echo $current_date;?>">
<input type="hidden" name="end_date" value="<?php echo $current_date;?>">
<input type="hidden" name="cur_date" value="<?php echo $cur_date;?>">
<input type="hidden" name="current_date" value="<?php echo getServerDate();?>" />
<input type="hidden" name="post_action" value="">
</form>
<?php
	// construct current post details as hidden details to work out "back" action
	$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","day");
?>
</table>
<?php 
   function tep_get_event_daytext($session_result)
   {
     $type=$session_result['sessions_type_option'];
     $result_text='';
     //$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;   
   }
  ?>
  
