<?php
define('THIS_SCRIPT', 'show');
include_once 'global.php';
$lang = load_lang($lang, 'show' );
include_once CACHE_PATH.'Forum_Show_Cache.php';
$stats = $lang['template1'];//论坛标题;
if ( $boardid == 0 ){
	$arrNavMenu = array(
		0=>array('linktitle'=>$stats,'linkurl'=>'show.php')
	);
	head(1,0,0,$arrNavMenu);
}else{
	$gettitle = $stats;
	head();
}
PageLoad();
footer();
function PageLoad(){
	global $filetype,$lang,$fsetting,$CurrentPage,$PageNum,$totalrec,$star,$pagelistnum,$Pcount,$toback,$tonext,$userinfo,$search,$hot_list;
	global  $groupsetting,$new_list,$file_list,$tab,$maxpage,$boardid,$username,$send,$action,$title_num,$userid,$showfile,$vipuser;
	global $boardmaster,$superboardmaster,$master,$membername,$hot_boardid,$news_boardid,$upload_url,$forumshowcache;
	$upload_url=basename($fsetting['forumuploadname'])."/";
	if( $userid <= 0 ){//判断是否登录;
		showmsg($lang['Error.strings1']);
		exit;
	}
	if( $groupsetting[49] == 0 ){//判断是否有浏览权限;
		showmsg($lang['Error.strings1']);
		exit;
	}
	file_browse();
	include_once printout('show');//print show.htm;
}
function file_browse(){
	global $dv,$db,$lang,$file_list,$CurrentPage,$totalrec,$Pcount,$star,$pagelistnum,$toback,$tonext,$maxpage,$tab,$boardid,$username,$userinfo,$search,$_DCACHE;
	$file_list=array();
	$boardidzero="f_boardid=0";
	$search="";
	$filetype=intval($_POST['filetype']);
	if($filetype>6){
		$filetype=0;
	}
	if($filetype==''){
		$filetype=intval($_GET['filetype']);
	}
	if($username!=""){
	    $search.="f_username='".$username."' and ";
	}
	if(is_numeric(intval($filetype))){
		$search.="f_type=".$filetype." and ";
	}
	$search=($boardid!='')? $search.'f_boardid='.$boardid:substr($search,0,(strlen($search)-5));
	if(strpos($search,$boardidzero)!==false){
		$search=(intval(strlen($search))==11)? '':substr($search,0,(strlen($search)-15));
	}
	if($search==''){
		$totalrec=intval($db->scalar("select count(1) as col from {$dv}upfile where f_boardid!=0 and f_boardid!=444 and f_boardid!=777"));//得到总记录;
	}
	else {
		$totalrec=intval($db->scalar("select count(1) as col from {$dv}upfile where ".$search." and f_boardid!=0 and f_boardid!=444 and f_boardid!=777"));//得到总记录;
	}
	$userinfo=($username!='')? str_replace('{$alertcolor}',$_DCACHE['stylecss'][19],str_replace('{$username}',$username,$lang['template3'])):'';
	if($tab=="" or $tab==0)$tab=4;//分页部分;
	$maxpage=$tab*3;//每页显示6/9/12条信息,根据分成几列,默认16条信息;
	if ($maxpage < 1) {
		$maxpage = 16;
	}
	if ($_GET['star']=="" or $_GET['star']<=1){//当前页;
		$star=1;
	}
	else{
		$star=$_GET['star'];
		$toback=$star-1;
		$tonext=$star+1;
	}
	$Pcount=ceil($totalrec/$maxpage);//得到多少页;
	if ($star>$Pcount)$star=$Pcount;//如果当前页大于总数页时,当前页等于总数页;
	if($search==""){
		$sql="select f_id,f_boardid,f_announceid,f_viewname,f_filetype,f_filename,f_type,f_username,f_downnum,f_readme,f_viewnum from {$dv}upfile where f_boardid!=0 and f_boardid!=444 and f_boardid!=777 order by f_addtime desc";
		$countStmt = "SELECT COUNT(1) FROM {$dv}upfile where f_boardid!=0 and f_boardid!=444 and f_boardid!=777";
	}
	else {
		$sql="select f_id,f_boardid,f_viewname,f_announceid,f_filetype,f_filename,f_type,f_username,f_downnum,f_readme,f_viewnum from {$dv}upfile where ".$search." and f_boardid!=0 and f_boardid!=444 and f_boardid!=777 order by f_addtime desc";
		$countStmt = "SELECT COUNT(1) FROM {$dv}upfile where ".$search." and f_boardid!=0 and f_boardid!=444 and f_boardid!=777";
	}
	$pagelistnum=$db->scalar($countStmt);
	if($pagelistnum=="")$pagelistnum=0;
	$result=$db->query($sql,array('absolutePage'=>$star,'pageSize'=>$maxpage));
	while($file_arr=$db->fetch_array($result)){
		$file_list[]=$file_arr;
	}
	$db->free_result($result);
}
function mb_substrs($str,$start,$len=-1) {
	preg_match_all("/[\x80-\xff]?./",$str,$arr);
	if($len==-1) $len=sizeof($arr[0])-$start;
	return @implode(array_slice($arr[0],$start,$len),"");
}
?>