msgfun.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. //--------------- 站内消息函数 ---------------
  3. //发送短消息
  4. function AddMsg($add){
  5. global $empire,$level_r,$dbtbpre;
  6. $user=islogin();
  7. $title=RepPostStr(trim($add['title']));
  8. $to_username=RepPostVar(trim($add['to_username']));
  9. $msgtext=RepPostStr($add['msgtext']);
  10. if(empty($title)||!trim($msgtext)||empty($to_username))
  11. {printerror("EmptyMsg","",1);}
  12. if($user['username']==$to_username)
  13. {printerror("MsgToself","",1);}
  14. //字数
  15. $len=strlen($msgtext);
  16. if($len>$level_r[$user[groupid]][msglen])
  17. {
  18. printerror("MoreMsglen","",1);
  19. }
  20. //接收方是否存在
  21. $r=$empire->fetch1("select ".eReturnSelectMemberF('userid,groupid')." from ".eReturnMemberTable()." where ".egetmf('username')."='$to_username' limit 1");
  22. if(!$r['userid'])
  23. {
  24. printerror("MsgNotToUsername","",1);
  25. }
  26. //对方短消息是否满
  27. $mnum=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsqmsg where to_username='$to_username'");
  28. if($mnum+1>$level_r[$r[groupid]][msgnum])
  29. {
  30. printerror("UserMoreMsgnum","",1);
  31. }
  32. $msgtime=date("Y-m-d H:i:s");
  33. $sql=$empire->query("insert into {$dbtbpre}enewsqmsg(title,msgtext,haveread,msgtime,to_username,from_userid,from_username,isadmin,issys) values('".addslashes($title)."','".addslashes($msgtext)."',0,'$msgtime','$to_username','$user[userid]','$user[username]',0,0);");
  34. $newhavemsg=eReturnSetHavemsg($user['havemsg'],0);
  35. $usql=$empire->query("update ".eReturnMemberTable()." set ".egetmf('havemsg')."='$newhavemsg' where ".egetmf('username')."='$to_username' limit 1");
  36. if($sql)
  37. {
  38. printerror("AddMsgSuccess","../member/msg/",1);
  39. }
  40. else
  41. {printerror("DbError","",1);}
  42. }
  43. //删除短消息
  44. function DelMsg($mid){
  45. global $empire,$dbtbpre;
  46. $user=islogin();
  47. $mid=(int)$mid;
  48. if(!$mid)
  49. {printerror("EmptyDelMsg","",1);}
  50. $sql=$empire->query("delete from {$dbtbpre}enewsqmsg where mid='$mid' and to_username='$user[username]'");
  51. if($sql)
  52. {
  53. $num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsqmsg where to_username='$user[username]' and haveread=0 limit 1");
  54. if(!$num)
  55. {
  56. $newhavemsg=eReturnSetHavemsg($user['havemsg'],0);
  57. $newhavemsg=$newhavemsg==2||$newhavemsg==3?2:0;
  58. $empire->query("update ".eReturnMemberTable()." set ".egetmf('havemsg')."='$newhavemsg' where ".egetmf('userid')."='$user[userid]'");
  59. }
  60. printerror("DelMsgSuccess","../member/msg/",1);
  61. }
  62. else
  63. {printerror("DbError","",1);}
  64. }
  65. //批量删除短消息
  66. function DelMsg_all($mid){
  67. global $empire,$dbtbpre;
  68. $user=islogin();
  69. $count=count($mid);
  70. if(!$count)
  71. {printerror("EmptyDelMsg","",1);}
  72. for($i=0;$i<$count;$i++)
  73. {
  74. $add.="mid='".intval($mid[$i])."' or ";
  75. }
  76. $add=substr($add,0,strlen($add)-4);
  77. $sql=$empire->query("delete from {$dbtbpre}enewsqmsg where (".$add.") and to_username='$user[username]'");
  78. if($sql)
  79. {
  80. $num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsqmsg where to_username='$user[username]' and haveread=0 limit 1");
  81. if(!$num)
  82. {
  83. $newhavemsg=eReturnSetHavemsg($user['havemsg'],0);
  84. $newhavemsg=$newhavemsg==2||$newhavemsg==3?2:0;
  85. $empire->query("update ".eReturnMemberTable()." set ".egetmf('havemsg')."='$newhavemsg' where ".egetmf('userid')."='$user[userid]'");
  86. }
  87. printerror("DelMsgSuccess","../member/msg/",1);
  88. }
  89. else
  90. {printerror("DbError","",1);}
  91. }
  92. ?>