<?php
# Name: PHP版程氏音乐CMS管理系统 v3.0
# Author: 程氏<web@chshcms.com> [QQ:848769359]
# Homepage:http://www.chshcms.cn/
include_once("../../lib/cs_label.php");
include_once("../loginstate.php");
SystemPer('2_2');
$ac=CS_Request("ac");
?>
<!doctype html>
<html>
<head>
<meta charset=utf-8>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>chshdjcms management</title>
<link href="../res/css/admin_style.css" rel="stylesheet" />
<link href="../../public/css/webox.css" rel="stylesheet" />
<script type="text/javascript" src="../res/js/ajax.js"></script>
<script language="javascript" src="../res/js/jquery.js"></script>
<script type="text/javascript" src="../../public/js/webox.js"></script>
<script language="javascript">
function del(_id){ 
  if (confirm("确定删除吗？")){
    window.location='?ac=del&id='+_id;
    return true;
  }else{
     return false;
  }		
}

</script>
</head>
<body>
<div class="wrap">
<!-- start -->
<div class="nav">
	<ul class="cc">
			<li class="current"><a href="?">歌曲服务器组</a></li>
		        <li><a href="javascript:Popsboxif('添加服务器组',450,305,'pathip_add.php');">添加服务器组</a></li>
	</ul>
</div>
<form method="post" class="J_ajaxForm" action="?ac=edit" data-role="list">
<div class="table_list">
	<table width="100%" id="J_table_list" style="table-layout:fixed;">
		<colgroup>
			<col width="30">
			<col width="250">
			<col width="300">
			<col width="300">
			<col>
		</colgroup>
		<thead>
			<tr>
				<td></td>
				<td>[ID] 组名称</td>
				<td>视听地址</td>
				<td>下载地址</td>
				<td>数据总数</td>
				<td>操作</td>
			</tr>
		</thead>
<?php
	global $db;
        $sql="select * from ".Getdbname('fwqip')." order by CS_ID asc";
	$rs=$db->query($sql);
	$num=$db->num_rows($rs);
 	for($i=0;$i<$num;$i++){ 
		$row=$db->fetch_array($rs);
                $dancenum= $db -> num_rows($db -> query("select * from ".Getdbname('dance')." where cs_fid=".$row['CS_ID'].""));
?>
		<tbody>
		<tr>
			<td><span class="zero_icon"></span></td>
			<td>
				<input name="CS_ID[]" type="text" class="input length_0 mr10" value="<?php echo $row['CS_ID']?>">
				<input name="CS_Name<?php echo $row['CS_ID']?>" type="text" class="input length_3 mr5" value="<?php echo $row['CS_Name']?>">
			</td>
			<td><input name="CS_Playip<?php echo $row['CS_ID']?>" type="text" class="input length_4" value="<?php echo $row['CS_Playip']?>"></td>
			<td><input name="CS_Downip<?php echo $row['CS_ID']?>" type="text" class="input length_4" value="<?php echo $row['CS_Downip']?>"></td>
			<td><a href="dj.php?fid=<?php echo $row['CS_ID']?>">共<?php echo $dancenum?>条</a></td>
			<td>
				<a style="cursor:pointer;"  onclick="del(<?php echo $row['CS_ID']?>);" class="mr10 J_ajax_del">[删除]</a>
			</td>
		</tr>
		</tbody>
<?php
 	} 
?>
	</table>
</div>
<div class="btn_wrap">
	<div class="btn_wrap_pd">
		<button class="btn btn_submit mr10 J_ajax_submit_btn" id="addlist" type="submit">提交</button>
                <div class="tips_error" id="Msg"></div>
	</div>
</div>	
</form>
<!-- end -->
</div>
<?php
   if($ac=='edit'){   //修改
        global $db;
   	$CS_ID=CS_RequestBox("CS_ID");
	$ID=explode(",",$CS_ID);
		for($i=0;$i<count($ID);$i++){
			$CS_Name=CS_Request("CS_Name".$ID[$i]);
			$CS_Playip=CS_Request("CS_Playip".$ID[$i]);
			$CS_Downip=CS_Request("CS_Downip".$ID[$i]);

                        if(!empty($CS_Name)&&!empty($CS_Playip)&&!empty($CS_Downip)){

				$sql="update ".Getdbname('fwqip')." set CS_Name='".$CS_Name."',CS_Playip='".$CS_Playip."',CS_Downip='".$CS_Downip."' where CS_ID=".$ID[$i]."";
				$db->query($sql);
                        }
		}

      echo '<script>document.getElementById("Msg").className="tips_success";$("#Msg").text("恭喜您,修改成功！").css("color","#026E12");</script>';
      echo "<script>setTimeout(\"window.location.href ='pathip.php';\",2000);</script>";
   }
   if($ac=='del'){   //删除
       $CS_ID=CS_Request("id");
		$sqlstr="select count(CS_ID) as vcount from ".Getdbname('dance')." where CS_FID=$CS_ID";
		$row=$db->getRow($sqlstr);
		if($row){
			if($row['vcount']>0){
                           echo '<script>$("#Msg").text("抱歉,该服务器组下有数据不能删除！").css("color","red");</script>';
                           exit();
			}
		}
                $sql="delete from ".Getdbname('fwqip')." where CS_ID=".$CS_ID;
		if($db->query($sql)){
                     echo '<script>document.getElementById("Msg").className="tips_success";$("#Msg").text("恭喜您,删除成功！").css("color","#026E12");</script>';
                     echo "<script>setTimeout(\"window.location.href ='pathip.php';\",2000);</script>";
                }else{
                     echo '<script>$("#Msg").text("抱歉,删除失败！").css("color","red");</script>';
                }
   }
?>
</body>
</html>
