<?php
#------------------------------------------------------#
#               本程序为zChain.net提供                 #
#                zChain论坛(ZBB)v2.00                  #
#------------------------------------------------------#
# INPUT[GET] : $page;
$listpage=20; # 社区每页显示的论坛数目

require "bin/config.php";
require "bin/common.php";

require_once('core/class_forum_base.php');
CForumBase::setFileBase("$filepath");
require_once('core/base_memo_file.php');
require_once('core/class_board.php');
require_once('core/class_user.php');
require_once('core/class_note.php');
require_once('core/class_topic.php');
require_once('core/base_array_file.php');
require_once('core/class_news.php');
require_once('core/class_board_list.php');
require_once('core/base_record_file.php');
require_once('core/class_topic_list.php');

#--- Record activity ---
if($interval>0){include('bin/set_online.php');}

#--- Set Root Position ---
setcookie('ck_root','1');
setcookie('ck_bname',$commname);

### Start generate list page ###
if($sv_user){
 $oUsr=new CUser;
 $oUsr->load($sv_user);
 if($oUsr->msg==""){$oUsr->msg=0;}
 if($oUsr->oldmsg==""){$oUsr->oldmsg=0;}
}
$oNote=new CNote;
$oNote->load();

page_header("$commname - zChain论坛系统(ZBB)","$imgurl/bg.gif");
print "<CENTER>";
include('bin/mainmenu.php');
print "</CENTER>";

#--- title ---
print <<<EOT
<TABLE width="90%" border=0 align="center">
<TR> 
 <TD align=middle width="25%" rowspan="2"><IMG src="$imgurl/zbbtitle.gif"></TD>
 <TD align=middle colspan="4" class=title>$commname</TD>
</TR>
<TR> 
 <TD align=center>社区管理人员</TD>
 <TD align=center>社区区长：<a href="viewuser.php?user=$admname">$admname</a></TD>
 <TD align=middle>注册会员：{$oNote->numuser}</TD>
 <TD align=middle>欢迎新会员：<a href="viewuser.php?user=$oNote->newuser">$oNote->newuser</a></TD>
</TR>
</TABLE>
EOT;

#--- broadcast ---
$oNws=new CNews;
$oNws->load();

print <<<EOT
<TABLE cellPadding=0 width="95%" border=0 align="center">
<TR>
 <TD width=20><IMG src="$imgurl/caution.gif"></TD>
 <TD width="60%">
  <MARQUEE scrollAmount=3><A href=affiche.php>$oNws->title</A></MARQUEE></TD>
 <TD>&nbsp;</TD>
</TR>
</TABLE>
EOT;

#--- Create board list ---
print <<<EOT
<table cellspacing=1 width=95% border=0 class="forumLine" cellpadding=2 align=center>
<tr>
 <td width="7%" class="rowCaption"></td>
 <td width="40%" align=center class="rowCaption">论坛</td>
 <td width="8%" align=center class="rowCaption">主题</td>
 <td width="30%" align=center class="rowCaption">最后发表</td>
 <td width="15%" align=center class="rowCaption">版主</td>
</tr>
EOT;

$oBrdLst=new CBoardList;
if(!$oBrdLst->load('community')){$oBrdLst->load();}

$size=$oBrdLst->itemCount();
$pages=ceil($size/$listpage);

if($page <= 0){$page=1;}
$firstitem=($page-1)*$listpage;
$lastitem=$firstitem+$listpage;
if($lastitem>$size){$lastitem=$size;}

for($i=$firstitem; $i<$lastitem; $i++) {
 $oBrdLst->moveTo($i);
 $cat=$oBrdLst->id;
 if(substr($cat,0,2)=='--'){
  $cat=substr($cat,2,strlen($cat)-2); if($cat==''){$cat='&nbsp;';}
 }else{
  $cat='';
 }

 if($cat != ""){
  print "<tr><td colspan=5 class=rowCat>$cat</td></tr>";
 }else{
  _printBoardInfo($oBrdLst->id);
 }
}

#--- Print user info ---
if($sv_user){
 list($kkk)=split(')',$GLOBALS['HTTP_USER_AGENT']);
 list($bzd,$ie,$win,$me)=split(';',$kkk);
 if($me == " Win 9x 4.90"){$win=" Windows Me";}
 elseif($win == " Windows NT 5.0"){$win=" Windows 2000";}
 elseif($win == " Windows NT 5.1"){$win=" Windows XP";};

 print <<<EOT
<tr>
 <td align=middle colspan=5 class="rowCaption">个人状态</td>
</tr>
<tr>
 <td align=middle width="7%" class="row1"><img src="$imgurl/user.gif"></td>
 <td colspan=4 width="93%" class="row1">
  $sv_user - 您现在有 $oUsr->oldmsg 条留言 (有 $oUsr->msg 条新留言)<br>
  您的 IP 是：{$uip} 　　操作系统：{$win} 　　浏览器：{$ie}</td>
 </tr>
EOT;

}

#--- Print online user info ---
if($interval>0){
 require_once('core/class_activity.php');
 $oAct=new CActivity;
 $oAct->load();
 $people=$oAct->itemCount();

 print <<<EOT
<tr>
 <td align=middle colspan=5 class="rowCaption">在线用户</td>
</tr>
<tr>
 <td align=middle width="7%" class="row1"><img src="$imgurl/online.gif"></td>
 <td colspan=4 width="93%" class="row1">
  <A href="viewonline.php">看看现在谁在这个论坛</A>
  (<font color=red>$people</font>)<BR>
  <table border=0 width=100%><tr>
EOT;

 for($i=0; $i<$people; $i++){
  $oAct->moveTo($i); $uname=$oAct->user;

  if($uname != ''){
   $newline=(($i+1)%6 == 0) ? '</tr><tr>' : '';
   print <<<EOT
<td width=16% style=word-break:break-all>
<a href=viewuser.php?user=$uname>$uname</a>
</td>$newline
EOT;
  }
 }

 print "</tr></table></TD></TR>";
}

#--- Print page navigator ---
print "</table><table width=95% border=0 align=center><tr><td align=center>";
for($i=1; $i<=$pages; $i++){
 if($page!=$i){print "<a href=?page=$i>[$i]</a>";}
 else{print "[$i]";}
}
print '</td></tr></table>';
 
page_footer();
exit;

function _printBoardInfo($bid){
 global $imgurl;

 $oBrd=new CBoard;
 $oTpcLst=new CTopicList;
 $oTpc=new CTopic;

 if(!$bid){return;}
 if(!$oBrd->load($bid)){return;}

 $oTpcLst->open($bid);
 $size=$oTpcLst->getRecordCount();
 if($size > 0){
  $oTpc->setBrief($oTpcLst->brief);
  $tpcInfo="<table><tr><td valign=top><img src=$imgurl/$oTpc->emotion.gif></td>"
   ."<td><a href=viewtopic.php?bid=$bid&tid=$oTpcLst->id>$oTpc->title</a>"
   ." ($oTpc->lastname)<br>$oTpc->lasttime</td></tr></table>";
 }else{
  $tpcInfo="&nbsp;";
 }

 print "<TR><TD vAlign=top align=middle width=7% class=row1>";

 if($oBrd->secret){print "<img src=$imgurl/bbslock.gif>";}
 elseif($rq < "1"){print "<img src=$imgurl/on.gif>";}
 else{print "<img src=$imgurl/off.gif>";}

 print <<<EOT
</TD>
<TD vAlign=top width="40%" class="row1">
<a href=viewboard.php?bid=$bid>$oBrd->name</a><br>$oBrd->desc</TD>
<TD valign=middle align=center width="8%" class="row2">$size</TD>
<TD width="30%" class="row1">$tpcInfo</TD>
<TD valign=middle align=center width="15%" class="row2">
<a href=viewuser.php?user=$oBrd->owner>$oBrd->owner</a><br>
<a href=viewuser.php?user=$oBrd->owner1>$oBrd->owner1</a><br>
<a href=viewuser.php?user=$oBrd->owner2>$oBrd->owner2</a></TD>
</TR>
EOT;
}
?>