<?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
*/

?>
<?php
 global $mainframe;

  $database = &JFactory::getDBO();

  jimport('joomla.html.pagination');

  $limit = $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );

  $limitstart = $mainframe->getUserStateFromRequest( "viewcom_dtregisterlimitstart", 'limitstart', 0 );
$aro = $this->getModel( 'aro' );
   $user = &JFactory::getUser();
   $aro = $this->getModel( 'aro' )->table->findaroByUser($user);
   
   $aco_id = $this->getModel( 'aco' )->table->getAcoIdbyTypeControllerTask('sessionUser','event','edit','DT_EDIT_OWN_EVENT');
   $permission = $this->getModel( 'permission' )->table->find('aro_id in('.implode(",",$aro).') and aco_id = '.$aco_id);
   $where = "";
  if($permission && count($permission) == count($aro)){
  	 $where = "where `public` = 1 or user_id = ".$user->id;
   }
   
   $sql = "Select SQL_CALC_FOUND_ROWS * from #__dtregister_payment   $where ";
  $database->setQuery( $sql,$limitstart,$limit);

  $payments=$database->loadObjectList();

  $database->setQuery('SELECT FOUND_ROWS();');

  $pageNav = new JPagination( $database->loadResult(), $limitstart, $limit  );
  $Muser = $this->getModel('user');
?>
<form action="index.php" method="post" name="adminForm" id="adminForm" enctype="multipart/form-data">

<table class="adminlist">

  <tr>

    <th width="12" class="dt_heading">

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

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

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

    </th>
     <th width="300" class="dt_heading">
          <?php echo JText::_('DT_PAYMENT_OWNER');?>
    </th>
	<th width="120" class="dt_heading">
	      <?php echo JText::_('DT_DEFAULT'); ?>
	</th>

   </tr>

  <tr>

  <?php 

  $k = 0;

  $i = 0;

    foreach($payments as $payment){

	  	$link = 'index.php?option=com_dtregister&task=edit&controller=payoption&hidematinmenu=1&cid[]='. $payment->id;

		  $checked = JHTML::_('grid.id', $i , $payment->id );

	  ?>

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

     <td>

      <?php echo $checked; ?>

     </td>

	 <td>
      
       <a href="<?php echo $link; ?>"><?php echo stripslashes($payment->name); ?></a>
      
	    <?php
        if($payment->public){
			echo "<i>(".JText::_('DT_GLOBAL').")</i>";
		}
		?>

     </td>
     
      <td>

      
      <?php if($payment->user_id > 0){ $Muser->table->TableJUser->load($payment->user_id); echo $Muser->table->TableJUser->username; } ?>


     </td>
     
     <td>
       <?php
          if($payment->default){
			  ?>
              <a href="index.php?option=com_dtregister#deselectdefault" onclick="return listItemTask('cb<?php echo $i;?>','deselectdefault')">
              <?php
			  echo JHTML::_('image', 'administrator/templates/bluestork/images/menu/icon-16-default.png', null);
			   ?>
               </a>
              <?php
		  }else{
		  ?>
			   <a href="index.php?option=com_dtregister#default" onclick="return listItemTask('cb<?php echo $i;?>','makedefault')"><?php echo JText::_('DT_MAKE_DEFAULT'); ?></a>
          <?php
		  }
	   ?>
     </td>
    
   </tr>

  <tr>

  <?php $i++; $k = 1 - $k; } ?>

   <td colspan="4">

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

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

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

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

   </td>

  </tr>

</table>

</form>