Tsimi

category tree inside html_output.php

Sep 29th, 2015
21
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function tep_show_tree_box($root_id = 0,$mainUlClass='navMain nav-list',$submenuUlClass='navMain nav-list collapse'){
  2.     global $languages_id,$cPath_array, $datas;
  3.     $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");
  4.     $items = array();
  5.     while ($categories = tep_db_fetch_array($categories_query))  {
  6.         $items[$categories['categories_id']] = array('name' => $categories['categories_name'], 'parent_id' => $categories['parent_id'], 'id' => $categories['categories_id']);
  7.     }
  8.     $citems=count($items);
  9.    
  10.     if($citems<=0) return '';
  11.     elseif($citems==1) $children[] = $items; //in case we have one category item without subcategories, rare but possible
  12.     else foreach( $items as $item ) $children[$item['parent_id']][] = $item;
  13.         $loop = !empty( $children[$root_id] );
  14.         $parent = $root_id;
  15.         $parent_stack = array();
  16.         $stack=array();//helper array so to know the current level
  17.     $pic=''; //products_in_category string
  18.        
  19.         // MAINMENU
  20.         $datas .='<ul class="'.$mainUlClass.'">';
  21.         while ( $loop && ( ( $option = each( $children[$parent] ) ) || ( $parent > $root_id ) ) ){
  22.             if ( $option === false ){
  23.                 $parent = array_pop( $parent_stack );
  24.                 $datas .= '</ul>';
  25.                 $datas .= '</li>';
  26.                 array_pop( $stack );
  27.             }elseif ( !empty( $children[$option['value']['id']] ) ){
  28.                 $stack[]=$option['value']['id'];
  29.                 $rt=$root_id>0 ? $root_id.'_' : '';
  30.                 $cpath_new=count($stack)<=0 ? 'cPath='.$rt.$option['value']['id'] : 'cPath='.$rt.implode('_',$stack);
  31.                 $datas .= '<li><a href="'.tep_href_link(FILENAME_DEFAULT, $cpath_new).'">';
  32.                 $sm=0;        
  33.                 if((isset($cPath_array) && in_array($option['value']['id'], $cPath_array))){
  34.                     $sm=1;
  35.                     $datas .='<strong>'.stripslashes($option['value']['name']).'</strong>';
  36.                 }else{
  37.                     $datas .=stripslashes($option['value']['name']);
  38.                 }
  39.                 $datas .='</a><a href="#" class="switch"><span class="glyphicon glyphicon-plus-sign '.($sm==1?'glyphicon-minus-sign':'').'"></span></a>';
  40.                 // SUBMENU
  41.                 $datas .= '<ul class="'.$submenuUlClass.' '.($sm==1?'in':'').' ">';
  42.                 $parent_stack[]=$option['value']['parent_id'];
  43.                 $parent = $option['value']['id'];
  44.           }else{
  45.                 $rt=$root_id>0 ? $root_id.'_' : '';
  46.                 $cpath_new= count($stack)<=0 ? 'cPath='.$rt.$option['value']['id'] : 'cPath='.$rt.implode('_',$stack).'_'.$option['value']['id'];
  47.                 $datas .= '<li><a href="'.tep_href_link(FILENAME_DEFAULT, $cpath_new).'" >';
  48.  
  49.                 if (isset($cPath_array) && in_array($option['value']['id'], $cPath_array)) {
  50.                     $datas .='<strong>'.stripslashes($option['value']['name']).'</strong>';
  51.                 }else{
  52.                     $datas .=stripslashes($option['value']['name']);
  53.                 }
  54.                 $datas .='</a></li>';  
  55.         }
  56.        }
  57.         $datas .='</ul>';
  58.        
  59.       return $datas;
  60.   }
RAW Paste Data