<?php
/**
* 菜单管理列表
* @author moufer<moufer@163.com>
* @copyright www.modoer.com
* @version $Id menulist.inc.php $
*/
(!defined('IN_ADMIN') || !defined('IN_MUDDER')) && exit('Access Denied');

if(!check_submit('dosubmit')) {
  
    $total = $db->get_value("SELECT COUNT(*) FROM {$dbpre}menus WHERE flag='website' AND isfolder=0");
    if($total > 0) {
        $limit = get_limit($page, $offset=10);
        $multipage = multi($total, $offset, $page, 'admincp.php?action='.$action.'&file='.$file);
        $query = $db->query("SELECT * FROM {$dbpre}menus ORDER BY listorder,menuid LIMIT $limit");
    }
    include cptpl('menulist');

} else {

    if($newmenu['title']) {
        if(empty($newmenu['url'])) {
            cpmsg('未填写新增地址，请返回填写。');
        }
        $newmenu['listorder'] = intval($newmenu['listorder']);
        $newmenu['flag'] = 'website';
        $db->insert_new($dbpre."menus", $newmenu);
    }

    if(is_array($menuids) && !empty($menuids)) {
        $ids = "'".implode("','", $menuids)."'";
        $db->query("DELETE FROM {$dbpre}menus WHERE menuid IN ($ids)");
    }

    if(is_array($menulist) && !empty($menulist)) {
        foreach($menulist as $key => $value) {
            $value['listorder'] = intval($value['listorder']);
            $db->update_new($dbpre."menus","menuid='$key'",$value);
        }
    }

    cache_menus();
    cpmsg("菜单更新完毕！");

}
?>