<?php

$id = $_GET['id'];
isset($conf['sys_menus'][$id]) or yun_error('该菜单不存在');
$subject = $conf['sys_menus'][$id]['subject'];
if (IS_POST)
{
    $name = postlangdatas('name');
    $doc = postlangdatas('doc');
    $order = intval($_POST['order']);
    $conf['sys_menus'][$id]['name'] = $name;
    $conf['sys_menus'][$id]['doc'] = $doc;
    $conf['sys_menus'][$id]['order'] = intval($_POST['order']);
    if ($conf['sys_menus'][$id]['mod'] <> 'home_')
    {
        $conf['sys_menus'][$id]['blank'] = !empty($_POST['blank']);
        $conf['sys_menus'][$id]['pid'] = intval($_POST['pid']);
        if ($conf['sys_menus'][$id]['mod'] == 'link_')
        {
            $conf['sys_menus'][$id]['link_'] = $_POST['link_'];
            $conf['sys_menus'][$id]['current_mod'] = trim($_POST['current_mod']);
            $conf['sys_menus'][$id]['current_mid'] = !empty($_POST['current_mid']);
        } else
            if ($conf['sys_menus'][$id]['mod'] == 'fun_')
            {
                $conf['sys_menus'][$id]['tplpf_c'] = $_POST['tplpf_c'];
            } else
                if ($conf['sys_menus'][$id]['mod'] == 'page_')
                {
                    ereg("^[a-z]{3,}$", $_POST['page_']) or yun_error('标识限定为小写字母,至少3位');
                    foreach ($conf['sys_menus'] as $k => $v)
                    {
                        if ($k <> $id && $v['page_'] == $_POST['page_'])
                            yun_error('标识已存在');
                    }
                    module_exists($_POST['page_']) && yun_error('非法标识名');
                    isset($conf['sys_subjects'][$_POST['page_']]) && yun_error('非法标识名');
                    $conf['sys_menus'][$id]['page_'] = $_POST['page_'];
                    $conf['sys_menus'][$id]['tplpf_c'] = $_POST['tplpf_c'];
                } else
                {
                    $conf['sys_menus'][$id] = do_apply('menu_post', 'array_merge', $conf['sys_menus'][$id]['mod']) +
                        $conf['sys_menus'][$id];
                }
    }

    $arr = array();
    foreach ($conf['sys_menus'] as $k => $v)
    {
        $arr[$v['order']][$k] = $v;
    }
    ksort($arr);
    $conf['sys_menus'] = array();
    foreach ($arr as $v)
    {
        foreach ($v as $key => $val)
        {
            $conf['sys_menus'][$key] = $val;
        }
    }
    set_conf('sys_menus', $conf['sys_menus']);
    yun_succeed('修改成功', url(RPGM . 'menu/'), true);
}
arg($id);

?>