<?php
/*******************************************************************
 * 版权协议：2009-2019
 * 版权所有: PHP-北京金南曦网络技术有限公司旗下PHPWMS，PHP商城系统技术支持中心http://www.php188.net，并保留所有权利。 
* PHP商城系统网址: http://www.php188.com
 * PHPWMS系统网址：http://www.phpwms.com
 * 销售电话：010-87875088
 * 销售电话：010-87875188 
*------------------------------------------------------------------
 * 这不是一个完全免费软件！您只能在不用于商业目的的前提下对程序代码进
 * 行修改和使用；不允许对程序代码以任何形式任何目的的再发布。
 *------------------------------------------------------------------
 * 文件名称：admin_navigation.php
 * 摘　　要：导航设置
 * 适用范围：PHPWMS 1.0
 * 版　　本：1.0
 *------------------------------------------------------------------
 * Script Written By phpwms项目组
 * 最后更新： 2009-09-24 phpwms 由PHP金南曦网络技术有限公司整理发布
 *******************************************************************/
if(!defined('IN_SYS'))exit('access die');
if (!getAdminPri('8105'))exit(NO_AUTH_LOGIN);
$do	  = trim($_REQUEST['do']);
$tpl -> assign("do",$do);
$url = 'admincp.php?action=navigation&do=list';
if($do == 'oper' || $do == 'delete' || $do == 'deleteall'){
	php188StaticCache::getInstance()->remove('phpwms_navigation');
}
switch($do){
	case 'showadd':
		$pn = '添加列表';
		break;
	case 'oper':
		$post = html_encode($_POST);
		$data = array();
		$data['nav_name'] = $post['name'];
		$data['nav_sort'] = intval($post['sort']); 
		$data['nav_link'] = $post['link'];
		$data['nav_position'] = $post['position'];
		$data['nav_blank'] = $post['target'];
		$data['nav_display'] = intval($post['display']);
		$type = $post['type'];
		$id = intval($post['id']);
		if(empty($id)){
			$error = $db->insert($data, 'navigation');
		}else{
			$where['nav_id'] = $id;
			$error = $db->update($data, 'navigation', $where);
		}
		if(!empty($error)){
			$sp->bgmsg('操作成功', $url);
		}else{
			$sp->bgmsg('操作失败', $url);
		}
		break;
	case 'delete':
		$id = intval($_GET['id']);
		$error = '';
		if(!empty($id)){
			$sql = "DELETE FROM ##__navigation WHERE nav_id = '$id'";
			$error = $db->query($sql);
		}
		if(!empty($error)){
			$sp->bgmsg('删除成功', $url);
		}else{
			$sp->bgmsg('删除失败', $url);
		}
		break;
	case 'edit':
		$id = intval($_GET['id']);
		$result = array();
		if(!empty($id)){
			$sql = "SELECT * FROM ##__navigation WHERE nav_id = '$id'";
			$result = $db->fetch($sql, true);
		}
		if(empty($result)){
			$sp->bgmsg('您要修改的导航信息不存在', $url);
		}
		$pn = '修改导航';
		$tpl->assign('nav', $result);
		break;
	case "deleteall":
		$ids = $_POST['navids'];
		if(empty($ids) || !is_array($ids)){
			$sp->bgmsg('请您选择要操作的项', $url);
		}
		$sql = "DELETE FROM ##__navigation WHERE nav_id IN(";
		$ids = array_filter($ids);
		foreach ($ids as $id) {
			$sql .= $id . ',';
		}
		$sql = substr($sql, 0, -1) . ')';
		if($db->query($sql)){
			$sp->bgmsg('删除成功', $url);
		}else{
			$sp->bgmsg('删除失败', $url);
		}
		break;
	default:
		$pn  = '导航列表';
		$opt = $_GET['opt'];
		$where = ' WHERE ';
		switch ($opt){
			case 'center':
				$where .= "`nav_position` = 'center'";
				break;
			case 'bottom':
				$where .= "`nav_position` = 'bottom'";
				break;
			case 'top':
				$where .= "nav_position = 'top'";
				break;
			default:$where .= ' 1=1 ';
		}
		$sql = "SELECT * FROM ##__navigation  $where ORDER BY nav_sort ASC";
		$result = $db->fetch($sql);
		$tpl->assign('navigation', $result);
		break;
}
$tpl -> assign("admin_nav",shownav($pn));
$tpl->display('navigation.tpl');
?>