<?php

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

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

$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?option=com_dtregister&Itemid=<?php echo $Itemid ?>" 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 class="coltitle">

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

		</th>
		
		<?php $j = 2;
		if($config->getGlobal('frontmgmt_email_show',0)){

            $j++;
			echo '<th class="coltitle">'.JHTML::_( 'grid.sort', JText::_( 'DT_EMAIL' ), 'email', $dir, $order).'</th>';

		} ?>
		
        <th class="coltitle">

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

		</th>

		<?php 
		if($config->getGlobal('frontmgmt_amount_show',0)){

            $j++;
			echo '<th class="coltitle">'.JHTML::_( 'grid.sort', JText::_( 'DT_AMOUNT' ), 'amount', $dir, $order).'</th>';

		} ?>
		
		<?php 
		if($config->getGlobal('frontmgmt_due_show',0)){

            $j++;
			echo '<th class="coltitle">'.JHTML::_( 'grid.sort', JText::_( 'DT_AMOUNT_DUE' ), 'amount', $dir, $order).'</th>';

		} ?>

		<?php 
		if($config->getGlobal('frontmgmt_regdate_show',0)){

            $j++;
			echo '<th class="coltitle">'.JHTML::_( 'grid.sort', JText::_( 'DT_DATE' ), 'date', $dir, $order).'</th>';

		} ?>
		
		<?php 
		if($config->getGlobal('frontmgmt_confnum_show',0)){

            $j++;
			echo '<th class="coltitle">'.JHTML::_( 'grid.sort', JText::_( 'DT_CONF_NUM' ), 'confirmNum', $dir, $order).'</th>';

		} ?>
		
		<?php 
		if($config->getGlobal('frontmgmt_paytype_show',0)){

            $j++;
			echo '<th class="coltitle">'.JHTML::_( 'grid.sort', JText::_( 'DT_PAYMENT_TYPE' ), 'type', $dir, $order).'</th>';

		} ?>

		<?php 
		if($config->getGlobal('frontmgmt_paystatus_show',0)){

            $j++;
			echo '<th class="coltitle">'.JHTML::_( 'grid.sort', JText::_( 'DT_PAID' ), 'paid', $dir, $order).'</th>';

		} ?>

		<?php 
		if($config->getGlobal('frontmgmt_attend_show',0)){

            $j++;
			echo '<th class="coltitle">'.JHTML::_( 'grid.sort', JText::_( 'DT_ATTENDED' ), 'attend', $dir, $order).'</th>';

		} ?>

		<?php 
		if($config->getGlobal('frontmgmt_status_show',0)){

            $j++;
			echo '<th class="coltitle">'.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=usermanage&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>
	
	           <br /><?php if($row->type=='G'){

				               if(!count($this->mUser->table->TableMember->findByUserId($row->userId))){
								  echo "<em>(".JText::_('DT_GROUP_OF'); echo " ".$row->memtot.")</em>";

							   }else{

				    ?>

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

						<?php } } ?>
	
	       </td>

		<?php 
		if($config->getGlobal('frontmgmt_email_show',0)){

           $j++;
           echo '<td align="center"><a href="mailto:'.stripslashes($email).'">'.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>

			<?php 
			if($config->getGlobal('frontmgmt_amount_show',0)){

	           $j++;
	           echo '<td align="center">'.DTreg::numberFormat($row->fee,2).'</td>';

			} ?>
			
			<?php 
			if($config->getGlobal('frontmgmt_due_show',0)){

	           $j++;
	           echo '<td align="center">';
			   if($row->cancel == 1){

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

				  }else{

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

				  }
		       echo '</td>';

			} ?>

			<?php 
			if($config->getGlobal('frontmgmt_regdate_show',0)){

	           $j++;
	           echo '<td align="center">'.$row->register_date.'</td>';

			} ?>
			
			<?php 
			if($config->getGlobal('frontmgmt_confnum_show',0)){

	           $j++;
	           echo '<td align="center">'.$row->confirmNum.'</td>';

			} ?>
			
			<?php 
			if($config->getGlobal('frontmgmt_paytype_show',0)){

	           $j++;
	           echo '<td align="center">';
		       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');
			   }
			   echo '</td>';

			} ?>
			
			<?php 
			if($config->getGlobal('frontmgmt_paystatus_show',0)){

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

			} ?>
			
			<?php 
			if($config->getGlobal('frontmgmt_attend_show',0)){

	           $j++;
	           echo '<td align="center">';
	
	           if(!count($this->mUser->table->TableMember->findByUserId($row->userId))) {

		   		 echo DtHtml::gridTask($row, $i,'attend');

			   }
			
			   echo '</td>';

			} ?>

			<?php 
			if($config->getGlobal('frontmgmt_status_show',0)){

	           $j++;
	           echo '<td align="center">'.$this->mUser->table->statustxt[$row->user_status].'</td>';

			} ?>
			
         </tr>

         <?php

		 $k = 1 - $k;

		 $i++;

		}

		?>

</table>

<div class="pagination"><?php echo $pageNav->getPagesLinks(); ?></div>

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

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

<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" />

<input type="hidden" name="limitstart" value="<?php echo $pageNav->limitstart; ?>" />

</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=usermanage" }

		});

			     });
	        
   })
  			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>