<?php
require_once(dirname(__FILE__)."/config.php");

if(!isset($cid)) $cid = 0;
if(!isset($keyword)) $keyword = "";
if(!isset($channelid)) $channelid = 0;
if(!isset($arcrank)) $arcrank = "";
if(!isset($adminid)) $adminid = 0;
if(!isset($ismember)) $ismember = 0;

//检查权限许可，总权限
CheckPurview('a_List,a_AccList,a_MyList');
//栏目浏览许可
if(TestPurview('a_List')){ ; }
else if(TestPurview('a_AccList')){
	 if($cid==0) $cid = $cuserLogin->getUserChannel();
	 else CheckCatalog($cid,"你无权浏览非指定栏目的内容！");
}else{
	 $adminid = $cuserLogin->getUserID();
}

////////////////////////////////////////////////////////////////////
require_once(dirname(__FILE__)."/../include/inc_typelink.php");
require_once(dirname(__FILE__)."/../include/pub_datalist_dm.php");
require_once(dirname(__FILE__)."/inc/inc_list_functions.php");
setcookie("ENV_GOBACK_URL",$dedeNowurl,time()+3600,"/");

$tl = new TypeLink($cid);

if($cid==0){
	if($channelid==0) $positionname = "所有栏目&gt;";
	else{
		$row = $tl->dsql->GetOne("Select typename From #@__channeltype where ID='$channelid'");
		$positionname = $row[0]."&gt;";
	}
}else{
	$positionname = str_replace($cfg_list_symbol,"&gt;",$tl->GetPositionName())."&gt;";
}

$seltypeids = 0;
if(!empty($cid)){
	$seltypeids = $tl->dsql->GetOne("Select ID,typename,channeltype From #@__arctype where ID='$cid' ");
}
$opall=1;
if(is_array($seltypeids)){
	$optionarr = GetTypeidSel('form3','cid','selbt1',0,$seltypeids['ID'],$seltypeids['typename']);
}else{
	$optionarr = GetTypeidSel('form3','cid','selbt1',0,0,'请选择...');
}


$whereSql = '';


if($ismember==1) $whereSql .= "And #@__infos.memberID > 0 ";

if(!empty($memberid)) $whereSql .= "And #@__infos.memberID = '$memberid' ";
else $memberid = 0;
if($arcrank!=""){
	$whereSql .= " And #@__infos.arcrank = '$arcrank' ";
	$CheckUserSend = "<input type='button' onClick=\"location='catalog_do.php?cid=".$cid."&dopost=listArchives';\" value='所有文档' class='inputbut'>";
}
else{
	$whereSql .= " And #@__infos.arcrank >-1 ";
	$CheckUserSend = "<input type='button' onClick=\"location='catalog_do.php?cid=".$cid."&dopost=listArchives&arcrank=-1';\" value='稿件审核' class='inputbut'>";
}
if($keyword!=""){
	$whereSql .= " And ( CONCAT(#@__infos.title,#@__infos.writer,#@__infos.source) like '%$keyword%') ";
}

if($cid!=0){
	$tlinkSql = $tl->GetSunID($cid,"#@__infos",0);
	$whereSql .= "And $tlinkSql ";
}
$whereSql = trim($whereSql);

if(eregi("^(And)",$whereSql))
{
$whereSql = substr($whereSql,3);

}
//exit;
$tl->Close();

if(empty($orderby)) $orderby = "ID";

$query = "
select #@__infos.*,#@__arctype.typename
from #@__infos
left join #@__arctype on #@__arctype.ID=#@__infos.typeid
where $whereSql
order by #@__infos.{$orderby} desc
";

$dlist = new DataList();
$dlist->pageSize = 20;
$dlist->SetParameter("dopost","listArchives");
$dlist->SetParameter("keyword",$keyword);
$dlist->SetParameter("adminid",$adminid);
$dlist->SetParameter("memberid",$memberid);
$dlist->SetParameter("cid",$cid);
$dlist->SetParameter("arcrank",$arcrank);
$dlist->SetParameter("channelid",$channelid);
$dlist->SetParameter("ismember",$ismember);
$dlist->SetParameter("orderby",$orderby);
$dlist->SetSource($query);
include(dirname(__FILE__)."/templets/info_list.htm");
$dlist->Close();

?>