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

$GuideFidStr="<a href='wapindex.php'>首页</a>";
$SQL="WHERE yz=1 ";

unset($listmorsort);
if($fid){
	$fidDB=$db->get_one("SELECT S.*,M.alias AS M_alias,M.config AS M_config,M.iftable FROM {$pre}sort S LEFT JOIN {$pre}article_module M ON S.fmid=M.id WHERE S.fid='$fid'");
	if(!$fidDB){
		showerr("栏目ID有误");
	}
	check_fid($fidDB);
	if($fidDB[type]&&$Fid_db[$fid]){
		$GuideFidStr.=" -&gt; <a href='waplist.php?fid=$fid'>$fidDB[name]</a>";
		$listmorsort.="<ul class=listmorsort>\r\n";
		$query = $db->query("SELECT * FROM {$pre}sort WHERE fup=$fid AND fmid=0");
		while($rs = $db->fetch_array($query)){
			$listmorsort.="<li><a href=\"waplist.php?fid=$rs[fid]\">{$rs[name]}</a></li>\r\n";
		}
		$listmorsort.="</ul>\r\n";
		$fids=$fid.GetAllSonFid($fid); 
		$SQL.="AND fid IN ($fids)";
	}elseif(!$fidDB[type]){
		if($Fid_db[name][$fidDB[fup]]){
			/*$listmorsort.="<ul class=listmorsort>\r\n";
			$query = $db->query("SELECT * FROM {$pre}sort WHERE fup='$fidDB[fup]' AND fmid=0");
			while($rs = $db->fetch_array($query)){
				$ckclass=($fid==$rs[fid])?"class='ck'":"";
				$listmorsort.="<li><a href=\"waplist.php?fid=$rs[fid]\" $ckclass>{$rs[name]}</a></li>\r\n";
			}
			$listmorsort.="</ul>\r\n";*/
			$GuideFidStr.=" -&gt; <a href='waplist.php?fid=$fidDB[fup]'>{$Fid_db[name][$fidDB[fup]]}</a> -&gt; <a href='waplist.php?fid=$fid'>$fidDB[name]</a>";
		}else{
			$GuideFidStr.=" -&gt; <a href='waplist.php?fid=$fid'>$fidDB[name]</a>";
		}
		$SQL.="AND fid='$fid'";
	}
}
if($keyword){
	$SQL.="AND title LIKE '%$keyword%'";
	$GuideFidStr.=" -&gt; 内容搜索";
}

$page||$page=1;
$rows=10;
$min=($page-1)*$rows;

unset($listtitle);
$query = $db->query("SELECT * FROM {$pre}article $SQL ORDER BY aid DESC LIMIT $min,$rows");
while($rs = $db->fetch_array($query)){
	$listdb[]=$rs;
	$listtitle.="<li><a href=\"wapbencandy.php?fid=$rs[fid]&id=$rs[aid]\">{$rs[title]}</a></li>\r\n";
}

if($job=='showmore'){
	$listtitle=$listtitle?$listtitle:"nodate";
	die($listtitle);
}

$showMoreSort=1;

require(html('waplist'));
/**
*栏目配置文件检查
**/
function check_fid($fidDB){
	global $web_admin,$groupdb,$fid;
	if(!$fidDB){
		showerr("栏目不存在");
	}
	//跳转到外部地址
	if( $fidDB[jumpurl] ){
		header("location:$fidDB[jumpurl]");
		exit;
	}
	//栏目密码
	if( $fidDB[passwd] ){
		if( $_POST[password] ){
			if( $_POST[password] != $fidDB[passwd] ){
				echo "<A HREF=\"?fid=$fid\">密码不正确,点击返回</A>";
				exit;
			}
			else{
				setcookie("sort_passwd_$fid",$fidDB[passwd]);
				$_COOKIE["sort_passwd_$fid"]=$fidDB[passwd];
			}
		}
		if( $_COOKIE["sort_passwd_$fidDB[fid]"] != $fidDB[passwd] ){
			echo "<CENTER><form name=\"form1\" method=\"post\" action=\"\">请输入栏目密码:<input type=\"password\" 	name=\"password\"><input type=\"submit\" name=\"Submit\" value=\"提交\"></form></CENTER>";
			exit;
		}
	}
	if( $fidDB[allowviewtitle] || $fidDB[allowviewcontent] ){
		if(!$web_admin&&!in_array($groupdb[gid],explode(",","$fidDB[allowviewtitle],$fidDB[allowviewcontent]"))){
			showerr("你所在用户组不允许浏览标题");
		}
	}
}
function GetAllSonFid($fid){
	global $Fid_db;
	$fid=intval($fid);
	foreach($Fid_db[$fid] AS $key=>$value){
		$show.=",$key";
		$show.=GetAllSonFid($key);
	}
	return $show;
}
?>