<?php
include('action.abs.php');
class followers extends action {
		var $db = null;
		function followers() {
				parent :: action();
				$this->db = APP :: ADP('db');
				$this->db->setTable(T_FOLLOWERS_COUNT);
		}

		/**
		 *  已屏蔽的列表
		 */
		function disabledList() {
				$page = V('g:page', 1);
				$each = V('g:each', 20);
				$keyword = V('g:keyword', '');
				$offset = ($page -1) * $each;

				$select_count = 'SELECT COUNT(*) FROM ' . $this->db->getTable(T_DISABLED_FOLLOWERS) ;
				$count = $this->db->getOne($select_count);

				$pager = APP :: N('pager');
				$page_param = array('currentPage'=> $page, 'pageSize' => $each, 'recordCount' => $count, 'linkNumber' => 10);
				$pager->setParam($page_param);
				TPL :: assign('pager', $pager->makePage());

				$sql = 'SELECT a.*,b.name FROM ' . $this->db->getTable(T_DISABLED_FOLLOWERS) . ' AS a LEFT JOIN ' . $this->db->getTable(T_ADMIN_USER) . ' AS b ON a.operator=b.id ORDER BY a.id DESC LIMIT ' . $offset . ',' . $each;
				$rs = $this->db->query($sql);
				TPL :: assign('list', $rs);
				$this->_display('followers/disabled_list');
		}

		/**
		 * 当前人气关注列表
		 */
		function followersList() {
				$page = V('g:page', 1);
				$each = V('g:each', 20);
				$keyword = V('g:keyword', '');
				$offset = ($page -1) * $each;

				$select_count = 'SELECT COUNT(*) FROM ' . $this->db->getTable() ;
				$count = $this->db->getOne($select_count);

				$pager = APP :: N('pager');
				$page_param = array('currentPage'=> $page, 'pageSize' => $each, 'recordCount' => $count, 'linkNumber' => 10);
				$pager->setParam($page_param);
				TPL :: assign('pager', $pager->makePage());

				$sql = 'SELECT * FROM ' . $this->db->getTable(T_FOLLOWERS_COUNT) . ' WHERE uid NOT IN(SELECT uid FROM ' . $this->db->getTable(T_DISABLED_FOLLOWERS) . ') ORDER BY followers_count DESC LIMIT ' . $offset . ',' . $each;
				
				$rs = $this->db->query($sql);
				TPL :: assign('list', $rs);
				$this->_display('followers/followers_list');
		}

		/**
		 * 删除关注项
		 */
		function delete() {
				$id = V('r:id');
				$nick = V('r:nick');
				$sql = 'INSERT IGNORE INTO '. $this->db->getTable(T_DISABLED_FOLLOWERS) . '(screen_name,uid,add_time,operator) VALUES("' .$nick. '","' .$id. '","' .time(). '","' .$this->_getUid(). '")';
				$rs = $this->db->execute($sql);
				if ($err = $this->db->getError()) {
					exit('{"state": false,"msg": "' . $err . '"}');
				}
				echo '{"state": true}';
		}

		/**
		 * 恢复关注项
		 */
		function resume() {
				$id = V('r:id');
				$rs = $this->db->delete($id, T_DISABLED_FOLLOWERS, 'uid');	
				$this->_succ('已经成功恢复', array(disabledList));
		}
		

}
