<?php
require_once("../../global/checkuser1.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="REFRESH" content="2; URL=index.php" />
<title>处理函数</title>
</head>

<body>
<?php
require_once("../../global/connect.php");
if("add"==$_GET["mod"]){
if(mysql_num_rows(mysql_query("select * from website"))<4){
$surl=strip_tags($_POST["url"]);
$surl=str_replace("http://","",$surl);
$surl=str_replace("www.","",$surl);
$surl=explode(".",$surl);
if(mysql_num_rows(mysql_query("select * from website where url='$_POST[url]'"))==0){
if(mysql_num_rows(mysql_query("select * from website where type = '友好'"))<1||$_POST["type"]=="竞争"){
$name=strip_tags($_POST["name"]);
$url=strip_tags($_POST["url"]);
$type=strip_tags($_POST["type"]);
$sql="INSERT INTO website (name,url,type,surl) VALUES ('$name','$url','$type','$surl[0]')";
mysql_query($sql);
echo "操作成功!2秒后自动返回...";
}
else
echo "操作失败!只能存在一个友好的网站!";
}
else
echo "操作失败!".$_POST["url"]."已存在。";
}
else
echo "操作失败，最多只能添加4个网站";
}
if("modify"==$_GET["mod"]){
$all=mysql_query("select * from website where id ='$_POST[id]'");
while($row=mysql_fetch_array($all)){
$type=$row["type"];
}
if(mysql_num_rows(mysql_query("select * from website where type='友好'"))<1||$_POST["type"]=="竞争"||$type==$_POST["type"]){
$name=strip_tags($_POST["name"]);
$type=strip_tags($_POST["type"]);
$sql="update website set name='$name',type='$type' where id='$_POST[id]'";
mysql_query($sql);
echo "操作成功!2秒后自动返回...";
}
else
echo "操作失败!只能存在一个友好的网站!";
}
if("delete"==$_GET["mod"]){
mysql_query("delete from website where id=$_GET[id]");
echo "操作成功!2秒后自动返回...";
}
echo "<script>setTimeout('parent.location.reload()',2000);</script>";
?>
</body>
</html>
