<?php
  require("CommonAction.class.php");
  class CultureAction extends CommonAction{
   
      //PDF上传
	  public function pdf()
	  {
	     $category = M("category");
		 $maps["del"] = array("eq","0");
		 $maps["parentid"] = array("eq",c('0.categoryid'));
		 $categoryData = $category->where($maps)->order("id desc")->field("id,name")->select();
		 $this->assign("categoryData",$categoryData);
	     $this->display();
	  }
	  //上传处理
      public function upload()
	  {
		$pdf = D("admin.pdf");
		$_POST["fileaddr"] = __APP__."/public".$_POST["fileaddr"];
		if ($pdf->create()) {
            if (false !== $pdf->add()) {
			    $this->assign("jumpUrl",__URL__."/pdfmanage");
                $this->success('PDF添加成功！');
            } else {
			    $this->assign("jumpUrl",__URL__."/pdfmanage");
                $this->error('PDF添加错误');
            }
        } else {
            // 字段验证错误
            $this->error($news->getError());
        }
	  }
	  public function index()
	  {
	     $category = M('category');
	     $map['del'] = array('eq','0');
	     $map["parentid"] = array('eq','8');
	     $categoryData = $category->where($map)->field('id,name')->order('sort desc')->findall();
	     $this->assign('categoryData',$categoryData);
	     $this->assign('times',time());
	     $this->display("news/index");
	  }
	  //公司文化管理
	  public function lists()
	  {
	    $news = M("news");
		$category = M('category');
		import("@.ORG.Page");       //导入分页类
         //栏目栈
		$categorySt = array();	
		$map["del"] = array("eq","0");
		$mapd["parentid"] = array("eq",'8');
		$categoryCl = $category->where($mapd)->field('id,name')->order('sort desc')->findall();
		foreach($categoryCl as $value)
		{
		   array_push($categorySt,$value["id"]);
		}
		$map["category"] = array("in",$categorySt);
		$count = $news->where($map)->count();    //计算总数
		$p = new Page ( $count, c("0.num") );
		$data = $news->limit($p->firstRow.','.$p->listRows)->where($map)->field("id,title,tj,times,hits,top,flash,category")->order("id desc,del desc")->findall();
		
		$p->setConfig('header','篇新闻');
		$page = $p->show ();            //分页的导航条的输出变量
		$this->assign( "page", $page);
		$this->assign("data",$data);
		$this->assign("table","culture");
		$maps["del"] = array("eq","0");
		$categoryData = $category->where($maps)->field('id,name')->order('sort desc')->findall();
	    $this->assign('categoryData',$categoryData);
	    $this->display('news/lists');
	  }
	 //PDF管理 
	public function pdfmanage()
	{
	   $pdf = M("pdf");
	   $map["del"] = array("eq","0");
	   $data = $pdf->where($map)->order("id desc")->findall();
	   $this->assign("data",$data);
	   $this->assign("host",$_SERVER['HTTP_HOST']);
	   $this->display();
	}
	//pdf 修改
	public function pdfedit()
	{
	   if(!is_numeric($_GET["id"]))
	   {
	       $this->error("没有注入点谢谢");
		   exit;
	   }
	   $map["id"] = array("eq",$_GET["id"]);
	   $pdf = M("pdf");
	   $data = $pdf->where($map)->findall();
	   $this->assign("data",$data);
	   $category = M("category");
	   $maps["del"] = array("eq","0");
	    $maps["parentid"] = array("eq",c('0.categoryid'));
		$s = $this->getKeyWord();
		$maps = array_merge($maps,$s);
		 $categoryData = $category->where($maps)->order("id desc")->field("id,name")->select();
		 $this->assign("categoryData",$categoryData);
	   $this->display();
	}
	//确定修改
	public function updatePdf()
	{
	   if(!is_numeric($_GET["id"]))
	   {
	       $this->error("没有注入点谢谢");
		   exit;
	   }
	   $map["id"] = array("eq",$_GET["id"]);
	   if( strlen($_POST["fileaddr"]) >= 25 )
	   {
	      //表示已经更新
		  $_POST["fileaddr"] = __APP__."/public".$_POST["fileaddr"];
	   }
	   $pdf = M("pdf");
	   $result = $pdf->where($map)->save($_POST);
	   if($result)
	   {
	        $this->assign("jumpUrl",__URL__."/pdfmanage");
            $this->success('PDF更新成功！');
	   }
	   else
	   {
	     $this->assign("jumpUrl",__URL__."/pdfmanage");
                $this->error('PDF更新错误');
	   }
	}
	  
	 //添加新闻
	 public function addNews()
	 {
	    $news = D("admin.news");
		if ($news->create()) {
            if (false !== $news->add()) {
			    $this->assign("jumpUrl",__URL__."/lists");
                $this->success('新闻添加成功！');
            } else {
			    $this->assign("jumpUrl",__URL__."/category");
                $this->error('新闻添加错误');
            }
        } else {
            // 字段验证错误
            $this->error($news->getError());
        }
		
	 }
	//文章修改
	public function edit()
	{
	   $id=$_GET["id"];
	    if(!is_numeric($_GET["id"]))
	   {
	       $this->error("没有注入点谢谢");
		   exit;
	   }
	   $news = M("news");
	   $map["id"] = array("eq",$_GET["id"]);
	   $map["del"] = array("eq",0);
	   $data2 = $news->where($map)->select();
	   $category = M("category");
	   $maps["del"] = array("eq","0");
	   $data = $category->where($maps)->field("id,name")->select();
	   $this->assign("data",$data);
	   $this->assign("data2",$data2);
	   $this->display("news/edit");
	}
	//文章修改
	public function updateNews()
	{
	   if(!is_numeric($_GET["id"]))
	   {
	       $this->error("没有注入点谢谢");
		   exit;
	   }
	   $map["id"] = array("eq",$_GET["id"]);
	   $news = M("news");
	   $data = $_POST;
	   $data["content"] = strip($_POST["content"]);
	   $data["top"] = judge($_POST["top"]);
	   $data["tj"] = judge($_POST["tj"]);
	   $data["flash"] = judge($_POST["flash"]);
	   $data["times"] = time();
	   $result = $news->where($map)->save($data);
	   if($result)
	   {
	     $this->assign("jumpUrl",__URL__."/lists");
	     $this->success("新闻更新成功");
	   }
	   else
	   {
	    $this->assign("jumpUrl",__URL__."/lists");
	     $this->success("新闻更新失败");
	   }
	 } 
  }

?>