<?php
/**
 * Adodis Blog package
 * @author J-Extension <contact@jextn.com>
 * @link http://www.jextn.com
 * @copyright (C) 2012 - 2013 J-Extension
 * @license GNU/GPL, see LICENSE.php for full license.
**/

// Check to ensure this file is included in Joomla!
	defined('_JEXEC') or die('Restricted access');

$listOrder	= $this->state->get('list.ordering');
$listDirn	= $this->state->get('list.direction');
$canOrder	= $this->user->authorise('core.edit.state', 'com_adodisblog.category');
$saveOrder	= $listOrder == 'tm.ordering';
?>
<form action="<?php echo JRoute::_('index.php?option=com_adodisblog'); ?>" method="post" name="adminForm" id="adminForm">
	<fieldset id="filter-bar">
		<div class="filter-search fltlft">
			<label class="filter-search-lbl" for="filter_search">
				<?php echo JText::_('JSEARCH_FILTER_LABEL'); ?>
			</label>
			<input type="text" name="filter_search" id="filter_search" value="<?php echo $this->escape($this->state->get('filter.search')); ?>" title="<?php echo JText::_('COM_ADODISBLOG_SEARCH_IN_TITLE'); ?>" class="hasTip"/>
			<button type="submit">
				<?php echo JText::_('JSEARCH_FILTER_SUBMIT'); ?>
			</button>
			<button type="button" onclick="document.getElementById('filter_published').value=''; document.getElementById('filter_category_id').value=''; document.getElementById('filter_access').value=''; document.getElementById('filter_language').value=''; document.id('filter_search').value='';this.form.submit();">
				<?php echo JText::_('JSEARCH_FILTER_CLEAR'); ?>
			</button>
		</div>

		<div class="filter-select fltrt">
			<select name="filter_published" id="filter_published" class="inputbox" onchange="this.form.submit()">
				<option value="">
					<?php echo JText::_('JOPTION_SELECT_PUBLISHED');?>
				</option>
				<?php echo JHtml::_('select.options', JHtml::_('jgrid.publishedOptions'), 'value', 'text', $this->state->get('filter.published'), true);?>
			</select>

			<select name="filter_category_id" id="filter_category_id" class="inputbox" onchange="this.form.submit()">
				<option value="">
					<?php echo JText::_('JOPTION_SELECT_CATEGORY');?>
				</option>
				<?php echo JHtml::_('select.options', JHtml::_('category.options', 'com_adodisblog'), 'value', 'text', $this->state->get('filter.category_id'));?>
			</select>

	        <select name="filter_access" id="filter_access" class="inputbox" onchange="this.form.submit()">
				<option value="">
					<?php echo JText::_('JOPTION_SELECT_ACCESS');?>
				</option>
				<?php echo JHtml::_('select.options', JHtml::_('access.assetgroups'), 'value', 'text', $this->state->get('filter.access'));?>
			</select>

			<select name="filter_language" id="filter_language" class="inputbox" onchange="this.form.submit()">
				<option value="">
					<?php echo JText::_('JOPTION_SELECT_LANGUAGE');?>
				</option>
				<?php echo JHtml::_('select.options', JHtml::_('contentlanguage.existing', true, true), 'value', 'text', $this->state->get('filter.language'));?>
			</select>
		</div>
	</fieldset>

	<div class="clr"> </div>

	<table class="adminlist">
		<thead>
			<tr>
				<th width="3%">
					<?php echo JText::_( 'JE_SERNO' ); ?>
				</th>
				<th width="1%">
					<input type="checkbox" name="checkall-toggle" value="" onclick="checkAll(this)" />
				</th>
				<th>
					<?php echo JHtml::_('grid.sort',  'COM_ADODISBLOG_TITLE', 'tm.title', $listDirn, $listOrder); ?>
				</th>
				<th width="10%">
					<?php echo JHtml::_('grid.sort',  'COM_ADODISBLOG_USERNAME', 'tm.intro_text', $listDirn, $listOrder); ?>
				</th>
				<th width="10%">
					<?php echo JHtml::_('grid.sort', 'JCATEGORY', 'tm.catid', $listDirn, $listOrder); ?>
				</th>
				<th width="10%">
					<?php echo JHtml::_('grid.sort',  'COM_ADODISBLOG_IPADDRESS', 'tm.ip_address', $listDirn, $listOrder); ?>
				</th>
				<th width="5%">
					<?php echo JHtml::_('grid.sort', 'JPUBLISHED', 'tm.published', $listDirn, $listOrder); ?>
				</th>
				<th width="10%">
					<?php echo JHtml::_('grid.sort',  'JGRID_HEADING_ORDERING', 'tm.ordering', $listDirn, $listOrder); ?>
					<?php if ($canOrder && $saveOrder) :?>
						<?php echo JHtml::_('grid.order',  $this->items, 'filesave.png', 'blogs.saveorder'); ?>
					<?php endif; ?>
				</th>
				<th width="10%">
					<?php echo JHtml::_('grid.sort', 'JGRID_HEADING_ACCESS', 'access_level', $listDirn, $listOrder); ?>
				</th>
				<th width="5%">
					<?php echo JHtml::_('grid.sort', 'JGRID_HEADING_LANGUAGE', 'tm.language', $listDirn, $listOrder); ?>
				</th>
				<th width="1%">
					<?php echo JHtml::_('grid.sort', 'JGRID_HEADING_ID', 'tm.id', $listDirn, $listOrder); ?>
				</th>
			</tr>
		</thead>

		<tfoot>
			<tr>
				<td colspan="11">
					<?php echo $this->pagination->getListFooter(); ?>
				</td>
			</tr>
		</tfoot>

		<tbody>
			<?php
			$n = count($this->items);
			foreach ($this->items as $i => $item) :
				$ordering	= $listOrder == 'tm.ordering';
				$canCreate	= $this->user->authorise('core.create',		'com_adodisblog.category.'.$item->catid);
				$canEdit	= $this->user->authorise('core.edit',		'com_adodisblog.category.'.$item->catid);
				$canEditOwn	= $this->user->authorise('core.edit.own',	'com_adodisblog.category.'.$item->catid);
				$canChange	= $this->user->authorise('core.edit.state',	'com_adodisblog.category.'.$item->catid);
				?>
				<tr class="row<?php echo $i % 2; ?>">
					<td align="center">
						<?php echo $i+1; ?>
					</td>
					<td class="center">
						<?php echo JHtml::_('grid.id', $i, $item->id); ?>
					</td>
					<td>
						<?php
						if ($canEdit || $canEditOwn) :
						?>
							<span class="editlinktip hasTip" title="<?php echo addslashes(htmlspecialchars(JText::_('COM_ADODISBLOG_TOOLTIP_EDITBLOG').'::'.$item->title)); ?>">
								<a href="<?php echo JRoute::_('index.php?option=com_adodisblog&task=blog.edit&id='.(int) $item->id); ?>">
									<?php echo $item->title; ?>
								</a> &nbsp;
							</span>
							<p class="smallsub">
								<?php echo JText::sprintf('JGLOBAL_LIST_ALIAS', $this->escape($item->alias));?>
							</p>
						<?php
						endif;
						?>
					</td>
					<td align="center">
						<?php
							if($item->user_name)
								echo $item->user_name;
							else
								echo $item->name;
						?>
					</td>
					<td align="center">
						<?php echo $item->category_title; ?>
					</td>
					<td align="center">
						<?php echo $item->ip_address; ?>
					</td>
					<td align="center">
						<?php echo JHtml::_('jgrid.published', $item->published, $i, 'blogs.', $canChange, 'cb'); ?>
					</td>
					<td class="order">
						<?php if ($canChange) :
									if ($saveOrder) :
										if ($listDirn == 'asc') : ?>
									<span>
										<?php echo $this->pagination->orderUpIcon($i, ($item->catid == @$this->items[$i-1]->catid),'blogs.orderup', 'JLIB_HTML_MOVE_UP', $ordering); ?>
									</span>
									<span>
										<?php echo $this->pagination->orderDownIcon($i, $n, ($item->catid == @$this->items[$i+1]->catid), 'blogs.orderdown', 'JLIB_HTML_MOVE_DOWN', $ordering); ?>
									</span>
								<?php elseif ($listDirn == 'desc') : ?>
									<span>
										<?php echo $this->pagination->orderUpIcon($i, ($item->catid == @$this->items[$i-1]->catid),'blogs.orderdown', 'JLIB_HTML_MOVE_UP', $ordering); ?>
									</span>
									<span>
										<?php echo $this->pagination->orderDownIcon($i, $n, ($item->catid == @$this->items[$i+1]->catid), 'blogs.orderup', 'JLIB_HTML_MOVE_DOWN', $ordering); ?>
									</span>
								<?php endif;
								endif;
								$disabled = $saveOrder ?  '' : 'disabled="disabled"'; ?>
							<input type="text" name="order[]" size="5" value="<?php echo $item->ordering;?>" <?php echo $disabled ?> class="text-area-order" />
						<?php else :
								 echo $item->ordering;
							endif;
						?>
					</td>
					<td align="center">
						<?php echo $item->access_level; ?>
					</td>
					<td class="center">
						<?php if ($item->language=='*'):
									echo JText::alt('JALL','language');
								else:
									echo $item->language_title ? $this->escape($item->language_title) : JText::_('JUNDEFINED');
								endif;
						?>
					</td>
					<td align="center">
						<?php echo $item->id; ?>
					</td>
				</tr>
			<?php endforeach; ?>
		</tbody>
	</table>
	<div>
		<input type="hidden" name="task" value="" />
		<input type="hidden" name="boxchecked" value="0" />
		<input type="hidden" name="filter_order" value="<?php echo $listOrder; ?>" />
		<input type="hidden" name="filter_order_Dir" value="<?php echo $listDirn; ?>" />
		<?php echo JHtml::_('form.token'); ?>
	</div>
</form>

<div class="clr"></div>
<p class="copyright" align="center">
	<?php /*require_once( JPATH_COMPONENT . DS . 'copyright' . DS . 'copyright.php' );*/ ?>
</p>