<?php 

/**
* @version 2.8.1
* @package Joomla 2.5
* @subpackage DT Register
* @copyright Copyright (C) 2006 DTH Development
* @copyright contact dthdev@dthdevelopment.com
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
*/

 $TableUser = $this->getModel('user')->table; 
 $archive = 0;
  $where = "archive = 0";
  if(isset($_REQUEST['search']['event_archive'])) {
	  if($_REQUEST['search']['event_archive'] == -1){
	     $where = "(archive = 1 or  archive = 0) ";
	  } else {
  	  	$archive = $_REQUEST['search']['event_archive'];
		$where = "archive = $archive";
	  }
  }
   $aro = $this->getModel( 'aro' );
   $user = &JFactory::getUser();
   $aro = $this->getModel( 'aro' )->table->findaroByUser($user);
   
   $aco_id = $this->getModel( 'aco' )->table->getAcoIdbyTypeControllerTask('sessionUser','event','edit','DT_EDIT_OWN_EVENT');
   $permission = $this->getModel( 'permission' )->table->find('aro_id in('.implode(",",$aro).') and aco_id = '.$aco_id);
   
   if($permission && count($permission) == count($aro)){
  	  $event = $TableUser->TableEvent ;
	  $events_obj = $event->TableModerator->find('user_id = '.$user->id);
				  $events = array();
				  foreach($events_obj as $evt) {
					 $events[] = $evt->eventId ;
				  }
				  $user_condtion = " slabId in(".implode(",",$events).")";
	              if(count($events) > 0){
	                 $where .= " and ". $user_condtion;
				  }
   }
  $events        = $TableUser->TableEvent->optionslist($where,'dtstart desc');
  $eventoptions  =  DtHtml::options($events,JText::_("DT_SELECT_EVENT"));
 
  $status = isset($this->search['status'])?$this->search['status']:'';
  $attend = isset($this->search['attend'])?$this->search['attend']:'-1';
  $fee_status = isset($this->search['fee_status'])?$this->search['fee_status']:'';
  $event_archive = isset($this->search['event_archive'])?$this->search['event_archive']:'';
  $query = isset($this->search['query'])?$this->search['query']:'';
   
?>
<table class="adminheading" border="0" width="100%">

      <tr>

		<td style="padding:2px">

			<?php echo JHTML::_('select.genericlist', $eventoptions,'search[eventId]','onchange="submit()"','value','text',$this->eventId);;?></td>
       
        <td style="padding:2px">
            <?php echo JHTML::_('select.genericlist', DtHtml::options($TableUser->statustxt,JText::_('DT_SELECT_STATUS')),'search[status]',' onchange="submit()" ','value','text',$status)?>
        </td>

        <td style="padding:2px"><?php echo JText::_( 'DT_ATTENDED' ); ?>:&nbsp;

		<?php echo JHTML::_('select.genericlist', DtHtml::options(array('-1'=>Jtext::_('DT_NONE'),0=>JText::_('DT_NO'),1=>JText::_('DT_YES'))),'search[attend]',' onchange="submit()" ','value','text',$attend)?></td>

	</tr>

	<tr>
      <td align="left" style="padding:2px">   
            <?php echo JText::_('DT_SEARCH');?>:<input type="text" size="30" name="search[query]" value="<?php echo addslashes($query);?>" /><input type="submit" value="Go" />
      </td>
      <td align="left" colspan="2" style="padding:2px">
	      <?php

			$options=array();

	        $options[]=JHTML::_('select.option',"0",JText::_( 'DT_HIDE_ARCHIVE' ));

		    $options[]=JHTML::_('select.option',"1",JText::_( 'DT_SHOW_ARCHIVE' ));

		    $options[]=JHTML::_('select.option',"-1",JText::_( 'DT_ALL_EVENT' ));

	        $archive = JRequest::getVar('archive',0);

		    echo JHTML::_('select.genericlist', $options,"search[event_archive]",' onchange="submit()" ',"value","text",$event_archive);

		  ?>
	      </td>
	  </td>
     </tr>

	</table>