<?php
// 本文档自动生成，仅供测试运行
    require("CommonAction.class.php");
class IndexAction extends CommonAction
{
 

    public function index() {

        $this->display();
    }

    public function verify() {
        $type = isset($_GET['type']) ? $_GET['type'] : 'gif';
        import("@.ORG.Image");
        Image::buildImageVerify(4, 1, $type);
    }
		
	// 顶部页面
	public function top() {
	   
		$this->display();
	}
	// 顶部页面
	public function center() {
	   
		$this->display();
	}
	// 尾部页面
	public function down() {
		$this->display();
	}
		// 菜单页面
	public function left() {
        $this->checkUser();
        if(isset($_SESSION[C('USER_AUTH_KEY')])) {
            //显示菜单项
            $menu  = array();
            if(isset($_SESSION['menu'.$_SESSION[C('USER_AUTH_KEY')]])) {
                //如果已经缓存，直接读取缓存
                $menu   =  $_SESSION['menu'.$_SESSION[C('USER_AUTH_KEY')]];
            }else {
                //读取数据库模块列表生成菜单项
                $node =  M("Node");
				$RoleUser = M("RoleUser");
				$map["user_id"] = array("eq",$_SESSION["userid"]);
				$Role = $this->StringChangeArray($RoleUser->where($map)->getField("role_id"));
				if(empty($Role) && $_SESSION["authId"]!= 3)
				{
				    $this->error("你没有权限");
				}
				$where['status']=1;
				$where['pid'] = 0;
			if($_SESSION["authId"] == 3)
			{
			     $list	=	$node->where($where)->field('id,name,title')->order('sort asc')->select();
				 foreach($list as $key=>$module) {
                     
                        //设置模块访问权限
                        $module['access'] =   1;
                        $menu[$key]  = $module;
						$where['pid'] = $module["id"];
						$child = $node->where($where)->field('id,name,title')->order('sort asc')->select();
						array_push($menu[$key],$child);
                                             
                                                    }
			}else
			{
                $list	=	$node->where($where)->field('id,name,title')->order('sort asc')->select();
			    $accessList = $_SESSION['_ACCESS_LIST'];
                foreach($Role as $value)
				{
				     foreach($list as $key=>$module) {
                     if($value == $module["id"]) {
                        //设置模块访问权限
                        $module['access'] =   1;
                        $menu[$key]  = $module;
					    //新建数组
						
						$where['pid'] = $module["id"];
						$child = $node->where($where)->field('id,name,title')->order('sort asc')->select();
						array_push($menu[$key],$child);
                                               }
                                                       }
				}
			}
                //缓存菜单访问
                $_SESSION['menu'.$_SESSION[C('USER_AUTH_KEY')]]	=	$menu;
            }
		}
		//dump($menu);
		$this->assign("menu",$menu);
		$this->display();
	}
	   //将字符串转换成数组
	protected function StringChangeArray($string)
	{
	   if(is_string($string))
	   {
	       $array = explode("|",$string);
	   }
	     return $array;
	}
	
	public function main()
	{
	   $category = M("category");
	  $map["parentid"] = array("eq","0");
	  $map["del"] = array("eq","0");
	  $category = $category->where($map)->field("id,name")->findall();
	  $this->assign("category",$category);
	  $this->assign("newsid",c('0.newid'));
	  $this->assign("categoryid",c('0.categoryid'));
	  $this->assign("subjectid",c('0.subjectid'));
      $this->display();
	}
	public function _default()
	{
	   $this->display();
	}
	
}
?>