<?php

if (IS_POST)
{
    $order = intval($_POST['order']);
    $name = postlangdatas('name');
    $doc = postlangdatas('doc');

    $lastid = $conf['sys_menu_lastid'] + 1;
    if ($_POST['menumod'] == 'home_')
    {

        $conf['sys_menus'][$lastid] = array('mod' => $_POST['menumod'], 'name' => $name,
            'doc' => $doc, 'order' => intval($_POST['order']), 'show' => array('main'), );
    } else
        if ($_POST['menumod'] == 'link_')
        {

            $conf['sys_menus'][$lastid] = array('mod' => $_POST['menumod'], 'name' => $name,
                'doc' => $doc, 'order' => intval($_POST['order']), 'blank' => !empty($_POST['blank']),
                'pid' => intval($_POST['pid']), 'show' => array('main'),
                'link_' => $_POST['link_'], 'current_mod' => trim($_POST['current_mod']),
                'current_mid' => !empty($_POST['current_mid']), );
        } elseif ($_POST['menumod'] == 'fun_')
        {
            if (empty($_POST['fun_']) || !isset($conf['sys_funs'][$_POST['fun_']]))
                yun_error('功能未指定');
            $conf['sys_menus'][$lastid] = array('mod' => $_POST['menumod'], 'name' => $name,
                'doc' => $doc, 'order' => intval($_POST['order']), 'blank' => !empty($_POST['blank']),
                'pid' => intval($_POST['pid']), 'show' => array('main'), 'fun_' => $_POST['fun_'],
                'tplpf_c' => $_POST['tplpf_c'], );
        } elseif ($_POST['menumod'] == 'page_')
        {
            ereg("^[a-z]{3,}$", $_POST['page_']) or yun_error('标识限定为小写字母,至少3位');
            foreach ($conf['sys_menus'] as $k => $v)
            {
                if ($v['page_'] == $_POST['page_'])
                    yun_error('标识已存在');
            }
            module_exists($_POST['page_']) && yun_error('非法标识名');
            isset($conf['sys_subjects'][$_POST['page_']]) && yun_error('非法标识名');
            $conf['sys_menus'][$lastid] = array('mod' => $_POST['menumod'], 'name' => $name,
                'doc' => $doc, 'order' => intval($_POST['order']), 'blank' => !empty($_POST['blank']),
                'pid' => intval($_POST['pid']), 'show' => array('main'), 'page_' => $_POST['page_'],
                'tplpf_c' => $_POST['tplpf_c'], );
            $db->query("insert into " . PF . "page (id,post_time) values('" . $lastid .
                "','" . TIME . "')");
        } else
        {

            module_exists($_POST['menumod']) or yun_error('模块不存在');
            $conf['sys_menus'][$lastid] = array('name' => $name, 'doc' => $doc, 'order' =>
                intval($_POST['order']), 'blank' => !empty($_POST['blank']), 'pid' => intval($_POST['pid']),
                'show' => array('main'), 'mod' => $_POST['menumod'], );
            $conf['sys_menus'][$lastid] += do_apply('menu_post', 'array_merge', $_POST['menumod']);
        }

        $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_menu_lastid', $lastid);
    set_conf('sys_menus', $conf['sys_menus']);
    yun_succeed('创建成功', url(RPGM . 'menu/'), true);
}
$arr = array_pop($conf['sys_menus']);
arg(++$arr['order']);

?>