<?php
session_start();
if ($_SESSION['login']!="ok") {
	echo "<script language='javascript'>";
	echo " location='./';";
	echo "</script>";
}
?>
<?php
function select_kind($kind,$db){//通过id查分�?
	$req=mysql_query("select * from kind where id=$kind",$db);
	if($return=mysql_fetch_array($req))
	return $return['name'];
}
function un_select_kind($kindname,$db){//通过分类名称查id
	$req=mysql_query("select * from kind where name='$kindname'",$db);
	if($return=mysql_fetch_array($req))
	return $return['id'];
}
function select_hot($id){
	$return=mysql_query("select count(usr_id) as count from usr_link where link_id=$id");
	if($req=mysql_fetch_array($return)){
		return $req['count'];
	}else{
		return "0";
	}
}
function un_select_states($states){//通过状态差id
   if($states=="已通过")return "1";
   else return "0";	
}
function select_states($states){//通过id查状态
   if($states==1)return "已通过";	
   if($states==0)return "未通过";
}
function web_url_del($id){//删除单个网站
	mysql_query("delete from link where id=$id");
}
function web_pass($id){
	mysql_query("update link set states=1 where id=$id");
}
function count_kind_web($kind){//统计每个类网站个�?
if($kind==99999){//当分类为99999的时候统计所有分�?
	 $req=mysql_query("select count(id) as count from link");
}else{
	 $req=mysql_query("select count(id) as count from link where kind=$kind");
}
   
	$return=mysql_fetch_array($req);
	return $return['count'];	
}
function kind_del($id){//删除分类,连同所有继承自他的分类,以及属于他们的网站记录
	mysql_query("delete from kind where id=$id");
	mysql_query("delete from link where kind=$id");
	$req=mysql_query("select * from kind where father_id=$id");
	while ($return=mysql_fetch_array($req)) {
		$fid=$return['id'];
		kind_del($fid);
		mysql_query("delete from kind where id=$fid");
		mysql_query("delete from link where kind=$fid");
	}
}
?>
