PageRenderTime 54ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/class/admin/ShowPost.class.php

https://github.com/hylinux/ltebbs
PHP | 158 lines | 71 code | 43 blank | 44 comment | 20 complexity | 66803d97538496a361d780775ece4d5b MD5 | raw file
  1. <?php
  2. //vim:set expandtab tabstop=3 shiftwidth=3 softtabstop=3 foldcolumn=1 foldmethod=marker:
  3. /**
  4. * Project Name: 5anet
  5. * File Name : class/admin/ShowPost.class.php
  6. *
  7. * 显示系统公告
  8. *
  9. * PHP Version 5
  10. *
  11. * @package: class.admin
  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: ShowPost.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/AdminBaseAction.class.php';
  19. //include the language file
  20. if ( file_exists(LANG_PATH.SYSTEM_LANG.'/admin/ShowPost.lang.php') ) {
  21. include_once LANG_PATH.SYSTEM_LANG.'/admin/ShowPost.lang.php';
  22. }
  23. class ShowPost extends AdminBaseAction {
  24. /**
  25. * 数据库的连接
  26. */
  27. public $db;
  28. private $page_number = 25;
  29. /**
  30. * 构造函数
  31. * @param: NULL
  32. * @return: NULL
  33. * @access: public
  34. */
  35. public function __construct() {
  36. $this->db = $this->getDB();
  37. }
  38. /**
  39. * run this action
  40. * @param: NULL
  41. * @return: NULL
  42. * @access: public
  43. */
  44. public function run() {
  45. $smarty = $this->getSmarty();
  46. //求总的数量
  47. $sql = 'select count(*) as num from site_post';
  48. $res = $this->db->Execute($sql);
  49. $rows = $res->FetchRow();
  50. $total_number = $rows['num'];
  51. //求总公的页面
  52. $total_page = ceil($total_number / $this->page_number );
  53. //取得当前的页面
  54. $page = $this->getParameter('page');
  55. if ( !$page || $page < 0 ) {
  56. $page = 1;
  57. }
  58. if ( $page > $total_page && $total_page > 0 ) {
  59. $page = $total_page;
  60. }
  61. $begin_page = 1;
  62. $end_page = $total_page;
  63. if ( $page <= 10 && $total_page >=10 ) {
  64. $end_page = 10;
  65. } else if ( $page > 10 ) {
  66. if ( $page % 10 == 0 ) {
  67. //向前翻
  68. $end_page = $page;
  69. $begin_page = $end_page - 9;
  70. } else if ( $page % 10 == 1 ) {
  71. //向后翻
  72. //确定开始的页数
  73. $begin_page = $page;
  74. if ( $begin_page > $total_page ) {
  75. $begin_page = $page - 9;
  76. }
  77. if ( ( $begin_page + 9 ) > $total_page ) {
  78. $end_page = $total_page;
  79. } else {
  80. $end_page = $begin_page + 9;
  81. }
  82. } else {
  83. $num = $page % 10;
  84. $pre_num = floor($page / 10 );
  85. $begin_page = $pre_num * 10 + 1;
  86. $end_page = $begin_page + 9;
  87. }
  88. }
  89. $nav_page_array = array();
  90. for( $i = $begin_page; $i<=$end_page; $i++ ) {
  91. array_push($nav_page_array, $i);
  92. }
  93. //帖子导航栏
  94. $smarty->assign('nav_page', $nav_page_array);
  95. //当前的页面
  96. $smarty->assign('now_page', $page);
  97. //共有的页面
  98. $smarty->assign('total_page', $total_page);
  99. //显示搜索结果
  100. //求出偏移
  101. $offset_number = ( $page - 1 ) * $this->page_number;
  102. //求用户的情况
  103. $sql = 'select id, title, begin_date, expires, case when expires > unix_timestamp() then 0 '.
  104. ' else 1 end as expire from site_post';
  105. $res = $this->db->SelectLimit($sql, $this->page_number, $offset_number);
  106. $temp_array = array();
  107. while ( $rows = $res->FetchRow() ) {
  108. $temp_array[] = $rows;
  109. }
  110. $smarty->assign('post', $temp_array);
  111. $smarty->display('adminpost.tmpl');
  112. return;
  113. }
  114. }
  115. ?>