PageRenderTime 37ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/class/message/InBox.class.php

https://github.com/hylinux/ltebbs
PHP | 268 lines | 144 code | 68 blank | 56 comment | 23 complexity | dcc6e47d5b952c15e852b1a0e645d1e7 MD5 | raw file
  1. <?php
  2. //vim:set expandtab tabstop=3 shiftwidth=3 softtabstop=3 foldcolumn=1 foldmethod=marker:
  3. /**
  4. * 项目: 5anet(BBS)
  5. * 文件: class/message/InBox.class.php
  6. *
  7. * 显示用户的短消息收件箱
  8. *
  9. * PHP Version 5
  10. *
  11. * @package: class.message
  12. * @author: Mike.G Chinese Name: 黄叶 <hylinux@gmail.com>
  13. * @license: http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
  14. * @copyright: http://www.5anet.com
  15. * @version: $Id: InBox.class.php,v 1.1.1.1 2006-08-28 13:09:20 ghw Exp $
  16. * @date: $Date: 2006-08-28 13:09:20 $
  17. */
  18. include_once CLASS_PATH.'main/BaseAction.class.php';
  19. include_once CLASS_PATH.'user/UserUtil.class.php';
  20. include_once FUNCTION_PATH.'utf8_substr.fun.php';
  21. //include the language file
  22. if ( file_exists(LANG_PATH.SYSTEM_LANG.'/InBox.lang.php') ) {
  23. include_once LANG_PATH.SYSTEM_LANG.'/InBox.lang.php';
  24. }
  25. class InBox extends BaseAction {
  26. /**
  27. * 数据库的连接
  28. */
  29. public $db;
  30. /**
  31. * 每页显示的信息条数
  32. */
  33. private $page_number = 10;
  34. /**
  35. * 构造函数
  36. * @param: NULL
  37. * @return: NULL
  38. * @access: public
  39. */
  40. public function __construct() {
  41. $this->db = $this->getDB();
  42. }
  43. /**
  44. * 显示用户的短消息收件箱
  45. * @param: NULL
  46. * @return: NULL
  47. * @access: public
  48. */
  49. public function run() {
  50. //求得用户的id
  51. $user_id = UserUtil::getUserId($this->db, $_SESSION['user']['name']);
  52. $smarty = $this->getSmarty();
  53. $user_name = $_SESSION['user']['name'];
  54. $smarty->assign('view_user_name', $user_name);
  55. //用户的所在组
  56. $sql = 'select b.group_name from base_user_info as a join sys_group as b on '.
  57. ' a.group_dep = b.id where a.id=?';
  58. $sth = $this->db->Prepare($sql);
  59. $res = $this->db->Execute($sth, array($user_id));
  60. $rows = $res->FetchRow();
  61. $smarty->assign('user_roles', $rows['group_name']);
  62. //加入统计信息
  63. $user_header = UserUtil::getUserHeader($this->db, $user_id);
  64. $smarty->assign('head_url', $user_header);
  65. //查询新的短消息的数量
  66. $sql = 'select count(*) as num from message_inbox where user_id=? and is_read = 0 ';
  67. $sth = $this->db->Prepare($sql);
  68. $res = $this->db->Execute($sth, array($user_id));
  69. $rows = $res->FetchRow();
  70. $smarty->assign('new_message_label', $rows['num']);
  71. //共有短消息数
  72. $sql = 'select count(*) as num from message_inbox where user_id=? ';
  73. $sth = $this->db->Prepare($sql);
  74. $res = $this->db->Execute($sth, array($user_id));
  75. $rows = $res->FetchRow();
  76. $smarty->assign('total_message_number', $rows['num']);
  77. //取得用户注册时间
  78. $sql = 'select register_date from base_user_info where id=?';
  79. $stmt = $this->db->prepare($sql);
  80. $res = $this->db->CacheExecute(60*60, $stmt, array($user_id));
  81. $rows = $res->FetchRow();
  82. $smarty->assign('user_register_date', $rows['register_date']);
  83. //取得用户最后的登录时间
  84. $sql = 'SELECT from_unixtime(last_time) as lastlogout FROM `user_last_time_logout` where user_id=?';
  85. $stmt = $this->db->prepare($sql);
  86. $res = $this->db->CacheExecute(60*60, $stmt, array($user_id));
  87. $rows = $res->FetchRow();
  88. $smarty->assign('user_last_logout', $rows['lastlogout']);
  89. //发表的主题数
  90. $sql = 'select count(*) as num from bbs_subject where author = ?';
  91. $stmt = $this->db->Prepare($sql);
  92. $res = $this->db->CacheExecute(10, $stmt, array($user_name));
  93. $rows = $res->FetchRow();
  94. $smarty->assign('all_topic_number', $rows['num']);
  95. //参与的帖子数
  96. $sql = 'select count(*) as num from bbs_reply where author=?';
  97. $stmt = $this->db->Prepare($sql);
  98. $res = $this->db->CacheExecute(10, $stmt, array($user_name));
  99. $rows = $res->FetchRow();
  100. $smarty->assign('all_reply_number', $rows['num']);
  101. ///拥有的短消息的数量
  102. $sql = 'select count(*) as num from message_inbox where user_id=?';
  103. $stmt = $this->db->prepare($sql);
  104. $res = $this->db->CacheExecute(20, $stmt, array($user_id));
  105. $rows = $res->FetchRow();
  106. $number_inbox = $rows['num'];
  107. $sql = 'select count(*) as num from message_outbox where user_id=?';
  108. $stmt = $this->db->prepare($sql);
  109. $res = $this->db->CacheExecute(20, $stmt, array($user_id));
  110. $rows = $res->FetchRow();
  111. $smarty->assign('message_all_number', $number_inbox + $rows['num']);
  112. //拥有的收藏数
  113. $sql = 'select count(*) as num from favor where user_id=?';
  114. $stmt = $this->db->prepare($sql);
  115. $res = $this->db->CacheExecute(10, $stmt, array($user_id));
  116. $rows = $res->FetchRow();
  117. $smarty->assign('favor_amount', $rows['num']);
  118. //求页数
  119. $sql = 'select count(*) as num from message_inbox where user_id=?';
  120. $sth = $this->db->Prepare($sql);
  121. $res = $this->db->Execute($sth, array($user_id));
  122. $rows = $res->FetchRow();
  123. $total_number = $rows['num'];
  124. //求总公的页面
  125. $total_page = ceil($total_number / $this->page_number );
  126. //取得当前的页面
  127. $page = $this->getParameter('page');
  128. if ( !$page || $page < 0 ) {
  129. $page = 1;
  130. }
  131. if ( $page > $total_page && $total_page > 0 ) {
  132. $page = $total_page;
  133. }
  134. $begin_page = 1;
  135. $end_page = $total_page;
  136. if ( $page <= 10 && $total_page >=10 ) {
  137. $end_page = 10;
  138. } else if ( $page > 10 ) {
  139. if ( $page % 10 == 0 ) {
  140. //向前翻
  141. $end_page = $page;
  142. $begin_page = $end_page - 9;
  143. } else if ( $page % 10 == 1 ) {
  144. //向后翻
  145. //确定开始的页数
  146. $begin_page = $page;
  147. if ( $begin_page > $total_page ) {
  148. $begin_page = $page - 9;
  149. }
  150. if ( ( $begin_page + 9 ) > $total_page ) {
  151. $end_page = $total_page;
  152. } else {
  153. $end_page = $begin_page + 9;
  154. }
  155. } else {
  156. $num = $page % 10;
  157. $pre_num = floor($page / 10 );
  158. $begin_page = $pre_num * 10 + 1;
  159. $end_page = $begin_page + 9;
  160. }
  161. }
  162. $nav_page_array = array();
  163. for( $i = $begin_page; $i<=$end_page; $i++ ) {
  164. array_push($nav_page_array, $i);
  165. }
  166. //帖子导航栏
  167. $smarty->assign('nav_page', $nav_page_array);
  168. //当前的页面
  169. $smarty->assign('now_page', $page);
  170. //共有的页面
  171. $smarty->assign('total_page', $total_page);
  172. //求用户的信息
  173. $offset_page = ( $page - 1 ) * $this->page_number;
  174. $sql = 'select a.id, a.send_user_id, b.user_name, a.title, a.receive_time, '.
  175. ' a.is_read from message_inbox '.
  176. ' as a left join base_user_info as b on a.send_user_id = b.id '.
  177. ' where user_id=? order by a.id desc ';
  178. $res = $this->db->SelectLimit($sql, $this->page_number, $offset_page, array($user_id));
  179. $temp_array = array();
  180. while ( $rows = $res->FetchRow() ) {
  181. if ( $rows['send_user_id'] == 0 ) {
  182. $send_user_name = 'system';
  183. } else {
  184. $send_user_name = $rows['user_name'];
  185. }
  186. $temp_array[] = array (
  187. 'id'=> $rows['id'],
  188. 'is_read' => $rows['is_read'],
  189. 'send_user_id' => $rows['send_user_id'],
  190. 'send_user_name' => $send_user_name,
  191. 'title' => $rows['title'],
  192. 'short_title' => utf8_substr($rows['title'], 0, 18),
  193. 'send_date' => $rows['receive_time']
  194. );
  195. }
  196. $smarty->assign('msg', $temp_array);
  197. $smarty->display('userinbox.tmpl');
  198. }
  199. }
  200. ?>