<?php
if (!defined('IN_ASC'))
{
    die('Hacking attempt');
}

/**
 * 取得menu
 * @return  array 
 */

function get_menu()
{
    include_once('includes/inc_menu.php');

    include_once('includes/inc_priv.php');

    global $_LANG;
    global $_CFG;
    
    foreach ($modules AS $key => $value)
    {
        ksort($modules[$key]);
    }

    ksort($modules);

    foreach ($modules AS $key => $val)
    {
        $menus[$key]['label'] = $_LANG[$key];

        if (is_array($val))
        {
            foreach ($val AS $k => $v)
            {
                if ( isset($purview[$k]))
                {
                    if (is_array($purview[$k]))
                    {
                        $boole = false;
                        foreach ($purview[$k] as $action)
                        {
                             $boole = $boole || admin_priv($action, '', false);
                        }
                        if (!$boole)
                        {
                            continue;
                        }

                    }
                    else
                    {
                        if (! admin_priv($purview[$k], '', false))
                        {
                            continue;
                        }
                    }
                }
                if ($k == 'ucenter_setup' && $_CFG['integrate_code'] != 'ucenter')
                {
                    continue;
                }
                $menus[$key]['children'][$k]['label']  = $_LANG[$k];
                $menus[$key]['children'][$k]['action'] = $v;
            }
        }
        else
        {
            $menus[$key]['action'] = $val;
        }

        // 如果children的子元素長度為0則刪除該組
        if(empty($menus[$key]['children']))
        {
            unset($menus[$key]);
        }

    }
    return $menus;
}