<?php
namespace admin\Controller;
use Think\Controller;
class MainController extends CommonController {
	public function index(){
	  $this->display();
	}
	public function top_menu(){
		$menu=$this->get_admin_menu(0);
		$user=D('User')->get_user_one(session('uu.uid'),true,1);
		$this->assign('menu',$menu);
		$this->assign('user',$user);
		$this->display();
	}
	public function left_menu(){
		$menu_id=I('get.menu_id','1','intval');
		$menu=$this->get_admin_menu($menu_id);
		$this->assign('menu',$menu);
	  	$this->display();
	}
	public function main(){
	
		 if (APP_DEBUG == true) {
            $message[] = array(
                'type' => 'error',
                'content' => "系统debug处于打开模式，建议关闭，关闭后可提升系统运行效率。",
            );
        }
		//待办
		$map['audit']=0;
		$wait_info['question']=M('Question')->where($map)->count();
		$wait_info['article']=M('Article')->where($map)->count();
		$wait_info['tag']=M('Tag')->where($map)->count();
		
		//今日统计
		$today=get_mktime(0);
		$map['addtime'] = array(array('gt',$today[0]),array('lt',$today[1])) ;
		$usermap['reg_time'] = array(array('gt',$today[0]),array('lt',$today[1])) ;
		$today_info['user']=M('User')->where($usermap)->count();
		$today_info['question']=M('Question')->where($map)->count();
		$today_info['article']=M('Article')->where($map)->count();
		$today_info['tag']=M('Tag')->where($map)->count();
		
		//昨日统计
		$yesterday=get_mktime('-1');
		$map['addtime'] = array(array('gt',$yesterday[0]),array('lt',$yesterday[1])) ;
		$usermap['reg_time'] = array(array('gt',$yesterday[0]),array('lt',$yesterday[1])) ;
		$yesterday_info['user']=M('User')->where($usermap)->count();
		$yesterday_info['question']=M('Question')->where($map)->count();
		$yesterday_info['article']=M('Article')->where($map)->count();
		$yesterday_info['tag']=M('Tag')->where($map)->count();
		
		//系统信息
		$system_info = array(
            'server_os' => PHP_OS,
            'web_server' => $_SERVER["SERVER_SOFTWARE"],
            'php_version' => PHP_VERSION,
            'mysql_version' => mysql_get_server_info()
        );
		//总数统计
		$count_info['user']=M('User')->count();
		$count_info['question']=M('Question')->count();
		$count_info['article']=M('Article')->count();
		$count_info['answer']=M('Answer')->count();
		$count_info['tag']=M('Tag')->count();
		$count_info['img']=M('QuestionImg')->count();
		$count_info['notice']=M('Notice')->count();
		$this->assign('message', $message);
 		$this->assign('wait_info', $wait_info);
		$this->assign('today_info',$today_info);
		$this->assign('yesterday_info',$yesterday_info);
		$this->assign('count_info', $count_info);
        $this->assign('system_info',$system_info);
	  	$this->display();
	}
}
?>