<?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>csdjcms management</title>
<link href="../res/css/admin_style.css" rel="stylesheet" />
<script language="javascript" src="../res/js/jquery.js"></script>
<script language="javascript" type="text/javascript" src="../../public/datepicker/wdatepicker.js"></script>
<style> 
body{width:440px;}
</style>
<script type="text/javascript" charset="utf-8" src="../../public/editor/kindeditor.js"></script>
<script type="text/javascript">
     KE.show({
	id : 'CS_Neir',
	resizeMode : 1,
	allowPreviewEmoticons : false,
	allowUpload : false,
	items : [
	'source', '|', 'fontsize', 'textcolor', 'bgcolor', 'bold', 'italic', 'underline',
	'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
	'insertunorderedlist', '|', 'image', 'link', 'unlink']
     });
</script>
<script language="javascript">
$(document).ready(function(){
	$("#addgo").click(function(){
		var CS_User=$("#CS_User").val();
		var CS_Title=$("#CS_Title").val();
		var CS_Neir=$("#CS_Neir").val();
	$("#CS_User").css("border-color","#666 #ccc #ccc #666");
	$("#CS_Title").css("border-color","#666 #ccc #ccc #666");
	$("#CS_Neir").css("border-color","#666 #ccc #ccc #666");
	if(CS_User==""){
		$("#CS_User").css("border","1px solid red");
		$("#Msg").text("请填写接收会员！").css("color","red");
		return false;
		}
	else if(CS_Title==""){
		$("#CS_Title").css("border","1px solid red");
		$("#Msg").text("请填写邮件标题！").css("color","red");
		return false;
		}
	else if(CS_Neir==""){
		$("#CS_Neir").css("border","1px solid red");
		$("#Msg").text("请填写邮件内容！").css("color","red");
		return false;
		}
        else {
                  document.getElementById("Msg").className="tips_success";
                  document.getElementById('Msg').innerHTML='<img src="../../public/images/load.gif">正在发送,请稍等...';
             }
	});
});

function dhcolok(){
    this.parent.$('.webox').css({display:'none'});
    this.parent.$('.background').css({display:'none'});
}
</script>
</head>
<body class="body_none">
<div>
<!-- mod start -->
<form method="post" class="J_ajaxForm" action="?ac=go" data-role="edit">
<div class="pop_cont pop_table">
	<table width="100%" style="table-layout:fixed;">
		<col width="70" />
		<col />
		<tr>
			<th>接收会员</th>
			<td>
				<span class="must_red">*</span>
				<input type="text" id="CS_User" name="CS_User" class="input input_hd length_5" value="<?php echo $id?>">
				<div class="gray">多个会员用逗号“，”阁开</div>
			</td>
		</tr>
		<tr>
			<th>邮件标题</th>
			<td>
				<span class="must_red">*</span>
				<input type="text" id="CS_Title" name="CS_Title" class="input input_hd length_5" value="">
			</td>
		</tr>
 		<tr>
			<th>邮件内容</th>
			<td>
				<div class="mb5"><textarea style="width:100%;height:250px;" id="CS_Neir" name="CS_Neir"></textarea></div>
			</td>
		</tr>
	</table>
</div>
<!-- mod end -->
<div class="pop_bottom">
    <div class="tips_error" id="Msg"></div>
	<button class="btn fr" onclick="dhcolok();" type="button">取消</button>
	<button class="btn btn_submit J_ajax_submit_btn mr10 fr" id="addgo" type="submit">提交</button>
</div>
</form>
<!-- end -->
</div>
<?php 
    if($ac=='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){
                         //发送邮件
                         $send=$smtp->sendmail($row['CS_Email'],CS_Mailname,$CS_Title,$CS_Neir,'HTML');
                         if($send==1){
                              echo '<script>document.getElementById("Msg").className="tips_success";$("#Msg").text("恭喜,'.$row['CS_Email'].'发送完成!").css("color","#026E12");</script>';
                         }else{
                             echo '<script>$("#Msg").text("发送给'.$row['CS_Email'].'，发送失败!").css("color","red");</script>';
                         }
                    }
                }
        echo '<script>document.getElementById("Msg").className="tips_success";$("#Msg").text("恭喜,邮件全部发送完成!").css("color","#026E12");</script>';
	echo "<script>setTimeout(\"this.parent.$('.webox').css({display:'none'});this.parent.$('.background').css({display:'none'});\",3000);</script>";
    }
?>
</body>
</html>
