<?php

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

global $Itemid,$xhtml,$mainframe;

$rows = $this->rows;

$pageNav = $this->pageNav;

$search = $this->search;

$order = Jrequest::getVar('filter_order');

$dir = Jrequest::getVar('filter_order_Dir');

$paymthd = $this->getModel('Paymentmethod');
$pMethods = $paymthd->getMergeList(true);
$document =& JFactory::getDocument();
$document->addScript( JURI::root(true).'/components/com_dtregister/assets/js/jquery-ui.js');

 
$document->addStyleSheet(JURI::root(true).'/components/com_dtregister/assets/css/south-street/jquery-ui.css');


?>

<form action="index.php" method="post" name="adminForm" id="adminForm">

<?php

echo $this->loadTemplate('description');

?>

<table class="adminlist">

  <tr>

			<th width="5">#</th>

			<th width="20">

				<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count( $rows ); ?>);" />

			</th>

			<th>

			<?php echo JHTML::_( 'grid.sort', JText::_( 'DT_ADMIN_REGISTRANT_NAME' ), 'name', $dir, $order); ?>

			</th>

			<th>     <?php echo JHTML::_( 'grid.sort', JText::_( 'DT_EMAIL' ), 'email', $dir, $order); ?>

            </th>

			<th>

			  <?php echo JHTML::_( 'grid.sort', JText::_( 'DT_EVENT' ), 'event', $dir, $order); ?>

			</th>

			<th>

            <?php echo JHTML::_( 'grid.sort', JText::_( 'DT_AMOUNT' ), 'amount', $dir, $order); ?>

            </th>

			<th>

			<?php echo JHTML::_( 'grid.sort', JText::_( 'DT_REGISTER_DATE' ), 'date', $dir, $order); ?>

		</th>

      <th>

	     <?php echo JHTML::_( 'grid.sort', JText::_( 'DT_CONFIRMATION_NUMBER' ), 'confirmNum', $dir, $order); ?>

	  </th>

      <th>

	    <?php echo JHTML::_( 'grid.sort', JText::_( 'DT_DISCOUNT_CODE' ), 'discount_code', $dir, $order); ?>

	 </th>

      <th>

	    <?php echo JHTML::_( 'grid.sort', JText::_( 'DT_PAYMENT_TYPE' ), 'type', $dir, $order); ?>

	  </th>

	   <th>

			<?php echo JHTML::_( 'grid.sort', JText::_( 'DT_PAY_LATER_PAID' ), 'paid', $dir, $order); ?>

	   </th>

			<th>

			<?php echo JHTML::_( 'grid.sort', JText::_( 'DT_ATTENDED' ), 'attend', $dir, $order); ?>

			</th>

			<th>

			<?php echo JHTML::_( 'grid.sort', JText::_( 'DT_MEMBERS' ), 'members', $dir, $order); ?>

			</th>

        <th>

		<?php echo JHTML::_( 'grid.sort', JText::_( 'DT_DUE_AMOUNT' ), 'due_amount', $dir, $order); ?>

		</th>

         <th>

		 <?php echo JHTML::_( 'grid.sort', JText::_( 'DT_STATUS' ), 'status', $dir, $order); ?>

		</th>

		</tr>

        <?php

		$k = 0;

		$i = 0;

		$fieldNameMap = $this->mUser->table->TableUserfield->Tablefield->mapNametoId();
		
        if($this->rows)
		foreach($this->rows as $row){
            $fee = $this->mUser->table->TableFee->findByUserId($row->userId);
			 
			$name = array();

			$link = 'index.php?option=com_dtregister&task=edit&controller=user&cid[]='. $row->userId;

			$field_values = $this->mUser->table->TableUserfield->findByUserId($row->userId);

			$name = array();
            if(isset($field_values[$fieldNameMap['firstname']])){
			 $name[] = $field_values[$fieldNameMap['firstname']];
			}
            if(isset($field_values[$fieldNameMap['lastname']])){
			   $name[] = $field_values[$fieldNameMap['lastname']];
			}
			$name = implode(" ",array_filter($name));
			$email = "";
			if(isset($field_values[$fieldNameMap['email']])){
			$email = $field_values[$fieldNameMap['email']];
			}

		 ?>

         <tr class="<?php echo "row$k"; ?>" >

           <td><?php echo $pageNav->getRowOffset( $i ); ?></td>

           <td><?php echo $checked = JHTML::_('grid.id', $i, $row->userId); ?></td>

           <td align="center"><a href="<?php echo $link?>"><?php echo $name; ?></a></td>

           <td align="center"><a href="mailto:<?php echo stripslashes($email);?>"><?php echo stripslashes($email);?></a></td>

           <td align="center"><?php 
		    $evtTable = $this->getModel('event')->table;
			$evtTable->slabId = $row->slabId;
			$evtTable->dtstart = $row->dtstart;
			$evtTable->title = $row->title;
		    echo $evtTable->displayTitle(); ?> </td>

           <td align="center"><?php echo DTreg::numberFormat($row->fee,2);?></td>

           <td align="center"><?php echo $row->register_date;?></td>

           <td align="center"><?php echo $row->confirmNum; ?></td>

           <td align="center"><?php echo isset($row->code)?$row->code:'';?></td>

           <td align="center">
				<?php 
				if((isset($fee->fee) && $fee->fee >0) || $fee->payment_method == "offline_payment"){
				    	if ( (isset($fee) && $fee != "") && isset($pMethods[$fee->payment_method])  ) echo $pMethods[$fee->payment_method]; 
				else if (isset($fee->payment_method)) echo $fee->payment_method;
				}else{
				  echo Jtext::_('DT_FREE');
				}
	
				?>
           </td>

           <td align="center"><?php echo (isset($fee->fee) && $fee->fee >0)?DtHtml::gridTask($row, $i,'fee_status'):''; ?></td>

           <td><?php 
		    if(!count($this->mUser->table->TableMember->findByUserId($row->userId))) {
				
		   		echo DtHtml::gridTask($row, $i,'attend');
				
			}
		   ?></td>

           <td>	<?php if($row->type=='G'){
			   
			               if(!count($this->mUser->table->TableMember->findByUserId($row->userId))){
							echo $row->memtot." "; echo JText::_('DT_MEMBERS');
							   
						   }else{
			      
			    ?>

					<a class = "colorbox" href="index.php?option=com_dtregister&controller=member&task=index&tmpl=component&showtoolbar=1&userId=<?php echo $row->userId;?>&eventId=<?php echo $row->eventId?>"><?php echo $row->memtot;?> <?php echo JText::_('DT_MEMBERS')?></a>

					<?php } } ?></td>

             <td align="center"><?php 

				  if($row->cancel == 1){

				    echo DTreg::numberFormat($row->due,2);

				  }else{

				    echo DTreg::numberFormat(($row->fee-$row->paid_amount),2);

				  }

				?>

                </td>

                 <td align="center"><?php 
	  
				    echo $this->mUser->table->statustxt[$row->user_status];

				?></td>

         </tr>

         <?php

		 $k = 1 - $k;

		 $i++;

		}

		?>

</table>

<?php echo $pageNav->getListFooter(); ?>

<input type="hidden" name="option" value="<?php echo DTR_COM_COMPONENT;?>" />

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

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

<input type="hidden" name="filter_order" value="<?php echo Jrequest::getVar('filter_order','date');?>" />

<input type="hidden" name="filter_order_Dir" value="<?php echo Jrequest::getVar('filter_order_Dir','desc');?>" />

<input type="hidden" name="boxchecked" value="0" />

</form>

<script type="text/javascript">
   DTjQuery(function(){
		
		
		 DTjQuery(".colorbox").live('click',function(e){

		e.preventDefault();

		var horizontalPadding = 10;

		var verticalPadding = 10;
         
		var win_title = DTjQuery(this).attr('title');
		 
		DTjQuery('<iframe id="externalSite" style="display:none;min-width:800px;min-height:500px" class="externalSite" src="'+DTjQuery(this).attr('href')+'" />').dialog({

			title:  win_title,

			autoOpen: true,

			width:  800,

			height: 600,

			modal: true,

			resizable: true,

			overlay: {

				opacity: 0.5,

				background: "black"

			},
			close: function(event, ui) { window.location =  "index.php?option=com_dtregister&controller=user" }

		});

			     });
	        
   })
  			Joomla.submitbutton = function(pressbutton) {

				if(pressbutton=='new' || pressbutton=='group_registration')

				{

					var selectTag=document.adminForm["search[eventId]"];

					if(selectTag.value=="")

					{

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

						return;

					}

					else

					{

						submitform(pressbutton);

					}

				}

				else

				{

					submitform(pressbutton);

				}

			}

</script>