<?php
/**
* @package   Warp Theme Framework
* @author    YOOtheme http://www.yootheme.com
* @copyright Copyright (C) YOOtheme GmbH
* @license   http://www.gnu.org/licenses/gpl.html GNU/GPL
*/

// no direct access
defined('_JEXEC') or die;

JHtml::addIncludePath(JPATH_COMPONENT.'/helpers/html');
JHtml::_('behavior.tooltip');
JHtml::core();

// Create some shortcuts
$params		= &$this->item->params;
$n			= count($this->items);
$listOrder	= $this->escape($this->state->get('list.ordering'));
$listDirn	= $this->escape($this->state->get('list.direction'));

?>

<?php if (empty($this->items)) : ?>

	<?php if ($this->params->get('show_no_articles', 1)) : ?>
	<p><?php echo JText::_('COM_CONTENT_NO_ARTICLES'); ?></p>
	<?php endif; ?>

<?php else : ?>

<form action="<?php echo htmlspecialchars(JFactory::getURI()->toString()); ?>" method="post" name="adminForm" id="adminForm">

	<?php if (($this->params->get('filter_field') != 'hide') || $this->params->get('show_pagination_limit')) :?>
	<div class="filter">
	
		<?php if ($this->params->get('filter_field') != 'hide') :?>
		<div>
			<label for="filter-search"><?php echo JText::_('COM_CONTENT_'.$this->params->get('filter_field').'_FILTER_LABEL'); ?></label>
			<input type="text" name="filter-search" id="filter-search" value="<?php echo $this->escape($this->state->get('list.filter')); ?>" onchange="document.adminForm.submit();" title="<?php echo JText::_('COM_CONTENT_FILTER_SEARCH_DESC'); ?>" />
		</div>
		<?php endif; ?>
		
		<?php if ($this->params->get('show_pagination_limit')) : ?>
		<div>
			<?php echo JText::_('JGLOBAL_DISPLAY_NUM'); ?>
			<?php echo $this->pagination->getLimitBox(); ?>
		</div>
		<?php endif; ?>
		
	</div>
	<?php endif; ?>

	<table class="zebra" border="0" cellspacing="0" cellpadding="0">

		<?php if ($this->params->get('show_headings')) : ?>
		<thead>
			<tr>
				<th align="left"><?php  echo JHtml::_('grid.sort', 'JGLOBAL_TITLE', 'a.title', $listDirn, $listOrder) ; ?></th>
				
				<?php if ($date = $this->params->get('list_show_date')) : ?>
				<th align="left" width="25%">
					<?php if ($date == "created") : ?>
						<?php echo JHtml::_('grid.sort', 'COM_CONTENT_'.$date.'_DATE', 'a.created', $listDirn, $listOrder); ?>
					<?php elseif ($date == "modified") : ?>
						<?php echo JHtml::_('grid.sort', 'COM_CONTENT_'.$date.'_DATE', 'a.modified', $listDirn, $listOrder); ?>
					<?php elseif ($date == "published") : ?>
						<?php echo JHtml::_('grid.sort', 'COM_CONTENT_'.$date.'_DATE', 'a.publish_up', $listDirn, $listOrder); ?>
					<?php endif; ?>
				</th>
				<?php endif; ?>
				
				<?php if ($this->params->get('list_show_author', 1)) : ?>
				<th align="left" width="20%"><?php echo JHtml::_('grid.sort', 'JAUTHOR', 'author', $listDirn, $listOrder); ?></th>
				<?php endif; ?>
				
				<?php if ($this->params->get('list_show_hits', 1)) : ?>
				<th align="center" width="5%"><?php echo JHtml::_('grid.sort', 'JGLOBAL_HITS', 'a.hits', $listDirn, $listOrder); ?></th>
				<?php endif; ?>
				
			</tr>
		</thead>
		<?php endif; ?>

		<tbody>
		
			<?php foreach ($this->items as $i => $article) : ?>
			<tr class="<?php if ($i % 2 == '0') { echo 'odd'; } else { echo 'even'; } ?>">
			
				<?php if (in_array($article->access, $this->user->getAuthorisedViewLevels())) : ?>
					
					<td>
						<a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($article->slug, $article->catid)); ?>"><?php echo $this->escape($article->title); ?></a>
						<?php if ($article->params->get('access-edit')) echo JHtml::_('icon.edit', $article, $params); ?>
					</td>
					
					<?php if ($this->params->get('list_show_date')) : ?>
					<td><?php echo JHtml::_('date', $article->displayDate, $this->escape($this->params->get('date_format', JText::_('DATE_FORMAT_LC3')))); ?></td>
					<?php endif; ?>
					
					<?php if ($this->params->get('list_show_author', 1) && !empty($article->author )) : ?>
					<td>
					
						<?php
							$author =  $article->author;
							$author = ($article->created_by_alias ? $article->created_by_alias : $author);
	
							if (!empty($article->contactid ) &&  $this->params->get('link_author') == true) {
								echo JHtml::_('link', JRoute::_('index.php?option=com_contact&view=contact&id='.$article->contactid), $author);
							} else {
								echo $author;
							}
						?>

					</td>
					<?php endif; ?>
					
					<?php if ($this->params->get('list_show_hits', 1)) : ?>
					<td align="center"><?php echo $article->hits; ?></td>
					<?php endif; ?>
				
				<?php else : // Show unauth links ?>
				
					<td colspan="4">
						<?php
							echo $this->escape($article->title).' : ';
							$menu		= JFactory::getApplication()->getMenu();
							$active		= $menu->getActive();
							$itemId		= $active->id;
							$link = JRoute::_('index.php?option=com_users&view=login&Itemid='.$itemId);
							$returnURL = JRoute::_(ContentHelperRoute::getArticleRoute($article->slug));
							$fullURL = new JURI($link);
							$fullURL->setVar('return', base64_encode($returnURL));
						?>
						<a href="<?php echo $fullURL; ?>"><?php echo JText::_( 'COM_CONTENT_REGISTER_TO_READ_MORE' ); ?></a>
					</td>
					
				<?php endif; ?>
				
			</tr>
			<?php endforeach; ?>
			
		</tbody>
		
	</table>

	<?php // Code to add a link to submit an article. ?>
	<?php if ($this->category->getParams()->get('access-create')) : ?>
	<p class="edit"><?php echo JHtml::_('icon.create', $this->category, $this->category->params); ?> <?php echo JText::_('TPL_WARP_CREATE_ARTICLE'); ?></p>
	<?php  endif; ?>

	<?php if (($this->params->def('show_pagination', 2) == 1  || ($this->params->get('show_pagination') == 2)) && ($this->pagination->get('pages.total') > 1)) : ?>
	<?php echo $this->pagination->getPagesLinks(); ?>
	<?php endif; ?>

	<input type="hidden" name="filter_order" value="" />
	<input type="hidden" name="filter_order_Dir" value="" />
	<input type="hidden" name="limitstart" value="" />

</form>
<?php endif; ?>