<?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;


$dsql = new DedeSql(false);
//¶ÁÈ¡ËùÓÐÀ¸Ä¿
$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 = "";
$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.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();
$dsql->Close();
?>