<?php
session_start();
if ($_SESSION['login']!="ok") {
	echo "<script language='javascript'>";
	echo " location='./';";
	echo "</script>";
}
?>
<?php
require("conn.php");
require("function.php");
if($_GET['action']=="webadd"){//添加网站记录
	$webname=$_POST['webname'];
	$weburl=$_POST['weburl'];
	if(substr($weburl,0,7)!="http://"){
		$weburl="http://".$weburl;
	}
	$webkey=$_POST['key'];
	$webkind=$_POST['kind'];
	$webkind=un_select_kind($webkind,$db);
	$webstates=$_POST['states'];
	$webstates=un_select_states($webstates);
	if (mysql_query("insert into link values(0,'$webname','$weburl',$webstates,'$webkey',$webkind)",$db)) {
		echo "{success:true,message:\"添加成功\"}"; 
	}else {
		echo "{success:false,message:\"添加失败\"}";
	}
}
if($_GET['action']=="webedit"){//编辑网站记录
	$urlid=$_POST['webid'];
	$webname=$_POST['webname'];
	$weburl=$_POST['weburl'];
	if(substr($weburl,0,7)!="http://"){
		$weburl="http://".$weburl;
	}
	$webkey=$_POST['key'];
	$webkind=$_POST['kind'];
	$webkind=un_select_kind($webkind,$db);
	$webstates=$_POST['states'];
	$webstates=un_select_states($webstates);
	if (mysql_query("update link set name='$webname',url='$weburl',states=$webstates,letter='$webkey',kind=$webkind where id=$urlid",$db)) {
		echo "{success:true,message:\"修改成功\"}"; 
	}else {
		echo "{success:false,message:\"修改失败\"}";
	}
}
if($_GET['action']=="webdel"){//删除网站记录
	web_url_del($_POST['id']);
}
if($_GET['action']=="webpass"){//审核网站记录
	web_pass($_POST['id']);
}
if($_GET['action']=="staradd"){//添加星座记录
	$date=$_POST['star_time'];
	$kind=$_POST['star_kind'];
	$info=$_POST['star_info'];
	$show=$_POST['star_show'];
	if(mysql_query("insert into star_content values(0,'$info','$date','$kind','$show')")){
		echo "{success:true,message:\"添加成功\"}"; 
	}else {
		echo "{success:false,message:\"添加失败\"}";
	}
}
if($_GET['action']=="staredit"){//修改星座记录
$id=$_POST['id'];
	$date=$_POST['star_time'];
	$kind=$_POST['star_kind'];
	$info=$_POST['star_info'];
	$show=$_POST['star_show'];
	if(mysql_query("update star_content set value='$info',starshow='$show',time='$date',kind='$kind' where id=$id")){
		echo "{success:true,message:\"修改成功\"}"; 
	}else {
		echo "{success:false,message:\"修改失败\"}";
	}
}
if($_GET['action']=="stardel"){//删除网站记录
	$id=$_POST['id'];
	mysql_query("delete from star_content where id=$id");
}
if($_GET['action']=="webkindadd"){
	$sonkind=$_POST['kind_add_name'];
	$fatherkind=$_POST['kind_name'];
	if($fatherkind==99999){$fatherkind=0;}
	mysql_query("insert into kind values(0,'$sonkind',$fatherkind)");
}
if($_GET['action']=="kinddel"){//删除网站分类
	$id=$_POST['id'];
	kind_del($id);
}
//管理员名和密码修改开始
if($_GET['action']=="user_edit"){
	$old_user=$_POST['user_name'];
	$old_pass=md5($_POST['or_pass']);
	$new_user=$_POST['new_user_name'];
	$new_pass=md5($_POST['new_pass']);
	$return=mysql_query("select * from user where id=3");
	$req=mysql_fetch_array($return);
	if($req['name']==$old_user&&$req['passwd']==$old_pass){
		if(mysql_query("update user set name='$new_user',passwd='$new_pass' where id=3")){
			echo "{success:true,message:\"修改成功\"}"; 
		}else{
			echo "{success:false,message:\"修改失败\"}"; 
		}
	}else{
		echo "{success:false,message:\"原始用户或密码不正确\"}"; 
	}
}
?>
