<?php

/**
 * 后台首页
 * ============================================================================
 * TBlog TBlog博客系统　BY Tmac PHP MVC framework
 * $Author: zhaojianjun $  <zwttmac@qq.com>
 * $Id: index.php 158 2012-02-16 05:31:34Z zhaojianjun $
 * http://www.t-mac.org；
 */
class indexAction extends Action
{

    //定义初始化变量
    private $menu;

    public function _init()
    {
        //加载并返回Model文件夹下的Model对象。
        $this->menu = Tmac::model('Menu');
        $check_model = $this->M('check');
        $check_model->checkLogin();
        $check_model->CheckPurview('zhuna_admin,zhuna_editor,zhuna_lock');
    }

    public function index()
    {
        $menusMain = "
        <m:top mapitem='0' name='资讯管理' rank='zhuna_admin,zhuna_editor'>
          <m:item name='资讯添加' link='" . PHP_SELF . "?m=article.add' rank='zhuna_admin,zhuna_editor' target='main' />
          <m:item name='资讯管理' link='" . PHP_SELF . "?m=article' rank='zhuna_admin,zhuna_editor' target='main' />          
          <m:item name='资讯类别添加' link='" . PHP_SELF . "?m=article_class.add' rank='zhuna_admin,zhuna_editor' target='main' />
          <m:item name='资讯类别管理' link='" . PHP_SELF . "?m=article_class' rank='zhuna_admin,zhuna_editor' target='main' />              
        </m:top>

        <m:top mapitem='0' name='广告管理' rank='zhuna_admin'>
          <m:item name='广告管理' link='" . PHP_SELF . "?m=ad' rank='zhuna_admin' target='main' />
          <m:item name='广告添加' link='" . PHP_SELF . "?m=ad.add' rank='zhuna_admin' target='main' />                        
        </m:top>
        
        <m:top mapitem='0' name='辅助功能' rank='zhuna_admin'>          
          <m:item name='专题管理' link='" . PHP_SELF . "?m=special' rank='zhuna_admin' target='main' />          
          <m:item name='友情链接添加' link='" . PHP_SELF . "?m=flink.add' rank='zhuna_admin' target='main' />
          <m:item name='友情链接管理' link='" . PHP_SELF . "?m=flink' rank='zhuna_admin' target='main' />                        
        </m:top>        
        
        <m:top mapitem='0' name='模板管理' rank='zhuna_admin'>          
          <m:item name='模板选择' link='" . PHP_SELF . "?m=templates' rank='zhuna_admin' target='main' />          
          <m:item name='模板修改' link='" . PHP_SELF . "?m=templates.edit' rank='zhuna_admin' target='main' />          
        </m:top>
        
        <m:top mapitem='0' name='数据更新' rank='zhuna_admin'>          
          <m:item name='全部更新' link='" . PHP_SELF . "?m=updatehotel' rank='zhuna_admin' target='main' />       
          <m:item name='个别更新' link='" . PHP_SELF . "?m=updatehotel.updateone' rank='zhuna_admin' target='main' />        
        </m:top>        
        
        <m:top mapitem='0' name='站点设置' rank='zhuna_admin,zhuna_editor,zhuna_lock'>
          <m:item name='网站设置' link='" . PHP_SELF . "?m=config' rank='zhuna_admin' target='main' />
          
          <m:item name='页面关键字管理' link='" . PHP_SELF . "?m=keywords' rank='zhuna_admin' target='main' />          
          <m:item name='管理员添加' link='" . PHP_SELF . "?m=manage.add' rank='zhuna_admin' target='main' />
          <m:item name='管理员管理' link='" . PHP_SELF . "?m=manage' rank='zhuna_admin' target='main' />
          <m:item name='数据库备份' link='" . PHP_SELF . "?m=data.back' rank='zhuna_admin' target='main' />              
          <m:item name='数据库还原' link='" . PHP_SELF . "?m=data.revert' rank='zhuna_admin' target='main' />                  
          <m:item name='退出系统' link='" . PHP_SELF . "?m=login.out' rank='zhuna_admin,zhuna_editor,zhuna_lock' target='main' />                                
        </m:top>
        
        <m:top mapitem='0' name='帮助中心' rank='zhuna_admin'>          
          <m:item name='帮助中心' link='http://union.api.zhuna.cn/api/utf-8/docs/' rank='zhuna_admin' target='_blank' />           
        </m:top>  
                
        ";
        //取config配置文件
        $configcache = Tmac::config('configcache.config.cfg_indexurl', APP_WWW_NAME, '.inc.php');
        $verLockFile = VAR_ROOT . 'Data/ver.txt';
        $version = file_get_contents( $verLockFile);        
        $this->assign('admin_title', $GLOBALS['TmacConfig']['config']['admin_title']);
        $this->assign('indexurl', $configcache);
        $this->assign('version', $version);   
        $this->assign('menua', $this->menu->getMenua($menusMain));
        $this->assign('username', $_SESSION['admin']);
        $this->V();
    }

    public function body()
    {
        $verLockFile = VAR_ROOT . 'Data/ver.txt';
        $fp = fopen($verLockFile, 'r');
        $upTime = trim(fread($fp, 64));
        fclose($fp);    
        $this->assign('gdversion', $this->menu->gdversion());
        $this->assign('upTime', $upTime);
        $this->V('index_body');
    }

}