<?php
/*
'#################################################################
'# 程序名称：中环CMSV2.0
'# 授权方式：免费软件
'# 作者：善
'# 联系QQ:9118847
'# 作者网站:http://www.ps173.com
'# 发布时间：2015-6-10
'# 声明：欢迎广大的PHP爱好者一起共同探讨
'# 声明：各种用途均可免费使用、自由传播，但必须保留程序代码中的版权信息。
'#################################################################
 */

//前台首页输出
class IndexAction extends CommonAction{

	public function index(){ 
		if(!$this->isCached()){
			$this->assign("new", $this->article->art_list("id, title, posttime", 12, array("views"=>0)));
			$this->assign("host", $this->article->art_list("id, title, posttime", 11, array("views"=>0), "count desc"));
			$this->assign("thumb_cent", $this->article->art_list("id, title, thumb", 4, array("views"=>0)));
			$this->assign("paly", $this->article->art_list("id, title, paly", 5, array('attr'=>"%大图%", "views"=>0)));
			$this->assign("head_list", $this->article->art_list("id, title, posttime", 9, array('attr'=>"%头条%", "views"=>0)));
			$this->assign("head_one", $this->article->art_list("id, title, info", 1, array('attr'=>"%头条%", "views"=>0)));
			$this->assign("reclist", $this->article->art_list("id, title, posttime", 13, array('attr'=>"%推荐%", "views"=>0)));
			$this->assign("fournav", $this->fournav());
			$this->assign("list", $this->nav->menu());
			$this->assign("info", $this->info());
			$this->assign("flink", $this->viewflink());
		}

		$this->assign("adver", $this->viewadver());
		$this->display();
	}

	public function search(){
		if(!empty($_POST['search'])){
			$sers = !empty($_POST['search']) ? $_POST : $_GET;
			$where = array($sers['sertype']=>"%{$sers["search"]}%", "views"=>0);

			$args = "sertype/{$sers["sertype"]}/search/{$sers["search"]}";
			$total = $this->article->arttotal($where);

			$size = $this->set->list_one("size");
			$page = new Page($total, $size['size'], $args);
			$this->assign("total", $total);
			$this->assign("all", $this->article->search($where, $page->limit));
			$this->assign("search", $sers['search']);
			$this->assign("page", $page->pageinfo());
		}else{
			$this->msg('请输入要搜索的内容');
		}

		$this->assign("adver", $this->viewadver());
		if(!$this->isCached()){
			$this->assign("flink", $this->viewflink());
			$this->assign("list", $this->nav->menu());
			$this->assign("info", $this->info());
			$this->assign("hostpid", $this->article->art_list("id, title, posttime", 10, array("views"=>0), "count desc"));
			$this->assign("books", $this->article->art_list("id, title, posttime", 10, array("views"=>0), "nums desc"));
		}
		$this->display();
	}

	private function fournav(){
		$nav = $this->nav->fournav();
		if(isset($nav)){
			$i = 1;
			$html = '';
			foreach($nav as $val){
				if($i++ % 2 == 0){
					$html .='<div class="news1 news3"><h2>'.$val['title'].'</h2>';
					$html .= $this->article->getart($val['id']);
					$html .='</div>';
				}else{
					$html .='<div class="news1"><h2>'.$val['title'].'</h2>';
					$html .= $this->article->getart($val['id']);
					$html .='</div>';
				}
				
			}
		}
		
		return $html;
	}


}

?>