<?
require("datafile/superadmin.php");
require("datafile/config.php");
require("datafile/style.php");
require("global.php");

if (empty($forumid) || !file_exists("forum$forumid")) exit;

if (empty($page)) $page=1;

get_forum_info();

if (file_exists("datafile/admin.php")) {
	$adminlist=file("datafile/admin.php");
	$count=count($adminlist);
	for ($i=0; $i<$count; $i++) {
		$detail=explode("|", trim($adminlist[$i]));
		if ($detail[0]==$forumid) $forum_admin[]=$detail[1];
	}
}
if (file_exists("forum".$forumid."/last_mo.php")) {
	$last_modify=explode("|",readfromfile("forum$forumid/last_mo.php"));
	$amount=$last_modify[1];
}
else $amount=0;

$add_title=" &gt; $forum_name";

require("header.php");

$des="您现在正在访问的是 $forum_name<br>目前本版共有 <b>$amount</b> 篇文章";

navi_bar($des,$forum_name);

if ($view_forum_online) whosonline();

print <<<EOT
<br>
<table width=$tablewidth border=0 cellspacing=0 cellpadding=0 align=center>
  <tr align=right valign=bottom> 
    <td align=left><a href="vibpost.php?forumid=$forumid"><img src="images/system/newthread.gif" border=0></a>
    <a href="vibvote.php?forumid=$forumid"><img src="images/system/newsta.gif" border=0></a>
    <a href="vibucom.php?forumid=$forumid"><img src="images/system/newucom.gif" border=0></a>
    </td>
    <td width=50%>斑竹：
EOT;

if (isset($forum_admin)) {
	$count=count($forum_admin);
	for ($i=0; $i<$count; $i++) echo "<a href='vibprofile.php?job=show&target=$forum_admin[$i]'>$forum_admin[$i]</a> ";
}
else echo "空缺";

?>
</td>
</tr>
</table>
<?
echo <<<EOT
<table cellspacing=0 cellpadding=0 width=$tablewidth align=center bgcolor=$bordercolor border=0><tr><td height=1></td></tr></table>
<table cellspacing=0 cellpadding=0 width=$tablewidth align=center border=1 bgcolor=$titlecolor bordercolor=$bordercolor>
  <tr align=center height=26>
    <td width=32 background=images/style/catbg.gif><b>状态</b></td>
    <td width=* background=images/style/catbg.gif><b>主&nbsp;&nbsp;题</b> (点击心情符号可以打开新窗口浏览)</td>
    <td width=85 background=images/style/catbg.gif><b>作 者</b></td>
    <td width=32 background=images/style/catbg.gif><b>回复</b></td>
    <td width=32 background=images/style/catbg.gif><b>点击</b></td>
    <td width=195 background=images/style/catbg.gif><b>最后跟贴时间 | 跟贴者</b></td>
  </tr>
</table>
EOT;

if (file_exists("forum$forumid/list.php")) {

	$total=( max($page,10) * $perpage );
	$fp=fopen("forum$forumid/list.php","r");
	flock($fp,LOCK_SH);
	$count=0;
	while (!feof($fp) && $count<$total) {
		$article_list[]=fgets($fp,800);
		$count++;
	}
	fclose($fp);
	if (!$article_list[$count-1]) {
		unset ($article_list[$count-1]);
		$count--;
	}
	//$article_list=file("forum$forumid/list.php");
	//$count=count($article_list);
	if ($count%$perpage==0) $maxpageno=$count/$perpage;
		else $maxpageno=floor($count/$perpage)+1;
	if ($page>$maxpageno) $page=$maxpageno;
	$pagemin=min( ($page-1)*$perpage , $count-1);
	$pagemax=min( $pagemin+$perpage-1, $count-1);
	for ($i=$pagemin; $i<=$pagemax; $i++) {
		$a_info=$article_list[$i];
		article_line();
	}
}else {$maxpageno=1;}
?><TABLE style=BORDER-COLLAPSE: collapse borderColor=#111111 cellSpacing=0 cellPadding=0 width=95% align=center border=0><TBODY><tr>
  <td background=images/style/bottombg.gif><P align=left><IMG height=18 src=images/style/bottomleft.gif width=2 border=0></P></td>
  <td background=images/style/bottombg.gif><P align=right><IMG height=18 src=images/style/bottomright.gif width=2 border=0></P></td>
</TBODY></tr>
</TABLE>
</table>
<br>
<!---Pages list & forum jump begin-->
<table cellspacing=0 cellpadding=0 width=<?=$tablewidth?> align=center border=0 bgcolor=<?=$list_color1?>>
<form name=jump action=viblist.php method=post>
<tr> 
<td align=left>&nbsp;
<?
if ($maxpageno==1) echo "<b>本论坛只有一页</b>";
else {echo "<b>可选择页</b>:";
      echo "[ ";
      $nextpage=$page+1;
      $previouspage=$page-1;
      if ($page>=2) echo "<a href=\"viblist.php?forumid=$forumid&page=$previouspage\"><b>←</b></a> ";
      else echo "<b>←</b> ";

      if ($page<=$maxpageno-1) echo "<a href=\"viblist.php?forumid=$forumid&page=$nextpage\"><b>→</b></a> ";
      else echo "<b>→</b> ";
      
    for ($i=1; $i<=$maxpageno; $i++) {
      if ($i!=$page) 
      echo " <a href=\"viblist.php?forumid=$forumid&page=$i\"><b>$i</b></a> ";
      if ($i==10) {echo "以及更多"; break;}
    }

    echo "]";
}
?></td>
<td align=right> 
<script language=JavaScript>
<!-- 
function menu(){
var URL = document.jump.jumpto.options[document.jump.jumpto.selectedIndex].value;
top.location.href = URL; target = '_self';
}
// -->
</script>
<select onChange=menu() name=jumpto>
<OPTION value="viboard.php" selected>论坛跳至
<?
$count=count($forumlist)-1;
for ($i=0; $i<=$count; $i++) {
	$forum_list_info=explode("|",$forumlist[$i]);
	if ($forum_list_info[0]=="category") echo "<OPTION target=_self value=\"viboard.php\">$forum_list_info[1]";
		else echo "<OPTION target=_self value=\"viblist.php?forumid=$forum_list_info[3]\">&nbsp;|- $forum_list_info[1]";
}
?>
</OPTION>
</select>
</td></tr>
</form>
</table>
<img src='' width=9 height=8><br>
<script language="JavaScript1.2">
<!--
helpstat = false;
stprompt = true;
basic = false;
clckcnt = 0;
var postmaxchars = <?=$max_post_length?>;
ie = (document.all)? true:false
if (ie){
function ctlent(eventobject){if(event.ctrlKey && window.event.keyCode==13){this.document.FORM.submit();}}
}
function clckcntr() {
clckcnt++;
if(clckcnt > 1) {
if(clckcnt > 2) { return false; }
alert('贴子已经发出了......\n\n' + '请等待片刻......\n\n' + '不要重复按提交键，谢谢！');
return false;
}
return true;
}
function thelp(swtch){
if (swtch == 1){
basic = false;
stprompt = false;
helpstat = true;
} else if (swtch == 0) {
helpstat = false;
stprompt = false;
basic = true;
} else if (swtch == 2) {
helpstat = false;
basic = false;
stprompt = true;
}
}
function AddText(NewCode) {
document.FORM.articlecontent.value+=NewCode
}
function validate(theform) {
if (theform.articletitle.value=="" || theform.articlecontent.value=="") {
alert("请完成标题和内容栏目.");
clckcnt=0;
return false; }
if (postmaxchars != 0) {
if (theform.articlecontent.value.length > <?=$max_post_length?>) {
alert("你的信息太长了.\n\n请限制在 <?=$max_post_length?> 字节以内.\n当前已有 "+theform.articlecontent.value.length+" 字节.");
clckcnt=0;
return false; }
else { return true; }
} else { return true; }
}
function checklength(theform) {
if (postmaxchars != 0) { message = "\n最大的字符为 <?=$max_post_length?> 字节."; }
else { message = ""; }
alert("你的信息已经有 "+theform.articlecontent.value.length+" 字节."+message);
}
//-->
</script>
<table cellspacing=0 cellpadding=0 width=<?=$tablewidth?> align=center bgcolor=<?=$bordercolor?> border=0> 
<tr>
<td height=1></td>
</tr>
</table>
<table cellspacing=0 cellpadding=0 width=<?=$tablewidth?> align=center border=0>
<tr>
<td valign=center width=1 bgcolor=<?=$bordercolor?> height=22></td>
<td valign=center align=left width=* background=images/style/catbg.gif>
<table cellspacing=1 cellpadding=0 width=100% border=0>
<tr bgcolor=<?=$titlecolor?>>
<td valign=center align=left background=images/style/catbg.gif>&nbsp;<b>-=&gt; 快速发表新帖子</b> </td>
</tr>
</table> 
</td>
<td valign=center width=1 bgcolor=<?=$bordercolor?> height=22></td>
</tr>
</table>
<table cellspacing=0 cellpadding=0 width=<?=$tablewidth?> align=center bgcolor=<?echo"$bordercolor";?> border=0>
<tr>
<td height=1></td>
</tr>
</table>
<table cellspacing=0 cellpadding=0 width=<?=$tablewidth?> align=center border=1 bordercolor=<?echo"$bordercolor";?>>
<tr>
<td bgcolor=<? if ($bgcolor==$article_color1) $bgcolor=$article_color2; else $bgcolor=$article_color1;echo"$bgcolor";?>>
<table cellspacing=0 cellpadding=4 width=100% height="100%" bgcolor=<?echo"$bgcolor";?>>
<tr>
<td valign=top width=20% bgcolor=<?=$bgcolor?> rowspan=2 align="center">  
<br>
<b>文章内容</b>：<br>
<br>
HTML 代码不可用 <br>  
<b class=cau><a href="javascript:openScript('vibfaq.php',700,500)"><font face="Courier New, Courier">VIB Code</font></a></b> 开放<br>  
点击 <a href="javascript:openScript('vibfaq.php',700,500)"><b>这里</b></a>  
看使用方法 <br>  
<b>VIB代码选项</b>：<br>
<font face=verdana>
<? 
echo '[img]   -'; 
if ($vibcode_post['pic']) echo ' 
</font> 开启<font face=verdana>'; else echo ' 
</font> 关闭<font face=verdana>'; 
echo '<br>[flash] -'; 
if ($vibcode_post['flash']) echo ' 
</font> 开启<font face=verdana>'; else echo ' 
</font> 关闭<font face=verdana>'; 
echo '<br>[size]  -'; 
if ($vibcode_post['fontsize']) echo ' 
</font> 开启<font face=verdana>'; else echo ' 
</font> 关闭<font face=verdana>';  
?>
</font> <br>
</td>
<td width=* bgcolor=<?echo"$bgcolor";?> height=100% rowspan=2>
<table height=100% cellspacing=0 cellpadding=0 width=1 bgcolor=<?echo"$bordercolor";?>>
<tr>
<td width=1></td>
</tr>
</table>
</td>
<td width=* bgcolor=<?echo"$bgcolor";?> rowspan=2>  
<script>
function DoTitle(addTitle) {
var revisedTitle;
var currentTitle = document.FORM.articletitle.value;
revisedTitle = currentTitle+addTitle;
document.FORM.articletitle.value=revisedTitle;
document.FORM.articletitle.focus();
return; }
function DoComments(addTitle) { 
var revisedTitle; 
var currentTitle = document.FORM.articlecontent.value; revisedTitle = currentTitle+addTitle; document.FORM.articlecontent.value=revisedTitle; document.FORM.articlecontent.focus(); 
return; 
}
</script>
<form name="FORM" method="post" action="vibpost.php" onSubmit="return validate(this)" enctype="multipart/form-data">
<input type=hidden name="autourl" value="yes"><input type=hidden name="usesignature" value="checkbox">
<b>文章标题</b>：  
<input type="text" name="articletitle" value="" size="35" maxlength="45" style="background-color:#ffffff; border: 1 double #B4B4B4" onMouseOver = "this.style.backgroundColor = '#E5F0FF'" onMouseOut = "this.style.backgroundColor = ''">
<INPUT class=input3 type=hidden value=yes name=actioneot> <a onFocus=this.blur()  href="javascript:checklength(document.FORM);">[查看帖子长度]</a> 
<br>
<?  
if ($login_status==0) $bym=0;  
else {  
	if (file_exists("$id_unique/$username")) {  
	list($id,$pwd,$usericon,$useremail,$oicq,$regdate,$sign[$author],  
	$homepage,$from,$com,$honor,$lp,$amount,$publicemail,$none,$bym,  
	$lasttime,$nowtime,$icq,$sex,$born,$guoji,$tuijianren,$money,  
	$lasttitle,$lastaddr,$group,$yanzheng,$bei1,$bei2,$bei3,$bei4)  
	= explode("|",readfromfile("$id_unique/$username"));  
	$bym=floor($bym/10);}  
}  
?>
<br>
<textarea onkeydown=ctlent() name="articlecontent" cols="90" rows="6" style="background-color:#F0F0f3; border: 1 double #B4B4B4"></textarea>
<br>
 <input type=hidden value=2 name=step>
<input type=hidden value="<?=$action?>" name=action>  
<input type=hidden value="<?=$forumid?>" name=forumid><?  
if ($filename) echo "<input type=hidden value='$filename' name='filename'>";  
if (isset($article)) echo "<input type=hidden value='$article' name='article'>";  
?>  
<?if ($login_status==0) {  
?>  
昵称:  
<input type=text name=username maxlength=25 size=12 style="background-color:#ffffff; border: 1 double #B4B4B4" onMouseOver = "this.style.backgroundColor = '#E5F0FF'" onMouseOut = "this.style.backgroundColor = ''">
密码:   
<input onkeydown=ctlent() type=password name=password maxlength=25 size=12 style="background-color:#ffffff; border: 1 double #B4B4B4" onMouseOver = "this.style.backgroundColor = '#E5F0FF'" onMouseOut = "this.style.backgroundColor = ''">
<? } ?>
<input onclick="return clckcntr();" type="submit" value="发 表" style="height:20px;background-color:#f3f3f3;border:1 solid black" onMouseOver ="this.style.backgroundColor='#FFC864'" onMouseOut ="this.style.backgroundColor='#f3f3f3'">
<input type="reset" value="重 写" style="height:20px;background-color:#f3f3f3;border:1 solid black" onMouseOver ="this.style.backgroundColor='#FFC864'" onMouseOut ="this.style.backgroundColor='#f3f3f3'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;可按 [CTRL]+[ENTER] 直接发表
</form>
</td>
</tr>
</table>
</td>
</tr>
<TABLE style=BORDER-COLLAPSE: collapse borderColor=#111111 cellSpacing=0 cellPadding=0 width=95% align=center border=0><TBODY><tr>
  <td background=images/style/bottombg.gif><P align=left><IMG height=18 src=images/style/bottomleft.gif width=2 border=0></P></td>
  <td background=images/style/bottombg.gif><P align=right><IMG height=18 src=images/style/bottomright.gif width=2 border=0></P></td>
</TBODY></tr>
</TABLE>
</table>
<br>
<!---Illustration Begin------->
<table cellpadding=0 cellspacing=0 border=0 width=<?=$tablewidth?> bgcolor=<?=$bordercolor?> align=center>
 <tr><td>
  <table cellpadding=5 cellspacing=1 border=0 width=100%>
   <tr><td background=images/style/catbg.gif><b>-=&gt; 图标信息说明</b></td></tr>
   <tr><td bgcolor=<?=$list_color2?>>
	<table cellspacing=4 cellpadding=0 width=92% border=0 align=center>
	 <tr align=center> 
	  <td><img src="images/system/topicnew.gif"> <img src="images/system/mytopicnew.gif"></td>
	  <td align=left>打开的主题/我的主题</td>
	  <td><img src="images/system/statistic.gif"> <img src="images/system/ucommend.gif"></td>
	  <td align=left>打开的投票统计 / U-推荐</td>
	  <td><img src="images/system/newred.gif"></td>
	  <td align=left>小时内有更新的主题</td>
	</tr>
	<tr align=center> 
	  <td><img src="images/system/topichot.gif"> <img src="images/system/mytopichot.gif"></td>
	  <td align=left>热门主题/我的热门主题</td>
	  <td><img src="images/system/closesta.gif"> <img src="images/system/closeu.gif"></td>
	  <td align=left>锁定的投票统计 / U-推荐</td>
	  <td><img src="images/system/newblue.gif"></td>
	  <td align=left>一天内有更新的主题</td>
	</tr>
	<tr align=center> 
	  <td><img src="images/system/topiclocked.gif"> <img src="images/system/mytopiclocked.gif"></td>
	  <td align=left>已锁定主题/我的锁定主题</td>
	  <td><img src="images/system/holdtopic.gif"></td>
	  <td align=left>置顶的主题</td>
	  <td><img src="images/system/newgreen.gif"></td>
	  <td align=left>两天内有更新的主题</td>
	</tr>
  </table>
 </td></tr>
<TABLE style=BORDER-COLLAPSE: collapse borderColor=#111111 cellSpacing=0 cellPadding=0 width=100% align=center border=0><TBODY><tr>
  <td background=images/style/bottombg.gif><P align=left><IMG height=18 src=images/style/bottomleft.gif width=2 border=0></P></td>
  <td background=images/style/bottombg.gif><P align=right><IMG height=18 src=images/style/bottomright.gif width=2 border=0></P></td>
</TBODY></tr>
</TABLE>
</table>

<?
require("footer.php");
exit;

function article_line() {
global $a_info,$forumid,$list_color1,$list_color2,$bordercolor,$username,$tablewidth,$read_perpage,$timestamp;
list($title,$author,$date,$des,$icon,$filename,$reply,$hit,$last_mod_data,$islock,$topic_type)=explode("|",$a_info);

if (strlen($author)>=12) $viewauthor=substr($author,0,9).'...';
	else $viewauthor=$author;

if ($icon=="ran") $icon=mt_rand(0,25).'.gif';

$icon="<a target=_blank href='vibread.php?forumid=$forumid&filename=$filename'><img src='images/emotion/$icon' width=13 alt=开新窗口浏览此主题 border=0></a>";
if ($topic_type==1) {
	$stats="<img src='images/system/statistic.gif'>";
	if ($islock==1) $stats="<img src='images/system/closesta.gif'>";
} elseif ($topic_type==2) {
	$stats="<img src='images/system/ucommend.gif'>";
	if ($islock==1) $stats="<img src='images/system/closeu.gif'>";
} elseif ($topic_type>=3) {
	$stats="<img src='images/system/holdtopic.gif'>";
} else {
	if ($username!=$author) {
		$stats="<img src='images/system/topicnew.gif'>";
		if ($reply>=10) $stats="<img src='images/system/topichot.gif'>";
		if ($islock==1) $stats="<img src='images/system/topiclocked.gif'>";
	} else {
		$stats="<img src='images/system/mytopicnew.gif'>";
		if ($reply>=10) $stats="<img src='images/system/mytopichot.gif'>";
		if ($islock==1) $stats="<img src='images/system/mytopiclocked.gif'>";
	}
}

//-------if more than one page-----------
if ($reply+1>$read_perpage) {

	if (($reply+1)%$read_perpage==0) $maxpageno=($reply+1)/$read_perpage;
		else $maxpageno=floor(($reply+1)/$read_perpage)+1;
	if ($maxpageno>5) $multipage='<br>&nbsp;';
		else $multipage=' ';
	$multipage.='[ <b style="font-size:7pt;font-family:verdana;">';
	for ($i=1; $i<=$maxpageno; $i++) {
		$multipage.=" <a style='color:505060' href=\"vibread.php?forumid=$forumid&filename=$filename&page=$i\">$i</a>";
		if ($i==23) {$multipage.=" ... <a style='color:000066' href=\"viblist.php?forumid=$forumid&page=last\">Last</a>"; break;}
	}
	$multipage.='</b> 页]';
}

if (strlen($title)>=40) $title=substr($title,0,37)."...";
$title=str_replace('%a%','<img src="images/system/addon.gif" border=0>',$title);
$title="<a href='vibread.php?forumid=$forumid&filename=$filename'\">$title</a>";
$lmd=explode(",",$last_mod_data);
$g=$timestamp-$lmd[2];
if ($g<=3600) $title.=' <img src="images/system/newred.gif">';
elseif ($g<=86400) $title.=' <img src="images/system/newblue.gif">';
elseif ($g<=172800) $title.=' <img src="images/system/newgreen.gif">';
if ($lmd[2]==$date) $lmdauthor="------";
else $lmdauthor="<a href=\"vibprofile.php?job=show&target=$lmd[1]\">$lmd[1]</a>";
$lmdtime=get_date($lmd[2]).' '.get_time($lmd[2]);
print ("
<table cellspacing=0 cellpadding=0 width=$tablewidth align=center border=1 bordercolor=$bordercolor>
<tr align=center height=25 bgcolor=$list_color1>
<td width=32>$stats</td>
<td width=* bgcolor=$list_color2 align=left>&nbsp;$icon&nbsp;<acronym title=\"$des\">$title</acronym>$multipage</td>
<td width=85 ><a href=\"vibprofile.php?job=show&target=$author\">$viewauthor</a></td>
<td width=32 bgcolor=$list_color2>$reply</td>
<td width=32 bgcolor=$list_color2>$hit</td>
<td width=195 align=left>&nbsp; &nbsp;{$lmdtime}&nbsp;<font color=#000066>|</font>&nbsp;$lmdauthor</td>
</tr>
</table>
");
}
//----------------------------------------------------------------------
function whosonline() {
global $timestamp,$online_limit,$forumid,$tablewidth,$bordercolor,$list_color2,$titlecolor;
	$onlinefile="datafile/online.php";

	$userno=0;
	$guestno=0;
	$usergroup='';

	$online_user=file($onlinefile);

	$count=count($online_user);
	for ($i=0; $i<$count; $i++) {
		$online_user_info=explode("|",trim($online_user[$i]));
		if ($timestamp-$online_user_info[1]<=$online_limit && $online_user_info[3]==$forumid)
		  if ($online_user_info[0]=="guest") $guestno++;
		  else {
			$usergroup.="&nbsp;<a onclick='Show(messanger)' href='messanger.php?job=write&target=$online_user_info[0]' target=msg><img alt=给该用户留言 border=0 src='images/system/ren.gif'></a><span title=查看该用户资料><a href='vibprofile.php?job=show&target=$online_user_info[0]'>$online_user_info[0]</a></span>";
			$userno++;
		  }
	}
	if ($usergroup) $usergroup="<tr><td bgcolor=$list_color2>$usergroup</td></tr>";
	$sum=$userno+$guestno;
print <<<EOT
<table cellpadding=0 cellspacing=0 border=0 width=$tablewidth bgcolor=$bordercolor align=center>
<tr><td>
<table cellpadding=5 cellspacing=1 border=0 width=100%>
<tr bgcolor=$titlecolor>
<td background=images/style/catbg.gif>本讨论区版块目前共有 <b>$sum</b> 人访问，包括 <b>$userno</b> 名注册用户，和 <b>$guestno</b> 名访客</td>
</tr>
$usergroup
</table>
</td></tr>
<TABLE style=BORDER-COLLAPSE: collapse borderColor=#111111 cellSpacing=0 cellPadding=0 width=95% align=center border=0><TBODY><tr>
  <td background=images/style/bottombg.gif><P align=left><IMG height=18 src=images/style/bottomleft.gif width=2 border=0></P></td>
  <td background=images/style/bottombg.gif><P align=right><IMG height=18 src=images/style/bottomright.gif width=2 border=0></P></td>
</TBODY></tr>
</TABLE>
</table><br>
EOT;
}
