<?php
require("../../e/class/connect.php");
require("../../e/class/userfun.php");
require("../../e/class/q_functions.php");
require("../../e/class/db_sql.php");
/*
 * 数据库操作
 */
$link=db_connect();
$empire=new mysqlquery();

// die();
$act=trim($_GET['act']);

$titleadd = '';
$whereadd = "";

//搜素新闻
$keyboards = $_GET['keyboard'];


//获取page分页参数
$page=(int)RepPIntvar($_GET['page']);
if($page<=0) $page=1;
$newstype=(string)$_GET['newstype'];
$classid = 7;//新闻栏目

$year=(int)$_GET['year'];

if($keyboards != ""){
	$newstype = '';
}


//获取新闻类型
$newstypeInfo = $empire->fetch1("select fvalue from {$dbtbpre}enewsf where f='newstype' limit 1");
$newstypeList = explode("|",$newstypeInfo['fvalue']);
foreach($newstypeList as $newstypeK => $newstypeV){
	$newstypeList[$newstypeK] = explode("==",$newstypeV);
}

// print_r($newstypeList);
// $classid = (int)RepPostVar($_GET['classid'])?(int)RepPostVar($_GET['classid']):109;
/*
 * 标题关键词
 */
$class = $empire->fetch1("select c.classid,c.classname,c.classpagekey,c.intro,n.seotitle,n.banner from {$dbtbpre}enewsclass c,{$dbtbpre}enewsclassadd n where c.classid=n.classid and c.classid = 7 limit 1");
//标题
if($page)
	$thispagetitle = $class['seotitle']."第".($page+1)."页";
else
	$thispagetitle = $class['seotitle'];
$thispagetitle = $titleadd.$thispagetitle;
$keyboard = $class['classpagekey'];//关键词
$intro = $class['intro'];//描述
if($keyboard!= ''){
	$thispagetitle = $keyboard." | ".$thispagetitle;
}

$whereadd = " and 1=1 ";


// print_r($class);
$whereadd = " and 1=1 ";



//新闻类型
if($newstype != ""){	
	$whereadd .= " and newstype='".$newstype."' ";

	$url = "/news/".$newstype;
}

//新闻发布时间
if($year != "")	{
	// 获取一年的第一天
	$startOfYear = strtotime($year . '-01-01 0:0:0');

	// 获取一年的最后一天
	$endOfYear = strtotime($year . '-12-31 23:59:59');

	$whereadd .= " and (newstime BETWEEN '".$startOfYear."' and  '".$endOfYear."' )";

	$url = "/news/".$year;
}

//搜索关键词
if($keyboards != ""){	
	$whereadd .= " and title like '%".$keyboards."%' ";
	$search = "?keyboard=".$keyboards;

	$url = "/news/search";
}


// echo $whereadd;

//执行
$line=9;//显示多少条数据
// $page_line=10;
$start=0;


//分页
$offset=($page-1)*$line;
$num=$empire->gettotal("select count(id) as total from {$dbtbpre}ecms_news where classid=".$classid." $whereadd");
// $query="select id,company_log,establishDate,state,company_name,score,mechanism_id,tsl,yhf,ywc from {$dbtbpre}platform_lists".$where;
// $query.=" order by $order limit $offset,$line";

$query ="select * from {$dbtbpre}ecms_news where classid=".$classid." $whereadd order by newstime desc limit $offset,$line";

// echo $query;
$sql_all=$empire->query($query);
// print_r($sql_all);die();
// echo "select count(id) as total from {$dbtbpre}ecms_news where classid=".$classid." $whereadd";
// echo $num."<br>";
// echo $line;
// die();
if($num % $line == 0){
	$totalpage=ceil($num/$line);
}else{
	$totalpage=intval($num/$line)+1;
}
if($page>=$totalpage) $page = $totalpage;

if($num>0){
	$returnpage=page_list_2($num,$totalpage,$page,$search,$url);
}

//导入模板
require(ECMS_PATH.'/api/news/template/index.php');
db_close();
$empire=null;