<?php
require("../../class/connect.php");
require("../../class/q_functions.php");
require("../../class/t_functions.php");
require("../../class/db_sql.php");
require("../class/user.php");
require "../".LoadLang("pub/fun.php");
$link=db_connect();
$empire=new mysqlquery();
$editor=1;
eCheckCloseMods('member');//关闭模块
$user=islogin();
if($_GET["Action"]=="MsgJson"){
  $query="select mid as ID,title as Title,haveread as HaveRead,from_userid as UserID,from_username as UserName,isadmin as IsAdmin,msgtime as MsgTime,issys as IsSys from {$dbtbpre}enewsqmsg where to_username='$user[username]' and haveread=0 order by mid desc";
  $sql=$empire->query($query);
  $Msgs = array();
  while($r=$empire->fetch($sql)){
    $UserInfo = sys_ShowMemberInfo($r["UserID"],'userpic');
    if($UserInfo[userpic]==""){$UserInfo[userpic]=$public_r['newsurl']."e/data/images/nouserpic.gif";}
    $r["UserFace"] = $UserInfo[userpic];
    $r["MsgTime"] = date("m-d H:i",strtotime($r["MsgTime"]));
    $Msgs[] = $r;
  }
  echo json_encode($Msgs);
}elseif($_GET["Action"]=="NoticeJson"){
  $query="select mid as ID,title as Title,haveread as HaveRead,from_userid as UserID,from_username as UserName,isadmin as IsAdmin,msgtime as MsgTime,issys as IsSys from {$dbtbpre}enewsqmsg where to_username='$user[username]' and haveread=0 and issys=1 order by mid desc";
  $sql=$empire->query($query);
  $Notices = array();
  while($r=$empire->fetch($sql)){
    $Notices[] = $r;
  }
  echo json_encode($Notices);
}else{
  $start=0;
  $page=(int)$_GET['page'];
  $page=RepPIntvar($page);
  $add='';
  $search='';
  $line=20;//每行显示
  $page_line=10;
  $offset=$page*$line;
  $totalquery="select count(*) as total from {$dbtbpre}enewsqmsg ";
  if($_GET["Type"]=="Sended"){
    $query="select mid,title,haveread,to_username as from_username,isadmin,msgtime,issys from {$dbtbpre}enewsqmsg where from_username='$user[username]'";
    $totalquery.="where from_username='$user[username]'";
  }elseif($_GET["Type"]=="NoRead"){
    $query="select mid,title,haveread,from_userid,from_username,isadmin,msgtime,issys from {$dbtbpre}enewsqmsg where to_username='$user[username]' and haveread=0";
    $totalquery.="where to_username='$user[username]' and haveread=0";
  }elseif($_GET["Type"]=="System"){
    $query="select mid,title,haveread,from_userid,from_username,isadmin,msgtime,issys from {$dbtbpre}enewsqmsg where to_username='$user[username]' and issys=1";
    $totalquery.="where to_username='$user[username]' and issys=1";
  }else{
    $query="select mid,title,haveread,from_userid,from_username,isadmin,msgtime,issys from {$dbtbpre}enewsqmsg where to_username='$user[username]'";
    $totalquery.="where to_username='$user[username]'";
  }
  $num=$empire->gettotal($totalquery);
  $query.=" order by mid desc limit $offset,$line";
  $sql=$empire->query($query);
  $returnpage=page_cp($num,$line,$page_line,$start,$page,$search);
  //导入模板
  require(ECMS_PATH.'e/template/member/msg.php');
}
db_close();
$empire=null;
?>