<?php
 require("CommonAction.class.php");
 class EngineerAction extends CommonAction
 {
   //工程说明
   public function index()
   {
      $award_num = $this->getTableNum("award_type");
      $industry_num = $this->getTableNum("industry");
	  $award_data = $this->getTableData("award_type");
	  $industry_data = $this->getTableData("industry");
	  $this->assign("award_data",$award_data);
	   $this->assign("industry_data",$industry_data);
	  $this->assign("award_num",$award_num);
	  $this->assign("industry_num",$industry_num);
	  $this->display();
   }
   //企业资质
   public function qualification()
   {
       //获取资质类型
	   $map["del"] = array("eq",0);
       $qualification = M("qualification");  
	   import("@.ORG.Page");       //导入分页类
	   $count = $qualification->where($map)->count();    //计算总数
	   $p = new Page ( $count, c("0.num") );
	   $data = $qualification->limit($p->firstRow.','.$p->listRows)->where($map)->order("category asc,id desc")->findall();
       $p->setConfig('header','个社会荣誉');
	   $page = $p->show ();            //分页的导航条的输出变量
	   $this->assign( "page", $page);
	   $this->assign("data",$data);
      $this->display();
   }
   //修改资质
   public function qualificationedit()
   {
       if(!is_numeric($_GET["id"]))
	   {
	       $this->error("没有注入点谢谢");
		   exit;
	   }
	   $map["id"] = array("eq",$_GET["id"]);
	   $qualification = M("qualification");
	   $data = $qualification->where($map)->findall();
	   $maps["id"] = array("eq","29");
	   $category = M("category");
 	   $categoryData = $category->where($maps)->field("id,name")->select();
	   $this->assign("categoryData",$categoryData);
	   $this->assign("data",$data);
	   $this->display();
   }
   public function qualificationAdd()
   {
       $category = M("category");
       $map["del"] = array("eq",0);
	   $map["id"] = array("eq","29");
 	   $categoryData = $category->where($map)->field("id,name")->select();
	   $this->assign("categoryData",$categoryData);
       $this->display();
   }
   //添加社会荣誉
   public function q_add()
   {
        
      	 import("@.ORG.UploadFile");
        //导入上传类
        $upload = new UploadFile();
        //设置上传文件大小
        $upload->maxSize = c('0.uploadMax')*1024*1024;
        //设置上传文件类型
        $upload->allowExts = explode(',', 'jpg,gif,png,jpeg');
        //设置附件上传目录
        $upload->savePath = './Uploads/';
        //设置需要生成缩略图，仅对图像文件有效
        $upload->thumb = true;
        // 设置引用图片类库包路径
        $upload->imageClassPath = '@.ORG.Image';
        //设置需要生成缩略图的文件后缀
        $upload->thumbPrefix = 'b_,s_';  //生产2张缩略图
        //设置缩略图最大宽度
        $upload->thumbMaxWidth = '1600,147';
        //设置缩略图最大高度
        $upload->thumbMaxHeight = '1149,215';
        //设置上传文件规则
        $upload->saveRule = 'uniqid';
        //删除原图
        $upload->thumbRemoveOrigin = true;
        if (!$upload->upload()) {
            //捕获上传异常
             $this->error($upload->getErrorMsg());
       }else {
           //取得成功上传的文件信息
           $uploadList = $upload->getUploadFileInfo();
           $_POST['b_images'] = "__APP__/Uploads/b_".$uploadList[0]['savename'];
           $_POST['s_images'] = "__APP__/Uploads/s_".$uploadList[0]['savename'];
            }
      	 $dao = D("admin.qualification");
		 if ($dao->create()) {
            if (false !== $dao->add()) {
			    $this->assign("jumpUrl",__URL__."/qualification");
                $this->success('数据添加成功！');
            } else {
			    $this->assign("jumpUrl",__URL__."/qualification");
                $this->error('数据写入错误');
            }
        } else {
            // 字段验证错误
            $this->error($dao->getError());
        }
   }
   //修改社会荣誉
   public function q_update()
   {
     $map["id"] = array("eq",$_GET["id"]);
     //判断图片有没有更新
       if($_FILES['images']['size'])
	   {
	    import("@.ORG.UploadFile");
        //导入上传类
        $upload = new UploadFile();
        //设置上传文件大小
        $upload->maxSize = c('0.uploadMax')*1024*1024;
        //设置上传文件类型
        $upload->allowExts = explode(',', 'jpg,gif,png,jpeg');
        //设置附件上传目录
        $upload->savePath = './Uploads/';
        //设置需要生成缩略图，仅对图像文件有效
        $upload->thumb = true;
        // 设置引用图片类库包路径
        $upload->imageClassPath = '@.ORG.Image';
        //设置需要生成缩略图的文件后缀
        $upload->thumbPrefix = 'b_,s_';  //生产2张缩略图
        //设置缩略图最大宽度
        $upload->thumbMaxWidth = '1600,147';
        //设置缩略图最大高度
        $upload->thumbMaxHeight = '1149,215';
        //设置上传文件规则
        $upload->saveRule = 'uniqid';
        //删除原图
        $upload->thumbRemoveOrigin = true;
        if (!$upload->upload()) {
            //捕获上传异常
             $this->error($upload->getErrorMsg());
       }else {
           //取得成功上传的文件信息
           $uploadList = $upload->getUploadFileInfo();
           $data['b_images'] = "__APP__/Uploads/b_".$uploadList[0]['savename'];
           $data['s_images'] = "__APP__/Uploads/s_".$uploadList[0]['savename'];
            }
	   }
	   else
	   {
	      $data['name'] = trim($_POST['name']);
		  $data['times'] = trim($_POST['times']);
		  $data['category'] = trim($_POST['category']);
		  $dao = M("qualification");
		  if ($dao->where($map)->save($data)) {
			    $this->assign("jumpUrl",__URL__."/qualification");
                $this->success('数据更新成功！');
            } else {
			    $this->assign("jumpUrl",__URL__."/qualification");
                $this->error('数据更新错误');
            }
	   }
   }
   //修改工程
   public function awardedit()
   {
        $id = $_GET["id"];
	    $dao = M("honor");
		$maps["id"] = array("eq",$_GET["id"]);
		$maps["del"] = array("eq","0");
		$data = $dao->where($maps)->findall();
		$this->assign("data",$data);
	    $industry = M("industry");
	  $map["del"] = array("eq","0");
	  $industry_data = $industry->where($map)->findall();
	  $award_type = M("award_type");
	  $type = $award_type->where($map)->findall();
	  $this->assign("industry_data",$industry_data);
	  $this->assign("award_type",$type);
		$this->display();
   }
   //获取工程
   public function award()
   {
	    $honor = M("Honor");
	    $map["del"] = array("eq","0");
	    import("@.ORG.Page");       //导入分页类
		$count = $honor->where($map)->count();    //计算总数
		$p = new Page ( $count, c("0.num") );
		$data = $honor->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->display();
   }
 
   //添加获奖工程
   public function awardAdd()
   {
      $industry = M("industry");
	  $map["del"] = array("eq","0");
	  $industry_data = $industry->where($map)->findall();
	  $award_type = M("award_type");
	  $type = $award_type->where($map)->findall();
	  $this->assign("industry_data",$industry_data);
	  $this->assign("award_type",$type);
      $this->display();
   }
    //获取当前栏目的个数
	 private function getTableNum($table)
	 {
	     $category = M($table);
		 $map["del"] = array("eq",0);
		 $num = $category->where($map)->count();
		 return $num;
	 }
	 //获取数据
	 private function getTableData($table)
	 {
	     $category = M($table);
		 $map["del"] = array("eq",0);
		 $data = $category->where($map)->order("id desc")->findall();
		 return $data;
	 }
	 //添加荣誉
	 public function addHonor()
	 {
      	$dao = D("admin.honor");
		$_POST["images"] = __APP__."/public".$_POST["images"];
		 if ($dao->create()) {
            if (false !== $dao->add()) {
			    $this->assign("jumpUrl",__URL__."/award");
                $this->success('数据添加成功！');
            } else {
			    $this->assign("jumpUrl",__URL__."/award");
                $this->error('数据写入错误');
            }
        } else {
            // 字段验证错误
            $this->error($dao->getError());
        }
	}
	//更新荣誉
	public function UpdateHonor()
	{
	    if(!is_numeric($_GET["id"]))
	   {
	       $this->error("没有注入点谢谢");
		   exit;
	   }
	   $map["id"] = array("eq",$_GET["id"]);
	   if( strlen($_POST["images"]) >= 25 )
	   {
	      //表示已经更新
		  $_POST["images"] = __APP__."/public".$_POST["images"];
	   }
	   $honor = M("honor");
	   $result = $honor->where($map)->save($_POST);
	   if($result)
	   {
	        $this->assign("jumpUrl",__URL__."/award");
            $this->success('荣誉更新成功！');
	   }
	   else
	   {
	     $this->assign("jumpUrl",__URL__."/award");
                $this->error('荣誉更新错误');
	   }
	}
	//资质管理
	public function zizhi()
	{
	   $zizhi = M("zizhi");
	   $map["del"] = array("eq","0");
	   $data = $zizhi->where($map)->order("id desc")->findall();
	   $this->assign("data",$data);
	   $this->display();
	}
	//添加资质
	public function zizhiadd()
	{
	   $this->display();
	}
	//资质更新
	public function updatezizhi()
	{
	   $id = $_GET["id"];
	    if(!is_numeric($id))
	   {
	       $this->error("参数不正确");
		   exit;
	   }
	   $map["id"] = array("eq",$id);
	   $zizhi = M("zizhi");
	   $result = $zizhi->where($map)->save($_POST);
	   if($result)
	   {
	            $this->assign("jumpUrl",__URL__."/zizhi");
                $this->success('数据更新成功！');
	   }
	   else {
			    $this->assign("jumpUrl",__URL__."/zizhi");
                $this->error('数据更新错误');
            }
	}
	public function addzizhi()
	{
	     $dao = D("admin.zizhi");
		 if ($dao->create()) {
            if (false !== $dao->add()) {
			    $this->assign("jumpUrl",__URL__."/zizhi");
                $this->success('数据添加成功！');
            } else {
			    $this->assign("jumpUrl",__URL__."/zizhi");
                $this->error('数据写入错误');
            }
        } else {
            // 字段验证错误
            $this->error($dao->getError());
        }
	}
	public function zizhiedit()
	{
	     if(!is_numeric($_GET["id"]))
	   {
	       $this->error("没有注入点谢谢");
		   exit;
	   }
	   $map["id"] = array("eq",$_GET["id"]);
	   $zizhi = M("zizhi");
	   $data = $zizhi->where($map)->findall();
	   $this->assign("data",$data);
	   $this->display();
	}
}

?>