<?php

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

class DtregisterControllerEvent extends DtrController {

	var $name ='event';

	function __construct($config = array()){

		  parent::__construct($config);

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

		  $this->view->setModel($this->getModel('event'),true);

		  $this->view->setModel($this->getModel( 'location' ));

		  $this->view->setModel($this->getModel( 'user' ));

		  $this->view->setModel($this->getModel( 'member' ));

		  $this->view->setModel($this->getModel( 'field' ));

		  $this->view->setModel($this->getModel( 'fieldtype' ));

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

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

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

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

		  $this->registerTask( 'new', 'add' );

		  $this->registerTask( 'category', 'events' );

		  $this->registerDefaultTask("events");

	}

	function print_session(){	    

		echo "<pre>";

		print_r($_SESSION);

		die;

	}

	function checkpermission(){

		true;	

	}

	function events(){

		$zip = JRequest::getVar('zip','');

		$distance = JRequest::getVar('distance','');

		/*if($zip != "" && $distance != "") {

			$temp = $this->getlnglat();

			if($temp['success']) {    

				$this->view->assign('location_point',$temp['location']);

			} else {

			    $this->view->assign('error',$temp['error']);

			}

		}*/

	    $this->view->setModel($this->getModel('category'));

	    $this->view->setLayout('list');

		$this->view->display();

	}

	function cut_off(){

	   $this->display();

	}

	function check_waiting() {

		$eventId = JRequest::getInt('eventId',DT_Session::get('Setting.eventId'));

	 // prd($_SESSION);

	    $event = & DtrTable::getInstance('Event','Table');

	    $event->load($eventId );

		$event->registered = $event->getTotalregistered($event->slabId);

		$registering = $event->count_registering();

		$total = $event->registered + $registering; 

		if($event->max_registrations == "0" || $event->max_registrations > $total) {

			echo "regular";

		} else if($event->max_registrations <= $total && $event->waiting_list > 0) {

			echo "waiting";

		} else {

			echo "full";

		}

		die;

		echo $event->is_waiting_check()?"false":"true";

		die;

		

	}

	function register(){

	   

	   global $mainframe,$xhtml,$Itemid,$now;	   

	   global $disable_cart;

		

	    if(DT_Session::get('Setting')){

			DT_Session::set('Setting');

			DT_Session::set('Setting.process','register');

		} else {
 
      			DT_Session::set('Setting');

		}

		if($disable_cart ==0 ) {

			DT_Session::clear('register.User');

		}

	   DT_Session::set('Setting.reg_status','start');

	   $type = JRequest::getVar('type');

	   $eventId = JRequest::getInt('eventId',0);

	   $tEvent = $this->getModel('event')->table;

	   $tUser = $this->getModel('user')->table;

	   $tEvent->load($eventId);

	   $tEvent->is_registerable($tUser);

	   if($type=="options"){
		   
       // sleep_till_session_written();
    $mainframe->redirect(JRoute::_("index.php?option=com_dtregister&controller=event&task=options&Itemid=".$Itemid."&eventId=".$eventId,$xhtml));
 $mainframe->close();
 
	   }else{
		 
		//sleep_till_session_written();
	       $mainframe->redirect(JRoute::_("index.php?option=com_dtregister&controller=event&task=options&Itemid=".$Itemid."&eventId=".$eventId,$xhtml));
  $mainframe->close();
  die;
	   }

	   $event = $this->getModel('event')->table;

	   $event->load($eventId);

	   $this->view->assign('header_eventId',$eventId);

	}

	function options(){

	  global $mainframe,$Itemid,$xhtml;

	  $eventId = JRequest::getInt('eventId',0);

	  DT_Session::set('Setting.eventId', $eventId);

	  DT_Session::set('Setting.process', 'register');

	  $tEvent = $this->getModel('event')->table;

	  $tEvent->load($eventId);

	  $my = &JFactory::getUser();

	  $tUser = $this->getModel('user')->table;

	  $tEvent->is_registerable($tUser);

	   DT_Session::set('Setting.User.eventId',$eventId);

	   $registered = $tEvent->getTotalregistered($tEvent->slabId);

	   if (isset($tEvent->max_registrations) && $tEvent->max_registrations > 0) {

		if($tEvent->max_registrations <= $registered){

		   	if($tEvent->waiting_list){

			     DT_Session::set('Setting.User.status',-2);

			}

		}

	    }

	   if($tEvent->registration_type=="individual"){

		     if(isset($_REQUEST['back']) &&  DT_Session::get('Setting.Editindex')=== false){

			    $mainframe->redirect(JRoute::_('index.php?option=com_dtregister&Itemid='.$Itemid,$xhtml));

			 }else{
 $mainframe->redirect(JRoute::_('index.php?option=com_dtregister&Itemid='.$Itemid.'&eventId='.$eventId.'&controller=event&task=individualRegister',$xhtml));

			 }

	   }elseif($tEvent->registration_type=="group"){

		   if($tEvent->group_registration_type !="detail"){

			  $mainframe->redirect(JRoute::_('index.php?option=com_dtregister&controller=event&task=groupNum&Itemid='.$Itemid,$xhtml));

		   }
 $mainframe->redirect(JRoute::_('index.php?option=com_dtregister&Itemid='.$Itemid.'&eventId='.$eventId.'&controller=event&task=memberdata',$xhtml));

	   }

	   $this->view->assign('header_eventId',$eventId);

	   $this->view->assign('tEvent',$tEvent);

	   $this->view->setLayout('options');

	   $this->view->display();

	}

	function confirm(){

//		 pr($_SESSION);

		global $mainframe,$Itemid,$xhtml,$member_confirmnum,$partial_payment_group_reg;

		if(false === DT_Session::get('Setting.eventId') || DT_Session::get('Setting.eventId') == 0){

		   $mainframe->redirect(JRoute::_("index.php?option=com_dtregister&Itemid=".$Itemid,$xhtml));

	   }

	   global $Itemid,$mainframe,$xhtml_url,$offline_zero_credit,$paymentmethod;

	   $this->view->setModel($this->getModel( 'field' ));

	   $this->view->setModel($this->getModel( 'fieldtype' ));

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

	   $my = &JFactory::getUser();

	   $eventId = JRequest::getInt('eventId',DT_Session::get('Setting.eventId'));

	   $event = & DtrTable::getInstance('Event','Table');

	   $event->load($eventId );

	   if($step ==="confirm"){

			// pr(DT_Session::get('register.User')); prd('exit here');

		   $memtot = DT_Session::get('Setting.User.memtot');

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

           if($event->partial_payment > 0 && $partial_payment_group_reg == 'eachmember') {

				if(DT_Session::get('Setting.User.type')=='G'){ 

					if( $memtot > 1 ){

						$paying_amount *= $memtot;	

					}

				}

		   }

		   $TableUser =& DtrTable::getInstance('Duser','Table');

	       $TableUser->create(DT_Session::get('Setting.User'));

	       $feeObj = new DT_Fee($event,$TableUser);

	       $feeObj->getFee($my->id);

	       $fee_arr = DTrCommon::objectToArray($feeObj->getObjectdata());
		   
		   $fee_arr['paid_amount'] = $paying_amount;
		   $fee_arr['paying_amount'] = $paying_amount;

	       DT_Session::set('Setting.User.fee',$fee_arr);

		   if($my->id){

			    DT_Session::set('Setting.User.user_id', $my->id);  

		   }

		   $tableUser = $this->getModel('user')->table;

		   if(DT_Session::get('Setting.User.type')=='G' &&  $member_confirmnum){

			   $members = DT_Session::get('Setting.User.members');

			   $i = 1;

			   if($members)

			   foreach($members as $key => $member){

				   $confirmnum = $tableUser->generateconfirmNum($event);

				   DT_Session::set('Setting.User.members.'.$key.'.confirmnum',$confirmnum );

				   if($i == 1) {

					  DT_Session::set('Setting.User.confirmNum',$confirmnum);

				   }

				   $i++;

			   }

		   } else {

				  DT_Session::set('Setting.User.confirmNum',$tableUser->generateconfirmNum($event));

		   }

		   $event->add_registering($memtot);

		   $status = DT_Session::get('Setting.User.status');

		   $cart = new DT_Cart();

		   $cart_amount = $cart->getAmount();

		   if($status == -2){ // free or waiting $paying_amount <= 0 

			   if($status == -2){

				   DT_Session::set('Setting.User.fee.paid_amount',0);

		           DT_Session::set('Setting.User.fee.paying_amount',0);

				   $task = "waiting_msg";

			   }else{

				   $task = "freethanks";

			   }

			    if($cart_amount > 0 || ($offline_zero_credit && in_array('offline_payment',$paymentmethod ))) {

					$users = DT_Session::get('register.User');

					$users[] = DT_Session::get('Setting.User');

					DT_Session::set('register.User',$users);

					DT_Session::clear('Setting.User');

					sleep_till_session_written();

 		$mainframe->redirect(JRoute::_("index.php?option=com_dtregister&controller=event&task=viewCart&Itemid=".$Itemid,$xhtml));

			   } else {

			   		$tableUser->register(DT_Session::get('Setting.User'));

			   		DT_Session::set('Setting.User.userId',$tableUser->userId);

					sleep_till_session_written();

 		$mainframe->redirect(JRoute::_("index.php?option=com_dtregister&controller=message&task=$task&Itemid=".$Itemid,$xhtml));
die;
			   }

		   }else{

			   $users = DT_Session::get('register.User');

			   $index = $_REQUEST['Index'];

			   DT_Session::set('Setting.User.confirmed',1);

			   DT_Session::set('Setting.User.Index',$index);

			   $users[$index] = DT_Session::get('Setting.User');

			   DT_Session::set('register.User',$users);
 
			  // pr(count($users));

			   //prd($users);

			   DT_Session::clear('Setting.User');

			   DT_Session::set('Setting.reg_status','confirmed');

			   sleep_till_session_written();

			   $mainframe->redirect(JRoute::_("index.php?option=com_dtregister&controller=event&task=viewCart&Itemid=".$Itemid,$xhtml));

		   }

	   }

	    if(DT_Session::get('Setting.User') === false) {

	      $this->load_from_last_reg();

	   } 

	   $userdata = DT_Session::get('Setting.User');

	   DT_Session::set('Setting.User.eventId', $eventId);

	   $fieldtype =$this->getModel( 'fieldtype' );

	   $viewMemFields = "";

	   if(DT_Session::get('Setting.User.type')=='G'){

	      $back = JRoute::_("index.php?option=com_dtregister&Itemid=".$Itemid."&eventId=".$eventId."&controller=event&task=billinginfo", $xhtml_url);

		  $type = 'B';

		   $members = DT_Session::get('Setting.User.members');

		   if($members)

		   foreach($members as $key => $member){

		      $viewMemFields .= "<div style='clear:both'><u>".JText::_( 'DT_MEMBER' ).($key+1)." </u></div>";

			  if(DT_Session::get('Setting.User.members.'.$key) != false){ 

			  	  $member_data = DT_Session::get('Setting.User.members.'.$key);

			  } else {

			  	  $member_data = DT_Session::get('register.User.0.members.'.$key);

			  }

		      $viewMemFields .= $event->viewFields('M',$member_data,false,'frmcart',false);

		   }

	   }else{

	      $back = JRoute::_("index.php?option=com_dtregister&Itemid=".$Itemid."&eventId=".$eventId."&controller=event&task=individualRegister", $xhtml_url);

		  $type = 'I';

	   }

	   $TableUser =& DtrTable::getInstance('Duser','Table');

	   $TableUser->create($userdata);

	   $feeObj = new DT_Fee($event,$TableUser);

	   $feeObj->getFee($my->id);

	   if($event->is_waiting()){

		  DT_Session::set('Setting.User.status',-2);

		  $this->view->assign('paying_amount',0);

	   }else{

		   $this->view->assign('paying_amount',$feeObj->paid_fee);

	   }

	   // pr($feeObj->getObjectdata());

	   DT_Session::set('Setting.User.fee',DTrCommon::objectToArray($feeObj->getObjectdata()));

	   $this->view->assign('currentfee',$feeObj->currentfee);

	   $this->view->assign('back',$back);

	   $this->view->assign('eventId',$eventId);

	   $this->view->assign('header_eventId',$eventId);

	   //$event->load($eventId);

	   $this->view->assign( 'viewFields' ,$event->viewFields($type,$userdata,false,'frmcart',false));

	   $this->view->assign( 'viewMemFields',$viewMemFields);

	   $this->view->assign( 'event',$event);

	   $this->view->setLayout('confirm');

	   if(isset($_REQUEST['Index'])) {

	       $this->view->assign('Index',$_REQUEST['Index']);

	   } else {

	   	   $this->set_User_index();

	   }

	   $this->view->display();

	   pr(DT_Session::get('Setting.User'));

	  // $db = &JFactory::getDBO();

	  // $db->profileData = array();

	}

	function confirmsave() {

	    global $mainframe,$Itemid,$xhtml,$member_confirmnum,$partial_payment_group_reg;

		if(false === DT_Session::get('Setting.eventId') || DT_Session::get('Setting.eventId') == 0){

		   $mainframe->redirect(JRoute::_("index.php?option=com_dtregister&Itemid=".$Itemid,$xhtml));

	   }

	   global $Itemid,$mainframe,$xhtml_url,$offline_zero_credit,$paymentmethod;

	   $this->view->setModel($this->getModel( 'field' ));

	   $this->view->setModel($this->getModel( 'fieldtype' ));

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

	   $my = &JFactory::getUser();

	   $eventId = JRequest::getInt('eventId',DT_Session::get('Setting.eventId'));

	   $event = & DtrTable::getInstance('Event','Table');

	   $event->load($eventId );

	   if(isset($_REQUEST['Field'])){

	     DT_Session::set('Setting.User.fields', $_REQUEST['Field']);

		 if(isset($_REQUEST['username'])){

		   DT_Session::set('Setting.User.username', $_REQUEST['username']);

		   DT_Session::set('Setting.User.password', $_REQUEST['password']);

		 }

		 if(DT_Session::get('Setting.User.fee')) {

		 	DT_Session::clear('Setting.User.fee');

			$data = DT_Session::get('register.User');

	        $data = end($data);

			if(isset($data['memtot']) && $data['memtot'] != "" ) {

			DT_Session::set('Setting.User.memtot',$data['memtot']);

			}

			if(isset($data['type']) && $data['type'] != "" ) {

			DT_Session::set('Setting.User.type',$data['type']);

			}

			if(DT_Session::get('Setting.User.eventId') ==  false) {

				DT_Session::set('Setting.User.eventId',$data['eventId']);

		   }

		 }

		if(isset($_REQUEST['discount_code']) && $_REQUEST['discount_code'] != ""){

			$memtot = DT_Session::get('Setting.User.memtot');

	   			$reg_type = DT_Session::get('Setting.User.type');

	   			$type = $reg_type == 'I'?'I':'B';

				$discount_code_id = $event->validate_code($_REQUEST['discount_code'],NULL,$type,$memtot,$reg_type); 

			//$discount_code_id = $event->validate_code($_REQUEST['discount_code']); 

			if($discount_code_id !== false){

			   DT_Session::set('Setting.User.discount_code_id', $discount_code_id );

			}else{

			   DT_Session::set('Setting.User.discount_code_id', false );

			   if(!isset($event->TableEventdiscountcode->TableDiscountcode->error)){

						$event->TableEventdiscountcode->TableDiscountcode->error = 'Invalid Code.';

					}

			  $this->view->assign('discountCodeError',$event->TableEventdiscountcode->TableDiscountcode->error );

			}

		}

		if(isset($_REQUEST['Tax_exemption']) && $_REQUEST['Tax_exemption'] == 1) {

			DT_Session::set('Setting.User.tax_exemption' ,1);

			if(isset($_REQUEST['Tax_exemption_code'])) {

			  DT_Session::set('Setting.User.tax_exemption_code' ,$_REQUEST['Tax_exemption_code']);

			}

		}

		$userdata = DT_Session::get('Setting.User');

	   }

	    if(isset($_REQUEST['mailchimp_register'])) {

	      DT_Session::set('Setting.User.mailchimp_register', $_REQUEST['mailchimp_register']);

	   }

	   $userdata = DT_Session::get('Setting.User');

	   $TableUser =& DtrTable::getInstance('Duser','Table');

	   $TableUser->create($userdata);

	  // pr($userdata);

	   $feeObj = new DT_Fee($event,$TableUser);

	   $feeObj->getFee($my->id);

	    DT_Session::set('Setting.User.fee',DTrCommon::objectToArray($feeObj->getObjectdata()));

		sleep_till_session_written();

	   $mainframe->redirect(JRoute::_('index.php?option=com_dtregister&controller=event&task=confirm&Itemid='.$Itemid,$xhtml));

	   $mainframe->redirect(JRoute::_('index.php?option=com_dtregister&controller=event&task=confirm&Itemid='.$Itemid,$xhtml));

	}

	function viewCart(){

		global $mainframe,$Itemid,$disable_cart,$minimum_cart_event;

		global $xhtml;

		if(false === DT_Session::get('Setting.eventId') || DT_Session::get('Setting.eventId') == 0){

		   if(DT_Session::get('register.User') === false) {

			   $mainframe->redirect(JRoute::_("index.php?option=com_dtregister&Itemid=".$Itemid,$xhtml));

		   }

	   }

	   $my = &JFactory::getUser();

	   $event = & DtrTable::getInstance('Event','Table');

	   $TableUser =& DtrTable::getInstance('Duser','Table');

	   foreach(DT_Session::get('register.User') as $key => $userdata) {

		  $TableUser->create($userdata);

		  $event->load($userdata['eventId'] );

		// pr($userdata);

		 $feeObj = new DT_Fee($event,$TableUser);

		 $feeObj->getFee($my->id);

		 $new_fee = DTrCommon::objectToArray($feeObj->getObjectdata());

		if($new_fee['paid_fee'] != $userdata['fee']['paid_fee'] || $userdata['fee']['paying_amount'] > $userdata['fee']['paid_fee']) {

			 $paid_amount = $userdata['fee']['paid_amount'];

			 $paying_amount = $userdata['fee']['paying_amount'];

			 $new_fee['paying_amount'] = $paying_amount;

			 $new_fee['paid_amount'] = $paid_amount;

			 DT_Session::set('register.User.'.$key.'.fee',$new_fee);

		}

	   }

	   global $mainframe,$Itemid,$disable_cart;

	   if ($disable_cart == 0) {

		    sleep_till_session_written();

		    if(isset($_REQUEST['back'])) {

	 $mainframe->redirect(JRoute::_('index.php?option=com_dtregister&controller=event&task=confirm&back=1&Itemid='.$Itemid,$xhtml));

			} else {
			   $mainframe->redirect(JRoute::_('index.php?option=com_dtregister&controller=payment&task=methods&Itemid='.$Itemid,$xhtml));

			}

	   }	

	   $this->view->setLayout('viewcart');

	   $this->view->display();

	}

	function memberdata(){

	   global $mainframe,$Itemid,$xhtml;

		if(false === DT_Session::get('Setting.eventId') || DT_Session::get('Setting.eventId') == 0){

		   $mainframe->redirect(JRoute::_("index.php?option=com_dtregister&Itemid=".$Itemid,$xhtml));

	   }

	   if(DT_Session::get('Setting.User.type') === false) {

	   		DT_Session::set('Setting.User.type','G');

	   }

	   $this->view->setModel($this->getModel( 'field' ));

	   $this->view->setModel($this->getModel( 'fieldtype' ));

	   $field = $this->getModel( 'field' )->table;

	   $eventId = JRequest::getInt('eventId',DT_Session::get('Setting.eventId'));

	   $fieldtype =$this->getModel( 'fieldtype' );

	   $event = $this->getModel('event')->table;

	   $event->load($eventId);

	   if(isset($_POST['member_data'])){

	       DT_Session::set('Setting.Member.fields', $_REQUEST['Field']);

	       $event->addUsageToSession($_REQUEST['Field']);

		   if(isset($_REQUEST['discount_code']) && $_REQUEST['discount_code'] != ""){

				$memtot = DT_Session::get('Setting.User.memtot');

	   			$reg_type = DT_Session::get('Setting.User.type');

	   			$type = 'M';

				$discount_code_id = $event->validate_code($_REQUEST['discount_code'],NULL,$type,$memtot,$reg_type); 

				if($discount_code_id !== false){

			   		DT_Session::set('Setting.Member.discount_code_id', $discount_code_id );

				}else{

			   		DT_Session::set('Setting.Member.discount_code_id', false );

					if(!isset($event->TableEventdiscountcode->TableDiscountcode->error)){

						$event->TableEventdiscountcode->TableDiscountcode->error = 'Invalid Code.';

					}

			 		$this->view->assign('discountCodeError',$event->TableEventdiscountcode->TableDiscountcode->error );

				}

		}

		$members = DT_Session::get('Setting.User.members')?DT_Session::get('Setting.User.members'):array();

		$index = $_REQUEST['Index'];

		DT_Session::set('Setting.Member.Index',$index);

		DT_Session::clear('Setting.Member.Add');

		$members[$index] = DT_Session::get('Setting.Member');

		DT_Session::set('Setting.User.members',$members);

		DT_Session::clear('Setting.Member');

	   /* if(!(($memberIndex+1) < DT_Session::get('Setting.User.memtot'))){

		  $mainframe->redirect('index.php?option=com_dtregister&controller=event&task=billinginfo&Itemid='.$Itemid,$xhtml));

	    }

	    $memberIndex++; */

		 if( $_REQUEST['flow'] == 'memberdata') {

	     	 $task = 'memberdata';

		 } else {

		 		$task = 'billinginfo'; 

		 }

		 global $xhtml_url;

		 // prd(JRoute::_('index.php?option=com_dtregister&controller=event&task='.$task.'&Itemid='.$Itemid,$xhtml_url));

		 sleep_till_session_written();

		    $mainframe->redirect(JRoute::_('index.php?option=com_dtregister&eventid='.$eventId.'&controller=event&task='.$task.'&Itemid='.$Itemid,$xhtml_url));

			exit;

	   }

	   if(DT_Session::get('Setting.User.memtot')) {

		   if(DT_Session::get('Setting.User.members')) {

			   if(DT_Session::get('Setting.Member.Index') !== false) {

		          $memtot = count(DT_Session::get('Setting.User.members')); 

			   } else {

			      $memtot = count(DT_Session::get('Setting.User.members')) + 1;

			   }

		   } else {

		       $memtot = 1;

		   }

	   }  else {

	   	  $memtot = 1;

	   }

	   if(DT_Session::get('Setting.Member.Index') !== false) {

			$index = DT_Session::get('Setting.Member.Index') + 1;

	   } else {

		   if(DT_Session::get('Setting.Member.nextIndex'))  {

		      $index = DT_Session::get('Setting.Member.nextIndex') +1;

			  DT_Session::clear('Setting.Member.nextIndex');

		   } else {

	   		 $index = $memtot;

		   }

	   }

	   if($index > 1) {

	     $back =  JRoute::_("index.php?option=com_dtregister&Itemid=".$Itemid."&eventId=".$eventId."&controller=event&task=editlastmember");

	   } else {

	   	  $back = JRoute::_("index.php?option=com_dtregister&Itemid=".$Itemid."&eventId=".$eventId."&controller=event&task=options&back=1");

	   }

	   DT_Session::set('Setting.User.memtot',$memtot);

	   $this->view->assign( 'form' ,$event->form('M',(array)DT_Session::get('Setting.Member'),false,'frmcart',false,$memtot));

	   $this->view->assign('memtot',$memtot);

	   $this->view->setLayout('memberdata');

	   $this->view->assign('header_eventId',$eventId);

	   $this->view->assign('memberIndex',$index);

	   $this->view->assign('tEvent',$event);

	   $this->view->assign('back',$back);

	   $this->view->display();

	}

	function add_member() {

		global $mainframe,$Itemid;

		DT_Session::clear('Setting.Member' );

		//DT_Session::set('Setting.Member.Index' ,(count(DT_Session::get('Setting.User.members')) + 1) );

		DT_Session::set('Setting.Member.Add','yes' );

		//print_r(max(array_keys(DT_Session::get('Setting.User.members'))));

		$next_index = max(array_keys(DT_Session::get('Setting.User.members')));

		$next_index++;

		//echo $next_index;

		DT_Session::set('Setting.Member.nextIndex',$next_index);

		sleep_till_session_written();

		$mainframe->redirect(JRoute::_('index.php?option=com_dtregister&controller=event&task=memberdata&Itemid='.$Itemid,$xhtml));

		exit();

	}

	function member_cancel() {

		global $mainframe,$Itemid;

		DT_Session::clear('Setting.Member' );

		$memtot = count(DT_Session::get('Setting.User.members'));

		DT_Session::set('Setting.User.memtot',$memtot);

		//DT_Session::set('Setting.Member.Index' ,(count(DT_Session::get('Setting.User.members')) + 1) );

		sleep_till_session_written();

		$mainframe->redirect(JRoute::_('index.php?option=com_dtregister&controller=event&task=billinginfo&Itemid='.$Itemid,$xhtml));

	}

	function billinginfo(){

	   global $mainframe,$Itemid,$xhtml;

		if(false === DT_Session::get('Setting.eventId') || DT_Session::get('Setting.eventId') == 0){

		   $mainframe->redirect(JRoute::_("index.php?option=com_dtregister&Itemid=".$Itemid,$xhtml));

	   }

	   $eventId = JRequest::getInt('eventId',DT_Session::get('Setting.User.eventId'));

	   $fieldtype =$this->getModel( 'fieldtype' );

	   $event = $this->getModel('event')->table;

	   $event->load($eventId);

	   $this->loadprofile();

	   $memtot = DT_Session::get('Setting.User.memtot');

	   $this->view->assign( 'form' ,$event->form('B',(array)DT_Session::get('Setting.User'),false,'frmcart',false,$memtot));

	   // pr($_SESSION['DTregister']);

	   $viewMemFields = "";

	   $member_list = array();

	    if(DT_Session::get('Setting.User.type')=='G'){

	      $type = 'B';

		   $members = DT_Session::get('Setting.User.members');

		   if($members) {

			 foreach($members as $key => $member){

				$member_list[$key+1] = $event->viewFields_array('M',$member,false,'frmcart',false);

			 }

		   }

	   }

	   $this->view->assign('member_list',$member_list);

	   $this->view->setLayout('individualRegister');

	   if($event->group_registration_type !="detail"){

		    $back =  JRoute::_('index.php?option=com_dtregister&Itemid='.$Itemid.'&eventId='.$eventId.'&controller=event&task=groupNum');

	   }else{

		    $back = JRoute::_("index.php?option=com_dtregister&Itemid=".$Itemid."&controller=event&task=editlastmember");

	   }

	   $this->view->assign('pageTile',JText::_( 'DT_BILLING_INFORMATION'));

	   $this->view->assign('task','confirmsave');

	   $this->view->assign('back',$back);

	   $this->view->assign('tEvent',$event);

	   $this->view->assign('eventId',$eventId);

	   $this->view->assign('header_eventId',$eventId);

	   $this->set_User_index();

	   $this->view->display();

	}

	function terms(){

		$eventId = JRequest::getInt('eventId',0);

		$event = $this->getModel('event')->table;

	    $event->load($eventId);

		if($event->terms_conditions_set == 1){

			$terms = $event->terms_conditions_msg;

		}else{

			$terms = $this->config->getGlobal('terms_conditions_msg','');

		}

		$this->view->assign('terms',$terms);

		$this->view->setLayout('terms');

		$this->view->display();

	}

	function cartRemove(){

	   global $mainframe,$Itemid;

	   $userIndex = JRequest::getVar('userIndex');

	   // pr($userIndex);

	   DT_Session::clear('register.User.'.$userIndex);

	   DT_Session::set('Setting.User',DT_Session::get('Setting.User'));

	   foreach(DT_Session::get('Setting.User') as $key => $user) {

	   		DT_Session::set('Setting.User.'.$key.".Index" ,$key);

	   }

	   // prd(DT_Session::get('register.User'));

	   // prd($_SESSION);

	    if(count(DT_Session::get('register.User')) < 1) {

	   		DT_Session::clearAll('');

	   }

	   sleep_till_session_written();

	   $mainframe->redirect(JRoute::_('index.php?option=com_dtregister&controller=event&task=viewCart&Itemid='.$Itemid,$xhtml));	   

	}

	function remove_member(){

	   global $mainframe,$Itemid;

	   $index = JRequest::getVar('index');

	   // pr($userIndex);

	   DT_Session::clear('Setting.User.members.'.$index );

	   // re arrange key index;

	   DT_Session::set('Setting.User.members',DT_Session::get('Setting.User.members'));

	   foreach(DT_Session::get('Setting.User.members') as $key => $member) {

	   		DT_Session::set('Setting.User.members.'.$key.".Index" ,$key);

	   }

	   DT_Session::set('Setting.User.memtot',count(DT_Session::get('Setting.User.members')));

	  sleep_till_session_written();

	   $mainframe->redirect(JRoute::_('index.php?option=com_dtregister&controller=event&task=billinginfo&Itemid='.$Itemid,$xhtml));	   

	}

	function edit_member(){

	   global $mainframe,$Itemid;

	   $index = JRequest::getVar('index');

	   // pr($userIndex);

	   $memberdata = DT_Session::get('Setting.User.members.'.$index );

	   DT_Session::set('Setting.Member',$memberdata);

	   sleep_till_session_written();

	   $mainframe->redirect(JRoute::_('index.php?option=com_dtregister&controller=event&task=memberdata&Itemid='.$Itemid,$xhtml));	   

	}

	function editlastmember() {

		global $mainframe,$Itemid;

	    //$index = end(DT_Session::get('Setting.User.members'));

	   // pr($userIndex);

	   $memberdata = end(DT_Session::get('Setting.User.members'));

	   DT_Session::set('Setting.Member',$memberdata);

	   sleep_till_session_written();

	   $mainframe->redirect(JRoute::_('index.php?option=com_dtregister&controller=event&task=memberdata&Itemid='.$Itemid,$xhtml));

	}

	function edit(){

	   global $mainframe,$Itemid;

	   $userIndex = JRequest::getVar('userIndex');

	   // pr($userIndex);

	   $userdata = DT_Session::get('register.User.'.$userIndex);

	   if($userdata['type'] == 'G') {

	       $task = "billinginfo";

	   } else {

	   	   $task = "individualRegister";

	   }

	    DT_Session::set('Setting.User',$userdata);

		DT_Session::set('Setting.Editindex',$userIndex);

		DT_Session::set('Setting.eventId', $userdata['eventId']);

		sleep_till_session_written();

	   $mainframe->redirect(JRoute::_('index.php?option=com_dtregister&controller=event&task='.$task.'&Itemid='.$Itemid,$xhtml));	   

	}

	function loadprofile(){

	   $user = JFactory::getUser();

	   $muser = $this->getModel('user');

       $tuser = $muser->table;

       $profile = $tuser->TableJUser; 

       $user_id = $user->id;

       $userdata = $profile->getProfile($user_id);

	   if (is_array($userdata) && count($userdata) && $user_id) { 

		 foreach($userdata as $field_id => $val){

			 if($field_id != "" && isset($userdata[$field_id])){

				   $currentval = DT_Session::get('Setting.User.fields.'.$field_id);

				   if($currentval === false){

					  DT_Session::set('Setting.User.fields.'.$field_id,$userdata[$field_id]);

				   }

			 }

		 } 

	   } else {

	   		$this->load_from_first_reg();

	   }

	}

	function individualRegister(){

	   global $mainframe,$Itemid,$xhtml;

	   $eventId = JRequest::getInt('eventId');

	   if (isset($eventId) && $eventId > 0) {

	    	DT_Session::set('Setting.eventId', $eventId);

			DT_Session::set('Setting.process', 'register');

	   } else {

	   	   $eventId = DT_Session::get('Setting.eventId');

	   }

	   if(false === DT_Session::get('Setting.eventId') || DT_Session::get('Setting.eventId') == 0){

		   $mainframe->redirect(JRoute::_("index.php?option=com_dtregister&Itemid=".$Itemid,$xhtml));

	   }

	   $tEvent = $this->getModel('event')->table;

	   $tUser = $this->getModel('user')->table;

	   $tEvent->load($eventId);

	   $tEvent->is_registerable($tUser);  

		if(false === DT_Session::get('Setting.eventId')){

		   $mainframe->redirect(JRoute::_("index.php?option=com_dtregister&Itemid=".$Itemid,$xhtml));

	   }

	   if(DT_Session::get('Setting.User.type') == 'G') {

	   		DT_Session::clear('Setting.User');

			if(DT_Session::get('Setting.Editindex') === false) {

				DT_Session::clear('register');

			}

	   }

	   DT_Session::set('Setting.User.memtot',1);

	   DT_Session::set('Setting.User.type','I');

	   if(DT_Session::get('Setting.User.eventId') ==  false) {

				DT_Session::set('Setting.User.eventId',$eventId);

		   }

	   $this->view->setModel($this->getModel( 'field' ));

	   $this->view->setModel($this->getModel( 'fieldtype' ));

	   $field = $this->getModel( 'field' )->table;

	   $eventId = JRequest::getInt('eventId',DT_Session::get('Setting.User.eventId'));

	   $fieldtype =$this->getModel( 'fieldtype' );

	   $event = $this->getModel('event')->table;

	   $event->load($eventId);

	   $tUser = $this->getModel('user')->table;

	   $event->is_registerable($tUser);	

	   $this->loadprofile();

	   $memtot = DT_Session::get('Setting.User.memtot');

	   $this->view->assign( 'form' ,$event->form('I',(array)DT_Session::get('Setting.User'),false,'frmcart',false,$memtot));

	   $this->view->setLayout('individualRegister');

	  $back =  JRoute::_("index.php?option=com_dtregister&Itemid=".$Itemid."&eventId=".$eventId."&controller=event&task=options&back=1");

	  $this->view->assign('pageTile', JText::_( 'USER_INFORMATION' ));

	  $this->view->assign('task','confirmsave');

	  $this->view->assign('back',$back);

	  $this->view->assign('tEvent',$event);

	  $this->view->assign('eventId',$eventId);

	  $this->view->assign('header_eventId',$eventId);

	  $this->set_User_index();

	  $this->view->display();

//	  sleep_till_session_written();

	}

	function set_User_index() {

	   global $disable_cart;

	   $usertot = 0;

	   if(DT_Session::get('register.User')) {

		 if(DT_Session::get('Setting.User.Index') !== false) {

			$usertot = count(DT_Session::get('register.User')); 

		 } else {

			 if(DT_Session::get('register.User') !== false) {

			  $usertot = count(DT_Session::get('register.User'));

			 } else

			 {

			$usertot = 0;

			 }

		 }

	   }  else {

	   	  $usertot = 0;

	   }

	   if(DT_Session::get('Setting.User.Index') !== false) {

			$index = DT_Session::get('Setting.User.Index');

	   } else {

	   		$index = $usertot;

	   }

	   if($disable_cart == 0) {

		  $index = 0;

	   }

	   $this->view->assign('Index',$index);

	}

	function price_header(){

	$layout = JRequest::getVar('dttmpl','price_header');

	   if(isset($_REQUEST['Field'])){

		   $userdata = DT_Session::get('Setting.User');

		   if(isset($_REQUEST['member_data'])){

			  $memberdata = DT_Session::get('Setting.Member');

	         // DT_Session::set('Setting.Member.fields', $_REQUEST['Field']);

			  $memberdata['fields'] = $_REQUEST['Field'];

			   if(isset($_REQUEST['discount_code']) && $_REQUEST['discount_code'] != ""){

				  $eventId = JRequest::getInt('eventId',DT_Session::get('Setting.eventId'));

				  $event = $this->getModel('event')->table;

	              $event->load($eventId);

				  $memtot = DT_Session::get('Setting.User.memtot');

	   			  $reg_type = DT_Session::get('Setting.User.type');

	   			  $type = 'M';

				  $discount_code_id = $event->validate_code($_REQUEST['discount_code'],NULL,'M',$memtot,$reg_type); 

				  if($discount_code_id !== false){

					  //DT_Session::set('Setting.Member.discount_code_id', $discount_code_id );

					  $memberdata['discount_code_id'] = $discount_code_id;

				  }else{

					  // DT_Session::set('Setting.Member.discount_code_id', false );

					   $memberdata['discount_code_id'] = false;

					//  DT_Session::set('Setting.User.discount_code_id', false );

					  $userdata['discount_code_id'] = false;

					  if(!isset($event->TableEventdiscountcode->TableDiscountcode->error)){

					  		$event->TableEventdiscountcode->TableDiscountcode->error = "Inalid code.";

					  }

					  $this->view->assign('discountCodeError',$event->TableEventdiscountcode->TableDiscountcode->error );

				  }

			  }else{

				  // DT_Session::set('Setting.Member.discount_code_id', 0 );

				   $memberdata['discount_code_id'] = 0;

			  }

			  $this->view->assign('memberdata',$memberdata);

		   }else{

			  // DT_Session::set('Setting.User.fields', $_REQUEST['Field']);

			  $userdata['fields'] = $_REQUEST['Field'];

			   if(isset($_REQUEST['username'])){

				  // DT_Session::set('Setting.User.username', $_REQUEST['username']);

				   $userdata['username'] = $_REQUEST['username'];

				  // DT_Session::set('Setting.User.password', $_REQUEST['password']);

				   $userdata['password'] = $_REQUEST['password'];

			   }

			  if(isset($_REQUEST['discount_code']) && $_REQUEST['discount_code'] != ""){

				$eventId = JRequest::getInt('eventId',DT_Session::get('Setting.eventId'));

				$event = $this->getModel('event')->table;

	            $event->load($eventId);

				$memtot = DT_Session::get('Setting.User.memtot');

	   			$reg_type = DT_Session::get('Setting.User.type');

	   			$type = $reg_type == 'I'?'I':'B';

				$discount_code_id = $event->validate_code($_REQUEST['discount_code'],NULL,$type,$memtot,$reg_type); 

				  if($discount_code_id !== false){

					  //DT_Session::set('Setting.User.discount_code_id', $discount_code_id );

					   $userdata['discount_code_id'] = $discount_code_id ;

				  }else{

					 // DT_Session::set('Setting.User.discount_code_id', false );

					 $userdata['discount_code_id'] = false;

					  if(!isset($event->TableEventdiscountcode->TableDiscountcode->error)){

					  		$event->TableEventdiscountcode->TableDiscountcode->error = "Inalid code.";

					  }

					  $this->view->assign('discountCodeError',$event->TableEventdiscountcode->TableDiscountcode->error );

				  }

			  }else{

				  // DT_Session::set('Setting.User.discount_code_id', 0 );

				   $userdata['discount_code_id'] = 0;

			  }

		   }

		    if(isset($_REQUEST['Tax_exemption'])) {

			     //DT_Session::set('Setting.User.tax_exemption', $_REQUEST['Tax_exemption'] );

				 $userdata['tax_exemption'] = $_REQUEST['Tax_exemption'];

				  if(isset($_REQUEST['Tax_exemption_code'])) { 

			        $userdata['tax_exemption_code']  = $_REQUEST['Tax_exemption_code'];

			      }

			  }

	   } else if(DT_Session::get('Setting.User.fields') == false){

			$this->load_from_first_reg();

			 $userdata = DT_Session::get('Setting.User');

			  $memberdata = DT_Session::get('Setting.Member');

			  if($memberdata !== false)

			  {

			     $this->view->assign('memberdata',$memberdata);

			  }

	   } else {

	        $userdata = DT_Session::get('Setting.User');

			  $memberdata = DT_Session::get('Setting.Member');

			  if($memberdata !== false)

			  {

			     $this->view->assign('memberdata',$memberdata);

			  }

	   }

	   $session = JFactory::getSession();

	   $session->close();

	   $this->view->assign('userdata',$userdata);

	   $this->view->setLayout($layout );

	   $this->view->display();

	 //  sleep_till_session_written();

	   die;

	}

	function price_header_old(){

	$layout = JRequest::getVar('dttmpl','price_header');

	   if(isset($_REQUEST['Field'])){

		   if(isset($_REQUEST['member_data'])){

	          DT_Session::set('Setting.Member.fields', $_REQUEST['Field']);

			   if(isset($_REQUEST['discount_code']) && $_REQUEST['discount_code'] != ""){

				  $eventId = JRequest::getInt('eventId',DT_Session::get('Setting.eventId'));

				  $event = $this->getModel('event')->table;

	              $event->load($eventId);

				  $memtot = DT_Session::get('Setting.User.memtot');

	   			  $reg_type = DT_Session::get('Setting.User.type');

	   			  $type = 'M';

				  $discount_code_id = $event->validate_code($_REQUEST['discount_code'],NULL,'M',$memtot,$reg_type); 

				  if($discount_code_id !== false){

					  DT_Session::set('Setting.Member.discount_code_id', $discount_code_id );

				  }else{

					  DT_Session::set('Setting.Member.discount_code_id', false );

					  DT_Session::set('Setting.User.discount_code_id', false );

					  if(!isset($event->TableEventdiscountcode->TableDiscountcode->error)){

					  		$event->TableEventdiscountcode->TableDiscountcode->error = "Inalid code.";

					  }

					  $this->view->assign('discountCodeError',$event->TableEventdiscountcode->TableDiscountcode->error );

				  }

			  }else{

				   DT_Session::set('Setting.Member.discount_code_id', 0 );

			  }

		   }else{

			   DT_Session::set('Setting.User.fields', $_REQUEST['Field']);

			   if(isset($_REQUEST['username'])){

				   DT_Session::set('Setting.User.username', $_REQUEST['username']);

				   DT_Session::set('Setting.User.password', $_REQUEST['password']);

			   }

			  if(isset($_REQUEST['discount_code']) && $_REQUEST['discount_code'] != ""){

				$eventId = JRequest::getInt('eventId',DT_Session::get('Setting.eventId'));

				$event = $this->getModel('event')->table;

	            $event->load($eventId);

				$memtot = DT_Session::get('Setting.User.memtot');

	   			$reg_type = DT_Session::get('Setting.User.type');

	   			$type = $reg_type == 'I'?'I':'B';

				$discount_code_id = $event->validate_code($_REQUEST['discount_code'],NULL,$type,$memtot,$reg_type); 

				  if($discount_code_id !== false){

					  DT_Session::set('Setting.User.discount_code_id', $discount_code_id );

				  }else{

					  DT_Session::set('Setting.User.discount_code_id', false );

					  if(!isset($event->TableEventdiscountcode->TableDiscountcode->error)){

					  		$event->TableEventdiscountcode->TableDiscountcode->error = "Inalid code.";

					  }

					  $this->view->assign('discountCodeError',$event->TableEventdiscountcode->TableDiscountcode->error );

				  }

			  }else{

				   DT_Session::set('Setting.User.discount_code_id', 0 );

			  }

		   }

		    if(isset($_REQUEST['Tax_exemption'])) {

			     DT_Session::set('Setting.User.tax_exemption', $_REQUEST['Tax_exemption'] );

			  }

	   } else if(DT_Session::get('Setting.User.fields') == false){

			$this->load_from_first_reg();

	   }

	   $this->view->setLayout($layout );

	   $this->view->display();

	   die;

	}

	function load_from_first_reg() {

	   $data = DT_Session::get('register.User.0');

	   if($data !== false) {

		  if(DT_Session::get('Setting.reg_status') == 'start') {

			 DT_Session::set('Setting.User.fields',$data['fields']);

			 if(DT_Session::get('Setting.User.memtot') ===  false) {

			   DT_Session::set('Setting.User.memtot',$data['memtot']);

			 }

			 if(DT_Session::get('Setting.User.type') ===  false) {

			   DT_Session::set('Setting.User.type',$data['type']);

			 }

			 if(DT_Session::get('Setting.User.eventId') ==  false) {

			   DT_Session::set('Setting.User.eventId',$data['eventId']);

			 }

		  } else {

		  	 DT_Session::set('Setting.User', $data );

		  }

		  if(DT_Session::get('Setting.eventId') ==  false) {

			   DT_Session::set('Setting.eventId',DT_Session::get('Setting.User.eventId'));

			 }

	   }

	}

	function load_from_last_reg() {

	   $data = DT_Session::get('register.User');

	   $data = end($data);

	   if($data !== false) {

		  if(DT_Session::get('Setting.reg_status') == 'start') {

			DT_Session::set('Setting.User.fields',$data['fields']);

			 if(DT_Session::get('Setting.User.memtot') ==  false) {

			   DT_Session::set('Setting.User.memtot',$data['memtot']);

			 }

			 if(DT_Session::get('Setting.User.type') ==  false) {

			   DT_Session::set('Setting.User.type',$data['type']);

			 }

			 if(DT_Session::get('Setting.User.eventId') ==  false) {

			   DT_Session::set('Setting.User.eventId',$data['eventId']);

			 }

		  } else {

		  	 DT_Session::set('Setting.User', $data );

		  }

		   if(DT_Session::get('Setting.eventId') ==  false) {

			   DT_Session::set('Setting.eventId',DT_Session::get('Setting.User.eventId'));

			 }

	   }

	}

	function registrant(){

		global $mainframe,$registrant_list;

	    $mUser = $this->getModel( 'user' );

		$order = JRequest::getVar('filter_order','name');

		$dir = JRequest::getVar('filter_order_Dir','asc');

		jimport('joomla.html.pagination');

	    $listLimit = $mainframe->getCfg( 'list_limit', 10 );

        $limit=JRequest::getInt('limit',$listLimit);

	    $limitstart = JRequest::getVar('limitstart', 0, '', 'int');

		$searchtxt = JRequest::getVar( 'search' ,'' );

		$users = $mUser->getUsers(array('eventId'=>JRequest::getInt('eventId'),'query'=>$searchtxt,'status'=>array(0,1)),$order,$dir,$limitstart,$limit);

		$total = $mUser->table->getLastCount($mUser->count_query);

		$pageNav = new DtPagination( $total, $limitstart, $limit );

		$my = &JFactory::getUser();

		//pr($registrant_list);

		//pr($my->getAuthorisedViewLevels());

		$levels = array_unique($my->getAuthorisedViewLevels());

		if(!in_array($registrant_list,$levels)){

				echo JText::_( 'DT_LOGIN_REQUIRED');

				return;

		}

		$this->view->assign('users',$users);

		$this->view->assign('pageNav',$pageNav);

		$this->display();

	}

	function getjevent(){

	   $jevt = $this->getModel('event')->tableJevt;

	   $data = $jevt->find(' evdet_id='.JRequest::getInt('eventId',0));

	   $rep = $jevt->parserule(JRequest::getInt('eventId',0));

	 //  prd($jevt->getObjData());

	   ob_clean();

	//   prd(json_encode($repjson));

	   if($data){

	      $data = $data[0];

	   if($rep)

	      $data->reprules = $jevt->getObjData();

	   echo json_encode($data);

	   }else{

	      $array = array('error'=>'No event');

		  echo json_encode($array);

	   }

	   die;

	}

	function continue_reg() {

		global $mainframe,$Itemid,$xhtml;

		//DT_Session::set('Setting.cart','yes');

		sleep_till_session_written();

		$mainframe->redirect(JRoute::_("index.php?option=com_dtregister&controller=event&Itemid=".$Itemid,$xhtml));

	}

	function google_add() {

		require_once(JPATH_SITE.DS.'components'.DS.'com_dtregister'.DS.'lib'.DS.'google-api'.DS.'apiClient.php');

		require_once(JPATH_SITE.DS.'components'.DS.'com_dtregister'.DS.'lib'.DS.'google-api'.DS.'contrib'.DS.'apiCalendarService.php');

		$client = new apiClient();

		$client->setApplicationName("Dtreg");

		// Visit https://code.google.com/apis/console?api=calendar to generate your

		// client id, client secret, and to register your redirect uri.

		$client->setClientId('104978521689-da0l8eq7vlnv76vnh36gh42brjmpagbi.apps.googleusercontent.com');

		$client->setClientSecret('OYIT1IorBqcK5hnlv9Da07OC');

		$client->setRedirectUri('http://joomlaeventregistration.com/j25/index.php/index.php?option=com_dtregister&Itemid=233&controller=calendar&task=auth');

		$client->setDeveloperKey('AIzaSyAyyhb1g0uEDg0WbQniTYGgmgmtZdDkxbg');

		$cal = new apiCalendarService($client);

		if (isset($_GET['logout'])) {

		  unset($_SESSION['token']);

		}

		if (isset($_GET['code'])) {

		  $client->authenticate();

		  $_SESSION['token'] = $client->getAccessToken();

		}

		if (isset($_SESSION['token'])) {

		  $client->setAccessToken($_SESSION['token']);

		}

		if ($client->getAccessToken()) {

		  $calList = $cal->calendarList->listCalendarList();

		  print "<h1>Calendar List</h1><pre>" . print_r($calList, true) . "</pre>";

		  $_SESSION['token'] = $client->getAccessToken();

		} else {

		  $authUrl = $client->createAuthUrl();

		  print "<a class='login' href='$authUrl'>Click Here to continue!</a>";

		}

		pr($_REQUEST);

		die;

	}

	function groupNum(){

	   global $mainframe,$Itemid,$xhtml;

	   $eventId = JRequest::getInt('eventId');

	   if(DT_Session::get('Setting.User.type') == 'I') {

	   		DT_Session::clear('Setting.User');

			if(DT_Session::get('Setting.cart') === false && DT_Session::get('Setting.Editindex') === false) {

				DT_Session::clear('register');

			}

	   }

	   if (isset($eventId) && $eventId > 0) {

	    	DT_Session::set('Setting.eventId', $eventId);

			DT_Session::set('Setting.User.eventId', $eventId);

			DT_Session::set('Setting.process', 'register');

	   }

		if(false === DT_Session::get('Setting.eventId') || DT_Session::get('Setting.eventId') == 0){

		   $mainframe->redirect(JRoute::_("index.php?option=com_dtregister&Itemid=".$Itemid,$xhtml));

	   }

	   $userIndex = DT_Session::get('Setting.current.userIndex');

	   $eventId = JRequest::getInt('eventId',DT_Session::get('Setting.eventId'));

	   $tEvent = $this->getModel('event')->table;

	   $tUser = $this->getModel('user')->table;

	   $tEvent->load($eventId);

	   $tEvent->is_registerable($tUser);

	   if($tEvent->group_registration_type =="detail"){

		   sleep_till_session_written();

	   	  $mainframe->redirect(JRoute::_("index.php?option=com_dtregister&controller=event&task=memberdata&Itemid=".$Itemid,$xhtml));

	   }

	   if(isset($_POST['memtot'])){

	       DT_Session::clear('Setting.User.members');

		   DT_Session::set('Setting.User.memtot',$_POST['memtot']);

		   if($tEvent->group_registration_type !="detail"){

			   sleep_till_session_written();

		 $mainframe->redirect(JRoute::_('index.php?option=com_dtregister&controller=event&task=billinginfo&Itemid='.$Itemid,$xhtml));

		   }else{

			   sleep_till_session_written();
		     $mainframe->redirect(JRoute::_("index.php?option=com_dtregister&controller=event&task=memberdata&Itemid=".$Itemid,$xhtml));

		   }

	   }

	   // echo '<pre>'; print_r($tEvent->max_group_size);

	   DT_Session::set('Setting.User.type','G');

	   $this->view->assign('header_eventId',$eventId);

	   $this->view->setLayout('groupNum');

	   $this->view->assign('tEvent',$tEvent);

	   $this->view->display();

	}

}

?>