<?php 
    $i = 0;
    $all[0]['idparent']= '';
    if(isset($_SERVER['REDIRECT_URL']))
		$tablica = explode('/', $_SERVER['REDIRECT_URL']);

    foreach($menu_items as $menu_item){

        $current='';
        if($menu_item['active']){
            if(isset($tablica[3])){
                //echo $menu_item['friendlyurl'].'-'.$menu_item['idelement'].'.html<br/>';
                if($tablica[3] == $menu_item['friendlyurl'].'-'.$menu_item['idelement'].'.html' || $tablica[3] == $menu_item['friendlyurl'].'.html'){
                    $current=array( 'idparent'=>$menu_item['idparent'],
                                    'idmenu_items'=>$menu_item['idmenu_items']
                                  );
                }elseif(isset($subarticle)){
                    if($tablica[3] == $article['friendlyurl'].'-'.$article['idarticles'].'.html' && $subarticle['friendlyurl'].'-'.$subarticle['idarticles'].'.html' == $menu_item['friendlyurl'].'-'.$menu_item['idelement'].'.html'){
                        $current=array( 'idparent'=>$menu_item['idparent'],
                                        'idmenu_items'=>$menu_item['idmenu_items']
                                      );
                    }elseif(isset($parent)){
                        if($parent['friendlyurl'].'-'.$parent['idarticles'].'.html' == $menu_item['friendlyurl'].'-'.$menu_item['idelement'].'.html'){
                            $current=array( 'idparent'=>$menu_item['idparent'],
                                            'idmenu_items'=>$menu_item['idmenu_items']
                                          );
                        }
                    }
                }
            }elseif(isset($tablica[2])){
                if($tablica[2] == $menu_item['friendlyurl'].'-'.$menu_item['idelement'].'.html' || $tablica[2] == $menu_item['friendlyurl']){
                    $current=array( 'idparent'=>$menu_item['idparent'],
                                    'idmenu_items'=>$menu_item['idmenu_items']
                                  );
                }
            }else{
                if('' == $menu_item['friendlyurl']){
                    $current=array( 'idparent'=>$menu_item['idparent'],
                                    'idmenu_items'=>$menu_item['idmenu_items']
                                  );
                }
            }
            if($current!=''){
                $all[$i] = $current;
                break;
            }
        }
    }
    //przygotowanie drzewka menu
    if(isset($all)){
        $i++;
         do{
            $child = false;
            foreach($menu_items as $menu_item){
                if($all[$i-1]['idparent']==$menu_item['idmenu_items']){
                    $all[$i] = array( 'idparent'=>$menu_item['idparent'],
                                    'idmenu_items'=>$menu_item['idmenu_items']
                                  );
                    if($all[$i]['idparent']!=''){
                       $child = true;
                       $i++;
                       break;
                    }
                }
            }
         }while($child);
         foreach($menu_items as $menu_item){
			if($menu_item['active']){
                if($menu_item['idparent']==null){
                    echo '<div class="menu-footer-item">';
                    switch($menu_item['type']){
                        case 'article':
                            echo '<a href="/'.strtolower($this->site['lang']['skrot']).'/'.$this->site['linki_do_sitemapy']['artykul'].'/'.$menu_item['friendlyurl'].'-'.$menu_item['idelement'].'.html">'.$menu_item['elementname'].'</a>';
                            break;
                        case 'gallery':
                            echo '<a href="/'.strtolower($this->site['lang']['skrot']).'/'.$this->site['linki_do_sitemapy']['galeria'].'/'.$menu_item['friendlyurl'].'-'.$menu_item['idelement'].'.html">'.$menu_item['elementname'].'</a>';
                            break;
                        case 'news':
                            echo '<a href="/'.strtolower($this->site['lang']['skrot']).'/'.$this->site['linki_do_sitemapy']['news'].'/'.$menu_item['friendlyurl'].'-'.$menu_item['idelement'].'.html">'.$menu_item['elementname'].'</a>';
                            break;
                        case 'none':
                            if($menu_item['friendlyurl']!=''){
                                echo '<a href="/'.strtolower($this->site['lang']['skrot']).'/'.$menu_item['friendlyurl'].'">'.$menu_item['elementname'].'</a>';
                            }else{
                                echo '<a href="/">'.$menu_item['elementname'].'</a>';
                            }
                            break;
                        case 'product_category':
                            echo 'a href="/'.strtolower($this->site['lang']['skrot']).'/'.$menu_item['friendlyurl'].'.html">'.$menu_item['elementname'].'</a>';
                            break;
                        case 'product':
                            echo '<a href="/'.strtolower($this->site['lang']['skrot']).'/'.$this->site['linki_do_sitemapy']['produkt'].'/'.$menu_item['friendlyurl'].'-'.$menu_item['idelement'].'.html">'.$menu_item['elementname'].'</a>';
                            break;
                    }
                    echo '</div>';
                }
            }
         }
    }
    echo '<div class="menu-footer-item"><a href="http://panel.networds.pl/">PANEL KLIENTA</a></div><div class="clear_it"></div>'
 ?> 