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

$forumlist=file('datafile/forumdata.php');
if (file_exists('datafile/announcement.php')) include('datafile/announcement.php');
	else $announcement='暂时没有发布公告';
if (file_exists('datafile/newuser.php')) $newuserinfo=readfromfile('datafile/newuser.php');
	else $newuserinfo='|0|0';
$newuser_info=explode('|',$newuserinfo);
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]));
		$admin_list[]=$detail[1];
		$forum_admin[$detail[0]][]=$detail[1];
	}
}

$cip=convert_ip($ip);

require("header.php");
?>

<table width=<?=$tablewidth?> border=0 cellspacing=0 cellpadding=0 align=center>
  <tr> 
    <td class=cau><? if ($login_status==0) echo "欢迎你，你还未登录，请先<a href=viblogin.php><font color=#FF0000>登录</font></a>或<a href=register.php><font color=#FF0000>注册</font></a>"; else echo "你好，{$HTTP_SESSION_VARS['vibid']}，欢迎你来到讨论区"; ?>&nbsp;&nbsp;<font face="Verdana, Arial" class=menutext><b>&nbsp;功能选项｜</b>『<? if ($login_status==1) {?> <a href="viblogin.php?job=quit">退出登录</a> | <font color="#ff0000" style="CURSOR:hand" onclick="Show(messanger);">论坛短讯</font> | <a href="sendmail.php?job=toadmin">站长信箱</a> | <a href="vibll.php">访问统计</a> <? }else echo "请选登录，不然就不可以使用这些功能";?>』
</td>
  </tr>
</table>
<table width=<?=$tablewidth?> border=0 cellspacing=0 cellpadding=1 align=center>
  <tr> 
    <td width=65% valign=top align=left> 
    <img src="images/system/announce.gif">
    <font class=cau>本站公告：</font><br>
<?=$announcement?>
    </td>
    <td width=35% align=right valign=top>
<div align=left><img src="images/system/statistic.gif">
<font class=cau>数据统计：</font></div>
目前论坛有会员 <b><?=$newuser_info[1]?></b> 人， 文章 <b><?=$newuser_info[2]?></b> 篇<br>
热烈欢迎新会员<? echo " <a href=\"vibprofile.php?job=show&target=$newuser_info[0]\">$newuser_info[0]</a> "; ?>的加入
</td>
</tr>
</table>
<script src=counter.php></script>
<table cellspacing=0 cellpadding=0 width=<?=$tablewidth?> align=center border=0>
<tr> 
<td> 
<table cellspacing=1 cellpadding=5 width=100% border=0 bgcolor=<?=$bordercolor?>>
<tr align=center height=22 bgcolor=<?=$titlecolor?>>
<td background=images/style/catbg1.gif width=26><b>图标</b></td>
<td background=images/style/catbg1.gif width=*><b>讨论区名称和简介</b></td>
<td background=images/style/catbg1.gif width=74><b>斑竹</b></td>
<td background=images/style/catbg1.gif width=54><b>贴子数</b></td>
<td background=images/style/catbg1.gif width=168><b>最后发表</b></td>
</tr>

<?
$count=count($forumlist);
for ($i=0; $i<$count; $i++) {
  $detail=explode('|',$forumlist[$i]);
  if ($detail[0]=='forum' || $detail[0]=='selection') forum_line($detail[0]);
  	elseif ($detail[0]=='category') category_line($detail[1]);
}
?>
<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>
    </td>
  </tr>
</table>
<?
//--Allied Forums------
if (file_exists("datafile/shareforum.php")) {
	$alliedforums=file("datafile/shareforum.php");
	if (!empty($alliedforums)) {

		print("<img src='' width=9 height=8><br>
<!----- Allied Forums --------->
<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/catbg1.gif bgcolor=$titlecolor colspan=2>
<b>-=> 联盟论坛</b></td></tr>");
echo "<tr><td bgcolor=$forumcolortwo width=26 align=center>
			<img src=images/system/shareforum.gif alt=\"联盟论坛\">
			</td>
			<td bgcolor=$forumcolorone width=*>";
		        $count=count($alliedforums);
               		for ($i=0; $i<$count; $i++) {
			list($alliedforumname, $alliedforumurl, $alliedforuminfo) = explode("|" , $alliedforums[$i]);
			echo "
			<a href=$alliedforumurl target=_blank><img src=$alliedforumname border=0 height=31 width=88 alt=$alliedforuminfo></a> ";
		}
		echo "</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></td></tr></table>
<!----- Allied Forums End --------->";
	}
}
?>
<img src='' width=9 height=8><br>
<table cellpadding=0 cellspacing=0 border=0 width=<?=$tablewidth?> bgcolor=<?=$bordercolor?> align=center>
<tr><td><table cellpadding=5 cellspacing=1 border=0 width=100%>
<?

$browser=browseinfo();
$os=osinfo();

$yourstatus="今次你的IP：<font class=cau>$ip</font> 来自:<font class=cau>$cip</font> 浏览器:<font class=cau>".$browser."</font> 操作系统:<font class=cau>".$os."</font>";

if ($login_status==1) {
	if ($gotNewMessage==0) $your_status_icon='inboxnonew';
		else $your_status_icon='inboxnew';
	$forum_admin=$admin_list;
	$level=getUserLevel($postamount,$username);
	$yourstatus.="<br>您的短消息收件箱里有 <b>$gotNewMessage</b> 条新消息，目前您已发表了 <b>$postamount</b> 篇文章，您目前的等级是 <b>$level</b>";
} else {
	$your_status_icon='inboxnologin';
	$yourstatus.='<br>你还没有登录，所以无法查看其他消息';
}
print <<<EOT
<tr bgcolor=$titlecolor>
  <td background=images/style/catbg1.gif colspan=2><b>-=&gt; 你的信息</b></td>
</tr>
<tr>
  <td bgcolor=$forumcolortwo width=26 align=center><img src="images/system/$your_status_icon.gif"></td>
  <td bgcolor=$forumcolorone>$yourstatus</td>
</tr>
<tr bgcolor=$titlecolor> 
  <td background=images/style/catbg1.gif colspan=2><b>-=&gt; 论坛在线统计</b></td>
</tr>
<tr>
  <td bgcolor=$forumcolortwo width=26 align=center><img src="images/system/online.gif"></td>
  <td bgcolor=$forumcolorone>
EOT;
whosonline(); ?></td>
</tr>
<?
if ($login_status==0) show_login();
?>
<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>
    </td>
  </tr>
</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 bgcolor=<?=$titlecolor?>>
    <td background=images/style/catbg1.gif><b>-=&gt; 图标信息说明</b></td>
    <td background=images/style/catbg1.gif noWrap width=18% align=right>所有时间 - 中国时间</td>
   </tr>
   <tr bgcolor=<?=$list_color2?>><td colspan=2>
	<table cellspacing=4 cellpadding=0 width=92% border=0 align=center>
	 <tr align=center>
	  <td><img src="images/system/forum.gif"></td>
	  <td align=left>普通的开放的版块</td>
	  <td><img src="images/system/forumnew.gif"></td>
	  <td align=left>上次访问后有新贴</td>
	  <td><img src="images/system/selection.gif"></td>
	  <td align=left>论坛精华贴的版块</td>
	  <td><img src="images/system/shareforum.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>
</td></tr>
</table>
<!---Illustration End------->

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

function category_line($name) {
global $categorycolor,$i,$bordercolor,$tablewidth,$categoryfontcolor;
	if ($i==0)
	print("<tr><td background=images/style/catbg.gif bgcolor=$categorycolor colspan=7><img src='' width=5 height=5><font color=$categoryfontcolor>-=> $name </font></td></tr>");
	else
	print
"<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>
    </td>
  </tr>
</table><img src='' height=5 width=9><br>
<table cellspacing=0 cellpadding=0 width=$tablewidth align=center border=0>
 <tr>
  <td>
    <table cellspacing=1 cellpadding=5 width=100% border=0 bgcolor=$bordercolor>
     <tr><td background=images/style/catbg.gif bgcolor=$categorycolor colspan=7><img src='' width=5 height=5><font color=$categoryfontcolor>-=> $name</font></td></tr>";
}

function forum_line($forum_type) {
global $detail,$forumcolorone,$forumcolortwo,$script_pos,$forum_admin,$forumnamecolor,$forumdescolor,$lastvisit,$login_status;

	if (file_exists("forum".$detail[3]."/last_mo.php")) {
		$last_modify=explode("|",readfromfile("forum$detail[3]/last_mo.php"));
		$last_modify_list=explode(",",$last_modify[0]);

		if (strlen($last_modify_list[0])>=18) $last_modify_list[0]=substr($last_modify_list[0],0,16)."..";
		$modifytime=get_stamp($last_modify_list[2]);
		$title="<font class=cau>标题：</font><a href=\"vibread.php?forumid=$detail[3]&filename=$last_modify_list[3]\">$last_modify_list[0]</a>";
		$user="<font class=cau>作者</font>：<a href=\"vibprofile.php?job=show&target=$last_modify_list[1]\">$last_modify_list[1]</a>";
		$time="<font class=cau>时间：</font>".$last_modify_list[2];
	}
	else {
		$title=""; $user=""; $time=""; $last_modify[1]=0;
		$modifytime=-1;
	}
if ($forum_type=="forum") {

	//----- is there any new post? ------
	//echo $lastvisit;echo $lastvisit-$modifytime;
	if (!$login_status) $forum_icon='<img src="images/system/forum.gif" border=0>';
	elseif (!$lastvisit) $forum_icon='<img src="images/system/forumnew.gif" border=0>';
	elseif ($modifytime && $lastvisit<$modifytime) $forum_icon='<img src="images/system/forumnew.gif" border=0>';
	else $forum_icon='<img src="images/system/forum.gif" border=0>';
} else $forum_icon='<img src="images/system/selection.gif" border=0>';

	$forumlabel="<table border=0 width=100%>
  <tr>
    <td width=70%><a href=viblist.php?forumid=$detail[3]><font color=$forumnamecolor>『 $detail[1] 』</font></a></td>
    <td width=30%><p align=right><a href=vibpost.php?forumid=$detail[3]><img src=images/system/mini_post.gif border=0 alt=在[$detail[1]]发表一个新主题></a>&nbsp;<a href=vibvote.php?forumid=$detail[3]><img src=images/system/mini_votes.gif border=0 alt=在[$detail[1]]发表一个新投票></a>&nbsp;<a href=vibucom.php?forumid=$detail[3]><img src=images/system/mini_ucom.gif border=0 alt=在[$detail[1]]发表一个新U-推荐></a></td>
  </tr>
</table>";

	if (!empty($forum_admin[$detail[3]])) {
		$count=count($forum_admin[$detail[3]]);
		for ($j=0; $j<$count; $j++) {
			if ($j==2) {$admin_list.='<b>...</b>'; break; }
			$adminname=$forum_admin[$detail[3]][$j];
			$admin_list.="<span title=\"点击查看管理员 $adminname 的资料\"><a href=\"vibprofile.php?job=show&target=$adminname\">$adminname</a></span><br>";
		}
	}
	print(
"<tr align=center valign=middle bgcolor=$forumcolortwo>
<td width=26><a href=\"viblist.php?forumid=$detail[3]\">$forum_icon</a></td>
<td width=* bgcolor=$forumcolorone align=left>$forumlabel<font color=$forumdescolor>----$detail[2]</font></td>
<td width=74>$admin_list</td><td width=54 bgcolor=$forumcolortwo valign=middle align=center><b><font class=cau>$last_modify[1]</font></b></td>
<td width=168 bgcolor=$forumcolorone align=left>&nbsp;$title<br>&nbsp;$user<br>&nbsp;$time</td>
</tr>");
}

function show_login() {
global $titlecolor,$forumcolorone,$forumcolortwo;
print <<<EOT
<tr bgcolor=$titlecolor> 
  <td background=images/style/catbg1.gif colspan=2><b>-=&gt; 快速登录入口</b></td>
</tr>
<form action=viblogin.php method=post>
<tr> 
  <td bgcolor=$forumcolortwo align=center width=26><img src="images/system/login.gif"></td>
  <td bgcolor=$forumcolorone>
用户名：<input style="background-color:#FFFFFF; color:#9999FF; border: 1 double #B4B4B4" onMouseOver = "this.style.backgroundColor = '#E5F0FF'" onMouseOut = "this.style.backgroundColor = ''" type=text size=10 name=loginuser>
密码：<input style="background-color:#FFFFFF; color:#9999FF; border: 1 double #B4B4B4" onMouseOver = "this.style.backgroundColor = '#E5F0FF'" onMouseOut = "this.style.backgroundColor = ''" type=password size=10 name=loginpwd>
<input style="color: #000000; background-color: #f3f3f3; border-style: solid; border-width: 1" onMouseOver ="this.style.backgroundColor='#FFC864'" onMouseOut ="this.style.backgroundColor='#f3f3f3'" type=submit value="登 录">
<input type=hidden name='step' value=2> (<a href='sendpwd.php'>忘记了密码？</a>)
  </td>
</tr>
</form>
EOT;
}
function get_stamp($last_str) {
	list($last_date,$last_time)=explode(" ",$last_str);
	list($y,$m,$d)=explode("-",$last_date);
	list($h,$minute)=explode(":",$last_time);
	return mktime($h,$minute,0,$m,$d,$y);
}

//-------Display who's online-------------
function whosonline() {
global $timestamp,$online_limit;
	$onlinefile="datafile/online.php";

	$userno=0;
	$guestno=0;
	$online_user=file($onlinefile);

	$count=count($online_user);
	for ($i=0; $i<$count; $i++) {
		$online_user_info=explode("|",$online_user[$i]);
		if ($timestamp-$online_user_info[1]<=$online_limit && $online_user_info[0]!="guest") {
			echo "&nbsp;<a onclick='Show(messanger)' href='messanger.php?job=write&target=$online_user_info[0]' alt=给该用户留言 target=msg><img 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 ($timestamp-$online_user_info[1]<=$online_limit && $online_user_info[0]=="guest") $guestno++;
	}

	echo "<br>&nbsp;目前共计有 <b>$userno</b> 位注册用户和 <b>$guestno</b> 位游客在线";

}