<?php

/*

  osCommRes, Services Online
  http://www.oscommres.com

  Copyright (c) 2005 osCommRes

  Released under the GNU General Public License
  
  Freeway eCommerce from ZacWare
http://www.zac-ware.com/freeway

Copyright 2007 ZacWare Pty. Ltd
*/
// Set flag that this is a parent file
	define( '_FEXEC', 1 );
  require('includes/application_top.php');
  tep_get_last_access_file();require(DIR_WS_CLASSES . 'currencies.php');
  //added new
  define(BOX_WIDTH1,'125');

//Added for Categories Description 1.5  
  //require('includes/functions/sessions_description.php');
  $dis_time_format="";
  if(defined('TIME_FORMAT')) $dis_time_format=TIME_FORMAT;
  
  $currencies = new currencies();
   $query_instructor="";
   if ($login_groups_type==TEXT_INSTRUCTOR_ENTRY) 
     $query_instructor=" and e.events_instructor='" . $login_id ."'";

	if (isset($HTTP_GET_VARS['page']) && ($HTTP_GET_VARS['page'] > 1)) $rows = $HTTP_GET_VARS['page'] * MAX_DISPLAY_SEARCH_RESULTS - MAX_DISPLAY_SEARCH_RESULTS;
	$rows=0;
	$instructors_query="select concat(a.admin_firstname,' ',a.admin_lastname) as instructor_name,e.events_id,e.events_max_reserve,ed.events_name,time_format(e.events_start_time,'%h:%i %p') as start_time,time_format(e.events_start_time,'%H:%i') as stime,time_format(e.events_end_time,'%h:%i %p') as end_time,time_format(e.events_end_time,'%H:%i') as etime from " .
		     TABLE_EVENTS . " e, " . TABLE_EVENTS_DESCRIPTION . " ed, " . TABLE_ADMIN . " a " .
		     "where e.events_id=ed.events_id and e.events_instructor=a.admin_id " . $query_instructor . " and ed.language_id=" . $languages_id . EVENTS_CONDITION_STATUS . " order by instructor_name,events_name";
	$instructors_split = new splitPageResults($HTTP_GET_VARS['page'], MAX_DISPLAY_SEARCH_RESULTS, $instructors_query, $instructors_query_numrows);
	$result_query=tep_db_query($instructors_query);
	$cnt=tep_db_num_rows($result_query);
	$prev_name="";
?>
<!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">
<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">
<div id="spiffycalendar" class="text"></div>
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
<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="2">	
      <tr><!--<td>
           <table border="0" width="100%" cellspacing="0" cellpadding="0">      
           <tr><td align=left class='pageHeading' colspan=8><?php //echo HEADING_TITLE; ?></td></tr>
	   </table></td>!--></tr>
      <tr>
	<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <?php if ($cnt>0) {?>
          <tr>
	   <td valign="top"><table border="0" width='100%'cellspacing="0" cellpadding="2">      
	   <tr class='dataTableHeadingRow'><td class='dataTableHeadingContent' width="300"><?php echo TEXT_INSTRUCTOR_EVENTNAME; ?>&nbsp;</td>
	   <td class='dataTableHeadingContent' width="200"><?php echo TEXT_INSTRUCTOR_TIMINGS; ?></td>
	   <td class='dataTableHeadingContent' align=right width="200"><?php echo TEXT_INSTRUCTOR_TOTAL_RESERVED; ?></td>
            <?php 
	      $rows=0;$currow=0;
	      while($result=tep_db_fetch_array($result_query)) { 
		    $rows++;
		    $currow++;
		    if (strlen($rows) < 2) {
		      $rows = '0' . $rows;
		    }
           $count_query=tep_db_query("select count(*) as total from " . TABLE_EVENTS_SESSIONS . " where events_id='" . $result['events_id'] . "' and sessions_type!=''");
	   $total_sessions_count=0;
	   $total_reserved_count=0;
	   if ($count_result=tep_db_fetch_array($count_query)){;
	       $total_sessions_count=$count_result['total'];
	   }
           $count_query=tep_db_query("select sum(op.products_quantity) as total from " . TABLE_ORDERS_PRODUCTS . " op, " .  TABLE_ORDERS . " o, " . TABLE_EVENTS_SESSIONS . " s where s.events_id='" . $result['events_id'] . "' and s.sessions_type!='' and op.events_type='R' and op.products_id=s.sessions_id and op.orders_id=o.orders_id group by o.customers_id");
	   if ($count_result=tep_db_fetch_array($count_query)){;
	       $total_reserved_count=$count_result['total'];
	   }
	   if ($prev_name!=$result['instructor_name']){
	      $prev_name=$result['instructor_name'];
	   ?>
	      <tr height=20 class="main"><td colspan=4><?php echo $prev_name; ?></td></tr>
	   <?php } ?>
    	      <tr class='dataTableRow' height=20>
	       <td class='dataTableContent'><?php echo $result['events_name']; ?></td>
	       <td class='dataTableContent'><?php 
		   $instruct_time=$result['start_time'] . ' - ' . $result['end_time'];
		   if($dis_time_format!="") {
		   	if($dis_time_format=='24')
				$instruct_time=$result['stime'] . ' - ' . $result['etime'];
		   }
		   echo $instruct_time; ?></td>
	       <td class='dataTableContent' align=right width=100><?php echo $total_reserved_count; ?></td>
	       </tr>
       	       <?php } ?>
	       </table></td></tr>
	      <tr>
		<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
	      </tr>
		  <tr>
		    <td colspan="11"><table border="0" width="100%" cellspacing="0" cellpadding="2">
		      <tr>
			<td class="smallText" valign="top"><?php echo $instructors_split->display_count($instructors_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, $HTTP_GET_VARS['page'], TEXT_DISPLAY_NUMBER_OF_EVENTS); ?></td>
			<td class="smallText" align="right"><?php echo $instructors_split->display_links($instructors_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $HTTP_GET_VARS['page'],tep_get_all_get_params(array('page','x','y'))); ?>&nbsp;</td>
		      </tr>
		    </table></td>
		  </tr>
	   <?php } else { ?>
	   <tr><td align=left class='main' colspan=8><?php echo TEXT_NO_RESULTS ?></td></tr>
	   <?php } ?>
      <tr>
	<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      </table>
      </td>
</tr>
</table>
<!-- body_text_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
