<?php
define('CURSCRIPT', 'thread');
require_once './engine/common.inc.php';
require_once './engine/attachment.func.php';
require_once './clientdata/cache/cache_navigation.php';
require_once './engine/gateweicode.func.php';
$curpage=isset($page)?$page:1;
$ppp=5;//每页显示回复帖子数 postperpage
$floor=($curpage==1)?2:(($curpage-1)*$ppp+2);
$startrecord=($curpage-1)*5;
$q = $db->query("SELECT a.*, c.gid , c.userid , c.postcount , c.userface , c.registertime , b.content FROM g_thread_content b , g_threads a left join g_members c ON a.uid = c.uid  WHERE a.tid=$tid and a.tid = b.tid LIMIT 1");
	if(!$allthread=$db->fetch_array($q)){
			showmsg("主题不存在或未通过审核");
	};
	$view=++$allthread['view'];
	$forid=$allthread['forid'];
	@extract($forumcategory[$forid]);
	accessforum();
	$siteheadtitle=implode(' ',array($allthread['title'],$forumcategory[$forid]['forumtitle'],$forumname,$sitename,$sitekeywords));
	if(!$allthread['uid']){
		$allthread['gid']=4;
	}
	$q = $db->query("UPDATE g_threads SET view = $view WHERE tid = $tid LIMIT 1");
	$aq = $db->query("SELECT * FROM g_attachments WHERE bid=$tid and typeid=3");
	while($q_attach=$db->fetch_array($aq)){
			$q_attach['icon']=attachtype(fileext($q_attach['storename'])."\t".$q_attach['type']);
			$allattachs[$q_attach['fid']]=$q_attach;
		}
	$totalrecord=$db->result($db->query("SELECT count(*) FROM g_replys WHERE typeid = 3 and bid = $tid"),0);
	$rq=$db->query("SELECT a.*,b.uid,b.userid, b.userface , b.gid,b.postcount,b.registertime FROM g_replys a left join g_members b ON a.reply_uid=b.uid WHERE a.typeid = 3 and a.bid = $tid ORDER BY subtime limit $startrecord,$ppp");
	while($q_reply=$db->fetch_array($rq)){
	if(!$q_reply['uid']){
		$q_reply['userid']='访客';
		$q_reply['userface']='01.png';
		$q_reply['ip']=$q_reply['ip1'].'.'.$q_reply['ip2'].'.*.*';
		$q_reply['gid']=4;
		}
	$replys[]=$q_reply;
	$raq = $db->query("SELECT * FROM g_attachments WHERE typeid=4 and bid = {$q_reply['rid']}");
	while($q_attachs=$db->fetch_array($raq)){
			$q_attachs['icon']=attachtype(fileext($q_attachs['storename'])."\t".$q_attachs['type']);
			$replyattachs[$q_reply['rid']][$q_attachs['fid']]=$q_attachs;
		}
	}
$message=gateweicode($allthread['content']);
  foreach($replys as $key => $val){
	$rrrid=$val['rid'];
	$replys[$key]['content']=gateweicode($val['content']);
	$replys[$key]['ip']=$val['ip1'].'.'.$val['ip2'].'.*.*';//此处设置调整显示ip显示的位数
	$replys[$key]['floor']=$floor;
	$floor++;
}

if(!empty($allattachs)){
		foreach($allattachs as $key => $val){
				if(!in_array($key,$displayattachs)){
				$downattachs[$key]=$val;
			}
		}
	}

if(!empty($replyattachs)){
		foreach($replyattachs as $keys => $vals){
			foreach($vals as $key => $val){
				if(!in_array($key,$displayattachs)){
				$replydownattachs[$keys][$key]=$val;
				}
			}
		}
	}
foreach ($replyattachs as  $val){
}
$floor=isset($floor)?$floor+$ppp-1:2;
$multipage=multi($totalrecord, $ppp, $curpage, "viewthread.php?tid=".$tid);
include($templatedir."viewthread.tpl.php");

