<?php
require ('authentication_member.php');
?>
<?php

/* 短信箱 */
/* 162100源码 - 162100.com */



$n = $mess = 0;
$text = $err = '';
if (!isset($sql['db_err'])) {
  db_conn();
}

if ($sql['db_err'] == '') {

  $result = @mysql_query('SELECT mess,mess_num,check_reg FROM '.$sql['pref'].''.$sql['data']['承载成员档案的表名'].' WHERE username="'.$session[0].'" LIMIT 1', $db);
  if ($row = @mysql_fetch_assoc($result)) {
    if ($row['check_reg'] == '1') {
      $err = '帐号注册审核中！';
    } elseif ($row['check_reg'] == '2') {
      $err = '帐号已被移除至<a href="list_member.php?act=punished" target="_blank">黑名单</a>！';
    } else {
      $mess = '<span class="grayword">'.preg_replace('/^\d+/', '<span>$0</span>', $row['mess_num']).'</span>';
    }
  } else {
    $err = '帐号不存在！';
  }
  @mysql_free_result($result);

  if (empty($err)) {
    $messlist = array_filter(explode("\n", trim($row['mess'])));

    unset($row);
    $n = count($messlist); //总记录数
    if ($n > 0) {
      require ('inc/function/get_page.php');
      require ('inc/function/get_date.php');
      $p = get_page($n); //页数
      $seek = $web['pagesize'] * ($p - 1);
      $end = $seek + $web['pagesize'] > $n ? $n : $seek + $web['pagesize'];

      for ($i = $seek; $i < $end; $i++) {
      //foreach ($messlist as $key => $line) { //时间|来信人|主题|内容|||已读状态
        $row = @explode('|', $messlist[$i]);
        if ($row[6] == 'o') {
          $read_y_n = '已读';
        } else {
          $read_y_n = '未读';
        }
          $text .= '
<table width="100%" class="li" id="check_'.$row[0].'" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="20"><input name="id[]" id="id[]" type="checkbox" class="checkbox" value="'.$row[0].'" /></td>
    <td><a href="javascript:void(0)" class="li_a" onclick="openZhaiyao(this,\''.$row[0].'\');return false;">'.$row[2].'</a>

<span id="show'.$row[0].'" class="zairu"></span>
     <div class="li_">

    来信人（<a href="user.php?get=card&username='.urlencode($row[1]).'" target="_blank">'.$row[1].'</a>）
  收信时间（'.get_date_c(get_date($row[0])).'）
  状态（<span id="read'.$row[0].'" class="greenword"><b>'.$read_y_n.'</b></span>，<a href="member.php?get=mess&username='.urlencode($row[1]).'" target="_blank" class="redword">回信</a>）
     </div>
</td>
  </tr>
</table>

  
';

        unset($row);
	  }
      $text .= get_page_foot($n, $web['pagesize'], $p, '?get=messbox&p=');
      $read_arr = preg_grep('/\|\s*$/', $messlist);
      $read_n = count($read_arr);
      //echo count($read_n);die;
      if ($read_n != $mess) {
        @mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载成员档案的表名'].' SET mess_num="'.$read_n.'/'.$n.'" WHERE username="'.$session[0].'"', $db);
      }
    } else {
      $err = '数据库查无数据！';
    }
  }

} else {
  $err .= $sql['db_err'];
}

@ require ('inc/function/add_online.php'); //在线
@mysql_close();



?>
<style type="text/css">
<!--
.zairu { display:inline; padding-left:0; }
.zairu_ { display:block; min-height:37px; padding-left:37px; background:url(inc/images/loading.gif) 0 0 no-repeat; }
#zhaiyao, .zhaiyao { background:#FFFFFF; }
-->
</style>
<script language="javascript" type="text/javascript">
<!--
//预览
function openZhaiyao(obj,sid){
  try{
    $('show'+sid).className='zairu_';
  }catch(err){
  }
  try{
    var zy=$('zhaiyao');
    var pp=zy.parentNode;
    pp.removeChild(zy);
  }catch(err){
  }
  var tdobj=obj;
  var t=tdobj.offsetTop;
  while(tdobj=tdobj.offsetParent){
    t+=tdobj.offsetTop;
  }
  obj.id='zhaiyaoopen';
  $('lastFrame').src='inc/require/z_other_getmess.php?obj='+obj.id+'&id='+sid+'&t='+t+'';
}
-->
</script>
<iframe id="lastFrame" name="lastFrame" frameborder="0" style="display:none;"></iframe>
<div class="list_title"><a class="list_title_in">短信列表<span>（<?php echo $n; ?>）</span></a><a href="member.php?get=mess">我要写信</a>
</div>

<form method="post" id="manageform" action="?post=unity_run&dataname=messbox">
  <div class="manager_menu"> <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="120"><a href="javascript:void(0)" onclick="allChoose(true,true);return false;">全选</a> - <a href="javascript:void(0)" onclick="allChoose(true,false);return false;">反选</a> - <a href="javascript:void(0)" onclick="allChoose(false,false);return false;">不选</a></td>
          <td width="200">
      <button name="act" type="button" onclick="chk(this.form,this,'messover')"><b>设为已读</b></button>
    <button name="act" type="button" onclick="chk(this.form,this,'messdel')"><b>删除</b></button></td>
          <td><div style="width:100%;overflow:hidden;line-height:normal;">
  <div style="float:left">短信箱容量：</div>
  <div style="float:left;background-color:#FFFFFF;width:200px;height:8px;padding:1px;border:#CCCCCC 1px solid;overflow:hidden;">
    <div style="float:left;width:<?php echo intval(($n * 200) / $web['mess_count']); ?>px;height:8px;background-color:#669966;overflow:hidden;">&nbsp;</div>
  </div>
  <?php echo $n.'/'.$web['mess_count'], $n >= $web['mess_count'] ? '<br /><span class="redword">（已满！请清理，以便于接收系统通知）</span>' : ''; ?></div></td>
        </tr>
      </table>
  </div>
  <?php echo $text, $err; ?>
  <input type="hidden" name="limit" />
</form>
