#!/usr/bin/perl
#------------------------------------------------------#
#              本程序為Yuzi工作室免費提供	       #
#                     Yuzi論壇2.0版                    #
#                                                      #
#                    謝謝您使用本程序  Yuzi            #
#                    E-mail: yuzi@21cn.com             #
#                    Http://yuzi.126.com	       #
#                                                      #
#     本程序為免費程序，如將本程序免費提供免費下       #
#     載，請著名本站出品，並加入本站連接！             #
#     本程序未經許可請勿用於商業用途！                 #
#     您可以使用本程序, 但必須保留Yuzi工作室的字       #
#     樣鍊接! 您可以任意修改本程序, 但要求您保留       #
#     以上信息!                                        #
#------------------------------------------------------#
# 說明：
# 本程序採用自動設定方式，因此不用改動即
# 可使用。您只須將程序上傳，再修改文件屬
# 性為「755」即可使用。
######################設定部分###########################
$admpsd    = "30";               #站長密碼
$admname   = "平安&如意";               #站長名字
$zyname    = "華航組員交流專區";           #主頁名稱
$outurl    = "http://meowfly.myweb.hinet.net";#主頁地址
$bbstitle  = "華航交流專區(請勿人身攻擊!保持禮節)";           #論壇標題
$titleimg  = "";                   #論壇標題圖片
#####################設定結束###########################
$cgiurl="bbs.cgi";
$psdbook="bbspsdci123.yuzi";
$people="peopleci123.yuzi";
$bbsbook="bbsci123.yuzi";
$replybook="regsbbsci123.yuzi";
$from    = $ENV{'REMOTE_ADDR'};

($sec,$min,$hour,$mday,$mon,$wday,$yday)= localtime(time);
$mon=$mon+1;
if($mday<10){$mday="0".$mday;} if($hour<10){$hour="0".$hour+16;}
if($mon <10){$mon="0".$mon;}

if($hour<10){$hour="0".$hour+16;}
if($min<10){$min="0".$min;}
if($sec<10){$sec="0".$sec;}
{$year="2005".$year;}
$thistime=$year."-".$mon."-".$mday.".".$hour.":".$min.":".$sec;
$lasttime=$year."-".$mon."-".$mday;


unless(-f $psdbook){
open(TMP,">$psdbook")||die $!;
print TMP "1__".$admpsd."__".$admname."____".$outurl."__".$lasttime."\n";
close(TMP);
chmod(0666,$psdbook);}

unless(-f $people){open(TMP,">$people");
close(TMP);
chmod(0666,$people);
}
##########
$|=1; 
$filename="$people"; 
($sec,$min,$hour,$mday,$mon,$year)=localtime(time); 
$mon=$mon+1;
$year=$year+1900;
$people=2;
open (FILE,"$filename") || die "Can't Open $filename: $!\n";
@LINES=<FILE>; 
close(FILE);

$SIZE=@LINES; 
open (FILE,">$filename") || die "Can't Open $filename: $!\n";
for ($i=0;$i<$SIZE;$i++) 
{
$_=$LINES[$i];
($addr,$come_hour,$come_min,$come_sec,$host,$come_time)=split(/,/,$_);
$flag=($hour-$come_hour)*3600+($min-$come_min)*60+($sec-$come_sec);

if ( $addr eq "$ENV{'REMOTE_ADDR'}" ) {
print FILE "$ENV{'REMOTE_ADDR'},$hour,$min,$sec,$ENV{'REMOTE_HOST'},$come_time\n";
$check=1;
}
elsif ($flag < 120 && $flag > 0) {
print FILE $_;
$people++;
}
}
if ($check == 0) {
print FILE "$ENV{'REMOTE_ADDR'},$hour,$min,$sec,$ENV{'REMOTE_HOST'},$hour:$min:$sec\n";
}
close (FILE); 
##########
if ($ENV{'REQUEST_METHOD'} eq "POST") {
  read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
} 
else {
  $buffer = $ENV{'QUERY_STRING'};
}
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
   ($name, $value) = split(/=/, $pair);
   $value =~ tr/+/ /;
   $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
   $value =~ s/<!--(.|\n)*-->//g;
   $value =~ s/__/--/g;
   $value =~ s/>/&gt;/g;
   $value =~ s/</&lt;/g;
   $FORM{$name} = $value;
}
##########

$username = $FORM{'username'};
$userpsd  = $FORM{'userpsd'};
$titles   = $FORM{'titles'};
$comment  = $FORM{'comment'};
$mail     = $FORM{'mail'};
$home     = $FORM{'home'};
$a_method = $FORM{'a_method'};
$replytime= $FORM{'replytime'}; 
$deltitle = $FORM{'deltitle'};
$level=6;

unless(-f $bbsbook){
open(TMP,">$bbsbook")||die $!;
close(TMP);
chmod(0666,$bbsbook);
}
unless(-f $replybook){
open(TMP,">$replybook")||die $!;
close(TMP);
chmod(0666,$replybook);
}
$regd=0;
$regda=0;
$regdb=0;

if($a_method eq "reguser"){&reguser; exit;}
if(($username)&&($userpsd)){
$regd=1;
open(PSD,"$psdbook")|| die $!;
@lines=<PSD>;
close(PSD);
foreach $line (@lines) {
$line=~ s/\n//g;
($rdlevel,$rdpassword,$rdname,$rdmail,$rdhome,$rlast)=split(/__/,$line);
if($username eq $rdname){
$regda=1;
if($userpsd eq $rdpassword){
$level=$rdlevel;
$regdb=1;
if($mail eq ""){
$mail=$rdmail;
}
if(($home eq "")||($home eq "http://")){
$home =$rdhome;
}
}
}
}
}else{
$username="";
$userpsd="";
}

if(($regd eq "1")&&($regda ne "1")&&($level==6)){
open(PSD,">>$psdbook")||die $!;
print PSD "5__".$userpsd."__".$username."__".$mail."__".$home."__".$lasttime;
print PSD "\n";
close(PSD);
$level=5;
}
if(($regda eq "1")&&($regdb ne "1")){
&send_html;
print "<html><head>\n";
print "<script Language=\"JavaScript\">\n";
print "alert(\"名字已被註冊或密碼錯誤! 請重新輸入\");\n";
print "history.back();";
print "</script></head></html>\n";
exit;
}
if($FORM{'page'}){$page = $FORM{'page'};}
else{$page =0;}
if($FORM{'slttitle'}){$slttitle = $FORM{'slttitle'};}
else{$slttitle =0;}
$hassend=0;
$hasreply=0;
   if($a_method eq "reply"){&reply; exit;}
   if($a_method eq "reg"){&reg;exit;}
   if($a_method eq "show"){&show; exit;}
   if($a_method eq "fabiao"){&fabiao;exit;}
   if($a_method eq "win"){&win;exit;}
   if($a_method eq "guest"){&guest;exit;}
   if($a_method eq "addtitle"){&addtitle; exit;}
   if($a_method eq "delreply"){&delreply; exit;}
   if($a_method eq "deltitle"){&deltitle; exit;}
&listtitle; 
exit;
##########
sub show{
$tmp=$_[0];

open(TITLES,"$bbsbook")|| die $!;
@hastitles=<TITLES>;
close(TITLES);
&send_html;
print <<EOF;
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
</head>
<style>
a { text-decoration: none; color: rgb(125,125,180) }
a:hover {color:red;text-decoration:underline}
td {font-size:9pt; line-height:13pt}
body{font-size:9pt; }
</style>
<style>input{font-size:9pt;color:#000080;background-color:#FFFFFF;padding-top:3px}<!--body,table a{text-decoration:none}a:hover{color:red;text-decoration:underline}--></style>
 <BODY BGCOLOR="#FEFCE0">
<p align="center">
EOF
if($titleimg ne ""){
print "<img src=$titleimg alt=$bbstitle>";
}else{
print "<font color=\"#0080ff\" face=\"黑體\" size = \"5\"><b>$bbstitle</b></font>";
}
print <<EOF;
</table>
<div align="center"><center>

<table border="0" borderColor="#008000" borderColorDark="#9EC49D"
borderColorLight="#65A264" cellPadding="0" cellSpacing="1" height="19">
  <tr>
    <td align="middle" bgColor="#a6caa4" height="8"
    style="BORDER-BOTTOM: rgb(69,113,68) 1px solid; BORDER-LEFT: rgb(69,113,68) 1px solid; BORDER-RIGHT: rgb(69,113,68) 1px solid; BORDER-TOP: rgb(69,113,68) 1px solid"
    vAlign="bottom" width="71"><a href="$cgiurl?a_method=fabiao&userpsd=$userpsd&username=$username">發表新文章</a></td>
    <td align="middle" bgColor="#a6caa4" height="8"
    style="BORDER-BOTTOM: rgb(69,113,68) 1px solid; BORDER-LEFT: rgb(69,113,68) 1px solid; BORDER-RIGHT: rgb(69,113,68) 1px solid; BORDER-TOP: rgb(69,113,68) 1px solid"
    vAlign="bottom" width="71"><a href="#newreply">回覆文章</a></td>
    <td align="middle" bgColor="#a6caa4" height="8"
    style="BORDER-BOTTOM: rgb(69,113,68) 1px solid; BORDER-LEFT: rgb(69,113,68) 1px solid; BORDER-RIGHT: rgb(69,113,68) 1px solid; BORDER-TOP: rgb(69,113,68) 1px solid"
    vAlign="bottom" width="76"><a href="$cgiurl?a_method=reg&userpsd=$userpsd&username=$username">資料修改</a></td>
    <td align="middle" bgColor="#a6caa4" height="8"
    style="BORDER-BOTTOM: rgb(69,113,68) 1px solid; BORDER-LEFT: rgb(69,113,68) 1px solid; BORDER-RIGHT: rgb(69,113,68) 1px solid; BORDER-TOP: rgb(69,113,68) 1px solid"
    vAlign="bottom" width="76"><a href="$cgiurl?a_method=guest&userpsd=$userpsd&username=$username">用戶管理</a></td>
    <td align="middle" bgColor="#a6caa4" height="8"
    style="BORDER-BOTTOM: rgb(69,113,68) 1px solid; BORDER-LEFT: rgb(69,113,68) 1px solid; BORDER-RIGHT: rgb(69,113,68) 1px solid; BORDER-TOP: rgb(69,113,68) 1px solid"
    vAlign="bottom" width="99"><a
    href="$cgiurl?a_method=listtitle&userpsd=$userpsd&username=$username">回主題頁</a></td>
  </tr>
</table>
EOF

foreach $m (@hastitles){
$m=~ s/\n//g;
if($m ne ""){
($rtitles,$rthistime,$rusername,$rcomment,$rfrom,$rhasreply,$rmail,$rhome)=split(/__/,$m);
if(($rthistime eq $slttitle)||($rthistime eq $tmp)){
$replytime=$rthistime;
$seachreply=$rhasreply;
$thistitle=$rtitles;
print<<EOF;
<table border=0 align="center" width="100%">
  <tr>
    <td bgColor="#95caff" width="100%"><table border="0" cellPadding="0" cellSpacing="0"
    width="100%">
<TBODY>
      <tr>
        <td width="60%"><img src="3.gif" width="15" height="13"> 您的位置 <img
        src="3.gif" width="15" height="13"> <a href="$outurl">$zyname</a> <img src="3.gif"
        width="15" height="13"> <a
        href="$cgiurl?a_method=listtitle&userpsd=$userpsd&username=$username">$bbstitle</a> 
        <img src="3.gif" width="15" height="13"> $rtitles</td>
      </tr>
    </table>
    </td>
  </tr>
</table>
<table border="0" width="100%">
  <tr>
    <td bgColor="#EEF7FF" width="100%">

EOF
print "<table border=\"0\" width=\"100%\">";
print "<tr>";
print "<td bgColor=\"#EEF7FF\" width=\"100%\"><div align=\"center\"><center><table bgColor=\"#51a8ff\" border=\"0\" cellPadding=\"2\" cellSpacing=\"1\">";
print "<tr>";
print "<td bgColor=\"#FFFFFF\" width=\"50\"><img src=5.gif>標題:</td>";
print "<td bgColor=\"#FFFFFF\" colspan=\"3\">$rtitles</td>";
print "</tr>";
print "<tr>";
if(($rusername eq $username)||($level<3)){
print "　<center>[<a href=$cgiurl?a_method=deltitle&deltitle=$rthistime&userpsd=$userpsd&username=$username>刪除</a>]<br>";
}
print "<td bgColor=\"#FFFFFF\" width=\"50\"><img src=5.gif>姓名:</td>";
print "<td bgColor=\"#FFFFFF\" width=\"200\"><a href=\"mailto:$rmail\">$rusername</a></td>";
print "<td bgColor=\"#FFFFFF\" width=\"50\"><img src=5.gif>主頁:</td>";
print "<td bgColor=\"#FFFFFF\" width=\"200\"><a href=\"$rhome\" target=_blank>$rhome</a></td>";
print "</tr>";
print "<tr>";
print "<td bgColor=\"#FFFFFF\" width=\"50\"><img src=5.gif>來自:</td>";
print "<td bgColor=\"#FFFFFF\" width=\"200\">$rfrom</td>";
print "<td bgColor=\"#FFFFFF\" width=\"50\"><img src=5.gif>日期:</td>";
print "<td bgColor=\"#FFFFFF\" width=\"200\">$rthistime</td>";
print "</tr>";
print "<tr>";
print "<td bgColor=\"#FFFFFF\" width=\"50\"><img src=5.gif>內容:</td>";
print "<td bgColor=\"#ffffff\" colSpan=\"3\">$rcomment</td>";
print "</tr>";
print "</table>";


EOF
   }
  }
 }
if($seachreply > 0){
open(REPLY,"$replybook")|| die $!;
@hasreply=<REPLY>;
close(REPLY);
foreach $m (@hasreply){
$m=~ s/\n//g;
if($m ne ""){
($rtime,$rthistime,$rusername,$rcomment,$rfrom,$rmail,$rhome)=split(/__/,$m);
if($rtime eq $replytime){
print <<EOF;
<br>
EOF
if(($rusername eq $username)||($level<3)){
print "[<a href=$cgiurl?a_method=delreply&deltitle=$rthistime&username=$username&userpsd=$userpsd>刪除</a>]<br>";
}
print "<div align=center><center><table bgcolor=#51a8ff border=0 cellPadding=2 ellSpacing=1>";

print "<table bgcolor=\"#51a8ff\" border=\"0\" cellPadding=\"2\" cellSpacing=\"1\">";
print "<td bgColor=\"#FFFFFF\" width=\"50\"><img src=5.gif>姓名:</td>";
print "<td bgColor=\"#FFFFFF\" width=\"200\"><a href=\"mailto:$rmail\">$rusername</a></td>";
print "<td bgColor=\"#FFFFFF\" width=\"50\"><img src=5.gif>主頁:</td>";
print "<td bgColor=\"#FFFFFF\" width=\"200\"><a href=\"$rhome\" target=_blank>$rhome</a></td>";
print "</tr>";
print "<tr>";
print "<td bgColor=\"#FFFFFF\" width=\"50\"><img src=5.gif>來自:</td>";
print "<td bgColor=\"#FFFFFF\" width=\"200\">$rfrom</td>";
print "<td bgColor=\"#FFFFFF\" width=\"50\"><img src=5.gif>日期:</td>";
print "<td bgColor=\"#FFFFFF\" width=\"200\">$rthistime</td>";
print "</tr>";
print "<tr>";
print "<td bgColor=\"#FFFFFF\" width=\"50\"><img src=5.gif>內容:</td>";
print "<td bgColor=\"#ffffff\" colSpan=\"3\">$rcomment</td>";
print "</tr>";
print "</table>";
EOF
}
}
}
}
print <<EOF;
</table>
<a name="newreply"></a>
<table border=0 align="center" width="100%">
<tr bgcolor="#95caff">
<td align=center width="100%"><b>回復：</b>$thistitle
</td></tr>
</table>
</table>
<FORM ACTION="$cgiurl" NAME="reply" METHOD="POST">

<table border=0 align="center">
<TR><td>
名字：<INPUT TYPE="TEXT" NAME="username" SIZE=20 MAXLENGTH=10 value=$username>
　密碼：<INPUT TYPE="password" NAME="userpsd" SIZE=28 MAXLENGTH=12 value=$userpsd>
<p>信箱：<INPUT TYPE="TEXT" NAME="mail" SIZE=20 MAXLENGTH=40>
　主頁：<INPUT TYPE="TEXT" NAME="home" VALUE="http://" SIZE=28 MAXLENGTH=50>
<p>內容：<TEXTAREA NAME="comment" ROWS=6 COLS=50 WRAP="VIRTUAL"></TEXTAREA>
</td></table>
<INPUT TYPE="HIDDEN" NAME="a_method" VALUE="reply">
<INPUT TYPE="HIDDEN" NAME="replytime" VALUE="$replytime">
<CENTER>第一次填寫的名字、密碼及資料將自動註冊、保存<br><br>
<INPUT TYPE="Submit" NAME="SUBMIT" VALUE="寫好了">
<INPUT TYPE="RESET" NAME="RESET" VALUE="重新寫">
</center></form>
<table align="center" bgColor="#79BCFF" border="0">
  <tr>
    <td bgColor="#FFFFFF" align="center"><p align="center"><img src="2.gif"><span
    style="FONT-SIZE: 9pt">頁面採用自動更新程式設計,程式製作<img
    src="2.gif"></td>
  </tr>
</table>
</body></html>
EOF
exit;
}
##########
sub addtitle{
if($level >5){
&sorry;
exit;
}
$comment=~ s/<([^>]|\n)*>/ /g;
$comment=~ s/>/&gt;/g;
$comment=~ s/</&lt;/g;
$comment=~ s/__/--/g;
$comment=~ s/\n/\<br\>/g;
$titles=~ s/<([^>]|\n)*>/ /g;
$titles=~ s/>/&gt;/g;
$titles=~ s/</&lt;/g;
$titles=~ s/__/--/g;
$titles=~ s/\n//g;
$username=~ s/<([^>]|\n)*>/ /g;
$username=~ s/>/&gt;/g;
$username=~ s/</&lt;/g;
$username=~ s/__/--/g;
$username=~ s/\n//g;

if(($titles eq "")||($username eq "")){
&send_html;
print <<EOF;
<html>
<head>
<script Language="JavaScript">
 alert("主題不能為空！");
history.back();
</script>
</head>
<body>
</body>
</html>
EOF
exit;
}  
open(PSD,"$psdbook")|| die $!;
@lines=<PSD>;
close(PSD);
open(PSD,">$psdbook")|| die $!;
foreach $line (@lines) {
$line=~ s/\n//g;
if($line ne ""){
($rdlevel,$rdpassword,$rdname,$rdmail,$rdhome,$rlast)=split(/__/,$line);
if($username eq $rdname){
print PSD $rdlevel."__".$rdpassword."__".$rdname."__".$rdmail."__".$rdhome."__".$lasttime."\n";
}else{
print PSD $line."\n";
}
}
}
close(PSD);
open(TITLES,"$bbsbook")|| die $!;
@hastitles=<TITLES>;
close(TITLES);
$size=@hastitles;
$newtitle=$titles."__".$thistime."__".$username."__".$comment."__".$from."__".$hasreply."__".$mail."__".$home."__--__".$thistime;
open(TITLES,">$bbsbook")|| die $!;
print TITLES "$newtitle\n";
for($i=0;$i<=$size;$i++){
if($i < 399){
$m=@hastitles[$i];
print TITLES "$m";
}else{
($rtitles,$rthistime,$rusername,$rcomment,$rfrom,$rhasreply,$rmail,$rhome,$lastname,$lasttime)=split(/__/,$m);
if($rhasreply >0){
&delreply($rthistime);
}
}
}
close(TITLES);
&send_html;
print <<EOF;
<html>
<head>
</head>
<body>
<meta http-equiv="refresh" content="0;url=$cgiurl?a_method=win&userpsd=$userpsd&username=$username">
</body>
</html>
EOF

exit;

}
##########
sub send_html {
  if ($has_send ne "1") {
    print "Content-type: text/html\n\n";
    $has_send = "1";
  }
}
##########
sub listtitle{
open(TITLES,"$bbsbook")|| die $!;
@hastitles=<TITLES>;
close(TITLES);
$size=@hastitles;
open(TITLES,"$replybook")|| die $!;
@replynum=<TITLES>;
close(TITLES);
$size1=@replynum;
$size2=$size+$size1;
&send_html;
print <<EOF;
<html>

<head>
<title>$bbstitle</title>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<style>
a { text-decoration: none; color: rgb(0,120,120) }
a:visited {color: rgb(100,100,100) }
a:hover {color:red;text-decoration:underline}
td {font-size:9pt}
</style>
</head>
<body bgcolor="#dfefff" topmargin="0">
<table border="0" width="100%" cellspacing="0" cellpadding="0">
  <tr>
    <td width="50%" align="center" >
EOF
if($titleimg ne ""){
print "<img src=$titleimg alt=$bbstitle>";
}else{
print "<font color=#0080ff face=黑體 size = 5><b>$bbstitle</b></font>";
}
print <<EOF;
<table border="0" cellSpacing="1" width="100%">
  <tr>
    <td bgColor="#95caff" width="100%"><table border="0" cellPadding="0" cellSpacing="0"
    width="100%">
<TBODY>
      <tr>
        <td width="60%"><img src="3.gif"> 上網位置&nbsp; <img src="3.gif"> <a href="$outurl">$zyname</a> 
        <img src="3.gif"> $bbstitle</td>
        <td width="40%" align="right"><span style="font-size: 9pt"><img src="1.gif">文章數: <font
        color="#ff0000">$size2</font>&nbsp;&nbsp;<img src="1.gif">論題數: <font color="#ff0000">$size&nbsp;&nbsp;</font></span></td>
      </tr>
    </table>
    </td>
  </tr>
</table>
<table border="0" cellPadding="0" cellSpacing="0" height="16"
style="PADDING-LEFT: 10px; PADDING-RIGHT: 10px">
  <tr>
    <td height="16" style="BORDER-BOTTOM: rgb(66,109,65) 2px solid" vAlign="bottom"
    width="200">版主:<font color="#FF0000">$admname</font></td>
    <td height="16" style="BORDER-BOTTOM: rgb(66,109,65) 2px solid" width="500"><table
    border="0" width="100%" cellspacing="0" cellpadding="0">
      <tr>
        <td><div align="center"><center><table border="0" borderColor="#008000"
        borderColorDark="#9EC49D" borderColorLight="#65A264" cellPadding="0" cellSpacing="1"
        height="19">
<TBODY>
</TBODY>
          <tr>
            <td align="middle" bgColor="#a6caa4" height="8"
            style="BORDER-BOTTOM: rgb(69,113,68) 1px solid; BORDER-LEFT: rgb(69,113,68) 1px solid; BORDER-RIGHT: rgb(69,113,68) 1px solid; BORDER-TOP: rgb(69,113,68) 1px solid"
            vAlign="bottom" width="71"><a href="$cgiurl?a_method=fabiao&userpsd=$userpsd&username=$username">發表文章</a></td>
            <td align="middle" bgColor="#a6caa4" height="8"
            style="BORDER-BOTTOM: rgb(69,113,68) 1px solid; BORDER-LEFT: rgb(69,113,68) 1px solid; BORDER-RIGHT: rgb(69,113,68) 1px solid; BORDER-TOP: rgb(69,113,68) 1px solid"
            vAlign="bottom" width="76"><a href="$cgiurl?a_method=reg&userpsd=$userpsd&username=$username">資料修改</a></td>
            <td align="middle" bgColor="#a6caa4" height="8"
            style="BORDER-BOTTOM: rgb(69,113,68) 1px solid; BORDER-LEFT: rgb(69,113,68) 1px solid; BORDER-RIGHT: rgb(69,113,68) 1px solid; BORDER-TOP: rgb(69,113,68) 1px solid"
            vAlign="bottom" width="76"><a href="$cgiurl?a_method=guest&userpsd=$userpsd&username=$username">用戶管理</a></td>
          </tr>
        </table>
        </center></div></td>
      </tr>
    </table>
    </td>
    <td height="16" style="BORDER-BOTTOM: rgb(66,109,65) 2px solid" vAlign="bottom"
    width="200"><p align="right">目前共有<font color="#FF0000">$people</font>人在線上</td>
  </tr>
</table>
<table border="1" align="center" width="100%" cellpadding="0" cellspacing="0"
bordercolor="#86C2FF">
  <tr bgcolor="#b0d8ff" align="center">
    <td width="40%">文章標題</td>
    <td width="14%">網友是:</td>
    <td width="12%">回複數</td>
    <td width="14%">最後回復</td>
    <td width="20%">最後更新時間</td>
  </tr>
EOF
$chgcolor=0;

for ($i=$page; $i<$page+40; $i++){
$hastitle=@hastitles[$i];
$hastitle=~ s/\n//g;
if($hastitle ne ""){
($rtitles,$rthistime,$rusername,$rcomment,$rfrom,$rhasreply,$mail,$home,$lastname,$lasttime)=split(/__/,$hastitle);
if($chgcolor==0){
print <<EOF;
  <tr BGCOLOR="#F9F7F2" align="center">
    <td align="left"><img src="6.gif"> <a href="$cgiurl?a_method=show&slttitle=$rthistime&username=$username&userpsd=$userpsd">$rtitles</a></td>
    <td>$rusername</td>
    <td>$rhasreply</td>
    <td>$lastname</td>
    <td>$lasttime</td>
  </tr>
EOF
$chgcolor=1;
}else{
print <<EOF;
  <tr BGCOLOR="#FEF1FE" align="center">
    <td align="left"><img src="6.gif"> <a href="$cgiurl?a_method=show&slttitle=$rthistime&username=$username&userpsd=$userpsd">$rtitles</a></td>
    <td>$rusername</td>
    <td>$rhasreply</td>
    <td>$lastname</td>
    <td>$lasttime</td>
  </tr>
EOF
$chgcolor=0;
}
}
}
print <<EOF; 
</table>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
  <tr>
    <td width="100%" align="right"><form ACTION="$cgiurl" METHOD="POST">
    <input type="hidden" name="userpsd" value="$userpsd">
    <input type="hidden" name="username" value="$username">
    <input type="hidden" name="a_method" value="listtitle">
    <input type="hidden" name="number" value="1">
    <img src="4.gif">查看<select TYPE="SUBMIT" NAME="page" onchange="submit();" size="1">
        <option value=0 SELECTED> 第1頁 </option>
EOF
if($size>40){
print "<option value=40";
if($page eq "40"){print " SELECTED";
}
print "> 第2頁 \n";
}
if($size>40){
print "<option value=40";
if($page eq "40"){print " SELECTED";
}
print "> 第3頁 \n";
}
if($size>60){
print "<option value=60";
if($page eq "60"){print " SELECTED";
}
print "> 第4頁 \n";
}
if($size>80){
print "<option value=80";
if($page eq "80"){print " SELECTED";
}
print "> 第5頁 \n";
}
if($size>100){
print "<option value=100";
if($page eq "100"){print " SELECTED";
}
print "> 第6頁 \n";
}
if($size>120){
print "<option value=120";
if($page eq "120"){print " SELECTED";
}
print "> 第7頁 \n";
}
if($size>140){
print "<option value=140";
if($page eq "140"){print " SELECTED";
}
print "> 第8頁 \n";
}
if($size>160){
print "<option value=160";
if($page eq "160"){print " SELECTED";
}
print "> 第9頁 \n";
}
if($size>180){
print "<option value=180";
if($page eq "180"){print " SELECTED";
}
print "> 第10頁 \n";
}
if($size>200){
print "<option value=200";
if($page eq "200"){print " SELECTED";
}
print "> 第11頁 \n";
}
if($size>220){
print "<option value=220";
if($page eq "220"){print " SELECTED";
}
print "> 第12頁 \n";
}
if($size>240){
print "<option value=240";
if($page eq "240"){print " SELECTED";
}
print "> 第13頁 \n";
}
if($size>260){
print "<option value=260";
if($page eq "260"){print " SELECTED";
}
print "> 第14頁 \n";
}
if($size>280){
print "<option value=280";
if($page eq "280"){print " SELECTED";
}
print "> 第15頁 \n";
}
if($size>300){
print "<option value=300";
if($page eq "300"){print " SELECTED";
}
print "> 第16頁 \n";
}
if($size>320){
print "<option value=320";
if($page eq "320"){print " SELECTED";
}
print "> 第17頁 \n";
}
if($size>340){
print "<option value=340";
if($page eq "340"){print " SELECTED";
}
print "> 第18頁 \n";
}
if($size>360){
print "<option value=360";
if($page eq "360"){print " SELECTED";
}
print "> 第19頁 \n";
}
if($size>380){
print "<option value=380";
if($page eq "360"){print " SELECTED";
}
print "> 第20頁 \n";
}
print <<EOF;
      </select>的文章
    </form>
</td>
  </tr>
</table>
<table align="center" bgColor="#79BCFF" border="0">
  <tr>
    <td bgColor="#FFFFFF" align="center"><p align="center"><img src="2.gif"><span
    style="FONT-SIZE: 9pt">本網用自動更新程式設計,</span><img
    src="2.gif"></td>
  </tr>
</table>
</table>
</html>
EOF
exit;
}
##########
sub reply{
if($level > 5){
&sorry;
exit;
}
$comment=~ s/<([^>]|\n)*>/ /g;
$comment=~ s/>/&gt;/g;
$comment=~ s/</&lt;/g;
$comment=~ s/__/--/g;
$comment=~ s/\n/\<br\>/g;

if(($comment eq "")||($username eq "")){
&send_html;
print <<EOF;
<html>
<head>
<script Language="JavaScript">
 alert("內容不能為空！");
history.back();
</script>
</head>
<body>
</body>
</html>
EOF
exit;
}  
open(PSD,"$psdbook")|| die $!;
@lines=<PSD>;
close(PSD);
open(PSD,">$psdbook")|| die $!;
foreach $line (@lines) {
$line=~ s/\n//g;
if($line ne ""){
($rdlevel,$rdpassword,$rdname,$rdmail,$rdhome,$rlast)=split(/__/,$line);
if($username eq $rdname){
print PSD $rdlevel."__".$rdpassword."__".$rdname."__".$rdmail."__".$rdhome."__".$lasttime."\n";
}else{
print PSD $line."\n";
}
}
}
close(PSD);
open(TITLES,"$bbsbook")|| die $!;
@hastitles=<TITLES>;
close(TITLES);
foreach $m (@hastitles){
$m=~ s/\n//g;
if($m ne ""){
($rtitles,$rthistime,$rusername,$rcomment,$rfrom,$rhasreply,$ramil,$rhome,$rlastname,$rlasttime)=split(/__/,$m);
if($rthistime eq $replytime){
$rhasreply=$rhasreply+1;
$newtitle=$rtitles."__".$rthistime."__".$rusername."__".$rcomment."__".$rfrom."__".$rhasreply."__".$rmail."__".$rhome."__".$username."__".$thistime;
}
}
}
open(TITLES,">$bbsbook")|| die $!;
print TITLES $newtitle."\n";
foreach $m (@hastitles){
$m=~ s/\n//g;
if($m ne ""){
($rtitles,$rthistime,$rusername,$rcomment,$rfrom,$rhasreply,$ramil,$rhome,$rlastname,$rlasttime)=split(/__/,$m);
if($rthistime eq $replytime){
}else{
print TITLES $m."\n";
}
}
}
close(TITLES);


$addreply=$replytime."__".$thistime."__".$username."__".$comment."__".$from."__".$mail."__".$home;
open(REPLY,">>$replybook")|| die $!;
print REPLY $addreply."\n";
close(REPLY);
&send_html;
print <<EOF;
<html>
<head>
</head>
<body>
<meta http-equiv="refresh" content="0;url=$cgiurl?a_method=win&username=$username&userpsd=$userpsd">
</body>
</html>
EOF

exit;

}
##########
sub sorry{
&send_html;
print <<EOF;
<html>
<head></head>
<body>
<script>
alert('您沒有輸入正確的名字與密碼，或者是名字已被註冊');
history.back();
</script>
</body>
</html>
EOF
exit;
}
##########
sub deltitle{
#if($password ne $userpsd){
#&sorry;
#exit;
#}

open(TITLES,"$bbsbook")|| die $!;
@hastitles=<TITLES>;
close(TITLES);
open(TITLES,">$bbsbook")|| die $!;
foreach $m (@hastitles){
$m=~ s/\n//g;
if($m ne ""){
($rtitles,$rthistime,$rusername,$rcomment,$rhassee,$rhasreply)=split(/__/,$m);
if($rthistime ne $deltitle){
print TITLES $m."\n";
}
}
}
close(TITLES);


open(TITLES,"$replybook")|| die $!;
@hastitles=<TITLES>;
close(TITLES);
open(TITLES,">$replybook")|| die $!;
foreach $m (@hastitles){
$m=~ s/\n//g;
if($m ne ""){
($rtime,$rthistime,$rusername,$rcomment)=split(/__/,$m);
if($rtime ne $deltitle){
print TITLES $m."\n";
}
}
}
close(TITLES);
&listtitle;
exit;
}
##########
sub delreply{

if($_[0]){
$deltitle=$_[0];
open(TITLES,"$replybook")|| die $!;
@hastitles=<TITLES>;
close(TITLES);
open(TITLES,">$replybook")|| die $!;
foreach $m (@hastitles){
$m=~ s/\n//g;
if($m ne ""){
($rtime,$rthistime,$rusername,$rcomment)=split(/__/,$m);
if($rtime ne $deltitle){
print TITLES $m."\n";
}
}
}
}else{
open(TITLES,"$replybook")|| die $!;
@hastitles=<TITLES>;
close(TITLES);
open(TITLES,">$replybook")|| die $!;
foreach $m (@hastitles){
$m=~ s/\n//g;
if($m ne ""){
($rtime,$rthistime,$rusername,$rcomment,$rfrom,$rmail,$rhome)=split(/__/,$m);
if($rthistime ne $deltitle){
print TITLES $m."\n";
}
else{
$n=$rtime;
}
}
}
&show($n);
exit;
}
}
##########
sub fabiao{
&send_html;
print <<EOF;
<html>
<head>
<title>發表文章</title>
<body bgcolor="#FFF4FD">
<style>
td {font-size:9pt;line-height:13pt;}
</style>
<style>input{font-size:9pt;color:#000080;background-color:#FFFFFF;padding-top:3px}<!--body,table a{text-decoration:none}a:hover{color:red;text-decoration:underline}--></style>
<p align="center">
EOF
if($titleimg ne ""){
print "<img src=$titleimg alt=$bbstitle>";
}else{
print "<font color=\"#0080ff\" face=\"黑體\" size = \"5\"><b>$bbstitle</b></font>";
}
print <<EOF;
</table>
<table border="0" align="center" width="100%">
  <tr>
    <td bgColor="#95caff" width="100%"><table border="0" cellPadding="0" cellSpacing="0"
    width="100%">
<TBODY>
      <tr>
        <td width="60%"><img src="3.gif" width="15" height="13"> 上線位置 <img src="3.gif"
        width="15" height="13"> <a href="$outurl">$zyname</a> <img src="3.gif" width="15"
        height="13"> <a
        href="$cgiurl?a_method=listtitle&userpsd=$userpsd&username=$username">$bbstitle</a> 
        <img src="3.gif" width="15" height="13"> 發表文章</td>
      </tr>
    </table>
    </td>
  </tr>
</table>

<table align="center">
  <tr>
    <td><form ACTION="$cgiurl" METHOD="POST" align="center">
      <input type="hidden" name="a_method" value="addtitle"><input type="hidden"><table border="0" cellpadding="3" cellspacing="0" width="550"
      bgcolor="#BDFDE3">
        <tr>
          <td width="100%" colspan="2" height="15" bgcolor="#769801"
          align="center&gt;&lt;font color=" #FFFFFF"><font color="#FFFFFF">發表文章</font></td>
        </tr>
        <tr>
          <td align="center" rowspan="4"></td>
          <td align="center">姓名:<input type="text" size="25" maxlength="10" name="username"
          value="$username"> &nbsp;&nbsp;密碼: <input type="password" size="25" maxlength="12"
          name="userpsd" VALUE="$userpsd"> </td>
        </tr>
        <tr>
          <td align="center">信箱:<input type="text" size="25" maxlength="45" name="mail" value> 
          &nbsp;&nbsp;主頁: <input type="text" name="home" size="25" maxlength="50"
          value="http://"> </td>
        </tr>
        <tr>
          <td align="center">主題:<input NAME="titles" VALUE SIZE="61" MAXLENGTH="80"></td>
        </tr>
        <tr>
          <td align="center">內容:<textarea NAME="comment" ROWS="6" COLS="51" WRAP="VIRTUAL"></textarea></td>
        </tr>
        <tr>
          <td colspan="2" align="center"><div align="center"><center>
<p><input TYPE="SUBMIT"
          NAME="Submit" VALUE="寫好啦"> &nbsp;&nbsp;<input TYPE="RESET" NAME="Reset"
          VALUE="重新寫"></td>
        </tr>
        <tr align="center"><p>&nbsp;</p>
          <td colspan="2" align="center">第一次填寫的名字、密碼及資料將自動註冊、保存</td>
        </tr>
      </table>
    </form>
    <div align="center"><center><table align="center" bgColor="#79BCFF" border="0">
  <tr>
    <td bgColor="#FFFFFF" align="center"><p align="center"><img src="2.gif"><span
    style="FONT-SIZE: 9pt">本網採用自動更新程式設計</span><img
    src="2.gif"></td>
  </tr>
</table>
    </center></div></td>
  </tr>
</table>
</body>
</html>
EOF
exit;
}
##########
sub win{
&send_html;
print <<EOF;
<html>

<head>
<title></title>
<meta HTTP-EQUIV="REFRESH"
CONTENT="2;URL=$cgiurl?a_method=listtitle&userpsd=$userpsd&username=$username">
</head>

<body bgcolor="#FFF4FD">

<p align="center">　</p>

<p align="center">　</p>

<p align="center">謝謝$username,正在寫入留言中! </p>

<p align="center">【<a
href="$cgiurl?a_method=listtitle&userpsd=$userpsd&username=$username">回$bbstitle</a>】 
</p>

<p align="center"><strong><big>2秒鐘後自動返回......</big></strong></p>

<table align="center" bgColor="#79BCFF" border="0">
  <tr>
    <td bgColor="#FFFFFF" align="center"><p align="center"><img src="2.gif"><span
    style="FONT-SIZE: 9pt">本網採用自動更新程式設計</span><img
    src="2.gif"></td>
  </tr>
</table>
</body>
</html>
EOF
exit;
}
##########
sub guest{
&send_html;
print <<EOF;
<html>
<head>
<title>用戶管理</title>
<body bgcolor="#FFF4FD">
<style>
td {font-size:9pt;line-height:13pt;}
</style>
<style>input{font-size:9pt;color:#000080;background-color:#FFFFFF;padding-top:3px}<!--body,table a{text-decoration:none}a:hover{color:red;text-decoration:underline}--></style>
<p align="center">
EOF
if($titleimg ne ""){
print "<img src=$titleimg alt=$bbstitle>";
}else{
print "<font color=\"#0080ff\" face=\"黑體\" size = \"5\"><b>$bbstitle</b></font>";
}
print <<EOF;
</table>
<table border="0" align="center" width="100%">
  <tr>
    <td bgColor="#95caff" width="100%"><table border="0" cellPadding="0" cellSpacing="0"
    width="100%">
<TBODY>
      <tr>
        <td width="60%"><img src="3.gif" width="15" height="13"> 上線的位置 <img src="3.gif"
        width="15" height="13"> <a href="$outurl">$zyname</a> <img src="3.gif" width="15"
        height="13"> <a
        href="$cgiurl?a_method=listtitle&userpsd=$userpsd&username=$username">$bbstitle</a> 
        <img src="3.gif" width="15" height="13"> 用戶管理</td>
      </tr>
    </table>
    </td>
  </tr>
</table>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
  <tr>
    <td align="center" valign="bottom"><form action="$cgiurl">
      <table border="0" cellpadding="3" cellspacing="0" width="400" bgcolor="#BDFDE3">
        <tr>
          <td width="100%" colspan="2" height="15" bgcolor="#769801"><font color="#FFFFFF">用戶管理</font></td>
        </tr>
        <tr>
          <td align="center">姓名：<input TYPE="TEXT" NAME="username" SIZE="20" MAXLENGTH="10"
          value="$username"></td>
          <td align="center">密碼：<input TYPE="password" NAME="userpsd" SIZE="20" MAXLENGTH="12"
          VALUE="$userpsd"></td>
        </tr>
        <tr>
          <td colspan="2" align="center"><input TYPE="SUBMIT" NAME="Submit" VALUE="管理文章"></td>
        </tr>
      </table>
    </form>
    </td>
  </tr>
</table>
<table align="center" bgColor="#79BCFF" border="0">
  <tr>
    <td bgColor="#FFFFFF" align="center"><p align="center"><img src="2.gif"><span
    style="FONT-SIZE: 9pt">本網採用自動更新程式設計,</span><img
    src="2.gif"></td>
  </tr>
</table>
</body>
</html>
EOF
exit;
}
##########
sub reg{
&send_html;
print <<EOF;
<html>

<head>
<title>資料修改</title>
<body bgcolor="#FFF4FD">
<style>
td {font-size:9pt;line-height:13pt;}
</style>
<style>input{font-size:9pt;color:#000080;background-color:#FFFFFF;padding-top:3px}<!--body,table a{text-decoration:none}a:hover{color:red;text-decoration:underline}--></style>
</head>
<p align="center">
EOF
if($titleimg ne ""){
print "<img src=$titleimg alt=$bbstitle>";
}else{
print "<font color=\"#0080ff\" face=\"黑體\" size = \"5\"><b>$bbstitle</b></font>";
}
print <<EOF;
</table>
<table border="0" align="center" width="100%">
  <tr>
    <td bgColor="#95caff" width="100%"><table border="0" cellPadding="0" cellSpacing="0"
    width="100%">
<TBODY>
      <tr>
        <td width="60%"><img src="3.gif" width="15" height="13"> 上線位置 <img src="3.gif"
        width="15" height="13"> <a href="$outurl">$zyname</a> <img src="3.gif" width="15"
        height="13"> <a
        href="$cgiurl?a_method=listtitle&userpsd=$userpsd&username=$username">$bbstitle</a> 
        <img src="3.gif" width="15" height="13"> 資料修改</td>
      </tr>
    </table>
    </td>
  </tr>
</table>

<form method="post" action="$cgiurl">
  <input type="hidden" name="a_method" value="reguser"><div align="center"><center><table border="0" cellpadding="3"
  cellspacing="0" width="480" bgcolor="#BDFDE3">
    <tr>
      <td width="100%" colspan="2" height="15" bgcolor="#769801"><font color="#FFFFFF">修改資料</font></td>
    </tr>
    <tr>
      <td width="9%">&nbsp;姓名:</td>
      <td><input type="text" size="25" maxlength="10" name="username" value="$username">&nbsp;密碼:&nbsp;<input type="password" size="25" maxlength="12" name="userpsd" value="$userpsd"> </td>
    </tr>
    <tr>
      <td>&nbsp;信箱:</td>
      <td><input type="text" size="25" maxlength="45" name="mail" value>&nbsp;主頁:&nbsp;<input
      type="text" name="home" size="25" maxlength="50" value="http://"> </td>
    </tr>
    <tr>
      <td colspan="2"><div align="center"><center><p><br>
      修改資料時輸入的信箱與主頁將自動顯示在發佈的消息及回貼中。<br>
      <br>
      </td>
    </tr>
    <tr align="center">
      <td width="100%" colspan="2"><input type="submit" value="送  出"> 
      &nbsp;&nbsp;&nbsp;&nbsp; <input type="reset" value="清  除"></td>
    </tr>
  </table>
  </center></div>
</form>
<table align="center" bgColor="#79BCFF" border="0">
  <tr>
    <td bgColor="#FFFFFF" align="center"><p align="center"><img src="2.gif"><span
    style="FONT-SIZE: 9pt">」</span><img
    src="2.gif"></td>
  </tr>
</table>
</body>
</html>
EOF
exit;
}
##########
sub reguser{
if(($userpsd eq "")||($username eq "")){
&send_html;
print "<html><head>\n";
print "<script Language=\"JavaScript\">\n";
print "alert(\"名字與密碼必須要填寫的， 不要亂寫請重新輸入\");\n";
print "history.back();";
print "</script></head></html>\n";
exit;
}
$regd=1;
$level=5;
open(PSD,"$psdbook")|| die $!;
@lines=<PSD>;
close(PSD);
foreach $line (@lines) {
$line=~ s/\n//g;
($rdlevel,$rdpassword,$rdname,$rdmail,$rdhome,$rlast)=split(/__/,$line);
if($username eq $rdname){
$regda=1;
if($userpsd eq $rdpassword){
$regdb=1;
$level=$rdlevel;
}
}
}
if(($regdb eq "1")||($regda ne "1")){
if($newpsd ne ""){$userpsd=$newpsd;}
open(PSD,">$psdbook")|| die $!;
foreach $line (@lines) {
$line=~ s/\n//g;
($rdlevel,$rdpassword,$rdname,$rdmail,$rdhome,$rlast)=split(/__/,$line);
if($username eq $rdname){
print PSD $level."__".$userpsd."__".$username."__".$mail."__".$home."__".$lasttime;
print PSD "\n";
}else{
print PSD $line."\n";
}
}
close(PSD);

}

if(($regda eq "1")&&($regdb ne "1")){
&send_html;
print "<html><head>\n";
print "<script Language=\"JavaScript\">\n";
print "alert(\"名字已被註冊! 換一個吧！\");\n";
print "history.back();";
print "</script></head></html>\n";
exit;
}

&send_html;
print "<html><head>\n";
print "<script Language=\"JavaScript\">\n";
print "alert(\"您的資料已經更新！\");\n";
print "window.location.href=\"$cgiurl?username=$username&userpsd=$userpsd\"";
print "</script></head></html>\n";
exit;
}