Código PHP:
<?php
// no direct access
defined( '_VALID_MOS' ) or die( 'Restricted access' );
function recurseCategories($id, $level, &$children,$itemid,$option,$expand,$order,$displaynumads) {
global $cur_template,$mosConfig_absolute_path,$mosConfig_live_site;
if (@$children[$id]) {
$i=0;$first=true; // borrar si da problemas
foreach ($children[$id] as $row) {
$link = sefRelToAbs("index.php?option=com_adsmanager&page=show_category&catid=".$row->id."&Itemid=".$itemid);
if ($level == 0)
{
if ($i==0)
{
echo '<tr>';
}
?>
<td width="33%" valign="top">
<table class="adsmanager-categories" width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="cat-<?php echo $row->id ?>">
<div class="adscat-wrapper clearfix">
<div class="adscat-image">
<?php
if (file_exists($mosConfig_absolute_path."/images/$option/categories/".$row->id."cat.jpg"))
echo '<a href="'.$link.'"><img class="imgcat" src="'.$mosConfig_live_site.'/images/'.$option.'/categories/'.$row->id.'cat.jpg" alt="'.$row->name.'" /></a>';
else
echo '<a href="'.$link.'"><img class="imgcat" src="'.$mosConfig_live_site.'/images/com_adsmanager/categories/'.$row->id.'cat.jpg" alt="'.$row->name.'" /></a>';
?>
</div>
<div class="adscat-title">
<h3><a href="<?php echo $link; ?>"><?php echo $row->name; ?></a> <span>(<?php echo $row->num_ads ?>)</span></h3>
<?php
$class="mainlevel";
}
else
{
//echo '<div style="padding-left: '.($level*4).'px"><img src="templates/'.$cur_template.'/images/indent'.$level.'.png" alt="" />';
//$class="sublevel";
}
$link = sefRelToAbs("index.php?option=com_adsmanager&page=show_category&catid=".$row->id."&Itemid=$itemid");
if ($displaynumads == 1)
{
//echo '<a href="'.$link.'" class="'.$class.'" >'.$row->name.' ('.$row->num_ads.')</a>';
}
else
{
echo '<a href="'.$link.'" class="'.$class.'" >'.$row->name.'</a>';
}
if (@$current_list[count($current_list) - 1 -$level] == $row->id)
{
recurseCategories($row->id, $level+1, $children,$option,$itemid,$expand,$order,$displaynumads);
//mod_adsmanager_menu_categories($row->id, $level+1, $children,$option,$itemid,$current_list,$expand,$order,$displaynumads);
}
if ($level == 0)
{
?>
</div>
</div>
<ul class="catlist">
<?php
}
else
{
if ($first == false)
echo '</li>';
echo '<li>';
echo '<a href="'.$link.'" class="'.$class.'">'.$row->name.'</a>';
$first = false;
}
if ($level == 0)
{
recurseCategories ($row->id, $level+1, $children,$itemid,$option,$expand,$order,$displaynumads);
}
if ($level == 0)
{
?>
</ul>
</td>
</tr>
</table>
</td>
<?php
if ($i==2)
{
echo '</tr>';
}
}
$i++;
if ($i == 3) $i=0;
{
?>
</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( mosGetParam( $_GET, 'Itemid', 0 ));
$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',0);
switch ($sqltype)
{
case 1:
$database->setQuery("SELECT c.*, ".
" (SELECT count(*) ".
" FROM #__adsmanager_ads a ".
" LEFT JOIN #__adsmanager_adcat as adcat ON adcat.adid = a.id ".
" WHERE adcat.catid = c.id ".
" AND a.published = 1 ".
" ) as num_ads ".
"FROM #__adsmanager_categories as c ".
"WHERE c.published = 1 ".
"ORDER BY c.parent,c.ordering");
break;
case 0:
default:
$database->setQuery( "SELECT c.*, count(*) as num_ads,a.id as not_empty ".
"FROM #__adsmanager_ads as a ".
"LEFT JOIN #__adsmanager_adcat as adcat ON a.id = adcat.adid ".
"RIGHT JOIN #__adsmanager_categories as c ON adcat.catid = c.id ".
"WHERE c.published = 1 ".
"GROUP BY c.id ".
"ORDER BY c.parent,c.ordering");
break;
}
$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="adsmanager-categories" width="100%" border="0" cellpadding="0" cellspacing="0">
<?php
if ($displaynumads == 1)
$all = ADSMANAGER_MENU_ALL_ADS. "($nb_ads)";
else
$all = ADSMANAGER_MENU_ALL_ADS;
?>
<?php
recurseCategories (0, 0, $children,$option,$itemid,$expand,$order,$displaynumads);
?>
</table>
Lo que deseo es que en vez de tablas me genere div y he tratado lógicamente de "jugar" con los td y los tr para insertarle div y pues no logro nada bueno.
Espero no confundir y tal vez alguien me ayuda a cómo debo colocar correctamente los div para que la salida sea en div. Realmente no se nada de php y todo ese cambio lo hice testeando.
Saludos