<?php
/*
'**************************************************************************************************
' 软件名称: 盘锦DJ舞曲网CMS Content Management PjRen.Net
' 版本编号: Version 2.5
' 盘锦舞曲: http://www.pj57.com
' 官方网站: http://www.pjren.net
' 小说网站: http://www.hx39.com
' 0427DJ网: http://www.0427dj.net
' 官方论坛: http://www.tianjiazhen.com
' 版权所有: 盘锦舞曲开发团队    盘锦人(QQ:814006710)
' 郑重声明:
'    1、任何个人或组织不得在未经授权的情况下删除、修改、拷贝本软件及其他副本上一切关于版权的信息；
'    2、盘锦网络事业部保留此软件的法律追究权利
'**************************************************************************************************
*/
include "../include/conn.php";
include "../include/function.php";
include "admin_version.php";
include "admin_loginstate.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">
</head>
<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);									 
			})							
		}
	})	
	$("#addlink").click(function(){
		 $("#S_Name").css("border-color","#666 #ccc #ccc #666");
		 $("#sname").text("");
		 $("#SInPut").text("");
		 $("#S_Pic").text("");
		 $("#S_PlayUrl").css("border-color","#666 #ccc #ccc #666");
		 $("#SWebUrl").text("").css("color","red");
		 var S_Name=$("#S_Name").val();
		 var S_PlayUrl=$("#S_PlayUrl").val();
		 var S_Pic=$("#S_Pic").val();
		 var S_InPut=$("#S_InPut").val();
		 if (S_Name==""){
			 $("#S_Name").css("border","1px solid red");
			 $("#sname").text("请填写服务器名！").css("color","red");
			 return false;}
		 else if(S_Name.length > 50){
		 	 $("#S_Name").css("border","1px solid red");
			 $("#sname").text("服务器名不能超过50个字符！").css("color","red");
			 return false;}
		 else if(S_PlayUrl==""){
			 $("#S_PlayUrl").css("border","1px solid red");
			 $("#SWebUrl").text("请填写服务器链接！").css("color","red");
			 return false;}
		 else if(S_PlayUrl.length > 100){
		 	 $("#S_PlayUrl").css("border","1px solid red");
			 $("#SWebUrl").text("服务器链接不能超过100个字符！").css("color","red");
			 return false;} 
		 else if(S_Pic.length > 150){
			 $("#SPic").text("申请服务器地址不能超过100个字符！").css("color","red");	
			 return false;
			 }
		 else if(S_InPut.length > 100){
			 $("#SInPut").text("申请服务器地址不能超过100个字符！").css("color","red");
			 return false;
			 }
		 })
	
	$("#btn_editall").click(function(){
		var page=$("#page").val();							 
		jConfirm('确定要编辑选中的服务器组吗?', '操作提示', function(r) {
				if(r==true){
					document.Link.action='?action=editall'
					Link.submit();}
				});
	 })
		
	 $("#btn_delall").click(function(){
		var page=$("#page").val();							 
		jConfirm('确定要删除选中的服务器组吗?', '操作提示', function(r) {
				if(r==true){
					document.Link.action='?action=delall'
					Link.submit();}
				});
	 })
		
})

function del(id,page){
	jConfirm('确定要删除该服务器组吗?', '操作提示', function(r) {
		if(r==true){
			window.location='?action=del&S_ID='+id;
			}
				});
		
		}

</script>

<body>
<?php
SystemPer(2);
	class ui_server{
		
		public function editdata($Arr,$url){
					$name=$Arr[0];
					$Playurl=$Arr[1];
					$Downurl=$Arr[2];
					$order=$Arr[3];

			
?>
<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 name="form1" method="post" action="<?php echo $url?>" >
			  <tr>
				<td height="30" colspan="2" class="td_title">&nbsp;添加服务器组</td>
			</tr>
			  <tr>
				<td width="28%" height="30" align="right" class="td_border">服务器名称：</td>
				<td width="72%" class="td_border">&nbsp;
				  <input name="S_Name" type="text" id="S_Name" value="<?php echo $name?>" size="35" />
                    <font color="#FF0000">＊</font>
                <label id="sname"></label>				</td>
		      </tr>
			  <tr>
			    <td height="30" align="right" class="td_border">视听地址：</td>
			    <td class="td_border"> &nbsp;
			      <input name="S_PlayUrl" type="text" id="S_PlayUrl"  value="<?php echo $Playurl?>" size="35" />
                  <font color="#FF0000">＊</font>
                  <label id="SWebUrl"></label></td>
		      </tr>
			  <tr>
			    <td height="30" align="right" class="td_border">下载地址：</td>
			    <td class="td_border"> &nbsp;
			      <input name="S_DownUrl" type="text" id="S_DownUrl"  value="<?php echo $Downurl?>" size="35" />
                  <font color="#FF0000">＊</font>
                  <label id="SWebUrl"></label></td>
		      </tr>
			  <tr>
			    <td height="30" align="right" class="td_border">服务器排序：</td>
			    <td class="td_border"> &nbsp;
			      <input name="S_TheOrder" type="text" id="S_TheOrder" value="<?php echo $order?>" size="5" />
                  <font color="#FF0000">&nbsp;&nbsp;＊按数字序列排序</font>
                  <label id="SWebUrl"></label></td>
		      </tr>
			  
			  
			  <tr>
				<td height="30" align="right" class="td_border">&nbsp;</td>
				<td height="30" class="td_border"> &nbsp;
				  <input type="submit" name="Submit" value="确定提交" class="rb1" id="addlink"/>
				  &nbsp;&nbsp; <input type="reset" name="Submit2" value="清除重置" class="rb1" /></td>
			  </tr>
			</form>  
</table>
		</div>
	</div>
</div>
<?php			
			}
		
		public function main(){
			global $db;
			$Arr=getpagerow("select * from s_pathip",20);//sql,每页显示条数
			$result=$db->query($Arr[2]);
			$pathnum=$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="Link" action="">
                      <tr>
                        <td colspan="6" class="td_title" height="30">&nbsp;服务器组管理</td>
                      </tr>
                      <tr>
                        <td width="126" height="30" bgcolor="#FFFFFF" class="td_border">&nbsp;&nbsp;编号</td>
                        <td width="180" bgcolor="#FFFFFF" class="td_border">&nbsp; 服务器名称<font color="#FF0000">(＊)</font></td>
                        <td width="268" bgcolor="#FFFFFF" class="td_border">&nbsp; 视听地址<font color="#FF0000">(＊)</font></td>
                        <td width="268" bgcolor="#FFFFFF" class="td_border">&nbsp; 下载地址<font color="#FF0000">(＊)</font></td>
                        <td width="106" bgcolor="#FFFFFF" class="td_border">&nbsp; 排序</td>
                         <td width="227" align="center" bgcolor="#FFFFFF" class="td_border">操作</td>
                      </tr>
                       <?php
					   if($pathnum==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="126" height="28" 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 bgcolor="#FFFFFF" class="td_border">
			         &nbsp;
		          <input type="text" name="S_Name<?php echo $row["S_ID"]?>" value="<?php echo $row["S_Name"]?>" size="12" /></td>
				  <td bgcolor="#FFFFFF" class="td_border"> &nbsp;
			      <input type="text" name="S_PlayUrl<?php echo $row["S_ID"]?>" value="<?php echo $row["S_AddPath"]?>" size="35" /></td>
                  <td bgcolor="#FFFFFF" class="td_border"> &nbsp;
			      <input type="text" name="S_DownUrl<?php echo $row["S_ID"]?>" value="<?php echo $row["S_DownPath"]?>" size="35" /></td>
                  <td bgcolor="#FFFFFF" class="td_border"> &nbsp;
                    <input type="text" name="S_TheOrder<?php echo $row["S_ID"]?>" value="<?php echo $row["S_TheOrder"]?>"size="5"/></td>
					<td align="center" bgcolor="#FFFFFF" class="td_border"><a href="?action=editdata&S_ID=<?php echo $row['S_ID']?>">编辑</a>&nbsp;&nbsp; &nbsp;<a style="cursor:pointer;"  onclick="del(<?php echo $row['S_ID']?>)">删除</a></td>
	  </tr>
   <?php
                         							   
		 }
	 }
?> 
      <tr>
            <td height="30" colspan="6" align="left" bgcolor="#FFFFFF" class="td_border">&nbsp;
   <input type="hidden" name="page" id="page" value="<?php echo page?>"><input type="checkbox" name="ChkAll" id="ChkAll" ids="S_ID"  class="checkbox"/>
   全选&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
   &nbsp; <input type="button" id="btn_editall" value="修改服务器组" class="rb1"   />
   &nbsp;&nbsp;
  <input type="button" value="删除服务器组"  class="rb1" id="btn_delall" />
 &nbsp; <input type="button" value="添加服务器组"  class="rb1" id="btn_add" onclick="window.location='?action=add'" />
  </td></tr>
      </form>
      <tr><td height="30" colspan="8" align="right" class="td_border" style="font-size:12px; color:#033d61;">
        <?php echo $Arr[0];?></td></tr>
</table>
		</div>
	</div>
</div>
<?php			
				
			}
		}//end class

?>

<?php
	$ui=new ui_server;
	$action=SafeRequest("action","get");
	switch ($action){
		case 'main':
			$ui->main();
			break;
		case 'editdata':
			editdata();
			break;
		case 'saveedit':
			saveedit();
			break;
		case 'add':
			add();
			break;
		case 'saveadd':
			saveadd();
			break;
		case 'del':
			del();
			break;
		case 'delall':
			delall();
			break;
		case 'editall':
			editall();
			break;
		case 'changeverify':
			changeverify();
			break;
		case 'changeindex':
			changeindex();
			break;
		default:
			$ui->main();
		}
	function changeindex(){
		global $db;
		$isindex=SafeRequest("isindex","get");
		$id=SafeRequest("id","get");
		if(!IsNum($isindex)) $isindex=0;
		if(!IsNum($id)) die("<script>jAlert('id传输错误?','操作提示',function(R){history.back();})</script>");
		$sql="update s_pathip set S_IsIndex=$isindex where S_ID=$id";
		if($db->query($sql)){
			die("<script>window.location='admin_pathip.php';</script>");
			}
		else{
			die("<script>jAlert('未知错误!','操作提示',function(R){history.back();})</script>");
			}			

		}		
		
	function changeverify(){
		global $db;
		$isverify=SafeRequest("isverify","get");
		$id=SafeRequest("id","get");
		if(!IsNum($isverify)) $isverify=0;
		if(!IsNum($id)) die("<script>jAlert('id传输错误?','操作提示',function(R){history.back();})</script>");
		$sql="update s_pathip set S_IsVerify=$isverify where S_ID=$id";
		if($db->query($sql)){
			die("<script>window.location='admin_pathip.php';</script>");
			}
		else{
			die("<script>jAlert('未知错误!','操作提示',function(R){history.back();})</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_PlayUrl=SafeRequest("S_PlayUrl".$ID[$i]."","post");
				$S_DownUrl=SafeRequest("S_DownUrl".$ID[$i]."","post");
				$S_Order=SafeRequest("S_TheOrder".$ID[$i]."","post");
			if(!IsNul($S_Name)){echo "<script>jAlert('服务器组名称不能为空!','操作提示',function(R){history.back();})</script>";}
			if(!IsNul($S_PlayUrl)){echo "<script>jAlert('服务器组视听地址不能为空!','操作提示',function(R){history.back();})</script>";}
			if(!IsNul($S_DownUrl)){echo "<script>jAlert('服务器组下载地址不能为空!','操作提示',function(R){history.back();})</script>";}
				$sql="update s_pathip set S_Name='".$S_Name."',S_AddPath='".$S_PlayUrl."',S_DownPath='".$S_DownUrl."',S_TheOrder=".$S_Order." where S_ID=".$ID[$i]."";
				$db->query($sql);
				}
			die("<script>jAlert('恭喜！服务器组编辑完毕!','操作提示',function(R){window.location='admin_pathip.php';})</script>");
			}	
		}
		
	function add(){
		global $ui;
		$Arr=array("","","");
		$ui->editdata($Arr,"?action=saveadd");
		}
		
	function saveadd(){
		global $db;
		$S_Name=SafeRequest("S_Name","post");
		$S_PlayUrl=SafeRequest("S_PlayUrl".$ID[$i]."","post");
		$S_DownUrl=SafeRequest("S_DownUrl".$ID[$i]."","post");
		$sql="Insert s_pathip  (S_Name,S_AddPath,S_DownPath,S_TheOrder,S_SystemID) values ('".$S_Name."','".$S_PlayUrl."','".$S_DownUrl."',0,0)";
		//die($sql);
		$db->query($sql);
		echo "<script>window.location='admin_pathip.php';</script>";
		}


	function delall(){
		global $db;
		$S_ID=RequestBox("S_ID");
		$sql="delete from s_pathip where S_ID in ($S_ID)";
		//die($S_ID);
		if($S_ID=="0"){
			die("<script>jAlert('请选择要删除的服务器组?','操作提示',function(R){history.back();})</script>");
			}
		else{
			if($db->query($sql)){
				die("<script>jAlert('恭喜你！操作成功了！','成功提示',function(R){window.location='admin_pathip.php';})</script>");
				}
			}	
		}

	function del(){
		global $db;
		$S_ID=SafeRequest("S_ID","get");
		$sql="delete from s_pathip where S_ID='".$S_ID."'";
		//die($sql);
		if($db->query($sql)){
			echo "<script>window.location='admin_pathip.php';</script>";
			}
		}


	function saveedit(){
		global $db;
		$S_ID=SafeRequest("S_ID","get");
		$S_Name=SafeRequest("S_Name","post");
		$S_PlayUrl=SafeRequest("S_PlayUrl".$ID[$i]."","post");
		$S_DownUrl=SafeRequest("S_DownUrl".$ID[$i]."","post");
		$S_TheOrder=SafeRequest("S_TheOrder","post");
		if(!IsNum($S_TheOrder)) $S_TheOrder=0;
		$sql="update s_pathip set S_Name='".$S_Name."',S_AddPath='".$S_PlayUrl."',S_DownPath='".$S_DownUrl."',S_TheOrder=".$S_TheOrder." where S_ID=".$S_ID."";
		
		$db->query($sql);
		echo "<script>window.location='admin_pathip.php';</script>";
		}

	function editdata(){
		global $db;
		global $ui;
		$S_ID=SafeRequest("S_ID","get");
		if(IsNum($S_ID)){
			$sql="SELECT * FROM `s_pathip` Where S_ID='".$S_ID."'";
			$row=$db->Getrow($sql);
				if($row){
					$Arr=array($row['S_Name'],$row['S_AddPath'],$row['S_DownPath'],$row['S_TheOrder']);
					}
				$ui->editdata($Arr,"?action=saveedit&S_ID=".$S_ID."");
			}
		}

	
?>
<?php include "admin_bottom.php"; ?>
</body>
</html>