#┌─────────────────────────────────
#│ e-PAD (pcom.pl) - 2004/03/04
#│ Copyright (c) KentWeb
#│ webmaster@kent-web.com
#│ http://www.kent-web.com/
#└─────────────────────────────────

sub html {
	local($flag,$no,$date,$name,$mail,$sub,$resub,$recom,$next,$back);

	# クッキー情報を取得
	local($cname,$cmail,$curl,$cpwd) = &get_cookie;
	if ($curl eq "") { $curl="http://"; }

	# レス処理
	$resub=""; $recom="";
	if ($in{'res'} > 0) {
		open(IN,"$logfile") || &error("Open Error: $logfile");
		while (<IN>) {
			($no,$date,$nam,$eml,$sub,$com) = split(/<>/);
			last if ($in{'res'} == $no);
		}
		close(IN);

		$sub   =~ s/^Re:[\[\]\d\s]+//g;
		$resub = "Re:[$no] $sub";
		$recom = "&gt; $com";
		$recom =~ s/<br>/\n&gt; /ig;

		# 絵文字復元
		$resub =~ s/&lt;/</g;
		$resub =~ s/&gt;/>/g;
		$resub = &i2i($resub);
		$resub = &j2j($resub);
		$recom = &i2i($recom);
		$recom = &j2j($recom);
	}

	&header;
	print "<center>\n";
	print "$banner1<P>\n" if ($banner1 ne "<!-- 上部 -->");
	print <<EOM;
<b style="font-size:$t_size;color:$t_color">$title</b>
<hr width="90%">
[<a href="$home" target="_top">トップに戻る</a>]
[<a href="$script?mode=howto">留意事項</a>]
[<a href="$script?mode=find">ワード検索</a>]
[<a href="$script?mode=admin">管理用</a>]
<hr width="90%">
</center>
<blockquote>
<form action="$script" method="$method">
<input type=hidden name=mode value="regist">
<table cellpadding=1 cellspacing=1>
<tr>
  <td><b>おなまえ</b></td>
  <td><input type=text name=name size=28 value="$cname"></td>
</tr>
<tr>
  <td><b>Ｅメール</b></td>
  <td><input type=text name=email size=28 value="$cmail"></td>
</tr>
<tr>
  <td><b>タイトル</b></td>
  <td>
    <input type=text name=sub size=36 value="$resub">
    <input type=submit value="送信する"><input type=reset value="リセット">
  </td>
</tr>
<tr>
  <td colspan=2>
    <b>メッセージ</b><br>
    <textarea name=comment cols=56 rows=7 wrap=soft>$recom</textarea>
  </td>
</tr>
<tr>
  <td><b>ＵＲＬ</b></td>
  <td><input type=text name=url size=50 value="$curl"></td>
</tr>
<tr>
  <td><b>削除キー</b></td>
  <td>
    <input type=password name=pwd size=8 maxlength=8 value="$cpwd">
    &nbsp; &nbsp; &nbsp; <input type=checkbox name=cook value="on" checked>
    クッキー情報を保存
  </td>
</tr>
</table>
<ul>
<li>パソ\コンと携帯端末で、レイアウトを自動振分する掲示板です。
<li>絵文字は、iモード、J-スカイ及びEZwebに対応しています。
</ul>
</form>
</blockquote>
<div align="center">
EOM

	$i=0;
	open(IN,"$logfile") || &error("Open Error: $logfile");
	while (<IN>) {
		$i++;
		if ($i < $page + 1) { next; }
		if ($i > $page + $p_log) { next; }

		($no,$dat,$nam,$eml,$sub,$com,$url,$hos,$pw,$tim,$typ) = split(/<>/);
		if ($autolink) { &auto_link($com); }

		# 絵文字
		$sub = &imode($sub);
		$nam = &imode($nam);
		$com = &imode($com);
		$sub = &jsky($sub);
		$nam = &jsky($nam);
		$com = &jsky($com);

		print "<P><table border=1 width=\"92%\" cellpadding=6 cellspacing=1 bgcolor=white>\n";
		print "<tr><td><b style=\"color:$sub_color\">$sub</b> ";
		print "投稿者：<b>$nam</b> 投稿日：$dat &nbsp;";
		print "<font color=\"green\">No.$no</font> &nbsp;";

		print "<a href=\"mailto:$eml\"><img src=\"$imgurl/mail.gif\" border=0 align=top alt='Mail'></a>\n" if ($eml);
		print "<a href=\"$url\" target=\"_blank\"><img src=\"$imgurl/home.gif\" border=0 align=top alt='Home'></a>\n" if ($url);

		print "&nbsp;&nbsp;[<a href=\"$script?res=$no\">返信</a>]";
		print "<br><br><table width=\"100%\" cellpadding=10>\n";
		print "<tr><td><img src=\"$imgurl/$typ.gif\" align=top></td>";
		print "<td width=\"95%\">$com</td></tr></table></td></tr></table>\n";
	}
	close(IN);
	print "</div><br>\n";

	$next = $page + $p_log;
	$back = $page - $p_log;
	print "<table align=left><tr>\n";
	$flag=0;
	if ($back >= 0) {
		$flag=1;
		print "<td><form action=\"$script\" method=\"$method\">\n";
		print "<input type=hidden name=page value=\"$back\">\n";
		print "<input type=submit value=\"前の$p_log件\"></td></form>\n";
	}
	if ($next < $i) {
		$flag=1;
		print "<td class=num><form action=\"$script\" method=\"$method\">\n";
		print "<input type=hidden name=page value=\"$next\">\n";
		print "<input type=submit value=\"次の$p_log件\"></td></form>\n";
	}
	# ページ移動ボタン表示
	if ($flag) {
		print "<td width=7></td><td class=num> ";
		$x=1; $y=0;
		while ($i > 0) {
			if ($page == $y) { print "<b>[$x]</b>\n"; }
			else { print "[<a href=\"$script?page=$y\">$x</a>]\n"; }
			$x++;
			$y += $p_log;
			$i -= $p_log;
		}
		print "</td>\n";
	}

	print <<"EOM";
</tr></table>
<table align=right><tr><td nowrap align=center>
<form action="$script" method="$method">
<input type=hidden name=mode value="usrdel">
記事No<input type=text name=no size=3>
削除キー<input type=password name=pwd size=4 maxlength=8>
<input type=submit value="記事削除"></td></form>
</tr></table><br clear=all>
<!-- 著作権表\示（削除不可）-->
<div align='center'>$banner2<P><!-- $ver -->
<span style='font-size:10px;font-family:Verdana,Helvetica,Arial'>
- <a href='http://www.kent-web.com/' target='_top'>e-PAD</a> -
</span></div>
</body>
</html>
EOM
	exit;
}

#-------------------------------------------------
#  エラー処理
#-------------------------------------------------
sub error {
	if ($lockflag) { &unlock; }

	&header;
	print "<div align=center><hr width=400><h3>ERROR !</h3>\n";
	print "<font color='#dd0000'>$_[0]</font>\n";
	print "<p><hr width=400></div>\n</body>\n</html>\n";
	exit;
}

#-------------------------------------------------
#  クッキー発行
#-------------------------------------------------
sub set_cookie {
	local(@cook) = @_;
	local($gmt, $cook, @t, @m, @w);

	@t = gmtime(time + 60*24*60*60);
	@m = ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
	@w = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat');

	# 国際標準時を定義
	$gmt = sprintf("%s, %02d-%s-%04d %02d:%02d:%02d GMT",
			$w[$t[6]], $t[3], $m[$t[4]], $t[5]+1900, $t[2], $t[1], $t[0]);

	# 保存データをURLエンコード
	foreach (@cook) {
		s/(\W)/sprintf("%%%02X", unpack("C", $1))/eg;
		$cook .= "$_<>";
	}

	# 格納
	print "Set-Cookie: e_pad=$cook; expires=$gmt\n";
}

#-------------------------------------------------
#  クッキー取得
#-------------------------------------------------
sub get_cookie {
	local($key, $val, *cook);

	# クッキーを取得
	$cook = $ENV{'HTTP_COOKIE'};

	# 該当IDを取り出す
	foreach ( split(/;/, $cook) ) {
		($key, $val) = split(/=/);
		$key =~ s/\s//g;
		$cook{$key} = $val;
	}

	# データをURLデコードして復元
	foreach ( split(/<>/, $cook{'e_pad'}) ) {
		s/%([0-9A-Fa-f][0-9A-Fa-f])/pack("C", hex($1))/eg;

		push(@cook,$_);
	}
	return (@cook);
}

#-------------------------------------------------
#  ワード検索
#-------------------------------------------------
sub find {
	local($wd,$flag,$i,$next,$back,$enwd,@wd);

	&header;
	print <<"EOM";
[<a href="$script?">掲示板に戻る</a>]
<ul>
<li>検索したいキーワードを入力し検索ボタンを押してください。
<li>キーワードはスペースで区切って複数指定することができます。
<form action="$script" method="$method">
<input type=hidden name=mode value="find">
キーワード：<input type=text name=word size=35 value="$in{'word'}">
条件：<select name=cond>
EOM

	foreach ("AND", "OR") {
		if ($in{'cond'} eq $_) {
			print "<option value=\"$_\" selected>$_\n";
		} else {
			print "<option value=\"$_\">$_\n";
		}
	}
	print "</select> 表\示：<select name=view>\n";

	foreach (10,15,20,25,30) {
		if ($in{'view'} == $_) {
			print "<option value=\"$_\" selected>$_件\n";
		} else {
			print "<option value=\"$_\">$_件\n";
		}
	}

	print <<EOM;
</select>
<input type=submit value=" 検索 "></form>
</ul>
EOM

	# 検索実行
	if ($in{'word'} ne "") {

		# 入力内容整理
		$in{'word'} =~ s/\x81\x40/ /g;
		@wd = split(/\s+/, $in{'word'});

		# 検索
		print "<DL>\n";
		$i=0;
		open(IN,"$logfile") || &error("Open Error: $logfile");
		while (<IN>) {
			$flag=0;
			foreach $wd (@wd) {
				if (index($_,$wd) >= 0) {
					$flag=1;
					if ($in{'cond'} eq 'OR') { last; }
				} else {
					if ($in{'cond'} eq 'AND') { $flag=0; last; }
				}
			}
			# 検索にヒット
			if ($flag) {
				$i++;
				if ($i < $page + 1) { next; }
				if ($i > $page + $in{'view'}) { next; }

				($no,$dat,$nam,$eml,$sub,$com,$url) = split(/<>/);
				if ($eml) { $nam = "<a href=\"mailto:$eml\">$nam</a>"; }

				# 絵文字
				$sub = &imode($sub);
				$com = &imode($com);
				$sub = &jsky($sub);
				$com = &jsky($com);

				print "<DT><hr>[<b>$no</b>] ";
				print "<font color=\"$sub_color\"><b>$sub</b></font> ";
				print "投稿者：<b>$nam</b> 投稿日：$dat<br><br><DD>$com";
				print "<P><a href=\"$url\" target=\"_blank\">$url</a>" if ($url);
				print "<br><br>\n";
			}
		}
		close(IN);
		print "<DT><hr>検索結果：<b>$i</b>件</DL>\n";

		$next = $page + $in{'view'};
		$back = $page - $in{'view'};

		$enwd = &url_enc($in{'word'});
		if ($back >= 0) {
			print "[<a href=\"$script?mode=find&page=$back&word=$enwd&view=$in{'view'}&cond=$in{'cond'}\">前の$in{'view'}件</a>]\n";
		}
		if ($next < $i) {
			print "[<a href=\"$script?mode=find&page=$next&word=$enwd&view=$in{'view'}&cond=$in{'cond'}\">次の$in{'view'}件</a>]\n";
		}

	}
	print "</body>\n</html>\n";
	exit;
}

#-------------------------------------------------
#  URLエンコード
#-------------------------------------------------
sub url_enc {
	local($_) = @_;

	s/(\W)/'%' . unpack('H2', $1)/eg;
	s/\s/+/g;
	$_;
}

#-------------------------------------------------
#  使い方表示
#-------------------------------------------------
sub howto {
	&header;
	print <<EOM;
<br>
<div align="center">
<table width="90%" border=1 cellspacing=1 cellpadding=8 bgcolor="white"><tr><td>
<h3 style="font-size:15px;">留意事項</h3>
<ol>
<li>この掲示板はパソ\コンの他に、iモード、J-スカイ及びEZwebに対応しており、それぞれ<b>絵文字が利用可能\</b>です。
<li>絵文字は、各携帯端末同士で似たものがある場合には相互に自動変換し、それ以外の場合には画像に置き換えて表\示します。
<li>この掲示板は<b>クッキー対応</b>ですので、1度記事を投稿いただくと、お名前、Ｅメール、ＵＲＬ、削除キー情報は2回目以降は自動入力されます。（ブラウザがクッキー対応の場合）
<li>投稿記事には、<b>タグは一切使用できません。</b>
<li>記事を投稿する上での必須入力項目は<b>「おなまえ」</b>と<b>「メッセージ」</b>です。Ｅメール、ＵＲＬ、題名、削除キーは任意です。
<li>記事には、<b>半角カナは一切使用しないで下さい。</b>文字化けの原因となります。
<li>記事の投稿時に<b>「削除キー」</b>にパスワード（英数字で8文字以内）を入れておくと、その記事は次回<b>削除キー</b>によって削除することができます。
<li>記事の保持件数は<b>最大$max件</b>です。それを超えると古い順に自動削除されます。
<li>過去の投稿記事から<b>「キーワード」によって検索することができます。</b>トップメニューの<a href="$script?mode=find">「ワード検索」</a>のリンクをクリックすると検索モードとなります。
<li>管理者が著しく不利益と判断する記事や、他人を誹謗中傷する記事は予\告なく削除することがあります。
</ol>
</td></tr></table>
<P>
<form>
<input type=button value="記事リストにもどる" onClick="history.back()">
</form>
</div>
</body>
</html>
EOM
	exit;
}


1;


__END__

