<?php
/*
　* @$Id
　* @
　* @Ver: 1.0
　* @Create: 2009-04-01 8:10
　* @Modify: 
　* @Author: CPWEB http://www.zilaiye.org
　* @Copyright (C) 2008 www.zilaiye.org. All Rights Reserved.
　* @License CPWEB is free software and use is subject to license terms
　*/
class IndexAction extends GlobalAction 
{
	public $INDEX=array();
	public function Index(){
		//加载首页设置
		$index_set=$this->cpweb_setall('index_set');
		foreach ($index_set AS $key ){
			$this->INDEX[$key['title']]=$key['set_values'];
		}
		//启用首页简单模式
		if($this->INDEX['index_simple']=='1'){
			$this->cpweb_find();
			$this->model='Channel';
			$this->cpweb_find['map']['Type.type_values']='model';
			$this->cpweb_find['assign']['open']=true;
			$this->cpweb_page=false;
			$this->cpweb_find['page']['value']=false;
			$this->cpweb_model='model';
			$this->cpweb_find['view']='View';
			$this->cpweb_find['limit']='';
			$this->channel['id']='';
			$this->cpweb_list();
			if($this->cpweb_find['assign']['value']['list']){
				foreach($this->cpweb_find['assign']['value']['list'] AS $key => $value){
					$this->channelview($value);
				}
			}
		}
		//启用首页豪华模式
		if($this->INDEX['index_luxurious']=='1'){
			$this->cpweb_find();
			$this->model='Category';
			$this->cpweb_find['assign']['open']=true;
			$this->cpweb_page=false;
			$this->cpweb_find['page']['value']=false;
			$this->cpweb_find['view']='View';
			$this->cpweb_find['limit']='';
			$this->channel['id']='';
			$this->cpweb_find['order']='';
			$this->cpweb_list();
			$c=$this->cpweb_category_list_a();
			if($c){
				foreach ($c AS $key => $value){
					$this->categoryview($value);
				}
			}
		}
		//加载模块内容
		$this->model='Model';
		$this->cpweb_find['map']['Type.type_values']='module';
		$this->cpweb_find['assign']['open']=true;
		$this->cpweb_page=false;
		$this->cpweb_find['page']['value']=false;
		$this->cpweb_model=false;
		$this->cpweb_find['order']='id desc';
		$this->cpweb_find['view']='View';
		$this->cpweb_find['limit']='';
		$this->cpweb_list();
		if($this->cpweb_find['assign']['value']['list']){
			foreach ($this->cpweb_find['assign']['value']['list'] AS $key => $value){
				$this->channel($value);
			}
		}
		//显示产品分类
		$ChannelView=D('ChannelView');
		//加载栏目信息，按栏目加载分类内容
		$ChannelViewMap['type_values']='model';
		$channelview=$ChannelView->where($ChannelViewMap)->findall();
		if($channelview){
			$CategoryView=D('CategoryView');
			for($id=0;$id<count($channelview);$id++)
			{
				$CategoryViewMap['channel_id']=$channelview[$id]['id'];
				$categoryview=$CategoryView->where($CategoryViewMap)->findall();
				$this->assign('c_list_'.$channelview[$id]['folder'],$categoryview);
			}
		}
		if(ACTION_NAME!='index'){
			$this->assign('action',ACTION_NAME);
		}
		$this->cpweb_display('Index:index');
	}
	public function channelview($i){
		if($this->INDEX['index_'.strtolower($i['address'])] != '0'){
			$this->cpweb_find();
			$this->model=$i['address'];
			$this->cpweb_find['assign']['open']=true;
			$this->cpweb_page=false;
			$this->cpweb_model='model';
			$this->cpweb_find['view']='View';
			if($this->INDEX['index_'.strtolower($i['address'])] == '-1'){
				$this->cpweb_find['limit']='';
			}else{
				$this->cpweb_find['limit']=$this->INDEX['index_'.strtolower($i['address'])];
			}
			$this->channel['id']=$i['id'];
			$this->cpweb_find['order']=$i['address'].'.istop desc,'.$i['address'].'.id desc';
			$this->cpweb_list();
			$this->assign($i['address'].'_list_'.$i['folder'],$this->cpweb_find['assign']['value']['list']);
		}
	}
	public function channel($i){
		if($this->INDEX['index_'.strtolower($i['address'])] != '0'){
			if($this->INDEX['index_'.strtolower($i['address'])] == '-1'){
				$limit='';
			}else{
				$limit=$this->INDEX['index_'.strtolower($i['address'])];
			}
			$List=M($i['address']);
			$list=$List->where($map)->limit($limit)->order('id desc')->findAll();
			$this->assign($i['address'].'_list',$list);
		}
	}
	public function categoryview($i){
		if($this->INDEX['index_'.strtolower($i['address'])] != '0'){
			$this->cpweb_find();
			$this->model=$i['address'];
			$this->cpweb_find['assign']['open']=true;
			$this->cpweb_page=false;
			$this->cpweb_model='model';
			$this->cpweb_find['view']='View';
			$this->cpweb_find['category']=$i['id'];
			if($this->INDEX['index_'.strtolower($i['address'])] == '-1'){
				$this->cpweb_find['limit']='';
			}else{
				$this->cpweb_find['limit']=$this->INDEX['index_'.strtolower($i['address'])];
			}
			$this->channel['id']=false;
			$this->cpweb_find['order']=$i['address'].'.istop desc,'.$i['address'].'.id desc';
			$this->cpweb_list();
			$this->assign('c'.'_list_'.$i['id'],$this->cpweb_find['assign']['value']['list']);
		}
	}
}
?>