#! /usr/bin/perl

$script = "bbs.cgi" ;

$pass_file = "pass_file.cgi" ;

$data_dir = "data" ;

$setting = "set.cgi" ;

$page = "5";

$s_cnt = 0;


# ------------------------------------------------------------------------------

require "$setting" ;
&decode ;

# ------------------------------------------------------------------------------

if ($in{'mode'} eq "p_move") {$s_cnt = $in{'s_cnt'};}


open (IN,"$pass_file") ;
@ppp = <IN> ;
close (IN) ;

foreach (@ppp) {
  ($file,$id,$pass,$title) = split (/<>/) ;
  if ($in{'id'} eq "$id" && $in{'pass'} eq "$pass") {
    $main_flag = "1" ;
    last ;
  } else {
    next ;
  }
}

if ($main_flag eq "1") {
  &bbs_main("$file","$id","$pass","$title") ;
} elsif ($in{'entyo'} eq "1") {
  &bbs_main("2006101815483524008","en","tyo","園長先生の日記") ;
} else {
  &id_pass ;
}

# ------------------------------------------------------------------------------

sub id_pass {

# &head("#FFFFFF","#000000","IDとPASSを入力してください。") ;
# $head = "1" ;

print "Content-type:text/html\n\n" ;

print <<"EOM" ;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<title>二葉通信</title>
<link href="../fonts.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="$style_file">
</head>

<body bgcolor="#DEE1C8" text="#666666" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<table width="761" height="100%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
  <tr>
    <td width="16" height="7" valign="top" background="../image/b02.jpg"><img src="../image/b01.jpg" width="16" height="7"></td>
    <td width="180" rowspan="3" valign="top"><table width="180" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td><img src="../image/t01.gif" width="180" height="7"></td>
      </tr>
      <tr>
        <td><div align="center"><img src="../image/logo01.gif" width="180" height="115"><br>
              <img src="../image/logo02.jpg" width="180" height="70"><br>
              <a href="../pc_index.html"><img src="../image/bt00.gif" alt="トップページ" width="180" height="25" border="0"></a><br>
              <a href="../rekishi.html"><img src="../image/bt01.gif" alt="二葉幼稚園の歴史" width="180" height="25" border="0"></a><br>
              <a href="../gaiyou.html"><img src="../image/bt02.gif" alt="二葉幼稚園の概要" width="180" height="25" border="0"></a><br>
              <a href="../days.html"><img src="../image/bt03.gif" alt="二葉幼稚園での一日" width="180" height="25" border="0"></a><br>
              <a href="../address.html"><img src="../image/bt04.gif" alt="二葉幼稚園の所在地" width="180" height="25" border="0"></a><br>
              <img src="../image/b05.gif" width="180" height="22"><br>
              <a href="../sch/sche.cgi"><img src="../image/bt05.gif" width="180" height="25" border="0" alt="スケジュール"></a><br>
            <a href="../gaiyou.html#gai11"><img src="../image/sumire.gif" alt="スケジュール" width="180" height="25" border="0"></a><br>
              <a href="$script?entyo=1"><img src="../image/bt06.gif" width="180" height="25" border="0" alt="園長先生の日記"></a><br>
<a href="../glossary.html"><img src="../image/2.gif" alt="二葉基礎用語集" width="180" height="25" border="0"></a><br>
<a href="../entrance.html"><img src="../image/b_en.gif" alt="入園のご案内" width="180" height="25" border="0"></a><br>
<a href="../paper.html"><img src="../image/11.gif" alt="届出用紙ダウンロード" width="180" height="25" border="0"></a><br>
              <a href="../mail.cgi"><img src="../image/bt07.gif" width="180" height="25" border="0" alt="お問い合わせ"></a><br>
              <img src="../image/b05.gif" width="180" height="22"><br>
              <br>
              <a href="$script"><img src="../image/bana01.jpg" width="166" height="56" border="0" alt="二葉通信"></a> 
            </div></td>
      </tr>
    </table>
    </td>
    <td width="549" rowspan="2" valign="top" background="../image/b04.jpg"><table width="549" border="0" cellpadding="0" cellspacing="0" class="font12-1">
        <tr> 
          <td width="549" height="9" colspan="2"><img src="../image/t02.jpg" width="549" height="9"></td>
        </tr>
        <tr>
          <td colspan="2"><img src="../image/futabatsushin_img01.jpg" width="549" height="208"></td>
        </tr>
        <tr>
          <td><img src="../image/spase.gif" width="19" height="60"></td>
          <td width="549" valign="bottom"><img src="../image/bbs_02.gif" width="530" height="47"></td>
        </tr>
        <tr>
          <td rowspan="3"><img src="../image/spase.gif" width="19" height="8"></td>
          <td>　</td>
        </tr>
        <tr>
          <td>
            <table border="0" cellpadding="2" cellspacing="1" width="521" bgcolor="#F0EEEC" class="font12-1">
              <tr>
                <td align="center">




<form action="$script" method="POST">
<table border="0" cellpadding="2" cellspacing="0" align="center">
<tr>
<td colspan="2"><font color="#ff0000" size="2">IDとPASSを入力してください。<BR></font></td>
</tr>
<tr>
<td><font size="2">ID　</font></td>
<td><input type="text" name="id" size="8"></td><BR>
</tr>
<tr>
<td><font size="2">PASS</font></td>
<td><input type="password" name="pass" size="8"></td><BR>
</tr>
<tr>
<td colspan="2">　</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="送信"></td>
</tr>
</table>
</form>




</td>
</tr>
</table>
</td>
        </tr>
      </table></td>
    <td width="16" rowspan="3" valign="top" background="../image/b03.jpg"><img src="../image/b03.jpg" width="16" height="1"></td>
  </tr>
  <tr>
    <td rowspan="2" valign="top" background="../image/b02.jpg"><img src="../image/b02.jpg" width="16" height="1"></td>
  </tr>
  <tr>
    <td valign="bottom" background="../image/b04.jpg">
    <br><br><br>
<table width="549" border="0" cellpadding="0" cellspacing="0">
      <tr>
          <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr> 
                <td width="19"><img src="../image/spase.gif" width="19" height="10"></td>
                <td><table width="530" border="0" cellspacing="0" cellpadding="0" class="font10">
                    <tr> 
                      <td width="103"><img src="../image/logo03.gif" width="93" height="10"></td>
                      <td>〒951-8118 新潟市中央区西中町714番地 TEL 025-222-4509 FAX 025-222-9130</td>
                    </tr>
                  </table></td>
              </tr>
              <tr> 
                <td colspan="2"><img src="../image/spase.gif" width="5" height="5"></td>
              </tr>
              <tr> 
                <td colspan="2"><img src="../image/bot03.jpg" width="549" height="29"></td>
              </tr>
            </table>
          </td>
      </tr>
    </table>
    </td>
  </tr>
</table>
EOM

&foot ;

}

# ------------------------------------------------------------------------------

sub bbs_main {

($file,$k_id,$k_pass,$k_title) = @_ ;

if ($k_id eq "en" && $k_pass eq "tyo") {
  $in{'entyo'} = "1" ;
}

open (IN,"$data_dir/$file/data.cgi") ;
@oo = <IN> ;
close (IN) ;

@sorted = sort { (split(/<>/, $b))[0] cmp (split(/<>/, $a))[0] } @oo;

$e_cnt = $s_cnt + $page -1;
if ($e_cnt > $#sorted) {$e_cnt = $#sorted;}


$i = "0" ;
$img_flag = "0" ;
foreach ($s_cnt .. $e_cnt) {
  chomp ;
  ($b_file,$b_name,$b_year,$b_mon,$b_day,$b_title,$b_comment,$b_image1,$b_image2,$b_image3) = split (/<>/,$sorted[$_]) ;

  $tmpri .= "<table width=\"521\" border=\"1\" cellpadding=\"5\" cellspacing=\"0\" bordercolor=\"#E0DCD8\" style=\"font-size:12px;line-height:18px\">\n" ;
  $tmpri .= "<tr>\n" ;
  $tmpri .= "<td bgcolor=\"#E0DCD8\"><font color=\"#333333\"><b>$b_year/$b_mon/$b_day $b_title ($b_name)</b></font></td>\n" ;
  $tmpri .= "</tr>\n" ;
  $tmpri .= "<tr>\n" ;
  $tmpri .= "<td>$b_comment<br>\n" ;
  $tmpri .= "<br>\n" ;
  if ($b_image1 ne "" || $b_image2 ne "" || $b_image3 ne "") {
    $tmpri .= "<table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"3\" style=\"font-size:12px;line-height:18px\">\n" ;
    $tmpri .= "<tr>\n" ;
    if ($b_image1) {
      $tmpri .= "<td align=\"center\"><a href=\"data/$file/$b_image1\" target=\"_blank\"><img src=\"data/$file/s$b_image1\" width=\"150\" height=\"113\" border=\"0\"></a><BR><font size=\"2\" color=\"#999999\">画像クリックで拡大</font></td>\n" ;
      $img_flag = "1" ;
    }
    if ($b_image2) {
      $tmpri .= "<td align=\"center\"><a href=\"data/$file/$b_image2\" target=\"_blank\"><img src=\"data/$file/s$b_image2\" width=\"150\" height=\"113\" border=\"0\"></a><BR><font size=\"2\" color=\"#999999\">画像クリックで拡大</font></td>\n" ;
      $img_flag = "1" ;
    }
    if ($b_image3) {
      $tmpri .= "<td align=\"center\"><a href=\"data/$file/$b_image3\" target=\"_blank\"><img src=\"data/$file/s$b_image3\" width=\"150\" height=\"113\" border=\"0\"></a><BR><font size=\"2\" color=\"#999999\">画像クリックで拡大</font></td>\n" ;
      $img_flag = "1" ;
    }
    $tmpri .= "</tr>\n" ;
    $tmpri .= "<tr>\n" ;
    $tmpri .= "</tr>\n" ;
    $tmpri .= "</table>\n" ;
  }
  $tmpri .= "</td>\n" ;
  $tmpri .= "</tr>\n" ;
  $tmpri .= "</table>\n" ;
  $tmpri .= "<br><br>\n" ;
}

$bn .= "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n<tr>\n";
  if ($s_cnt > 1) { 
    # Backを表示
#-------------------print "s:$s_cnt<BR>e:$e_cnt<BR>new:$#new";
    $back = $s_cnt - $page;
    $bn .= "<td>";
    $bn .= "<FORM action=\"$script\" method=\"POST\">\n";
    $bn .= "<INPUT type=\"hidden\" name=\"s_cnt\" value=\"$back\">\n";
    $bn .= "<INPUT type=\"hidden\" name=\"mode\" value=\"p_move\">\n";
    $bn .= "<INPUT type=\"hidden\" name=\"pass\" value=\"$in{'pass'}\">\n";
    $bn .= "<INPUT type=\"hidden\" name=\"id\" value=\"$in{'id'}\">\n";
    $bn .= "<INPUT type=\"hidden\" name=\"entyo\" value=\"$in{'entyo'}\">\n";
    $bn .= "<INPUT type=\"submit\" name=\"pbOk\" value=\"Back\" class=\"button\">\n";
    $bn .= "</FORM>\n";
    $bn .= "</td>";
  }
  if ($e_cnt < $#sorted) {
    # NEXTを表示]
#-------------------print "s:$s_cnt<BR>e:$e_cnt<BR>new:$#new";
    $next = $s_cnt + $page;
    $bn .= "<td>";
    $bn .= "<FORM action=\"$script\" method=\"POST\">\n";
    $bn .= "<INPUT type=\"hidden\" name=\"s_cnt\" value=\"$next\">\n";
    $bn .= "<INPUT type=\"hidden\" name=\"mode\" value=\"p_move\">\n";
    $bn .= "<INPUT type=\"hidden\" name=\"pass\" value=\"$in{'pass'}\">\n";
    $bn .= "<INPUT type=\"hidden\" name=\"id\" value=\"$in{'id'}\">\n";
    $bn .= "<INPUT type=\"hidden\" name=\"entyo\" value=\"$in{'entyo'}\">\n";
    $bn .= "<INPUT type=\"submit\" name=\"pbOk\" value=\"Next\" class=\"button\">\n";
    $bn .= "</FORM>\n";
    $bn .= "</td>";
  }
$bn .= "</tr>\n</table>\n";

if ($in{'entyo'} eq "1") {
  $xxx1 = "<img src=\"../image/encyonikki_img01.jpg\" width=\"549\" height=\"208\">\n" ;
  $xxx2 = "<img src=\"../image/encyonikki_tit01.gif\" width=\"530\" height=\"47\">\n" ;
  $xxx3 = "" ;
} else {
  $xxx1 = "<img src=\"../image/futabatsushin_img01.jpg\" width=\"549\" height=\"208\">\n" ;
  $xxx2 = "<img src=\"../image/bbs_02.gif\" width=\"530\" height=\"47\">\n" ;
  $xxx3 = "　<font color=\"#CC6699\" size=\"3\"><b>$k_title</b></font><br><br>\n" ;
}



# &head ("#FFFFFF","#000000","maryell.jp") ;
$head = "1" ;

print "Content-type:text/html\n\n" ;

print <<"EOM" ;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<title>二葉通信</title>
<link href="../fonts.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="$style_file">
</head>

<body bgcolor="#DEE1C8" text="#666666" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<table width="761" height="100%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
  <tr>
    <td width="16" height="7" valign="top" background="../image/b02.jpg"><img src="../image/b01.jpg" width="16" height="7"></td>
    <td width="180" rowspan="3" valign="top"><table width="180" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td><img src="../image/t01.gif" width="180" height="7"></td>
      </tr>
      <tr>
        <td><div align="center"><img src="../image/logo01.gif" width="180" height="115"><br>
              <img src="../image/logo02.jpg" width="180" height="70"><br>
              <a href="../pc_index.html"><img src="../image/bt00.gif" alt="トップページ" width="180" height="25" border="0"></a><br>
              <a href="../rekishi.html"><img src="../image/bt01.gif" alt="二葉幼稚園の歴史" width="180" height="25" border="0"></a><br>
              <a href="../gaiyou.html"><img src="../image/bt02.gif" alt="二葉幼稚園の概要" width="180" height="25" border="0"></a><br>
              <a href="../days.html"><img src="../image/bt03.gif" alt="二葉幼稚園での一日" width="180" height="25" border="0"></a><br>
              <a href="../address.html"><img src="../image/bt04.gif" alt="二葉幼稚園の所在地" width="180" height="25" border="0"></a><br>
              <img src="../image/b05.gif" width="180" height="22"><br>
              <a href="../sch/sche.cgi"><img src="../image/bt05.gif" width="180" height="25" border="0" alt="スケジュール"></a><br>
            <a href="../gaiyou.html#gai11"><img src="../image/sumire.gif" alt="スケジュール" width="180" height="25" border="0"></a><br>
              <a href="$script?entyo=1"><img src="../image/bt06.gif" width="180" height="25" border="0" alt="園長先生の日記"></a><br>
<a href="../glossary.html"><img src="../image/2.gif" alt="二葉基礎用語集" width="180" height="25" border="0"></a><br>
<a href="../entrance.html"><img src="../image/b_en.gif" alt="入園のご案内" width="180" height="25" border="0"></a><br>
<a href="../paper.html"><img src="../image/11.gif" alt="届出用紙ダウンロード" width="180" height="25" border="0"></a><br>
              <a href="../mail.cgi"><img src="../image/bt07.gif" width="180" height="25" border="0" alt="お問い合わせ"></a><br>
              <img src="../image/b05.gif" width="180" height="22"><br>
              <br>
              <a href="$script"><img src="../image/bana01.jpg" width="166" height="56" border="0" alt="二葉通信"></a> 
            </div></td>
      </tr>
    </table>
    </td>
    <td width="549" rowspan="2" valign="top" background="../image/b04.jpg">
      <table width="549" border="0" cellpadding="0" cellspacing="0" class="font12-1">
        <tr> 
          <td width="549" height="9" colspan="2"><img src="../image/t02.jpg" width="549" height="9"></td>
        </tr>
        <tr>
          <td colspan="2">$xxx1</td>
        </tr>
        <tr>
          <td><img src="../image/spase.gif" width="19" height="60"></td>
          <td width="549" valign="bottom">$xxx2</td>
        </tr>
        <tr>
          <td rowspan="4"><img src="../image/spase.gif" width="19" height="8"></td>
          <td>　</td>
        </tr>
        <tr>
          <td>$xxx3
          $tmpri
$bn
          </td>
        </tr>
      </table>
<br><br>
</td>
    <td width="16" rowspan="3" valign="top" background="../image/b03.jpg"><img src="../image/b03.jpg" width="16" height="1"></td>
  </tr>
  <tr>
    <td rowspan="2" valign="top" background="../image/b02.jpg"><img src="../image/b02.jpg" width="16" height="1"></td>
  </tr>
  <tr>
    <td valign="bottom" background="../image/b04.jpg">
    <br><br><br>
<table width="549" border="0" cellpadding="0" cellspacing="0">
      <tr>
          <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr> 
                <td width="19"><img src="../image/spase.gif" width="19" height="10"></td>
                <td><table width="530" border="0" cellspacing="0" cellpadding="0" class="font10">
                    <tr> 
                      <td width="103"><img src="../image/logo03.gif" width="93" height="10"></td>
                      <td>〒951-8118 新潟市中央区西中町714番地 TEL 025-222-4509 FAX 025-222-9130</td>
                    </tr>
                  </table></td>
              </tr>
              <tr> 
                <td colspan="2"><img src="../image/spase.gif" width="5" height="5"></td>
              </tr>
              <tr> 
                <td colspan="2"><img src="../image/bot03.jpg" width="549" height="29"></td>
              </tr>
            </table>
          </td>
      </tr>
    </table>
    </td>
  </tr>
</table>
EOM

&foot ;


}

