/** * 显示用户的控制面板 */ 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'); }