<?php 
defined('IN_TS') or die('Access Denied.');

		
switch($ts){
	case "":
		$title = '分类设置';
		$strsitenav = $db->fetch_all_assoc("select * from ".dbprefix."goods_cate where parent_id=0 and appname<>'' order by sort asc");
		$strMobileNav = $db->fetch_all_assoc("select * from ".dbprefix."mobile_cate order by sort asc");
		$sitenav = is_array($strMobileNav)?$strMobileNav:$strsitenav;
		
		include template("admin/setcate");
		break;
		
	case "do":

		
		qiMsg("未知操作！","<a href=\"index.php?app=system&ac=sitenav\">返回</a>");
		
		break;
		
		
		case "do_nav":
		
		
		$arrcate_id = $_POST['cate_id'];
		$arrtbcateid = $_POST['tbcateid'];
		$arrcate_name = $_POST['cate_name'];
		
		$arris_nav = $_POST['is_nav'];
		
		$arrimg = $_POST['img'];

		$arrsort = $_POST['sort'];

	
		foreach($arrcate_name as $key=>$item){
			$cate_name = trim($item);
			$cate_id = trim($arrcate_id[$key]);
			$tbcateid = trim($arrtbcateid[$key]);
			$is_nav = trim($arris_nav[$key]);
			
			$img = $arrimg[$key];

			$sort = trim($arrsort[$key]);
			
			if(!$sort){
				$sort='0';
			}
			
			if($cate_name){
				
				$iscateid = $db ->once_num_rows("select cate_id from ".dbprefix."mobile_cate where cate_id='".$cate_id."'");
				if($iscateid){
				$updatenav = $db->query("UPDATE ".dbprefix."mobile_cate SET  cate_name='".$cate_name."',tbcateid='".$tbcateid."',sort='".$sort."',img='".$img."',is_nav='".$is_nav."' where cate_id = '".$cate_id."'");
				}elseif($cate_id<>1){
				$insertnav = $db->query("insert into ".dbprefix."mobile_cate SET  cate_name='".$cate_name."',tbcateid='".$tbcateid."',sort='".$sort."',img='".$img."',is_nav='".$is_nav."'");
				}

			}
			
			
		}
		

		
		qiMsg("手机分类修改成功！","<a href=\"index.php?app=mobile&ac=admin&mg=setcate\">返回</a>");
		
		break;
		
		case "del":
		
		$cate_id = intval($_GET['cate_id']);
		$arrNavdo = array();
		if($cate_id){
			
			$db->query("DELETE FROM ".dbprefix."mobile_cate WHERE  cate_id='$cate_id'");
		
		qiMsg("导航删除成功！","<a href=\"index.php?app=mobile&ac=admin&mg=setcate\">返回</a>");
		}
		
		break;
		
		case "isnav":
		$arrNavdo = array();
		$cate_id = $_POST['cate_id'];
		
		if(intval($cate_id)>0){
		$updateisnav = $db->query("UPDATE ".dbprefix."goods_cate SET  is_nav='1' where cate_id = '$cate_id'");
		$sitenav = $db->fetch_all_assoc("select cate_name,appname from ".dbprefix."goods_cate where is_nav=1 and parent_id=0 and appname<>''");
		foreach($sitenav as $key=>$item){
				$arrNav = array(
					$item['appname']	=> 	$item['cate_name'],
					);
				$arrNavdo = $arrNavdo+$arrNav;
		}
		fileWrite('top_appnav.php','data',$arrNavdo);
		}elseif(!empty($cate_id)){
			
		$sys_nav_arrs = fileRead('appnav.php','data','sys');
		
		foreach($sys_nav_arrs as $key=>$item){
			if($key==$cate_id){
				
				$sys_nav_arr[$key] =  array (
										'name' => $item['name'],
										'seo_keywords' =>  $item['seo_keywords'],
										'seo_desc' =>  $item['seo_desc'],
										'is_show' => 1,
									  );
									  
			}else{
				$sys_nav_arr[$key] = $item;
			}
		}
			
		fileWrite('sys_appnav.php','data',$sys_nav_arr);
			
		}
		
		
		echo '1';
		
		break;
		
		case "unnav":
		$arrNavdo = array();
		$cate_id = $_POST['cate_id'];
		if(intval($cate_id)>0){
		$updateisnav = $db->query("UPDATE ".dbprefix."goods_cate SET  is_nav='0' where cate_id = '$cate_id'");
		$sitenav = $db->fetch_all_assoc("select cate_name,appname from ".dbprefix."goods_cate where is_nav=1 and parent_id=0 and appname<>''");
		foreach($sitenav as $key=>$item){
				$arrNav = array(
					$item['appname']	=> 	$item['cate_name'],
					);
				$arrNavdo = $arrNavdo+$arrNav;
		}
		fileWrite('top_appnav.php','data',$arrNavdo);
		
		}elseif(!empty($cate_id)){
			
			$sys_nav_arrs = fileRead('appnav.php','data','sys');
		
		foreach($sys_nav_arrs as $key=>$item){
			if($key==$cate_id){
				
				$sys_nav_arr[$key] =  array (
										'name' => $item['name'],
										'seo_keywords' =>  $item['seo_keywords'],
										'seo_desc' =>  $item['seo_desc'],
										'is_show' => 0,
									  );
									  
			}else{
				$sys_nav_arr[$key] = $item;
			}
		}
			
		fileWrite('sys_appnav.php','data',$sys_nav_arr);
			
			
		}
		echo '1';
		
		break;
}