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

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

$class					= ' class="first"';
$empty_categories_if	= 0;
$empty_categories_else	= 0;

if (count($this->items[$this->parent->id]) > 0 && $this->maxLevelcat != 0) {
	foreach($this->items[$this->parent->id] as $id => $item) {
		if($this->params->get('show_empty_categories_cat') || $item->numitems || count($item->getChildren())) {
			$empty_categories_if	= 1;
			if(!isset($this->items[$this->parent->id][$id + 1])) {
				$class = ' class="last"';
			}
		?>
		<div class="adodis-blog_bgitem_container" style="background-color:<?php echo $this->settings->bg_color;?>;" >
			<?php $class = ''; ?>
			<span class="item-title">
				<a href="<?php echo JRoute::_(AdodisBlogHelperRoute::getCategoryRoute($item->id));?>">
					<h1>
					<?php
					echo $this->escape($item->title);
					?>
					</h1>
				</a>
			</span>

			<?php
			if ($this->params->get('show_subcat_desc_cat') == 1) {

				if ($item->description) {
				?>
					<div class="category-desc">
						<?php echo JHtml::_('content.prepare', $item->description); ?>
					</div>
				<?php
				}
			}
			if ($this->params->get('show_cat_items_cat') == 1) {
			?>
				<dl class="newsfeed-count">
					<dt>
						<?php echo JText::_('COM_ADODISBLOG_CAT_NUM'); ?>
					</dt>
					<dd>
						<?php echo $item->numitems; ?>
					</dd>
				</dl>
			<?php
			}
			if(count($item->getChildren()) > 0) {
				$this->items[$item->id] = $item->getChildren();
				$this->parent = $item;
				$this->maxLevelcat--;
				echo $this->loadTemplate('items');
				$this->parent = $item->getParent();
				$this->maxLevelcat++;
			}
		} else {
			$empty_categories_else	= 1;
		}
		?>
		</div>
		<?php
	}
} else {
	JError::raiseNotice(404, JText::_('COM_ADODISBLOG_ERROR_CATEGORIES_NOT_FOUND'));
}

if( $empty_categories_else == 1 && $empty_categories_if == 0 ) {
	if( !$this->params->get('show_empty_categories_cat') ) {
		JError::raiseNotice(404, JText::_('COM_ADODISBLOG_ERROR_EMPTYCATEGORIES'));
	}
}
?>