<?php

/**
* @version 2.8.14
* @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
*/

defined('_JEXEC') or die();
jimport( 'joomla.application.component.view');
class DtrView extends JView {
     
	 function __construct($params){
        
	    parent::__construct($params);
	    $this->addHelperPath(JPATH_COMPONENT_ADMINISTRATOR.DS.'helpers');
	    $this->loadHelper('html');
		$this->loadHelper('dtregister');

	 }
	 
	public function setLayout($layout)
	{
		$view_name = $this->getName();
		
		//$this->addTemplatePath(JPATH_COMPONENT_ADMINISTRATOR.DS.'views'.DS.$view_name.DS.'tmpl'.DS);
		//pr($this); die;
		return parent::setLayout($layout);
	}
	 
	 function display($tpl){
		
		global $mainframe,$option,$form_field_style,$controller;
		$option = "com_dtregister";
		$bar = & JToolBar::getInstance('toolbar');
		$document =& JFactory::getDocument();
		$document->addScript( JURI::root(true).'/components/com_dtregister/assets/js/extend_obj.js');
		$document->addScript( JURI::root(true).'/components/com_dtregister/assets/js/dt_jquery.js');
		 $document->addScript( JURI::root(true).'/components/com_dtregister/assets/js/textareaCounter.js');
		$document->addScript( JURI::root(true).'/components/com_dtregister/assets/js/validate.js');
		$document->addScript( JURI::root(true).'/components/com_dtregister/assets/js/validationmethods.js');
		$document->addScript( JURI::root(true).'/components/com_dtregister/assets/js/jquery-ui.js');
		$document->addScript( JURI::root(true).'/components/com_dtregister/assets/js/ui.jquery.checkbox.js');
		if(!(isset($_REQUEST['tmpl']) || isset($_REQUEST['no_html']) || isset($_REQUEST['format']))){
		?>
        <script type="text/javascript">
		  if(typeof DTjQuery != 'undefined') {
		   DTjQuery.extend(
		                    DTjQuery.validator.messages, {
							  required: "<?php echo JText::_('DT_WARNING_FIELD_REQUIRED')?>",
							  remote: "Please fix this field.",
							  email: "<?php echo JText::_('DT_INVALID_EMAIL')?>",
							  url: "Please enter a valid URL.",
							  date: "Please enter a valid date.",
							  dateISO: "Please enter a valid date (ISO).",
							  number: "Please enter a valid number.",
							  digits: "Please enter only digits.",
							  creditcard: "<?php echo JText::_('DT_CARD_NUMBER_INVALID')?>",
							  equalTo: "<?php echo JText::_('DT_WARNING_SAME_VALUE')?>",
							  accept: "Please enter a value with a valid extension.",
							  maxlength: DTjQuery.validator.format("Please enter no more than {0} characters."),
							  minlength: DTjQuery.validator.format("Please enter at least {0} characters."),
							  rangelength: DTjQuery.validator.format("Please enter a value between {0} and {1} characters long."),
							  range: DTjQuery.validator.format("Please enter a value between {0} and {1}."),
							  max: DTjQuery.validator.format("Please enter a value less than or equal to {0}."),
							  min: DTjQuery.validator.format("Please enter a value greater than or equal to {0}.")
						  }
						  );
		  }
		
		</script>
        <?php
		}
		if(!$mainframe->isAdmin()){
			
		   	if((!(isset($_REQUEST['tmpl']) || isset($_REQUEST['no_html']) || (isset($_REQUEST['format']) && $_REQUEST['format']!='html' ))) || isset($_REQUEST['showtoolbar'])){
				if(!isset($mainframe->JComponentTitle)){
						$mainframe->JComponentTitle = "";
				}
				echo $bar->render().$mainframe->JComponentTitle."<div style='clear:both;'></div>";
				
			}
			$document->addStyleSheet(JURI::root(true).'/components/com_dtregister/assets/css/main.css');
			$document->addStyleSheet(JURI::root(true).'/components/com_dtregister/assets/css/south-street/jquery-ui.css');
			$document->addStyleSheet(JURI::root(true).'/components/com_dtregister/assets/css/south-street/ui-checkbox.css');
			
			ob_start();
			?>
            
            DTjQuery(function(){
   
               DTjQuery('a.toolbar').click(function(event){
                  event.preventDefault();
               
               });
               <?php if($form_field_style) { ?>
               		DTjQuery('input').checkBox();
               <?php } ?>
                
                 DTjQuery(".hover_radio").find('img').height(DTjQuery(".hover_radio").prev().height()+2)
                 DTjQuery(".hover_radio").find('img').width(DTjQuery(".hover_radio").prev().width()+2)
                 DTjQuery(".hover_radio").prev().addClass('dt_full');
            });
            <?php
			 $js = ob_get_clean();
			 $document->addScriptDeclaration( $js );
			
		}else{
			
			 if(isset($_REQUEST['showtoolbar'])){
			 	echo $bar->render().$mainframe->JComponentTitle."<div style='clear:both;'></div>";
			 }
			 $document =& JFactory::getDocument();

			 JToolBarHelper::custom('cpanel','default','',JText::_( 'DT_CONTROL_PANEL'),false);
		   	 JSubMenuHelper::addEntry(
			 JText::_('DTREG_CATEGORIES'),
			 'index.php?option=com_dtregister&controller=category',
			 $controller == 'category'
		);
JSubMenuHelper::addEntry(
			JText::_('DTREG_CONFIGURATION'),
			'index.php?option=com_dtregister&controller=config',
			$controller == 'config'
		);
JSubMenuHelper::addEntry(
			JText::_('DTREG_CSVEXPORT'),
			'index.php?option=com_dtregister&controller=export',
			$controller == 'export'
		);
		
JSubMenuHelper::addEntry(
			JText::_('DTREG_FIELDS'),
			'index.php?option=com_dtregister&controller=field',
			$controller == 'field'
		);
		
JSubMenuHelper::addEntry(
			JText::_('DTREG_DISCOUNT_CODES'),
			'index.php?option=com_dtregister&controller=discountcode',
			$controller == 'discountcode'
		);
		
JSubMenuHelper::addEntry(
			JText::_('DTREG_EMAIL_REGS'),
			'index.php?option=com_dtregister&controller=registrantemail',
			$controller == 'registrantemail'
		);
JSubMenuHelper::addEntry(
			JText::_('DTREG_EVENTS'),
			'index.php?option=com_dtregister&controller=event',
			$controller == 'event'
		);
JSubMenuHelper::addEntry(
			JText::_('DTREG_LOCATIONS'),
			'index.php?option=com_dtregister&controller=location',
			$controller == 'location'
		);
JSubMenuHelper::addEntry(
			JText::_('DTREG_PAYOPTIONS'),
			'index.php?option=com_dtregister&controller=payoption',
			$controller == 'payoption'
		);
JSubMenuHelper::addEntry(
			JText::_('DTREG_PERMISSIONS'),
			'index.php?option=com_dtregister&controller=permission',
			$controller == 'permission'
		);
		
JSubMenuHelper::addEntry(
			JText::_('DTREG_RECORDS'),
			'index.php?option=com_dtregister&controller=user',
			$controller == 'user'
		);
		
		JSubMenuHelper::addEntry(
			JText::_('DTREG_REMINDERS'),
			'index.php?option=com_dtregister&controller=reminder',
			$controller == 'reminder'
		);
		  
			 ob_start();
             ?>
              DTjQuery(function(){
                
                DTjQuery("a[onclick*='cpanel']").click( function(){
                        
                        document.adminForm.controller.value = 'cpanel';
                        submitform('index');
                        
                });
                DTjQuery("a[onclick*='cpanel']").attr('onclick' ,null);
              });
             <?php
			 $js = ob_get_clean();
			 $document->addScriptDeclaration( $js );
		 
		}
		
	   	parent::display($tpl);
		if($mainframe->isAdmin()){
			 $document->addStyleSheet(JURI::root(true).'/administrator/components/com_dtregister/assets/css/admin.dtregister.css');
		}
	 }
	 function lnglat($zip,$country="") {
		 global $mainframe;
		  
		     
		     $http = new JHttp();
			 $lTable = $this->getModel('location')->table;
			  $json =  array('success'=>false,'errormsg'=>JText::_('DT_LOCATION_NOT_FOUND'));
			 
				$url = "http://maps.google.com/maps/api/geocode/json?components=postal_code:".urlencode($zip)."|country:".urlencode($country)."&sensor=false" ;
				$obj = $http->get($url);
				if($obj->code=="200") {
					
					$obj = json_decode($obj->body);
					if($obj->status == "OK") {
						
						$location = $obj->results[0]->geometry->location;
						$json['success'] = true ;
						$json['errormsg'] = "" ;
						$json['location'] = $location ;
						
												
					}
					
					
				}
				return $json;
				ob_clean();		
				//echo json_encode($json);
				$mainframe->close();
				die;
			
			
		 
	}
	
	 function viewUserField(){
	    require_once(JPATH_SITE."/components/com_dtregister/views/field/view.html.php");
	     $fieldView = new DtregisterViewField(array());
	  
	      foreach($fieldView->getTemplatePath() as $path){
	        if(file_exists($path)){
		      $basepath = $path;
			   break;
		    }
	      }
	      $file = $basepath."default.php";
		  $tpl = file_get_contents($file);
		 
		  $userIndex = DT_Session::get('Setting.current.userIndex');
		  
		  $label = JText::_('DT_USERNAME');
	      $value = DT_Session::get('register.User.username');
		  $constants = array('[label]','[value]','[description]');
		  $replace = array($label,$value,'');
		  $tpl = file_get_contents($file);
		  return $html = str_replace($constants,$replace,$tpl); 
    }
	function userFields($usercreation=0){
	     global $amp,$xhtml;
		 $my = &JFactory::getUser();
		
		 if($my->id || $usercreation==0){
		    	return "";
		 }
	     require_once(JPATH_SITE."/components/com_dtregister/views/field/view.html.php");
	     $fieldView = new DtregisterViewField(array());
	      
	      foreach($fieldView->getTemplatePath() as $path){
	        if(file_exists($path)){
		      $basepath = $path;
			   break;
		    }
	      }
	      $file = $basepath."default.php";
	      $label = JText::_('DT_USERNAME')." <span class='required'>&nbsp;&nbsp;*&nbsp;&nbsp;</span> ";
	      $value = '<input type="text" name="username" id="username" value="" class="required" />';
	      $constants = array('[label]','[value]','[description]');
		  $replace = array($label,$value,'');
		  $tpl = file_get_contents($file);
		  $html = str_replace($constants,$replace,$tpl);
		  
		  $label = JText::_('DT_PASSWORD')." <span class='required'>&nbsp;&nbsp;*&nbsp;&nbsp;</span> ";
	      $value = '<input type="password" name="password" id="password"  value="" class="required" />';
		  $replace = array($label,$value,'');
		  $tpl = file_get_contents($file);
		  $html .= str_replace($constants,$replace,$tpl); 
		  
		  $label = JText::_('DT_CONFIRM_PASSWORD')." <span class='required'>&nbsp;&nbsp;*&nbsp;&nbsp;</span> ";
	      $value = '<input type="password" id="confirmpassword" name="confirmpassword" value="" class="required" />';
		  $replace = array($label,$value,'');
		  $tpl = file_get_contents($file);
		  $html .= str_replace($constants,$replace,$tpl);
	   	  $document = &JFactory::getDocument();
		  ob_start();
		  ?>
             DTjQuery(function(){
                  DTjQuery(document.frmcart).validate({
                        ignore:":not(:visible)",
                        success: function(label) {
                            label.addClass("success");
                        }
              
                });
                   DTjQuery('#username').val('');
                   DTjQuery('#password').val('');
                   DTjQuery('#confirmpassword').val('');
                   DTjQuery('#username').rules('add',{remote: "<?php echo JRoute::_('index.php?option=com_dtregister&controller=validate&task=uniqueUser&no_html=1',$xhtml); ?>"
                 
             });
                   DTjQuery('#confirmpassword').rules('add',{equalTo: "#password"
                  });

              });
          <?php
		  $js = ob_get_clean();
		  $document->addScriptDeclaration($js);
	   	 return $html;
	 }
	 
	 function getTemplatePath() {
	 	
		return $this->_path['template'];
	 }
	 
	 function capthaField(){
	     global $amp,$xhtml;
		 require_once(JPATH_SITE."/components/com_dtregister/views/field/view.html.php");
	     $fieldView = new DtregisterViewField(array());
	  
	      foreach($fieldView->getTemplatePath() as $path){
	        if(file_exists($path)){
		      $basepath = $path;
			   break;
		    }
	      }
		  $constants = array('[label]','[value]','[description]');
	      $file = $basepath."default.php";
		  
		  $label = JText::_('DT_ENTER_SECURITY_CODE')." <span class='required'>&nbsp;&nbsp;*&nbsp;&nbsp;</span>";
	      $value = '<input type="text" id="captchaField" name="captcha" value="" class="required" /> <img src="'. JURI::root(true).'/components/com_dtregister/CaptchaSecurityImages.php?width=100'. $amp.'height=40'.$amp.'characters=5" id="captchaelement" align="middle" alt="" /><label for="captchaField" style="display:none" generated="true" class="error"></label>
';
          $document = &JFactory::getDocument();
		  ob_start();
		  ?>
             DTjQuery(function(){
                 
                 DTjQuery('#captchaelement').live('click',function(){
                     var src = DTjQuery(this).attr('src');
                     DTjQuery(this).attr('src','');
                     DTjQuery(this).attr('src',src+"&rand"+Math.floor(Math.random()*5));
                     
                 });
                   DTjQuery(document.frmcart).validate({
                        ignore:":not(:visible)",
                        success: function(label) {
                            label.addClass("success");
                        }
              
                });
                   DTjQuery('#captchaField').rules('add',{remote: "<?php echo JRoute::_('index.php?option=com_dtregister&controller=validate&task=captcha&no_html=1',$xhtml); ?>"
});
                 
             });
          <?php
		  $js = ob_get_clean();
		  $document->addScriptDeclaration($js);
		  $replace = array($label,$value,'');
		  $tpl = file_get_contents($file);
		  $html .= str_replace($constants,$replace,$tpl); 
		  return $html;
		
	 }
   
  function termsField($eventId){
	    global $amp,$xhtml;
	     require_once(JPATH_SITE."/components/com_dtregister/views/field/view.html.php");
	     $fieldView = new DtregisterViewField(array());
	  
	      foreach($fieldView->getTemplatePath() as $path){
	        if(file_exists($path)){
		      $basepath = $path;
			   break;
		    }
	      }
	      $file = $basepath."default.php";
		  $label = JText::_( 'DT_CHECK_TERMS_CONDITIONS' );
	      $value = '<input type="checkbox" name="terms_conditions" id="terms_conditionscheck" value="terms" class="required" />';
		  $value .= '<a href="'.JRoute::_('index.php?option=com_dtregister&controller=event&task=terms&no_html=1&eventId='.$eventId).'" id="terms_conditions_popup" class="lbOn">'. htmlspecialchars  (JText::_( 'DT_TERMS_CONDITIONS_READ' )).'</a> <label for="terms_conditions" style="display:none" generated="true" class="error"></label> ';
              
	      $constants = array('[label]','[value]','[description]');
		  $replace = array($label,$value,'');
		  $tpl = file_get_contents($file);
		  $html = str_replace($constants,$replace,$tpl);
		  $document	=& JFactory::getDocument();
		  if(!JModuleHelper::isEnabled('s5_box')){
		  	$document->addStyleSheet(JURI::root(true).'/components/com_dtregister/assets/css/jquery.lightbox.css');
		  }
		  $document->addScript( JURI::root(true).'/components/com_dtregister/assets/js/jquery.lightbox.js');
		   ob_start();
		  ?>
             DTjQuery(function(){
                 DTjQuery("#terms_conditions_popup").live('click',function(){
                
			var href = DTjQuery(this).attr('href');
            
			DTjQuery.fn.colorbox({href:DTjQuery(this).attr('href'), open:true,iframe:true,  innerWidth:'50%',innerHeight:'50%' });
			
			return false;

		});
                
             });
          <?php
		  $js = ob_get_clean();
		  $document->addScriptDeclaration($js);
		  return $html;
  }
  
  	  function sessionUserCheck($aco,$aro,$acoController){ 
	 pr($aco);
	 pr($aro);
	 
	 $user = &JFactory::getUser();
	// $acoController = str_replace("dtregistercontroller",'',strtolower(get_class($this)));
	  $map = array('eventmanage' => 'event','user'=>'usermanage');
	 if(isset($map[$acoController])){
		$acoController = $map[$acoController];
	 }
	 
	  if($aro !== false){
		 $permission = $this->getModel( 'permission' )->table->find('aro_id in('.implode(",",$aro).') and aco_id = '.$aco->id);
		  pr($permission);
		  $aco_edit_own = $this->getModel( 'aco' )->table->find(' controller="entity" and task="edit" ');
		  if(isset($aco_edit_own[0])) {
		     $aco_edit_own = $aco_edit_own[0];
		  }
		  pr('aro_id in('.implode(",",$aro).') and aco_id = '.$aco_edit_own->id);
		  $permission_edit_own = $this->getModel( 'permission' )->table->find('aro_id in('.implode(",",$aro).') and aco_id = '.$aco_edit_own->id);
		   pr($permission_edit_own);
	        if($permission && count($permission) == count($aro) && $permission_edit_own ){ //die("line 354");
				 prd("enter");
			//if(1){
		    $cid = JRequest::getVar( 'cid', array(), 'request', 'array' );
pr($cid );
		    if($cid){
		
		        $rowKey = $cid[0];
				$model = $this->getModel( $aco->controller );
				$table = $model->table;
				if($aco->controller == "event" || $aco->controller == "eventmanage") {
				  $events_obj = $table->TableModerator->find('user_id = '.$user->id);
				  $events = array(0);
				  foreach($events_obj as $evt) {
					 $events[] = $evt->eventId;
				  }
				  $user_condtion = "";
				if(count($events) > 0) {
				$user_condtion = " slabId in(".implode(",",$events).")";
				}
			   } else {
			      $user_condtion = " user_id =".$user->id;
			   }
			   
				$data = $table->find($user_condtion.' and '.$table->getKeyName().' = '.$rowKey);
				
				if($data){
					$return = true;
				}else{
					$return = false;
				}
				//$return = ($data)?true:false;
				
				return ($return);
				
	         }else{ 
			    return true;	 
			 }
		 }else if(count($permission) > 0 ) {   
			 return true;
	      }elseif($aco->alias == "DT_EDIT_OWN_EVENT"){
			 if($aco->task == "events" || $aco->task== "edit") {

				 if($acoController == 'event') {
					 $edit_task = 'delete';
				 } else {
					 $edit_task = 'edit';
				 }
		 
		      $editaco = $this->getModel( 'aco' )->table->find(' controller="'.$acoController.'" and task="'.$edit_task.'" ');
		      $addaco = $this->getModel( 'aco' )->table->find(' controller="'.$acoController.'" and task="add" ');
			  
			  $publish = $this->getModel( 'aco' )->table->find(' controller="'.$acoController.'" and task="publish" ');
			  $edit_permission = false;
			  $add_permission = false;
			   $publish_permission = false;
			  if(isset($editaco[0])){ 
			     
				 $editaco = $editaco[0];
			 
			     $function = $editaco->type."Check";
			 
		         $edit_permission = $this->{$function}($editaco,$aro);

			  }
			  
			  if(isset($addaco[0])) {
				  $addaco = $addaco[0];
		         $function = $addaco->type."Check";
			 
		         $add_permission = $this->{$function}($addaco,$aro);
			  }
			  
			   if(isset($publish[0])) {
				  $publish = $publish[0];
		         $function = $addaco->type."Check";
			 
		         $publish_permission = $this->{$function}($publish,$aro);
			  }
			  if($edit_permission ||$add_permission || $publish_permission) {
			     return true;
			  } else {
			     return false; 
			  }

			 } else {
			
			 return   (count($permission) > 0);
			 }
		  }
		  else
		  {
		     return false;
		  }
		  return true;
	  } else {}
	  die; 
	// return false;
		
        //return ($permission);

  }
  
  function actionCheck($aco,$aro,$acoController=""){  
 //pr($aco);
	 //pr($aro);
	  if($aro !== false){

			$permission = $this->getModel( 'permission' )->table->find('aro_id in('.implode(",",$aro).') and aco_id = '.$aco->id);

			 return ((boolean)$permission);

		}
		return true;
	  
  }
 
  
 
  
 
  
     function checkpermission_flex($acoController, $task){
	 
     $user = &JFactory::getUser();
	 $aro = $this->getModel( 'aro' )->table->findaroByUser($user);
	 $acomodel = $this->getModel( 'aco' );
	 if(isset($aro) && is_array($aro))
     foreach($aro as $key=>$ar){
	 	if($ar==1){
		    unset($aro[$key]);
			break;
		}
	 }
	
	 if($acoController == "permission") { return true ;}
	 $map = array('eventmanage' => 'event','user'=>'usermanage');
	 if(isset($map[$acoController])){
		$acoController = $map[$acoController];
	 }
	
	
	
	 if(isset($acomodel->relation[$acoController]) &&  isset($acomodel->relation[$acoController][$task]) ) {
	   // or permission
	   pr($acomodel->relation[$acoController][$task]);
	   foreach($acomodel->relation[$acoController][$task] as $aconame) {
		   pr($acomodel->AcoGroup[$aconame]);
		   
		   foreach($acomodel->AcoGroup[$aconame] as $tasks){
			 $task = $tasks['task'];
			 $controller = $tasks['controller'];
			 $aco = $this->getModel( 'aco' )->table->find(' controller="'.$controller.'" and task="'.$task.'" ');
			 pr($aco);
			 if(isset($aco[0])){
		   
				 $aco = $aco[0];
				 $function = $aco->type."Check";
				 pr($function);
				// var_dump($this->{$function}($aco,$aro));
				 if($this->{$function}($aco,$aro,$acoController)){
					return true;
				 }
	
			 } else {
				continue;
			 }
		   }
		   
		   //$aco = $this->getModel( 'aco' )->table->find(' controller="'.$acoController.'" and task="'.$edit_task.'" ');
	     
	   }
	   return false ;  // have no permission to child resources .
	   prd('check child permission');
	 }
	  if( $task != 'eventlist' && $task !="index" && $task !="payments" && $task != "display" && $task !="events"){ 
		 if($acoController == 'event') {
		     $edit_task = 'delete';
		 } else {
		     $edit_task = 'edit';
		 }
		 
	 	 $editaco = $this->getModel( 'aco' )->table->find(' controller="'.$acoController.'" and task="'.$edit_task.'" ');
		 $addaco = $this->getModel( 'aco' )->table->find(' controller="'.$acoController.'" and task="add" ');
		 pr($editaco);
		 pr($addaco);
		 if(isset($editaco[0]) && isset($addaco[0])){
			 $editaco = $editaco[0];
			 $addaco = $addaco[0];
			 
			 $function = $editaco->type."Check";
			 
		     $edit_permission = $this->{$function}($editaco,$aro,$acoController);
			 $function = $addaco->type."Check";
			 
		     $add_permission = $this->{$function}($addaco,$aro,$acoController);
			
			 if($add_permission || $edit_permission){
				 return true;
			 }else{
				 return false;
			 }
			 
		 }
		 
	 }else{
	  
	   $aco = $this->getModel( 'aco' )->table->find(' controller="'.$acoController.'" and task="'.$task.'" ');
	   pr($task);
	   pr($acoController);
	   pr($aco);
	   pr($aro);
	
	   if(isset($aco[0])){
		 
		   $aco = $aco[0];
		   $function = $aco->type."Check";
		   pr($function);
		  // var_dump($this->{$function}($aco,$aro));
		   return $this->{$function}($aco,$aro,$acoController);
  
	   } else {
		 //  prd($aro);
	      return true ;  
	   }
	 }
	 
	 return true;

  }
	 
	 
	 function checkpermission(){
     $user = &JFactory::getUser();
	 $aro = $this->getModel( 'aro' )->table->findaroByUser($user);
	foreach($aro as $key=>$ar){
	 	if($ar==1){
		    unset($aro[$key]);
			break;
		}
	 }
	 $acoController = str_replace("dtregistercontroller",'',strtolower(get_class($this)));
	 $acoController = 'event';
	 $map = array('eventmanage' => 'event');
	 if(isset($map[$acoController])){
		$acoController =  $map[$acoController];
	 }
	
	 $task = 'publish';

	 if(0){
	 	 $editaco = $this->getModel( 'aco' )->table->find(' controller="'.$acoController.'" and task="edit" ');
		 $addaco = $this->getModel( 'aco' )->table->find(' controller="'.$acoController.'" and task="add" ');
		 if(isset($editaco[0]) && isset($addaco[0])){
			 $editaco = $editaco[0];
			 $addaco = $addaco[0];
			 
			 $function = $editaco->type."Check";
			 
		     $edit_permission = $this->{$function}($editaco,$aro);
			 $function = $addaco->type."Check";
			 
		     $add_permission = $this->{$function}($addaco,$aro);
			
			 if($add_permission && $edit_permission){
				 return true;
			 }else{
				 return false;
			 }
			 
		 }
		 
	 }else{
	  
	   $aco = $this->getModel( 'aco' )->table->find(' controller="'.$acoController.'" and task="'.$task.'" ');
	 
	   $index = 0;
	   if($acoController == 'event' || $acoController == 'eventmanage' ) {
	   		if($task == 'publish' || $task == 'unpublish') {
				foreach($aco as $acodata) {
					if($acodata->type == "action") {
						$actionaco = $acodata;
					} else{
					    $sessionaco = $acodata;
					}
				}
				
				if($this->actionCheck($actionaco,$aro,$acoController)) {
					if(isset($sessionaco)) {
					  return $this->sessionUserCheck($sessionaco,$aro);
					} else {
					   return true;
					}
				} else {
					return false;
				}
			}
	   }
	 
	   if(isset($aco[$index])){
		  
		   $aco = $aco[$index];
		   $function = $aco->type."Check";
		   return $this->{$function}($aco,$aro);
  
	   }
	 }
	 //die;
	 return true;

  }
  
  
   function checkpermission_create_event(){
     $user = &JFactory::getUser();
	 $aro = $this->getModel( 'aro' )->table->findaroByUser($user);
	foreach($aro as $key=>$ar){
	 	if($ar==1){
		    unset($aro[$key]);
			break;
		}
	 }
	 $acoController = str_replace("dtregistercontroller",'',strtolower(get_class($this)));
	 $acoController = 'event';
	 $map = array('eventmanage' => 'event');
	 if(isset($map[$acoController])){
		$acoController =  $map[$acoController];
	 }
	
	 $task = 'add';

	 if(0){
	 	 $editaco = $this->getModel( 'aco' )->table->find(' controller="'.$acoController.'" and task="edit" ');
		 $addaco = $this->getModel( 'aco' )->table->find(' controller="'.$acoController.'" and task="add" ');
		 if(isset($editaco[0]) && isset($addaco[0])){
			 $editaco = $editaco[0];
			 $addaco = $addaco[0];
			 
			 $function = $editaco->type."Check";
			 
		     $edit_permission = $this->{$function}($editaco,$aro);
			 $function = $addaco->type."Check";
			 
		     $add_permission = $this->{$function}($addaco,$aro);
			
			 if($add_permission && $edit_permission){
				 return true;
			 }else{
				 return false;
			 }
			 
		 }
		 
	 }else{
	  
	   $aco = $this->getModel( 'aco' )->table->find(' controller="'.$acoController.'" and task="'.$task.'" ');
	 
	   $index = 0;
	   if($acoController == 'event' || $acoController == 'eventmanage' ) {
		  // pr($aco);
	   		if($task == 'add') {
				foreach($aco as $acodata) {
					if($acodata->type == "action") {
						$actionaco = $acodata;
					} else{
					    $sessionaco = $acodata;
					}
				}
				//pr($actionaco);
				//pr($aro);
				if($this->actionCheck($actionaco,$aro)) {
					if(isset($sessionaco)) {
					  return $this->sessionUserCheck($sessionaco,$aro);
					} else {
					   return true;
					}
				} else {
					return false;
				}
			}
	   }
	
	   if(isset($aco[$index])){
		  
		   $aco = $aco[$index];
		   $function = $aco->type."Check";
		   return $this->{$function}($aco,$aro);
  
	   }
	 }
	 //die;
	 return true;

  }
  
}
?>
<?php 
global $mainframe;
if($mainframe->isAdmin() && !isset($_REQUEST['no_html'])){
?>
<style>
 div.current label, div.current span.faux-label {
    clear: none;
    display: block;
    float: left;
    margin: 0px 10px 0px 5px;
    min-width: 30px;
}

</style>
<?php
}
?>