#!/usr/bin/perl

#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#+++　　[ 目指せ世界制覇!! Ver0.52 ]　…　2001.03.17　Update
#+++
#+++		･････>>> All Created by Tacky				     
#+++
#+++		･････>>> Copyright (c) 2000.12 Tacky's Room. All rights reserved....
#+++
#+++        Email    >>> tacky2@ops.dti.ne.jp
#+++        Homepage >>> http://www.eva.hi-ho.ne.jp/takeuchi/
#+++
#+++ 設置方法構成(具体例)
#+++ public_html（ホームページディレクトリ）
#+++ |
#+++ |-- cgi-bin（任意のディレクトリ）
#+++   |-- jcode.pl      (755)…(日本語ライブラリ)
#+++   |-- mezase2.cgi   (755)…(スクリプト本体)
#+++   |-- mezase2.txt   (666)…(ログファイル)…空のままアップロード
#+++
#+++ 　　■( )内はパーミッッションの値です。
#+++ 　　■gif以外はアスキーモード、gifはバイナリーモードでアップロードして下さい。
#+++ 　　■mezase2.lockは自動作成＆削除しますので、各自でご用意する必要はありません。
#+++ 　　■ログファイル・ロックファイルの指定はフルパス(http://〜)で指定するとサーバーエラーになりますのでご注意下さい。
#+++
#+++ >>> Update-History...
#+++
#+++	2001.03.17(Ver0.52 )  >>　すいません〜アジアが２個ありましたぁ。以前も修正したつもりだったんだけど・・・(^^ゞ
#+++                            　トクトク対応。
#+++	2001.01.22(Ver0.51 )  >>　検索文字列を指定せずに検索ボタンを押下した場合、「北海道」のデータが表示されるバグを修正
#+++	2000.12.30(Ver0.5  )  >>　リリース
#+++
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

require './jcode.pl';											#日本語コード変換

$url	 		=  "http://www.xxxxx.ne.jp/xxxxxxxx/";			#<<<戻り先ＵＲＬ
$script			=  "./mezase2.cgi";								#<<<このＣＧＩの名前を指定
$method			= 'POST';										#<<<METHODの指定(POST又はGET)
$logfile		= './mezase2.txt';								#<<<ログファイルの名前を指定　http://〜で指定してはダメですよ
$logfile2		= './mezase22.txt';								#<<<追加　ログファイル(一時保存)の名前を指定
$lockfile		= './mezase2.lock';								#<<<ロックファイルの名前を指定　http://〜で指定してはダメですよ
$title			= '* 天気のことわざ辞典 *';							#<<<タイトルを指定
$titlelogo		= '';								#<<<タイトル画像を指定
$titlelogo_w	= 0 ;											#<<<タイトル画像の幅。わからない場合は0
$titlelogo_h	= 0 ;											#<<<タイトル画像の高さ。わからない場合は0
$bgcolor		= '#99CC33';									#<<<背景色を指定
$backpicture	= '';											#<<<背景画像を指定（使用しない場合は、''で良い)

$tbgcolor		= '#99cc00';									#<<<入力フォームの背景色を指定
$tbgtxcolor		= '#000000';									#<<<入力フォームの文字色を指定

$textcolor	    = "#000000";									# 文字色
$linkcolor	    = "#cc6600";									# リンク色（未読リンク）
$vlinkcolor		= "#666666";									# リンク色（既読リンク）
$alinkcolor	 	= "#ff3300";									# リンク色（押した時）
$hovercolor		= '#ff0000';									#ﾘﾝｸをﾎﾟｲﾝﾄした際のｱﾝﾀﾞｰﾗｲﾝ色(IEのみ)
$pt				= '10pt';										#全体のフォントサイズ（pt指定以外何があるのか、僕知らない。(^^ゞ）	#i000331

$hpicon1		= "../../common/hp1.gif";									#<<<ホームページアイコン（男性用）
$hpicon2		= "../../common/hp2.gif";									#<<<ホームページアイコン（女性用）
$headbgcolor	= "#990000";									#<<<メッセージ表示部分の見出しセル背景色
$headtxcolor	= "#ffffff";									#<<<メッセージ表示部分の見出しセル文字色
$cellbgcolor1	= "#CCFF00";									#<<<メッセージ表示部分のセル背景色１
$celltxcolor1	= "#336600";									#<<<メッセージ表示部分のセル文字色１
$cellbgcolor2	= "#ffff66";									#<<<メッセージ表示部分のセル背景色２（１と２で繰り返し表示される）
$celltxcolor2	= "#996600";									#<<<メッセージ表示部分のセル文字色２（１と２で繰り返し表示される）

$datamax		= 300 ;											#<<<最大データ保存件数
$pagemax		= 30;											#<<<１ページ内に表示する件数

$master_password = 'isama';								#<<<メンテナンス用パスワード（管理者用）

$col 		= 46 ;												#メッセージ欄の桁数
$row 		= 4 ;												#メッセージ欄の行数
$tsz 		= '90%' ;											#ログ表示部のテーブル横幅

#投稿時のパスワードをcrypt関数を使用する（暗号化）
#crypt関数が利用出来ない場合もありますので、投稿時にエラーになる場合は、「0:使用しない」にして下さいね。
$ango			= 1 ;	#0:使用しない 1:使用する　（推奨：１：使用する）

#=============================================================================================================================================================================================
#フォームＣＳＳ設定　※使用しない場合は、$css_style = "";とし、そこから２行(先頭がEOMの行までを)を削除して下さい。
$css_style = <<"EOM";
STYLE=font-size:$pt;color:#333333;background-color:#CCFF00;border-style:solid;border-color:#999900;border-width:1;
EOM

$sekaiwamadamada	= 0 ;	#世界制覇は無理そうだから日本だけの場合は1。世界制覇は0

$colorflg	= 1 ;	#地域毎に色分けするのではなく、地域に登録した人数によって色分けする場合は1。以外は0

$sz_w				= 20 ;	#地図上の１都道府県の幅
$sz_h				= 10 ;	#地図上の１都道府県の高さ

#<<<地域テーブル　※$colorflg=0の場合、下記で指定したカラーコードで地域が表示されます。$colorflg=1の場合は修正不要です
$AREATBL[0] = '北海道';   $COLORTBL[0] = "#993300";
$AREATBL[1] = '青森';   $COLORTBL[1] = "#336600";
$AREATBL[2] = '秋田';   $COLORTBL[2] = "#CCFF00";
$AREATBL[3] = '岩手';   $COLORTBL[3] = "#66CC00";
$AREATBL[4] = '山形';   $COLORTBL[4] = "#33CC00";
$AREATBL[5] = '宮城';   $COLORTBL[5] = "#336600";
$AREATBL[6] = '新潟';   $COLORTBL[6] = "#996600";
$AREATBL[7] = '福島';   $COLORTBL[7] = "#660033";
$AREATBL[8] = '石川';   $COLORTBL[8] = "#006600";
$AREATBL[9] = '富山';   $COLORTBL[9] = "#999999";
$AREATBL[10] = '群馬';   $COLORTBL[10] = "#333300";
$AREATBL[11] = '栃木';   $COLORTBL[11] = "#990000";
$AREATBL[12] = '茨城';   $COLORTBL[12] = "#330033";
$AREATBL[13] = '福井';   $COLORTBL[13] = "#990033";
$AREATBL[14] = '長野';   $COLORTBL[14] = "#CC6600";
$AREATBL[15] = '埼玉';   $COLORTBL[15] = "#660066";
$AREATBL[16] = '東京';   $COLORTBL[16] = "#006666";
$AREATBL[17] = '千葉';   $COLORTBL[17] = "#000033";
$AREATBL[18] = '島根';   $COLORTBL[18] = "#003333";
$AREATBL[19] = '鳥取';   $COLORTBL[19] = "#669900";
$AREATBL[20] = '兵庫';   $COLORTBL[20] = "#330066";
$AREATBL[21] = '大阪';   $COLORTBL[21] = "#999900";
$AREATBL[22] = '京都';   $COLORTBL[22] = "#990000";
$AREATBL[23] = '滋賀';   $COLORTBL[23] = "#009999";
$AREATBL[24] = '岐阜';   $COLORTBL[24] = "#999933";
$AREATBL[25] = '山梨';   $COLORTBL[25] = "#CC6699";
$AREATBL[26] = '神奈川';   $COLORTBL[26] = "#006699";
$AREATBL[27] = '佐賀';   $COLORTBL[27] = "#663300";
$AREATBL[28] = '福岡';   $COLORTBL[28] = "#336600";
$AREATBL[29] = '山口';   $COLORTBL[29] = "#CC3300";
$AREATBL[30] = '広島';   $COLORTBL[30] = "#993366";
$AREATBL[31] = '岡山';   $COLORTBL[31] = "#333333";
$AREATBL[32] = '和歌山';   $COLORTBL[32] = "#FFCC66";
$AREATBL[33] = '奈良';   $COLORTBL[33] = "#330000";
$AREATBL[34] = '三重';   $COLORTBL[34] = "#CC6633";
$AREATBL[35] = '愛知';   $COLORTBL[35] = "#FF9900";
$AREATBL[36] = '静岡';   $COLORTBL[36] = "#666633";
$AREATBL[37] = '長崎';   $COLORTBL[37] = "#660033";
$AREATBL[38] = '熊本';   $COLORTBL[38] = "#996600";
$AREATBL[39] = '大分';   $COLORTBL[39] = "#003366";
$AREATBL[40] = '鹿児島';   $COLORTBL[40] = "#666666";
$AREATBL[41] = '宮崎';   $COLORTBL[41] = "#CCCC00";
$AREATBL[42] = '愛媛';   $COLORTBL[42] = "#CC9966";
$AREATBL[43] = '香川';   $COLORTBL[43] = "#CC0000";
$AREATBL[44] = '高知';   $COLORTBL[44] = "#FFFF33";
$AREATBL[45] = '徳島';   $COLORTBL[45] = "#FF6666";
$AREATBL[46] = '沖縄';   $COLORTBL[46] = "#006666";
$AREATBL[47] = 'ヨーロッパ(Europe)';   $COLORTBL[47] = "#ffffcc";
$AREATBL[48] = 'アフリカ(Africa)';   $COLORTBL[48] = "#ffffcc";
$AREATBL[49] = 'アジア(Asia)';   $COLORTBL[49] = "#ffffcc";
$AREATBL[50] = '北アメリカ(North America)';   $COLORTBL[50] = "#ffffcc";
$AREATBL[51] = '南アメリカ(South America)';   $COLORTBL[51] = "#ffffcc";
$AREATBL[52] = 'オーストラリア(Australlia)';   $COLORTBL[52] = "#ffffcc";
$AREATBL[53] = 'その他';   $COLORTBL[53] = "#ffffcc";

#$colorflg=1の場合、COLOR_NUMで指定した人数以上いる地域は、地図上$COLORで指定した色の背景色で表示されます。$colorflg=0の場合は修正不要です
$COLOR_NUM[0] =   0 ;	$COLOR[0] = '#ffffff';
$COLOR_NUM[1] =   1 ;	$COLOR[1] = '#9999CC';
$COLOR_NUM[2] =   3 ;	$COLOR[2] = '#FF9900';
$COLOR_NUM[3] =   5 ;	$COLOR[3] = '#FFFF66';
$COLOR_NUM[4] =   7 ;	$COLOR[4] = '#FF6600';
$COLOR_NUM[5] =  10 ;	$COLOR[5] = '#66CCCC';
$COLOR_NUM[6] =  20 ;	$COLOR[6] = '#006600';
$COLOR_NUM[7] =  30 ;	$COLOR[7] = '#990000';

@SEXTBL = ('','♂','♀','？');	#性別テーブル　修正不要。※修正する場合は一番最初は''のままにしておいてね。

#投稿時に管理者にメール送信する場合、sendmailのパスを指定
$sendmail = "";

#メール送信先アドレス。（管理者のアドレス）…「＠」の前には必ず「￥」を付けてね。
$smail_address = "xxxxx\@xxxx.co.jp";

$hiho			= 0 ;	#プロバイダーが「hi-ho」の人のみ「1」にして下さい。　※Sendmail使う場合

$damedame		= 0 ;	#Locationヘッダが使えないサーバーは1。通常は0でいいはず。※トクトク、3nopage,WinNTサーバー等が1かな。

#<<<↓の画像はそのまま使用してね。パスだけ修正。
$gif_spacer			= '../../common/spacer.gif';				#ダミー透過画像

#<<<　ここから下はいじらない方がいいですよ。
utime time(), time(), __FILE__; 								# スクリプト生成日時の更新

###############################################################################
#### Main Process  START  #####################################################
###############################################################################
#<<<システム日時・時刻取得
$ENV{'TZ'} = "JST-9";
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = sprintf("%02d",$year + 1900);	$month = sprintf("%02d",$mon + 1);	$mday = sprintf("%02d",$mday);
$hour = sprintf("%02d",$hour);	$min = sprintf("%02d",$min);
$today = "$year/$month/$mday-$hour:$min";
if ($ENV{'HTTP_USER_AGENT'} !~ /MSIE/i) {	$css_style = "" ;	}
&decode ;
if ( $FORM{'action'} eq "maintenance" ) 	{  &Maintenance; }    	#<<<"処理"がメンテナンスの場合
elsif	( $FORM{'action'} eq "update" )		{ &update ; }			#<<<ログファイル更新（編集時）
elsif	( $FORM{'action'} eq "disp" )		{ &seiha ; }			#<<<登録状況を見る
elsif   ( $FORM{'action'} eq 'regist' )		{	&regist ;	}		#<<<ログ出力処理
elsif   ( $FORM{'action'} eq 'input' )		{	&forminput ;	}	#<<<入力フォーム表示
elsif   ( $FORM{'action'} eq 'view' )		{	&view ;	}			#<<<ログ表示
else	{	&menu ; }												#<<<初期画面表示
&footer ;

exit;
###############################################################################
#### Main Process  END  #######################################################
###############################################################################

###<--------------------------------------------------------------
###<---   デコード＆変数代入
###<--------------------------------------------------------------
sub decode{	
	if ($ENV{'REQUEST_METHOD'} eq "POST") {
		read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
	} else { $buffer = $ENV{'QUERY_STRING'}; }
	@pairs = split(/&/,$buffer);
	foreach $pair (@pairs) {
		($name, $value) = split(/=/, $pair);
		$value =~ tr/+/ /;
		$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
		$value =~ s/</&lt;/g;
		$value =~ s/>/&gt;/g;
		$value =~ s/\,/，/g;
		&jcode'convert(*value,'sjis');
		$FORM{$name} = $value;
	}
	$FORM{'comment'} =~ s/\r\n/<br>/g;	$FORM{'comment'} =~ s/\r|\n/<br>/g;	
	$FORM{'hp'}   =~ s/^http\:\/\///;

}
###<--------------------------------------------------------------
###<---   初期メニュー
###<--------------------------------------------------------------
sub menu { 
	&dataread ;
	&header ;
	$total = 0 ;
	for ( @LOG )	{ 
		($address,$no,$name,$email,$sex,$hp,$yobi,$comment,$regdate,$p) = split(/,/,$_);
		$area = sprintf("%02d",$address) ;
		$touroku{$address}++ ;	$total++ ;
	}
print "<p align=left>\n";		
print "<a href=../../frontindex.html target=_self>\n";
print "<img src=../../common/menu.gif border=1pt style=text-decoration:none>\n";
print "</a>\n";
print "</p>\n";
	print "<center>\n";
	if ( $titlelogo )	{
		$dmy = "";
		if ( $titlelogo_w != 0 ) { $dmy  = " width=$titlelogo_w "; }
		if ( $titlelogo_h != 0 ) { $dmy .= " height=$titlelogo_h "; }
		print "<img src=\"$titlelogo\" $dmy><br><br>\n";
	}	else	{

	}print "<img src=../../weather/images/weather_yours.gif border=0 > <br><br>\n";
	print "<hr size=1 noshade color=#ffffff width=80%><br>\n";
	if ( $FORM{'action'} ne 'maintenance' )	{
		print "<form action=\"$script\" method=\"$method\">\n";
		print "<td nowrap>&nbsp;&nbsp;&nbsp;&nbsp;Word:<input type=hidden name=\"action\" value=\"view\">\n";
		print "<input type=hidden name=\"area\" value=\"$FORM{'area'}\">\n";
	    print "<INPUT size=20 type=text name=findname  $css_style>&nbsp;&nbsp;\n";
		print "<INPUT type=submit value=\"検索する\" $css_style></td></form>";
	}
	print "</tr></table>";
	print "<table><tr>\n";
	print "<form><td>\n";
	print "<INPUT TYPE=button VALUE=\"Home\" ";
	print "onClick=\"parent.location.href = \'$url\'\" $css_style></td></form>\n";
	print "<form><td>\n";
	print "<INPUT TYPE=button VALUE=\"ことわざの全登録状況\" ";
	print "onClick=\"parent.location.href = \'$script?action=disp\'\" $css_style></td></form>\n";
	print "</tr></table><br>\n";
print <<"EOM";
<hr size=1 noshade color=#ffffff width=80%><br>
<table border="0" cellspacing="1" cellpadding="0" align="center">
  <tr valign="middle" align="center"> 
EOM
&area_link(47) ;	#ヨーロッパ
print <<"EOM";
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
EOM
&area_link(49) ;	#アジア
print <<"EOM";
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
EOM
&area_link(0) ;
print <<"EOM";
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
EOM
&area_link(50) ;	#北アメリカ
print <<"EOM";
  </tr>
  <tr valign="middle" align="center"> 
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
  </tr>
  <tr valign="middle" align="center"> 
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
EOM
&area_link(1) ;
print <<"EOM";
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
  </tr>
  <tr valign="middle" align="center"> 
EOM
&area_link(48) ;	#アフリカ
print <<"EOM";
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
EOM
&area_link(2) ;
&area_link(3) ;
print <<"EOM";
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
EOM
&area_link(51) ;	#南アメリカ
print <<"EOM";
  </tr>
  <tr valign="middle" align="center"> 
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
EOM
&area_link(4) ;
&area_link(5) ;
print <<"EOM";
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
  </tr>
  <tr valign="middle" align="center"> 
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
EOM
&area_link(6) ;
&area_link(7) ;
print <<"EOM";
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
  </tr>
  <tr valign="middle" align="center"> 
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
EOM
&area_link(8) ;
&area_link(9) ;
&area_link(10) ;
&area_link(11) ;
&area_link(12) ;
print <<"EOM";
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
  </tr>
  <tr valign="middle" align="center"> 
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
EOM
&area_link(13) ;
&area_link(14) ;
&area_link(15) ;
&area_link(16) ;
&area_link(17) ;
print <<"EOM";
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
  </tr>
  <tr valign="middle" align="center"> 
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
EOM
&area_link(18) ;
&area_link(19) ;
&area_link(20) ;
&area_link(21) ;
&area_link(22) ;
&area_link(23) ;
&area_link(24) ;
&area_link(25) ;
&area_link(26) ;
print <<"EOM";
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    </tr>
  <tr valign="middle" align="center"> 
    <td width=$sz_w height=$sz_h>　</td>
EOM
&area_link(27) ;
&area_link(28) ;
print <<"EOM";
    <td width=$sz_w height=$sz_h>　</td>
EOM
&area_link(29) ;
&area_link(30) ;
&area_link(31) ;
print <<"EOM";
    <td width=$sz_w height=$sz_h>　</td>
EOM
&area_link(32) ;
&area_link(33) ;
&area_link(34) ;
&area_link(35) ;
&area_link(36) ;
print <<"EOM";
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
  </tr>
  <tr valign="middle" align="center"> 
EOM
&area_link(37) ;
&area_link(38) ;
&area_link(39) ;
print <<"EOM";
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
  </tr>
  <tr valign="middle" align="center"> 
    <td width=$sz_w height=$sz_h>　</td>
EOM
&area_link(40) ;
&area_link(41) ;
print <<"EOM";
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
EOM
&area_link(42) ;
&area_link(43) ;
print <<"EOM";
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
  </tr>
  <tr valign="middle" align="center"> 
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
EOM
&area_link(44) ;
&area_link(45) ;
print <<"EOM";
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
EOM
&area_link(52) ;	#オーストラリア
print <<"EOM";
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
     <td width=$sz_w height=$sz_h> </td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
EOM
&area_link(53) ;	#その他
print <<"EOM";
  </tr>
  <tr valign="middle" align="center"> 
    <td width=$sz_w height=$sz_h>　</td>
EOM
&area_link(46) ;
print <<"EOM";
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>

EOM
print <<"EOM";
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
    <td width=$sz_w height=$sz_h>　</td>
  </tr>
</table><br>
<hr size=1 noshade color=#ffffff width=80%>
EOM
&area_link(99) ;
print "</center><br><br><br><br><br><br><br>";
}
###<--------------------------------------------------------------
###<---   入力フォーム
###<--------------------------------------------------------------
sub forminput { 
	&dataread ;
	&header ;
	print "[<a href=\"JavaScript:history.back()\">BACK</a>]\n";
	print "<center>\n";
	print "<form action=\"$script\" method=\"$method\">\n";
	if ( $FORM{'action'} ne 'maintenance' )	{
		print "<input type=hidden name=\"action\" value=\"regist\">\n";
	}	else	{
		print "<input type=hidden name=\"action\" value=\"update\">\n";
		print "<input type=hidden name=\"no\" value=\"$FORM{'no'}\">\n";
		print "<input type=hidden name=\"proc\" value=\"edit\">\n";
	}
	if ( $titlelogo )	{
		print "<img src=\"$titlelogo\">\n";
	}	else	{
		print "$title\n";
	}
	print "<br><br><TABLE border=0 cellpadding=1 cellspacing=0 bgcolor=#000000><tr><td>\n";
	print "<TABLE border=0 cellpadding=5 cellspacing=0>\n";
    print "<TR>\n";
	print "<TD bgcolor=\"$tbgcolor\"><font color=$tbgtxcolor>Name</font></TD>\n";
    print "<TD bgcolor=\"$tbgcolor\"><INPUT size=25 type=text name=name value=\"$c_name\" $css_style></TD>\n";
    print "<TD bgcolor=\"$tbgcolor\"><font color=$tbgtxcolor>Sex</font></TD>\n";
    print "<TD bgcolor=\"$tbgcolor\">\n";

	print "<select name=\"sex\" $css_style>\n";
	for ( $i = 1 ; $i <= $#SEXTBL ; $i++ ) {
		if ( ($c_sex && $i == $c_sex) || ( $c_sex eq '' && $i == 3 ) )	{	$dmy = "selected";	}	else	{	$dmy = "" ;	} 
		print "<option value=$i $dmy>$SEXTBL[$i]\n";
	}
	print "</select>\n";
    print "</TD>\n";
    print "</TR>\n";
    print "<TR>\n";
    print "<TD bgcolor=\"$tbgcolor\"><font color=$tbgtxcolor>Email</font></TD>\n";
    print "<TD bgcolor=\"$tbgcolor\"><INPUT size=25 type=text name=email value=\"$c_email\" $css_style></TD>\n";
    print "<TD bgcolor=\"$tbgcolor\"><font color=$tbgtxcolor>Area</font></TD>\n";
	print "<TD bgcolor=\"$tbgcolor\">\n";
	&areaset ;
    print "</TD>\n";
	print "</TR>\n";
    print "<TR><TD bgcolor=\"$tbgcolor\"><font color=$tbgtxcolor>URL</font></TD>\n";
    print "<TD bgcolor=\"$tbgcolor\"><INPUT size=25 type=text name=hp value=\"http://$c_hp\" $css_style></TD>\n";
    print "<TD bgcolor=\"$tbgcolor\"><font color=$tbgtxcolor>Pass</font></TD>\n";
    print "<TD bgcolor=\"$tbgcolor\"><INPUT size=8 type=password name=pass value=\"$c_pass\" $css_style></TD></TR>\n";
    print "<TR><TD bgcolor=\"$tbgcolor\" colspan=4 align=center>\n";
	print "<font color=$tbgtxcolor>*適切と思われないコメントは、管理者により<br>編集・削除されることがあります。</font><br><TEXTAREA rows=$row cols=$col name=comment $css_style>$c_comment</TEXTAREA>\n";
    print "</TD></TR>\n";
    print "<TR>\n";
    print "<TD bgcolor=\"$tbgcolor\">&nbsp;</TD>\n";
    print "<TD bgcolor=\"$tbgcolor\" colspan=3>\n";
	print "<INPUT type=submit value=\"--Submit--\" $css_style>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<INPUT type=reset value=\"--Clear--\" $css_style>\n";
	print "</TD></TR>";
	print "</TABLE>\n";
	print "</TD></TR></TABLE>\n";
	print "</form>\n";
	print "</CENTER><br><br><br><br><br>\n";
}
###<--------------------------------------------------------------
###<---   地域情報設定
###<--------------------------------------------------------------
sub areaset	{	
	print " <SELECT name=area  $css_style>\n";
	for ( $i = 0 ; $i <= $#AREATBL ; $i++ )	{
		$j = sprintf("%02d",$i);
		if ( $c_address == $j || (!($c_address) && $j ==0 ) ) { $dmy = "selected"; } else { $dmy = ""; }
		print "  <OPTION value=$j $dmy>$AREATBL[$i]\n";
	}	
	print "</SELECT>\n";
}
###<--------------------------------------------------------------
###<---   HTMLヘッダー書き出し
###<--------------------------------------------------------------
sub header { 
	print "Content-type: text/html; charset=Shift_JIS\n\n";
	print "<html>\n<head>\n";
	print "<META HTTP-EQUIV=\"Content-type\" CONTENT=\"text/html; charset=x-sjis\">\n";
	print "<title>$title</title>\n";
	#<<<CSS START>>>
	print "<style type=\"text/css\">\n";
	print "<!--\n";
	print "a:link    {font-size: $pt; text-decoration:none; color:$linkcolor }\n";			
	print "a:visited {font-size: $pt; text-decoration:none; color:$vlinkcolor }\n";	
	print "a:active  {font-size: $pt; text-decoration:none; color:$alinkcolor }\n";	
	print "a:hover   {font-size: $pt; text-decoration:underline; color:$hovercolor; }\n";	
	print "body,tr,td { font-size: $pt;}\n";
	print "-->\n";
	print "</style>\n";
	#<<<CSS END>>>
	print "</head>\n";
	if ($backpicture) { $set = "background=\"$backpicture\""; if ( $bgcolor ) { $set .= " bgcolor=\"$bgcolor\"" ; }	}
	elsif ($bgcolor )	{ $set = "bgcolor=\"$bgcolor\""; }
	print "<body $set text=$textcolor link=$linkcolor vlink=$vlinkcolor alink=$alinkcolor>\n";
}
###<--------------------------------------------------------------
###<---   HTMLフッダー書き出し
###<--------------------------------------------------------------
sub footer { 
	#<<<　↓消さないでネ♪
	print "<p align=right><font size=2><a href=http://tackysroom.com/ target=_top>Base CGI from mezase-sekaiseiha Ver0.52 by Tacky</a></font></p>\n";
	print "</body></html>\n";
}
###<--------------------------------------------------------------
###<---   ログファイル読み込み
###<--------------------------------------------------------------
sub	dataread	{
	if ( !(open(IN,"$logfile")))	{	&error("ログファイル($logfile)のオープンに失敗しました");	}
	@LOG = <IN>;
	close(IN);
}
###<--------------------------------------------------------------
###<---   ログ表示
###<--------------------------------------------------------------
sub	view	{
	&header ;
	&dataread ;
	$total = 0 ;
	for ( @LOG )	{ 
		($address,$no,$name,$email,$sex,$hp,$yobi,$comment,$regdate,$p) = split(/,/,$_);
		$area = sprintf("%02d",$address) ;
		$touroku{$address}++ ;	$total++ ;
	}
	print "[<a href=\"$script\">BACK</a>]&nbsp;&nbsp;\n";
	print "<center>\n";
	if ( $titlelogo )	{
		print "<img src=\"$titlelogo\"><br><br>\n";
	}	else	{
		print "$title<br><br>\n";
	}

	@new = ();
	foreach $buf ( @LOG )	{
		($address,$no,$name,$email,$sex,$hp,$yobi,$comment,$regdate,$p) = split(/,/,$buf);
		if 	(($FORM{'findname'} eq '' && (($FORM{'area'} ne '' && $FORM{'area'} == $address) || $FORM{'area'} == 99) )  || 	#u010122
		    ($FORM{'findname'} && (index($name,$FORM{'findname'}) >= 0 || index($comment,$FORM{'findname'}) >= 0) )) {
			push(@new,$buf);
		}
	}

	print "<table border=0 cellpadding=0 bgcolor=#666666><tr><td>\n";
	print "<table border=0 cellpadding=1 bgcolor=\"$bgcolor\"><tr><td>\n";
	if ( $FORM{'findname'} eq '' && $FORM{'area'} ne '' )	{	 	#u010122
		$i = sprintf("%02d",$FORM{'area'}) ;
		if ( $i != 99 ) {
			print "$AREATBL[$FORM{'area'}]…$touroku{$i}人";
		}	else	{
			print "最新登録者から表\示しています…全$total人";
		}
	}	else	{
		print "検索ワード：『<b>$FORM{'findname'}</b>』<br>" . @new . "人見つかりました";
	}
	print "</td></tr></table>\n";
	print "</td></tr></table>\n";
	print "<br>";
	print "<table width=$tsz border=0 cellspacing=1 cellpadding=3>\n";
	print "<tr>";
	print "<td bgcolor=\"$headbgcolor\" align=right nowrap><font color=\"$headtxcolor\">No</font></td>\n";
	if ( $FORM{'area'} == 99 )	{
		print "<td bgcolor=\"$headbgcolor\" align=center width=50><font color=\"$headtxcolor\">地域</font></td>\n";
	}
#改造：2002/11/17	
	print "<td bgcolor=\"$headbgcolor\" align=center width=80><font color=\"$headtxcolor\">お名前</font></td>\n";
	print "<td bgcolor=\"$headbgcolor\" align=center width=30><font color=\"$headtxcolor\">性別</font></td>\n";
	print "<td bgcolor=\"$headbgcolor\" align=center width=30><font color=\"$headtxcolor\">HP</font></td>\n";
	print "<td bgcolor=\"$headbgcolor\" align=center><font color=\"$headtxcolor\" width=350>ことわざ</font></td>\n";
	
#改造：2002/11/16	
	print "<td bgcolor=\"$headbgcolor\" align=center width=100><font color=\"$headtxcolor\">雲つか から</font></td>\n";
	
	
	print "<td bgcolor=\"$headbgcolor\" align=center><font color=\"$headtxcolor\">登録日</font></td></tr>\n";

	#表示対象ページの先頭データ件数を算出
	$dm = @new;
	if ( $dm % $pagemax == 0) {	$p = $dm / $pagemax ;	}
	else	{	$p = $dm / $pagemax + 1;	}			
	$p = sprintf("%3d",$p);
	if ( $FORM{'disppage'} ) {	$d = $FORM{'disppage'} * $pagemax - $pagemax ; 	}
	else	{	$d = 0	;	$FORM{'disppage'} = 1 ;	}

	$z = 1;
	for ( $i = $d ; ( $z <= $pagemax ) && ( $i < $dm ); $i++ )	{ 
		($address,$no,$name,$email,$sex,$hp,$yobi,$comment,$regdate,$p) = split(/,/,$new[$i]);
		if ( $bg eq $cellbgcolor1 ) {
			$bg = $cellbgcolor2;
			$tx = $celltxcolor2;
		}	else	{
			$bg = $cellbgcolor1;
			$tx = $celltxcolor1;
		}
		print "<tr>\n";
		print "<td bgcolor=\"$bg\" align=right nowrap><font  color=\"$tx\">$no</font></td>\n";
		if ( $FORM{'area'} == 99 )	{
			print "<td bgcolor=\"$bg\" align=center nowrap width=50><font  color=\"$tx\">$AREATBL[$address]</font></td>\n";
		}
		if ( $email ne '' )	{
			print "<td bgcolor=$bg align=center nowrap width=80><font  color=\"$tx\">\n";
			print "<a href=mailto:$email>$name</a></font></td>\n";
		}	else	{
			print "<td bgcolor=\"$bg\" align=center nowrap width=80><font  color=\"$tx\">$name</font></td>\n";
		}
		print "<td bgcolor=\"$bg\" align=center width=30><font  color=\"$tx\">$SEXTBL[$sex]</font></td>\n";
		if ( $hp ne '' )	{
			print "<td bgcolor=$bg align=center width=30><a href=\"http://$hp\" target=_blank>";
			print "<img src=\"$hpicon1\" border=0>" if ( $sex != 2 ) ;
			print "<img src=\"$hpicon2\" border=0>" if ( $sex == 2 ) ;
			print "</a></td>\n";
		}	else	{
			print "<td bgcolor=$bg width=30>　</td>\n";
		}

#改造：2002/11/16	
		@temp_kumo = split(/\.\.\.kumo\.\.\./, $comment);
		$comment = $temp_kumo[0];
		$kumotsuka = $temp_kumo[1];


		if ( $comment ne '' )	{
			print "<td bgcolor=\"$bg\"><font  color=\"$tx\">$comment</font></td>\n";
		}	else	{
			print "<td bgcolor=\"$bg\">　</font></td>\n";
		}


#改造：2002/11/16	
		if ( $kumotsuka ne '' )	{
			print "<td bgcolor=\"$bg\" width=100><font  color=\"$tx\">$kumotsuka</font></td>\n";
		}	else	{
			print "<td bgcolor=\"$bg\" width=100>　</font></td>\n";
		}



		print "<td bgcolor=\"$bg\" align=center nowrap width=5%><font color=\"$tx\">$regdate</font></td></tr>\n";
		$z++;
	}
	print "</table><br>\n";
	$dm = @new;
	if ( $dm % $pagemax == 0) {	$p = $dm / $pagemax ;}	else {	$p = $dm / $pagemax + 1;}			
	$p = sprintf("%3d",$p);

	print "<table border=0 cellpadding=0 cellspacing=5><tr>\n";
	if ( $FORM{'disppage'} != 0 && $FORM{'disppage'} !=1)	{
		print "<form action=$script method=$method>\n";
		$pag = $FORM{'disppage'} - 1 ;
		print "<input type=hidden name=\"disppage\" value=$pag>\n";
		print "<input type=hidden name=\"action\" value=\"$FORM{'action'}\">\n";
		print "<input type=hidden name=\"area\" value=\"$FORM{'area'}\">\n";
		print "<input type=hidden name=\"findname\" value=\"$FORM{'findname'}\">\n";
		print "<td><input type=submit name=\"page\" value=\"BACK\" $css_style></td></form>\n";
	}	
	if ( $FORM{'disppage'} + 1 <= $p )	{
		print "<form action=$script method=$method>\n";
		$pag = $FORM{'disppage'} + 1 ;
		print "<input type=hidden name=\"disppage\" value=$pag>\n";
		print "<input type=hidden name=\"action\" value=\"$FORM{'action'}\">\n";
		print "<input type=hidden name=\"area\" value=\"$FORM{'area'}\">\n";
		print "<input type=hidden name=\"findname\" value=\"$FORM{'findname'}\">\n";
		print "<td><input type=submit name=\"page\" value=\"NEXT\" $css_style></td></form>\n";
	}
	print "</tr></form></table>\n";
	if ( $p == 0 ) { $p = 1; }
	if ( $p != 1 )	{
		for ( $i = 1 ; $i <= $p ; $i++ )	{
			if ( (!($FORM{'disppage'}) && $i != 1 ) || ( $FORM{'disppage'} && ( $i ne $FORM{'disppage'}) ) )	{
				print "<a href=\"$script?disppage=$i&action=$FORM{'action'}&area=$FORM{'area'}&findname=$FORM{'findname'}\">$i</a>&nbsp;\n";
			}	else	{
				print "<b>$i</b>&nbsp;\n";
			}
		}
	}
	print "<br><br><font size=2>-- １ページに$pagemax件表\示されます --</font><br>\n";
	print "<br><hr width=80% size=1>\n";
	print "</center><div align=right>\n";
	print "<form action=\"$script\" method=\"$method\">\n";
	print "<font size=-1>あなたが投稿した記事に表\示されている\"No\"<br>及び投稿時に入力した
パスワードを指定すると修正・削除が行えます。</font><br>\n";
	print "No<input type=text name=\"no\" size=5 $css_style>\n";
	print "Pass<input type=password name=\"pass\" size=10 $css_style>\n";
	print "<select name=proc $css_style>\n";
	print "<option value=\"edit\">edit";
	print "<option value=\"delete\">delete";
	print "</select>\n";
	print "<input type=hidden name=\"action\" value=\"maintenance\">\n";
	print "<input type=submit value=\"update\" $css_style>\n";
	print "</form></div>\n";	
}
###<--------------------------------------------------------------
###<---   ログ出力
###<--------------------------------------------------------------
sub	regist	{
	if ( $FORM{'name'} eq "")	{	&error("名前を入力して下さい。") ;	}
if ( $FORM{'pass'} eq "")	{	&error("パスワードは必ず入力して下さい。") ;	}
if ( $FORM{'comment'} eq "")	{	&error("ことわざは必ず入力して下さい。") ;	}
	&filelock ;		#ファイルロック
	&dataread ;

	$dcnt = @LOG;	if ($dcnt >= $datamax) {	pop(@LOG);	}

	if ( $dcnt < 1 )	{
		$no = 1;											#１件目
	}	else	{
		($dummy,$no,$dummy) = split(/,/,$LOG[0]);					#最新記事No取得
		$no++;
	}

#改造 2006/06/04
	# パスワードの暗号化（crypt関数使用））
	if ($FORM{'pass'} ne "") { &pass_enc($FORM{'pass'}); }	else	{ $pass = '' ; }
	unshift(@LOG2,"$FORM{'area'},$no,$FORM{'name'},$FORM{'email'},$FORM{'sex'},$FORM{'hp'},$FORM{'ans'},$FORM{'comment'},$today,$pass\n");

	if ( !(open(OUT,">$logfile2")))	{	&fileunlock ;	&error("ログファイル($logfile)のオープンに失敗しました");	}
	print OUT @LOG2;
	close(OUT);

	if ( $sendmail ) { &SMail(1) ;	}

	&fileunlock ;	#ファイルロック解除
	
	if ( $damedame == 0 )	{
		print "Location: $script?\n\n";
	}	else	{
		print "Content-type: text/html\n\n";
		print "<html><head><META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=";
		print "$script\"></head><body></body></html>\n\n";
	}
	exit ;

}
###<--------------------------------------------------------------
###<---   メンテナンスモード
###<--------------------------------------------------------------
sub Maintenance {
	if ( $FORM{'no'} eq "")	{	&error("メンテナンスする記事Noを入力して下さい。") ;	}
	if ( $FORM{'pass'} eq "")	{	&error("パスワードを入力して下さい") ;	}

	$found = 0 ;
	&dataread ;
	foreach ( @LOG )	{ 
		($address,$n,$name,$email,$sex,$hp,$yobi,$comment,$regdate,$p) = split(/,/,$_);
		$p =~ s/\n//;
		if ( $FORM{'no'} eq $n )	{		
			$found = 1 ;
			if ($FORM{'pass'} ne $master_password && (&pass_dec($p))) { &error("パスワードが違います。"); }
			if ( $FORM{'proc'} eq "delete" )	{
				&update ;
				exit;
			}
			$c_address = $address ;	$c_sex = $sex ;
			$c_name = $name ;	$c_email = $email ;	$c_hp = $hp ;
			$c_comment = $comment ; 	$c_comment =~ s/\<br\>/\n/g;	$c_pass = $FORM{'pass'} ;	
			&forminput ;
			last;
		}
	}
	if ( $found == 0 )	{
		&error("該当する記事Noのデータは存在していません。");
	}
	&footer ;
	exit;
}

###<--------------------------------------------------------------
###<---   ログファイル更新
###<--------------------------------------------------------------
sub update {

	&filelock ;		#ファイルロック
	&dataread ;
    foreach (@LOG) {
		($dummy,$no,$dummy) = split(/,/,$_);
		if ( $FORM{'no'} eq $no)	{								#<<<メンテ対象者の場合
			if ( $FORM{'proc'} eq "edit" )	{
				# パスワードの暗号化（crypt関数使用））
				if ($FORM{'pass'} ne "") { &pass_enc($FORM{'pass'}); }	else	{ $pass = '' ; }
				push(@new,"$FORM{'area'},$no,$FORM{'name'},$FORM{'email'},$FORM{'sex'},$FORM{'hp'},$FORM{'ans'},$FORM{'comment'},$today,$pass\n");
			}
		}	else	{
			push(@new,"$_"); 								#<<<そのまま出力
		}
	}
	if ( !(open(OUT,">$logfile")))	{	&fileunlock ;	&error("ログファイル($logfile)のオープンに失敗しました");	}
	print OUT @new;
	close(OUT);
	&fileunlock ;	#ファイルロック解除
	if ( $damedame == 0 )	{
		print "Location: $script?\n\n";
	}	else	{
		print "Content-type: text/html\n\n";
		print "<html><head><META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=";
		print "$script\"></head><body></body></html>\n\n";
	}
}
###<--------------------------------------------------------------
###<---   全国制覇状況表示
###<--------------------------------------------------------------
sub seiha {
	&header ;

	&dataread ;
	for ( @LOG )	{ 
		($address,$no,$name,$email,$sex,$hp,$yobi,$comment,$regdate,$p) = split(/,/,$_);
		$area = sprintf("%02d",$address) ;
		$touroku{$address}++ ;
	}
	print "[<a href=\"JavaScript:history.back()\">BACK</a>]\n";
	print "<br><br><center><font size=+1>*-- 登録状況 --*</font>\n";
	print "<br><br>（）内の数字はその地域の登録者数です。\n";
	print "<br><br><table width=70% cellpadding=3 cellspacing=2 border=0>\n";
	print "<tr>\n";
	$j = 1 ;
	for ( $i = 0 ; $i <= $#AREATBL ; $i++ )	{
		$i = sprintf("%02d",$i) ;
		print "<td bgcolor=\"$tbgcolor\" align=center nowrap width=100><font color=$tbgtxcolor>$AREATBL[$i]</font></td>\n";
		if ( $touroku{$i} )	{
			print "<td bgcolor=\"$tbgcolor\" nowrap><font color=$tbgtxcolor>登録数&nbsp;($touroku{$i}人)</font></td>\n";
		}	else	{
			print "<td bgcolor=\"$tbgcolor\" width=50 nowrap >&nbsp;</td>\n";
		}
		$j++ ;
		if ( $j > 3 ) { 
			print "</tr>\n";
			print "<tr>\n" if ( $i != $#AREATBL ) ;
			$j = 1 ;
		}
	}
	print "</table>\n";

	&footer;
	exit;
}
###<--------------------------------------------------------------
###<---   エラー処理
###<--------------------------------------------------------------
sub error {
	&header ;
	print "<br><br>$_[0]\n";
	&footer;
	exit;
}
###<--------------------------------------------------------------
###<---   ファイルロック設定
###<--------------------------------------------------------------
sub filelock {
	foreach (1 .. 5) {
		if (-e $lockfile) { sleep(1); }
		else {
			open(LOCK,">$lockfile");
			close(LOCK);
			return;
		}
	}
	&error("只今他の方が書き込み中です。ブラウザの「戻る」で戻って再度登録を行って下さい。"); 
}
###<--------------------------------------------------------------
###<---   ファイルロック解除
###<--------------------------------------------------------------
sub fileunlock {
	if (-e $lockfile) { unlink($lockfile); }
}
###<-------------------------------------------------------------
###<---   パスワード暗号化
###<--------------------------------------------------------------
sub pass_enc {
	if ( $ango == 1 ) {
		$pass = crypt($_[0], $_[0]);
	}	else	{
		$pass = $_[0];
	}
}
###<-------------------------------------------------------------
###<---   パスワードチェック
###<--------------------------------------------------------------
sub pass_dec {
	if ( $ango == 1 ) {
		if ($_[0] ne '' && ( crypt($FORM{'pass'}, $_[0]) eq $_[0]) )  {	
			return 0 ;
		}
	}	else	{
		if ($FORM{'pass'} eq $_[0]) {	
			return 0 ;
		}
	}
	return 1;
}
###<-------------------------------------------------------------
###<---   都道府県別リンク部分生成
###<--------------------------------------------------------------
sub area_link {
	$i = sprintf("%02d",$_[0]) ;
	if ( $i != 99 )	{
		if ( $sekaiwamadamada == 1 && $i > 46 && $i != 53 )	{
			print "<td width=$sz_w height=$sz_h>";
		}	else	{
			if ( $colorflg == 0 ) {	#初期設定色を使用
			    print "<td width=$sz_w height=$sz_h bgcolor=$COLORTBL[$i]>";
			}	else	{			#登録人数によって色変更
				$j = 0 ;	$k = 0 ;
				foreach $buf ( @COLOR_NUM )	{
					if ( $buf <= $touroku{$i} )	{	$j = $k ; 	}
					$k++ ;
				}
			    print "<td width=$sz_w height=$sz_h bgcolor=$COLOR[$j]>";
			}
			if ( $touroku{$i} eq '' ) { $wk = "0人" ; }
			else	{	$wk = "$touroku{$i}人登録されています"; }
			print "<a href=\"$script?action=view&area=$i\"><img src=\"$gif_spacer\" border=0 width=\"$sz_w\" height=\"$sz_h\" alt=\"$AREATBL[$i]…$wk\"></a>";
		}
		print "</td>\n";
	}	else	{
		print "<br>△地域をクリックすると記事が表\示されます<br><br>\n";
		print "<a href=\"$script?action=view&area=$i\">現在の登録者$total人を最新から表\示</a>";
		if ( $colorflg == 1 )	{
			print "<br><br><table>\n";
			foreach ( 0..$#COLOR_NUM )	{
			    print "<tr><td width=$sz_w height=$sz_h><font color=\"$COLOR[$_]\">■</font></td><td>$COLOR_NUM[$_]人以上</td></tr>";
			}
			print "</table>\n";
		}
	}
}
###<--------------------------------------------------------------
###<---   SendMail
###<--------------------------------------------------------------
sub SMail {
	$ttl = $title;
	$wkcomment = $FORM{'comment'} ;
	$wkcomment =~ s/&lt;/</g;
	$wkcomment =~ s/&gt;/>/g;
	$wkcomment =~ s/<br>/\n/g;

	if ($FORM{'hp'} ne "") { $wk =  "http://$FORM{'hp'}"; }
$DETAIL = <<"EOM";
-------------------------------------------------------------
投稿された内容は下記の通りです。
-------------------------------------------------------------

▼投稿日
$today

▼記事No
$no

▼お名前
$FORM{'name'}

▼メールアドレス
$FORM{'email'}

▼地域
$AREATBL[$FORM{'area'}]

▼性別
$SEXTBL[$FORM{'sex'}]

▼ホームページ
$wk

▼メッセージ
$wkcomment

▼パスワード
$FORM{'pass'}

-------------------------------------------------------------
EOM

	#管理人用メール送信
	if ( $FORM{'email'} ) { $email = $FORM{'email'} ; } else { $email = $smail_address ; }
	if ( $hiho == 1 )	{
	   	&jcode'convert(*ttl,'euc');
		open(MAIL,"| $sendmail -s \"$ttl\" -f $email $smail_address ") || &error("Sendmail Error!!");
	}	else	{
		open(MAIL,"| $sendmail -t") || &error("Sendmail Error!!");
		$mailbuf = "To: $smail_address\n";
		$mailbuf .= "From: $email\n";
		$mailbuf .= "Reply-to: $email\n";
		$mailbuf .= "Subject: $ttl\n";
		$mailbuf .= "Content-Transfer-Encoding: 7bit\n";
		$mailbuf .= "Content-type: text/plain\n";
		$mailbuf .= "\n\n";
	}
	$mailbuf .= $DETAIL ;

	#漢字コードＪＩＳ変換＆改行コードLF変換。
   	&jcode'convert(*mailbuf,'jis');
	print MAIL	$mailbuf ;
	close(MAIL);

}
