#!/usr/local/bin/perl

# YY-BOARD v4.1 (2001/01/27)
# Copyright(C) Kent Web 1997-2001
# webmaster@kent-web.com
# http://www.kent-web.com/

# バージョン情報
$ver = 'YYBBS v4.1';

#--- [注意事項] ------------------------------------------------#
# 1. このスクリプトはフリーソフトです。このスクリプトを使用した	#
#    いかなる損害に対して作者は一切の責任を負いません。		#
# 2. 設置に関する質問はサポート掲示板にお願いいたします。	#
#    直接メールによる質問は一切お受けいたしておりません。	#
# 3. 添付の home.gif は L.O.V.E の mayuRin さんによる画像です。	#
#---------------------------------------------------------------#

# 【ファイル構成例】
#
#  public_html (ホームディレクトリ)
#      |
#      +-- yybbs / yybbs.cgi [755]
#            |     yybbs.log [666]
#            |     count.dat [666]
#            |     jcode.pl  [644]
#            |     pastno.dat[666]
#            |
#            +-- img / home.gif, bear.gif, ...
#            |
#            +-- lock [777] /
#            |
#            +-- past [777] / 1.dat [666] ...

#============#
#  設定項目  #
#============#

$fBBSDB			= "../../cgi2/dbfile/bbsdb.dat";

# 文字コードライブラリ取込
require "./jcode.pl";

# タイトル名を指定
$title = "大館市・田代町合併協議会【みんなの広場】";

# タイトルの色
$t_color = "#000000";

# タイトルの大きさ（ポイント数:スタイルシートで有効）
$t_size = '20pt';

# タイトル文字のフォントタイプ
$t_face = "ＭＳ Ｐゴシック";

# 本文の文字大きさ（ポイント数:スタイルシートで有効）
$b_size = '12pt';

# 壁紙を指定する場合（http://から指定）
$backgif = "";

# 背景色を指定
$bgcolor = "#FFFFFF";

# 文字色を指定
$text = "#000000";

# リンク色を指定
$link  = "#0000FF";	# 未訪問
$vlink = "#800080";	# 訪問済
$alink = "#FF0000";	# 訪問中

# 戻り先のURL (index.htmlなど)
$homepage = "../../";

# 最大記事数
$max = 2000;

# 管理者用マスタパスワード (英数字で８文字以内)
$pass = 'gappe1';

# アイコン画像のある「ディレクトリ」
# → フルパスなら http:// から記述する
# → 最後は必ず / で閉じる
$imgurl = "./img/";

# アイコンを定義（上下は必ずペアで）
@icon1 = ('bear.gif','cat.gif','cow.gif','dog.gif','fox.gif','hituji.gif',
		'monkey.gif','zou.gif','mouse.gif','panda.gif','pig.gif','usagi.gif');
@icon2 = ('くま','ねこ','うし','いぬ','きつね','ひつじ',
		'さる','ぞう','ねずみ','パンダ','ぶた','うさぎ');

# 管理者専用アイコン機能 (0=no 1=yes)
#  --> 【使い方】記事投稿時に「管理者アイコン」を選択し、削除キーに
#                「管理用パスワード」を入力して下さい。
$my_icon = 0;

# 管理者専用アイコンの「ファイル名」を指定
$my_gif  = 'admin.gif';

# アイコンモード (0=no 1=yes)
$icon_mode = 0;

# 返信がつくと親記事をトップへ移動 (0=no 1=yes)
$topsort = 1;

# ホスト名取得モード
#  --> 0 : $ENV{'REMOTE_HOST'} で取得できる場合
#  --> 1 : gethostbyaddr で取得できる場合
$get_remotehost = 0;

# タイトルにGIF画像を使用する時 (http://から記述)
$title_gif = "t_bbs.gif";
$tg_w = '600';	# GIF画像の幅 (ピクセル)
$tg_h = '75';	#    〃    高さ (ピクセル)

# ファイルロック形式
# → 0=no 1=symlink関数 2=open関数 3=mkdir関数
# → 設定する場合は、ロックファイルを生成するディレクトリ
#    のパーミッションは原則として「777」に設定する。
$lockkey = 3;

# ロックファイル名
$lockfile = "./lock/yybbs.lock";

# ミニカウンタの設置
#  --> 0=no 1=テキスト 2=GIF画像
$counter = 0;

# ミニカウンタの桁数
$mini_fig = 6;

# テキストのとき：ミニカウンタの色
$cnt_color = "#555555";

# ＧＩＦのとき：画像までのディレクトリ
# → 最後は必ず / で閉じる
$gif_path = "./img/";
$mini_w = 8;		# 画像の横サイズ
$mini_h = 12;		# 画像の縦サイズ

# カウンタファイル
$cntfile = "./count.dat";

# タグの許可 (0=no 1=yes)
$tagkey = 0;

# スクリプトのファイル名
#  --> フルパスで指定する場合は http:// から記述
$script  = "./yybbs.cgi";

# ログファイルを指定
#  --> フルパスで指定する場合は / から記述
$logfile = "./yybbs.log";

# 記事 [タイトル] 部の長さ (全角文字換算)
$sub_len = '12';

# 記事の [タイトル] 部の色
$sub_color = "#006400";

# 記事表示部の下地の色
$tbl_color = "#FFFFFF";

# 家アイコンの使用 (0=no 1=yes)
$home_icon = 1;
$home_gif = "home.gif";	# 家アイコンのファイル名
$home_wid = 16;		# 画像の横サイズ
$home_hei = 20;		#   〃  縦サイズ

# イメージ参照画面の表示形態
#  1 : JavaScript
#  2 : HTML (JavaScriptが不安定なブラザが多い場合はこちら）
$ImageView = 1;

# イメージ参照画面のサイズ (JavaScriptの場合)
$img_w = '550'; # 横幅
$img_h = '450'; # 高さ

# methodの形式 (POST/GET)
$method = 'POST';

# 記事の更新は method=POST 限定 (0=no 1=yes)
#  --> 連続投稿などの荒らし対策
$MethPost = 1;

# 同一IPアドレスからの連続投稿時間（秒数）
#  --> 連続投稿などの荒らし対策
#  --> 値を 0 にするとこの機能は無効になります
$wait = 0;

# １ページ当たりの記事表示数 (親記事)
$p_log = 20;

# 投稿があるとメール通知する (sendmail必須)
#  0 : 通知しない
#  1 : 通知するが、自分の投稿記事はメールしない。
#  2 : 通知する。自分の投稿記事も通知する。
$mailing = 0;

# メールアドレス(メール通知する時)
$mailto = "";

# sendmailパス（メール通知する時）
$sendmail = "/usr/sbin/sendmail";

# 他サイトから投稿排除時に指定 (http://から書く)
$base_url = "";

# 文字色の設定。
@COLORS = ('800000','DF0000','008040','0000FF','C100C1','FF80C0','FF8040','000080');

# 投稿フォーム改行形式 (soft=手動 hard=強制)
$wrap = 'soft';

# URLの自動リンク (0=no 1=yes)
#  --> タグ許可の場合は no とすること。
$autolink = 1;

# タグ広告挿入オプション (FreeWebなど）
#   → <!--上部--> <!--下部--> の代わりに「広告タグ」を挿入する。
#   → 広告タグ以外に、MIDIタグ や LimeCounter等のタグにも使用可能です。
$banner1 = '<!-- 上部 -->';	# 掲示板上部に挿入
$banner2 = '<!-- 下部 -->';	# 掲示板下部に挿入

# アクセス制限（ホスト名、IPアドレスを記述）
@deny = (
	"anonymizer.com",
	"cache*.*.interlog.com",
	"211.154.120.*",
	"",
	"",
	"",
	"",
	"",
	""
	);

#---(以下は「過去ログ」機能を使用する場合の設定です)---#
#
# 過去ログ生成 (0=no 1=yes)
$pastkey = 0;

# 過去ログ用NOファイル
$nofile  = "./pastno.dat";

# 過去ログのディレクトリ
# → yybbs.cgiと同一のディレクトリに作成するならばこのままでよい
# → フルパスなら / から記述（http://からではない）
# → 最後は必ず / で閉じる
$pastdir = "./past/";

# 過去ログ１ファイルの行数
# → この行数を超えると次ページを自動生成します
$log_line = '1000';

@tColor			= ('333333', 'cc0000', '0033cc', '336633', 'FF6600');

#============#
#  設定完了  #
#============#

# メイン処理
&decode;
&axs_check;
if ($mode eq "howto") { &howto; }
elsif ($mode eq "find") { &find; }
elsif ($mode eq "usr_del") { &usr_del; }
elsif ($mode eq "regist") { &regist; }
elsif ($mode eq "res") { &res_form; }
elsif ($mode eq "admin") { &admin; }
elsif ($mode eq "image") { &image; }
elsif ($mode eq "past") { &past; }
elsif ($mode eq "check") { &check; }
&html_log;

#----------------#
#  アクセス制限  #
#----------------#
sub axs_check {
	# ホスト名を取得
	&get_host;

	$flag=0;
	foreach (@deny) {
		if (!$_) { next; }
		$_ =~ s/\*/\.\*/g;
		if ($host =~ /$_/i) { $flag=1; last; }
	}
	if ($flag) { &error("アクセスを許可されていません"); }
}

#--------------#
#  記事表示部  #
#--------------#
sub html_log {
	# クッキーを取得
	&get_cookie;

	# フォーム長を調整
	&get_agent;

	# ヘッダを出力
	if ($ImageView == 1) { &header('ImageUp'); }
	else { &header; }

	# カウンタ処理
	if ($counter) { &counter; }

		if (!open(DATA, "+< $fBBSDB")) {
			# ファイルを開けないためエラーを出力
			print "Content-type: text/html\n\n";
			print '*ファイルをオープンできません。';
			&unlock;
			exit(0);
		}
		
		$inMAIN		= <DATA>;
		$tTitle		= <DATA>;
		$tColor		= <DATA>;
		$tBold		= <DATA>;
		
		close(DATA);
		
		$tTitle		=~ s/\r\n//g;
		$tTitle		=~ s/\r//g;
		$tTitle		=~ s/\n//g;
		$tColor		=~ s/\r\n//g;
		$tColor		=~ s/\r//g;
		$tColor		=~ s/\n//g;
		$tBold		=~ s/\r\n//g;
		$tBold		=~ s/\r//g;
		$tBold		=~ s/\n//g;
		
		
	if ($tBold eq "YES")
	{
		$tTitle	= "<b>".$tTitle."</b>";
	}

	# タイトル部
	print "<center>\n";
	if ($banner1 ne "<!-- 上部 -->") { print "$banner1<P>\n"; }
	if ($title_gif eq '') {
		print "<font color=\"$t_color\" size=6 face=\"$t_face\"><b><SPAN>$title</SPAN></b></font>\n";
	}
	else {
		print <<"EOF";
<table width="90%" border="0" align="center">
<tr>
<td><p class=\"maintxt3\"><span class=\"maintxt3\"><font size="+2" color="#$tColor[$tColor]">$tTitle</span></p>
</td>
</tr>
<tr>
<td><p class=\"maintxt3\"><span class=\"maintxt3\">$inMAIN</span></p>
</td>
</tr>
</table>
EOF
	}

	print "<hr width='90%'>\n";
	print "[<a href=\"$homepage\" target='_top'>トップに戻る</a>]\n";
	print "[<a href=\"$script?mode=howto\">使い方</a>]\n";
	print "[<a href=\"$script?mode=find\">ワード検索</a>]\n";

	# 過去ログのリンク部を表示
	if ($pastkey) {	print "[<a href=\"$script?mode=past\">過去ログ</a>]\n"; }

	print <<"EOM";
[<a href="$script?mode=admin">管理用</a>]
<hr width='90%'>
</center>
<blockquote>
<form method="$method" action="$script">
<input type=hidden name=mode value="regist">
<table border=0 cellspacing=0>
<tr>
  <td nowrap><b>おなまえ</b></td>
  <td><input type=text name=name size="$nam_wid" value="$c_name"></td>
</tr>
<tr>



  <td nowrap><b>Ｅメール</b></td>
  <td><input type=text name=email size="$nam_wid" value="$c_email"></td>
</tr>
<tr>
  <td nowrap><b>題　　名</b></td>
  <td nowrap>
    <input type=text name=sub size="$sub_wid">
　  <input type=submit value="投稿する"><input type=reset value="リセット">
  </td>
</tr>
<tr>
  <td colspan=2>
    <b>コメント</b><br>
    <textarea cols="$com_wid" rows=7 name=comment wrap="$wrap"></textarea>
  </td>
</tr>
<tr>
  <td nowrap><b>ＵＲＬ</b></td>
  <td><input type=text size="$url_wid" name=url value="http://$c_url"></td>
</tr>
EOM

	# 管理者アイコンを配列に付加
	if ($my_icon) {
		push(@icon1,"$my_gif");
		push(@icon2,"管理者用");
	}

	if ($icon_mode) {
		print "<tr><td nowrap><b>イメージ</b></td><td><select name=icon>\n";
		foreach(0 .. $#icon1) {
			if ($c_icon eq "$icon1[$_]") {
				print "<option value=\"$icon1[$_]\" selected>$icon2[$_]\n";			   } else {
				print "<option value=\"$icon1[$_]\">$icon2[$_]\n";
			}
		}
		print "</select> <small>(あなたのイメージを選択して下さい)</small>\n";

		# イメージ参照のリンク
		if ($ImageView == 1) {
			print "[<a href=\"javascript:ImageUp()\">画像イメージ参照</a>]";
		} else {
			print "[<a href=\"$script?mode=image\" target=\"_blank\">画像イメージ参照</a>]";
		}
		print "</td></tr>\n";
	}

	print "<tr><td nowrap><b>削除キー</b></td>\n";
	print "<td><input type=password name=pwd size=8 maxlength=8 value=\"$c_pwd\">\n";
	print "<small>(自分の記事を削除時に使用。英数字で8文字以内)</small></td></tr>\n";
	print "<tr><td nowrap><b>文字色</b></td><td>\n";

	# クッキーの色情報がない場合
	if ($c_color eq "") { $c_color = $COLORS[0]; }

	foreach (0 .. $#COLORS) {
		if ($c_color eq "$COLORS[$_]") {
			print "<input type=radio name=color value=\"$COLORS[$_]\" checked>";
			print "<font color=\"$COLORS[$_]\">■</font>\n";
		} else {
			print "<input type=radio name=color value=\"$COLORS[$_]\">";
			print "<font color=\"$COLORS[$_]\">■</font>\n";
		}
	}

	print "</td></tr></table></form>\n";
	print "</blockquote><center><br>\n";

	# ページ区切り処理
	$start = $page + 1;
	$end   = $page + $p_log;

	# 記事を展開
	open(IN,"$logfile") || &error("Open Error : $logfile");
	$top = <IN>;

	$i=0;
	$flag=0;
	while (<IN>) {
		($no,$reno,$date,$name,$mail,$sub,
			$comment,$url,$host,$pw,$color,$icon) = split(/<>/);

		if ($reno eq "") { $i++; }
		if ($i < $start) { next; }
		if ($i > $end) { last; }

		if ($mail) { $name = "<a href=\"mailto:$mail\">$name</a>"; }
		if ($home_icon && $url) { $url = "<a href=\"http://$url\" target='_blank'><img src=\"$imgurl$home_gif\" border=0 align=top alt='HomePage' width=\"$home_wid\" height=\"$home_hei\"></a>"; }
		elsif (!$home_icon && $url) { $url = "&lt;<a href=\"http://$url\" target='_blank'>HOME</a>&gt;"; }
		if (!$icon_mode) { $comment = "<table width=\"80%\" border=\"0\" align=\"center\"><tr><td valign=\"top\"><font color=\"$color\">$comment</font></td></tr></table>"; }

		if (!$reno && $flag) {
			print "</TD></TR></TABLE><br><br>\n";
			$flag=1;
		}
		if (!$reno) {
			print "<TABLE BORDER=1 WIDTH='90%' BGCOLOR=\"$tbl_color\" CELLSPACING=0 CELLPADDING=2><TR><TD>\n";
			$flag=1;
		}

		if ($reno) { print "<hr noshade size=1 width='85%'>\n"; }
		print "<table border=0 cellpadding=2 width='100%'><tr>\n";
		if ($reno) { print "<td rowspan=2 width=40><br></td>"; }

		print "<td valign=top nowrap><font color=\"$sub_color\"><b>$sub</b></font>　";

		if (!$reno) { print "投稿者：<b>$name</b> <small>投稿日：$date</small> "; }
		else { print "<b>$name</b> - <small>$date</small> "; }

		print "<font color=\"$sub_color\"><small>No\.$no</small></font> <small></small></td>";
		print "<td valign=top nowrap> &nbsp; $url </td><td valign=top>\n";

		if (!$reno) {
			print "<form action=\"$script\" method=$method>\n";
			print "<input type=hidden name=mode value=res>\n";
			print "<input type=hidden name=no value=$no>\n";
			print "<input type=submit value='返信'></td></form>\n";
		} else {
			print "<br></td>\n";
		}

		print "</tr></table><table border=0 cellpadding=5 width='100%'><tr>\n";
		if ($reno) { print "<td width=32><br></td>\n"; }

		# アイコンモード
		if ($icon_mode) { print "<td><img src=\"$imgurl$icon\"></td>"; }

		print "<td>$comment";
		print "</td></tr></table>\n";

	}
	close(IN);
	print "</TD></TR></TABLE>\n";

	$next_page = $page + $p_log;
	$back_page = $page - $p_log;

	print "<blockquote><table align=left cellpadding=0 cellspacing=0><tr>\n";
	if ($back_page >= 0) {
		print "<td><form action=\"$script\" method=\"$method\">\n";
		print "<input type=hidden name=page value=\"$back_page\">\n";
		print "<input type=submit value=\"前の$p_log件\">\n";
		print "</td></form>\n";
	}
	if ($next_page < $i) {
		print "<td><form action=\"$script\" method=\"$method\">\n";
		print "<input type=hidden name=page value=\"$next_page\">\n";
		print "<input type=submit value=\"次の$p_log件\">\n";
		print "</td></form>\n";
	}
	print "</tr></table>\n";
	print "<table align=right><tr>\n";
	print "<form action=\"$script\" method=\"$method\"><td nowrap align=center>\n";
	print "<input type=hidden name=mode value=\"usr_del\">\n";
	print "<font color=\"$sub_color\">【記事削除フォーム】</font><br>\n";
	print "記事No<input type=text name=no size=3>\n";
	print "削除キー<input type=password name=pwd size=4 maxlength=8>\n";
	print "<input type=submit value=\"削除\">\n";
	print "</td></form>\n";
	print "</tr></table></blockquote></center>\n";

	# 著作権表示部
	# MakiMakiさんの画像使用の有無に関わらずこの2箇所のリンク部の
	# 削除改変を禁止します


	print <<"EOF";
										</p>
									</div>
								</td>
							</tr>
							<tr>
								<td align="center">
									$banner2<small><!-- $ver -->
- <a href='http://www.kent-web.com/' target='_top'>KENT</a> &amp; 
<a href='http://village.infoweb.ne.jp/~fwhf2602/' target='_top'>MakiMaki</a> -
								</td>
							</tr>
</td>
				</tr>
				<tr>
					<td align="right"><a href="#anchor_pagetop"><img src="../../img/btn_pagetop.gif" alt="" width="30" height="27" align="absmiddle" border="0">ページのトップへ</a></td>
				</tr>
			</table>
		</div>
	</BODY>
</HTML>
EOF
	exit;
}

#----------------#
#  ログ書込処理  #
#----------------#
sub regist {
	# POST限定
	if ($MethPost && !$post_flag) { &error("不正なアクセスです"); }

	# 他サイトからのアクセスを排除
	if ($base_url) {
		$ref_url = $ENV{'HTTP_REFERER'};
		$ref_url =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
		if ($ref_url !~ /$base_url/i) { &error("不正なアクセスです"); }
	}

	# 名前とコメントは必須
	if ($in{'name'} eq "") { &error("名前が入力されていません"); }
	if ($in{'comment'} eq "") { &error("コメントが入力されていません"); }
	if ($in{'email'} && $in{'email'} !~ /(.*)\@(.*)\.(.*)/)
		{ &error("Ｅメールの入力内容が正しくありません"); }
	# 題名の長さ制限
	if (length($in{'sub'}) > $sub_len * 2)
		{ &error("題名の長さは全角$sub_len文字までにして下さい"); }

	# 管理アイコンのチェック
	if ($my_icon && $in{'icon'} eq "$my_gif") {
		if ($in{'pwd'} ne "$pass") { &error("管理用アイコンは管理者専用です"); }
	}

	# 時間を取得
	&get_time;

	# クッキーを発行
	&set_cookie;

	# ファイルロック
	if ($lockkey) { &lock; }

	# ログを開く
	open(IN,"$logfile") || &error("Open Error : $logfile");
	@lines = <IN>;
	close(IN);

	# 記事NO処理
	$top = shift(@lines);
	($no,$ip,$time2) = split(/<>/, $top);
	$no++;

	# 連続投稿チェック
	if ($addr eq "$ip" && $wait > $times - $time2)
		{ &error("連続投稿はもうしばらく時間をおいて下さい"); }

	# 削除キーを暗号化
	if ($in{'pwd'} ne "") { $ango = &encrypt($in{'pwd'}); }

	# URL自動リンク
	if ($autolink) { &auto_link($in{'comment'}); }

	# 親記事の場合
	if ($in{'reno'} eq "") {

		$i=0;
		$stop=0;
		foreach (@lines) {
			($no2,$reno2) = split(/<>/);
			$i++;
			if ($i > $max-1 && $reno2 eq "") { $stop=1; }
			if (!$stop) { push(@new,$_); }
			elsif ($stop && $pastkey) { push(@data,$_); }
		}
		unshift(@new,"$no<><>$date<>$in{'name'}<>$in{'email'}<>$in{'sub'}<>$in{'comment'}<>$in{'url'}<><>$ango<>$in{'color'}<>$in{'icon'}<>\n");
		unshift(@new,"$no<>$addr<>$times<>\n");

		# 過去ログ更新
		if ($data[0]) { &pastlog; }

		# 更新
		open(OUT,">$logfile") || &error("Write Error : $logfile");
		print OUT @new;
		close(OUT);
	}
	# レス記事の場合：トップソートあり

	elsif ($in{'reno'} && $topsort) {

		$match=0;
		@new=();
		@tmp=();
		foreach (@lines) {
			($no2,$reno2) = split(/<>/);

			if ($in{'reno'} eq "$no2") {
				$match=1;
				push(@new,$_);
			}
			elsif ($in{'reno'} eq "$reno2") {
				push(@new,$_);
			}
			elsif ($match == 1 && $in{'reno'} ne "$reno2") {
				$match=2;
				push(@new,"$no<>$in{'reno'}<>$date<>$in{'name'}<>$in{'email'}<>$in{'sub'}<>$in{'comment'}<>$in{'url'}<>$host<>$ango<>$in{'color'}<>$in{'icon'}<>\n");
				push(@tmp,$_);
			}
			else { push(@tmp,$_); }
		}

		if ($match == 1) {
			push(@new,"$no<>$in{'reno'}<>$date<>$in{'name'}<>$in{'email'}<>$in{'sub'}<>$in{'comment'}<>$in{'url'}<>$host<>$ango<>$in{'color'}<>$in{'icon'}<>\n");
		}
		push(@new,@tmp);

		# 更新
		unshift(@new,"$no<>$addr<>$times<>\n");
		open(OUT,">$logfile") || &error("Write Error : $logfile");
		print OUT @new;
		close(OUT);

	}
	# レス記事の場合：トップソートなし
	else {
		$match=0;
		@new=();
		foreach (@lines) {
			($no2,$reno2) = split(/<>/);

			if ($match == 0 && $in{'reno'} eq "$no2") { $match=1; }
			elsif ($match == 1 && $in{'reno'} ne "$reno2") {
				$match=2;
				push(@new,"$no<>$in{'reno'}<>$date<>$in{'name'}<>$in{'email'}<>$in{'sub'}<>$in{'comment'}<>$in{'url'}<>$host<>$ango<>$in{'color'}<>$in{'icon'}<>\n");
			}
			push(@new,$_);
		}

		if ($match == 1) {
			push(@new,"$no<>$in{'reno'}<>$date<>$in{'name'}<>$in{'email'}<>$in{'sub'}<>$in{'comment'}<>$in{'url'}<>$host<>$ango<>$in{'color'}<>$in{'icon'}<>\n");
		}

		# 更新
		unshift(@new,"$no<>$addr<>$times<>\n");
		open(OUT,">$logfile") || &error("Write Error : $logfile");
		print OUT @new;
		close(OUT);
	}

	# ロック解除
	if ($lockkey) { &unlock; }

	# メール処理
	if ($mailing == 1 && $in{'email'} ne "$mailto") { &mail_to; }
	elsif ($mailing == 2) { &mail_to; }
}

#----------------#
#  返信フォーム  #
#----------------#
sub res_form {
	# フォーム長を定義
	&get_agent;

	# クッキーを取得
	&get_cookie;

	# ログを読み込み
	open(IN,"$logfile") || &error("Open Error : $logfile");
	$top = <IN>;

	# ヘッダを出力
	if ($ImageView == 1) { &header('ImageUp'); }
	else { &header; }

	# 関連記事出力
	print "- 以下は、記事NO. <B>$in{'no'}</B> に関する<a href='#RES'>返信フォーム</a>です -<hr>\n";

	while (<IN>) {
		($no,$reno,$date,$name,$mail,$sub,$com,$url) = split(/<>/);

		if ($in{'no'} eq "$no" || $in{'no'} eq "$reno") {
			if ($in{'no'} eq "$no") { $resub = $sub; }
			if ($url) { $url = "&lt;<a href=\"http://$url\">HOME</a>&gt;"; }
			if ($reno) { print '　　'; }
			print "<font color=$sub_color><b>$sub</b></font> 投稿者：<b>$name</b> 投稿日：$date $url <font color=$sub_color>No\.$no</font><br>\n";
			print "<blockquote>$com</blockquote><hr>\n";
		}
	}
	close(IN);

	# タイトル名
	if ($resub !~ /^Re\:/) { $resub = "Re\: $resub"; }

	print <<"EOM";
<a name="RES"></a>
<form action="$script" method="$method">
<input type=hidden name=mode value="regist">
<input type=hidden name=reno value="$in{'no'}">
<blockquote>
<table>
<tr>
  <td nowrap><b>おなまえ</b></td>
  <td><input type=text name=name value="$c_name" size=$nam_wid></td>
</tr>
<tr>
  <td nowrap><b>Ｅメール</b></td>
  <td><input type=text name=email value="$c_email" size=$nam_wid></td>
</tr>
<tr>
  <td nowrap><b>タイトル</b></td>
  <td><input type=text name=sub value="$resub" size=$sub_wid>
  <input type=submit value="返信する"><input type=reset value="リセット"></td>
</tr>
<tr>
  <td colspan=2><b>メッセージ</b><br>
  <textarea cols=$com_wid rows=5 name=comment wrap="$wrap"></textarea></td>
</tr>
<tr>
  <td nowrap><b>ＵＲＬ</b></td>
  <td><input type=text name=url value="http://$c_url" size=$url_wid></td>
</tr>
EOM

	# 管理者アイコンを配列に付加
	if ($my_icon) {
		push(@icon1,"$my_gif");
		push(@icon2,"管理者用");
	}

	if ($icon_mode) {
		print "<tr><td nowrap><b>イメージ</b></td><td><select name=icon>\n";
		foreach(0 .. $#icon1) {
			if ($c_icon eq "$icon1[$_]") {
				print "<option value=\"$icon1[$_]\" selected>$icon2[$_]\n";
			} else {
				print "<option value=\"$icon1[$_]\">$icon2[$_]\n";
			}
		}
		print "</select>\n";

		if ($ImageView == 1) {
			print "[<a href=\"javascript:ImageUp()\">画像イメージ参照</a>]";
		} else {
			print "[<a href=\"$script?mode=image\" target=\"_blank\">画像イメージ参照</a>]";
		}
		print "</td></tr>\n";
	}

	print "<tr><td nowrap><b>削除キー</b>";
	print "<td><input type=password name=pwd size=8 maxlength=8 value=\"$c_pwd\">\n";
	print "<small>(自分の記事を削除時に使用。英数字で8文字以内)</small></td></tr>\n";
	print "<tr><td nowrap><b>文字色</b></td><td>\n";

	# クッキーの色情報がない場合
	if ($c_color eq "") { $c_color = $COLORS[0]; }

	foreach (0 .. $#COLORS) {
		if ($c_color eq "$COLORS[$_]") {
			print "<input type=radio name=color value=\"$COLORS[$_]\" checked>";
			print "<font color=\"$COLORS[$_]\">■</font>\n";

		} else {
			print "<input type=radio name=color value=\"$COLORS[$_]\">";
			print "<font color=$COLORS[$_]>■</font>\n";
		}
	}

	print "</td></tr></table></form>\n";
	print "</blockquote>\n";
	print <<"EOF";
										</p>
									</div>
								</td>
							</tr>
							<tr>
								<td align="center">
									$banner2<small><!-- $ver -->
- <a href='http://www.kent-web.com/' target='_top'>KENT</a> &amp; 
<a href='http://village.infoweb.ne.jp/~fwhf2602/' target='_top'>MakiMaki</a> -
								</td>
							</tr>
</td>
				</tr>
				<tr>
					<td align="right"><a href="#anchor_pagetop"><img src="../../img/btn_pagetop.gif" alt="" width="30" height="27" align="absmiddle" border="0">ページのトップへ</a></td>
				</tr>
			</table>
		</div>
	</BODY>
</HTML>
EOF
	exit;
}

#----------------#
#  デコード処理  #
#----------------#
sub decode {
	$post_flag=0;
	if ($ENV{'REQUEST_METHOD'} eq "POST") {
		$post_flag=1;
		if ($ENV{'CONTENT_LENGTH'} > 51200) { &error("投稿量が大きすぎます"); }
		read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
	} else { $buffer = $ENV{'QUERY_STRING'}; }
	@pairs = split(/&/, $buffer);
	foreach (@pairs) {
		($name,$value) = split(/=/);

		if ($name eq "word") { $word = $value; }

		$value =~ tr/+/ /;
		$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

		# 文字コードをシフトJIS変換
		&jcode'convert(*value, "sjis", "", "z");

		# タグ処理
		if ($tagkey) { $value =~ s/<>/&lt;&gt;/g; }
		else {
			$value =~ s/</&lt;/g;
			$value =~ s/>/&gt;/g;
			$value =~ s/\"/&quot;/g;
		}

		# 改行等処理
		if ($name eq "comment") {
			$value =~ s/\r\n/<br>/g;
			$value =~ s/\r/<br>/g;
			$value =~ s/\n/<br>/g;
		} else {
			$value =~ s/\r//g;
			$value =~ s/\n//g;
		}

		# 一括削除用
		if ($name eq "del") { push(@DEL,$value); }

		$in{$name} = $value;
	}
	$mode = $in{'mode'};
	$page = $in{'page'};
	$in{'url'} =~ s/^http\:\/\///;
	if ($in{'sub'} eq "") { $in{'sub'} = "無題"; }
}

#----------------------------#
#  掲示板の使い方メッセージ  #
#----------------------------#
sub howto {
	if ($tagkey == 0) { $tag_msg = "投稿内容には、<b>タグは一切使用できません。</b>\n"; }
	else { $tag_msg = "コメント欄には、<b>タグ使用をすることができます。</b>\n"; }

	&header;
	print <<"HTML";
[<a href="$script?">掲示板にもどる</a>]
<table width="100%">
<tr><th bgcolor="#0000A0">
  <font color="#FFFFFF">掲示板の利用上の注意</font>
</th></tr>
</table>
<P><center>
<table width="90%" border=1 cellpadding=10>
<tr><td bgcolor="$tbl_color">
<OL>
<LI>この掲示板は<b>クッキー対応</b>です。１度記事を投稿いただくと、おなまえ、Ｅメール、ＵＲＬ、削除キーの情報は２回目以降は自動入力されます。（ただし利用者のブラウザがクッキー対応の場合）<P>
<LI>$tag_msg<P>
<LI>記事を投稿する上での必須入力項目は<b>「おなまえ」</b>と<b>「メッセージ」</b>です。Ｅメール、ＵＲＬ、題名、削除キーは任意です。<P>
<LI>記事には、<b>半角カナは一切使用しないで下さい。</b>文字化けの原因となります。<P>
<LI>記事の投稿時に<b>「削除キー」</b>にパスワード（英数字で8文字以内）を入れておくと、その記事は次回<b>削除キー</b>によって削除することができます。<P>
<LI>既存の記事に<b>「返信」</b>をすることができます。各記事の上部にある<b>「返信」</b>ボタンを押すと返信用フォームが現れます。<P>
<LI>過去の投稿記事から<b>「キーワード」によって簡易検索ができます。</b>トップメニューの<a href="$script?mode=find">「ワード検索」</a>のリンクをクリックすると検索モードとなります。<P>
<LI>管理者が著しく不利益と判断する記事や他人を誹謗中傷する記事は予\告なく削除することがあります。
</OL>
</td></tr></table>
</center>
										</p>
									</div>
								</td>
							</tr>
							<tr>
								<td align="center">
									$banner2<small><!-- $ver -->
- <a href='http://www.kent-web.com/' target='_top'>KENT</a> &amp; 
<a href='http://village.infoweb.ne.jp/~fwhf2602/' target='_top'>MakiMaki</a> -
								</td>
							</tr>
</td>
				</tr>
				<tr>
					<td align="right"><a href="#anchor_pagetop"><img src="../../img/btn_pagetop.gif" alt="" width="30" height="27" align="absmiddle" border="0">ページのトップへ</a></td>
				</tr>
			</table>
		</div>
	</BODY>
</HTML>
HTML
	exit;
}

#------------------#
#  ワード検索処理  #
#------------------#
sub find {
	&header;
	print <<"EOM";
[<a href="$script?">掲示板にもどる</a>]
<table width="100%">
<tr><th bgcolor="#0000A0">
  <font color="#FFFFFF">ワード検索</font>
</th></tr></table>
<P>
<UL>
  <LI>検索したい<b>キーワード</b>を入力し、「条件」「表\示」を選択して「検索」ボタンを押して下さい。
  <LI>キーワードは「半角スペース」で区切って複数指定することができます。
<P><form action="$script" method="$method">
<input type=hidden name=mode value="find">
キーワード：<input type=text name=word size=30 value="$in{'word'}">
条件：<select name=cond>
EOM
	if (!$in{'cond'}) { $in{'cond'} = "AND"; }
	foreach ("AND", "OR") {

		if ($in{'cond'} eq "$_") {
			print "<option value=\"$_\" selected>$_\n";
		} else {
			print "<option value=\"$_\">$_\n";
		}
	}
	print "</select>\n";
	print "表\示：<select name=view>\n";
	if ($in{'view'} eq "") { $in{'view'} = $p_log; }
	foreach (5,10,15,20) {
		if ($in{'view'} == $_) {
			print "<option value=\"$_\" selected>$_件\n";
		} else {
			print "<option value=\"$_\">$_件\n";
		}
	}
	print "</select>\n";
	print "<input type=submit value='検索'>";
	print "</form></UL>\n";

	# ワード検索の実行と結果表示
	if ($in{'word'} ne ""){

		# 入力内容を整理
		$in{'word'} =~ s/　/ /g;
		@pairs = split(/\s+/, $in{'word'});

		# ファイルを読み込み
		@new=();
		open(IN,"$logfile") || &error("Open Error : $logfile");
		$top = <IN>;
		while (<IN>) {
			$flag=0;
			foreach $pair (@pairs) {
				if (index($_,$pair) >= 0) {
					$flag=1;
					if ($in{'cond'} eq 'OR') { last; }
				} else {
					if ($in{'cond'} eq 'AND') { $flag=0; last; }
				}
			}
			if ($flag) { push(@new,$_); }
		}
		close(IN);

		# 検索終了
		$count = @new;
		print "検索結果：<b>$count</b>件\n";
		if ($page eq '') { $page = 0; }
		$end_data = @new - 1;
		$page_end = $page + $in{'view'} - 1;
		if ($page_end >= $end_data) { $page_end = $end_data; }

		$next_line = $page_end + 1;
		$back_line = $page - $in{'view'};

		if ($back_line >= 0) {
			print "[<a href=\"$script?mode=find&page=$back_line&word=$word&view=$in{'view'}&cond=$in{'cond'}\">前の$in{'view'}件</a>]\n";
		}
		if ($page_end ne "$end_data") {
			print "[<a href=\"$script?mode=find&page=$next_line&word=$word&view=$in{'view'}&cond=$in{'cond'}\">次の$in{'view'}件</a>]\n";
		}
		print "[<a href=\"$script?mode=find\">検索やり直し</a>]\n";

		foreach ($page .. $page_end) {
			($no,$reno,$date,$name,$email,$sub,$com,$url)
							= split(/<>/, $new[$_]);

			if ($email) { $name = "<a href=\"mailto:$email\">$name</a>"; }
			if ($url) { $url = "&lt;<a href=\"http://$url\" target='_top'>HOME</a>&gt;"; }

			if ($reno) { $no = "$renoへのレス"; }


			# 結果を表示
			print "<hr>[<b>$no</b>] <font color=\"$sub_color\"><b>$sub</b></font>";
			print " 投稿者：<b>$name</b> <small>投稿日：$date</small> $url<br>\n";
			print "<blockquote>$com</blockquote>\n";
		}
		print "<hr>\n";
	}
	print <<"EOF";
										</p>
									</div>
								</td>
							</tr>
							<tr>
								<td align="center">
									$banner2<small><!-- $ver -->
- <a href='http://www.kent-web.com/' target='_top'>KENT</a> &amp; 
<a href='http://village.infoweb.ne.jp/~fwhf2602/' target='_top'>MakiMaki</a> -
								</td>
							</tr>
</td>
				</tr>
				<tr>
					<td align="right"><a href="#anchor_pagetop"><img src="../../img/btn_pagetop.gif" alt="" width="30" height="27" align="absmiddle" border="0">ページのトップへ</a></td>
				</tr>
			</table>
		</div>
	</BODY>
</HTML>
EOF
	exit;
}

#---------------------------------#
#  ブラウザを判断:フォーム幅調整  #
#---------------------------------#
sub get_agent {
	# ブラウザ名を取得
	$agent = $ENV{'HTTP_USER_AGENT'};

	if ($agent =~ /MSIE 3/i) { 
		$nam_wid = 30;
		$sub_wid = 40;
		$com_wid = 65;
		$url_wid = 48;
		$nam_wid2 = 20;
	} elsif ($agent =~ /MSIE 4/i || $agent =~ /MSIE 5/i) { 
		$nam_wid = 30;
		$sub_wid = 40;
		$com_wid = 60;
		$url_wid = 70;
		$nam_wid2 = 20;
	} else {
		$nam_wid = 20;
		$sub_wid = 25;
		$com_wid = 56;
		$url_wid = 50;
		$nam_wid2 = 10;
	}
}

#------------------#
#  クッキーの発行  #
#------------------#
sub set_cookie {
	# クッキーは60日間有効
	local($sec,$min,$hour,$mday,$mon,$year,$wday) = gmtime(time+60*24*60*60);

	@month=('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
	$gmt = sprintf("%s, %02d-%s-%04d %02d:%02d:%02d GMT",
			$week[$wday],$mday,$month[$mon],$year+1900,$hour,$min,$sec);
	$cook="name<>$in{'name'}\,email<>$in{'email'}\,url<>$in{'url'}\,pwd<>$in{'pwd'}\,icon<>$in{'icon'}\,color<>$in{'color'}";
	print "Set-Cookie: YYBBS=$cook; expires=$gmt\n";
}

#------------------#
#  クッキーを取得  #
#------------------#
sub get_cookie {
	local($key, $val);
	@pairs = split(/;/, $ENV{'HTTP_COOKIE'});
	foreach (@pairs) {
		($key,$val) = split(/=/);
		$key =~ s/\s//g;
		$GET{$key} = $val;
	}
	@pairs = split(/,/, $GET{'YYBBS'});
	foreach (@pairs) {
		($key,$val) = split(/<>/);
		$COOK{$key} = $val;
	}
	$c_name  = $COOK{'name'};
	$c_email = $COOK{'email'};
	$c_url   = $COOK{'url'};
	$c_pwd   = $COOK{'pwd'};
	$c_icon  = $COOK{'icon'};
	$c_color = $COOK{'color'};

	if ($in{'name'})  { $c_name  = $in{'name'}; }
	if ($in{'email'}) { $c_email = $in{'email'}; }
	if ($in{'url'})   { $c_url   = $in{'url'}; }
	if ($in{'pwd'})   { $c_pwd   = $in{'pwd'}; }
	if ($in{'icon'})  { $c_icon  = $in{'icon'}; }
	if ($in{'color'}) { $c_color = $in{'color'}; }
}

#--------------#
#  エラー処理  #
#--------------#
sub error {
	if ($lockkey) { &unlock; }

	&header if (!$head_flag);
	print "<center><hr width=400><h3>ERROR !</h3>\n";
	print "<P><font color=red><B>$_[0]</B></font>\n";
	print "<P><hr width=400></center>\n";
	print "</body></html>\n";
	exit;
}

#--------------#
#  管理モード  #
#--------------#
sub admin {
	if ($in{'pass'} ne "" && $in{'pass'} ne "$pass") {
		&error("パスワードが違います");
	}

	&header;
	print "[<a href=\"$script?\">掲示板に戻る</a>]\n";
	print "<table width='100%'><tr><th bgcolor=\"#800080\">\n";
	print "<font color=\"#FFFFFF\">管理モード</font>\n";
	print "</th></tr></table>\n";

	if ($in{'pass'} eq "") {
		print "<P><center><h4>パスワードを入力して下さい</h4>\n";
		print "<form action=\"$script\" method=\"$method\">\n";
		print "<input type=hidden name=mode value=\"admin\">\n";
		print "<input type=hidden name=action value=\"del\">\n";
		print "<input type=password name=pass size=8>";
		print "<input type=submit value=\" 認証 \"></form>\n";
	}
	else {
		# 削除処理
		if ($DEL[0]) {

			# ロック処理
			if ($lockkey) { &lock; }

			# 削除情報をマッチングし更新
			@new=();
			open(IN,"$logfile") || &error("Open Error : $logfile");
			$top = <IN>;
			while (<IN>) {
				$flag=0;
				($no,$reno,$date) = split(/<>/);
				foreach $del (@DEL) {
					if ($no eq "$del" || $reno eq "$del") {
						$flag=1; last;
					}
				}
				if ($flag == 0) { push(@new,$_); }
			}
			close(IN);

			# 更新
			unshift(@new,$top);
			open(OUT,">$logfile") || &error("Write Error : $logfile");
			print OUT @new;
			close(OUT);

			# ロック解除
			if ($lockkey) { &unlock; }
		}

		# 管理を表示
		if ($page eq "") { $page = 0; }
		print "<P><center><table><tr><td>\n";
		print "<UL><LI>削除する記事のチェックボックスにチェックを入れ、削除ボタンを押して下さい。\n";
		print "<LI>親記事を削除するとレス記事も一括して削除されます。</UL>\n";
		print "</td></tr></table>\n";
		print "<form action=\"$script\" method=\"$method\">\n";
		print "<input type=hidden name=mode value=\"admin\">\n";
		print "<input type=hidden name=page value=\"$page\">\n";
		print "<input type=hidden name=pass value=\"$in{'pass'}\">\n";
		print "<input type=hidden name=action value=\"$in{'action'}\">\n";
		print "<input type=submit value=\"削除する\">";
		print "<input type=reset value=\"リセット\">\n";
		print "<P><table border=0 cellspacing=1>\n";
		print "<tr><th>削除</th><th>記事NO</th><th>投稿日</th><th>タイトル</th>";
		print "<th>投稿者</th><th>URL</th><th>コメント</th><th>ホスト名</th></tr>\n";

		# ページ区切り処理
		$start = $page + 1;
		$end   = $page + $p_log;

		open(IN,"$logfile") || &error("Open Error : $logfile");
		$top = <IN>;
		$i=0;
		while (<IN>) {
			($no,$reno,$date,$name,$mail,$sub,$com,$url,$host,$pw)
								 = split(/<>/);
			if ($reno eq "") { $i++; }
			if ($i < $start) { next; }
			if ($i > $end) { last; }

			if ($mail) { $name="<a href=\"mailto:$mail\">$name</a>"; }
			($date,$dmy) = split(/\(/, $date);

			if ($url) { $url = "&lt;<a href=\"http://$url\" target='_top'>Home</a>&gt;"; }
			else { $url = '-'; }

			$com =~ s/<br>//ig;
			$com =~ s/</&lt;/g;
			$com =~ s/>/&gt;/g;
			if (length($com) > 40) {
				$com = substr($com,0,38);
				$com .= "...";
			}

			if ($reno eq "") { print "<tr><th colspan=8><hr></th></tr>\n"; }

			# 削除チェックボックス
			print "<tr><th><input type=checkbox name=del value=\"$no\"></th>";
			print "<td align=center>$no</td>";
			print "<td><small>$date</small></td><th>$sub</th><th>$name</th>";
			print "<td align=center>$url</td><td><small>$com</small></td>";
			print "<td><small>$host</small></td></tr>\n";

		}
		close(IN);

		print "<tr><th colspan=8><hr></th></tr>\n";
		print "</table></form>\n";
	}

	$next_page = $page + $p_log;
	$back_page = $page - $p_log;

	print "<P><table cellspacing=0 cellpadding=0><tr>\n";
	if ($back_page >= 0) {
		print "<td><form action=\"$script\" method=\"$method\">\n";
		print "<input type=hidden name=page value=\"$back_page\">\n";
		print "<input type=hidden name=pass value=\"$in{'pass'}\">\n";
		print "<input type=hidden name=mode value=\"admin\">\n";
		print "<input type=hidden name=action value=\"$in{'action'}\">\n";
		print "<input type=submit value=\"前の$p_log組\">\n";
		print "</form></td>\n";
	}
	if ($next_page < $i) {
		print "<td><form action=\"$script\" method=\"$method\">\n";
		print "<input type=hidden name=page value=\"$next_page\">\n";
		print "<input type=hidden name=pass value=\"$in{'pass'}\">\n";
		print "<input type=hidden name=mode value=\"admin\">\n";
		print "<input type=hidden name=action value=\"$in{'action'}\">\n";
		print "<input type=submit value=\"次の$p_log組\">\n";
		print "</form></td>\n";
	}
	print "</tr></table></center>\n";
	print <<"EOF";
										</p>
									</div>
								</td>
							</tr>
							<tr>
								<td align="center">
									$banner2<small><!-- $ver -->
- <a href='http://www.kent-web.com/' target='_top'>KENT</a> &amp; 
<a href='http://village.infoweb.ne.jp/~fwhf2602/' target='_top'>MakiMaki</a> -
								</td>
							</tr>
</td>
				</tr>
				<tr>
					<td align="right"><a href="#anchor_pagetop"><img src="../../img/btn_pagetop.gif" alt="" width="30" height="27" align="absmiddle" border="0">ページのトップへ</a></td>
				</tr>
			</table>
		</div>
	</BODY>
</HTML>
EOF
	exit;
}

#------------------#
#  ユーザ記事削除  #
#------------------#
sub usr_del {
	# POST限定
	if ($MethPost && !$post_flag) { &error("不正なアクセスです"); }

	if ($in{'no'} eq '' || $in{'pwd'} eq '')
		{ &error("記事Noまたは削除キーが入力モレです"); }

	# ロック処理
	if ($lockkey) { &lock; }

	open(IN,"$logfile") || &error("Open Error : $logfile");
	@lines = <IN>;
	close(IN);
	$top = shift(@lines);

	$flag=0;
	foreach (@lines) {
		($no,$reno,$dt,$name,$mail,$sub,$com,$url,$host,$pw) = split(/<>/);

		if ($flag == 0 && $in{'no'} eq "$no") {
			$PW = $pw;
			if ($reno eq "") { $flag=2; }
			else { $flag=1; }
		}
		elsif ($flag == 2 && $in{'no'} eq "$reno") { next; }
		else { push(@new,$_); }
	}

	if ($flag == 0) { &error("該当記事が見当たりません"); }
	if ($PW eq '') { &error("該当記事には削除キーが設定されていません"); }

	# 削除キーを照合
	$match = &decrypt("$in{'pwd'}","$PW");
	if ($match ne 'yes') { &error("削除キーが違います"); }

	# 更新
	unshift(@new,$top);
	open(OUT,">$logfile") || &error("Write Error : $logfile");
	print OUT @new;
	close(OUT);

	# ロック解除
	if ($lockkey) { &unlock; }
}

#--------------#
#  時間を取得  #
#--------------#
sub get_time {
	$ENV{'TZ'} = "JST-9";
	$times = time;
	($sec,$min,$hour,$mday,$mon,$year,$wday) = localtime($times);
	@week = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat');

	# 日時のフォーマット
	$date = sprintf("%04d/%02d/%02d(%s) %02d:%02d",
			$year+1900,$mon+1,$mday,$week[$wday],$hour,$min);
}

#----------------#
#  カウンタ処理  #
#----------------#
sub counter {
	# 閲覧時のみカウントアップ
	if ($mode eq '') { $cntup=1; } else { $cntup=0; }

	# カウントファイルを読みこみ
	open(IN,"$cntfile") || &error("Open Error : $cntfile");
	eval "flock(IN, 1);";
	$data = <IN>;
	close(IN);

	# IPチェックとログ破損チェック
	($cnt, $ip) = split(/:/, $data);
	if ($addr eq "$ip" || $cnt eq "") { $cntup=0; }

	# カウントアップ
	if ($cntup) {
		$cnt++;
		open(OUT,"+< $cntfile") || &error("Write Error : $cntfile");
		eval "flock(OUT, 2);";
		truncate(OUT, 0);
		seek(OUT, 0, 0);
		print OUT "$cnt\:$addr";
		close(OUT);
	}


	# 桁数調整
	while(length($cnt) < $mini_fig) { $cnt = '0' . $cnt; }
	@cnts = split(//, $cnt);

	# GIFカウンタ表示
	if ($counter == 2) {
		foreach (0 .. $#cnts) {
			print "<img src=\"$gif_path$cnts[$_]\.gif\" alt=\"$cnts[$_]\" width=\"$mini_w\" height=\"$mini_h\">";
		}
	}
	# テキストカウンタ表示
	else {
		print "<font color=\"$cnt_color\" face=\"verdana,Times New Roman,Arial\">$cnt</font><br>\n";
	}
}

#--------------#
#  ロック処理  #
#--------------#
sub lock {
	# symlink関数式ロック
	if ($lockkey == 1) {
		local($retry) = 5;
		while (!symlink(".", $lockfile)) {
			if (--$retry <= 0) { &error('Lock is busy'); }
			sleep(1);
		}
	# open関数式ロック
	} elsif ($lockkey == 2) {
		local($flag)=0;
		foreach (1 .. 5) {
			if (-e $lockfile) { sleep(1); }
			else {
				open(LOCK,">$lockfile")
					|| &error("Lock Error: $lockfile");
				close(LOCK);
				$flag = 1;
				last;
			}
		}
		if (!$flag) { &error; }
	# mkdir関数式ロック
	} elsif ($lockkey == 3) {
		if (-e $lockfile) {
			# 3分以上古いロックは削除する
			($mtime) = (stat($lockfile))[9];
			if ($mtime < time - 90) { rmdir($lockfile); }
		}
		local($retry) = 5;
		while (!mkdir($lockfile, 0755)) {
			if (--$retry <= 0) { &error('Lock is busy'); }
			sleep(1);
		}
	}
}

#--------------#
#  ロック解除  #
#--------------#
sub unlock {
	if ($lockkey == 1 || $lockkey == 2) { unlink($lockfile); }
	elsif ($lockkey == 3) { rmdir($lockfile); }
}

#--------------#
#  メール送信  #
#--------------#
sub mail_to {
	# メールタイトルを定義
	$MailSub = "[$title : $no] $in{'sub'}";

	# 記事の改行・タグを復元
	$com  = $in{'comment'};
	$com =~ s/<br>/\n/g;
	$com =~ s/&lt;/</g;
	$com =~ s/&gt;/>/g;
	$com =~ s/&quot;/\"/g;

	# メール本文を定義
	$MailBody = <<"EOM";
投稿日時：$date
ホスト名：$host
ブラウザ：$ENV{'HTTP_USER_AGENT'}

投稿者名：$in{'name'}
Ｅメール：$in{'email'}
ＵＲＬ  ：$in{'url'}
タイトル：$in{'sub'}
投稿記事：

$com
EOM
	# JISコード変換
    	&jcode'convert(*MailSub,'jis');
    	&jcode'convert(*MailBody,'jis');

	# メールアドレスがない場合はダミーメールに置き換え
	if ($in{'email'} eq "") { $email = "nomail\@xxx.xxx"; }
	else { $email = $in{'email'}; }

	if (!open(MAIL,"| $sendmail -t")) { &error("メール送信に失敗しました"); }
	print MAIL "To: $mailto\n";
	print MAIL "From: $email\n";
	print MAIL "Subject: $MailSub\n";
	print MAIL "MIME-Version: 1.0\n";
	print MAIL "Content-type: text/plain; charset=ISO-2022-JP\n";
	print MAIL "Content-Transfer-Encoding: 7bit\n";
	print MAIL "X-Mailer: $ver\n\n";
	print MAIL "--------------------------------------------------------\n";
	print MAIL "$MailBody\n";
	print MAIL "--------------------------------------------------------\n";
	close(MAIL);
}

#----------------------#
#  パスワード暗号処理  #
#----------------------#
sub encrypt {
	local($inpw) = $_[0];
	local(@SALT, $salt, $encrypt);

	@SALT = ('a'..'z', 'A'..'Z', '0'..'9', '.', '/');
	srand;
	$salt = $SALT[int(rand(@SALT))] . $SALT[int(rand(@SALT))];
	$encrypt = crypt($inpw, $salt) || crypt ($inpw, '$1$' . $salt);
	return $encrypt;
}

#----------------------#
#  パスワード照合処理  #
#----------------------#
sub decrypt {
	local($inpw, $logpw) = @_;
	local($salt, $key, $check);

	$salt = $logpw =~ /^\$1\$(.*)\$/ && $1 || substr($logpw, 0, 2);
	$check = "no";
	if (crypt($inpw, $salt) eq "$logpw" || crypt($inpw, '$1$' . $salt) eq "$logpw")
		{ $check = "yes"; }
	return $check;
}

#------------------#
#  HTMLのヘッダー  #
#------------------#
sub header {
	$head_flag=1;
	print "Content-type: text/html\n\n";
	print <<"EOM";
<HTML lang="ja">
<HEAD>
<TITLE>大館市・田代町合併協議会／あなたの声をお聞かせください</TITLE>
<meta name="keywords" content="大館市・田代町合併協議会,大館市田代町合併協議会,大館市,田代町,秋田県,合併,法定,法定協議会,任意,市町村合併">
<meta name="description" content="秋田県大館市・田代町合併協議会（法定）の公式サイトです。">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=x-sjis">
		<link href="../../comon.css" rel="stylesheet" media="screen">
		<style type="text/css" media="screen"><!--
#layer1 { position: absolute; top: 51px; left: 0px; width: 191px; height: 26px; visibility: visible; display: block }
#layer2  { position: absolute; top: 51px; left: 0px; width: 191px; height: 286px; visibility: hidden; display: block }
--></style>
		<csactions>
			<csaction name="BC6954D70" class="ShowHide" type="onevent" val0="layer2" val1="1"></csaction>
			<csaction name="BC6956541" class="ShowHide" type="onevent" val0="layer2" val1="1"></csaction>
			<csaction name="BC69565F2" class="ShowHide" type="onevent" val0="layer2" val1="0"></csaction>
			<csaction name="BC69566D3" class="ShowHide" type="onevent" val0="layer2" val1="1"></csaction>
			<csaction name="BC6956754" class="ShowHide" type="onevent" val0="layer2" val1="0"></csaction>
			<csaction name="BC6956815" class="ShowHide" type="onevent" val0="layer2" val1="1"></csaction>
			<csaction name="BC69568B6" class="ShowHide" type="onevent" val0="layer2" val1="0"></csaction>
			<csaction name="BC6956977" class="ShowHide" type="onevent" val0="layer2" val1="1"></csaction>
			<csaction name="BC69569F8" class="ShowHide" type="onevent" val0="layer2" val1="0"></csaction>
			<csaction name="BC6956A99" class="ShowHide" type="onevent" val0="layer2" val1="1"></csaction>
			<csaction name="BC6956B110" class="ShowHide" type="onevent" val0="layer2" val1="0"></csaction>
			<csaction name="BC6956BC11" class="ShowHide" type="onevent" val0="layer2" val1="1"></csaction>
			<csaction name="BC6956C712" class="ShowHide" type="onevent" val0="layer2" val1="0"></csaction>
			<csaction name="BC6956D213" class="ShowHide" type="onevent" val0="layer2" val1="1"></csaction>
			<csaction name="BC6956DD14" class="ShowHide" type="onevent" val0="layer2" val1="0"></csaction>
			<csaction name="BC6956EC15" class="ShowHide" type="onevent" val0="layer2" val1="1"></csaction>
			<csaction name="BC6956F416" class="ShowHide" type="onevent" val0="layer2" val1="0"></csaction>
			<csaction name="BC6956FF17" class="ShowHide" type="onevent" val0="layer2" val1="1"></csaction>
			<csaction name="BC69570818" class="ShowHide" type="onevent" val0="layer2" val1="0"></csaction>
			<csaction name="BC69571619" class="ShowHide" type="onevent" val0="layer2" val1="1"></csaction>
			<csaction name="BC69572120" class="ShowHide" type="onevent" val0="layer2" val1="0"></csaction>
			<csaction name="BC69572D21" class="ShowHide" type="onevent" val0="layer2" val1="1"></csaction>
			<csaction name="BC69573622" class="ShowHide" type="onevent" val0="layer2" val1="0"></csaction>
		</csactions>
		<csscriptdict>
			<script type="text/javascript"><!--
CSInit = new Array;
function CSScriptInit() {
if(typeof(skipPage) != "undefined") { if(skipPage) return; }
idxArray = new Array;
for(var i=0;i<CSInit.length;i++)
	idxArray[i] = i;
CSAction2(CSInit, idxArray);}
CSAg = window.navigator.userAgent; CSBVers = parseInt(CSAg.charAt(CSAg.indexOf("/")+1),10);
CSIsW3CDOM = ((document.getElementById) && !(IsIE()&&CSBVers<6)) ? true : false;
function IsIE() { return CSAg.indexOf("MSIE") > 0;}
function CSIEStyl(s) { return document.all.tags("div")[s].style; }
function CSNSStyl(s) { if (CSIsW3CDOM) return document.getElementById(s).style; else return CSFindElement(s,0);  }
CSIImg=false;
function CSInitImgID() {if (!CSIImg && document.images) { for (var i=0; i<document.images.length; i++) { if (!document.images[i].id) document.images[i].id=document.images[i].name; } CSIImg = true;}}
function CSFindElement(n,ly) { if (CSBVers<4) return document[n];
	if (CSIsW3CDOM) {CSInitImgID();return(document.getElementById(n));}
	var curDoc = ly?ly.document:document; var elem = curDoc[n];
	if (!elem) {for (var i=0;i<curDoc.layers.length;i++) {elem=CSFindElement(n,curDoc.layers[i]); if (elem) return elem; }}
	return elem;
}
function CSGetImage(n) {if(document.images) {return ((!IsIE()&&CSBVers<5)?CSFindElement(n,0):document.images[n]);} else {return null;}}
CSDInit=false;
function CSIDOM() { if (CSDInit)return; CSDInit=true; if(document.getElementsByTagName) {var n = document.getElementsByTagName('DIV'); for (var i=0;i<n.length;i++) {CSICSS2Prop(n[i].id);}}}
function CSICSS2Prop(id) { var n = document.getElementsByTagName('STYLE');for (var i=0;i<n.length;i++) { var cn = n[i].childNodes; for (var j=0;j<cn.length;j++) { CSSetCSS2Props(CSFetchStyle(cn[j].data, id),id); }}}
function CSFetchStyle(sc, id) {
	var s=sc; while(s.indexOf("#")!=-1) { s=s.substring(s.indexOf("#")+1,sc.length); if (s.substring(0,s.indexOf("{")).toUpperCase().indexOf(id.toUpperCase())!=-1) return(s.substring(s.indexOf("{")+1,s.indexOf("}")));}
	return "";
}
function CSGetStyleAttrValue (si, id) {
	var s=si.toUpperCase();
	var myID=id.toUpperCase()+":";
	var id1=s.indexOf(myID);
	if (id1==-1) return "";
	s=s.substring(id1+myID.length+1,si.length);
	var id2=s.indexOf(";");
	return ((id2==-1)?s:s.substring(0,id2));
}
function CSSetCSS2Props(si, id) {
	var el=document.getElementById(id);
	if (el==null) return;
	var style=document.getElementById(id).style;
	if (style) {
		if (style.left=="") style.left=CSGetStyleAttrValue(si,"left");
		if (style.top=="") style.top=CSGetStyleAttrValue(si,"top");
		if (style.width=="") style.width=CSGetStyleAttrValue(si,"width");
		if (style.height=="") style.height=CSGetStyleAttrValue(si,"height");
		if (style.visibility=="") style.visibility=CSGetStyleAttrValue(si,"visibility");
		if (style.zIndex=="") style.zIndex=CSGetStyleAttrValue(si,"z-index");
	}
}
function CSClickReturn () {
	var bAgent = window.navigator.userAgent; 
	var bAppName = window.navigator.appName;
	if ((bAppName.indexOf("Explorer") >= 0) && (bAgent.indexOf("Mozilla/3") >= 0) && (bAgent.indexOf("Mac") >= 0))
		return true; // dont follow link
	else return false; // dont follow link
}
function CSButtonReturn () { return !CSClickReturn(); }
CSIm=new Object();
function CSIShow(n,i) {
	if (document.images) {
		if (CSIm[n]) {
			var img=CSGetImage(n);
			if (img&&typeof(CSIm[n][i].src)!="undefined") {img.src=CSIm[n][i].src;}
			if(i!=0) self.status=CSIm[n][3]; else self.status=" ";
			return true;
		}
	}
	return false;
}
function CSILoad(action) {
	im=action[1];
	if (document.images) {
		CSIm[im]=new Object();
		for (var i=2;i<5;i++) {
			if (action[i]!='') {CSIm[im][i-2]=new Image(); CSIm[im][i-2].src=action[i];}
			else CSIm[im][i-2]=0;
		}
		CSIm[im][3] = action[5];
	}
}
CSStopExecution=false;
function CSAction(array) {return CSAction2(CSAct, array);}
function CSAction2(fct, array) { 
	var result;
	for (var i=0;i<array.length;i++) {
		if(CSStopExecution) return false; 
		var aa = fct[array[i]];
		if (aa == null) return false;
		var ta = new Array;
		for(var j=1;j<aa.length;j++) {
			if((aa[j]!=null)&&(typeof(aa[j])=="object")&&(aa[j].length==2)){
				if(aa[j][0]=="VAR"){ta[j]=CSStateArray[aa[j][1]];}
				else{if(aa[j][0]=="ACT"){ta[j]=CSAction(new Array(new String(aa[j][1])));}
				else ta[j]=aa[j];}
			} else ta[j]=aa[j];
		}			
		result=aa[0](ta);
	}
	return result;
}
CSAct = new Object;
function CSSetStyleVis(s,v) {
	if (CSIsW3CDOM){CSIDOM();document.getElementById(s).style.visibility=(v==0)?"hidden":"visible";}
	else if(IsIE())CSIEStyl(s).visibility=(v==0)?"hidden":"visible";
	else CSNSStyl(s).visibility=(v==0)?'hide':'show';
}
function CSGetStyleVis(s) {
	if (CSIsW3CDOM) {CSIDOM();return(document.getElementById(s).style.visibility=="hidden")?0:1;}
	else if(IsIE())return(CSIEStyl(s).visibility=="hidden")?0:1;
	else return(CSNSStyl(s).visibility=='hide')?0:1;
}
function CSShowHide(action) {
	if (action[1] == '') return;
	var type=action[2];
	if(type==0) CSSetStyleVis(action[1],0);
	else if(type==1) CSSetStyleVis(action[1],1);
	else if(type==2) { 
		if (CSGetStyleVis(action[1]) == 0) CSSetStyleVis(action[1],1);
		else CSSetStyleVis(action[1],0);
	}
}

// --></script>
		</csscriptdict>
		<csactiondict>
			<script type="text/javascript"><!--
CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'button_menu2',/*URL*/'../../img/btn_menu.gif',/*URL*/'../../img/btn_menu.gif',/*URL*/'','');
CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'button_menu3',/*URL*/'../../img/btn_menu.gif',/*URL*/'../../img/btn_menu.gif',/*URL*/'','');
CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'button1',/*URL*/'../../img/btn/btn1.gif',/*URL*/'../../img/btn/btn1.gif',/*URL*/'','');
CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'button2',/*URL*/'../../img/btn/btn2.gif',/*URL*/'../../img/btn/btn2.gif',/*URL*/'','');
CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'button3',/*URL*/'../../img/btn/btn3.gif',/*URL*/'../../img/btn/btn3.gif',/*URL*/'','');
CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'button4',/*URL*/'../../img/btn/btn4.gif',/*URL*/'../../img/btn/btn4.gif',/*URL*/'','');
CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'button5',/*URL*/'../../img/btn/btn5.gif',/*URL*/'../../img/btn/btn5.gif',/*URL*/'','');
CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'button6',/*URL*/'../../img/btn/btn6.gif',/*URL*/'../../img/btn/btn6.gif',/*URL*/'','');
CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'button7',/*URL*/'../../img/btn/btn7.gif',/*URL*/'../../img/btn/btn7.gif',/*URL*/'','');
CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'button8',/*URL*/'../../img/btn/btn8.gif',/*URL*/'../../img/btn/btn8.gif',/*URL*/'','');
CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'button9',/*URL*/'../../img/btn/btn9.gif',/*URL*/'../../img/btn/btn9.gif',/*URL*/'','');
CSInit[CSInit.length] = new Array(CSILoad,/*CMP*/'button10',/*URL*/'../../img/btn/btn10.gif',/*URL*/'../../img/btn/btn10.gif',/*URL*/'','');
CSAct[/*CMP*/ 'BC6954D70'] = new Array(CSShowHide,/*CMP*/ 'layer2',1);
CSAct[/*CMP*/ 'BC6956541'] = new Array(CSShowHide,/*CMP*/ 'layer2',1);
CSAct[/*CMP*/ 'BC69565F2'] = new Array(CSShowHide,/*CMP*/ 'layer2',0);
CSAct[/*CMP*/ 'BC69566D3'] = new Array(CSShowHide,/*CMP*/ 'layer2',1);
CSAct[/*CMP*/ 'BC6956754'] = new Array(CSShowHide,/*CMP*/ 'layer2',0);
CSAct[/*CMP*/ 'BC6956815'] = new Array(CSShowHide,/*CMP*/ 'layer2',1);
CSAct[/*CMP*/ 'BC69568B6'] = new Array(CSShowHide,/*CMP*/ 'layer2',0);
CSAct[/*CMP*/ 'BC6956977'] = new Array(CSShowHide,/*CMP*/ 'layer2',1);
CSAct[/*CMP*/ 'BC69569F8'] = new Array(CSShowHide,/*CMP*/ 'layer2',0);
CSAct[/*CMP*/ 'BC6956A99'] = new Array(CSShowHide,/*CMP*/ 'layer2',1);
CSAct[/*CMP*/ 'BC6956B110'] = new Array(CSShowHide,/*CMP*/ 'layer2',0);
CSAct[/*CMP*/ 'BC6956BC11'] = new Array(CSShowHide,/*CMP*/ 'layer2',1);
CSAct[/*CMP*/ 'BC6956C712'] = new Array(CSShowHide,/*CMP*/ 'layer2',0);
CSAct[/*CMP*/ 'BC6956D213'] = new Array(CSShowHide,/*CMP*/ 'layer2',1);
CSAct[/*CMP*/ 'BC6956DD14'] = new Array(CSShowHide,/*CMP*/ 'layer2',0);
CSAct[/*CMP*/ 'BC6956EC15'] = new Array(CSShowHide,/*CMP*/ 'layer2',1);
CSAct[/*CMP*/ 'BC6956F416'] = new Array(CSShowHide,/*CMP*/ 'layer2',0);
CSAct[/*CMP*/ 'BC6956FF17'] = new Array(CSShowHide,/*CMP*/ 'layer2',1);
CSAct[/*CMP*/ 'BC69570818'] = new Array(CSShowHide,/*CMP*/ 'layer2',0);
CSAct[/*CMP*/ 'BC69571619'] = new Array(CSShowHide,/*CMP*/ 'layer2',1);
CSAct[/*CMP*/ 'BC69572120'] = new Array(CSShowHide,/*CMP*/ 'layer2',0);
CSAct[/*CMP*/ 'BC69572D21'] = new Array(CSShowHide,/*CMP*/ 'layer2',1);
CSAct[/*CMP*/ 'BC69573622'] = new Array(CSShowHide,/*CMP*/ 'layer2',0);

// --></script>
		</csactiondict>
	</HEAD>
<BODY onload="CSScriptInit();" background="../../bg_img/bg.gif" BGCOLOR=white LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
		<div align="left">
			<table width=100% border=0 cellpadding=0 cellspacing=0 height="51">
				<tr>
					<td colspan=4 valign="top"><a name="anchor_pagetop"></a><img src="../img/page_title8_2.gif" alt="みんなの広場" border="0"></td>
					<td valign="top"></td>
					<td align="right" valign="top" width="190"><img src="../../img/title_next.gif" alt="大館市・田代町合併協議会" width="190" height="51" border="0"></td>
				</tr>
			</table>
			<div id="layer1">
				<table border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td align="left"><a title="ホームページへ" href="../../index.shtml"><img src="../../img/btn_home.gif" alt="" width="65" height="26" border="0"></a></td>
						<td align="left"><csobj al="メニューを表示" csover="BC6954D70" h="26" ht="../../img/btn_menu.gif" t="Button" w="126"><a href="#" onmouseover="CSAction(new Array(/*CMP*/'BC6954D70'));return CSIShow(/*CMP*/'button_menu2',1)" onmouseout="return CSIShow(/*CMP*/'button_menu2',0)" onclick="return CSButtonReturn()"><img src="../../img/btn_menu.gif" width="126" height="26" name="button_menu2" border="0" alt="メニューを表示"></a></csobj></td>
					</tr>
				</table>
			</div>
			<div id="layer2">
				<table border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td align="left"><a href="../../index.shtml"><img src="../../img/btn_home.gif" alt="ホーム" width="65" height="26" border="0"></a></td>
						<td align="left"><csobj al="" csout="BC69565F2" csover="BC6956541" h="26" ht="../../img/btn_menu.gif" t="Button" w="126"><a href="#" onmouseover="CSAction(new Array(/*CMP*/'BC6956541'));return CSIShow(/*CMP*/'button_menu3',1)" onmouseout="CSAction(new Array(/*CMP*/'BC69565F2'));return CSIShow(/*CMP*/'button_menu3',0)" onclick="return CSButtonReturn()"><img src="../../img/btn_menu.gif" width="126" height="26" name="button_menu3" border="0" alt=""></a></csobj></td>
					</tr>
					<tr>
						<td colspan="2" align="left"><csobj al="合併協議会とは" csout="BC6956754" csover="BC69566D3" h="26" ht="../../img/btn/btn1.gif" t="Button" w="191"><a href="../../1gappei/index.shtml" onmouseover="CSAction(new Array(/*CMP*/'BC69566D3'));return CSIShow(/*CMP*/'button1',1)" onmouseout="CSAction(new Array(/*CMP*/'BC6956754'));return CSIShow(/*CMP*/'button1',0)" onclick="return CSButtonReturn()"><img src="../../img/btn/btn1.gif" width="191" height="26" name="button1" border="0" alt="合併協議会とは"></a></csobj></td>
					</tr>
					<tr>
						<td colspan="2" align="left"><csobj al="これまでの経過" csout="BC69568B6" csover="BC6956815" h="26" ht="../../img/btn/btn2.gif" t="Button" w="191"><a href="../../2keika/index.shtml" onmouseover="CSAction(new Array(/*CMP*/'BC6956815'));return CSIShow(/*CMP*/'button2',1)" onmouseout="CSAction(new Array(/*CMP*/'BC69568B6'));return CSIShow(/*CMP*/'button2',0)" onclick="return CSButtonReturn()"><img src="../../img/btn/btn2.gif" width="191" height="26" name="button2" border="0" alt="これまでの経過"></a></csobj></td>
					</tr>
					<tr>
						<td colspan="2" align="left"><csobj al="各種会議・住民説明会のお知らせ" csout="BC69569F8" csover="BC6956977" h="26" ht="../../img/btn/btn3.gif" t="Button" w="191"><a href="../../3osirase/index.shtml" onmouseover="CSAction(new Array(/*CMP*/'BC6956977'));return CSIShow(/*CMP*/'button3',1)" onmouseout="CSAction(new Array(/*CMP*/'BC69569F8'));return CSIShow(/*CMP*/'button3',0)" onclick="return CSButtonReturn()"><img src="../../img/btn/btn3.gif" width="191" height="26" name="button3" border="0" alt="各種会議・住民説明会のお知らせ"></a></csobj></td>
					</tr>
					<tr>
						<td colspan="2" align="left"><csobj al="協議状況" csout="BC6956B110" csover="BC6956A99" h="26" ht="../../img/btn/btn4.gif" t="Button" w="191"><a href="../../4jyoukyo/index.shtml" onmouseover="CSAction(new Array(/*CMP*/'BC6956A99'));return CSIShow(/*CMP*/'button4',1)" onmouseout="CSAction(new Array(/*CMP*/'BC6956B110'));return CSIShow(/*CMP*/'button4',0)" onclick="return CSButtonReturn()"><img src="../../img/btn/btn4.gif" width="191" height="26" name="button4" border="0" alt="協議状況"></a></csobj></td>
					</tr>
					<tr>
						<td colspan="2" align="left"><csobj al="合併協定項目" csout="BC6956C712" csover="BC6956BC11" h="26" ht="../../img/btn/btn5.gif" t="Button" w="191"><a href="../../5kyoutei/kekka.shtml" onmouseover="CSAction(new Array(/*CMP*/'BC6956BC11'));return CSIShow(/*CMP*/'button5',1)" onmouseout="CSAction(new Array(/*CMP*/'BC6956C712'));return CSIShow(/*CMP*/'button5',0)" onclick="return CSButtonReturn()"><img src="../../img/btn/btn5.gif" width="191" height="26" name="button5" border="0" alt="合併協定項目"></a></csobj></td>
					</tr>
					<tr>
						<td colspan="2" align="left"><csobj al="わたしたちのまちってどんなとこ？" csout="BC6956DD14" csover="BC6956D213" h="26" ht="../../img/btn/btn6.gif" t="Button" w="191"><a href="../../6machi/index.shtml" onmouseover="CSAction(new Array(/*CMP*/'BC6956D213'));return CSIShow(/*CMP*/'button6',1)" onmouseout="CSAction(new Array(/*CMP*/'BC6956DD14'));return CSIShow(/*CMP*/'button6',0)" onclick="return CSButtonReturn()"><img src="../../img/btn/btn6.gif" width="191" height="26" name="button6" border="0" alt="わたしたちのまちってどんなとこ？"></a></csobj></td>
					</tr>
					<tr>
						<td colspan="2" align="left"><csobj al="合併協議会だより" csout="BC6956F416" csover="BC6956EC15" h="26" ht="../../img/btn/btn7.gif" t="Button" w="191"><a href="../../7dayori/index.shtml" onmouseover="CSAction(new Array(/*CMP*/'BC6956EC15'));return CSIShow(/*CMP*/'button7',1)" onmouseout="CSAction(new Array(/*CMP*/'BC6956F416'));return CSIShow(/*CMP*/'button7',0)" onclick="return CSButtonReturn()"><img src="../../img/btn/btn7.gif" width="191" height="26" name="button7" border="0" alt="合併協議会だより"></a></csobj></td>
					</tr>
					<tr>
						<td colspan="2" align="left"><csobj al="あなたの声をお聞かせください" csout="BC69570818" csover="BC6956FF17" h="26" ht="../../img/btn/btn8.gif" t="Button" w="191"><a href="../../8iken/index.shtml" onmouseover="CSAction(new Array(/*CMP*/'BC6956FF17'));return CSIShow(/*CMP*/'button8',1)" onmouseout="CSAction(new Array(/*CMP*/'BC69570818'));return CSIShow(/*CMP*/'button8',0)" onclick="return CSButtonReturn()"><img src="../../img/btn/btn8.gif" width="191" height="26" name="button8" border="0" alt="あなたの声をお聞かせください"></a></csobj></td>
					</tr>
					<tr>
						<td colspan="2" align="left"><csobj al="資料室" csout="BC69572120" csover="BC69571619" h="26" ht="../../img/btn/btn9.gif" t="Button" w="191"><a href="../../9siryo/index.shtml" onmouseover="CSAction(new Array(/*CMP*/'BC69571619'));return CSIShow(/*CMP*/'button9',1)" onmouseout="CSAction(new Array(/*CMP*/'BC69572120'));return CSIShow(/*CMP*/'button9',0)" onclick="return CSButtonReturn()"><img src="../../img/btn/btn9.gif" width="191" height="26" name="button9" border="0" alt="資料室"></a></csobj></td>
					</tr>
					<tr>
						<td colspan="2" align="left"><csobj al="リンク" csout="BC69573622" csover="BC69572D21" h="26" ht="../../img/btn/btn10.gif" t="Button" w="191"><a href="../../10link/index.shtml" onmouseover="CSAction(new Array(/*CMP*/'BC69572D21'));return CSIShow(/*CMP*/'button10',1)" onmouseout="CSAction(new Array(/*CMP*/'BC69573622'));return CSIShow(/*CMP*/'button10',0)" onclick="return CSButtonReturn()"><img src="../../img/btn/btn10.gif" width="191" height="26" name="button10" border="0" alt="リンク"></a></csobj></td>
					</tr>
				</table>
			</div>
			<p></p>
		</div>
		<div align="center">
			<table width="770" border="0" cellspacing="0" cellpadding="10">
				<tr>
					<td><br><br>
EOM
}

#-----------------#
#  自動URLリンク  #
#-----------------#
sub auto_link {
	$_[0] =~ s/([^=^\"]|^)(http\:[\w\.\~\-\/\?\&\+\=\:\@\%\;\#\%]+)/$1<a href=\"$2\" target='_top'>$2<\/a>/g;
}

#--------------------#
#  画像イメージ表示  #
#--------------------#
sub image {
	&header;
	print "<center><hr width=\"75%\">\n";
	print "<b><big>画像イメージサンプル</big></b>\n";
	print "<P><small>- 現在登録されている画像イメージは以下のとおりです -</small>\n";
	print "<hr width=\"75%\">\n";
	print "<P><table border=1 cellpadding=5 cellspacing=0><tr>\n";

	$i=0; $j=0;
	$stop = @icon1;
	foreach (0 .. $#icon1) {
		$i++; $j++;
		print "<th><img src=\"$imgurl$icon1[$_]\" ALIGN=middle> $icon2[$_]</th>\n";
		if ($i >= 5) { print '</tr><tr>'; $i=0; }
		if ($j eq "$stop") {
			if ($i == 0) { last; }
			while ($i < 5) { print "<th><br></th>"; $i++; }
		}
	}

	print "</tr></table><br>\n";
	print "<FORM><INPUT TYPE=\"button\" VALUE=\"  CLOSE  \" onClick=\"top.close();\"></FORM></center>\n";
	print <<"EOF";
										</p>
									</div>
								</td>
							</tr>
							<tr>
								<td align="center">
									$banner2<small><!-- $ver -->
- <a href='http://www.kent-web.com/' target='_top'>KENT</a> &amp; 
<a href='http://village.infoweb.ne.jp/~fwhf2602/' target='_top'>MakiMaki</a> -
								</td>
							</tr>
</td>
				</tr>
				<tr>
					<td align="right"><a href="#anchor_pagetop"><img src="../../img/btn_pagetop.gif" alt="" width="30" height="27" align="absmiddle" border="0">ページのトップへ</a></td>
				</tr>
			</table>
		</div>
	</BODY>
</HTML>
EOF
	exit;
}

#----------------#
#  ホスト名取得  #
#----------------#
sub get_host {
	$host = $ENV{'REMOTE_HOST'};
	$addr = $ENV{'REMOTE_ADDR'};

	if ($get_remotehost) {
		if ($host eq "" || $host eq "$addr") {
			$host = gethostbyaddr(pack("C4", split(/\./, $addr)), 2);
		}
	}
	if ($host eq "") { $host = $addr; }
}

#----------------#
#  過去ログ生成  #
#----------------#
sub pastlog {
	local($past_flag)=0;

	# 過去NOを開く
	open(NO,"$nofile") || &error("Open Error : $nofile");
	$count = <NO>;
	close(NO);

	# 過去ログのファイル名を定義
	$pastfile  = "$pastdir$count\.dat";

	# 過去ログを開く
	open(IN,"$pastfile") || &error("Open Error : $pastfile");
	@past = <IN>;
	close(IN);

	# 規定の行数をオーバーすると次ファイルを自動生成
#	if ($#past > $log_line) {
#		$past_flag=1;

		# カウントファイル更新
#		$count++;
#		open(NO,">$nofile") || &error("Write Error : $nofile");
#		print NO $count;

#		close(NO);

#		$pastfile = "$pastdir$count\.dat";
#		@past=();
#	}

	@temp=();
	foreach (@data) {
		($pno,$preno,$pdate,$pname,$pmail,$psub,$pcom,$purl,$pho)
								 = split(/<>/);
		if ($pmail) { $pname = "<a href=\"mailto:$pmail\">$pname</a>"; }
		if ($purl) { $purl = "&lt;<a href=\"http://$purl\" target='_top'>HOME</a>&gt;"; }
		if ($preno) { $pno = "$prenoへのレス"; }

		# 保存記事をフォーマット
		push(@temp,"<hr>[$pno] <font color=\"$sub_color\"><b>$psub</b></font> 投稿者：<b>$pname</b> <small>投稿日：$pdate</small> $purl<br><blockquote>$pcom</blockquote><!-- $pho -->\n");
	}

	# 過去ログを更新
	unshift(@past,@temp);
	open(OUT,">$pastfile") || &error("Write Error : $pastfile");
	print OUT @past;
	close(OUT);

	if ($past_flag) { chmod(0666,$pastfile); }
}

#------------#
#  過去ログ  #
#------------#
sub past {
	open(IN,"$nofile") || &error("Open Error : $nofile");
	$pastno = <IN>;
	close(IN);

	if (!$in{'pastlog'}) { $in{'pastlog'} = $pastno; }

	&header;
	print <<"EOM";
[<a href="$script?">掲示板に戻る</a>]

<table width="100%"><tr><th bgcolor="#000080">
  <font color="#FFFFFF">過去ログ[$in{'pastlog'}]</font>
</th></tr></table>
<P><table><tr><td>
<form action="$script" method="$method">
<input type=hidden name=mode value=past>
過去ログ：<select name=pastlog>
EOM

	$pastkey = $pastno;
	while ($pastkey > 0) {
		if ($in{'pastlog'} == $pastkey) {
			print "<option value=\"$pastkey\" selected>$pastkey Page\n";
		} else {
			print "<option value=\"$pastkey\">$pastkey Page\n";
		}
		$pastkey--;
	}
	print "</select>\n<input type=submit value='移動'></td></form>\n";
	print "<td width=30></td><td>\n";
	print "<form action=\"$script\" method=\"$method\">\n";
	print "<input type=hidden name=mode value=past>\n";
	print "<input type=hidden name=pastlog value=\"$in{'pastlog'}\">\n";
	print "ワード検索：<input type=text name=word size=30 value=\"$in{'word'}\">\n";
	print "条件：<select name=cond>\n";

	foreach ('AND', 'OR') {
		if ($in{'cond'} eq "$_") {
			print "<option value=\"$_\" selected>$_\n";
		} else {
			print "<option value=\"$_\">$_\n";
		}
	}
	print "</select>\n";
	print "表\示：<select name=view>\n";
	if ($in{'view'} eq "") { $in{'view'} = $p_log; }
	foreach (5,10,15,20,25,30) {
		if ($in{'view'} eq "$_") {
			print "<option value=\"$_\" selected>$_件\n";
		} else {
			print "<option value=\"$_\">$_件\n";
		}
	}
	print "</select>\n<input type=submit value='検索'></td></form>\n";
	print "</td></tr></table>\n";

	# 表示ログを定義
	$file = "$pastdir$in{'pastlog'}\.dat";

	# ワード検索処理
	if ($in{'word'} ne "") {
		$in{'word'} =~ s/　/ /g;
		@pairs = split(/\s+/, $in{'word'});

		@new=();
		open(IN,"$file") || &error("Open Error : $file");
		while (<IN>) {
			$flag=0;
			foreach $pair (@pairs) {
				if (index($_,$pair) >= 0) {
					$flag=1;
					if ($in{'cond'} eq 'OR') { last; }
				} else {
					if ($in{'cond'} eq 'AND') { $flag=0; last; }
				}
			}
			if ($flag) { push(@new,$_); }
		}
		close(IN);

		$count = @new;
		print "検索結果：<b>$count</b>件\n";
		if ($page eq '') { $page = 0; }
		$end_data = @new - 1;
		$page_end = $page + $in{'view'} - 1;
		if ($page_end >= $end_data) { $page_end = $end_data; }

		$next_line = $page_end + 1;
		$back_line = $page - $in{'view'};

		if ($back_line >= 0) {
			print "[<a href=\"$script?mode=past&page=$back_line&word=$word&view=$in{'view'}&cond=$in{'cond'}&pastlog=$in{'pastlog'}\">前の$in{'view'}件</a>]\n";
		}
		if ($page_end ne "$end_data") {
			print "[<a href=\"$script?mode=past&page=$next_line&word=$word&view=$in{'view'}&cond=$in{'cond'}&pastlog=$in{'pastlog'}\">次の$in{'view'}件</a>]\n";
		}
		print "[<a href=\"$script?mode=past&pastlog=$in{'pastlog'}\">検索やり直し</a>]\n";

		# 表示開始
		foreach ($page .. $page_end) {
			print $new[$_];
		}
		print "<hr>\n";
		print "</body></html>\n";
		exit;
	}

	# ページ区切り処理
	$start = $page + 1;
	$end   = $page + $p_log;

	$i=0;
	open(IN,"$file") || &error("Open Error : $file");
	while (<IN>) {
		$flag=0;
		if ($_ =~ /^\<hr\>\[\d+\]/) { $flag=1; $i++; }
		if ($i < $start) { next; }
		if ($i > $end) { last; }

		if ($flag) { print $_; }
		else {
			$_ =~ s/<hr>//ig;
			print "<blockquote>$_</blockquote>\n";
		}
	}
	close(IN);
	print "<hr>\n";

	$next_page = $page + $p_log;
	$back_page = $page - $p_log;

	print "<table>\n";
	if ($back_page >= 0) {
		print "<td><form action=\"$script\" method=\"$method\">\n";
		print "<input type=hidden name=mode value=past>\n";
		print "<input type=hidden name=pastlog value=\"$in{'pastlog'}\">\n";
		print "<input type=hidden name=page value=\"$back_page\">\n";
		print "<input type=submit value=\"前の$p_log件\">\n";
		print "</td></form>\n";
	}
	if ($next_page < $i) {
		print "<td><form action=\"$script\" method=\"$method\">\n";
		print "<input type=hidden name=mode value=past>\n";
		print "<input type=hidden name=pastlog value=\"$in{'pastlog'}\">\n";
		print "<input type=hidden name=page value=\"$next_page\">\n";
		print "<input type=submit value=\"次の$p_log件\">\n";
		print "</td></form>\n";
	}
	print "</table>\n";
	print <<"EOF";
										</p>
									</div>
								</td>
							</tr>
							<tr>
								<td align="center">
									$banner2<small><!-- $ver -->
- <a href='http://www.kent-web.com/' target='_top'>KENT</a> &amp; 
<a href='http://village.infoweb.ne.jp/~fwhf2602/' target='_top'>MakiMaki</a> -
								</td>
							</tr>
</td>
				</tr>
				<tr>
					<td align="right"><a href="#anchor_pagetop"><img src="../../img/btn_pagetop.gif" alt="" width="30" height="27" align="absmiddle" border="0">ページのトップへ</a></td>
				</tr>
			</table>
		</div>
	</BODY>
</HTML>
EOF
	exit;
}

#------------------#
#  チェックモード  #
#------------------#
sub check {
	&header;
	print "<h2>Check Mode</h2>\n";
	print "<UL>\n";

	# ログパス
	if (-e $logfile) { print "<LI>ログファイルのパス：OK\n"; }
	else { print "<LI>ログファイルのパス：NG → $logfile\n"; }

	# ログパーミッション
	if (-r $logfile && -w $logfile) { print "<LI>ログファイルのパーミッション：OK\n"; }
	else { print "<LI>ログファイルのパーミッション：NG\n"; }

	# カウンタログ
	print "<LI>カウンタ：";
	if ($counter) {
		print "設定あり\n";
		if (-e $cntfile) { print "<LI>カウンタログファイルのパス：OK\n"; }
		else { print "<LI>カウンタログファイルのパス：NG → $cntfile\n"; }
	}
	else { print "設定なし\n"; }

	# ロックディレクトリ
	print "<LI>ロック形式：";
	if ($lockkey == 0) { print "ロック設定なし\n"; }
	else {
		if ($lockkey == 1) { print "symlink\n"; }
		else { print "open\n"; }

		($lockdir) = split(/\/yybbs\.lock$/, $lockfile);
		if (-d $lockdir) { print "<LI>ロックディレクトリのパス：OK\n"; }
		else { print "<LI>ロックディレクトリ：NG → $lockdir\n"; }

		if (-r $lockdir && -w $lockdir && -x $lockdir) {
			print "<LI>ロックディレクトリのパーミッション：OK\n";
		} else {
			print "<LI>ロックディレクトリのパーミッション：NG → $lockdir\n";
		}
	}

	# 過去ログ
	print "<LI>過去ログ：";
	if ($pastkey == 0) { print "設定なし\n"; }
	else {
		print "設定あり\n";

		# NOファイル
		if (-e $nofile) { print "<LI>NOファイルパス：OK\n"; }
		else { print "<LI>NOファイルのパス：NG → $nofile\n"; }
		if (-r $nofile && -w $nofile) { print "<LI>NOファイルパーミッション：OK\n"; }
		else { print "<LI>NOファイルパーミッション：NG → $nofile\n"; }

		# ディレクトリ
		if (-d $pastdir) { print "<LI>過去ログディレクトリパス：OK\n"; }
		else { print "<LI>過去ログディレクトリパーミッション：NG → $pastdir\n"; }
		if (-r $pastdir && -w $pastdir && -x $pastdir) {
			print "<LI>過去ログディレクトリパーミッション：OK\n";
		} else {
			print "<LI>過去ログディレクトリパーミッション：NG → $pastdir\n";
		}
	}

	print "</UL>\n</body></html>\n";
	exit;
}
