<?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( 'Restricted access' );
jimport('joomla.application.component.controller');

class DtrController extends JController {

	 function __construct($config = array()){

		$this->addModelPath(JPATH_COMPONENT_ADMINISTRATOR.DS.'models');

		parent::__construct($config);
        if(isset($config['task_map'])){
		  	foreach($config['task_map'] as $task=>$map){
				$this->registerTask( $task, $map );	
			}
		}
		$view = & $this->getView( $this->name, 'html','dtregisterview' );
        $this->getModel('payoption');
		$this->config = $this->getModel('config');

		$this->config->setGlobal();
        global $DT_config,$timezone;
				
		$timezone = $DT_config['global']['timezone'];
		  global $sign_up_redirect,$Itemid,$private_event_notification,$private_event_redirect; 

		if($private_event_notification=='redirect'){

		   $sign_up_redirect = $private_event_redirect;

		}else{

		   $sign_up_redirect = "index.php?option=com_dtregister&controller=content&Itemid=$Itemid&task=sign_up";

		}

        $view->setModel($this->getModel('dtregister'),false);

		$view->setModel($this->getModel('config'),false);
		
		$view->setModel($this->getModel('Accessoptions'),false);
		
		$view->setModel($this->getModel( 'Currency' ),false);

		$view->setModel($this->getModel( 'jomsocial' ),false);

		$view->setModel($this->getModel( 'cbprofiler' ),false);

		$view->setModel($this->getModel( 'buttoncolor' ),false);

		$view->setModel($this->getModel( 'dateformat' ),false);

		$view->setModel($this->getModel( 'paymentmethod' ),false);

		$view->setModel($this->getModel( 'cardtype' ),false);

		$view->setModel($this->getModel( 'paylater' ),false);	

		$view->setModel($this->getModel( 'country' ),false);

		$view->setModel($this->getModel( 'barcode' ),false);	

		$view->setModel($this->getModel( 'aro' ),false);	

		$view->setModel($this->getModel( 'permission' ),false);

		$view->setModel($this->getModel( 'aco' ),false);
		
		$this->getModel('field');
		$tAccessoption = $this->getModel('Accessoptions')->table;
		
        $view->assign('accessOptions',$tAccessoption->optionslist());
		$eventId = DT_Session::get('register.Event.eventId');
        
		if($this->checkpermission() === false){

			JRequest::setVar('task','auth');

	    }elseif($eventId ){
		   	$evtTable = $this->getModel('event')->table;
			$evtTable->load($eventId);
			$user = & JFactory::getUser();
			if($evtTable->title !==""){
				$access_levels = $user->authorisedLevels();
			  if((!(in_array($evtTable->TableCategory->access ,$access_levels)) || $evtTable->TableCategory->published == 0)&&$evtTable->TableCategory->categoryId > 0){
			   	 JRequest::setVar('task','auth');
			  }
			}
			
		}

	}
	
	function populatelatlng() {
		      $options = JFactory::getConfig();

$transport = new JHttpTransportCurl($options);

// Create a 'stream' transport.
$http = new JHttp($options, $transport);
			 $lTable = $this->getModel('location')->table;
			  
			 $rows = $lTable->find();
			 foreach($rows as $row){
				$url = "http://maps.google.com/maps/api/geocode/json?components=postal_code:".urlencode($row->zip)."|country:".urlencode($row->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;
						$query = "update #__dtregister_locations set lng = '".$location->lng."' , lat = '".$location->lat."' where id= ".$row->id." ";
						$lTable->rawquery($query);
												
					}
					
				}

			 }

	}
	
	function getlnglat() {
		 global $mainframe;
		  
		  $document =& JFactory::getDocument();
           
          $document->setMimeEncoding('application/json');
		  $options = JFactory::getConfig();

$transport = new JHttpTransportCurl($options);

// Create a 'stream' transport.
                $http = new JHttp($options, $transport);
			    $lTable = $this->getModel('location')->table;
			    $json = array('success'=>false,'errormsg'=>JText::_('DT_LOCATION_NOT_FOUND'));
			    $zip = JRequest::getVar('zip',"");
			    $country = JRequest::getVar('country',"");
			    $address = array();
			    $address[] = JRequest::getVar('address',"");
			    $address[] = JRequest::getVar('address2',"");
			    $address[] = JRequest::getVar('city',"");
				$address[] = JRequest::getVar('state',"");
				
				$address = array_filter($address);
				
				$address = trim(implode(" ",$address));
				$url_address = "";
				if($address !=""){
			      $url_address = "&address=".urlencode($address);
				}
				$url = "http://maps.google.com/maps/api/geocode/json?components=postal_code:".urlencode($zip)."|country:".urlencode($country)."&sensor=false".$url_address;
				$obj = $http->get($url);
				$json['url'] = $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;
					
					}
		
				}
				ob_clean();		
				echo json_encode($json);
				$mainframe->close();
				die;

	}
	
	function lnglat($zip,$country="") {
		 global $mainframe;

		 $options = JFactory::getConfig();

$transport = new JHttpTransportCurl($options);

// Create a 'stream' transport.
$http = new JHttp($options, $transport);
			 $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 getModel($model,$prefix='dtregistermodel',$bool=array()){
		return parent::getModel($model,$prefix,array());
	}
	
	function getView( $view, $type='html',$prefix= 'dtregisterview' ){
		
		return parent::getView( $view, $type,$prefix);
		
	}
	
	function cbtest(){
		
		$mpermission = DtrModel::getInstance('permission','DtregisterModel');
	$acoObj = DtrModel::getInstance('aco','DtregisterModel');
	$aroObj = DtrModel::getInstance('aro','DtregisterModel');
	$aros = $aroObj->find();
	$matrix = $mpermission->table->getmatrix();
	$acos = $acoObj->AcoGroup;
	$data = array();
	$data['permission'] = array();
	//pr($aros);
	//pr($acos);
	foreach($aros as $aro){
	  foreach($acos as $name=>$aco){ 
		   if(isset($matrix[$aro->id]) && isset($matrix[$aro->id][$name])){ 
		      $data['permission'][$aro->id][$name] = 1;
		   }

	  }
	}
	 $tableRows = array();
	if (is_array($data['permission'])) 
	foreach($data['permission'] as $key => $permission){

			 foreach($permission as $name =>$val){

				 $tableRows[] = array('aro_id'=>$key,'group'=>$name);

			  }

		  } 
echo "<pre>";
print_r($matrix);
print_r($tableRows);
print_r($data);

die;
	$acoObj->table->truncate();
	$matrix = $mpermission->table->update($tableRows);

		/*$model = $this->getModel('user');
		$table = $model->table;
		$table->load(53);
		$table->createCbUser();*/
   }

  function auth(){

	   $view = & $this->getView('authorize', 'html' );

	   $view->display();

  }

  function display() {
      
   $this->view->setLayout($this->doTask);

   $this->view->display();

   //parent::display();

  }
 
  function checkpermission(){
	 
     $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;
		}
	 }
	 $acoController = str_replace("dtregistercontroller",'',strtolower(get_class($this)));
	 if($acoController == "permission") { return true ;}
	 $map = array('eventmanage' => 'event','user'=>'usermanage');
	 if(isset($map[$acoController])){
		$acoController = $map[$acoController];
	 }
	
	
	 if(@in_array(JRequest::getVar('task',$this->taskMap['__default']),$this->taskMap)){
		$task = JRequest::getVar('task',$this->taskMap['__default']);
	 }else{
	 	$task = $this->taskMap['__default'];
	 }
	 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)){
					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 == $this->taskMap['__default'] && $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);
			 $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.'" ');
	   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);
  
	   } else {
		 //  prd($aro);
	      return true ;  
	   }
	 }
	 
	 return true;

  }
  function sessionUserCheck($aco,$aro){
	 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){
 //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 testexport() {
     $exp = $this->getModel('export')->table;;
	 $exp->loadfirstRow();
	 $exp->getgeneralHeader();
	 $exp->mergeCustomFieldHeader();
	 $exp->makeheader();
	 $user = $this->getModel('user')->table;
	 $user->load(415);
	 $exp->addmembers($user);
	 echo $exp->csvoutput;
	 die;
  }
  
  function testemail(){
		global $subthanksemail,$thanksemail,$DT_mailfrom,$DT_fromname,$admin_registrationemail,$eventModifyNotification,$waitingemail;
		
	   $Tagparser = new DT_Tagparser();

       $user = $this->getModel('user')->table;
	   $user->load(415);
	   
$user->TableEvent->thksmsg_set = false;
	  if($user->TableEvent->thksmsg_set){

		  $thkmsg = $user->TableEvent->thksmsg;   

	  }else{

		  $thkmsg = $thanksemail;

	  }
	 // echo  $thkmsg = $waitingemail;
	  $mpaymentmethods = & DtrModel::getInstance('DtregisterModelPaymentmethod');

		 $methods = $mpaymentmethods->getMergeList(true);
		 echo  "<pre>";
		 $mpaymentmethods = & DtrModel::getInstance('DtregisterModelPaymentmethod');

		 $methods = $mpaymentmethods->getMergeList(true);
		 
		 
		 $user->TableFee->payment_method;
		 
		 print_r($methods);
	 
	  // var_dump($thkmsg);
	  $subject = $Tagparser->parsetags($subthanksemail,$user);
	  echo "<br /><b>Subject : </b>".$subject."<br />";
	 // echo $thkmsg;
	 
	  $thkmsg = $Tagparser->parse_paylater_tag($thkmsg,$user);
	
	  $groupmsg = $Tagparser->getTagcontent('GROUP_MEMBER',$thkmsg);
	  
	  $memberdata = "";
	  if($user->type == 'G')
	   foreach($user->members as $member){
          
		// pr($member);
	    // pr($groupmsg);
		   
		   $memberdata .= $Tagparser->parsetags($groupmsg,$member);	 	 

		}
		
		 $usermsg = $Tagparser->replaceTagContent('GROUP_MEMBER',$thkmsg,$memberdata);
		
         echo $Tagparser->parsetags($usermsg,$user);
	  die;
	  echo "<br /> <b><<<<======================Admin Email=============================///>>></b>";
	  
	   echo ($admin_registrationemail);
	  
	  $groupmsg = $Tagparser->getTagcontent('GROUP_MEMBER',$admin_registrationemail);
	  $usermsg = $Tagparser->replaceTagContent('GROUP_MEMBER',$admin_registrationemail);
	 //prd($user);
	   echo $Tagparser->parsetags($usermsg,$user);
	   if($user->type == 'G')
	   foreach($user->members as $member){

		    echo $Tagparser->parsetags($groupmsg,$member);   

		}
	  
  }
  
  function test2(){
	  
	  $user = $this->getModel('user')->table;
	  $user->eventId = 3;
	  $user->load(0);
	  $user->TableEvent->overrideGlobal($user->TableEvent->slabId);
	  global $DT_mailfrom,$DT_fromname;
	  global $currency_code,$email_cancel_confirm,$upsubcancelemail;
      $Tagparser = new Tagparser();
	  $msg = "";
	  $msg .= '<p>[EVENT_NAME] [LASTNAME]</p>';
	  
	 // pr($msg);
	  $msg = $Tagparser->parsetags($msg,$user);
	  prd($msg);

  }
  function status_change_email()  {
	 global $status_change_msg,$subchangestatusemail,$status_change_msg_send;
	 $user = $this->getModel('user')->table;
	 $user->load(422);
	 $mails = $user->parse_email($status_change_msg,$subchangestatusemail,$status_change_msg_send);
	 echo "<pre>";
	 echo $status_change_msg;
	 print_r($mails);
	 global $paid_status_change_msg,$subpaidstatusemail,$paid_status_change_msg_send;
	 $mails = $user->parse_email($paid_status_change_msg,$subpaidstatusemail,$paid_status_change_msg_send);
	 echo $paid_status_change_msg;
	 print_r($mails);
	// $user->status_change_email();  
  
  }
  function testcancel(){
	   
	   $user = $this->getModel('user')->table;
	   $user->load(340);
	   $user->TableEvent->overrideGlobal($user->TableEvent->slabId);
	   global $DT_mailfrom,$DT_fromname;
	   global $currency_code,$email_cancel_confirm,$upsubcancelemail;
      $Tagparser = new Tagparser();
	  $msg = "";
	  $msg .= '<p>[FIRSTNAME] [LASTNAME] '.JText::_('DT_ADMIN_MSG_CANCEL').' [EVENT_NAME]</p>';
	  $msg .= '<table class="message">';
		
	  $msg.="<tr><td>".JText::_('DT_CONFIRMATION_NUMBER').": </td><td>[CONFIRM_NUM]</td></tr>";
	  $msg.="<tr><td>".JText::_('DT_REGISTRATION_FEE').": </td><td>[AMOUNT]</td></tr>";
	  $msg.="<tr><td>".JText::_('DT_AMOUNT_PAID').": </td><td>[AMOUNT_PAID] </td></tr>";
	  $msg.="<tr><td>".JText::_('DT_PAYMENT_TYPE').": </td><td>[PAYMENT_TYPE]</td></tr>";
	 
      if( $user->TableFee->cancelfee > 0 ){
     
		$msg.="<tr><td>".JText::_('DT_CANCEL_FEE').": </td><td>[CANCEL_FEE]</td></tr>";
		$amount_due = $user->TableFee->fee -  $user->TableFee->paid_amount;
		if($amount_due > 0){  
		   $label = JText::_('DT_AMOUNT_DUE');
		}else{
		   $label = JText::_('DT_REFUND_DUE');
		}
		
		$msg.="<tr><td>".$label.": </td><td>[AMOUNT_DUE]</td></tr>";
	   
     }
  
     $msg .="</table>";
	 
	 $msg = $Tagparser->parsetags($msg,$user);
  	 $adminemails=$user->TableEvent->email;
     $adminemails = explode(";",$adminemails);
     $conf = &JFactory::getConfig();
     if($DT_mailfrom == ""){
        $DT_mailfrom = $conf->_registry['config']['data']->mailfrom;
     }
     if($DT_fromname==""){
        $DT_fromname =$conf->_registry['config']['data']->fromname;
     }

   echo "<br />".$msg;
    foreach($adminemails as $email){
   
    }
	
   $message = $Tagparser->parsetags($email_cancel_confirm,$user);
   $subject = $Tagparser->parsetags($upsubcancelemail,$user);
   
   $email = $user->getFieldByName('email');
    
   echo "<br /><b>Subject </b>: ".$subject;
   echo "<br />".$message;
	  
  }
  
  function testcontroller(){
	  // is_anyregistration  is fine .
      $eventTable = $this->getModel('event')->table;
	  $eventTable->load(101);
	  $oldrepetitions = $eventTable->getrepetions();
	 $data = array (
  'data' => 
  array (
    'event' => 
    array (
      'user_id' => '',
      'title' => 'Testing Still',
      'category' => '',
      'location_id' => '',
      'publish' => '0',
      'timeformat' => '1',
      'dtstart' => '2011-03-31',
      'dtstarttime' => '09:28 PM',
      'dtend' => '2011-03-31',
      'dtendtime' => '10:28 PM',
      'email' => 'dthdev@dthdevelopment.com',
      'repeatType' => 'weekly',
      'rpinterval' => '1',
      'countselector' => 'count',
      'rpcount' => '3',
      'rpuntil' => '',
      'weekdays' => 
      array (
        0 => '3',
      ),
      'monthdays' => '',
      'monthdayselector' => 'monthweekdays',
      'registration_type' => 'individual',
      'group_registration_type' => 'detail',
      'public' => '1',
      'max_registrations' => '0',
      'min_group_size' => '2',
      'max_group_size' => '0',
      'startdate' => '0000-00-00',
      'starttime' => '12:00 AM',
      'cut_off_date' => '0000-00-00',
      'cut_off_time' => '12:00 AM',
      'waiting_list' => '0',
      'article_id' => '',
      'detail_itemid' => '0',
      'detail_link_show' => '0',
      'show_registrant' => '0',
      'prevent_duplication' => '1',
      'usetimecheck' => '0',
      'excludeoverlap' => '0',
      'usercreation' => '0',
      'imagepath' => '',
      'payment_id' => '1',
      'partial_payment' => '0',
      'partial_amount' => '',
      'partial_minimum_amount' => '',
      'tax_enable' => '0',
      'tax_amount' => '0.00',
      'discount_type' => '0',
      'discount_amount' => '0.00',
      'bird_discount_type' => '0',
      'bird_discount_amount' => '',
      'bird_discount_date' => '0000-00-00',
      'bird_discount_time' => '12:00 AM',
      'latefee' => '0.00',
      'latefeedate' => '0000-00-00',
      'latefeetime' => '12:00 AM',
      'use_discountcode' => '0',
      'topmsg' => '',
      'event_describe_set' => '0',
      'event_describe' => '',
      'thanksmsg_set' => '0',
      'thanksmsg' => '',
      'pay_later_thk_msg_set' => '0',
      'pay_later_thk_msg' => '',
      'terms_conditions_set' => '0',
      'terms_conditions_msg' => '',
      'thksmsg_set' => '0',
      'thksmsg' => '',
      'admin_notification_set' => '0',
      'admin_notification' => '',
      'partial_payment_enable' => '0',
      'cancel_refund_status' => '0',
      'edit_fee' => '0',
      'change_date' => '',
      'change_time' => '12:00 AM',
      'cancel_enable' => '0',
      'cancel_date' => '',
      'cancel_time' => '12:00 AM',
      'changefee_enable' => '0',
      'changefee_type' => '1',
      'changefee' => '0.00',
      'cancelfee_enable' => '0',
      'cancelfee_type' => '1',
      'cancelfee' => '0.00',
      'slabId' => '101',
    ),
    'group' => 
    array (
      0 => 
      array (
        'member' => '1',
        'amount' => '0.00',
      ),
      1 => 
      array (
        'member' => '0',
        'type' => 'per_person',
        'amount' => '0.00',
      ),
      2 => 
      array (
        'member' => '0',
        'type' => 'per_person',
        'amount' => '0.00',
      ),
      3 => 
      array (
        'member' => '0',
        'type' => 'per_person',
        'amount' => '0.00',
      ),
      4 => 
      array (
        'member' => '0',
        'type' => 'per_person',
        'amount' => '0.00',
      ),
      5 => 
      array (
        'member' => '0',
        'type' => 'per_person',
        'amount' => '0.00',
      ),
      6 => 
      array (
        'member' => '0',
        'type' => 'per_person',
        'amount' => '0.00',
      ),
      7 => 
      array (
        'member' => '0',
        'type' => 'per_person',
        'amount' => '0.00',
      ),
      8 => 
      array (
        'member' => '0',
        'type' => 'per_person',
        'amount' => '0.00',
      ),
      9 => 
      array (
        'member' => '0',
        'type' => 'per_person',
        'amount' => '0.00',
      ),
      10 => 
      array (
        'member' => '0',
        'type' => 'per_person',
        'amount' => '0.00',
      ),
      11 => 
      array (
        'member' => '0',
        'type' => 'per_person',
        'amount' => '0.00',
      ),
      12 => 
      array (
        'member' => '0',
        'type' => 'per_person',
        'amount' => '0.00',
      ),
      13 => 
      array (
        'member' => '0',
        'type' => 'per_person',
        'amount' => '0.00',
      ),
      14 => 
      array (
        'member' => '0',
        'type' => 'per_person',
        'amount' => '0.00',
      ),
      15 => 
      array (
        'member' => '0',
        'type' => 'per_person',
        'amount' => '0.00',
      ),
      16 => 
      array (
        'member' => '0',
        'type' => 'per_person',
        'amount' => '0.00',
      ),
      17 => 
      array (
        'member' => '0',
        'type' => 'per_person',
        'amount' => '0.00',
      ),
      18 => 
      array (
        'member' => '0',
        'type' => 'per_person',
        'amount' => '0.00',
      ),
      19 => 
      array (
        'member' => '0',
        'type' => 'per_person',
        'amount' => '0.00',
      ),
      20 => 
      array (
        'member' => '0',
        'type' => 'per_person',
        'amount' => '0.00',
      ),
      21 => 
      array (
        'member' => '0',
        'type' => 'per_person',
        'amount' => '0.00',
      ),
      22 => 
      array (
        'member' => '0',
        'type' => 'per_person',
        'amount' => '0.00',
      ),
      23 => 
      array (
        'member' => '0',
        'type' => 'per_person',
        'amount' => '0.00',
      ),
      24 => 
      array (
        'member' => '0',
        'type' => 'per_person',
        'amount' => '0.00',
      ),
      25 => 
      array (
        'member' => '0',
        'type' => 'per_person',
        'amount' => '0.00',
      ),
      26 => 
      array (
        'member' => '0',
        'type' => 'per_person',
        'amount' => '0.00',
      ),
      27 => 
      array (
        'member' => '0',
        'type' => 'per_person',
        'amount' => '0.00',
      ),
      28 => 
      array (
        'member' => '0',
        'type' => 'per_person',
        'amount' => '0.00',
      ),
      29 => 
      array (
        'member' => '0',
        'type' => 'per_person',
        'amount' => '0.00',
      ),
      30 => 
      array (
        'member' => '0',
        'type' => 'per_person',
        'amount' => '0.00',
      ),
    ),
    'discountcode' => 
    array (
      0 => '3',
      1 => '4',
    ),
    'field' => 
    array (
      1 => 
      array (
        'showed' => '-1',
        'required' => '0',
        'group_behave' => '2',
      ),
      2 => 
      array (
        'showed' => '-1',
        'required' => '1',
        'group_behave' => '3',
      ),
      3 => 
      array (
        'showed' => '-1',
        'required' => '1',
        'group_behave' => '3',
      ),
      13 => 
      array (
        'showed' => '-1',
        'required' => '1',
        'group_behave' => '1',
      ),
      12 => 
      array (
        'showed' => '-1',
        'required' => '1',
        'group_behave' => '1',
      ),
      4 => 
      array (
        'showed' => '-1',
        'required' => '0',
        'group_behave' => '1',
      ),
      5 => 
      array (
        'showed' => '-1',
        'required' => '0',
        'group_behave' => '1',
      ),
      6 => 
      array (
        'showed' => '-1',
        'required' => '1',
        'group_behave' => '3',
      ),
      7 => 
      array (
        'showed' => '-1',
        'required' => '0',
        'group_behave' => '3',
      ),
      8 => 
      array (
        'showed' => '-1',
        'required' => '0',
        'group_behave' => '1',
      ),
      9 => 
      array (
        'showed' => '-1',
        'required' => '0',
        'group_behave' => '2',
      ),
      10 => 
      array (
        'showed' => '-1',
        'required' => '1',
        'group_behave' => '3',
      ),
      11 => 
      array (
        'showed' => '-1',
        'required' => '0',
        'group_behave' => '3',
      ),
      21 => 
      array (
        'showed' => '-1',
        'required' => '0',
      ),
      20 => 
      array (
        'showed' => '-1',
        'required' => '0',
        'group_behave' => '1',
      ),
      17 => 
      array (
        'showed' => '-1',
        'required' => '0',
        'group_behave' => '1',
      ),
      27 => 
      array (
        'showed' => '-1',
        'required' => '0',
        'group_behave' => '1',
      ),
      32 => 
      array (
        'showed' => '-1',
        'required' => '0',
        'group_behave' => '1',
      ),
      33 => 
      array (
        'showed' => '-1',
        'required' => '0',
        'group_behave' => '1',
      ),
      34 => 
      array (
        'showed' => '-1',
        'required' => '0',
        'group_behave' => '2',
      ),
      42 => 
      array (
        'showed' => '-1',
        'required' => '0',
      ),
      38 => 
      array (
        'showed' => '-1',
        'required' => '0',
        'group_behave' => '1',
      ),
    ),
  ),
  'articlesection' => '',
  'articlecategory' => '',
  'option' => 'com_dtregister',
  'controller' => 'event',
  'task' => 'save',
);
$data = $data['data'];
	  prd($eventTable->validDateChange($data));
	  //prd($eventTable->is_anyregistration($oldrepetitions));
  }
  
  function testplugin() {
	global $mainframe;
	//require_once( JPATH_BASE .  '/components/com_community/libraries/core.php');
	$user = $this->getModel('user')->table;
	$user->load(431);
	
	JPluginHelper::importPlugin( 'dtregister' );



    $mainframe->triggerEvent( 'OnDtregisterRegistration',array($user));
	$mainframe->triggerEvent( 'OnDtregisterUpdate',array($user));
	$mainframe->triggerEvent( 'OnDtregsiterDelete',array($user));
}

function testeventloadold() {
	$eventTable = $this->getModel('event')->table;
	  $eventTable->load_old(699);
	  
	  prd($eventTable);
}

function testeventload() {
	$eventTable = $this->getModel('event')->table;
	  $eventTable->load(699);
	  
	  prd($eventTable);
}

function testuser() {
	
	$users = array (
  'User' => 
  array (
    0 => 
    array (
      'eventId' => '3',
      'memtot' => 1,
      'type' => 'I',
      'fields' => 
      array (
        2 => '',
        3 => '',
        13 => '2',
        6 => 'city',
        8 => '',
        9 => '190',
        7 => '',
        10 => '',
        11 => '',
        18 => '',
      ),
      'discount_code_id' => 0,
      'fee' => 
      array (
        'basefee' => 5,
        'memberdiscount' => 0,
        'latefee' => 0,
        'birddiscount' => NULL,
        'discountcodefee' => NULL,
        'customfee' => -2.5,
        'tax' => 0,
        'currentfee' => 2.5,
        'fee' => 2.5,
        'paid_fee' => 2.5,
        'payment_method' => NULL,
        'changefee' => 0,
        'cancelfee' => 0,
        'fieldfee' => 
        array (
          16 => 
          array (
            'fee' => 0,
          ),
          17 => 
          array (
            'fee' => 0,
          ),
          13 => 
          array (
            'fee' => -2.5,
          ),
          21 => 
          array (
            'fee' => 0,
          ),
          19 => 
          array (
            'fee' => 0,
          ),
          24 => 
          array (
            'fee' => 0,
          ),
        ),
        'paid_amount' => '2.5',
        'paying_amount' => '2.5',
      ),
      'user_id' => '44',
      'confirmNum' => 'DT-7508062',
      'confirmed' => 1,
    ),
    1 => 
    array (
      'eventId' => '30',
      'memtot' => 1,
      'type' => 'I',
      'fields' => 
      array (
        2 => '',
        3 => '',
        6 => 'city',
        8 => '',
        9 => '190',
        7 => '',
        10 => '',
        11 => '',
        24 => '2',
      ),
      'discount_code_id' => 0,
      'fee' => 
      array (
        'basefee' => 395,
        'memberdiscount' => 0,
        'latefee' => 0,
        'birddiscount' => 25,
        'discountcodefee' => NULL,
        'customfee' => -150,
        'tax' => 0,
        'currentfee' => 220,
        'fee' => 220,
        'paid_fee' => 220,
        'payment_method' => NULL,
        'changefee' => 0,
        'cancelfee' => 0,
        'fieldfee' => 
        array (
          21 => 
          array (
            'fee' => 0,
          ),
          19 => 
          array (
            'fee' => 0,
          ),
          16 => 
          array (
            'fee' => 0,
          ),
          17 => 
          array (
            'fee' => 0,
          ),
          13 => 
          array (
            'fee' => 0,
          ),
          24 => 
          array (
            'fee' => -150,
          ),
        ),
        'paid_amount' => '220',
        'paying_amount' => '220',
      ),
      'user_id' => '44',
      'confirmNum' => 'DT-5225666',
      'confirmed' => 1,
    ),
  ),
  'payment' => 
  array (
    'method' => '2',
  ),
);

   $user = $this->getModel('user')->table;
   
   $user->registerall($users,2);

}

}

?>