Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //tep_draw_categories_tree BY JOHN BAROUNIS
- function tep_draw_categories_tree($drawExpanded=false,$root_id = 0,$mainUlClass='',$submenuUlClass='submenu'){
- global $languages_id,$cPath_array;
- //GET ALL CATEGORIES
- $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");
- $items = array();
- while ($categories = tep_db_fetch_array($categories_query)) {
- $items[$categories['categories_id']] = array('name' => $categories['categories_name'], 'parent_id' => $categories['parent_id'], 'id' => $categories['categories_id']);
- }
- $citems=count($items);
- if($citems<=0) return '';
- elseif($citems==1) $children[] = $items; //in case we have one category item without subcategories, rare but possible
- else foreach( $items as $item ) $children[$item['parent_id']][] = $item;
- // loop will be false if the root has no children (i.e., an empty categories!)
- $loop = !empty( $children[$root_id] );
- $parent = $root_id;
- $parent_stack = array();
- $html=array();//store html code
- $stack=array();//helper array so to know the current level
- $pic=''; //products_in_category string
- $html[]='<ul class="'.$mainUlClass.'">';
- while ( $loop && ( ( $option = each( $children[$parent] ) ) || ( $parent > $root_id ) ) ){
- if ( $option === false ){
- $parent = array_pop( $parent_stack );
- $html[] = str_repeat( "\t", ( count( $parent_stack ) + 1 ) * 2 ) . '</ul>';
- $html[] = str_repeat( "\t", ( count( $parent_stack ) + 1 ) * 2 - 1 ) . '</li>';
- array_pop( $stack );
- }elseif ( !empty( $children[$option['value']['id']] ) ){
- $tab = str_repeat( "\t", ( count( $parent_stack ) + 1 ) * 2 - 1 );
- $stack[]=$option['value']['id'];
- $rt=$root_id>0 ? $root_id.'_' : '';
- $cpath_new=count($stack)<=0 ? 'cPath='.$rt.$option['value']['id'] : 'cPath='.$rt.implode('_',$stack);
- $html[]=$tab.'<li><a href="'.tep_href_link(FILENAME_DEFAULT, $cpath_new).'">';
- if (SHOW_COUNTS == 'true') { //THIS SHOULD BE CHANGED SO NOT TO USE tep_count_products_in_category WHICH IS RECURSIVE
- $products_in_category = tep_count_products_in_category($option['value']['id']);
- if ($products_in_category > 0) {
- $pic=' (' . $products_in_category . ')';
- }
- }
- $sm=0;
- if((isset($cPath_array) && in_array($option['value']['id'], $cPath_array))){
- $sm=1;
- $html[]='<strong>'.stripslashes($option['value']['name']).'->'.$pic.'</strong>';
- }else{
- $html[]=stripslashes($option['value']['name']).'->'.$pic;
- }
- $html[]='</a>';
- $html[] = $tab . "\t" . '<ul class="'.$submenuUlClass.'" style="'.($sm!==1 && !$drawExpanded ?'display:none;':'').'">';
- $parent_stack[]=$option['value']['parent_id'];
- $parent = $option['value']['id'];
- }else{
- $rt=$root_id>0 ? $root_id.'_' : '';
- $cpath_new= count($stack)<=0 ? 'cPath='.$rt.$option['value']['id'] : 'cPath='.$rt.implode('_',$stack).'_'.$option['value']['id'];
- $html[]=str_repeat( "\t", ( count( $parent_stack ) + 1 ) * 2 - 1 ).'<li><a href="'.tep_href_link(FILENAME_DEFAULT, $cpath_new).'" >';
- if (SHOW_COUNTS == 'true') { //THIS SHOULD BE CHANGED SO NOT TO USE tep_count_products_in_category WHICH IS RECURSIVE
- $products_in_category = tep_count_products_in_category($option['value']['id']);
- if ($products_in_category > 0) {
- $pic=' (' . $products_in_category . ')';
- }
- }
- if (isset($cPath_array) && in_array($option['value']['id'], $cPath_array)) {
- $html[]='<strong>'.stripslashes($option['value']['name']).$pic.'</strong>';
- }else{
- $html[]=stripslashes($option['value']['name']).$pic;
- }
- $html[]='</a></li>';
- }
- }
- $html[]='</ul>';
- echo implode( "\r\n", $html );
- }
- //tep_draw_categories_tree BY JOHN BAROUNIS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement