<?php defined('_JEXEC') or die('Restricted access'); ?>

<?php JHTML::_('behavior.tooltip'); ?>

<?php
	$document =& JFactory::getDocument();
	$document->setTitle(JText::_('IP filters'));
	JToolBarHelper::title( JText::_( 'IP filters' ), 'kip.png' );
	JToolBarHelper::publishList('publish', 'Enable');
	JToolBarHelper::unpublishList('unpublish', 'Disable');
	JToolBarHelper::deleteList('','remove');
	JToolBarHelper::editListX('edit');
	JToolBarHelper::addNewX('add');
	//JToolBarHelper::custom( 'cpanel.display','back','back',JText::_( 'Control Panel' ) , false);
	//$db = & JFactory::getDBO();
	//$nullDate = $db->getNullDate();
?>
<script language="javascript" type="text/javascript">
	function submitbutton(pressbutton) {
		var form = document.adminForm;
		if (pressbutton == 'remove') {
			if(!confirm("<?php echo JText::_( 'Remove selected items?', true ); ?>"))
			return;
		}
		submitform( pressbutton );
	}
</script>

<form action="index.php" method="post" name="adminForm">
<table>
	<tr>
		<td align="left" width="100%">
			<?php echo JText::_( 'Filter' ); ?>:
			<input type="text" name="filter_search" id="filter_search" value="<?php echo $this->lists['search'];?>" class="text_area<?php echo $this->lists['search'] ? ' filter_selected' : '' ?>" onchange="document.adminForm.submit();" />
			<button onclick="this.form.submit();"><?php echo JText::_( 'Go' ); ?></button>
			<button onclick="document.getElementById('filter_search').value='';this.form.submit();"><?php echo JText::_( 'Reset' ); ?></button>
		</td>
		<td nowrap="nowrap">
		<?php 
			echo $this->lists['client_id'];	
			echo '&nbsp;';
			echo $this->lists['state'];
		?>
		</td>
	</tr>
</table>
<div id="tablecell">
	<table class="adminlist">
	<thead>
		<tr>
			<th width="10px">
				<?php echo JText::_( 'NUM' ); ?>
			</th>
			<th width="1%">
				<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count( $this->items ); ?>);" />
			</th>
			<th class="title" style="width:300px">
				<?php echo JHTML::_('grid.sort',   'IP address/range', 'i.iprange_txt', @$this->lists['order_Dir'], @$this->lists['order'], 'display' ); ?>
			</th>
			<th width="5%" align="center">
				<?php echo JHTML::_('grid.sort',   'State', 'i.published', @$this->lists['order_Dir'], @$this->lists['order'], 'display' ); ?>
			</th>
			<th width="130px" align="center">
				<?php echo JHTML::_('grid.sort',   'Type', 'i.client_id, u1.username', @$this->lists['order_Dir'], @$this->lists['order'], 'display' ); ?>
			</th>
			<th style="width:80px" align="center">
				<?php echo JHTML::_('grid.sort',   'Last update', 'lastupdate', @$this->lists['order_Dir'], @$this->lists['order'], 'display' ); ?>
			</th>
			<th>
				<?php echo JHTML::_('grid.sort',   'Notes', 'i.description', @$this->lists['order_Dir'], @$this->lists['order'], 'display' ); ?>
			</th>
			<th width="30" nowrap="nowrap">
				<?php echo JHTML::_('grid.sort',   'ID', 'i.id', @$this->lists['order_Dir'], @$this->lists['order'], 'display' ); ?>
			</th>
		</tr>
	</thead>
	<tfoot>
		<tr>
			<td colspan="9">
				<?php echo $this->pagination->getListFooter(); ?>
			</td>
		</tr>
	</tfoot>
	<tbody>
	<?php
	$k = 0;
	for ($i=0, $n=count( $this->items ); $i < $n; $i++)
	{
		$row = &$this->items[$i];
		$row->description = JFilterOutput::ampReplace($row->description);
		$row->description = str_replace('"', '&quot;', $row->description);
		
		$row->appliedto = $row->client_id==2 ? '<b>'.JText::_('User').':</b>&nbsp;'.$row->username : '<b>'.($row->client_id ? JText::_('Backend') : JText::_('Frontend')).'</b>';
		
		$link 		= JRoute::_( 'index.php?option='.$this->option.'&view='.$this->view.'&task=edit&cid[]='. $row->id );

		$checked 	= JHTML::_('grid.checkedout',   $row, $i );
		$published 	= JHTML::_('grid.published', $row, $i, 'tick.png', 'publish_x.png' );
	?>
		<tr class="<?php echo "row$k"; ?>">
			<td>
				<?php echo $this->pagination->getRowOffset( $i ); ?>
			</td>
			<td>
				<?php echo $checked; ?>
			</td>
			<td nowrap="nowrap">
				<?php if (  JTable::isCheckedOut($this->user->get('id'), $row->checked_out ) ) : ?>
				<?php echo $row->iprange_txt; ?>
				<?php else : ?>
				<span class="editlinktip hasTip" title="<?php echo JText::_( 'Edit' );?>::<?php echo $row->iprange_txt; ?>">
				<a href="<?php echo $link; ?>"><?php echo $row->iprange_txt; ?></a></span>
				<?php endif; ?>
			</td>
			<td align="center">
				<?php echo $published;?>
			</td>
			<td align="left">
				<?php echo $row->appliedto;?>
			</td>
			<td align="center">
				<?php 
					//$row->modified = $row->modified==$nullDate ? $row->created :  $row->modified;
					echo JHTML::_('date',  $row->lastupdate, JText::_('DATE_FORMAT_LC4') ); 
				?>
			</td>
			<td align="left">
				<?php echo $row->description; ?>
			</td>
			<td align="center">
				<?php echo $row->id; ?>
			</td>
		</tr>
		<?php
			$k = 1 - $k;
		}
		?>
	</tbody>
	</table>
</div>

	<input type="hidden" name="option" value="<?php echo $this->option ?>" />
	<input type="hidden" name="view" value="<?php echo $this->view ?>" />
	<input type="hidden" name="task" value="display" />
	<input type="hidden" name="boxchecked" value="0" />
	<input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
	<input type="hidden" name="filter_order_Dir" value="<?php echo $this->lists['order_Dir']; ?>" />
	<?php echo JHTML::_( 'form.token' ); ?>
</form>