<?php
/*******************************************************************
 * 版权协议：2009-2019
 * 版权所有: PHP-北京金南曦网络技术有限公司旗下PHPWMS，PHP商城系统技术支持中心http://www.php188.net，并保留所有权利。 
* PHP商城系统网址: http://www.php188.com
 * PHPWMS系统网址：http://www.phpwms.com
 * 销售电话：010-87875088
 * 销售电话：010-87875188 
*------------------------------------------------------------------
 * 这不是一个完全免费软件！您只能在不用于商业目的的前提下对程序代码进
 * 行修改和使用；不允许对程序代码以任何形式任何目的的再发布。
 *------------------------------------------------------------------
 * 文件名称：admincp.php
 * 摘　　要：菜单
 * 适用范围：PHPWMS 1.0
 * 版　　本：1.0
 *------------------------------------------------------------------
 * Script Written By phpwms项目组
 * 最后更新： 2009-09-24 phpwms 由PHP金南曦网络技术有限公司整理发布
 *******************************************************************/
require 'init.php';
require 'admin.lib.php';
$action = $_GET['action'];
$adminid = to_int($_GET['admin_id']);
if(empty($action) || isset($frames)) {
	parse_str($_SERVER['QUERY_STRING'], $getarray);
	$extra = $and = '';
	foreach($getarray as $key => $value) {
		if($key == 'action' && in_array($value, array('header', 'menu'))) {
			$extra .= $and.$key.'=home';
		} elseif(!in_array($key, array('a_id', 'frames'))) {
			@$extra .= $and.$key.'='.rawurlencode($value);
			$and = '&';
		}
	}
	$extra = $extra && $action ? $extra : (!empty($runwizard) ? 'action=runwizard' : 'action=home');
	$tpl->display('main.tpl');
}
if($action == 'menu') {
	$rs = get_models();
	$temp = array();
	foreach ($rs as $k=>$v){
		switch ($rs[$k]['en_name']){
			case 'article':
				if(getAdminPri('3100')){
					$v_name = $rs[$k]['cn_name'].'管理';
							$cnltype= '3100';
							if (getAdminPri('3101')) { 
								$cnlname_1 = $rs[$k]['cn_name']."频道";
								$cnlurl_1 ='admincp.php?action=channel&channel_type='.$rs[$k]['id']; 
							}
							if (getAdminPri('3102')) { 
								$cnlname_2 = "分类管理";
								$cnlurl_2 ='admincp.php?action=category&channel_type='.$rs[$k]['id']; 
							}
						   if (getAdminPri('3103')) { 
								$cnlname_3 = "添加".$rs[$k]['cn_name'];
		            		    $cnlurl_3='admincp.php?action=model_operate&task=add&channel_type='.$rs[$k]['id']; 
							}
							if (getAdminPri('3104')) { 
								$cnlname_4 = "管理".$rs[$k]['cn_name'];
		            		    $cnlurl_4='admincp.php?action=model_operate&task=list&channel_type='.$rs[$k]['id']; 
							}
							if (getAdminPri('3105')) { 
								$cnlname_6 = $rs[$k]['cn_name']."回收站";
		            		    $cnlurl_6='admincp.php?action=model_operate&task=recycle&channel_type='.$rs[$k]['id']; 
							}
				}
				break;
			case 'picture':
				if(getAdminPri('3200')){
					$v_name = $rs[$k]['cn_name'].'管理';
						$cnltype= '3200';
							if (getAdminPri('3201')) { 
								$cnlname_1 = $rs[$k]['cn_name']."频道";
								$cnlurl_1 ='admincp.php?action=channel&channel_type='.$rs[$k]['id']; 
							}
							if (getAdminPri('3202')) { 
								$cnlname_2 = "分类管理";
								$cnlurl_2 ='admincp.php?action=category&channel_type='.$rs[$k]['id']; 
							}
						   if (getAdminPri('3203')) { 
								$cnlname_3 = "添加".$rs[$k]['cn_name'];
		            		    $cnlurl_3='admincp.php?action=model_operate&task=add&channel_type='.$rs[$k]['id']; 
							}
							if (getAdminPri('3204')) { 
								$cnlname_4 = "管理".$rs[$k]['cn_name'];
		            		    $cnlurl_4='admincp.php?action=model_operate&task=list&channel_type='.$rs[$k]['id']; 
							}
	
							if (getAdminPri('3205')) { 
								$cnlname_6 = $rs[$k]['cn_name']."回收站";
		            		    $cnlurl_6='admincp.php?action=model_operate&task=recycle&channel_type='.$rs[$k]['id']; 
							}
				}
				break;
			case 'download':
		           $cnltype= '3300';
		           if(getAdminPri('3300')){
		           	$v_name = $rs[$k]['cn_name'].'管理';
							if (getAdminPri('3301')) { 
								$cnlname_1 = $rs[$k]['cn_name']."频道";
								$cnlurl_1 ='admincp.php?action=channel&channel_type='.$rs[$k]['id']; 
							}
							if (getAdminPri('3302')) { 
								$cnlname_2 = "分类管理";
								$cnlurl_2 ='admincp.php?action=category&channel_type='.$rs[$k]['id']; 
							}
						   if (getAdminPri('3303')) { 
								$cnlname_3 = "添加".$rs[$k]['cn_name'];
		            		    $cnlurl_3='admincp.php?action=model_operate&task=add&channel_type='.$rs[$k]['id']; 
							}
							if (getAdminPri('3304')) { 
								$cnlname_4 = "管理".$rs[$k]['cn_name'];
		            		    $cnlurl_4='admincp.php?action=model_operate&task=list&channel_type='.$rs[$k]['id']; 
							}
	
							if (getAdminPri('3305')) { 
								$cnlname_6 = $rs[$k]['cn_name']."回收站";
		            		    $cnlurl_6='admincp.php?action=model_operate&task=recycle&channel_type='.$rs[$k]['id']; 
							}
		           }
				break;
			case 'product':
				if(getAdminPri('4400')){
					$v_name = $rs[$k]['cn_name'].'管理';
		           $cnltype= '4400';
							if (getAdminPri('4401')) { 
								
								$cnlname_1 = $rs[$k]['cn_name']."频道";
								$cnlurl_1 ='admincp.php?action=channel&channel_type='.$rs[$k]['id']; 
							}
							if (getAdminPri('4402')) { 
								$cnlname_2 = "分类管理";
								$cnlurl_2 ='admincp.php?action=category&channel_type='.$rs[$k]['id']; 
							}
						   if (getAdminPri('4403')) { 
								$cnlname_3 = "添加".$rs[$k]['cn_name'];
		            		    $cnlurl_3='admincp.php?action=model_operate&task=add&channel_type='.$rs[$k]['id']; 
							}
							if (getAdminPri('4404')) { 
								$cnlname_4 = "管理".$rs[$k]['cn_name'];
		            		    $cnlurl_4='admincp.php?action=model_operate&channel_type='.$rs[$k]['id']; 
							}
							if (getAdminPri('4405')) { 
								$cnlname_6 = $rs[$k]['cn_name']."回收站";
		            		    $cnlurl_6='admincp.php?action=model_operate&task=recycle&channel_type='.$rs[$k]['id']; 
							}
				}
				break;
		}
		$temps[] = array(
				'name'=>$v_name,
				'menu'=> array(
						array('name' => $cnlname_1, 'url' => $cnlurl_1),
						array('name' => $cnlname_2, 'url' => $cnlurl_2),
						array('name' => $cnlname_3, 'url' => $cnlurl_3),
						array('name' => $cnlname_4, 'url' => $cnlurl_4),
						array('name' => $cnlname_6, 'url' => $cnlurl_6),
				 )
			);
	}
	$temps = array_uniques($temps);
	$t = getAdminPri('3408')|| getAdminPri('3409')?array('name'=>'扩展属性管理',
				'menu'=> array(
						getAdminPri('3408')?array('name' => '属性列表', 'url' => 'admincp.php?action=types&task=list'):'',
						getAdminPri('3409')?array('name' => '添加属性组', 'url' => 'admincp.php?action=types&task=add'):'',
				 )
			):array();
	array_unshift($temps,$t);
	unset($rs);	
	unset($t);
	$left_navs = array(
		'home'=>array(
				0=>array(
					'name'=>'系统常规操作',
					'menu'=> array(
								getAdminPri(3103)?array('name' => "添加文章", 'url' => 'admincp.php?action=model_operate&task=add&channel_type=1'):array(),
								getAdminPri(3303)?array('name' => "添加下载", 'url' => 'admincp.php?action=model_operate&task=add&channel_type=2'):array(),
								getAdminPri(4403)?array('name' => "添加产品", 'url' => 'admincp.php?action=model_operate&task=add&channel_type=4'):array(),
								getAdminPri(3203)?array('name' => "添加图片", 'url' => 'admincp.php?action=model_operate&task=add&channel_type=3'):array(),
								getAdminPri(7101)?array('name' => "会员列表", 'url' => 'admincp.php?action=core&do=associator'):array(),
								array('name' => "清除系统缓存", 'url' => 'admincp.php?action=home&do=clearcache'),
						   )
				),
			),
		'basic'=>array(
				0=>array(
					'name'=>'系统设置',
					'menu'=> array(
							getAdminPri('1101')?array('name' => "基本设置", 'url' => 'admincp.php?action=settings'):'',
					 )
				),
				1=>array('name'=>'邮件设置',
						'menu'=>array(
							getAdminPri('1201')?array('name' => "邮件服务器设置", 'url' => 'admincp.php?action=mail_set'):'',
							getAdminPri('1201')?array('name' => "邮件模板管理", 'url' => 'admincp.php?action=mail_set&do=mail_tpl'):'',
							getAdminPri('1203')?array('name' => "在线发邮件", 'url' => 'admincp.php?action=mail_set&do=mail_send'):''
						)
				),
			),
		'template'=>array(
				0=>array(
					'name'=>'模板设置',
					'menu'=> array(
							getAdminPri('10001')?array('name' => '模板设置', 'url' => 'admincp.php?action=templete'):'',
					 )
				),
		),
		'core'=>array(
				0=>array(
					'name'=>'会员管理',
					'menu'=> array(
							getAdminPri('7101')?array('name' => '会员列表', 'url' => 'admincp.php?action=core&do=associator'):'',
							getAdminPri('7102')?array('name' => ' 会员权限管理', 'url' => 'admincp.php?action=core&do=popedom'):'',
					 )
				),
				1=>array('name'=>'管理员管理',
						'menu'=>array(
							getAdminPri('7200')?array('name' => "管理员管理", 'url' => 'admincp.php?action=managectrller&do=admincper'):'',
					)
				),
			),
			
		'db'=>array(
				getAdminPri('9000')?array(
					'name'=>'数据库管理',
					'menu'=> array(
							getAdminPri('9001')?array('name' => "数据库备份", 'url' => 'admincp.php?action=db&do=backup'):'',
							getAdminPri('9002')?array('name' => "数据库恢复", 'url' => 'admincp.php?action=db&do=recover'):'',
							getAdminPri('9003')?array('name' => "数据库优化", 'url' => 'admincp.php?action=db&do=optimize'):'',
							getAdminPri('9003')?array('name' => "数据库修复", 'url' => 'admincp.php?action=db&do=repair'):'',
					 )
				):'',
			),
		'plugin'=>array(
				getAdminPri('8101')?array(
					'name'=>'附件管理器',
					'menu'=> array(
							array('name' => "文件列表", 'url' => 'admincp.php?action=filemanager'),
					 ),
				):'',
				getAdminPri('8101')?array(
					'name'=>'留言管理',
					'menu'=> array(
							array('name' => "客户留言及评论管理", 'url' => 'admincp.php?action=guestbook&do=list'),
							array('name' => "客户留言及评论设置", 'url' => 'admincp.php?action=guestbooksite'),
					 ),
				):'',
				getAdminPri('8102')?array(
					'name'=>'单页面管理',
					'menu'=> array(
							array('name' => "单页面列表", 'url' => 'admincp.php?action=single&do=list'),
							array('name' => "添加单页面", 'url' => 'admincp.php?action=single&do=add'),
					 ),
				):'',
				getAdminPri('8104')?array(
					'name'=>'幻灯片管理',
					'menu'=> array(
							array('name'=>'幻灯片列表', 'url'=>'admincp.php?action=slide&do=list'),
					 ),
				):'',
				getAdminPri('8103')?array(
					'name'=>'友情链接',
					'menu'=> array(
							array('name' => '链接列表', 'url' => 'admincp.php?action=link&do=list'),
							array('name' => '添加链接', 'url' => 'admincp.php?action=link&do=add'),
					 ),
				):'',
				getAdminPri('8108')?array(
					'name'=>'导航设置',
					'menu'=> array(
							array('name'=>'导航列表', 'url'=>'admincp.php?action=navigation&do=list'),
							array('name'=>'添加导航', 'url'=>'admincp.php?action=navigation&do=showadd'),
					 ),
				):'',
				getAdminPri('8108')?array('name'=>'站点公告管理',
						'menu'=>array(
							array('name' => "添加公告", 'url' => 'admincp.php?action=notice&do=add'),
							array('name' => "管理公告", 'url' => 'admincp.php?action=notice')
						)
				):'',
				getAdminPri('8106')?array(
					'name'=>'投票管理',
					'menu'=> array(
						array('name'=>'投票列表', 'url'=>'admincp.php?action=poll&do=list'),
					 ),
				):'',
				getAdminPri('8107')?array(
					'name'=>'广告管理',
					'menu'=> array(
							array('name'=>'广告位管理', 'url'=>'admincp.php?action=place&do=show'),
							array('name'=>'广告管理', 'url'=>'admincp.php?action=ads&do=show')
					 ),
				):'',
		),
	);
	$left_navs['channel'] = $temps;
	unset($temps);
	//基本设置
	function filter($ary){
		if(!is_array($ary))return $ary;
		foreach ($ary as &$a){
			$a = array_filter($a);
			if(is_array($a)){
				foreach ($a as $j=>&$e){
					if(isset($e['menu'])){
						$e['menu'] = array_filter($e['menu']);
						if(empty($e['menu']))unset($a[$j]);
						if(is_array($e['menu'])){
							foreach ($e['menu'] as $s=>$t){
								if(empty($t['name']))unset($e['menu'][$s]);
							}
						}
					}
				}
			}
		}
		return $ary;
	}
	if(!getAdminPri('1111'))unset($left_navs['basic']);
	if(!getAdminPri('7777'))unset($left_navs['member']);//核心模块
	if(!getAdminPri('3333'))unset($left_navs['channel']);//模型 频道管理
	if(!getAdminPri('7777'))unset($left_navs['core']);//核心模块
	if(!getAdminPri('9000'))unset($left_navs['db']);//数据库
	if(!getAdminPri('8888'))unset($left_navs['plugin']);//数据库
	$tpl->assign('left_nav',filter($left_navs));
	$tpl->display('left.nav.tpl');
	exit();
} elseif($action == 'header') {
	$base_link = 'admincp.php?action=home';
	$navs[] = array('tag'=>'home','name'=>'常规操作','link'=>getAdminPri(1101)?'admincp.php?action=settings&do=basic':$base_link);
	if(getAdminPri('1111')){
		$navs[] = array('tag'=>'basic','name'=>'系统设置','link'=>getAdminPri(1101)?'admincp.php?action=settings&do=basic':$base_link);
	}
	if(getAdminPri('3333')){
		$navs[] = array('tag'=>'channel','name'=>'频道管理','link'=>'admincp.php?action=channel');
	}
	if(getAdminPri('7777')){
		$navs[] = array('tag'=>'core','name'=>'核心模块','link'=>getAdminPri(7101)?'admincp.php?action=core':$base_link);
	}
	if(getAdminPri('8888')){
		$navs[] = array('tag'=>'plugin','name'=>'模块插件','link'=>getAdminPri(8101)?'admincp.php?action=guestbook&do=list':$base_link);
	}
	if(getAdminPri('10001')){
		$navs[] = array('tag'=>'template','name'=>'模板设置','link'=>'admincp.php?action=templete');
	}
	if(getAdminPri('9000')){
		$navs[] = array('tag'=>'db','name'=>'数据库管理','link'=>getAdminPri('9001')?'admincp.php?action=db&do=backup':$base_link);
	}
	$tpl->assign('navs',$navs);
	$menu = !empty($_GET['menu']) ? $_GET['menu'] : (!empty($_POST['menu']) ? $_POST['menu'] : 'home');
	$tpl->display('header.nav.tpl');
	exit();
} else {
	$cpscript = $action;
	if($cpscript) {
		$file = dirname(__FILE__).'/admin_'.$cpscript.'.php';
		if(!file_exists($file))exit('not exist admin_'.$cpscript.'.php');
		require $file ;
	}
}
?>