<?php
session_start();
$name=$_SESSION["name"];
?>
<!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" />
<title>收件箱</title>
<link href="index.css" rel="stylesheet" />
<script src="../global/jquery-latest.min.js"></script>
<script src="index.js"></script>
<script> 
          var checkall=document.getElementsByName("mailid[]");  
           function selectall(){                          //全选  
                for(var $i=0;$i<checkall.length;$i++){  
                    checkall[$i].checked=true;  
                }  
            }  
            function fanselect(){                        //反选  
                for(var $i=0;$i<checkall.length;$i++){  
                   if(checkall[$i].checked){  
                       checkall[$i].checked=false;  
                   }else{  
                        checkall[$i].checked=true;  
                    }  
                }  
           }           
         function noselect(){                          //全不选  
               for(var $i=0;$i<checkall.length;$i++){  
                    checkall[$i].checked=false;  
              }  
          }   
 function check(){
		  for(var $i=0;$i<checkall.length;$i++){  
                    if(checkall[$i].checked==true){
					   return true;
					}
                }  
			alert("请先选择要删除的邮件");
			 return false;
		  }        
 </script>
</head>

<body>
<div class="bigdiv">
<table cellspacing="0" cellpadding="0" style="font-size:14px;"><tr><td style="text-align:left;border-left:none;">您的位置：邮件系统/<a href="receive.php">收件箱</a></td><td style="border-left:none;text-align:right;"><a href="add.php">发邮件</a>&nbsp;&nbsp;&nbsp;&nbsp;</td></tr></table>
<div style="float:left;width:100%;border-bottom:2px solid #337abb;height:25px;font-size:14px;line-height:25px;"><ul>
<li style="float:left;width:100px;text-align:center;border:2px solid #337abb;border-top:1px solid #337abb;border-bottom:none;background:#337abb;margin-left:20px;display:inline;"><a style="color:#FFF;" href="receive.php">收件箱</a></li>
</ul></div>
<div class="list">
<form action='function.php?mod=deletes' method='post' onsubmit="return check()">
<table cellspacing="0" cellpadding="0"><tr style="background:#d3edf9;"><td style="width:4%;border-left:none;">&nbsp;</td><td style="width:8%;">状态</td><td style="width:58%;">标题</td><td style="width:8%;">发件人</td><td style="width:13%;">日期</td><td style="width:8%" >操作</td></tr></table>
<table cellspacing="0" cellpadding="0">
<?php
ob_start();
require_once("../global/page.class.php");
require_once("../global/connect.php");
mysql_query("delete from message where receive=''");
$pageSize=15;
$total=mysql_num_rows(mysql_query("SELECT * FROM message where receive like '%$name%'")); 
pageft($total,$pageSize,1,1,1,9,20,0);
$sql="SELECT * FROM  message where receive like '%$name%' order by id DESC limit $firstcount,$pageSize";
$sql=mysql_query($sql);
if($sql){ob_end_clean();
while($row=mysql_fetch_array($sql)){
if($row['state']!=""){
$state=explode($name,$row['state']);
if(count($state)>1)
$state='已读';
else
$state='未读';
}else
$state='未读';
$id=$row['id'];
$content=utf8Substr($row['content'],0,30);
$content=strip_tags($content);
echo "<tr><td style='width:4%;border-left:none;'><input type='checkbox' name='mailid[]' value='$id'></td><td style='width:8%;'>".$state."</td><td style='width:58%;text-align:left;'>&nbsp;<a href='showmsg.php?id=$id'>".$row['title']."<font style='color:#666666;fontsize:12px;'>&nbsp;--&nbsp;$content</font></a></td><td style='width:8%;'>".$row['send']."</td><td style='width:13%;'>".$row['date']."</td><td style='width:8%;'><a href='function.php?id=$id&mod=delete'>[删除]</a></td></tr>";
}}else
echo "<tr><td style='color:red;text-align:center;'>暂时没有记录！</td></tr>";
ob_end_flush();
//字符串截取
function utf8Substr($str, $from, $len) 
{ 
return preg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$from.'}'. 
'((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$len.'}).*#s', 
'$1',$str); 
} 
?>
</table>
<div>&nbsp;&nbsp;&nbsp;&nbsp;<input type='button' value="全选" onclick="selectall()"/><input type="button" value="反选" onclick="fanselect()"/><input type="button" value="全不选" onclick="noselect()"/><input type="submit" value="批量删除"/>&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $pagenav;?></div></form>
</div>
</div>
</body>
</html>
