예제 #1
0
 /**
  * 显示用户的控制面板
  */
 public function run()
 {
     //求得用户的id
     $user_id = UserUtil::getUserId($this->db, $_SESSION['user']['name']);
     $smarty = $this->getSmarty();
     $user_name = $_SESSION['user']['name'];
     $smarty->assign('view_user_name', $user_name);
     //用户的所在组
     $sql = 'select b.group_name from base_user_info as a join sys_group as b on ' . ' a.group_dep = b.id where a.id=?';
     $sth = $this->db->Prepare($sql);
     $res = $this->db->Execute($sth, array($user_id));
     $rows = $res->FetchRow();
     $smarty->assign('user_roles', $rows['group_name']);
     $user_header = UserUtil::getUserHeader($this->db, $user_id);
     $smarty->assign('head_url', $user_header);
     //查询新的短消息的数量
     $sql = 'select count(*) as num from message_inbox where user_id=? and is_read = 0 ';
     $sth = $this->db->Prepare($sql);
     $res = $this->db->Execute($sth, array($user_id));
     $rows = $res->FetchRow();
     $smarty->assign('new_message_label', $rows['num']);
     //共有短消息数
     $sql = 'select count(*) as num from message_inbox where user_id=? ';
     $sth = $this->db->Prepare($sql);
     $res = $this->db->Execute($sth, array($user_id));
     $rows = $res->FetchRow();
     $smarty->assign('total_message_number', $rows['num']);
     //取得用户注册时间
     $sql = 'select register_date from base_user_info where id=?';
     $stmt = $this->db->prepare($sql);
     $res = $this->db->CacheExecute(60 * 60, $stmt, array($user_id));
     $rows = $res->FetchRow();
     $smarty->assign('user_register_date', $rows['register_date']);
     //取得用户最后的登录时间
     $sql = 'SELECT from_unixtime(last_time) as lastlogout FROM `user_last_time_logout` where user_id=?';
     $stmt = $this->db->prepare($sql);
     $res = $this->db->CacheExecute(60 * 60, $stmt, array($user_id));
     $rows = $res->FetchRow();
     $smarty->assign('user_last_logout', $rows['lastlogout']);
     //发表的主题数
     $sql = 'select count(*) as num from bbs_subject where author = ?';
     $stmt = $this->db->Prepare($sql);
     $res = $this->db->CacheExecute(10, $stmt, array($user_name));
     $rows = $res->FetchRow();
     $smarty->assign('all_topic_number', $rows['num']);
     //参与的帖子数
     $sql = 'select count(*) as num from bbs_reply where author=?';
     $stmt = $this->db->Prepare($sql);
     $res = $this->db->CacheExecute(10, $stmt, array($user_name));
     $rows = $res->FetchRow();
     $smarty->assign('all_reply_number', $rows['num']);
     ///拥有的短消息的数量
     $sql = 'select count(*) as num from message_inbox where user_id=?';
     $stmt = $this->db->prepare($sql);
     $res = $this->db->CacheExecute(20, $stmt, array($user_id));
     $rows = $res->FetchRow();
     $number_inbox = $rows['num'];
     $sql = 'select count(*) as num from message_outbox where user_id=?';
     $stmt = $this->db->prepare($sql);
     $res = $this->db->CacheExecute(20, $stmt, array($user_id));
     $rows = $res->FetchRow();
     $smarty->assign('message_all_number', $number_inbox + $rows['num']);
     //拥有的收藏数
     $sql = 'select count(*) as num from favor where user_id=?';
     $stmt = $this->db->prepare($sql);
     $res = $this->db->CacheExecute(10, $stmt, array($user_id));
     $rows = $res->FetchRow();
     $smarty->assign('favor_amount', $rows['num']);
     //取得导航栏菜单
     //开始检查帖子。
     $total_number = LayoutUtil::getTotalNumberReplyByUser($this->db, $user_name);
     //求总公的页面
     $total_page = ceil($total_number / $this->page_number);
     //取得当前的页面
     $page = $this->getParameter('page');
     if (!$page || $page < 0) {
         $page = 1;
     }
     if ($page > $total_page && $total_page > 0) {
         $page = $total_page;
     }
     $begin_page = 1;
     $end_page = $total_page;
     if ($page <= 10 && $total_page >= 10) {
         $end_page = 10;
     } else {
         if ($page > 10) {
             if ($page % 10 == 0) {
                 //向前翻
                 $end_page = $page;
                 $begin_page = $end_page - 9;
             } else {
                 if ($page % 10 == 1) {
                     //向后翻
                     //确定开始的页数
                     $begin_page = $page;
                     if ($begin_page > $total_page) {
                         $begin_page = $page - 9;
                     }
                     if ($begin_page + 9 > $total_page) {
                         $end_page = $total_page;
                     } else {
                         $end_page = $begin_page + 9;
                     }
                 } else {
                     $num = $page % 10;
                     $pre_num = floor($page / 10);
                     $begin_page = $pre_num * 10 + 1;
                     $end_page = $begin_page + 9;
                 }
             }
         }
     }
     if ($end_page > $total_page) {
         $end_page = $total_page;
     }
     $nav_page_array = array();
     for ($i = $begin_page; $i <= $end_page; $i++) {
         array_push($nav_page_array, $i);
     }
     //帖子导航栏
     $smarty->assign('nav_page', $nav_page_array);
     //当前的页面
     $smarty->assign('now_page', $page);
     //共有的页面
     $smarty->assign('total_page', $total_page);
     $subject_array = LayoutUtil::getReplyInfoByUser($this->db, $user_name, $this->page_number, ($page - 1) * $this->page_number, $show_best);
     $smarty->assign('subject', $subject_array);
     $smarty->display('listmyreply.tmpl');
 }
예제 #2
0
 /**
  * 显示用户的控制面板
  */
 public function run()
 {
     //求得用户的id
     $user_id = UserUtil::getUserId($this->db, $_SESSION['user']['name']);
     $smarty = $this->getSmarty();
     $user_name = $_SESSION['user']['name'];
     $smarty->assign('view_user_name', $user_name);
     //用户的所在组
     $sql = 'select b.group_name from base_user_info as a join sys_group as b on ' . ' a.group_dep = b.id where a.id=?';
     $sth = $this->db->Prepare($sql);
     $res = $this->db->Execute($sth, array($user_id));
     $rows = $res->FetchRow();
     $smarty->assign('user_roles', $rows['group_name']);
     $user_header = UserUtil::getUserHeader($this->db, $user_id);
     $smarty->assign('head_url', $user_header);
     //查询新的短消息的数量
     $sql = 'select count(*) as num from message_inbox where user_id=? and is_read = 0 ';
     $sth = $this->db->Prepare($sql);
     $res = $this->db->Execute($sth, array($user_id));
     $rows = $res->FetchRow();
     $smarty->assign('new_message_label', $rows['num']);
     //共有短消息数
     $sql = 'select count(*) as num from message_inbox where user_id=? ';
     $sth = $this->db->Prepare($sql);
     $res = $this->db->Execute($sth, array($user_id));
     $rows = $res->FetchRow();
     $smarty->assign('total_message_number', $rows['num']);
     //取得用户注册时间
     $sql = 'select register_date from base_user_info where id=?';
     $stmt = $this->db->prepare($sql);
     $res = $this->db->CacheExecute(60 * 60, $stmt, array($user_id));
     $rows = $res->FetchRow();
     $smarty->assign('user_register_date', $rows['register_date']);
     //取得用户最后的登录时间
     $sql = 'SELECT from_unixtime(last_time) as lastlogout FROM `user_last_time_logout` where user_id=?';
     $stmt = $this->db->prepare($sql);
     $res = $this->db->CacheExecute(60 * 60, $stmt, array($user_id));
     $rows = $res->FetchRow();
     $smarty->assign('user_last_logout', $rows['lastlogout']);
     //发表的主题数
     $sql = 'select count(*) as num from bbs_subject where author = ?';
     $stmt = $this->db->Prepare($sql);
     $res = $this->db->CacheExecute(10, $stmt, array($user_name));
     $rows = $res->FetchRow();
     $smarty->assign('all_topic_number', $rows['num']);
     //参与的帖子数
     $sql = 'select count(*) as num from bbs_reply where author=?';
     $stmt = $this->db->Prepare($sql);
     $res = $this->db->CacheExecute(10, $stmt, array($user_name));
     $rows = $res->FetchRow();
     $smarty->assign('all_reply_number', $rows['num']);
     //拥有的收藏数
     $sql = 'select count(*) as num from favor where user_id=?';
     $stmt = $this->db->prepare($sql);
     $res = $this->db->CacheExecute(10, $stmt, array($user_id));
     $rows = $res->FetchRow();
     $smarty->assign('favor_amount', $rows['num']);
     ///拥有的短消息的数量
     $sql = 'select count(*) as num from message_inbox where user_id=?';
     $stmt = $this->db->prepare($sql);
     $res = $this->db->CacheExecute(20, $stmt, array($user_id));
     $rows = $res->FetchRow();
     $number_inbox = $rows['num'];
     $sql = 'select count(*) as num from message_outbox where user_id=?';
     $stmt = $this->db->prepare($sql);
     $res = $this->db->CacheExecute(20, $stmt, array($user_id));
     $rows = $res->FetchRow();
     $smarty->assign('message_all_number', $number_inbox + $rows['num']);
     //最新的5条短消息
     $sql = 'select a.id, a.user_id, b.user_name,a.send_user_id, ' . 'a.title, a.receive_time, a.is_read ' . ' from message_inbox as a, base_user_info as b  where a.send_user_id = b.id and a.user_id=? ' . ' order by a.id desc';
     $stmt = $this->db->prepare($sql);
     $res = $this->db->CacheSelectLimit(20, $stmt, 5, 1, array($user_id));
     $rows = $res->GetArray();
     $smarty->assign('msg', $rows);
     //最新5条发表的主题
     $subject_array = LayoutUtil::getSubjectInfoByUser($this->db, $user_name);
     $smarty->assign('subject', $subject_array);
     //最新参与的5条主题
     $reply_array = LayoutUtil::getReplyInfoByUser($this->db, $user_name);
     $smarty->assign('reply', $reply_array);
     //最新的5条收藏
     $favor_array = LayoutUtil::getSubjectInfoByFavor($this->db, $user_id);
     $smarty->assign('favor', $favor_array);
     $smarty->display('usercontrol.tmpl');
 }