<?php
/*
'**************************************************************************************************
' 软件名称: 搜一次 Content Management System
' 版本编号: Version 1.X
' 官方网站: http://www.syccms.com
' 官方论坛：http://bbs.syccms.com
' 版权所有: 搜一次运营团队
' 法律顾问: 杭州市元茂律师事务所 严飞律师
' 郑重声明:
'    1、任何个人或组织不得在未经授权的情况下删除、修改、拷贝本软件及其他副本上一切关于版权的信息；
'    2、搜一次网络事业部保留此软件的法律追究权利
'**************************************************************************************************
*/
include "../../include/conn.php";
include "../../include/function.php";
include "../admin_version.php";
include "../admin_loginstate.php";
header("Content-type: text/html;charset=gb2312");

?>
<?php
class ui_tie{
	public function tielist($ServerClassID,$ClassName){
?>		
		<form action="?action=tie&ServerClassID=<?php echo $ServerClassID?>" method="post">
		<b>将<font color=red>&nbsp;<?php echo $ClassName?>&nbsp;</font>分类绑定到</b>&nbsp;<select name="ClassID">
              <?php
			  global $db;
              	$sqlclass="select * from s_class where S_SystemID=1 ";
				$result=$db->query($sqlclass);
				if($result){
					while ($row=$db->fetch_array($result)){
						if(stristr($row['S_TieID'],",".$ServerClassID.",")){
							echo "<option value='".$row['S_ID']."' selected='selected'>".$row['S_Name']."</option>";
							}
						 else{
							 echo "<option value='".$row['S_ID']."'>".$row['S_Name']."</option>";
							 }	
						}
					}
			  ?>
        </select>
       <input  name="button" id="button" value="提交" type="button" onclick="Buidind(ClassID.value,'<?php echo $ServerClassID?>')" class="rb1"/>&nbsp;<?php if(checkbind2($ServerClassID)!="0"){?><input type="button" value="取消绑定" class="rb1" onclick="NoTie('<?php echo $ServerClassID?>')"><?php }?>&nbsp;<input type="button" value="关闭" onclick="RemoveBind()" class="rb1">
		</form>
<font color="red"><b>＊注意：未绑定的视频分类将存入“临时资源平台”！</b></font>
<?php
		}
	}
$ui=new ui_tie;	
$action = SafeRequest("action","get");
$ServerClassID = SafeRequest("ServerClassID","get");
$VideoClassID = SafeRequest("ClassID","post");
$ClassName = SafeRequest("ClassName","get");

switch($action){
	case 'tie':
		tie();
		break;
	case 'notie':
		notie();
		break;
	case 'checkbind':
		checkbind();
		break;
	default:
		main();
	}

function main(){
	global $ui;
	$ServerClassID = SafeRequest("ServerClassID","get");
	$ClassName = SafeRequest("ClassName","get");
	$ui->tielist($ServerClassID,$ClassName);
}

//绑定分类
function tie(){
	global $db;
	$ServerClassID = SafeRequest("ServerClassID","get");
	$VideoClassID = SafeRequest("VideoClassID","get");
	$sql="select * from s_class where S_TieID like '%,$ServerClassID,%' and S_SystemID=1";
	$result=$db->query($sql);
	if($result){
		while($row=$db->fetch_array($result)){
			$row['S_TieID']=ReplaceStr($row['S_TieID'],",".$ServerClassID.",","");
			$db->query("update s_class set S_TieID='".$row['S_TieID']."' where S_ID=".$row['S_ID']."");
			}
		}
		
	$sql2="select * from s_class where S_ID=".$VideoClassID."";
	$row2=$db->getrow($sql2);
	if($row2){
		$row2['S_TieID'].=",".$ServerClassID.",";
		$sql3="update s_class set S_TieID='".$row2['S_TieID']."' where S_ID=".$row2['S_ID']."";
		//die($sql3);
		if($db->query($sql3)){
			echo $ServerClassID;
			}
		}
	
	}
//判断绑定2
function checkbind2($ServerClassID){
	global $db;
	$isbind=0;
	$sql="select * from s_class where S_SystemID=1";
	$result=$db->query($sql);
	if($result){
		while($row=$db->fetch_array($result)){
			if(stristr($row['S_TieID'],",".$ServerClassID.",")){
				$isbind=$row['S_ID'];
				}
			}
		}
	return $isbind;
	}
	
//判断是否绑定
function checkbind(){
	global $db;
	$isbind=0;
	$ServerClassID = SafeRequest("ServerClassID","get");
	$sql="select * from s_class where S_SystemID=1";
	$result=$db->query($sql);
	if($result){
		while($row=$db->fetch_array($result)){
			if(stristr($row['S_TieID'],",".$ServerClassID.",")){
				$isbind=$row['S_ID'];
				}
			}
		}
	//die($isbind);	
	if($isbind==0){
		echo "<img src=../images/cno.gif>";
		}
	else{
		echo "<img src=../images/cyes.gif>";
		}
	}
	
//取消绑定
function notie(){
	global $db;
	$ServerClassID=SafeRequest("ServerClassID","get");
	$sql="select * from s_class where S_TieID like '%,$ServerClassID,%' and S_SystemID=1";
	//die($sql);
	$result=$db->query($sql);
	if($result){
		while($row=$db->fetch_array($result)){
					
			$row['S_TieID']=ReplaceStr($row['S_TieID'],",".$ServerClassID.",","");
			$db->query("update s_class set S_TieID='".$row['S_TieID']."' where S_ID=".$row['S_ID']."");
			echo $ServerClassID;
			}
		}
	}
	
?>