<?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('7_2');
$ac=CS_Request("ac");
$op=CS_Request("op");
if(empty($ac)) $ac='main';
?>
<!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 src="../../public/js/webox.js"></script>
<script language="javascript">

function del(_id){ 
  if (confirm("确定删除吗？")){
    window.location='?op=del&id='+_id;
    return true;
  }else{
     return false;
  }		
}
//复制代码
function CopyBq(url,title){ 
   window.clipboardData.setData("Text",url);
   alert(title); 
} 
</script>
</head>
<body>
<div class="wrap">
<?php
   //修改\增加
   if($ac=='edit'){
        global $db;
   	$CS_ID=CS_Request("id");
        if($CS_ID){
	   $row=$db->getrow("SELECT * FROM ".Getdbname('label')." Where CS_ID='".$CS_ID."'");
	   if($row){
		$Arr=array($row['CS_Name'],$row['CS_SelfLable']);
                $title="编辑标签";
	   }
        }else{
		$Arr=array('','');
                $title="填加标签";
        }
?>
<script type="text/javascript">
$(document).ready(function(){
	$("#addskins").click(function(){
		var CS_Name=document.getElementById('CS_Name').value;
		var CS_SelfLable=document.getElementById('CS_SelfLable').value;
		var re = /^[a-z0-9]*$/gi
	if(CS_Name==""){
		$("#Msg").text("请填写标签名称！").css("color","red");
		return false;
		}
	else if(CS_SelfLable==""){
		$("#Msg").text("请填写标签内容！").css("color","red");
		return false;
		}
	else if(re.test(CS_Name)==false){
		$("#CS_Name").css("border","1px solid red");
		$("#Msg").text("标签名称必须是数字或字母组成！").css("color","red");
		return false;
		}
	});
});
</script>
<div class="nav">
	<ul class="cc">
		<li><a href="?">标签列表</a></li>
		<li class="current"><a href="?ac=edit"><?php echo $title?></a></li>
	</ul>
</div>
<form class="J_ajaxForm" data-role="edit" name="form" action="?ac=edit&op=editdata" method="post">
<div class="h_a"><?php echo $title?></div>
<div class="table_full">
	<table width="100%" class="J_check_wrap">
		<col class="th" />
		<col width="400" />
		<col />
		<tr><input name="id" type="hidden" value="<?php echo $CS_ID?>" />
			<th>标签名称</th>
			<td>
				<input id="CS_Name" name="CS_Name" value="<?php echo $Arr[0]?>" type="text" class="input input_hd length_5">&nbsp;
			</td>
			<td><div class="fun_tips">填写标签名称</div></td>
		</tr>
		<tr>
			<th>标签内容</th>
			<td>
				<textarea style="width:100%;height:250px;" id="CS_SelfLable" name="CS_SelfLable"><?php echo $Arr[1]?></textarea>

			</td>
			<td><div class="fun_tips">标签内容</div></td>
		</tr>
</div>
<div class="btn_wrap">
	<div class="btn_wrap_pd">
		<button type="submit" id="addskins" class="btn btn_submit mr10 J_ajax_submit_btn">提交</button>
                <div class="tips_error" id="Msg"></div>
	</div>
</div>
<?php
         //增加、修改
         if($op=='editdata'){
		global $db;
		$CS_ID=CS_Request("id");
		$CS_Name=CS_Request("CS_Name");
		$CS_SelfLable=CS_Request("CS_SelfLable");
                if(empty($CS_Name)||empty($CS_SelfLable)){
                          echo '<script>$("#Msg").text("抱歉，资料不完整!").css("color","red");</script>';
                          exit("<script>setTimeout(\"history.back(1);\",20000);</script>");
                }
		//判断增加还是修改
                if($CS_ID){
		            $sql="update ".Getdbname('label')." set CS_Name='".$CS_Name."',CS_SelfLable='".$CS_SelfLable."' where CS_ID=".$CS_ID;
                }else{
		            $sql="Insert ".Getdbname('label')."  (CS_Name,CS_SelfLable) values ('".$CS_Name."','".$CS_SelfLable."')";
                }
		if($db->query($sql)){
                    echo '<script>document.getElementById("Msg").className="tips_success";$("#Msg").text("恭喜,数据操作成功!").css("color","#026E12");</script>';
	            echo "<script>setTimeout(\"window.location='skins_zdy.php'\",2000);</script>";
		}else{
                    echo '<script>$("#Msg").text("抱歉，操作失败!").css("color","red");</script>';
	            echo "<script>setTimeout(\"history.back(1);\",2000);</script>";
                }
         }
   }

   //标签主列表
   if($ac=='main'){
		global $db;
                $sql="select * from ".Getdbname('label')." order by CS_ID desc";
	        $result=$db->query($sql);
	        $tempcount=$db->num_rows($result);
?>
<div class="nav">
	<ul class="cc">
		<li class="current"><a href="topic.php">标签列表</a></li>
		<li><a href="?ac=edit">添加标签</a></li>
	</ul>
</div>
<form class="J_ajaxForm" action="?op=delall" method="post" name="formb">
<div class="table_list">
<?php
	if($tempcount==0){
                echo "<table width=\"100%\">
				<tbody>
					<tr><td class=\"tac\">啊哦，没有符合条件的内容！</td></tr>
				</tbody>
		</table>";

        }else{
                echo "<table width=\"100%\" id=\"dellist\">
		<thead>
			<tr>
				<td><label>选</label></td>
				<td>标签名称</td>
				<td><span>标签代码</span></td>
				<td>调用标签</td>
				<td>编辑/删除</td>
			</tr>
		</thead>";
        }
        if($result){
	     while ($row = $db ->fetch_array($result)){
                  echo "<tr>
				<td><input type=\"checkbox\" class=\"J_check\" name=\"CS_ID[]\" value=\"".$row['CS_ID']."\" id=\"CS_ID\"/>&nbsp;".$row['CS_ID']."</td>
				<td>".$row['CS_Name']."</td>
				<td>{csdjcmsself:".$row['CS_Name']."}</td>
				<td><a style=\"cursor:pointer;\"  onclick=\"CopyBq('{csdjcmsself:".$row['CS_Name']."}','复制成功，现在可以去粘贴到模版里面')\">复制标签</a></td>
				<td><a href=\"?ac=edit&id=".$row['CS_ID']."\">编辑</a> &nbsp;&nbsp;<a style=\"cursor:pointer;\"  onclick=\"del(".$row['CS_ID'].")\">删除</a></td>
			</tr>";
             }
        }
?>
	</table>
</div>
<div class="btn_wrap">
	<div class="btn_wrap_pd">
                <label class="mr20"><input type="checkbox" class="J_check_all" id="chkall" onClick="return CheckAll(this.form)" value="on">全选</label>
		<input name="button1" type="button" class="btn J_ajax_submit_btn" value="批量删除" onClick="DelInfo(this.form)">
                <div class="tips_error" id="Msg"></div>
	</div>
</div>
</form>
<?php
          //删除
          if($op=='del'){
		global $db;
		$CS_ID=CS_Request("id");
                $sql="delete from ".Getdbname('label')." 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='javascript:history.go(-1);'\",2000);</script>";
		}
          }

          //批量删除
          if($op=='delall'){
		global $db;
		$CS_ID=CS_RequestBox("CS_ID");
	        $Arr=explode(',',$CS_ID);
		for($i=0;$i<count($Arr);$i++){
			$db->query("delete from ".Getdbname('label')." where CS_ID=".$Arr[$i]."");
		}
                        echo '<script>document.getElementById("Msg").className="tips_success";$("#Msg").text("恭喜,删除成功!").css("color","#026E12");</script>';
	                echo "<script>setTimeout(\"window.location='javascript:history.go(-1);'\",2000);</script>";
          }
   }
?>
</div>
</body>
</html>
