<?php
# Name: PHP版程氏音乐CMS管理系统 v3.0
# Author: 程氏<web@chshcms.com> [QQ:848769359]
# Homepage:http://www.chshcms.cn/
include_once("../../lib/cs_conn.php");
include_once("../../lib/cs_common.php");
include "../loginstate.php";

	global $db;
	$CS_CSID=CS_Request("csid");
        $name=CS_Request("name");
	$CS_ID=CS_Request("cid");
	$ac=CS_Request("ac");
if($ac=='go'){
        if($CS_ID==0)  die("<script>alert('请先选择要绑定的分类！');window.location='javascript:history.go(-1);'</script>");
	$sql2="select * from ".Getdbname('class')." where CS_ID=".$CS_ID."";
	$row2=$db->getrow($sql2);
	if($row2){
		$row2['CS_CSID'].=",".$CS_CSID.",";
		$sql3="update ".Getdbname('class')." set CS_CSID='".$row2['CS_CSID']."' where CS_ID=".$CS_ID."";
		if($db->query($sql3)){
			exit("<script type=\"text/javascript\">
		           window.parent.document.getElementById('bd_".$CS_CSID."').innerHTML='<img src=../res/images/cyes.gif>';
		           this.parent.$('.webox').css({display:'none'});
		           this.parent.$('.background').css({display:'none'});</script>");
	        }else{
		           die("<script>alert('对不起，绑定出错！');window.location='javascript:history.go(-1);'</script>");
	        }
	}

}elseif($ac=='jieb'){
      $sql="update ".Getdbname('class')." set CS_CSID='' where CS_CSID=".$CS_CSID;
	if($db->query($sql)){
			exit("<script type=\"text/javascript\">
		           window.parent.document.getElementById('bd_".$CS_CSID."').innerHTML='<img src=../res/images/cno.gif>';
		           this.parent.$('.webox').css({display:'none'});
		           this.parent.$('.background').css({display:'none'});</script>");
	}else{
		die("<script>alert('对不起，解绑出错！');window.location='javascript:history.go(-1);'</script>");
	}
}elseif($ac=='jieball'){
      $sql="update ".Getdbname('class')." set CS_CSID=''";
	if($db->query($sql)){
			exit("<script type=\"text/javascript\">
                        for ( var i=1 ; i < 12 ; ++i ) {
		           window.parent.document.getElementById('bd_'+i).innerHTML='<img src=../res/images/cno.gif>';
                        }
		           this.parent.$('.webox').css({display:'none'});
		           this.parent.$('.background').css({display:'none'});</script>");
	}else{
		die("<script>alert('对不起，解绑出错！');window.location='javascript:history.go(-1);'</script>");
	}
}else{
?>
<!doctype html>
<html>
<head>
<meta charset="gbk">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>程氏官方数据同步分类绑定</title>
<link href="../res/css/admin_style.css" rel="stylesheet" />
<form method="post" action="?ac=go">
<div class="table_list">
<table width="100%" id="dellist">
  <input name="csid" type="hidden" value="<?php echo $CS_CSID?>">
    <TR>
      <TD height="30" width="20%">提示信息：</TD>
      <TD height="30"> 将资源库分类: <font color="red"><?php echo $name?></font> 绑定到
	  </TD>
    </TR>
    <TR>
      <TD height="30" width="20%">本地分类：</TD>
      <TD height="30">
      &nbsp;  
        <select name="cid"><option value='0'>--选择分类--</option>
              <?php
              	$sqlclass="select * from ".Getdbname('class')." where CS_SID=1 ";
				$results=$db->query($sqlclass);
				if($results){
					while ($row3=$db->fetch_array($results)){
						echo "<option value='".$row3['CS_ID']."'>".$row3['CS_Name']."</option>";	
					}
				}
			  ?>
		 </select>
	  </TD>
    </TR>
</table>
</div>
	<div class="btn_wrap_pd">
              &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
             <input class="btn J_ajax_submit_btn" type=submit value=绑定分类 name=Submit> &nbsp;
             <input name="button2" type="button" class="btn btn_submit J_ajax_submit_btn" onClick="window.location.href='?ac=jieb&csid=<?php echo $CS_CSID?>'" value="解除绑定"> &nbsp;
             <input name="button2" type="button" class="btn btn_submit J_ajax_submit_btn" onClick="window.location.href='?ac=jieball'" value="解除所有绑定"> 
	</div>
 </form>
<?php } ?>
</body>
</html>