<?php
defined('_JEXEC') or die('Restricted access');
function mod_adsmanager_menu_categories($id, $level, &$children, $itemid, $current_list, $expand, $order, $displaynumads) {
global $cur_template, $option;
if (@$children[$id]) {
foreach ($children[$id] as $row) {
if ($level == 0) {
?>
<tr align="left"><td>
<?php
$class='menu_ads';
} else {
echo '<div style="padding-left: '.($level*4).'px"><span id="arrow"></span>';
$class='sublevel';
}
if ($option)
$link = sefRelToAbs($option."?page=show_category&catid=".$row->id);
else
$link = sefRelToAbs("index.php?option=com_adsmanager&page=show_category&catid=".$row->id);
if ($children[$id] == $row->id)
$class='menu_ads_1';
if ($displaynumads == 1) {
$num = $row->num_ads;
$nums = number_format($num,0,'.',' ');
echo '<a href="'.$link.'" class="'.$class.'">'.$row->name.'<sup style="font-weight:normal;color:#999;"> '.$nums.'</sup></a>';
} else {
echo '<a href="'.$link.'" class="'.$class.'">'.$row->name.'</a>';
}
if (@$current_list[count($current_list) - 1 - $level] == $row->id) {
mod_adsmanager_menu_categories($row->id, $level + 1, $children, $itemid, $current_list, $expand, $order, $displaynumads);
}
if ($level == 0) {
?>
</td></tr>
<?php
} else {
?>
</div>
<?php
}
}
}
}
function calc_nb_ads($id, &$children, $sqltype) {
switch($sqltype) {
case 1:
$nb_ads = 0;
if (@$children[$id]) {
$nb = count($children[$id]);
for($i=0; $i < $nb; $i++) {
$children[$id][$i]->num_ads += calc_nb_ads($children[$id][$i]->id, $children, $sqltype);
$nb_ads += $children[$id][$i]->num_ads;
}
}
return $nb_ads;
break;
case 0:
$nb_ads = 0;
if (@$children[$id]) {
$nb = count($children[$id]);
for($i = 0; $i < $nb; $i++) {
if (!isset($children[$id][$i]->not_empty))
$children[$id][$i]->num_ads = 0;
$children[$id][$i]->num_ads += calc_nb_ads($children[$id][$i]->id,$children,$sqltype);
if (isset($children[$id][$i]->not_empty))
$nb_ads += $children[$id][$i]->num_ads;
}
}
return $nb_ads;
break;
}
}
/****************************************************/
$itemid = intval($params->get('default_itemid', mosGetParam($_GET, 'Itemid', 0)));
$option = $params->get('option', '');
$catid = intval(mosGetParam($_GET, 'catid', -1));
$expand = intval(mosGetParam($_GET, 'expand', 0));
$order = intval(mosGetParam($_GET, 'order', 0));
$displaynumads = $params->def('displaynumads', 1);
$sqltype = $params->def('sqltype', 1);
$database->setQuery("SELECT c.*, COUNT(a.id) AS num_ads ".
"FROM #__adsmanager_categories AS c ".
"LEFT JOIN #__adsmanager_ads AS a ON a.category = c.id AND a.published = 1 ".
"WHERE c.published = 1 GROUP BY c.id ORDER BY c.parent, c.ordering");
$rows = $database->loadObjectList();
if ($database->getErrorNum()) {
echo $database->stderr();
return false;
}
// establish the hierarchy of the menu
$children = array();
$orderlist = array();
// first pass - collect children
foreach($rows as $v) {
$pt = $v->parent;
$list = @$children[$pt] ? $children[$pt] : array();
array_push($list, $v);
$children[$pt] = $list;
$orderlist[$v->id] = $v;
}
if ($displaynumads == 1)
$nb_ads = calc_nb_ads(0, $children, $sqltype);
$current_list[] = $catid;
if ($catid != -1) {
$current = $catid;
while((isset($orderlist[$current])) && ($orderlist[$current]->parent != 0)) {
$current_list[] = $orderlist[$current]->parent;
$current = $orderlist[$current]->parent;
}
}
if (file_exists($mosConfig_absolute_path.'/components/com_adsmanager/lang/lang_'.$mosConfig_lang.'.php'))
include_once($mosConfig_absolute_path.'/components/com_adsmanager/lang/lang_'.$mosConfig_lang.'.php');
else
include_once($mosConfig_absolute_path.'/components/com_adsmanager/lang/lang_english.php');
?>
<table class="moduletable_menu" width="100%" border="0" cellpadding="0" cellspacing="0">
<?php
if($option)
$link_show_all = sefRelToAbs($option."?page=show_all");
else
$link_show_all = sefRelToAbs("index.php?option=com_adsmanager&page=show_all");
?>
<?php
if ($displaynumads == 1) {
$nb_ads1 = number_format($nb_ads, 0, '.', ' ');
$all = ADSMANAGER_MENU_ALL_ADS. '<sup style="color:#666;font-weight:normal;">'.$nb_ads1.'<sup style="color:green;font-size:8px;">+'.$nb_ads_1.'</sup></sup>';
}
else
$all = ADSMANAGER_MENU_ALL_ADS;
?>
<tr align="left"><td><ul><li><a href="<?php echo $link_show_all; ?>" style="font-size:10px;"><?php echo $all; ?></a></li></ul></td></tr>
<?php
mod_adsmanager_menu_categories(0, 0, $children, $itemid, $current_list, $expand, $order, $displaynumads);
?>
</table>