<?php
/*
'**************************************************************************************************
' 软件名称: 搜一次 Content Management System
' 版本编号: Version 1.X
' 官方网站: http://www.syccms.com
' 官方论坛：http://bbs.syccms.com
' 版权所有: 搜一次运营团队
' 法律顾问: 杭州市元茂律师事务所 严飞律师
' 郑重声明:
'    1、任何个人或组织不得在未经授权的情况下删除、修改、拷贝本软件及其他副本上一切关于版权的信息；
'    2、搜一次网络事业部保留此软件的法律追究权利
'**************************************************************************************************
*/
include "admin_loginstate.php";
include "../include/conn.php";
include "../include/function.php";
include "admin_version.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=gb2312" />
<link  href="images/style.css" rel="stylesheet" type="text/css" />
<title>视频分类</title>
<script type="text/javascript" language="javascript">var tentpath='<?php echo S_SitePath?>';</script>
<script src="js/jquery.js"></script>
<script language="javascript" src="js/alerts.js"></script>
<link type="text/css" href="images/alerts.css" rel="stylesheet" media="screen">
<script language="javascript">
 $(document).ready(function(){
	$("#ChkAll").click(function(){
		if($(this).attr("checked")==true){
			$("input[id='S_ID']").each(function(){
				$(this).attr("checked",true);									 
			})							
		}else{
			$("input[id='S_ID']").each(function(){
				$(this).attr("checked",false);									 
			})							
		}
	})	
		$("#addvc").click(function(){
		 var S_Name=$("#S_Name").val();
		 var S_TheOrder=$("#S_TheOrder").val();
		 var S_AliasName=$("#S_AliasName").val();
		 var S_Template=$("#S_Template").val();
		 var re = /^[a-z0-9]*$/gi
		 $("#S_Name").css("border-color","#666 #ccc #ccc #666");
		 $("#S_TheOrder").css("border-color","#666 #ccc #ccc #666");
		 $("#S_AliasName").css("border-color","#666 #ccc #ccc #666");
		 $("#S_Template").css("border-color","#666 #ccc #ccc #666");
		 $("#tishi").text("");
		 if (S_Name==""){
			 $("#S_Name").css("border","1px solid red");
			 return false;}
		 else if(S_Name.length > 50){
			 $("#S_Name").css("border","1px solid red");
			 $("#tishi").text("分类名称不能超过50个字符！").css("color","red");
			 return false;}
		 else if(S_AliasName==""){
			 $("#S_AliasName").css("border","1px solid red");
			 return false;}
		 else if(S_AliasName.length > 50){
			 $("#S_AliasName").css("border","1px solid red");
		 	 $("#tishi").text("别名不能超过50个字符！").css("color","red");
			 return false;}
		 else if(S_TheOrder==""){
			 $("#S_TheOrder").css("border","1px solid red");
			 return false;}
		 else if(S_TheOrder.length > 10){
			 $("#tishi").text("排序不能超过10个字符！").css("color","red");
			 return false;}
		 else if(S_Template.length > 30){
			 $("#S_Template").css("border","1px solid red");
		 	 $("#tishi").text("模板不能超过30个字符！").css("color","red");
			 return false;}
		 else if(re.test(S_AliasName)==false){
			 $("#S_AliasName").css("border","1px solid red");
		 	 $("#tishi").text("英文别名必须是数字或字母组成！").css("color","red");
			 return false;}
	})
$("#btn_editall").click(function(){
		jConfirm('你确定要修改选中的数据吗?', '操作提示', function(r) {
				if(r==true){
					formclass.action='?action=editall';
					formclass.submit();
					}
				});
	 })
	
$("#btn_delall").click(function(){
		jConfirm('您确定要删除选中的分类吗?', '操作提示', function(r) {
				if(r==true){
					formclass.action='?action=delall';
					formclass.submit();
					}
				});
	 })

	
})

function del(id){
	jConfirm('你确定删除这个分类吗?', '操作提示', function(r) {
		if(r==true){
			window.location='?action=del&S_ID='+id;
			}
				});
		
		}

function delbind(){
	jConfirm('确定取消去资源库绑定的分类吗?', '操作提示', function(r) {
		if(r==true){
			window.location='?action=delbind';
			}
				});
	}

function changehide(id,hi){ 
	window.location.href='?action=exhide&S_ID='+id+'&S_IsHide='+hi+'';
}

function SetClass(S_ID,S_FatherID){
		$("#ClassShow"+S_ID).css("display","");
		$("#Count"+S_ID).css("display","none")
}

function CloseSetClass(S_ID,S_FatherID){
		$("#ClassShow"+S_ID).css("display","none");
		$("#Count"+S_ID).css("display","")
	}

  function SelectPid(p,i){
  if(p!=i){
	  window.location.href = '?action=savefahterid&S_ID='+i+'&S_FatherID='+p;
	}
  }
</script>
</head>

<body>
<?php
class ui_class{
	public function main(){
		global $db;
		$sql="select * from s_class where S_SystemID=1 and S_FatherID=0";
		$result=$db->query($sql);
		$classnum=$db->num_rows($result);
?>
<div class="r_main">
	<div class="r_content">
		<div class="r_content_1">
      <table width="100%" border="0" cellpadding="0" cellspacing="0"  class="tb_style">
       <form method="post" name="formclass" action=""> 
       <tr>
        <td colspan="7" class="td_title" align="left">&nbsp;视频分类管理<a href="#" onclick="delbind()"><font color="red">【清空所有绑定的分类】</font></a></td>
       </tr>
        <tr>
          <td width="5%" height="30" bgcolor="#FFFFFF" class="td_border">&nbsp;&nbsp;编号</td>
          <td width="41%" bgcolor="#FFFFFF" class="td_border">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 中文名称</td>
          <td width="15%" align="center" bgcolor="#FFFFFF" class="td_border">英文别名</td>
          <td width="15%" align="center" bgcolor="#FFFFFF" class="td_border">频道模板</td>
          <td width="8%" align="center" bgcolor="#FFFFFF" class="td_border">排序</td>
          <td width="8%" align="center" bgcolor="#FFFFFF" class="td_border">显示</td>
          <td width="8%" align="center" bgcolor="#FFFFFF" class="td_border">操作</td>
        </tr>
<?php
	   if($classnum==0) echo "
			<tr>
				<td colspan=\"8\" class=\"td_border\" height=\"30\" align=center><b>暂无视频分类,请添加！</b></td>
			</tr>";		
		if($result){
			while($row=$db->fetch_array($result)){
?>	
			<tr>
          <td width="5%"   height="30" bgcolor="#FFFFFF" class="td_border">&nbsp;<input type="checkbox" name="S_ID[]" id="S_ID"  value="<?php echo $row['S_ID']?>" class="checkbox"/><?php echo $row['S_ID']?>、</td>
          <td width="41%"   bgcolor="#FFFFFF" class="td_border"><div style="float:left;">&nbsp; <?php if($row['S_FatherID']==0){echo "&nbsp;╄&nbsp;";}else{echo "&nbsp;├&nbsp;";}?><input type="text" value="<?php echo $row['S_Name']?>" size="10"  name="S_Name<?php echo $row['S_ID']?>">&nbsp;&nbsp;<input type="button" name="SetPart" value="设置上级"   class="rb1" onClick="SetClass(<?php echo $row['S_ID']?>,<?php echo $row['S_FatherID']?>)"/></div>
          
           <div id="Count<?php echo $row['S_ID']?>" style="float:left; height:25px; line-height:25px; color:red;">&nbsp;<a href="admin_video.php?action=listbycs&S_ID=<?php echo $row['S_ID']?>">(共<?php
           		$sqlstr="select count(S_ID) from s_video where S_ClassID=".$row['S_ID']."";
        		$res=@mysql_query($sqlstr);
 				$nums=@mysql_fetch_row($res);
				echo $nums[0];
		   ?>条)</a></div>
              <div id="ClassShow<?php echo $row['S_ID']?>" style=" float:left;display:none; height:25px; margin-top:5px;">&nbsp;<select id="classsel_<?php echo $row['S_ID']?>" name="classsel_<?php echo $row['S_ID']?>" onChange="SelectPid(this.value,<?php echo $row['S_ID']?>);">
              <option value="0">顶级分类</option>
              <?php
              	$sqlstr2="select * from s_class where S_SystemID=1 and S_FatherID=0";
				$re=$db->query($sqlstr2);
				if($re){
					while ($row2=$db->fetch_array($re)){
?>
					<option value="<?php echo $row2['S_ID']?>" <?php if($row2['S_ID']==$row['S_ID']){echo "selected";}?>><?php echo $row2['S_Name']?></option>
<?php
						}
					}
			  
			  ?>
  </select>&nbsp;<a onclick="CloseSetClass(<?php echo $row['S_ID']?>,<?php echo $row['S_FatherID']?>)"><img src="images/starno.gif" /></a></div>           
          </td>
          <td width="15%"   align="center" bgcolor="#FFFFFF" class="td_border">&nbsp;<input type="text" value="<?php echo $row['S_AliasName']?>" name="S_AliasName<?php echo $row['S_ID']?>" size="12"></td>
          <td width="15%"   align="center" bgcolor="#FFFFFF" class="td_border">&nbsp;<input type="text" value="<?php echo $row['S_Template']?>" name="S_Template<?php echo $row['S_ID']?>" size="15"></td>
          <td width="8%"    align="center" bgcolor="#FFFFFF" class="td_border">&nbsp;<input type="text" value="<?php echo $row['S_TheOrder']?>" name="S_TheOrder<?php echo $row['S_ID']?>" size="4"></td>
          <td width="8%"    align="center" bgcolor="#FFFFFF" class="td_border">&nbsp;<select name="S_IsHide<?php echo $row['S_ID']?>" onchange="changehide(<?php echo $row['S_ID']?>,this.value)">
          	<option value="0" <?php if($row['S_IsHide']==0){echo "selected";}?>>显示</option>
            <option value="1" <?php if($row['S_IsHide']==1){echo "selected";}?>>隐藏</option>
          </select></td>
          <td width="8%"    align="center" bgcolor="#FFFFFF" class="td_border">&nbsp;<input type="button" value="删除" onclick="del(<?php echo $row['S_ID']?>)"class="rb1"></td>
	</tr>
<?php			
		//处理此分类下的子分类
		$sql2="select * from s_class where S_FatherID=".$row['S_ID']."";
		$class2=$db->query($sql2);
		if($class2){
			while($rowclass2=$db->fetch_array($class2)){
?>
			<tr>
          <td width="5%"   height="30" bgcolor="#FFFFFF" class="td_border">&nbsp;<input type="checkbox" name="S_ID[]" id="S_ID"  value="<?php echo $rowclass2['S_ID']?>" class="checkbox"/><?php echo $rowclass2['S_ID']?>、</td>
          <td width="41%"   bgcolor="#FFFFFF" class="td_border"><div style="float:left;">&nbsp; <?php if($rowclass2['S_FatherID']==0){echo "&nbsp;╄&nbsp;";}else{echo "&nbsp;├&nbsp;";}?><input type="text" value="<?php echo $rowclass2['S_Name']?>" size="10"  name="S_Name<?php echo $rowclass2['S_ID']?>">&nbsp;&nbsp;<input type="button" name="SetPart" value="设置上级"   class="rb1" onClick="SetClass(<?php echo $rowclass2['S_ID']?>,<?php echo $rowclass2['S_FatherID']?>)"/></div>
          
           <div id="Count<?php echo $rowclass2['S_ID']?>" style="float:left; height:25px; line-height:25px; color:red;">&nbsp;<a href="admin_video.php?action=listbycs&S_ID=<?php echo $rowclass2['S_ID']?>">(共<?php
           		$sqlstr="select S_ID from s_video where S_ClassID=".$rowclass2['S_ID']." ";
        		$res=$db -> query($sqlstr);
 				$nums= $db -> num_rows($res);
				echo $nums;
		   ?>条)</a></div>
              <div id="ClassShow<?php echo $rowclass2['S_ID']?>" style=" float:left;display:none; height:25px; margin-top:5px;">&nbsp;<select id="classsel_<?php echo $rowclass2['S_ID']?>" name="classsel_<?php echo $rowclass2['S_ID']?>" onChange="SelectPid(this.value,<?php echo $rowclass2['S_ID']?>);">
              <option value="0">顶级分类</option>
              <?php
              	$sqlstr2="select * from s_class where S_SystemID=1 and S_FatherID=0";
				$re=$db->query($sqlstr2);
				if($re){
					while ($row2=$db->fetch_array($re)){
?>
					<option value="<?php echo $row2['S_ID']?>" <?php if($row2['S_ID']==$row['S_ID']){echo "selected";}?>><?php echo $row2['S_Name']?></option>
<?php
						}
					}
			  
			  ?>
              </select>&nbsp;[<a onclick="CloseSetClass(<?php echo $row['S_ID']?>,<?php echo $row['S_FatherID']?>)">关闭</a>]</div>           
          </td>
          <td width="15%"   align="center" bgcolor="#FFFFFF" class="td_border">&nbsp;<input type="text" value="<?php echo $rowclass2['S_AliasName']?>" name="S_AliasName<?php echo $rowclass2['S_ID']?>" size="12"></td>
          <td width="15%"   align="center" bgcolor="#FFFFFF" class="td_border">&nbsp;<input type="text" value="<?php echo $rowclass2['S_Template']?>" name="S_Template<?php echo $rowclass2['S_ID']?>" size="15"></td>
          <td width="8%"    align="center" bgcolor="#FFFFFF" class="td_border">&nbsp;<input type="text" value="<?php echo $rowclass2['S_TheOrder']?>" name="S_TheOrder<?php echo $rowclass2['S_ID']?>" size="4"></td>
          <td width="8%"    align="center" bgcolor="#FFFFFF" class="td_border">&nbsp;<select name="S_IsHide<?php echo $rowclass2['S_ID']?>" onchange="changehide(<?php echo $rowclass2['S_ID']?>,this.value)">
          	<option value="0" <?php if($rowclass2['S_IsHide']==0){echo "selected";}?>>显示</option>
            <option value="1" <?php if($rowclass2['S_IsHide']==1){echo "selected";}?>>隐藏</option>
          </select></td>
          <td width="8%"    align="center" bgcolor="#FFFFFF" class="td_border">&nbsp;<input type="button" value="删除" onclick="del(<?php echo $rowclass2['S_ID']?>)"class="rb1"></td>
	</tr>
<?php				
				}
			}
			}
		}

?>

		<tr>
<td height="30" colspan="7" align="left" bgcolor="#FFFFFF" class="td_border">&nbsp;<input type="checkbox" name="ChkAll" id="ChkAll" ids="S_ID"  class="checkbox"/>全选&nbsp;&nbsp;
						  &nbsp;&nbsp;&nbsp;&nbsp; <input type="button" name="editall" value="修改所选分类" class="rb1"  id="btn_editall"/>
				      &nbsp;&nbsp;<input type="button" name="delall"  value="删除所选分类" class="rb1"  id="btn_delall"/></td>
		 </tr>

    </form>
  </table> 
  
  			  <form id="form1" name="form1" method="post" action="?action=saveadd">
					<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tb_style">
                    <tr>
                      <td colspan="7" class="td_title">&nbsp;视频分类添加&nbsp;&nbsp;<label id="tishi"></label></td>
                     </tr>
					  <tr>
						<td  height="30" align="center" bgcolor="#FFFFFF" class="td_border">中文名称</td>
                        <td   align="center" bgcolor="#FFFFFF" class="td_border" >英文别名</td>
						<td   align="center" bgcolor="#FFFFFF"class="td_border">所属上级</td>
						<td   align="center" bgcolor="#FFFFFF" class="td_border">频道模板</td>
						<td  align="center" bgcolor="#FFFFFF" class="td_border">排序</td>
						<td   align="center" bgcolor="#FFFFFF" class="td_border">隐藏</td>
                        <td   align="center" bgcolor="#FFFFFF" class="td_border">&nbsp;</td>
					  </tr>
				   
					  
					<tr>
                        <td height="30" align="center" bgcolor="#FFFFFF" class="td_border">
						  <input type="text" name="S_Name" id="S_Name" value="" />
						</td>
                        <td height="30" align="center" bgcolor="#FFFFFF" class="td_border">
						  <input type="text" name="S_AliasName" id="S_AliasName" value="" size="15" />
						</td>
						<td  height="30" align="center" bgcolor="#FFFFFF" class="td_border">
						<select name="S_FatherID" id="S_FatherID">
							<option value="0">作为顶级</option>
              <?php
              	$sqlclass="select * from s_class where S_SystemID=1 and S_FatherID=0";
				$results=$db->query($sqlclass);
				if($results){
					while ($row3=$db->fetch_array($results)){
?>
					<option value="<?php echo $row3['S_ID']?>" ><?php echo $row3['S_Name']?></option>
<?php
						}
					}
			  
			  ?>						
              </select>
					  </td>
						<td  height="30" align="center" bgcolor="#FFFFFF" class="td_border">
							<input name="S_Template" type="text" id="S_Template" value="vodlist.html" />
						</td>
						<td  height="30" align="center" bgcolor="#FFFFFF" class="td_border"><input type="text" name="S_TheOrder" id="S_TheOrder" value="0" size="5" onkeyup="this.value=this.value.replace(/[^\d]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"/></td>
						<td  height="30" align="center" bgcolor="#FFFFFF" class="td_border">
                        <select name="S_IsHide">
                             <option value="0" >显 示</option>
                             <option value="1">隐 藏</option>
                         </select></td>
                      <td align="center"   class="td_border"><input type="submit" name="button" id="addvc" value="提 交" class="rb1" /></td>
					  </tr>
				</table>   
				  
				</form>
                <form action="?action=movevideo" name="movevideo" id="movevideo" method="post">
              <table width="100%" border="0" cellpadding="0" cellspacing="0" class="tb_style">
                <tr>
                  <td class="td_title">&nbsp;转移分类数据</td>
                </tr>
                <tr>
                  <td height="30" bgcolor="#FFFFFF" class="td_border">&nbsp;将分类：
                    <select size="1" name="Type_1">
                     <option value="">选择分类</option> 
              <?php
              	$sqlclass="select * from s_class where S_SystemID=1";
				$results=$db->query($sqlclass);
				if($results){
					while ($row3=$db->fetch_array($results)){
?>
					<option value="<?php echo $row3['S_ID']?>" ><?php echo $row3['S_Name']?></option>
<?php
						}
					}
			  
			  ?>						
                    </select>
的数据转移到
                    <select size="1" name="Type_2">
                    <option value="">选择分类</option>
              <?php
              	$sqlclass="select * from s_class where S_SystemID=1 ";
				$results=$db->query($sqlclass);
				if($results){
					while ($row3=$db->fetch_array($results)){
?>
					<option value="<?php echo $row3['S_ID']?>" ><?php echo $row3['S_Name']?></option>
<?php
						}
					}
			  
			  ?>						
                    </select>
					<input type="submit" value="确定转移" name="submit" class="rb1" /></td>
                </tr>
                <tr>
                  <td height="30"   class="td_border">&nbsp;<strong><font color="#FF0000">注意：操作前请先备份数据库，程序将前面的分类数据合并到后面分类后将不能再恢复原始分类，请一定要慎重操作!</font></strong></td>
                </tr>
              </table>
              </form>                
		</div>
	</div>
</div>
<?php
		}
	
	}//end class

?>        

<?php
$ui=new ui_class;
$action=SafeRequest("action","get");
switch($action){
	case 'main':
		$ui->main();
		break;
	case 'saveadd':
		saveadd();
		break;
	case 'del':
		del();
		break;
	case 'delall':
		delall();
		break;
	case 'editall':
		editall();
		break;
	case 'exhide':
		exhide();
		break;
	case 'savefahterid':
		savefahterid();
		break;
	case 'movevideo':
		movevideo();
		break;
	case 'delbind':
		delbind();
		break;
	default:
		$ui->main();
		break;
}
	
	function delbind(){
		global $db;
		$sql="select * from s_class";
		$result=$db->query($sql);
		if($result){
			while($row=$db->fetch_array($result)){
				$db->query("update s_class set S_TieID='' where S_ID=".$row['S_ID']."");
				}
			}
		die("<script>jAlert('分类绑定取消成功！','操作提示',function(R){window.location='admin_videoclass.php';})</script>");	
		}
	
	function exhide(){
		global $db;
		$S_ID=SafeRequest("S_ID","get");
		$S_IsHide=SafeRequest("S_IsHide","get");
		$sql="update s_class set S_IsHide=".$S_IsHide." where S_ID=".$S_ID."";
		$db->query($sql);
		echo "<script>window.location='admin_videoclass.php'</script>";
		}
	
	function movevideo(){
		global $db;
		$classa=SafeRequest("Type_1","post");
		$classb=SafeRequest("Type_2","post");
		if(!IsNul($classa)|!IsNul($classb) ){
			die("<script>jAlert('请选择要转移的分类?','操作提示',function(R){history.back();})</script>");
			}
			
		$sql="select * from s_video where S_ClassID=".$classa."";
		$result=$db->query($sql);
		if($result){
			while($row=$db->fetch_array($result)){
				$sqlstr="update s_video set S_ClassID=".$classb." where S_ID=".$row['S_ID']."";
				$db->query($sqlstr);
				}
			die("<script>jAlert('数据转移成功！','操作提示',function(R){window.location='admin_videoclass.php';})</script>");	
			}
		}
	
	function savefahterid(){
		global $db;
		$S_ID=SafeRequest("S_ID","get");
		$S_FatherID=SafeRequest("S_FatherID","get");
		if(IsNum($S_ID)||IsNum($S_FatherID)){
			$sql="update s_class set S_FatherID=".$S_FatherID." where S_ID=".$S_ID."";
			$db->query($sql);
			$sqlstr="select * from s_class where S_FatherID=".$S_ID."";
			$result=$db->query($sqlstr);
			if($result){
				while($row=$db->fetch_array($result)){
					$db->query("update s_class set S_FatherID=".$S_FatherID." where S_ID=".$row['S_ID']."");
					}
				}
			die("<script>window.location='admin_videoclass.php'</script>");
			}
		}
	
	function editall(){
		global $db;
		$S_ID=RequestBox("S_ID");
		if($S_ID=="0"){
			die("<script>jAlert('请选择要编辑的分类?','操作提示',function(R){history.back();})</script>");
			}
		else{
			$ID=explode(",",$S_ID);
			
			for($i=0;$i<count($ID);$i++){
				$S_Name=SafeRequest("S_Name".$ID[$i]."","post");
				$S_AliasName=SafeRequest("S_AliasName".$ID[$i]."","post");
				$S_Template=SafeRequest("S_Template".$ID[$i]."","post");
				$S_TheOrder=SafeRequest("S_TheOrder".$ID[$i]."","post");
				$S_IsHide=SafeRequest("S_IsHide".$ID[$i]."","post");
			if(!IsNul($S_Name)){echo "<script>jAlert('分类名称不能为空!','操作提示',function(R){history.back();})</script>";}
			if(!IsNul($S_AliasName)){echo "<script>jAlert('分类别名称不能为空!','操作提示',function(R){history.back();})</script>";}
				$sql="update s_class set S_Name='".$S_Name."',S_AliasName='".$S_AliasName."',S_TheOrder=".$S_TheOrder.",S_Template='".$S_Template."',S_IsHide=".$S_IsHide." where S_ID=".$ID[$i]."";
				$db->query($sql);
				}
			die("<script>jAlert('恭喜！恭喜分类编辑成功!','操作提示',function(R){window.location='admin_videoclass.php';})</script>");
			}			
		
		}
	
	function delall(){
		global $db;
		$S_ID=RequestBox("S_ID");
		$sql="delete from s_class where S_ID in ($S_ID)";
		if($S_ID=="0"){
			die("<script>jAlert('请选择要删除的分类?','操作提示',function(R){history.back();})</script>");
			}
		else{
			$arr=explode(',',$S_ID);
			for($i=0;$i<count($arr);$i++){
				//判断有无子级
				$sql2="select count(S_ID) as cc from s_class where S_FatherID=$arr[$i]";
				$row2=$db->getRow($sql2);
				if($row2){
					if($row2['cc']>0) die("<script>alert('ID为".$arr[$i]."分类下有子分类不能删除！');window.location='admin_videoclass.php';</script>");
					}
				//判断有无数据
				$sqlstr="select count(S_ID) as vcount from s_video where S_ClassID=$arr[$i]";
				$row=$db->getRow($sqlstr);
				if($row){
					if($row['vcount']>0) die("<script>alert('ID为".$arr[$i]."分类下有数据不能删除！');window.location='admin_videoclass.php';</script>");
					}
				}
			if($db->query($sql)){
				die("<script>jAlert('恭喜你！操作成功了！','成功提示',function(R){window.location='admin_videoclass.php';})</'script>");
				}
			}
		}
	
	function del(){
		global $db;
		$S_ID=SafeRequest("S_ID","get");
		//判断有无子级
		$sql2="select count(S_ID) as cc from s_class where S_FatherID=$S_ID";
		$row2=$db->getRow($sql2);
		if($row2){
			if($row2['cc']>0) die("<script>alert('ID为".$S_ID."分类下有子分类不能删除！');window.location='admin_videoclass.php';</script>");
			}		
		$sqlstr="select count(S_ID) as vcount from s_video where S_ClassID=$S_ID";
		$row=$db->getRow($sqlstr);
		if($row){
			if($row['vcount']>0) die("<script>alert('该分类下有数据不能删除！');window.location='admin_videoclass.php';</script>");
			}
		$sql="delete from s_class where S_ID='".$S_ID."'";
		if($db->query($sql)){
			die("<script>window.location='admin_videoclass.php'</script>");
			}
		}
	
	function saveadd(){
		global $db;
		$S_Name=SafeRequest("S_Name","post");
		$S_AliasName=SafeRequest("S_AliasName","post");
		$S_FatherID=SafeRequest("S_FatherID","post");
		$S_TheOrder=SafeRequest("S_TheOrder","post");
		$S_Template=SafeRequest("S_Template","post");
		$S_IsHide=SafeRequest("S_IsHide","post");
		$sql="insert into s_class (S_Name,S_AliasName,S_FatherID,S_TheOrder,S_Template,S_IsHide,S_SystemID,collectbind) values ('".$S_Name."','".$S_AliasName."',".$S_FatherID.",".$S_TheOrder.",'".$S_Template."',".$S_IsHide.",1,'')";
		$db->query($sql);
		echo "<script>window.location='admin_videoclass.php'</script>";
		}	
?>
<?php include "admin_bottom.php"; ?>
</body>
</html>