PHP-Code:
<?php
/* -----------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------*/
global $lastlevel;
include_once(DIR_WS_INCLUDES.'../smartyfuncs.php');
function getNewIndex($cat){
global $catindexshow;
global $newcatindex;
global $maxlevel;
for ($i=0;$i<count($catindexshow);$i++){
$category= $catindexshow[$i];
if ($category['parent_id']==$cat){
if (!$maxlevel||($category['parent_id']!=0)) {
$newcatindex[]= $category;
}
getNewIndex($category['categories_id']);
}
}
}
function getCatIndexForLevel($cat){
global $catindexshow;
$catindexshow= array();
global $maxlevel;
if ($cat!=0){
$maxlevel= true;
} else {
$maxlevel= false;
}
$level=0;
$parent= $cat;
if (!$parent){
$parent=0;
}
if ($parent > 0){
$query= "select c.categories_id, cd.categories_name from categories c, categories_description cd where c.parent_id='$parent' and c.categories_status='1' and cd.language_id='2' and cd.categories_id=c.categories_id order by c.sort_order,cd.categories_name";
$res= xtc_db_query($query);
if ($res){
while ($resarr= mysql_fetch_assoc($res)) {
$catindexshow[]= array('parent_id'=>$parent,
'categories_id'=>$resarr['categories_id'],
'categories_name'=>$resarr['categories_name'],
'level'=> $level );
}
}
$level=1;
}
//create index
do {
$query= "select parent_id from categories where categories_id='$cat'";
$res= xtc_db_query($query);
if ($res){
$resarr= mysql_fetch_assoc($res);
$parent= $resarr['parent_id'];
} else {
$parent= 0;
}
$query= "select c.categories_id, cd.categories_name from categories c, categories_description cd where c.parent_id='$parent' and c.categories_status='1' and cd.language_id='2' and cd.categories_id=c.categories_id order by c.sort_order,cd.categories_name";
$res= xtc_db_query($query);
if ($res){
while ($resarr= mysql_fetch_assoc($res)) {
$catindexshow[]= array('parent_id'=>$parent,
'categories_id'=>$resarr['categories_id'],
'categories_name'=>$resarr['categories_name'],
'level'=> $level );
}
}
$level++;
$cat= $parent;
} while ($parent>0);
global $newcatindex;
$newcatindex= array();
getNewIndex(0);
/* print_r($catindexshow);
print '<br><br>';
print_r($newcatindex);
print '<br><br>';
die(); */
}
function xtc_show_category($counter,$cat=null,$lastlevel=0) {
global $foo, $categories_string, $id, $lastlevel, $newcatindex;
$catid= $id[count($id)-1];
$level= getCatIndexForLevel($catid);
$img_1=' ';
$categories_string= "<ul>\n";
$lastlevel= $newcatindex[0]['level'];
for ($i=0; $i<count($newcatindex); $i++){
$category= $newcatindex[$i];
if ($category['level']<$lastlevel){
$categories_string .= "<ul>\n";
} elseif ($category['level']>$lastlevel){
for ($j= $lastlevel; $j < $category['level']; $j++){
$categories_string .= "</ul></li>\n";
}
}
if (in_array($category['categories_id'],$id)){
$categories_string .= "<li><b>".$category['categories_name']."</b>";
if ($category['level']==0||$category['level']==1){
$categories_string .= "</li>";
}
} else {
$categories_string .= '<li><a href="';
$cPath_new=xtc_category_link($category['categories_id'],$category['categories_name']);
$categories_string .= xtc_href_link(FILENAME_DEFAULT, $cPath_new);
$categories_string .= '" />';
if ($cat) {
$categories_string .= $img_1;
}
$categories_string .= $category['categories_name'].'</a></li>';
}
$categories_string .= "\n";
$lastlevel= $category['level'];
}
for ($i=$newcatindex[$i-1]['level']-1;$i<$level;$i++){
$categories_string .= "</ul>\n";
}
$categories_string .= "</ul>\n";
}
?>
HTML :
<!-- >> Left Navigation -->
<div id="leftnav">
<div class="holder">
<div class="box">
<h2><i></i><u></u>Kategorien</h2>
<ul>
<li><a href="#">CPU</a></li>
<li><a href="#">Kühler</a></li>
<li><a href="#">RAM</a></li>
<li><a href="#" class="on">Mainboard</a>
<ul>
<li><a href="#">ATX</a></li>
<li><a href="#">E-ATX Something Long Enough To Go On Second Line</a></li>
<li><a href="#">F-ATX</a></li>
<li><a href="#" class="on">M-ATX</a>
<ul>
<li><a href="#">M-ATX SUB1</a></li>
<li><a href="#" class="on">M-ATX SUB2</a>
<ul>
<li><a href="#">M-ATX SUB21</a></li>
<li><a href="#">M-ATX SUB22 Something Long Enough To Go On Second Line</a></li>
<li><a href="#">M-ATX SUB23</a></li>
<li><a href="#" class="on">M-ATX SUB24</a></li>
<li><a href="#">M-ATX SUB25</a></li>
</ul>
</li>
<li><a href="#">M-ATX SUB3</a></li>
<li><a href="#">M-ATX SUB4 Something Long Enough To Go On Second Line</a></li>
<li><a href="#">M-ATX SUB5</a></li>
</ul>
</li>
<li><a href="#">BTX</a></li>
<li><a href="#">mBTX</a></li>
<li><a href="#">SSI</a></li>
</ul>
</li>
<li><a href="#">wewe</a></li>
<li><a href="#">teste3</a></li>
</ul>
</div>