<?php
error_reporting(0);
session_start();
include_once '../comm/config.php';
include_once '../comm/checkpostandget.php';
include_once 'check.php';
include_once 'page.class.php';
include_once '../comm/wjt.php';

$recuser=$_GET['senduser'];
//$outuser=$_POST['ddusername']; 
$content1=$_POST['content']; 
$act=$_GET['act'];
$page = !($_GET['page'])?'1':intval($_GET['page']);
$pagesize=10;
$page2=($page-1)*$pagesize;

if (!$act and !$outuser) {
	echo "缺少必要参数";
	exit;
}
else
{
	if($act=='in'){
		$sql="select * from ".$BIAOTOU."msg where ddusername='".$_SESSION["duoduouser"]."'";
		$rs = mysql_query($sql);
		$total = mysql_num_rows($rs);	
		
		$sql="select * from ".$BIAOTOU."msg where ddusername='".$_SESSION["duoduouser"]."' order by id desc limit $page2,$pagesize";
		$rs = mysql_query($sql);
	}
	if($act=='out'){
		$sql="select * from ".$BIAOTOU."msg where senduser='".$_SESSION["duoduouser"]."'";
		$rs = mysql_query($sql);
		$total = mysql_num_rows($rs);	
		
		$sql="select * from ".$BIAOTOU."msg where senduser='".$_SESSION["duoduouser"]."' order by id desc limit $page2,$pagesize";
		$rs = mysql_query($sql);
	}
	//发送短信
	if($act=='send'&&$content1!=''){
		if($_SESSION["duoduouser"]!='网站客服')
		{
			$sj= date("Y-m-d H:i:s");
			$q="insert into ".$BIAOTOU."msg (title,content,addtime,see,ddusername,senduser) values ('站内消息','".$content1."','".$sj."',0,'网站客服','".$_SESSION["duoduouser"]."')";
			$rs = mysql_query($q);
		}
		echo "<script language=javascript>window.location='msg_list.php?act=out';</script>";
	}
}

$tag="center";
?>
<!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=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title>短消息 - 用户中心</title>
<link href="../template/<?=MOBAN?>/css/usercss.css" rel="stylesheet" type="text/css">
<link href="../template/<?=MOBAN?>/css/common.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="../template/<?=MOBAN?>/js/jquery.js"></script>
<script language="javascript" type="text/javascript">
function getLength(str) {
    var len = str.length;
    var reLen = 0;
    for (var i = 0; i < len; i++) {        
        if (str.charCodeAt(i) < 27 || str.charCodeAt(i) > 126) {
            // 全角    
            reLen += 2;
        } else {
            reLen++;
        }
    }
    return reLen;    
}
function checkoutuser(outuser)
{
    	if(getLength(outuser)==0)
		{
			document.getElementById("ckddusername").innerHTML = '<img src=../images/cuo.gif alt="错误" align=absmiddle /> <font color=#ff0000>请输入消息接收人</font>';
		}
		else
		{
			document.getElementById("ckddusername").innerHTML = '<img src=../images/dui.gif alt="正确" align=absmiddle /> <font color=#009900></font>';
		}
}
function checkcontent(content)
{
    	if(getLength(content)==0)
		{
			document.getElementById("ckcontent").innerHTML = '<img src=../images/cuo.gif alt="错误" align=absmiddle /> <font color=#ff0000>请输入短信内容</font>';
		}
		else
		{
			document.getElementById("ckcontent").innerHTML = '<img src=../images/dui.gif alt="正确" align=absmiddle /> <font color=#009900></font>';
		}
}
function checkall()
{
	if(document.getElementById("ddusername").value==""||document.getElementById("content").value=="")
	{
		alert('请填写完内容！');
		return false;
	}
	else
	{
		return true;
	}
}
</script>
</head>

<body id="msglist">
<?php
include("../template/".MOBAN."/header.tpl.php");
?>
<?php
include("../template/".MOBAN."/nav.tpl.php");
?><DIV style="MARGIN-TOP: 25px"></DIV>
<div id="main">
<DIV class=white_top>
<DIV class=white_top_left></DIV>
<DIV class=white_top_middle></DIV>
<DIV class=white_top_right></DIV></DIV>
<DIV class=white_bg_rl>
<?php
include("left.php");
?>
<div class="contain">
  <h2 class="left_nav4">我的站内消息</h2>
    <div class="order">
      <div class="title">
          <ul>
            <li><a style="MARGIN-LEFT: 10px" <?php if($act=='in') echo "class=\"current\"";?>
  href="msg_list.php?act=in">收到的消息</a></li>
  			<li><a style="MARGIN-LEFT: 10px" <?php if($act=='out') echo "class=\"current\"";?>
  href="msg_list.php?act=out">发出的消息</a></li>
  <li><a style="MARGIN-LEFT: 10px" <?php if($act=='send') echo "class=\"current\"";?>
  href="msg_list.php?act=send">联系客服</a></li>
          </ul>
      </div>    <div class="content">
      <ul style="width:710px">
	  	<?php if($act=='in'){?>
				<li class="order_title">
				<div class="item" style="width:30px"></div>
				<div class="item" style="width:100px">发送人</div>
				<div class="item" style="width:350px">消息内容</div>							
				<div class="item" style="width:130px;text-align:center;">发送时间</div>
				<div class="item" style="width:100px;text-align:center">执 行 操 作</div>
				</li>
			<?php
			while ($row = mysql_fetch_array($rs))
			{
				if($row["see"]=="1")
				{ $msgsrc="<div style=\" margin-top:7px; margin-left:5px;\"><img src=\"../images/msg-read.gif\" border=\"0\" align=\"absmiddle\"  alt=\"短消息\" /></div>";}
				else
				{$msgsrc="<div style=\" margin-top:7px; margin-left:5px;\"><img src=\"../images/msg.gif\" border=\"0\" align=\"absmiddle\" alt=\"新的短消息\" /></div>";}
				echo "<li><div class=\"item\" style=\"width:30px\">".$msgsrc."</div>";
				echo "<div class=\"item\" style=\"width:100px;\">".$row["senduser"]."</div>";
				echo "<div class=\"item\" style=\"width:350px\"><a href=msg_read.php?msg_id=".$row["Id"].">".$row["content"]."</a></div>";
				echo "<div class=\"item\" style=\"width:130px;text-align:center\">".$row["addtime"]."</div>";					
				echo "<div class=\"item\" style=\"width:100px;text-align:center\"><a href=msg_read.php?msg_id=".$row["Id"].">阅读</a> <a href=msg_list.php?act=send&senduser=".urlencode($row["senduser"]).">回复</a> <a  onclick=\"return confirm('您确定要删除吗?')\" href=msg_del.php?id=".$row["Id"].">删除</a></div>";
				echo "</li>";
			}
			?></ul>
			<?php }?>	
			
	  		<?php if($act=='out'){?>
				<li class="order_title">
				<div class="item" style="width:30px"></div>
				<div class="item" style="width:100px">接收人</div>
				<div class="item" style="width:460px">消息内容</div>							
				<div class="item" style="width:120px;text-align:center;">发送时间</div>
				</li>
			<?php
			while ($row = mysql_fetch_array($rs))
			{
				if($row["see"]=="1")
				{ $msgsrc="<div style=\" margin-top:7px;margin-left:5px;\"><img src=\"../images/msg-read.gif\" border=\"0\" align=\"absmiddle\"  alt=\"短消息\" /></div>";}
				else
				{$msgsrc="<div style=\" margin-top:7px;margin-left:5px;\"><img src=\"../images/msg.gif\" border=\"0\" align=\"absmiddle\" alt=\"新的短消息\" /></div>";}
				echo "<li><div class=\"item\" style=\"width:30px\">".$msgsrc."</div>";
				echo "<div class=\"item\" style=\"width:100px;\">".$row["ddusername"]."</div>";
				echo "<div class=\"item\" style=\"width:460px\">".$row["content"]."</div>";
				echo "<div class=\"item\" style=\"width:120px;text-align:center\">".$row["addtime"]."</div>";
				echo "</li>";
			}
			?></ul>
			<?php }?>
			<?php
			if($act=='send'){
		  ?>
	  	  <FORM onsubmit="return checkall()" method=post action="msg_list.php?act=send">
		  <LI style="LINE-HEIGHT: 40px; HEIGHT: 40px; CLEAR: both;width:600px; border-bottom:0px;"><LABEL>收件人：</LABEL><INPUT id="ddusername" size="60" type=text name="ddusername" style="width:300px;BORDER-BOTTOM: #c9c9c9 1px solid; BORDER-LEFT: #c9c9c9 1px solid; LINE-HEIGHT: 25px; HEIGHT: 25px; FONT-SIZE: 12px; BORDER-TOP: #c9c9c9 1px solid; BORDER-RIGHT: #c9c9c9 1px solid" value="网站客服" readonly="true" disabled="disabled">
		  </LI>
		  <LI style="LINE-HEIGHT: 40px; HEIGHT: 170px; CLEAR: both; width:700px; border-bottom:0px;"><LABEL>内　容：</LABEL><TEXTAREA style=" HEIGHT: 160px; width:500px; BORDER-BOTTOM: #c9c9c9 1px solid; BORDER-LEFT: #c9c9c9 1px solid; LINE-HEIGHT: 26px; FONT-SIZE: 12px; BORDER-TOP: #c9c9c9 1px solid; BORDER-RIGHT: #c9c9c9 1px solid" rows=10 cols=50 name="content" id="content" onblur="checkcontent(document.getElementById('content').value);"></TEXTAREA> 
		  <LABEL id="ckcontent" style="WIDTH: 100px; COLOR: #f00">*</LABEL></LI>
		  <LI style="LINE-HEIGHT: 40px; HEIGHT: 40px; CLEAR: both; border-bottom:0px; width:300px"><LABEL></LABEL><INPUT style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; FONT-SIZE: 12px; BORDER-TOP: 0px; BORDER-RIGHT: 0px; margin-left:50px;" class=smtgray value=立即发送 type=submit> 
		  </LI></FORM>
		  <?php
		  }
		  ?>	
	</div>
	</div>
</div>
	<div class="megas512" style="clear:both"><?php pageft($total,$pagesize,1,1,0,10,"msg_list.php?act=".$act."");	echo $pagenav;?></div>
</div><DIV class=white_bottomm>
<DIV class=white_bottom_left></DIV>
<DIV class=white_bottom_middle></DIV>
<DIV class=white_bottom_right></DIV></DIV></div>
<?php
include("../template/".MOBAN."/footer.tpl.php");
mysql_close();
?>
</body>
</html>