#!/usr/bin/perl
##############
#北海道市長会#
##############
#日本語コード変換モジュール
require 'jcode.pl';
#---------------------------------------
#メッセージを格納するデータベースファイル
$datafile = 'ment/news.txt';
#---------------------------------------
#バックグランドの画像ファイル
$bg_gif = '';
#---------------------------------------
#区切り線　画像を使用しない場合は''にする
$line_gif = '';
#---------------------------------------
#ワンポイント画像
$point_gif = '';
#---------------------------------------
#管理者削除モードのパスワード
$password = 'may4565';
#---------------------------------------
#掲示板の名前
$title = '北海道市長会ニュース';
#---------------------------------------
#バックグランドカラー
$bg_color = '#FFF8EC';
#テキストの文字色
$text_color = '#000000';
#リンク文字色
$link_color = '#000000';
#Ｖリンク文字色
$vlink_color = '#000000';
#Ａリンク文字色
$alink_color = '#000000';

#題名の文字色
$subject_color = '#AF0000';
#---------------------------------------
#保存する更新履歴（極端に多くするとパフォーマンスが低下します）
$max = 120;
#---------------------------------------
#1ページに表示する件数
$pagevew = 5;
#----------------------------------------
$textwidth = 60;
$title_html = <<"TITLE_HTML";
<CENTER>
<TABLE border="0">
    <tr>
      <TD></TD>
    </tr>
</TABLE>
</CENTER>
<TABLE width="90%">
  <TBODY>
    <TR>
      <TD align="center"><IMG src="ro1.gif" width="400" height="66" border="0"></TD>
    </TR>
  </TBODY>
</TABLE>
TITLE_HTML

$agent = $ENV{'HTTP_USER_AGENT'};

#if ($agent =~ /MSIE\ 3/i) { $textwidth = $textwidth * 1.5; }
if ($ENV{'REQUEST_METHOD'} eq "POST") {
	read(STDIN, $formdata, $ENV{'CONTENT_LENGTH'});
} else { $formdata = $ENV{'QUERY_STRING'}; }
@pairs = split(/&/,$formdata);
foreach $pair (@pairs) {
	($name, $value) = split(/=/, $pair);
	$value =~ tr/+/ /;
	$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
	if ($tag eq 'no') {
		$value =~ s/</&lt;/g;
		$value =~ s/>/&gt;/g;
	}
	$value =~ s/\n//g;
	$value =~ s/\,/，/g;
	&jcode'convert(*value,'sjis');
	$FORM{$name} = $value;
}

if (!open(NOTE,"$datafile")) { &error(bad_file); }
@DATA = <NOTE>;
close(NOTE);

&html; 
#=======================================================================================
sub html_head {
	print "Content-type: text/html\n\n";
	print "<HTML>\n";
	print "<HEAD><TITLE>北海道市長会ニュース</TITLE>\n";
	print "</HEAD>\n";
	print "<body text=#EBE4C9 bgcolor=#FFF8EC>\n";
	print "$title_html\n";
}
#=======================================================================================
sub html {
	&html_head;
#	print "<p>\n";
	&listvew;
	print 	"<CENTER><P>\n";
#	print 	"<HR SIZE=4 ALIGN=LEFT><FONT SIZE=-1><FONT COLOR=#00AF00>■</FONT><A HREF=news.cgi TARGET=bottomR>News</A>　<FONT COLOR=#00AF00>■</FONT><FONT COLOR=#AF0000><a href=../02.html TARGET=bottomR>都市情報</FONT>　<FONT COLOR=#00AF00>■</FONT><A HREF=../03.html TARGET=bottomR>組織活動状況</A>　<FONT COLOR=#00AF00>■</FONT><A HREF=../cabinet/cabinet.html TARGET=bottomR>会員のページ</A>　<FONT COLOR=#00AF00>■</FONT><A HREF=../05.html TARGET=bottomR>市町村振興協会</A>　<FONT COLOR=#00AF00>■</FONT><A HREF=../kouji.html TARGET=bottomR>北海道都市学会</A>　<FONT COLOR=#00AF00>■</FONT><A HREF=../kouji.html TARGET=bottomR>リンク集</A></FONT>\n";	print "<p><b><font color=#AF0000>▼<a href=../top.html TARGET=bottomR>ホームへ</a></font></b></center>\n";
	print "</body></html>\n";
	exit;
}
#=======================================================================================
sub listvew {
	if ($FORM{'nextpage'} eq '') { $nextpage = 0; } else { $nextpage = $FORM{'nextpage'}; }
	$end_data = @DATA - 1;
	$page_end = $nextpage + ($pagevew - 1);
	if ($page_end >= $end_data) { $page_end = $end_data; }
	#if ($line_gif eq '') { print "<hr width=600>"; }
	#else { print "<img src=$line_gif width=600>"; }
	foreach ($nextpage .. $page_end) {
		($date,$code,$subject,$gif,$url,$msg) = split(/\,/,$DATA[$_]);
		$msg =~ s/([^=^\"]|^)((http|ftp|mailto):[!#-9A-~]+)/$1<a href=$2 target=_top>ここをクリック<\/a>/g;
		$msg =~ s/\r/<br>/g;
		print "<TABLE BORDER=0 CELLPADDING=0 frame=void CELLSPACING=5 width=90%>\n";
		print "<TR BGCOLOR=#DDD288 width=70%><TD>\n";
		print "<font color=$subject_color size=><b>$subject<b></font></td>";
		print "<TD BGCOLOR=#DDD288 width=30%>\n";
		print "<div align=right><font color=$subject_color size=-1><i>発信日$date</i></font></div>";
		print "</td></tr>\n";
		print "<tr font BGCOLOR=#EBE4C9><td COLSPAN=2>";
		print "<p><font color=#000000>$msg</font></p>\n";
		print "</TD></TR>\n";
		print "</TABLE>\n";
		print "<P>\n";
		print "<P>\n";
	}
	$next_line = $page_end + 1;
	if ($page_end ne $end_data) {
		print "<FORM   method=POST   action=news.cgi>\n";
		print "<input  type=hidden   name=nextpage value=" . $next_line . ">\n";
		print "<input  type=submit   value=バックナンバー>\n";
		print "</FORM>\n";
	}
}
#=======================================================================================
