<?php

/**
* @version 2.7.17
* @package Joomla 1.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
*/

global $Itemid,$xhtml,$minimum_cart_event,$maximum_cart_event;
// pr(DT_Session::get('register.User'));

$events = array();

$html = "";

$event_count = 0;

foreach(DT_Session::get('register.User') as $key=>$registration){
	
    $eventTable = DtrTable::getInstance('event','Table');
	if(!isset($events[$registration['eventId']])){

	   $eventTable->load($registration['eventId']);

	   $events[$registration['eventId']] = $eventTable;

	}

    if(isset($registration['remove']) && $registration['remove']==1){

		continue;

    }
    
	if(!isset($registration['confirmed']) || $registration['confirmed'] !=1){
	  	continue;
	}
	$event_count ++;
	$event = $events[$registration['eventId']];
    
	$this->assign('index',$key);

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

	$this->assign('registration',$registration);

	$html .= $this->loadTemplate('row');

}

global $event_show_date;

?>
<div class="componentheading"><?php echo JText::_('DT_EVENT_REGISTRATION')?>: <?php echo JText::_( 'DT_MY_CART' );?>

</div>

<form action="index.php?option=com_dtregister&Itemid=<?php echo $Itemid; ?>" method="post" class="adminform" enctype="multipart/form-data">

<table class="adminlist">

<tr>

 <th class="dt_heading">

   <?php echo JText::_('DT_EVENT');?>

 </th>

 <th class="dt_heading">

   <?php echo JText::_('DT_TYPE');?>

 </th>

 <th class="dt_heading">

   <?php echo JText::_('DT_DEPOSIT_AMOUNT');?>

 </th>
 
 <th class="dt_heading">

   <?php echo JText::_('DT_PRICE');?>

 </th>
 
 <th class="dt_heading" colspan="2">

   <?php echo JText::_('DT_ACTION');?>

 </th>

</tr>

  <?php echo $html; ?>

  <tr>

    <td colspan="6">&nbsp;</td>

  </tr>

  <tr>

    <td colspan="6">
    
     <?php  
	      
	 	   if($minimum_cart_event == "") {
				$minimum_cart_event = $event_count - 1;
				if($minimum_cart_event < 0) {
					$minimum_cart_event = 0;
				}
		   }
		   
		   if($maximum_cart_event == "") {
				$maximum_cart_event = $event_count + 1;
		   }
		  
	 ?>
     
     <?php if(($event_count < $maximum_cart_event || $event_count < $minimum_cart_event)) {?>
      <input type="button" value="<?php echo JText::_('DT_REGISTER_ANOTHER_EVENT'); ?>" id="continue" />
      <?php } ?>
  <?php if($event_count <= $maximum_cart_event && $event_count >= $minimum_cart_event) {?>
      <input type="submit" value="<?php echo JText::_('DT_CHECKOUT'); ?>" id="checkout" />
   <?php } else {
	    	if($event_count < $minimum_cart_event){
				echo JText::_('DT_MINIMUM_CART_WARNING_FRONT')." ".$minimum_cart_event." ".JText::_('DT_MINIMUM_CART_WARNING_BACK');
			} else {
				echo JText::_('DT_MAXIMUM_CART_WARNING_FRONT')." ".$maximum_cart_event." ".JText::_('DT_MAXIMUM_CART_WARNING_BACK');
			}
	     	
		} ?>

    </td>

  </tr>

</table>

   <input type="hidden" name="option" value="com_dtregister" />

   <input type="hidden" name="controller" value="payment" />

   <input type="hidden" name="Itemid" value="<?php echo $Itemid; ?>" />

   <input type="hidden" name="task" value="methods" />

 </form>

 <script type="text/javascript">

    DTjQuery(function(){

		 DTjQuery("#continue").click(function(){

			 window.location = "<?php echo JRoute::_("index.php?option=com_dtregister&Itemid=".$Itemid."&cart=continue" ,false); ?>"; // $xhtml

			 return false;		 	 

		 });	

	});

 </script>