<?php
// 本文档自动生成，仅供测试运行
class IndexAction extends Action
{
   function _initialize() {
    //读取配置文件
				   $config = M("config");
				   $config = $config->limit(1)->order("id desc")->findall();
				   C($config);
   }
    public function index() {
	    $this->nav();
		$category = M("category");
		$map["del"] = array("eq","0");
		$map["parentid"] = array("eq",c("0.newid"));
		$data = $category->where($map)->field("id")->select();
		//定义新闻存储栈
		$news = array();
		foreach($data as $key=>$value)
		{  
		   //$news.$value["id"] = array();
		   
		   $news[$value["id"]] = $this->getNews($value["id"]);
		   //"news".$key = $this->getNews($value["id"]);
		   //dump($value["id"]);
		   //array_push($news,$newskey);
		}
		
		$this->assign("news",$news);
		$notice = $this->getNews(7,4);
		$Topic = $this->getTopic(31,3);
		$Subject = $this->getSubject();
		$this->assign("topic",$Topic);
		$this->assign("notice",$notice);
		$this->friendship();
		$this->display();
    }
//获取友情链接
   public function friendship()
   {
     $friendship = M("friendship");
	 $map["del"] = array("eq","0");
	 $map["show"] = array("eq","1");
	 $array = $friendship->where($map)->field("url,name")->order("sort desc")->select();
	 $this->assign("friendship",$array);
   } 
   
   
    public function Clist()
	{
	    $Classid = $_GET["id"];
		if(!is_numeric($Classid))
		{
		   $this->error("参数错误");
		}
		$this->assign("CategoryNum",$Classid);
		$CategoryName = getCategoryName($Classid);
		$this->assign("CategoryName",$CategoryName);
	    $this->assign("NewsId","25");
	    $news = M("news");
	    $map["del"] = array("eq","0");
		$map["category"] = array("eq",$Classid);
	    import("@.ORG.Page");       //导入分页类
		$count = $news->where($map)->count();    //计算总数
		$p = new Page ( $count, 10 );
		$data = $news->limit($p->firstRow.','.$p->listRows)->where($map)->order("id desc")->findall();
		$p->setConfig('header','篇文章');
		$page = $p->show ();            //分页的导航条的输出变量
		$this->assign( "page", $page);
	    $this->assign("data",$data);
	    $this->nav();
           $this->friendship();
	   $this->display();
	}
	//新闻栏目和状态栏目
	public function dlist($num='4')
	{
	    $this->nav();
	    $Classid = $_GET["id"];
	    if(!is_numeric($Classid))
		{
		   $this->error("参数错误");
		}else
		{
		  //获取子目录
		  $Category = M("category");
		  $news = M("news");
		  $map["del"] = array("eq","0");
		  $map["parentid"] = array("eq",$Classid);
		  $child = $Category->where($map)->order("sort asc")->field("id,name")->findall();
		  foreach($child as $key=>$value)
		  { 
		     $maps["category"] = array("eq",$value["id"]);
		     $data = $news->where($maps)->order("id desc")->limit($num)->field("id,title,times")->findall();
		     if(empty($data))
			 {
			    $data = array("0"=>array("title"=>"没有"));
			 }
			 $array[$value["id"]] = $data;
		  }
		}
		$this->assign("array",$array);
		$CategoryName = getCategoryName($Classid);
		$this->assign("CategoryName",$CategoryName);
	    $this->assign("NewsId","25");
            $this->friendship();
		//dump($array);
		$this->display();
	}
	
    public function verify() {
        $type = isset($_GET['type']) ? $_GET['type'] : 'gif';
        import("@.ORG.Image");
        Image::buildImageVerify(4, 1, $type);
    }
	//登陆
	
	//导航
	public function nav()
	{
	    $category = M("category");
		$map["del"] = array("eq",0);
		$map["parentid"] = array("eq",0);
		$map["umen"] = array("eq",1);
		//申请新节点
		$array = array();
		$nav =  $category->where($map)->order("sort asc")->field("id,url,name")->select();
	    foreach($nav as $value)
		{
		    $maps["del"] = array("eq",0);
			$maps["parentid"] = array("eq",$value["id"]);
			$array[$value["id"]] =  $category->where($maps)->order("sort asc")->limit(6)->field("url,name,id")->select();
		}
		$this->assign("nav",$array);
		$this->assign("fnav",$nav);
	}
	//获取文章
	public function getNews($Categoryid,$num='4')
	{
	   
	    $name = $this->getCategoryName($Categoryid);
		$data = $this->getTitle($Categoryid,$num);
	    return (array($name,$data));
		
	}
	//获取专业栏目
	public function getTopic($Categoryid,$num='3')
	{
	    $name = $this->getCategoryName($Categoryid);
		$data = $this->getChild($Categoryid,$num);
	    return array($name,$data);
	}
	//获取工程业绩
	public function getSubject($num='4')
	{
		$data = $this->getTitles($num);
	    return $data;
	}
	//获取子栏目
	public function getChild($categoryid,$num)
	{
	   $Category = M("category");
	   $map["del"] = array("eq","0");
	   $map["parentid"] = array("eq",$categoryid);
	   $data = $Category->where($map)->order("sort desc")->field("name,url,id")->select();
	    if(empty($data))
	  {
	     $data = array(array("title"=>"没有"));
	  }	
	     return $data;
	}
	//文章预览
	public function article()
	{
	     $id = $_GET["id"];
	    if(!is_numeric($id))
	   {
	      $this->error("参数错误");
	   }
	   else
	   {
	      $news = M("news");
		  $map["del"] = array("eq",0);
		  $map["id"] = array("eq",$id);
		  $data = $news->where($map)->select();
		  if(empty($data))
		  {
		     $this->error("参数错误");
		
		  }else
		  {
		     $this->assign("data",$data);
		  }
	   }
	   $this->nav();
	   //$CategoryName = $this->getCategoryName($_GET["id"]);
	  // $this->assign("CategoryName",$CategoryName);
$this->friendship();
	   $this->display();
	}
	//获取栏目名称
	public function getCategoryName($id)
	{
	   if(!is_numeric($id))
	   {
	      $this->error("参数错误4");
	   }
	   else
	   {
	      $category = M("category");
		  $map["del"] = array("eq",0);
		  $map["id"] = array("eq",$id);
		  $Name = $category->where($map)->getField("name");
		  if(empty($Name))
		  {
		     $this->error("参数错误");
			 exit;
		  }else
		  {
		     return $Name;
		  }
	   }
	}  
	//获取新闻条数
	public function getTitle($id,$num='5')
	{
      $news = M("news");
      $map["del"] = array("eq",0);
      $map["category"] = array("eq",$id);
      $data = $news->where($map)->limit($num)->order("id desc")->field("title,id,times")->select();
      if(empty($data))
	  {
	     $data = array(array("title"=>"没有"));
	  }	
	     return $data;
	}
	//获取工程业绩
	public function getTitles($num='4')
	{
	  $honor = M("honor");
      $map["del"] = array("eq",0);
      $data = $honor->where($map)->limit($num)->order("id desc")->field("name,images")->select();
      if(empty($data))
	  {
	     $data = array(array("title"=>"没有"));
	  }	
	     return $data;
	}
	//判断是不是数字
	public function is_num($value)
	{
	   return $value;
	}
	
	//数据处理成功
	public function result($data,$mes='')
	{
	  
	}
	
}
?>