<?php
class viewmenu{
    var $i= 0;
    
    function menu($status,$level,$username){
        if($username=='admin'){
          $menu = mysql_query("SELECT menu.nama ,menu.id_menu FROM menu WHERE status = '$status' ORDER BY menu.menu_order");  
        }
        else{
           $menu = mysql_query("SELECT menu.nama ,menu.id_menu FROM menu,level,level_otoritas WHERE menu.id_menu = level_otoritas.id_menu AND level.id_level = level_otoritas.id_level and menu.status = '$status' AND level.id_level = $level GROUP BY menu.id_menu ORDER BY menu.menu_order"); 
        }
        
        while ($m = mysql_fetch_array($menu)){
            $data[$i] = array(
                        'id' => $m[id_menu],
                        'nama' => $m[nama],
                        'link' => $m[link]
                     );
            
            $i++;
        }
        
        return $data;
    }
    
    function submenu($id,$level,$username){
        if($username=='admin'){
          $submenu = mysql_query("SELECT * FROM sub_menu WHERE id_menu = $id ORDER BY submenu_order");
        }
        else{
          $submenu = mysql_query("SELECT * FROM sub_menu,level,level_otoritas WHERE sub_menu.id_submenu = level_otoritas.id_submenu AND level.id_level = level_otoritas.id_level AND sub_menu.id_menu = $id AND level.id_level = $level ORDER BY sub_menu.submenu_order"); 
        }
        
        while ($sm = mysql_fetch_array($submenu)){
            $datasub[$i] = array(
                            'id' => $sm[id_submenu],
                            'nama' => $sm[nama],
                            'link' => $sm[link]
                        );
            
            $i++;
        }
        
        return($datasub);
    }
}

