<?php

include "../../include/conn.php";

include "../../include/function.php";

include "../admin_loginstate.php";

include "../admin_version.php";

/*

'**************************************************************************************************

' 软件名称: 黑色幻想舞曲管理系统CMS2.0

' 版本编号: hshxsdj 2.0

' 官方网站: http://www.hshxs.com

' 官方论坛：http://bbs.hshxs.com

' 版权所有: 黑色幻想开发团队    噬己翼(QQ:532917920)

' 郑重声明:

'    1、任何个人或组织不得在未经授权的情况下删除、修改、拷贝本软件及其他副本上一切关于版权的信息；

'    2、黑色幻想网络事业部保留此软件的法律追究权利

'**************************************************************************************************

*/


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>站内信管理</title>

<script type="text/javascript" language="javascript">var tentpath='<?php echo S_SitePath;?>';</script>

<script src="../js/jquery.js"></script>

<script src="../js/alerts.js"></script>

<link href="../images/alerts.css" rel="stylesheet" type="text/css" media="screen" />

<link  href="../images/style.css" rel="stylesheet" type="text/css" />

<script language="javascript">

	$(document).ready(function(){

                $("#ChkAll").click(function(){

		if($(this).attr("checked")==true){

			$("input[name='S_ID[]']").each(function(){

				$(this).attr("checked",true);									 

			})							

		}else{

			$("input[name='S_ID[]']").each(function(){

				$(this).attr("checked",false);									 

			})							

		}

                });

		$("#SelAll").click(function(){

			if($(this).attr("checked")==true){

				$("input[name='S_Type[]']").each(function(){

					$(this).attr("checked",true);									 

				})							

			}else{

				$("input[name='S_Type[]']").each(function(){

					$(this).attr("checked",false);									 

				})							

			}

		});

		$("#submit1").click(function(){

			var S_Title=$("#S_Title").val();

			var S_Content=$("#S_Content").val();

			$("#S_Title").css("border-color","#666 #ccc #ccc #666");

			$("#S_Content").css("border-color","#666 #ccc #ccc #666");

			if(S_Title==""){

				$("#tishi").text("请您输入短信标题！");

				$("#S_Title").css("border","1px solid red");

				return false;}

			if(S_Content==""){

				$("#tishi").text("请您请输入短信内容！");

				$("#S_Content").css("border","1px solid red");

				return false;}

		});

		

	});

function del(id){

	jConfirm('您确定要删除该短信吗?', '操作提示', function(r) {

		if(r==true){

			window.location='?action=del&S_ID='+id;

			}

				});

	};

function delall(){

	jConfirm('您确定要执行操作吗?', '操作提示', function(r) {

		if(r==true){form2.submit();}

		});

};

function qunzu(){

	$("#qunzu").css("display","");

	$("#geren").css("display","none");

};

function geren(){

	$("#qunzu").css("display","none");

	$("#geren").css("display","");

	};

function rebook(id){

	window.location='?action=rebook&S_ID='+id;

	};

function backpage(){

	window.history.go(-1);

	};

</script>

</head>

<body>

<?php

SystemPer(9);

class ui_stationmes{

	public function editboard($ActionUrl,$emValues){

		global $db;

		if(is_array($emValues)){

			$S_ID = $emValues[0];

			$S_Namea = $emValues[1];

			$S_Content = $emValues[2];

			$S_Nameb = $emValues[3];

			$S_Xid = $emValues[4];

			$S_Type = $emValues[5];

			$S_Addtime = $emValues[6];

			$S_Did = $emValues[7];

		}

if($_GET['action']=="add"){

$title="发送";

$S_Name=$S_Namea;

}else{

$title="回复";

$S_Name=$S_Nameb;

}

?>

<form method="post" action="<?php echo $ActionUrl?>">

	<table width="100%" border="0" cellpadding="0" cellspacing="0"  class="tb_style">

    	<tr>

    	  <td colspan="2" class="td_title">&nbsp;会员短信<?php echo $title?></td>

    	</tr>

    	<tr>

        	<td height="30" class="td_border">

            &nbsp;&nbsp;短信内容：

            </td>

            <td height="30" class="td_border">

            <textarea name="S_Content" id="S_Content" style="width:500px;height:100px"></textarea>

            </td>

        </tr>

        <tr>

        	<td height="30" class="td_border">

            &nbsp;&nbsp;发送方式：

            </td>

            <td height="30" class="td_border">

            <input type="radio" name="type" id="type" value=0 class="radio" <?php if(strpos($S_Type,",")==0){echo("checked='checked'");}?> onfocus="geren()"/>指定会员&nbsp;&nbsp;&nbsp;

            <input type="radio" name="type" id="type" value=1 class="radio" <?php if(strpos($S_Type,",")!=0){echo("checked='checked'");}?> onfocus="qunzu()"/>全部会员

            </td>

        </tr>

        <tr id="geren">

        	<td height="30" class="td_border">

            &nbsp;&nbsp;会员名称：

            </td>

          <td height="30" class="td_border">

              <input name="S_Name" type="text" id="S_Name" style="width:500px;" value="<?php echo $S_Name?>" />

            <font color="#FF0000">＊</font><br />

          <font color="#FF0000">  注意：多个会员请使用,号间隔分开　如：会员１号,会员２号</font></td>

        </tr>

        <tr id="qunzu" style="display:none">

        	<td height="30" class="td_border">

            </td>

        </tr>

        <tr>

        	<td height="40" class="td_border" align="right">&nbsp;</td>

            <td height="40" class="td_border" align="left"><input type="submit" name="submit1" id="submit1" value="发 送" class="rb1"/>

             &nbsp; <input type="reset" class="rb1" value="重 置" />

              &nbsp; <input type="button" class="rb1" value="返 回" onclick="backpage()" />

          </td>

        </tr>

    </table>

    </label>

    <?php

	if(strpos($S_Type,",")>0){

		echo("<script language='javascript'>showwb(1);</script>");

	}



	}

	

	function lists($sql,$size){

		global $db;

		$Arr=getpagerow($sql,$size);//sql,每页显示条数

		$result=$db->query($Arr[2]);

		$action=SafeRequest("action","get");

		?>

<form id="form2" action="?action=delall" method="post" name="form2">

    <table  width="100%" border="0" cellpadding="0" cellspacing="0" class="tb_style">

    	<tr>

            <td  height="30" colspan="5" class="td_title">&nbsp;消息列表</td>

        </tr>

        <tr>

            <td width="10%" height="30" bgcolor="#FFFFFF" class="td_btop3">&nbsp;编号</td>

            <td width="38%" height="30" bgcolor="#FFFFFF" class="td_btop3">&nbsp;短信内容</td>

            <td width="23%" height="30" bgcolor="#FFFFFF" class="td_btop3">&nbsp;发送者</td>

            <td width="18%" height="30" align="center" bgcolor="#FFFFFF" class="td_btop3">发送时间</td>

            <td width="11%" height="30" align="center" bgcolor="#FFFFFF" class="td_btop3">操作</td>

        </tr>

    <?php

$numdate="a";

if($result){

	while ($row = $db ->fetch_array($result)){

		$numdate="b";

    ?>

    

    <tr>

        <td height="30" class="td_border"><input type="checkbox" value="<?php echo $row["S_ID"]?>" name="S_ID[]" class="checkbox"/><?php echo $row["S_ID"]?>.</td>

        <td height="30" class="td_border">&nbsp;<?php echo $row["S_Content"]?></td>

        <td height="30" class="td_border">&nbsp;<a href="<?php echo linkweburl(1,$row["S_Nameb"])?>" target="_blank"><?php echo $row["S_Nameb"]?></a></td>

        <td height="30" class="td_border" align="center"><?php echo $row["S_Addtime"]?></td>

        <td height="30" class="td_border" align="center">

        <a href="?action=readmes&S_ID=<?php echo $row["S_ID"]?>">查看</a>&nbsp;&nbsp;&nbsp;

        <a href="?action=rebook&S_ID=<?php echo $row["S_ID"]?>">回复</a>&nbsp;&nbsp;&nbsp;

        <a style="cursor:pointer;" onclick="del(<?php echo $row["S_ID"]?>)">删除</a></td>

    </tr>

    <?php

	}

}

if($numdate=="a"){

	echo("<tr><td height='30' align='center' class='td_border' colspan='5'><b>暂无消息！</b></td></tr>");

}

	?>

    <tr>

        <td height="30" bgcolor="#FFFFFF"  colspan="10"><input type="checkbox" name="ChkAll" id="ChkAll" ids="S_ID" class="checkbox"/>

          全选 &nbsp;

        <input type="button" value="删除所选短信" class="rb1"  onclick="delall()"/>        </td>

      </tr>

    <tr>

          <td height="40" colspan="10" align="right" valign="bottom" bgcolor="#FFFFFF" class="td_btop3">

          <?php echo $Arr[0];?>

          </td>

      </tr>

    </table>	

</form>

    <?php

	}

	

}

?>

    

    

<?php

$action=SafeRequest("action","get");

$ui=new ui_stationmes;



switch($action){

	case "del" :

		Del();

		break;

	case "delall" :

		DelAll();

		break;

	case "add" :

		Add();

		break;

	case "edit" :

		Edit();

		break;

	case "saveedit" :

		SaveEdit();

		break;

	case "saveadd" :

		SaveAdd();

		break;

	case "list2" :

		List2();

		break;

	case "readmes" :

		ReadMes();

		break;

	case "rebook" :

		ReBook();

		break;

	default:

		Main();

		break;

}



function Main(){

	global $ui;

	$ui->lists("select * from s_xiaoxi where S_namea='系统消息' Order by S_ID desc",30);

}

	

function Del(){

	global $db;

	$S_ID = SafeRequest("S_ID","get");

	$sql="delete from s_xiaoxi where S_ID=".$S_ID;

	if($db->query($sql)){

		echo "<script>window.location='admin_stationmes.php'</script>";

	}else{

		echo "<script>jAlert('删除失败!','操作提示',function(R){history.back();})</script>";

	}

}



function DelAll(){

	global $db;

	$S_ID=RequestBox("S_ID");

	$S_ID=explode(",",$S_ID);

	for($j=0;$j<count($S_ID);$j++){

		$sql="delete from s_xiaoxi where S_ID=".$S_ID[$j];

		$db->query($sql);

	}

	echo "<script>window.location='admin_stationmes.php'</script>";

}



function Add(){

	global $ui;

	$arr=array("","","","","","","");

	$ui->editboard("?action=saveadd",$arr);

}



function SaveAdd(){

	global $db;

	$S_Nameb="系统消息";

	$S_Content=SafeRequest("S_Content","post");

	$S_Namea=SafeRequest("S_Name","post");

	$S_xid=0;

	$type=SafeRequest("type","post");

	$S_Addtime=date('Y-m-d H:i:s');

	if($type=="0"){

		$S_Vip=$S_Namea;

		if($S_Vip==""){

			echo "<script>jAlert('请输入要发送的对象!','操作提示',function(R){history.back();})</script>";

                        exit();

		}

	}else{

                        $S_Vip="";

			$sqlu="select * from s_users";

			$resultu=$db->query($sqlu);

			while($rowu=$db->fetch_array($resultu)){

				$S_Vip=$S_Vip.$rowu["S_Name"].",";

			}

	}



        $Arr=explode(",",$S_Vip);

        if($type=="0"){

               $ArrUnt=count($Arr);

        }else{

               $ArrUnt=count($Arr)-1;

        }



	for($i=0;$i<$ArrUnt;$i++){

	     $db->query("insert into s_xiaoxi (S_Nameb,S_Content,S_Namea,S_xid,S_Addtime) values ('".$S_Nameb."','".$S_Content."','".$Arr[$i]."',".$S_xid.",'".$S_Addtime."')");

	}

      	     echo "<script>jAlert('短信发送已成功!','操作提示',function(R){history.back();})</script>";

             exit();

}



function Edit(){

	global $db;

	global $ui;

	$S_ID=SafeRequest("S_ID","get");

	$sql="select * from s_xiaoxi where S_ID=".$S_ID;

	$result=$db->query($sql);

	$row=$db->fetch_array($result);

	$S_Namea = $row["S_Namea"];

	$S_Content = $row["S_Content"];

	$S_Nameb = $row["S_Nameb"];

	$S_Xid = $row["S_Xid"];

	$S_Addtime = $row["S_Addtime"];

	$S_Did = $row["S_Did"];

	$Arr=array($S_ID,$S_Namea,$S_Content,$S_Nameb,$S_Xid,$S_Addtime,$S_Did);

	$ui->editboard("?action=saveedit&S_ID=".$S_ID,$Arr);

}



function Rebook(){

	global $db;

	global $ui;

	$S_ID=SafeRequest("S_ID","get");

	$sql="select * from s_xiaoxi where S_ID=".$S_ID;

	$result=$db->query($sql);

	$row=$db->fetch_array($result);

	$S_Namea = $row["S_Namea"];

	$S_Content = $row["S_Content"];

	$S_Nameb = $row["S_Nameb"];

	$S_Xid = $row["S_Xid"];

	$S_Addtime = $row["S_Addtime"];

	$S_Vid = $row["S_Vid"];

	$Arr=array($S_ID,$S_Namea,$S_Content,$S_Nameb,$S_Xid,$S_Addtime,$S_Did);

	$ui->editboard("?action=saveedit&S_ID=".$S_Vid,$Arr);

}



function SaveEdit(){

	global $db;

	$S_Nameb="系统消息";

	$S_Content=SafeRequest("S_Content","post");

	$S_Namea=SafeRequest("S_Name","post");

	$S_xid=0;

	$type=SafeRequest("type","post");

	$S_Addtime=date('Y-m-d H:i:s');

	if($type=="0"){

		$S_Vip=$S_Namea;

		if($S_Vip==""){

			echo "<script>jAlert('请输入要发送的对象!','操作提示',function(R){history.back();})</script>";

                        exit();

		}

	}else{

                        $S_Vip="";

			$sqlu="select * from s_users";

			$resultu=$db->query($sqlu);

			while($rowu=$db->fetch_array($resultu)){

				$S_Vip=$S_Vip.$rowu["S_Name"].",";

			}

	}



        $Arr=explode(",",$S_Vip);

        if($type=="0"){

               $ArrUnt=count($Arr);

        }else{

               $ArrUnt=count($Arr)-1;

        }



	for($i=0;$i<$ArrUnt;$i++){

	     $db->query("insert into s_xiaoxi (S_Nameb,S_Content,S_Namea,S_xid,S_Addtime) values ('".$S_Nameb."','".$S_Content."','".$Arr[$i]."',".$S_xid.",'".$S_Addtime."')");

	}

      	     echo "<script>jAlert('短信回复成功!','操作提示',function(R){history.back();})</script>";

             exit();

}



function ReadMes(){

	global $db;

	$S_ID=SafeRequest("S_ID","get");

    $sql="select * from s_xiaoxi where S_ID=".$S_ID;

    $result=$db->query($sql);

    $row=$db->fetch_array($result);

	?>

    	<table width="100%" border="0" cellpadding="0" cellspacing="0"  class="tb_style">

    	<tr>

    	  <td colspan="2" class="td_title">&nbsp;会员短信回复</td>

    	</tr>

    	<tr>

        	<td height="30" class="td_border">

            &nbsp;&nbsp;内容：

            </td>

            <td height="30" class="td_border">

            <input type="text" name="S_ID" value="<%=S_ID%>" style="display:none" />

            <?php echo $row["S_Content"]?>

            </td>

        </tr>

        <tr>

        	<td height="30" class="td_border">

            &nbsp;&nbsp;会员名称：

            </td>

            <td height="30" class="td_border">

            <label><?php echo $row["S_Nameb"]?></label>

            </td>

        </tr>

        <tr>

        	<td height="40" class="td_border" align="right">&nbsp;</td>

            <td height="40" class="td_border" align="left">

              <input type="button" name="button1" id="button1" value="回 复" class="rb1" onclick="rebook(<?php echo $S_ID?>)"/>

              <input type="button" name="button2" id="button2" value="删 除" class="rb1" onclick="del(<?php echo $S_ID?>)"/>

            <input type="button" value="返 回" class="rb1" onclick="backpage()" />

          </td>

        </tr>

    </table>

    <?php

}

	function isselect($S_PurView,$values){

		if(($S_PurView=="0")||($S_PurView=="")){

			

		}

		else{

			$S_PurViewarr=explode(",",$S_PurView);

			for($i=0;$i<count($S_PurViewarr);$i++){

				if($S_PurViewarr[$i]==$values){

					echo("checked");

				}

			}

		}

	}

include "../admin_bottom.php";

?>



</body>

</html>