<?php
require_once(dirname(__FILE__)."/config.php");
require_once(dirname(__FILE__)."/../include/pub_datalist_dm.php");
setcookie("ENV_GOBACK_URL",$dedeNowurl,time()+3600,"/");
CheckPurview('story_list');
if(!isset($action)) $action = '';
if(!isset($catid)) $catid = 0;
if(!isset($keyword)) $keyword = "";
if(!isset($orderby)) $orderby = 0;
if(!isset($ischeck)){
	$ischeck = 0;
}
if(!isset($cid)){
	$cid = 0;
}
$dsql = new DedeSql(false);

if($action == 'checked'){
	 $id = intval($id);
	 $dsql->setquery("update #@__story_books set ischeck=1 where id=$id");
	 if($dsql->executenonequery()){
	 	showmsg('审核成功','story_books.php');
	 	exit();
	}else{
	 	showmsg('审核失败','story_books.php');
	 	exit();
	}


}


//读取所有栏目
$dsql->SetQuery("Select id,classname,pid,rank From #@__story_catalog order by rank asc");
$dsql->Execute();
$ranks = Array();
$btypes = Array();
$stypes = Array();
while($row = $dsql->GetArray()){
	if($row['pid']==0) $btypes[$row['id']] = $row['classname'];
	else $stypes[$row['pid']][$row['id']] = $row['classname'];
	$ranks[$row['id']] = $row['rank'];
}

$addquery = "";
if($ischeck == 1){
	$addquery .= " and ischeck=0 ";
}
$orderby = " order by b.id desc ";
if($catid!=0) $addquery .= " And (b.bcatid='$catid' Or b.catid='$catid') ";
if($keyword!="") $addquery .= " And (b.bookname like '%$keyword%' Or b.author like '%$keyword%') ";

$query = "
   Select b.id,b.catid,b.bookname,b.booktype,b.litpic,b.ischeck,b.postnum,b.senddate,c.id as cid,c.classname From #@__story_books b
   left join #@__story_catalog c on c.id = b.catid where b.id>0 $addquery $orderby
";

//echo $query;

$dlist = new DataList();
$dlist->pageSize = 20;
$dlist->SetParameter("keyword",$keyword);
$dlist->SetParameter("catid",$cid);
$dlist->SetParameter("orderby",$orderby);
$dlist->SetSource($query);
include(dirname(__FILE__)."/templets/story_books.htm");
$dlist->Close();

ClearAllLink();
?>