<?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('1_4');
$ac=CS_Request("ac");
?>
<!doctype html>
<html>
<head>
<meta charset="gbk">
<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,'link_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="280">
			<col width="280">
			<col width="80">
			<col>
		</colgroup>
		<thead>
			<tr>
				<td></td>
				<td>[ID] 站点名称</td>
				<td>站点地址</td>
				<td>链接内型</td>
				<td class="tac">启用</td>
				<td>操作</td>
			</tr>
		</thead>
<?php 
	global $db;
	$sql="select * from ".Getdbname('link')."";
	$result=$db->query($sql);
	$tempcount=$db->num_rows($result);
        if($tempcount=="0"){
		echo '<tbody>
			<tr><td colspan="6" class="tac">啊哦，没有符合条件的内容！</td></tr>
		 </tbody>';

        }else{
                if($result){
                     while($row=$db->fetch_array($result)){
?>
		<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_Url<?php echo $row['CS_ID']?>" type="text" class="input length_4" value="<?php echo $row['CS_Url']?>"></td>
			<td><?php if($row['CS_CID']==1){ echo '文字链接';}else{ echo '图片链接';}?></td>
			<td class="tac"><input name="CS_YID<?php echo $row['CS_ID']?>" type="checkbox" value="ok" <?php if($row['CS_YID']==0) echo 'checked';?>></td>
			<td>
				<a href="javascript:Popsboxif('链接编辑',450,305,'link_add.php?id=<?php echo $row['CS_ID']?>');" class="mr10 J_dialog" title="链接编辑">[编辑]</a>
				<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 -->
<?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_Url=CS_Request("CS_Url".$ID[$i]);
			$CS_YID=CS_Request("CS_YID".$ID[$i]);

                        if($CS_YID!='ok'){
                            $CS_YID=1;
                        }else{
                            $CS_YID=0;
                        }
                        if(!empty($CS_Name)&&!empty($CS_Url)){

				$sql="update ".Getdbname('link')." set CS_Name='".$CS_Name."',CS_Url='".$CS_Url."',CS_YID=".$CS_YID." 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 ='link.php';\",2000);</script>";
   }
   if($ac=='del'){   //删除
       $CS_ID=CS_Request("id");		
                $sql="delete from ".Getdbname('link')." 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 ='link.php';\",2000);</script>";
                }else{
                     echo '<script>$("#Msg").text("抱歉,删除失败！").css("color","red");</script>';
                }
   }
?>
</div>
</body>
</html>
