<?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('0_1');
$ac=CS_Request("ac");
$op=CS_Request("op");
$id=CS_Request("id");
?>
<!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 src="../../public/js/webox.js"></script>
<script type="text/javascript"> 
$(document).ready(function(){
	$("#xxgo").click(function(){
		var CS_User=document.getElementById('CS_User').value;
		var CS_Title=document.getElementById('CS_Title').value;
		var CS_Neir=document.getElementById('CS_Neir').value;
	if(CS_User==""){
		$("#Msg").text("请填写要发送的会员！").css("color","red");
		return false;
		}
	else if(CS_Title==""){
		$("#Msg").text("请填写消息标题！").css("color","red");
		return false;
		}
	else if(CS_Neir==""){
		$("#Msg").text("请填写要说的话！").css("color","red");
		return false;
		}
	});
});
</script>
</head>
<body>
<div class="wrap">
<div class="nav">
	<ul class="cc">
		<li <?php if($ac=='main') echo 'class="current"';?>><a href="?ac=main">消息列表</a></li>
		<li <?php if($ac=='') echo 'class="current"';?>><a href="?">发送消息</a></li>
		<li><a href="javascript:Popsboxif('发送邮件',450,470,'user_mail.php?id=<?php echo $id?>');">发送邮件</a></li>
	</ul>
</div>
<?php if($ac=='main'){ ?>
<form class="J_ajaxForm" action="?op=delall" method="post" name="formb">
<div class="table_list">
<table width="100%" id="dellist">
		<thead>
			<tr>
				<td><label>选</label></td>
				<td>名称</td>
				<td><span>内容</span></td>
				<td><span>时间</span></td>
				<td>删除</td>
			</tr>
		</thead>
<?php
		global $db;
                $sql="select * from ".Getdbname('xiaoxi')." where cs_usera='admin' and cs_userb<>'系统消息' order by CS_AddTime desc";
		$dancenum=$db->num_rows($db->query($sql));
		$Arr=getpagerow($sql,20);//sql,每页显示条数
		$result=$db->query($Arr[2]);
	if($dancenum==0){
                   echo '<tr><td class="tac" colspan="6">啊哦，没有符合条件的内容！</td></tr>';
        }else{
                if($result){
	                 while ($row = $db ->fetch_array($result)){
?>
			   <tr>
				<td><input type="checkbox" class="J_check" name="CS_ID[]" value="<?php echo $row['CS_ID']?>" id="CS_ID"/>&nbsp;<?php echo $row['CS_ID']?></td>
				<td><a href="<?php echo userlink('index',getuser('uid',$row['CS_Userb']))?>"><?php echo $row['CS_Userb']?></a></td>
				<td><?php echo facehtml(stripslashes(html_entity_decode($row['CS_Neir'])))?></td>
				<td><?php echo $row['CS_AddTime']?></td>
				<td><a style="cursor:pointer;"  onclick="del(<?php echo $row['CS_ID']?>)">删除</a></td>
			   </tr>
<?php
	                 }
                }
        }
?>
	</table>
			<div class="p10">
				<div class="pages">
				     <?php if($dancenum>20) echo $Arr[0];?>
                                </div>
			</div>
</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>
</div>
<?php 
          //删除
          if($op=='del'){
		global $db;
		$CS_ID=CS_Request("id");
                $sql="delete from ".Getdbname('xiaoxi')." 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('xiaoxi')." 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>";
          }

}else{ 
?>
	<div class="h_a">发送会员消息</div>
	<form action="?op=go" method="post" class="J_ajaxForm" id="J_backup_form">
	<div class="table_full">
		<table width="100%">
			<col width="200" />
			<tr>
				<th>接收会员</th>
				<td><input type="text" id="CS_User" name="CS_User" class="input input_hd length_6" value="<?php echo $id?>">  多个会员用逗号“,”阁开</td>
			</tr>
			<tr>
				<th>消息标题</th>
				<td><input type="text" id="CS_Title" name="CS_Title" class="input input_hd length_6" value=""></td>
			</tr>
			<tr>
				<th>消息内容</th>
				<td><textarea style="width:500px;height:150px;" id="CS_Neir" name="CS_Neir"></textarea></td>
			</tr>
		</table>
	</div>
<div class="btn_wrap">
	<div class="btn_wrap_pd">
		<button class="btn btn_submit J_ajax_submit_btn" id="xxgo" type="submit">确定发送</button>
	<div class="tips_error" id="Msg"></div>
	</div>
</div>
</form>
<?php 
    if($op=='go'){
          $CS_User=CS_Request("CS_User");
          $CS_Title=CS_Request("CS_Title");
          $CS_Neir=CS_Request("CS_Neir");
	        $Arr=explode(',',$CS_User);
		for($i=0;$i<count($Arr);$i++){
                    $row=$db->getRow("select * from ".Getdbname('user')." where CS_Name='".$Arr[$i]."'");
                    if($row){
                         //入库
	                 $sql="insert into ".Getdbname('xiaoxi')." (cs_usera,cs_userb,cs_name,cs_neir,cs_addtime) values ('".$row['CS_Name']."','系统消息','".$CS_Title."','".$CS_Neir."','".date('Y-m-d H:i:s')."')";
	                 $db->query($sql);
                    }
                }
        echo '<script>document.getElementById("Msg").className="tips_success";$("#Msg").text("恭喜,消息发送完成!").css("color","#026E12");</script>';
	echo "<script>setTimeout(\"history.back(1);\",3000);</script>";
    }
} 
?>
</div>
</body>
</html>
 

