<?php
	include("../include/global.php");
	include("ZC_Check_admin.php");
	$id=0;
	if(isset($_GET['id'])){
		$id=safe_check($_GET['id'],0);
	}
	
	//添加关键词
	if(isset($_GET['action'])&&safe_check($_GET['action'],1)=='add'){
		$keyword=htmldecode($_POST['keyword']);
		$replace=htmldecode($_POST['replace']);	
		$zimu=htmldecode($_POST['zimu']);	
		$klen=htmldecode($_POST['klen']);	
		$ip=$_SERVER['REMOTE_ADDR'];
		$addtime=time();
		$rs=$db->query("select * from `".PRE."keywords` where `keyword`='$keyword' and `id` <> $id");
		if(is_array($row=$db->fetch_array($rs))){
			echo "<SCRIPT LANGUAGE='JavaScript'>alert('此词组已存在！');history.go(-1);</SCRIPT>";
			exit;
		}
		$sql="insert into `".PRE."keywords`(`keyword`,`replace`,`zimu`,`klen`,`addtime`,`addname`,`ip`) values('".$keyword."','".$replace."','".$zimu."','".$klen."','".$addtime."','".$_SESSION['name']."','".$ip."')";		
		$db->query($sql) or die ("添加替换词出现错误");
		echo "<script type='text/javascript'> if(confirm('是否继续添加？')){ window.location.href='ZC_Seo_Manager.php?action=add';} else{ window.location.href='ZC_Seo_List.php'}</script>";
		set_keywords();
	//修改关键词
	}elseif(isset($_GET['action'])&&safe_check($_GET['action'],1)=='modify'){
		$keyword=htmldecode($_POST['keyword']);
		$replace=htmldecode($_POST['replace']);
		$zimu=htmldecode($_POST['zimu']);	
		$klen=htmldecode($_POST['klen']);
		$updatetime=time();

		$ip=$_SERVER['REMOTE_ADDR'];
		$rs=$db->query("select * from `".PRE."keywords` where `keyword`='$keyword' and `id` <>$id");	
		if(is_array($row=$db->fetch_array($rs))){
			echo "<SCRIPT LANGUAGE='JavaScript'>alert('此词组已存在！');history.go(-1);</SCRIPT>";
			exit;
		}
		$sql="update `".PRE."keywords` set `keyword`='".$keyword."',`replace`='".$replace."',`zimu`='".$zimu."',`klen`='".$klen."',`updatetime`='".$updatetime."',`updatename`='".$_SESSION['name']."',`ip`='".$ip."' where `id`=".$id;
		$db->query($sql) or die ("修改替换词出现错误");
		echo "<script type='text/javascript'>alert('修改成功！'); window.location.href='ZC_Seo_List.php?page=".$_SESSION['mypage']."';</script>";
		set_keywords();
	//删除单页
	}else{
		$getid=$_REQUEST['id'];//得到ID的值
		if(!$getid){
			echo "<SCRIPT LANGUAGE='JavaScript'>alert('未选择记录！');history.go(-1);</SCRIPT>";
			exit;
		}
		$getids=implode(',',$getid);
		//如果ID的值为数组则ID为字符中，否则为数字
		$id=is_array($getid)?$getids:$getid;
		if(!$id){
			echo "<SCRIPT LANGUAGE='JavaScript'>alert('操作的ID号丢失！');history.go(-1);</SCRIPT>";
			exit;
		}
		if($_GET[action]='delete'){
			$sql="delete from `".PRE."keywords` where `id` in ($id)";
			$db->query($sql) or die ("删除词组出现错误");
			echo "<script type='text/javascript'>alert('删除成功！'); window.location.href='ZC_Seo_List.php?page=".$_SESSION['mypage']."';</script>";
			set_keywords();
		}

	}
?>
