#!/usr/local/bin/perl

#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#+++　　[ tackynotesp Ver0.723 ]
#+++		･････>>> All Created by Tacky				     
#+++		･････>>> Copyright (c) 2001.10 Tacky's Room. All rights reserved....
#+++        Email    >>> tacky2@ops.dti.ne.jp
#+++        Homepage >>> http://tackysroom.com/
#+++
#+++ 設置方法構成(具体例)
#+++
#+++ public_html（ホームページディレクトリ）
#+++ |-- cgi-bin（任意のディレクトリ）
#+++   |-- jcode.pl        (755)…(日本語ライブラリ)
#+++   |-- tackynotesp.cgi   (755)…(スクリプト本体)
#+++   |-- notelog           (777)…(ログ保存用フォルダ)
#+++   |     |-- 200110.txt　…CGI内部で自動作成します
#+++   |     |-- 200111.txt　…CGI内部で自動作成します
#+++   |-- noteimg           (777)…(画像保存用フォルダ)
#+++   |     |-- xxxx.gif …(画像)…ファイル名はアップロードするファイル名そのままです。
#+++   |-- icon               (777)…(アイコン用フォルダ)
#+++   |     |-- xxxx.gif …(アイコン)
#+++   |-- logo_back.gif        (１ヶ月戻るアイコン)
#+++   |-- logo_back.gif        (１ヶ月進むアイコン)
#+++   |-- spacer.gif        (ダミー透明画像)
#+++
#+++ ■画像アップロードはPerl5以上が必要です。多分。(^^;;;　hi-hoは確かダメ。
#+++
#+++ ■( )内はパーミッッションの値です。
#+++
#+++ ■tackynotesp.cgi  ：Perlのパス、その他の項目を修正、テキストモードでアップロード。
#+++
#+++ >>> Update-History...
#+++
#+++    2004.03.08(Ver0.723) >>  タグロジックに対するバグ修正。
#+++    2004.03.06(Ver0.722) >>  タグを許可するロジックに対するバグ修正。
#+++    2004.03.03(Ver0.721) >>  不具合対応
#+++    2004.02.07(Ver0.72) >>  ようやく海の日・敬老の日対応＆セキュリティ強化
#+++	2002.06.30(Ver0.71)#
#+++	・レスを修正した時に文字色が反映されなかったのを修正。
#+++	・状況によってレス修正画面にタイトルやアイコン設定が現れるのを修正。
#+++	・lock処理がダブっていたのを修正。
#+++
#+++	2002.04.26(Ver0.7)  スーパーサポーターの「ふくちゃん」に不具合対応及び改造をして頂いちゃいました。(^^ゞ
#+++	・【古いバージョンとはログの互換性がありません。ログコンバートスクリプトをダウンロードしてね。】
#+++	・週間表示の場合の不具合を修正
#+++    ・日記書き込みのコメント文字色の選択を可能とする（$colorc部分、以前のものとはログの互換性無し）
#+++    ・$tbgcolorを有効にする
#+++    ・アイコン一覧での不要なものを表示しないよう修正
#+++    ・リンクを [ ] で囲む(^^;)
#+++	・カレンダー部分の曜日部分の背景色を指定
#+++	・カレンダー部分の曜日部分の文字色を日付の色に合わせる
#+++    2001.10.27(Ver0.5) >>  ・β版リリース
#+++
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

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

$url 				= "schedule.cgi";	#戻り先ＵＲＬ
$script				= "./schedule.cgi";		#このＣＧＩの名前を指定
$titlename			= '';			#タイトルを指定
$titlelogo			= '<img src=./title_livescedule.gif><br>';				#タイトル画像を指定。src=の後ろに画像のパスを指定してね。（使用しない場合は、''で良い)
								#例：$titlelogo = '<img src=xxxx.gif>';
$bgcolor			= '#FFFFFF';			#背景色を指定
$backpicture			= '';				#背景画像を指定（使用しない場合は、''で良い)
$tbgcolor			= '#FFFFFF';			#入力フォームの背景色を指定
$ftextcolor			= '#666666';			#入力フォームの文字色を指定

$calcolor				= '#FFFFFF';			#カレンダー部分のセル背景色を指定
$calyoubicolor			= '#FFFFFF' ;			#カレンダー部分の曜日部分の背景色を指定
$calbordercolor			= '#666666' ;			#カレンダー部分の枠線の色を指定

$msg_cellbgcolor		= '#FFFFFF';			#日記部分の本文セル背景色を指定

$msg_bordercolor2		= '#666666' ;			#日記部分の日付枠線の色を指定
$msg_cellbgcolor2		= '#666666';			#日記部分の日付セル背景色を指定
$msg_celltxcolor2		= '#FFFFFF';			#日記部分の日付セル文字色を指定

#下記の背景色指定をした場合に、上記の$msg_cellbgcolor2やtxcolor2の色指定ではなくって、
#指定した背景色とそれに対応した文字色と同じ色で「日付表示部分」を表示する場合は1。上記の指定にする場合は0。
#・・・って指定細かすぎ？だって・・・こだわりたいのだー！（笑）＜と無駄なソースをばんばん埋め込むσ(^_^)。
$awaseru			= 1 ;

$colb_use			= 0;				#(0:色指定する 1:色指定しない）
#$colb_useが1（指定しない）場合は、下記の１番目の色を採用します。
#入力フォーム・背景色の指定
@COLORS_B = ('#666666','#B1D23E','#E7DE38','#81BEC9','#F1A287','#E1BAE2','#FBF7A6','#E1E1E1','#D0B880','#EF653D');
#背景色に対してのタイトルやレスフォーム部分の文字色もやっぱり変更出来ないとだめだね。っちゅー訳でタイトルの文字色。
#$colb_useが1（指定しない）場合は、下記の@COLORS_Fの１番目の色を採用します。
@COLORS_F = ('#FFFFFF','#000000','#003399','#990000','#669900','#cc3399','#ff6633','#cc0000','#804000','#666666');	#タイトル色

#コメントの文字色
@COLORS_C = ('#666666','#008000','#ff4500','#4169E1','#ff6666','#666666','#999900','#ff9999','#cc99cc','#990000');
$password			= 'homework';			#メンテナンス用パスワード（管理者用）

#<<<祝日の設定(成人の日・体育の日・春分の日・秋分の日は除きます)
@holiday = ('0101','0211','0429','0503','0504','0505','1103','1123','1223');
#※成人の日・海の日・敬老の日・体育の日・春分の日・秋分の日は除いて下さい

#◆<<<　指定年月のログを、一度に１ヶ月分表示させるか？(yes,no,week)。
#◆<<<　noの場合は一日ずつ表示（一日毎にクリックするとログを表示するパターン）
#◆<<<　weekの場合は週単位で表示（１ヶ月分表示する事も可能です）
$monthview			= 'yes';
#◆<<<　上記の$monthviewが'no'以外の場合、
#◆<<<　ログを昇順(上から1〜31日)に表示するなら'1',降順(上から31〜1日）の場合'2'
$viewsort			= 1;
#◆<<<　カレンダー部分（ひとマス）のheight,width（四角形なので、設定値も１個だけね）40以上だとちょっと縦長になるけど我慢。
$calsize			= 35 ;			#Pixel
#◆<<<　↓お好きなようにどうぞ。例： ('Sun','Mon','Tue','Wed','Thu','Fri','Sat') 
@week = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat');

$col				= 50 ;			#日記を書く欄の横桁数(80だと日本語で40文字です）
$row				= 15 ;			#日記を書く欄の行数

#==========================================================================================
#＞＞＞カレンダー部分に『日記を書いた日』である事を認識させる設定
#==========================================================================================
#  $icon_gif[0]が設定されている場合は、$icon_gif[n]を優先的に表示させます。
#  $icon_gif[0]が設定されていない場合(削除してもいいけど）は
#  $img_gifが設定されていれば$img_gifの画像を表示、未設定の場合は■を表示します。
#１個のアイコンだけを使用する場合
$img_gif			= '';		#"メモを書いた日"に表示する画像を指定。（指定しないと■が表示されます）
#複数のアイコンを使用する場合。たくさん設定した場合、$icon[4]...$icon[9]のようにただ増やしていけばいいです。
$icon[0]='./live.gif' ;	$iconnm[0]='ライブ';
$icon[1]='./other.gif' ;$iconnm[1]='その他の予定';
$icon[2]='./media.gif' ;	$iconnm[2]='テレビ・ラジオ等の放送など';
$icon[3]='./star.gif' ;	$iconnm[3]='チケット等の発売日';

$icon_w				= 0;	#アイコン横サイズ（全アイコンが同じサイズの場合。異なる場合は0にしてね）
$icon_h				= 13;	#アイコン縦サイズ（全アイコンが同じサイズの場合。異なる場合は0にしてね）

$disp_icon			= 1 ;	#日記を表示した際に日記の横にアイコンも表示する？(0:no 1:yes)

#==================================================================================================================
#＞＞＞日記表示部に表示するアイコンの設定　$disp_icon = 1(yes)の設定の場合のみ有効。noの場合は無視していいです。
#==================================================================================================================
$onaji				= 1;	#カレンダーに表示するアイコンと同じアイコンを使う？(0:no 1:yes)
#アイコン・アイコン名称・アイコンの幅・アイコンの高さ。　幅と高さがわからない場合は、$icon2_w[0]=0;のように0を指定してね。
#アイコンを追加する場合は、$icon2[4]...$icon2[9]のようにただ増やしていけばいいです。
$icon2[0] = './ball.gif' ;		$iconnm2[0] = '気分はボール' ;
$icon2_w[0] = 32 ; $icon2_h[0] = 32 ;
$icon2[1] = './corgi.gif' ;	$iconnm2[1] = '気分はコーギー' ;
$icon2_w[1] = 32 ; $icon2_h[1] = 32 ;
$icon2[2] = './fire.gif' ;		$iconnm2[2] = '気分は炎' ;
$icon2_w[2] = 32 ; $icon2_h[2] = 32 ;
$icon2[3] = './beer.gif' ;		$iconnm2[3] = '気分はビール' ;
$icon2_w[3] = 32 ; $icon2_h[3] = 32 ;
$icon2[4] = './denchi.gif' ;	$iconnm2[4] = '気分は電池' ;
$icon2_w[4] = 32 ; $icon2_h[4] = 32 ;
$icon2[5] = './rainbow.gif' ;	$iconnm2[5] = '気分は虹' ;
$icon2_w[5] = 32 ; $icon2_h[5] = 32 ;
$icon2[6] = './space.gif' ;	$iconnm2[6] = '気分は宇宙' ;
$icon2_w[6] = 32 ; $icon2_h[6] = 32 ;
$icon2[7] = './tv.gif' ;		$iconnm2[7] = '気分はテレビ' ;
$icon2_w[7] = 32 ; $icon2_h[7] = 32 ;
$icon2[8] = './cow.gif' ;		$iconnm2[8] = '気分は牛' ;
$icon2_w[8] = 32 ; $icon2_h[8] = 32 ;
$icon2[9] = './hatena.gif' ;	$iconnm2[9] = '気分ははてな？' ;
$icon2_w[9] = 32 ; $icon2_h[9] = 32 ;
$icon2[10] = './mail.gif' ;	$iconnm2[10] = '気分はメール' ;
$icon2_w[10] = 32 ; $icon2_h[10] = 32 ;
$icon2[11] = './castela.gif' ;	$iconnm2[11] = '気分はカステラ' ;
$icon2_w[11] = 32 ; $icon2_h[11] = 32 ;

#アイコン一覧を表示する際、１行にアイコンを何個表示します？
$icon_line			= 2 ;			#←の場合、３個表示したら改行するって事です。

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

$back_gif			= './logo_back.gif';		#「１ヶ月戻る」用画像（使用しない場合は''）
$next_gif			= './logo_next.gif';		#「１ヶ月進む」用画像（使用しない場合は''）
$setyear_b			= 1;	#カレンダーを年月指定で移動する場合、「年」は過去何年まで表示します？(1の場合、前年まで表示）
$setyear_a			= 1;	#カレンダーを年月指定で移動する場合、「年」は未来何年まで表示します？(5の場合、５年先まで表示）

$tbl_sz				= '400' ;		#日記表示部のテーブル横幅（ピクセル又は％）

$color_nml			= '#666666';		#カレンダー・「平日」の文字色
$color_sat			= '#6666FF';		#カレンダー・「土曜日」の文字色
$color_sun			= '#FF6666';		#カレンダー・「日曜日」の文字色
$color_hol			= '#FF6666';		#カレンダー・「祝日」の文字色
$color_today			= '#CCFF00';		#カレンダー・「今日」の背景色

$resflg				= 0 ;			#レス機能を使用する？(0:しない 1:する)

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

#色の指定(１行レス投稿時の文字色)。色を増やしたい場合は、'#336699','#003366'のようにどんどん増やしていいですよ。
@COLORS 	= ('#000000','#008000','#ff4500','#4169E1','#ff6666','#666666','#999900','#ff9999','#cc99cc','#990000');
@COLORSNM	= ('Black','Green','Orange','Blue','Red','Gray','Gold','Pink','Purple','Brown');

#１行レス投稿フォームでの返信ボタンに表示する文字
$resword	= '感想';

$titleflg	= 1 ;		#日記に「タイトル」が必要？(0:不要 1:必要)

#掲示板荒らし対策。排除したいプロバのアドレスを設定して下さい。
#　"xxx?.com"とした場合、"xxx1.com","xxx2.com"等、「？」の部分が文字列１つと判断します
#  "xxx*.com"とした場合、"xxx1.com","xxx12345.com等、「＊」の部分が０個以上の文字列と判断します。
@DANGER_LIST=("xxx.com","yyy.com","zzz*.or.jp");

#掲示板荒らし対策その２。メッセージ最大文字数を指定。特に設定しない場合は、''として下さい。3000は全角1500文字です。
$Maxword = '3000' ;

#レス投稿フォームのコメント入力欄は「１行テキスト」？「複数行テキスト」？
$res_text	= 0 ;		#0:１行テキスト　1:複数行テキスト（テキストエリア）
$sz		= 60 ;		#１行レス場合、１行の文字数は？
$c_sz		= 40 ;		#複数行テキストの場合、１行の文字数
$r_sz		= 3 ;		#複数行テキストの場合、行数

$minnade	= 0;		#管理人以外も日記を書けるようにする？(0:しない 1:する)
$minnade_gif  = '';	#$minnade=1の場合に表示する「新規投稿用アイコン画像」を指定。画像を使用しない場合は''でいいです。その場合「新規投稿」と表示されます

$zurazura	= 0 ;		#１日に複数回（人）日記を書いた場合、アイコンを１個しか表示しないようにする？(0:しない 1:する)

$kiero		= 1;		#カレンダーを表示しますか？(0:no 1:yes)…同スクリプトに直接アクセスした際に、カレンダーを表示しないで、当月の日記部分のみ表示する場合は1となります	i001109

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

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Sendmailが使える方のみ以下の項目を設定して下さい。(Ver0.85からの機能)
#    ※Sendmailとは？
#　　　メールソフトを立ち上げないで、指定した相手にメールを送る事が出来る機能です。
#　　　自分のプロバイダーがSendmailに対応しているか、パスはどこ？等は、各自のプロバイダー
#　　　のＨＰでご確認して下さいね。
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#投稿時に管理者にメール送信する場合、sendmailのパスを指定
$sendmail = "";
#メール送信先アドレス。（管理者のアドレス）…「＠」の前には必ず「￥」を付けてね。
$smail_address = "xxxxxx\@xxx.xx.jp";

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

$sinchaku		= 0 ;			#レス機能有にした場合、最新レスのあった日記を表示します。0の場合は表示しない、0以外は指定した数だけ表示します。
$sinchaku2		= 0 ;			#最新投稿を表示します。0の場合は表示しない、0以外は指定した数だけ表示します。

$omakase		= 3 ;			#日記表示部分の「日付」が表示されてる所と、「本文」が表示されている
								#テーブルの間にある隙間をどれくらいにします？数字でよろしく。

#ログ表示の際、「日記の日付」・「投稿日付」の表示方法設定
#　　　　○：表示する　×：表示しない
#　$timedisp=1：「日記の日付：○」・「投稿日付：○」
#　$timedisp=2：「日記の日付：○」・「投稿日付：×」
#　$timedisp=3：「日記の日付：×」・「投稿日付：○」
#　$timedisp=4：「日記の日付：×」・「投稿日付：×」
$timedisp		= 2 ;

$method			= 'POST';				#METHODの指定(POST又はGET)

$tag			= 0 ;					#管理人以外もタグ許可しますか？(0:no 1:yes)

#<<< ログ設定…指定したディレクトリ($olddir)直下に"200101.txt".."200112.txt"（上４桁は年月）のように作成します
#<<< ※CGIと同じ階層には、設置出来ません。必ずログ保存用フォルダを作成してください。
#<<< ※月単位に日記を保存します。
$logdir			= './notelog/' ;	#過去ログ作成用ディレクトリを指定。最後に必ず「/」を付けてね。

$target			= '_blank' ;		#[HOME]をクリックした時のターゲット指定
$bdcolor		= '#666666';		#所々に使っております横線（水平線）の色（IEだけ色変わる）
$bdcolor2		= '#666666';		#レス有りの場合、本文とレス文の間の横線（水平線）の色（IEだけ色変わる）
$dlsw			= 0 ;			#ログをダウンロード可能にする場合(Winのみ)は「1」を指定。

$simaru			= '' ;		#日記本文のテーブルに枠線要らない？要るなら線の色を。要らないなら''。

$set_font		= 'Arial, Helvetica, sans-serif';	#カレンダーの数字部分だけフォント指定出来ます。フォント名を「,」で区切ってズラズラと
$findsw			= 0 ;				#「検索」を使用します？(0:使用しない　1:使用する)
$mojisz			= 2 ;				#日記表示部分のフォントサイズ

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

#▼タイトルの下に何か表示したいメッセージがあれば"EOM";の次の行からEOMの前の行にメッセージどうぞ。
#  表示しない場合は、"EOM";とEOMの間の行を削除してね。
$HEAD_COMMENT = <<"EOM";
ホームワーク関連アーティストのスケジュールです<BR>
（<a href="http://www.ban-ban-bazar.com/cgibin/schedule/schedule.cgi">バンバンバザール専用のスケジュールはこちら</a>）<BR>
ライブやイベントのある日にはアイコンが表\示されます<BR>
　<img src="live.gif">ライブ開催日<img src="media.gif">テレビ等の放映日<BR>
<img src="other.gif">その他のイベント開催日<img src="star.gif">チケットの発売日<BR>
<BR><BR>
EOM

#★【画像アップロードを使わない場合は、「$UpFolder = "";」にしておいて他の画像アップに関する設定項目は無視していいですよ】

# アップロードディレクトリのパス → パスの最後は / を付けてください。
#※hi-hoの方は、$UpFolder = "$ENV{'HOME'}/html/画像フォルダ名/";として下さいね。
#※Niftyの方は、$UpFoler  = "/homepage/画像フォルダ名/";でたぶん良いかと・・・(^^;;;
$UpFolder = "./noteimg/";

# アップロードディレクトリのＵＲＬパス → パスの最後は / を付けてください。
#※hi-hoの方は、$UpUrl = "../../../ユーザー名/画像フォルダ名/";
#※Niftyの方は、$UpUrl = "http://homepage?.nifty.com/ユーザー名/画像フォルダ名/";でたぶん良いかと・・・(^^;;;
#※画像がCGIフォルダに設置可能なサーバーをご使用の方は上記$UpFolderと同じでいいと思いますわ。
$UpUrl = "./noteimg/";

# 投稿受理最大サイズ (bytes)
# → 例 : 102400 = 100KB
$maxdatasz = '102400';

# 画像ファイルの最大表示サイズ（Pixel）。サイズを超えた場合は画像縮小表示。
$MaxWidth	= 300;	#横幅　※必ず指定して下さい。どうしても縮小したくない方は666666とかにしてね。
$MaxHeight	= 200;	#縦幅　※必ず指定して下さい。どうしても縮小したくない方は666666とかにしてね。

$point		= 1 ;	#画像の表示位置（1:Left 2:Center 3:Right)
$maware		= 1 ;	#画像に対して文章の回り込みをしますか？しない場合は１行下から文章が表示されます。
$sizeflg	= 0 ;	#画像の下にファイルサイズを表示しますか？(0:no 1:yes)　※$maware=1の場合はファイルサイズ表示せずimgタグのALTで表示されます

#ログ表示部の画像をクリックし、通常サイズの画像を表示する場合、
#１：画像の大きさのウインドウを開き画像を表示。
#２：新規ウインドウを開き画像を表示。※広告バナーが表示されるサーバーの方はこちらの設定ですね。
$imglink	= 1 ;

#初期表示は一日前の日記を表示する？
$initdisp	= 0 ;	#0:当日　1:前日

#アップロード可能とするファイル形式。 ※追加可。
@FMT	= ("gif","jpg","jpeg","png");

@errtag = ('table','meta','form','!--','embed','html','body','tr','td','th','a');		#デンジャラ〜なタグ

#スクロールバーの色変更。よくわからない方は、"EOM"の次の行から先頭がEOMの行の間を削除してね。
$scrollbar = <<"EOM";
EOM

#◆◆◆↓セキュリティ◆◆◆
$postchk		= 1;		#投稿時・メンテナンス時のMethodをPOST限定にする場合は１。以外は０。
$urlchk			= '';	#ここで指定されたアドレス(CGIの設置アドレスを記入)以外から投稿があった場合をエラーとします。設定しない場合は''
#◆◆◆↑セキュリティ◆◆◆

#スクロールバーの色変更。よくわからない方は、"EOM"の次の行から先頭がEOMの行の間を削除してね。
$scrollbar = <<"EOM";
EOM
	
$autolink	= 1 ;	#「http〜」を入力すると「こちら」と自動リンクするのを使う？(0:no 1:yes)　

#=============================================================================================================================================================================================
#<<<　ここから下はいじらない方が身のためです。
###############################################################################
#### Main Process  START  #####################################################
###############################################################################
#<<<システム日時・時刻取得
@cdays = (0,31,28,31,30,31,30,31,31,30,31,30,31);
$ENV{'TZ'} = "JST-9";

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$syear = sprintf("%02d",$year + 1900);$smonth = sprintf("%02d",$mon + 1);$sday = sprintf("%02d",$mday);
$week = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat') [$wday];
$hour = sprintf("%02d",$hour);$min = sprintf("%02d",$min);
$sysdate = "$syear/$smonth/$sday($week) $hour:$min";

if ( $initdisp == 1 ) {
	$iday = time + 86400 * (-1);
	($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($iday);
	$syear = sprintf("%02d",$year + 1900);$smonth = sprintf("%02d",$mon + 1);$sday = sprintf("%02d",$mday);
}

if ( $UpFolder && !(-e $UpFolder) ) { &error("画像アップロード先のフォルダが存在していません。"); }

&cookieget;						#<<<COOKIEの取得
&decode ;						#<<<デコード
$cyear = 1989;
$cday = 365;
($sec,$min,$hour,$day,$mon,$year,$wday)= localtime;
$day = '';
if ( $FORM{'action'} eq '' || $FORM{'action'} eq 'find')	{
	$year = $syear;
	$mon  = $smonth;
	$day  = $sday;
} else {
	if ( $FORM{'ym'} ne '' ) {
		$FORM{'year'} = substr($FORM{'ym'},0,4);
		$FORM{'month'} = substr($FORM{'ym'},4,2);
	} else {
		$year = $syear;
		$mon  = $smonth;
		$day  = $sday;
	}
	$year = $FORM{'year'};
	$mon = $FORM{'month'};
	$day = $FORM{'day'};
}
$mon = sprintf("%02d",$mon);
if ( $FORM{'action'} eq 'maintenance' ) {      				#"処理"がメンテナンスの場合
	if ( $FORM{'proc'} eq 'write' )	{
		if ( $FORM{'pass'} eq "" && $minnade == 0 ) { &error("パスワードを入力して下さい。"); }
		if ( $FORM{'pass'} ne $password && $minnade == 0 ) { &error("パスワードが違います。"); }
		&header ;						#htmlヘッダー出力
		&forminput ;						#入力フォーム表示
	} else {
		&Maintenance; 
	}
} elsif ( $FORM{'action'} eq 'update' )	{				#ログファイル更新（編集時）
	&update ;
} elsif ( $FORM{'action'} eq 'imgdisp' ) {				#画像表示
	print "Content-type: text/html; charset=Shift_JIS\n\n";
	print "<html><head><title></title></head>\n";
	print "<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>\n";
	print "<img src=\"$UpUrl$FORM{'img'}\" border=0>";
	print "</body></html>\n";
	exit;
} elsif ( $FORM{'action'} eq 'download' ) {				#ログをダウンロードするi001108
	&download ;
} elsif ( $FORM{'action'} eq 'icondisp' ) {				#アイコン一覧を見る
	&icondisp ;
} elsif ( $FORM{'action'} eq 'resdisp' ) {				#最新レス一覧を見る
	&header ;							#htmlヘッダー出力
	&view ;
} elsif ( $FORM{'action'} eq 'view' ) {					#ログファイル更新（編集時）
	&header ;							#htmlヘッダー出力
	&calender ;							#カレンダー表示
	&view ;								#ログ表示
} else {
	if ( $FORM{'action'} eq 'regist' ) {
		&regist ;
	}
	&header ;							#htmlヘッダー出力
	&calender ;							#カレンダー表示
	&view ; 							#ログ表示
}

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

###<--------------------------------------------------------------
###<---   デコード＆変数代入
###<--------------------------------------------------------------
sub decode {
	if ( $ENV{CONTENT_TYPE} =~ /multipart\/form-data/) {
		$post=1;
		local($buff,$buff2,$key,$len,$idx,@LIST) ;
		if ( $ENV{'CONTENT_LENGTH'} > $maxdatasz ) { &error("アップロードファイルのサイズが" . int($maxdatasz / 1024) . "kbを超えている為アップロード出来ません。"); }
		 # 標準入力からデータを読込む
	 	$buff = "";
		binmode(STDIN); 
       		read(STDIN, $buff, $ENV{'CONTENT_LENGTH'});
		if ($buff =~ /application\/x-macary/i) { $mac=1; }
		$buff =~ /^(.+)[\r|\n]/;
		$buff2 = $1;    $buff2 =~ s/[\r|\n]//;
		# 切り取る
	 	@LIST = ();   @LIST = split(/$buff2/, $buff);
	 	shift @LIST; pop @LIST; #余計なものはいらない
		foreach (@LIST){
		#キー情報を取得
	        $key = "";
	        $key = $1 if ($_ =~ /name="(.*)";/);
	        if ($key eq ""){
	            # ファイル以外のコントロールの場合
	            $key = $1 if ($_ =~ /name="(.*)"/);
	            if ($key eq "") { next ; }
	        }
	        #アップロードファイル名をフルパスからファイル名を抽出。
	        $upfname = "";
	        if ($_ =~ /filename="(.*)"/){
			    $upfname = $1;$upfname=~s/.+(\/|\\)//;
			}
	        #値情報を抽出
			if ( $upfname ne '' ) {
		        $idx = index $_, 'Content-Type:' ;
			} else { 
	        	$idx = index $_, 'Content-Disposition:';
			}
	        $len = length($_);
	        if ($idx != -1){
				#$_の文字列の中で$idxの位置より\r\n(改行ｺｰﾄﾞ)が見つかった位置を$idxに返却　※先頭は０
	            $idx = index $_, "\r\n", $idx;
	            if ($idx != -1){
	                $idx += 4;
	                # 最後の\r\nはつけないようにする
	                $value = substr($_, $idx, $len - $idx - 2);
					if ( $upfname eq '' ) {
						$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
						$value =~ s/\,/&knm/g;
						if ( $key ne 'comment' )	{	$value =~ s/\r\n//g;	$value =~ s/\r|\n//g;	}
						if ( $tag == 0 && $key ne 'comment' )	{	
							$value =~ s/&/&amp;/g;	$value =~ s/"/&quot;/g;
							$value =~ s/</&lt;/g;	$value =~ s/>/&gt;/g;
						}
						&jcode'convert(*value,'sjis');
					}
	                $FORM{$key} = $value;
	            }
	        }
	    }
	} else {
		if ($ENV{'REQUEST_METHOD'} eq "POST") {
			read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});	$post=1;
		} else { $buffer = $ENV{'QUERY_STRING'}; $post=0;}
		@pairs = split(/&/,$buffer);
		foreach $pair (@pairs) {
			($name, $value) = split(/=/, $pair);
			$name =~ tr/+/ /;
			$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
			$value =~ tr/+/ /;
			$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
			$value =~ s/\,/&knm/g;
			if ( $name ne 'comment' )	{	$value =~ s/\r\n//g;	$value =~ s/\r|\n//g;	}
			if ( $tag == 0 && $name ne 'comment' )	{	
				$value =~ s/&/&amp;/g;	$value =~ s/"/&quot;/g;
				$value =~ s/</&lt;/g;	$value =~ s/>/&gt;/g;
			}
			&jcode'convert(*value,'sjis');
			$FORM{$name} = $value;
		}
	}	
	if ($FORM{'pass'} ne $password ) { 
		if ( $tag == 0 ) { 
			$FORM{'comment'} =~ s/&/&amp;/g;	$FORM{'comment'} =~ s/</&lt;/g;	$FORM{'comment'} =~ s/>/&gt;/g;	$FORM{'comment'} =~ s/"/&quot;/g; 
		}	else {
			foreach ( @errtag ) { if ($FORM{'comment'} =~ /<$_(.|\n)*>/i) {	 &error("使用出来ないタグが入力されています"); } }
		}
	}
	if ( $FORM{'action'} eq 'regist' || $FORM{'action'} eq 'maintenance' || 
		 $FORM{'action'} eq 'update' )	{
		if ( $postchk && !$post )	{	&error("不正な投稿です。");	}
		if ( $urlchk && $ENV{HTTP_REFERER} !~ /$urlchk/i )	{	exit;	}
	}
	$FORM{'comment'} =~ s/\r\n/<br>/g;	$FORM{'comment'} =~ s/\r|\n/<br>/g;

}
###<--------------------------------------------------------------
###<---   ログファイル読み込み
###<--------------------------------------------------------------
sub dataread {
	@FINDTBL = split(/ /,$FORM{'word'});			#検索文字列
	@LOG = ();	@MAINLOG = () ; @RESLOG = () ;
	if ( $FORM{'action'} ne 'resdisp' && @FINDTBL < 1 ) {
		$logfile = $logdir . $year . $mon . ".txt";
		$newsw = 0 ;
		if ( open(IN,"$logfile") ) {
			@LOG = <IN>;	close(IN);
			foreach $BUF2( @LOG ) {
				($targetdate,$no,$ic,$title,$resno,$name,$color,$colorb,$colorc,$comment,$regdate,$pass,$hst,$ic2,$imgfile) = split(/,/,$BUF2);
				if ( $resno eq '' ) {
				push(@MAINLOG,$BUF2) ;
				} else {
				push(@RESLOG,$BUF2) ;
				}
			}
			@RESLOG = reverse @RESLOG ;			#レスログは古い順に。
		} else {
		$newsw = 1 ;
		}
	} else {
		if ( !(opendir(DIR,"$logdir")))	{ &error("ログ保存用フォルダ($logdir)が見つからないか又は開けません"); }
		@LOGDATA = grep(/\.txt/,readdir(DIR));
		closedir(DIR) ;
		foreach $BUF ( @LOGDATA ) {
			$logfile = $logdir . $BUF;
			$newsw = 0 ;
			if ( open(IN,"$logfile") ) {
				foreach $BUF2 ( <IN> ) {
					($targetdate,$no,$ic,$title,$resno,$name,$color,$colorb,$colorc,$comment,$regdate,$pass,$hst,$ic2,$imgfile) = split(/,/,$BUF2);
					if ( $FORM{'action'} eq 'find' ) {
						$found = 0;
						if ( @FINDTBL > 0 ) {
							foreach $buf ( @FINDTBL ) {
								#検索文字列
								if ( index($name,$buf) >= 0 ) {	$found = 1 ;	last ;}
								if ( index($title,$buf) >= 0 ) { $found = 1 ;	last ;}
								if ( index($comment,$buf) >= 0 ) { $found = 1 ;	last ;}
							}
						} else {
							$found = 1 ;
						}
						if ( $found == 1) {
							$found2 = 0 ;
							foreach $BUF3 ( @FINDLOG ) {
								($a,$b,$c) = split(/,/,$BUF3);
								if ( (substr($targetdate,0,6) == substr($c,0,6)) &&  ($b == $no || $b == $resno) ) {
								$found2=1; last ;
								}
							}
							if ( $found2 == 0 ) {
								if ( $resno eq '' ) {
								push(@FINDLOG,"$regdate,$no,$targetdate") ;
								} else {
								push(@FINDLOG,"$regdate,$resno,$targetdate") ;
								}
							}
						}
					} else {
						#▼投稿日を新着件数分配列退避
						if ( ($FORM{'rflg'} == 1 && $resno ne '') || ($FORM{'rflg'} == 2 && $resno eq '') ) {
							$found2 = 0 ;
							foreach $BUF3 ( @FINDLOG ) {
								($a,$b,$c) = split(/,/,$BUF3);
								if ( (substr($targetdate,0,6) == substr($c,0,6)) && ($b == $no || ($FORM{'rflg'} == 1 && $b == $resno) ) )	{
								$found2=1; last ;
								}
							}
							if ( $found2 == 0 ) {
								if ( $FORM{'rflg'} == 1 ) { $dmy = $resno ; } else { $dmy = $no ; }
								push(@FINDLOG,"$regdate,$dmy,$targetdate") ;
							}
						}
					}
				}
				close(IN);
			} else {
			$newsw = 1 ;
			}
		}

		@FINDLOG = sort @FINDLOG ;			#最新登録順
		@FINDLOG = reverse @FINDLOG ;			#最新登録順
		if ( $FORM{'action'} eq 'resdisp' ) {
			$i=1;
			foreach $BUF ( @FINDLOG ) {
				if ( ($FORM{'rflg'} == 1 && $i <= $sinchaku) || ($FORM{'rflg'} == 2 && $i <= $sinchaku2) ) { push(@sv,$BUF); }
				else { last ; }
				$i++;
			}
			@FINDLOG = @sv;
		}

		foreach $BUF ( @FINDLOG ) {
			($regdate,$fno,$ftargetdate) = split(/,/,$BUF);
			$logfile = $logdir . substr($ftargetdate,0,6) . ".txt" ;
			if ( open(IN,"$logfile") ) {
				foreach $BUF2 ( <IN> ) {
					($targetdate,$no,$ic,$title,$resno,$name,$color,$colorb,$colorc,$comment,$regdate,$pass,$hst,$ic2,$imgfile) = split(/,/,$BUF2);	
					if ( (substr($ftargetdate,0,6) == substr($targetdate,0,6)) && ($fno == $no || $fno == $resno) ) {
						if ( $resno eq '' ) {
						push(@MAINLOG,$BUF2) ;
						} else {
						push(@RESLOG,$BUF2) ;
						}
					}
				}
				close(IN);
			}
		}
		@RESLOG = reverse @RESLOG ;			#レスログは古い順に。
	}
}
###<--------------------------------------------------------------
###<---   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>$titlename</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";

	if ( $scrollbar ) { print $scrollbar; }

	print "-->\n";
	print "</style>\n";
	#<<<CSS END>>>
	print "</head>\n";
	$wk = "bgcolor=\"$bgcolor\"";
	$wk2 = "background=\"$backpicture\"";
	print "<body $wk $wk2 text=$tcolor link=$linkcolor vlink=$vlinkcolor alink=$alinkcolor leftmargin=5 topmargin=6 marginwidth=5 marginheight=6>\n";

	print "<table cellpadding=0 border=0 cellspacing=0 width=100%><tr>\n";
	print "<td nowrap>&nbsp;&nbsp;[<a href=$url target=\"$target\">HOME</a>]</td>\n";
	if ( $FORM{'action'} ne 'view' && $FORM{'action'} ne '') {
		print "<td nowrap>&nbsp;&nbsp;\n";
		print "[<a href=\"JavaScript:history.back()\">BACK</a>]</td>\n";
	}
	if ( $FORM{'action'} ne 'icondisp' && ($icon[0] ne '' || $icon2[0] ne '')) {
		if ( $kiero == 1 || ($disp_icon == 1 && $onaji == 0 && $icon2[0] ne '')) {	#i001213
			print "<td nowrap>&nbsp;&nbsp;&nbsp;[<a href=\"$script?action=icondisp\">information</a>]</td>\n";
		}	#i001213
	}
	if ( $resflg == 1 && $sinchaku != 0 ) {
		print "<td nowrap>&nbsp;&nbsp;&nbsp;[<a href=\"$script?action=resdisp&rflg=1\">最新レス</a>]</td>\n";
	}
	if ( $sinchaku2 != 0 ) {
		print "<td nowrap>&nbsp;&nbsp;&nbsp;[<a href=\"$script?action=resdisp&rflg=2\">最新投稿</a>]</td>\n";
	}
	print "<form action=\"$script\" method=\"$method\">\n";
	print "<td width=10% nowrap>&nbsp;</td>\n";
	print "<td width=80% align=right>";
	if ( $FORM{'action'} ne 'resdisp' ) {
		print "<table cellpadding=0><tr>";
		print "<td>";
		print "No.<input type=text name=\"no\" size=3 $css_style>\n";
		print "Pass<input type=password name=\"pass\" value=\"$c_pass\"size=10 $css_style>\n";
		print "<select name=\"proc\" $css_style>\n";
		print "<option value=write>write\n" if ( $minnade == 0 ) ;
		print "<option value=edit>edit\n";
		print "<option value=delete>delete\n";
		print "</select>\n";
		print "<input type=submit value=\"Go!\" $css_style>\n";
		print "<input type=hidden name=\"action\" value=\"maintenance\">\n";
		print "<input type=hidden name=\"year\" value=\"$year\">\n";
		print "<input type=hidden name=\"month\" value=\"$mon\">\n";
		print "<input type=hidden name=\"day\" value=\"$day\">\n";
		print "</td></form>";
		print "</tr></table>";
	}
	print "</td></tr></table>\n" if ( $FORM{'action'} ne 'resdisp' ) ;
	if ( $findsw == 1) {
		print "<table cellpadding=0 border=0 cellspacing=0 width=100%>\n";
		print "<tr>\n";
		print "<form action=\"$script\" method=\"$method\">\n";
		print "<td align=right>\n";
		print "<hr size=1 noshade color=\"$bdcolor\">\n" if ( $FORM{'action'} ne 'resdisp' ) ;
		print "<input type=hidden name=\"action\" value=\"find\">\n";
		print "<input type=text size=26, name=word value=\"$FORM{'word'}\" $css_style>\n";
		print "&nbsp<input type=submit name=button value=\"検索\" $css_style><br>\n";
		print "</td></tr>\n";
		print "</form>\n";
		print "</table>\n";
	}
	print "</td></tr></table>\n" if ( $FORM{'action'} eq 'resdisp' ) ;

	print "<center>\n";
	if ( $titlelogo ) {
		print "$titlelogo<br>\n";
	} else {
		print "<font size=\"+1\">$titlename</font><br>\n";
	}
	if ( $FORM{'proc'} ne 'write' )	{
		print $HEAD_COMMENT if ( $HEAD_COMMENT ) ;
		if ( $minnade == 1 ) {
			print "<form action=\"$script\">\n";
			if ( $minnade_gif ) {
				print "<input type=image src=$minnade_gif alt=新規投稿>\n";
			} else {
				print "<input type=submit value=新規投稿 $css_style>\n";
			}
			print "<input type=hidden name=\"action\" value=\"maintenance\">\n";
			print "<input type=hidden name=\"proc\" value=\"write\">\n";
			print "</form>";
		}
	}
	print "</center>\n";
}
###<--------------------------------------------------------------
###<---   HTMLフッダー書き出し
###<--------------------------------------------------------------
sub footer { 
	if ( $FORM{'action'} eq 'view' || $FORM{'action'} eq '' || $FORM{'action'} eq 'move') {
		if ( $dlsw == 1 )	{
			print "<form action=\"$script\" method=\"$method\">\n";
			print "<input type=hidden name=\"year\" value=\"$year\">\n";
			print "<input type=hidden name=\"month\" value=\"$mon\">\n";
			print "<input type=hidden name=\"action\" value=\"download\">\n";
			print "<input type=submit value=\"表\示月の日記を保存\" $css_style>\n";
			print "<br><input type=checkbox name=all value=1><font size=2>全ての日記を保存\n";
			print "<br>拡張子はhtmに変更して下さい。</font>";
			print "</form>";
		}
		print "<br><br><br>\n";
	}
	#<<<　↓消さないで下さい
	print "<p align=right>\n";
	print "<font size=2><a href=http://tackysroom.com target=_blank>tackynotesp Ver0.723 Tacky\'sRoom</a></font></p>\n";
	print "</body></html>\n";
}
###<--------------------------------------------------------------
###<---   入力フォーム
###<--------------------------------------------------------------
sub forminput { 
	print "<blockquote><blockquote>\n";
	if ( $FORM{'proc'} eq "write" )	{
		print "<form action=$script method=POST enctype=\"multipart/form-data\">\n";
		print "<input type=hidden name=\"action\" value=\"regist\">\n";
		$c_pass = $FORM{'pass'} ;
	} else {
		print "<form action=$script method=POST enctype=\"multipart/form-data\">\n";
		print "<input type=hidden name=\"action\" value=\"update\">\n";
		print "<input type=hidden name=\"no\" value=\"$FORM{'no'}\">\n";
		print "<input type=hidden name=\"resno\" value=\"$c_resno\">\n";
		print "<input type=hidden name=\"proc\" value=\"edit\">\n";
		$yy = substr($targetdate,0,4);
		$mm = substr($targetdate,4,2);
		$dd = substr($targetdate,6,2);
		print "<input type=hidden name=\"year\" value=\"$yy\">\n";
		print "<input type=hidden name=\"month\" value=\"$mm\">\n";
		print "<input type=hidden name=\"day\" value=\"$dd\">\n";
	}

	print "<table border=0 cellspacing=0 cellpadding=0><tr><td bgcolor=#000000>\n";
	print "<table border=0 cellspacing=1 cellpadding=3>\n";
	if ( $FORM{'proc'} eq "write" )	{
		print "<tr><td colspan=2 bgcolor=\"$tbgcolor\"><select name=\"year\" $css_style>\n";
		for ( $i = $syear - 10 ; $i <= $syear + 10 ; $i++ )	{
			if ( ($FORM{'year'} eq '' && $i == $syear) || $i == $FORM{'year'} ) {
				print "<option value=$i selected>$i\n";
			} else {
				print "<option value=$i>$i\n";
			}
		}
		print "</select><font color=\"$ftextcolor\">&nbsp;年</font>\n";
		print "<select name=\"month\" $css_style>\n";
		for ( $i = 1 ; $i <= 12 ; $i++ ) {
			if ( ($FORM{'month'} eq '' && $i == $smonth) || $i == $FORM{'month'} ) {
				print "<option value=$i selected>$i\n";
			} else {
				print "<option value=$i>$i\n";
			}
		} 
		print "</select><font color=\"$ftextcolor\">&nbsp;月</font>\n";
		print "<select name=\"day\" $css_style>\n";
		for ( $i = 1 ; $i <= 31 ; $i++ ) {
			if ( $i == $sday ) {
				print "<option value=$i selected>$i\n";
			} else {
				print "<option value=$i>$i\n";
			}
		} 
		print "</select><font color=\"$ftextcolor\">&nbsp;日の日記を書きます。</font></td></tr>\n";
	} else {
		print "<tr><td align=\"center\" colspan=2 bgcolor=\"$tbgcolor\">\n";
		print "<font color=\"$ftextcolor\">$yy年$mm月$dd日の日記を修正します。</font></td></tr>\n";

	}
	if ( ( $FORM{'proc'} ne "write" && $c_resno ne '' ) || $minnade == 1 ) {
		print "<tr><td align=left nowrap bgcolor=\"$tbgcolor\">\n";
		print "<font color=\"$ftextcolor\">お名前</font></td>\n";
		print "<td bgcolor=\"$tbgcolor\"><input type=text name=name size=20 maxlength=40 value=\"$c_name\" $css_style></td></tr>\n";		
	}
	#背景色
	if ( $colb_use != 1 && $FORM{'action'} ne 'res' && $c_resno eq '') {
		print "<tr><td nowrap bgcolor=\"$tbgcolor\"><font color=\"$ftextcolor\">背景色</font></td>\n";
		print "<td bgcolor=\"$tbgcolor\">\n";
		foreach (0 .. $#COLORS_B) {
			if ( $c_colorb == $_ || ($c_colorb eq '' && $_ == 0)) {	$dmy = "checked"; } else { $dmy = "" ; }
			print "<input type=radio name=colorb value=\"$_\" $dmy>\n";
			print "<font color=$COLORS_B[$_]>■</font>\n";
		}
		print "</td></tr>\n";

	#タイトル文字色
	print "<tr><td nowrap bgcolor=\"$tbgcolor\"><font color=\"$ftextcolor\">タイトル色</font></td>\n";
	print "<td bgcolor=\"$tbgcolor\">\n";
	foreach (0 .. $#COLORS_F) {
		if ( $c_color == $_ || ($c_color eq '' && $_ == 0)) { $dmy = "checked"; } else { $dmy = "" ; }
		print "<input type=radio name=color value=\"$_\" $dmy>\n";
		print "<font color=$COLORS_F[$_]>■</font>\n";
	}
	print "</td></tr>\n";
	}
	#コメント文字色
	if ( $FORM{'proc'} eq "edit" && $c_resno ne '') {							#u020605
	print "<tr><td nowrap bgcolor=\"$tbgcolor\"><font color=\"$ftextcolor\">コメント色</font></td>\n";	#u020605
	print "<td bgcolor=\"$tbgcolor\">\n";									#u020605
	foreach (0 .. $#COLORS) {										#u020605
		if ( $c_color == $_ || ($c_color eq '' && $_ == 0)) {	$dmy = "checked"; } else { $dmy = "" ; }	#u020605
		print "<input type=radio name=color value=\"$_\" $dmy>\n";					#u020605
		print "<font color=$COLORS[$_]>■</font>\n";							#u020605
	}													#u020605
	}													#u020605
	else {													#u020605
	print "<tr><td nowrap bgcolor=\"$tbgcolor\"><font color=\"$ftextcolor\">コメント色</font></td>\n";
	print "<td bgcolor=\"$tbgcolor\">\n";
	foreach (0 .. $#COLORS_C) {
		if ( $c_colorc == $_ || ($c_colorc eq '' && $_ == 0)) {	$dmy = "checked"; } else { $dmy = "" ; }
		print "<input type=radio name=colorc value=\"$_\" $dmy>\n";
		print "<font color=$COLORS_C[$_]>■</font>\n";
	}
	}													#u020605
	print "</td></tr>\n";
	if ( ($FORM{'proc'} eq "write" || $FORM{'proc'} eq "edit") && $c_resno eq '')	{		#u020605
		if ( $titleflg == 1 ) {
			print "<tr><td align=left nowrap bgcolor=\"$tbgcolor\">\n";
			print "<font color=\"$ftextcolor\">タイトル</font></td>\n";
			print "<td bgcolor=\"$tbgcolor\"><input type=text name=title size=50 value=\"$c_title\" $css_style></td></tr>\n";
		}
		if ( $icon[0] ne '' ) {	
			print "<tr><td bgcolor=\"$tbgcolor\">\n";
			print "<font color=\"$ftextcolor\">カレンダーに表\示<br>するアイコン</font></td>\n";
			print "<td bgcolor=\"$tbgcolor\"><select name=\"icon\" $css_style>\n";	
			for ( 0..$#icon ) {
				if ( ( $c_ic eq '' && $_ == 0 ) || ( $c_ic && $_ == $c_ic ) ) { $dmy = "selected"; } else { $dmy =""; }	#u001114
				print "<option value=$_ $dmy>$iconnm[$_]\n";
			}
			print "</select>\n";
			print "</td></tr>\n";
		}
		#日記部にアイコン表示＆カレンダーアイコンとは異なるアイコンを表示する場合i001109
		if ( $disp_icon == 1 && $onaji == 0 ) {
			print "<tr><td align=left nowrap bgcolor=\"$tbgcolor\">\n";
			print "<font color=\"$ftextcolor\">日記に表\示するアイコン</font></td>\n";
			print "<td bgcolor=\"$tbgcolor\"><select name=\"icon2\" $css_style>\n";
			for ( 0..$#icon2 ) {
				if ( ( $c_ic2 eq '' && $_ == 0 ) || ( $c_ic2 && $_ == $c_ic2 ) ) { $dmy = "selected"; } else { $dmy =""; }	#u001114
				print "<option value=$_ $dmy>$iconnm2[$_]\n";
			}
			print "</select>\n";
			print "</td></tr>\n";
		}
	}
	print "<tr><td nowrap bgcolor=\"$tbgcolor\">\n";
	print "<font color=\"$ftextcolor\">メッセージ</font></td><td bgcolor=\"$tbgcolor\">\n";
	if ( $FORM{'proc'} ne "write" && $c_resno ne '' ) {
		if ( $res_text == 0 ) {
			print "<input name=\"comment\" size=$sz value=\"$c_comment\" $css_style>\n";
		} else {
			print "<textarea name=\"comment\" cols=$c_sz rows=$r_sz $css_style>$c_comment</textarea>\n";
		}
		print "</td></tr>\n";
	} else {
		print "<textarea name=\"comment\" cols=$col rows=$row $css_style>$c_comment</textarea></td></tr>\n";
	}
	if ( $FORM{'proc'} eq "write" )	{
		print "<tr><td nowrap bgcolor=\"$tbgcolor\">\n";
		print "<font color=\"$ftextcolor\">パスワード</font></td>\n";
		print "<td bgcolor=\"$tbgcolor\"><input type=password name=pass size=6 value=\"$c_pass\" $css_style></td></tr>\n";
	}	else	{
		print "<input type=hidden name=pass value=\"$FORM{'pass'}\">\n";
	}
	#■新規投稿時のみファイルアップロード可とする
	if ( $UpFolder && $FORM{'action'} ne 'view' && $c_resno eq '' ) {
		print "<tr><td bgcolor=\"$tbgcolor\">\n";
		print "アップロード</td>\n";
		print "<td bgcolor=\"$tbgcolor\">";
		print "<input type=file name=\"fileupload\" size=56 $css_style>\n";
		if ( $c_upload ) { 
			print "<br>▲現在【&nbsp;<b>$c_upload</b>&nbsp;】が設定されています。<br>そのままで良い場合は何も入力しないで下さい\n";	
			if ( $imgfile =~ /gif|jpg|png/i ) { print "<br><img src=\"$c_upload\">\n"; }
		}
		print "</td></tr>\n";
		print "<tr><td bgcolor=\"$tbgcolor\">&nbsp;</td><td bgcolor=\"$tbgcolor\">▲アップロードファイルは最大" . int($maxdatasz / 1024) . "kb迄ですのでご注意下さい。<br>\n";	
		print "幅：$MaxWidth" . "Pixel、高さ：$MaxHeightを超える場合は画像は縮小表\示されます<br>\n";
		print "▼アップロード可能\なファイル形式<br><font size=+1>【&nbsp;";
		foreach ( 0..$#FMT){
			if ( $_ == $#FMT ) {
				print $FMT[$_] ;
			} else {
				print $FMT[$_] . "&nbsp;,&nbsp;" ;
			}
		}
		print "&nbsp;】</font></td></tr>\n";
	}
	print "<tr><td nowrap bgcolor=\"$tbgcolor\">&nbsp;</td><td bgcolor=\"$tbgcolor\">\n";
	if ( $FORM{'proc'} eq "write" )	{ print "<input type=submit value=登録 $css_style>";
	} elsif ( $FORM{'proc'} eq "edit" ) { print "<input type=submit value=修正 $css_style>";
	} else { print "<input type=submit value=削除 $css_style>"; }
	print "&nbsp;&nbsp;&nbsp;<input type=reset value=クリア $css_style>\n";
	print "</td></tr></table>\n";
	print "</td></tr></table>\n";
	print "</form></blockquote></blockquote>\n";
}
###<--------------------------------------------------------------
###<---   ログ表示
###<--------------------------------------------------------------
sub view {
	&dataread ;									#ログ読み込み
	if ( $FORM{'no'} eq '' ) { print "<a name=1></a>\n"; }

	if ( $FORM{'action'} ne 'resdisp' ) {
		@SORTLOG = sort {							#u010515,u010618
		(split (/,/, $a, 2))[0] <=> (split (/,/, $b, 2))[0] ||
		(split (/,/, $a, 3))[1] <=> (split (/,/, $b, 3))[1]
		} @MAINLOG ;
		if ( $viewsort == 2 && $FORM{'action'} ne 'download' ) {		#昇順の場合	u001109
			@SORTLOG = reverse @SORTLOG ;
		}
	} else {
		@SORTLOG = @MAINLOG ;
	}

	print "<center>\n";
	$sw = 0 ;	$rcnt=1;
	if ( $FORM{'action'} eq 'resdisp') {
		if ( $FORM{'rflg'} == 1 ) { $dmy = "レス"; $dispcnt = $sinchaku ; } else { $dmy = "投稿"; $dispcnt = $sinchaku2 ;}
		print "<br>最新$dmyを&nbsp;$dispcnt件&nbsp;表\示しています<br>\n";
	}
	if ( $FORM{'action'} eq 'download' || $FORM{'action'} eq 'resdisp' ) { $sw = 1 ; }	#i001216
	else {
		print "$year年$mon月のスケジュールです<br>\n" ;
		print "<br><font size=2>\n";

		if ( $monthview eq 'week' ) {
			if ( $year != $syear || $mon != $smonth ) { $weekpoint = 1 ;}
			if ( $FORM{'week'} ne '' && $FORM{'week'} != 9 ) { $weekpoint = $FORM{'week'} ; }
			if ( $FORM{'week'} == 9 ) { $weekpoint = 9 ; }
			if ($showweekpoint) { $weekpoint = $showweekpoint;}
			for ( 1..$weekcnt ) {
				if ( $weekpoint != $_ ) {
					print "[<a href=$script?action=view&year=$year&month=$mon&week=$_>$_週目</a>]&nbsp;&nbsp;";
				} else {
					print "<b>$_週目</b>&nbsp;&nbsp;";
					$getweek = "$_週目" ;
				}
			}
			if ( $FORM{'week'} != 9 ) { 
				print "[<a href=$script?action=view&year=$year&month=$mon&week=9>１ヶ月分の日記</a>]&nbsp;&nbsp;";
			} else {
				print "<b>１ヶ月分</b>&nbsp;&nbsp;";
			}
			print "</font><br>\n";
		}
	}

	if ( $FORM{'week'} == 9 ) {
		$weekstart[$FORM{'week'}] = 1 ;
		$weekend[$FORM{'week'}] = 31 ;
	}

	$find = 0;										
	foreach $buf ( @SORTLOG ) {
		($targetdate,$no,$ic,$title,$resno,$name,$color,$colorb,$colorc,$comment,$regdate,$ps,$hst,$ic2,$imgfile) = split(/,/,$buf);	
		$yy = substr($targetdate,0,4);
		$mm = substr($targetdate,4,2);
		$dd = substr($targetdate,6,2);
		$imgfile =~ s/\n//g;
		if ( $FORM{'no'} == $no || $FORM{'all'} == 1 || $FORM{'action'} eq 'resdisp' || $FORM{'action'} eq 'find' ||
			 ($FORM{'action'} eq 'download' && $monthview eq 'no' && $yy == $year && $mm == $mon) ||	#i001109
			 ($monthview ne 'no' && $yy == $year && $mm == $mon) ||
			 ( $FORM{'no'} eq '' && $monthview ne 'yes' && $yy == $syear && $mm == $smonth && $dd == $sday ) ||
			 ( $FORM{'no'} ne '' && $zurazura == 1 && $yy == $year && $mm == $mon && $dd == $day ) ) {
			if ( $FORM{'no'} == $no || $FORM{'all'} == 1 || $FORM{'action'} eq 'resdisp' || $FORM{'action'} eq 'find' ) {
			} else {
				if ( $FORM{'week'} ne '' ) {
					if ( $dd >= $weekstart[$FORM{'week'}] && $dd <= $weekend[$FORM{'week'}] ) {
					} else { next ;	}
				} else {
					if ( $monthview eq 'week' && $kiero == 1 ) {			#u020220
							if ( $yy == $syear && $mm == $smonth ) { 
								if ( $dd >= $weekstart[$weekpoint] && $dd <= $weekend[$weekpoint] ) {
								} else { next ; }
							} else {
								if ( $dd >= $weekstart[1] && $dd <= $weekend[1] ) {
								} else { next ; }
							}
					}
				}
			}
			$find = 1;
			$title =~ s/&knm/\,/g;	$comment =~ s/&knm/\,/g;
			if ( $awaseru == 1 && $colb_use != 1 ) {
				$msg_celltxcolor2 = $COLORS_F[$color]  ;	#日付テーブル部文字色u020219
				$msg_cellbgcolor2 = $COLORS_B[$colorb] ;	#日付テーブル部背景色
			}
			if ( $colb_use != 1 ) {
				$colorf = $COLORS_F[$color] ;			#記事タイトル文字色u020219
				$colorb = $COLORS_B[$colorb] ;			#記事テーブル背景色
			} else {
				$colorf = $COLORS_F[0] ;			#記事タイトル文字色
				$colorb = $COLORS_B[0] ;			#記事テーブル背景色
			}
			if ( substr($mm,0,1) == 0 ) { $mm =~ s/0/ /; }
			$dd = substr($targetdate,6,2);
			if ( substr($dd,0,1) == 0 ) { $dd =~ s/0/ /; }
			if ( $sw == 0 && !($FORM{'all'}) ) {			#u001216 
				print "<hr size=1 noshade width=70% color=\"$bdcolor\">\n";
				$sw = 1 ;
			}
			print "<br><br>\n";
			if ( $FORM{'no'} == $no ) { print "<a name=1></a>\n"; }
			$wek = &week_get($yy,$mm);		#表示対応年月の１日の曜日を算出
			for ( $i = 1 ; $i < $dd ; $i++ ) {
				if ( $wek == 6 ) {
					$wek = 0 ;
				} else {
					$wek++ ;
				}
			}

			if ( $msg_bordercolor2 ) {
				print "<table width=$tbl_sz border=0 cellspacing=0 cellpadding=1>\n";
				print "<tr><td bgcolor=\"$msg_bordercolor2\">";
				$wid = "100%";
			} else {
				$wid = $tbl_sz ;
			}


			print "<table width=$wid border=0 cellspacing=0 cellpadding=3>\n";
			print "<tr><td bgcolor=\"$msg_cellbgcolor2\"><font color=\"$msg_celltxcolor2\">";

			#　$timedisp=1：「日記の日付：○」・「投稿日付：○」
			#　$timedisp=2：「日記の日付：○」・「投稿日付：×」
			#　$timedisp=3：「日記の日付：×」・「投稿日付：○」
			#　$timedisp=4：「日記の日付：×」・「投稿日付：×」

			print "<b>▼$yy年$mm月$dd日&nbsp;($week[$wek])</b>\n" if ( $timedisp == 1 || $timedisp == 2 ) ;
			print "&nbsp;&nbsp;--&nbsp;" if ( $timedisp == 1 || $timedisp == 2 ) ;
			print "投稿日：$regdate&nbsp;&nbsp;&nbsp;...\n" if ( $timedisp == 1 || $timedisp == 3 ) ;
			print "No.[$no]";
			print "</font>\n";
			print "</td></tr></table>\n";
			print "</td></tr></table>\n" if ( $simaru ) ;
			print "<img src=$spacer_gif height=$omakase width=1><br>\n";
			
			if ( $simaru ) {
				print "<table width=$tbl_sz border=0 cellspacing=0 cellpadding=1>\n";
				print "<tr><td bgcolor=\"$simaru\">";
			}
			print "<table width=$wid border=0 cellspacing=0 cellpadding=5 align=\"center\">\n";

			if ( $title || $minnade == 1 )	{
				print "<tr><td bgcolor=\"$colorb\">";
				print "<font color=\"$colorf\">\n";
				if ( $title ) {	print "<b>$title</b>\n" ;	}
				print "&nbsp;&nbsp;&nbsp;...($name)" if ( $minnade == 1 && $name ) ;
				print "</font></td></tr>\n";
			}
			
			print "<tr><td bgcolor=\"$colorb\">\n";

			print "<table width=100% border=0 cellspacing=0 cellpadding=8 align=\"center\">\n";
			$comment =~ s/([^=^\"]|^)(http|ftp)([\w|\!\#\&\=\-\%\@\~\;\+\:\.\?\/]+)/$1<a href=\"$2$3\">こちら<\/a>/g if ( $autolink == 1 ) ;
			print "<tr>";
			if ( $disp_icon == 1 && $FORM{'action'} ne 'download') 	{
				print "<td bgcolor=\"$msg_cellbgcolor\" width=20 nowrap>";
				#日記部にアイコン表示＆カレンダーアイコンと同じアイコンを表示する場合i001109
				if ( $onaji == 1 ) 	{
					if ( $icon_w != 0 ) { $w = " width=$icon_w" ; } else { $w = ""; }
					if ( $icon_h != 0 ) { $h = " height=$icon_h" ; } else { $h = ""; }
					if ( $icon[0] eq '' ) {
						if ( $img_gif )	{ print "<img src=\"$img_gif\" border=0 $w $h vspace=5 hspace=5></a>\n" ; }
					} else {
						print "<img src=\"$icon[$ic]\" border=0 $w $h vspace=5 hspace=5 alt=\"$iconnm[$ic]\"></a>\n" ;
					}
				} elsif ( $ic2 ne '' ) {						#u001114
					if ( $icon2_w[$ic2] != 0 ) { $w = " width=$icon2_w[$ic2]" ; } else { $w = ""; }
					if ( $icon2_h[$ic2] != 0 ) { $h = " height=$icon2_h[$ic2]" ; } else { $h = ""; }
					print "<img src=\"$icon2[$ic2]\" border=0 $w $h vspace=5 hspace=5 alt=\"$iconnm2[$ic2]\"></a>\n" ;
				}
				print "</td>\n";
			}
			print "<td bgcolor=\"$msg_cellbgcolor\">";
			print "<table width=100% border=0 cellspacing=0 cellpadding=0><tr><td>\n";

			#■画像表示
			if ( $imgfile && $FORM{'action'} ne 'download')	{
				if ( $maware == 0 ) {	
					if ( $point == 1 ) { $dmy = "align=left"; }
					elsif ( $point == 3 ) { $dmy = "align=right"; }
					else { $dmy = "align=center"; }
					print "<div $dmy>"; $dmy ="" ; 
				} else {
					if ( $point == 1 ) { $dmy = "align=left"; }
					elsif ( $point == 3 ) { $dmy = "align=right"; }
					else { $dmy = ""; }
				}
				if ( $imgfile =~ /gif|jpg|png/i ) {
					if ( $sizeflg == 1 ) {
						($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $uptime, $mtime, $ctime, $blksize, $blocks) = stat($imgfile);
						local ($file) = $imgfile =~ /([^\/]+)$/;
						$size = int ((-s "$UpFolder$file") / 1024);
						$size = 1 if ( $size == 0 ) ;
					}
					if ( $sizeflg == 1 ) { $dmy3 = "alt=($size" . "kb)" ; } else { $dmy3 = ""; }
					if ( $imgfile =~ /gif/i ) {
						($W,$H) = &GIFSizeGet("$UpFolder$imgfile") ;
					}
					if ( $imgfile =~ /jpg/i ) {
						($W,$H) = &JPGSizeGet("$UpFolder$imgfile") ;
					}
					if ( $imgfile =~ /png/i ) {
						($W,$H) = &PNGSizeGet("$UpFolder$imgfile") ;
					}
					# 画像表示縮小
					$WS = $W ; $HS = $H ;
					if ($W > $MaxWidth || $H > $MaxHeight) {
						$W2 = $MaxWidth / $W;	$H2 = $MaxHeight / $H;
						if ($W2 < $H2) { $sv = $W2; } else { $sv = $H2; }
						$W = int ($W * $sv); $H = int ($H * $sv);
					}

					if ( $imglink == 2 ) {
						print "<a href=\"$UpUrl$imgfile\" target=_blank>\n";
					}
					if ( $imglink == 1 ) {
						#エンコード
						$ec = $imgfile;
						$ec =~ s/(\W)/sprintf("%%%02X", unpack("C", $1))/eg;
						print "<A href=\"javascript:void(0)\" ";
print <<"EOM";
onclick='window.open("$script?action=imgdisp&img=$ec","IMG","width=$WS,height=$HS,$dmy3")'>
EOM
						print "<img src=\"$UpUrl$imgfile\" border=0 width=$W height=$H $dmy $dmy3>";
						print "</a>\n";
					} else {
						print "<img src=\"$UpUrl$imgfile\" border=0 width=$W height=$H $dmy $dmy3></a>\n";
					}
				} else {
					print "<a href=\"$UpUrl$imgfile\">$imgfile</a>\n";
				}
				if ( $sizeflg == 1 ) {
					($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $uptime, $mtime, $ctime, $blksize, $blocks) = stat($imgfile);
					local ($file) = $imgfile =~ /([^\/]+)$/;
					$size = int ((-s "$UpFolder$file") / 1024);
					$size = 1 if ( $size == 0 ) ;
					if ( $maware == 0 ) { print "<br><font color=\"$COLORS_C[$colorc]\" size=$mojisz>(&nbsp;$size" ."kb&nbsp;)</font><br><br>\n"; }	
				}
				if ( $maware == 1 || !($imgfile =~ /gif|jpg|png/i) ) { print "<font color=\"$COLORS_C[$colorc]\" size=$mojisz>$comment</font>"; }	
				if ( $maware == 0 ) { print "</div>\n"; }
				if ( $maware == 0 ) { print "<br>\n"; }
			}
			if ( $maware == 0 || !($imgfile && $FORM{'action'} ne 'download') ) { print "<font color=\"$COLORS_C[$colorc]\" size=$mojisz>$comment</font>"; }	

			print "</td></tr></table>\n";

			$cnt = 0 ;
			foreach $buf ( @RESLOG ) {
				($targetdate2,$no2,$ic,$title,$resno,$name,$color,$colorb2,$colorc2,$comment,$regdate,$pass,$hst,$ic2,$imgfile) = split(/,/,$buf);	
				if ( (substr($targetdate,0,6) == substr($targetdate2,0,6)) && ($no == $resno) )	{
					$title =~ s/&knm/\,/g;	$comment =~ s/&knm/\,/g;
					if ( $cnt == 0 ) {
						print "<br><hr size=1 color=\"$bdcolor2\" noshade>";
						print "<table border=0 cellpadding=1 width=90% align=right>\n";
					}
					print "<tr><td width=20% valign=top>\n";
					print "<font color=\"$COLORS[$color]\" size=$mojisz>■$name</font></td><td>";
					$comment =~ s/([^=^\"]|^)(http|ftp)([\w|\!\#\&\=\-\%\@\~\;\+\:\.\?\/]+)/$1<a href=\"$2$3\">こちら<\/a>/g if ( $autolink == 1 ) ;
					print "<font color=\"$COLORS[$color]\" size=$mojisz>$comment</font>\n";
					print "<div align=right><font color=\"$COLORS[$color]\" size=-1>..$regdate&nbsp;($no2)</font></div>";
					print "<hr size=1 color=\"$bdcolor2\" noshade>\n";
					print "</td></tr>\n";
					$cnt++ ;
				}
			}
			if ( $cnt != 0 ) { print "</table>\n"; }

			print "</td></tr></table>\n" if ( $simaru ) ;

			if ( $resflg == 1 && $FORM{'action'} ne 'download' ) { 				#u001216
				print "<tr><td bgcolor=\"$colorb\">\n";
				print "<form action=$script method=$method>\n";
				print "<input type=hidden name=\"action\" value=\"regist\">\n";
				print "<input type=hidden name=\"resno\" value=\"$no\">\n";
				print "<input type=hidden name=\"year\" value=\"$yy\">\n";
				print "<input type=hidden name=\"month\" value=\"$mm\">\n";
				print "<input type=hidden name=\"day\" value=\"$dd\">\n";
				print "<table cellpadding=0 cellspacing=0 border=0>\n";
				print "<tr><td nowrap><font color=\"$colorf\" size=$mojisz>■名前&nbsp;&nbsp;&nbsp;&nbsp;</font></td>\n";
				print "<td><input type=text name=\"name\" size=10 value=\"$COOKIE{'nm'}\" $css_style></td>\n";
				print "<td nowrap>&nbsp;&nbsp;&nbsp;<font color=\"$colorf\" size=$mojisz>■文字色&nbsp;</font></td>\n";
				print "<td><SELECT name=\"color\" $css_style>\n";
				for ( $j = 0 ; $j <= $#COLORSNM ; $j++ ) {
					$wk = $j + 1 ;
					if ( $COOKIE{'cl'} == $j ) { $dmy = "selected" } else { $dmy = "" ; }
					print "<OPTION value=$j $dmy>$wk-$COLORSNM[$j]\n";
				}
				print "</SELECT></td>\n";
				print "<td nowrap>&nbsp;&nbsp;&nbsp;<font color=\"$colorf\" size=$mojisz>■パスワード&nbsp;</font></td>\n";
				print "<td><input type=password name=\"pass\" size=6 value=\"$COOKIE{'ps'}\" $css_style></td>\n";
				print "</tr></table>";
				print "<table cellpadding=0 cellspacing=0 border=0>\n";
				print "<tr><td nowrap><font color=\"$colorf\" size=$mojisz>■コメント&nbsp;</font></td>\n";
				print "<td>\n";
				if ( $res_text == 0 ) {
					print "<input type=text name=\"comment\" size=\"$sz\" $css_style>\n";
				} else {
					print "<textarea name=\"comment\" cols=\"$c_sz\" rows=\"$r_sz\" $css_style></textarea>\n";
				}
				print "</td><td>&nbsp;&nbsp;<input type=submit value=\"$resword\" $css_style></td></tr>\n";
				print "</table>\n";
				print "</td></tr></form>\n";
			}
			print "</td></tr></table>\n";
			print "</td></tr>\n";

			print "</table>\n";
			print "</td></tr></table>\n" ;

			$rcnt++ ;
			if ( $FORM{'action'} eq 'resdisp' && $rcnt > $dispcnt ) { last ; }
		}
	}
	if ( $find == 0 && ($FORM{'action'} eq 'view' || $FORM{'action'} eq 'move')) {
		if ( substr($mon,0,1) == 0 ) { $mon =~ s/0/ /; }
		if ($getweek) { $dmy = $getweek; } else { $dmy = ""; }
		print "<br><br><br>$year年$mon月$dmyは未定です<br>\n";	#i001105
		$sw == 1 ;
	}
	print "<br><hr size=1 noshade width=70% color=\"$bdcolor\">\n";
}
###<-------------------------------------------------------------
###<---   カレンダー表示部
###<--------------------------------------------------------------
sub calender { 
		#春分・秋分の日算出
		local($haru,$aki);
		$haru = "03" . int(20.8431 + 0.242194 * ($year - 1980) - int(($year - 1980) / 4));
		push(@holiday,$haru);
		$aki = "09" . int(23.248 + 0.242194 * ($year - 1980) - int(($year - 1980) / 4));
		push(@holiday,$aki);

		&dataread ;				#ログ読み込み
		print "<center>\n";
		$sday2 = &week_get($year,$mon);		#表示対象年月の１日の曜日を算出
		if ( substr($mon,0,1) == 0 )	{
			$wmon = $mon ;	$wmon =~ s/0/ /;
		} else { $wmon = $mon ;	}

		print "<table border=0 cellspacing=0 cellpadding=0><tr>\n";

		#▼年月移動部分
		print "<form action=\"$script\" method=\"$method\">\n";
		print "<td align=center>\n";
		print "<input type=hidden name=\"action\" value=\"move\">\n";
		print "<select name=\"ym\" $css_style>\n";
		for ( $i = $syear - $setyear_b ; $i <= $syear + $setyear_a ; $i++ )	{
			for ( $j = 1 ; $j <= 12 ; $j++ )	{
				$j = sprintf("%02d",$j);
				if ( $i == $year && $j == $mon ) { print "<option value=$i$j selected>$i年$j月\n"; }
				else { print "<option value=$i$j>$i年$j月\n"; }
			}
		} 
		print "</select>\n";
		print "<input type=hidden name=\"action\" value=\"move\">\n";
		print "<input type=submit value=\"を\表\示\" $css_style>\n";
		print "</td></form></tr>\n";

		if ( $kiero == 1 ) {

			print "<tr><td align=center>&nbsp;<br><table border=0 cellspacing=0 cellpadding=1 bgcolor=\"$calbordercolor\">\n";
			print "<tr><td>\n";
			print "<table border=0 cellpadding=2 cellspacing=1>\n";

			print "<tr>\n";
			for ($j = 0 ; $j < 7 ; $j++ ) {
				if ($j == 0) { $color_youbi = $color_sun; }
				elsif ($j == 6) { $color_youbi = $color_sat; }
				else { $color_youbi = $color_nml; }
				print "<td bgcolor=\"$calyoubicolor\" width=$calsize height=$calsize align=\"center\"><font color=\"$color_youbi\">$week[$j]</font></td>\n";		
			}
			print "</tr>\n";

			#カレンダーを表示
			$j = 0 ; #曜日＝日曜日
			$editsw = 0 ;
			$cnt_monday = 0 ;
			$weekcnt = 0 ;
			for ( $i = 1; $i <= $cdays[$mon] ;){
				if ( $sday2 == 0 || $j == 0) {
					print "<tr>\n";	$weekcnt++; 
					$weekstart[$weekcnt] = $i ;	#週の初日を退避
				}
				if ( $j >= $sday2 || $editsw == 1) {	#$sday2=対象月１日の曜日
					$editsw = 1 ;
					$ii = sprintf("%02d",$i);	$v = "$mon$ii";		$k = 0;		$hol = 0 ;
					foreach ( @holiday ) {
						if ( $v == $holiday[$k] ) {
							if ( $year >= 2000 && ( $v == '0115' || $v == '1010' ) ) {
							} else { $hol = 1 ; }
							last ;
						}
						$k++;
					}
					#成人の日算出
					if ( $year >= 2000 && $mon == 1 && $sday2 == 1 ) {	#１月で「月曜日」の場合
						 $cnt_monday++ ;		 if ( $cnt_monday == 2 ) {	$hol = 1 ; }
					}
					#体育の日算出
					if ( $year >= 2000 && $mon == 10 && $sday2 == 1 ) {	#１月で「月曜日」の場合
						 $cnt_monday++ ;		 if ( $cnt_monday == 2 ) { $hol = 1 ; }
					}
					#海の日・敬老の日算出
					if ( $year >= 2003 && ($mon == 7 || $mon == 9) && $sday2 == 1 ) {	#７月第三月曜日（海の日）・９月第三月曜日（敬老の日）
						 $cnt_monday++ ;
						 if ( $cnt_monday == 3 ) {	$hol = 1 ; }
					}
					#「日」
					if ( $syear == $year && $smonth == $mon && $sday == $i ) { $bg = "bgcolor=\"$color_today\"";	$weekpoint = $weekcnt ; }
					else { $bg = "bgcolor=\"$calcolor\""; }
					if ( $monthview eq 'week' && $syear == $year && $smonth == $mon) {
						$day = sprintf("%02d",$FORM{'day'});
						if ($day == $i) { $showweekpoint = $weekcnt ; }
						}
					print "<td $bg width=$calsize height=$calsize valign=\"top\" align=\"right\">";

					if ( $set_font ) { 
						$fontdmy = "face=$set_font";
					} else {
						$fontdmy = "";
					}
					if ( $hol == 1 || $sday2 == 0 || $svhol == 1)	{
						if ( $hol == 1 || $svhol == 1 ) { print "<font color=\"$color_hol\" $fontdmy>";	}
						else { print "<font color=\"$color_sun\" $fontdmy>"; }
					} else {
						if ( $sday2 == 6 )	{
							print "<font color=\"$color_sat\" $fontdmy>";
						} else {
							print "<font color=\"$color_nml\" $fontdmy>";
						}
					}
#					if ( $sw == 1 ) {
#						print "<a href=$script?action=view&mem=1&year=$yy&month=$mm&day=$dd&yy2=$year target=\"right\">$i</a>";
#					} else {
						print "$i";
#					}
					print "</font>\n";

					#祝日で日曜日の場合、翌日が振替祝日の為、退避
					if ( $hol == 1 && $sday2 == 0 ) { $svhol = 1 ; } else { $svhol = 0 ; }

					#日記帳ログを検索
					$set = 0 ;
					foreach $buf ( @MAINLOG ) {
						($targetdate,$no,$ic,$title,$resno,$name,$color,$colorb,$colorc,$comment,$regdate,$pass,$hst,$ic2,$imgfile) = split(/,/,$buf);		
						$yy = substr($targetdate,0,4);
						$mm = substr($targetdate,4,2);
						$dd = substr($targetdate,6,2);
						if ( $year == $yy && $mon == $mm && $ii == $dd && ( $zurazura == 0 || ( $zurazura == 1 && $set == 0 ) ) )	{
							$set = 1 ;
							if ( $monthview eq 'week' ) { $dmy = "&week=$weekcnt"; }
							else { $dmy = "";}
							print "<br><a href=$script?action=view\&year=$yy&month=$mm$dmy&day=$dd&no=$no#1>\n";
							if ( $icon_w != 0 ) { $w = " width=$icon_w" ; } else { $w = ""; }
							if ( $icon_h != 0 ) { $h = " height=$icon_h" ; } else { $h = ""; }
							if ( $icon[0] eq '' ) {
								if ( $img_gif )	{
									print "<img src=\"$img_gif\" border=0 $w $h></a>\n" ;
								} else {
									print "■</a>\n" ;
								}
							} else {
								print "<img src=\"$icon[$ic]\" border=0 $w $h></a>\n" ;
							}
						}
					}
					print "</td>\n";
					$sday2++;
					if ( $sday2 == 7 || $i == $cdays[$mon])	{
						if ( $i == $cdays[$mon] ) {
							for ( ; $sday2 < 7 ; $sday2++ )	{
								print "<td bgcolor=\"$calcolor\" width=$calsize height=$calsize valign=\"top\" align=\"center\">&nbsp;</td>\n";
							}
						}
						print "</tr>\n";
						$weekend[$weekcnt] = $i ;	#週の最終日を退避
						$sday2 = 0 ;
					}
					$i++;	$j=99;
				}	else	{
					print "<td bgcolor=\"$calcolor\" width=$calsize height=$calsize valign=\"top\" align=\"center\">&nbsp;</td>\n";
					$j++;
				}
			}
			print "</table>\n";
			print "</td></tr></table>\n";

			print "</td></tr>\n";
		}
		print "<tr><td align=center>\n";

		#前月・次月スクロールボタン
		print "<form action=\"$script\" method=\"$method\">\n";
		print "<table border=0 cellpadding=3 cellspacing=0><tr>\n";
		print "<td nowrap align=center>\n";
		print "<input type=hidden name=\"action\" value=\"move\">\n";
		if ( $mon == 1 ) { $wmon1 = 12 ; $wyear1 = $year - 1 ;	} else { $wmon1 = $mon - 1 ; $wyear1 = $year ;	}			
		print "<input type=hidden name=\"year\" value=\"$wyear1\">\n";
		print "<input type=hidden name=\"month\" value=\"$wmon1\">\n";
		if ( $back_gif )	{
			print "<input type=image name=year src=\"$back_gif\" border=0 alt=\"前の月へ戻る\">\n";
		} else {
			print "<input type=submit value=\"←\">\n";
		}
		print "</td></form>\n";
		print "<td nowrap width=10>&nbsp;</td>\n";
		print "<form action=\"$script\" method=\"$method\">\n";
		print "<td nowrap>\n";
		print "<input type=hidden name=\"action\" value=\"move\">\n";
		if ( $mon == 12 ) { $wmon2 = 1 ; $wyear2 = $year + 1 ;	} else { $wmon2 = $mon + 1 ; $wyear2 = $year ;	}
		print "<input type=hidden name=\"year\" value=\"$wyear2\">\n";
		print "<input type=hidden name=\"month\" value=\"$wmon2\">\n";
		if ( $next_gif ) {
			print "<input type=image name=year src=\"$next_gif\" border=0 alt=\"次の月へ進む\">\n";
		} else {
			print "<input type=submit value=\"→\">\n";
		}
		print "</td></form></tr></table><br>\n";
		print "</td></tr></table><br>\n";
		print "</center>\n";

}
###<--------------------------------------------------------------
###<---   ログ出力
###<--------------------------------------------------------------
sub regist {

	# ホスト名を取得
	$host = $ENV{'REMOTE_HOST'};
	$addr = $ENV{'REMOTE_ADDR'};
	if ($host eq "" || $host eq "$addr") {
		($p1,$p2,$p3,$p4) = split(/\./,$addr);
		$temp = pack("C4",$p1,$p2,$p3,$p4);
		$host = gethostbyaddr("$temp", 2);
		if ($host eq "") { $host = $addr; }
	}
	#掲示板荒らし対策
	foreach $buf(@DANGER_LIST){
		if ( $buf ) {
			# パターンマッチを変換
			$buf=~ s/\./\\./g;		$buf=~ s/\?/\./g;		$buf=~ s/\*/\.\*/g;
			if($host =~ /$buf/gi){
				&error("\申\し\訳ありません。<br>あなたのプロバイダーからは投稿できませんでした． ");
			}
		}
	}
	if ( $Maxword ne '' && (length($FORM{'comment'}) > $Maxword)) { &error("メッセージは$Maxword文字までしか登録出来ません。");}
	if ( $FORM{'resno'} ne '' && $FORM{'name'} eq "") { &error("お名前を入力して下さい。"); }
	if ( $FORM{'comment'} eq "") { &error("メッセージは省略出来ません。"); }

	&filelock ;		#ファイルロック
	&dataread ;									#ログ読み込み
	($targetdate,$delno,$ic,$title,$resno,$name,$color,$colorb,$colorc,$comment,$ps,$regdate,$hst,$ic2,$imgfile) = split(/,/,$LOG[0]);		
	if ( $name eq $FORM{'name'} && $comment eq $FORM{'comment'} ) {
		&fileunlock ;	&error("二重投稿は禁止しています。") ;
	}
	$dcnt = @LOG;
	$imonth = sprintf("%02d",$FORM{'month'});
	$iday = sprintf("%02d",$FORM{'day'});
	if ( $dcnt < 1 ) {
		$no = 1;									#１件目
	} else {
		($dummy,$no,$dummy) = split(/,/,$LOG[0]);					#最新記事No取得
		$no++;
	}

	# ファイル添付処理
	$ImgFile = "";
	if($upfname =~ /http/gi) {
		$ImgFile = $upfname ;
	} else {
		if ($upfname) { &fileupload; }
	}
	# パスワードの暗号化（crypt関数使用））
	if ($FORM{'pass'} ne "") { &pass_enc($FORM{'pass'}); }
	else { $pass = '' ; }
	unshift(@LOG,"$FORM{'year'}$imonth$iday,$no,$FORM{'icon'},$FORM{'title'},$FORM{'resno'},$FORM{'name'},$FORM{'color'},$FORM{'colorb'},$FORM{'colorc'},$FORM{'comment'},$sysdate,$pass,$host,$FORM{'icon2'},$ImgFile\n");			
	if ( !(open(OUT,">$logfile")))	{ &fileunlock ;	&error("ログファイル($logfile)のオープンに失敗しました"); }
	print OUT @LOG;
	close(OUT);
	if ( $newsw == 1 ) { 
		chmod(0666,"$logfile");		# パーミッション変更
	}
	#▼Sendmail使用＆レス記事のみ
	if ( $sendmail && $FORM{'resno'} ) { &SMail ; }
	
	&cookieset ;			#COOKIE設定
	&fileunlock ;			#ファイルロック解除

	if ( $FORM{'resno'} ) { $rno = $FORM{'resno'} ; } else { $rno = $no ; }
	if ( $FORM{'resno'} eq '' ) {
		&header ;							#<<<htmlヘッダー出力
		print "<br><br><center>\n";
		print "<font size=+2>正常に登録されました。</font><br><br><br>\n";
		print "[<a href=$script?action=view\&year=$FORM{'year'}&month=$imonth&day=$iday&no=$rno#1>投稿内容を確認する</a>]\n\n";
		print "<br><br><br><br><br>\n";
	} else {
		if ( $damedame == 0 ) {
			if ( $FORM{'resno'} ) { $rno = $FORM{'resno'} ; } else { $rno = $no ; } 
			print "Location: $script?action=view\&year=$FORM{'year'}&month=$imonth&day=$iday&no=$rno#1\n\n";
		} else {
			print "Content-type: text/html\n\n";
			print "<html><head><META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=";
			print "$script?action=view\&year=$FORM{'year'}&month=$imonth&day=$iday&no=$rno#1\"></head><body></body></html>\n\n";
		}
	}
	exit;	

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

	&dataread ;									#ログ読み込み
	$found = 0 ;
	foreach $buf ( @LOG ) {
		($targetdate,$n,$ic,$title,$resno,$name,$color,$colorb,$colorc,$comment,$regdate,$pass,$hst,$ic2,$imgfile) = split(/,/,$buf);	
		if ( $FORM{'no'} eq $n ) {
			if ($FORM{'pass'} ne $password && (&pass_dec($pass))) { &error("パスワードが違います。"); }
			$found = 1 ;
			if ( $FORM{'proc'} eq "delete" ) {
				$FORM{'year'} = substr($targetdate,0,4);
				$FORM{'month'} = substr($targetdate,4,2);
				&update ;
				exit;
			}
			&header ;
			$title =~ s/&knm/\,/g;	$comment =~ s/&knm/\,/g;
			$c_ic = $ic ; $c_ic2 = $ic2 ;	$c_title = $title ;	
			$c_name = $name ;	$c_color = $color ;	$c_colorb=$colorb ; $c_colorc=$colorc ;$c_resno = $resno ; $c_pass = $FORM{'pass'} ;		
			$c_comment = $comment ;			$c_comment =~ s/\<br\>/\n/g;
			local ($img) = $imgfile =~ /([^\/]+)$/;
			$img = $UpFolder .$img;			
			if($img) { $c_upload = $img ; }
			&forminput ;
			last;
		}
	}
	if ( $found == 0 ) { &error("該当する記事Noのデータは存在していません。"); }
	exit;
}

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

	if ( $FORM{'action'} eq 'edit' && $FORM{'comment'} eq "")	{
		&error("メッセージは省略出来ません。");
	}
	$imonth = sprintf("%02d",$FORM{'month'});
	$iday = sprintf("%02d",$FORM{'day'});

	&filelock ;								#ファイルロック
	&dataread ;								#ログ読み込み
	@new = ();
	foreach ( @LOG ) {
		($targetdate,$n,$ic,$title,$resno,$name,$color,$colorb,$colorc,$comment,$regdate,$pass,$hst,$ic2,$imgfile) = split(/,/,$_);	
		if ( $FORM{'no'} eq $n)	{					#<<<メンテ対象者の場合
			if ($FORM{'pass'} ne $password && (&pass_dec($pass))) {
				&fileunlock ;	#ファイルロック解除
				&error("パスワードが違います。"); 
			}
			$no=$n;
			$imgfile =~ s/\n//;
			#■アップロードファイルの削除
			local ($img) = $imgfile =~ /([^\/]+)$/;	
			$img = $UpFolder .$img;					
			if ( ($upfname || $FORM{'proc'} eq 'delete') && $img !~ /http/gi && $img && (-e $img)) { unlink($img); }
			if ( $FORM{'proc'} eq "edit" ) {
	            # ファイル添付処理
            			$ImgFile = "";
				if($upfname =~ /http/gi) {
					$ImgFile = $FORM{'fileupload'} ;
				} elsif ($upfname) { &fileupload; }
				else { $ImgFile = $imgfile ; }
				push(@new,"$FORM{'year'}$imonth$iday,$n,$FORM{'icon'},$FORM{'title'},$resno,$FORM{'name'},$FORM{'color'},$FORM{'colorb'},$FORM{'colorc'},$FORM{'comment'},$regdate,$pass,$hst,$FORM{'icon2'},$ImgFile\n");	
			}
		} else {
			push(@new,"$_"); 					#<<<そのまま出力
		}
	}
	if ( !(open(OUT,">$logfile")))	{ &fileunlock ;	&error("ログファイル($logfile)のオープンに失敗しました"); }
	print OUT @new;	
	close(OUT);

	&cookieset ;					#COOKIE設定
	&fileunlock ;					#ファイルロック解除
	&header ;								#<<<htmlヘッダー出力
	print "<br><br><center>\n";
	if ( $FORM{'proc'} eq "edit" ) {
		print "<font size=+2>正常に更新されました。</font><br><br><br>\n";
		print "[<a href=$script?action=move\&year=$FORM{'year'}&month=$imonth&day=$iday&no=999>修正内容を確認する</a>]\n\n";
	} else {
		print "<font size=+2>正常に削除されました。</font><br><br><br>\n";
		print "[<a href=$script?action=move\&year=$FORM{'year'}&month=$imonth&day=$iday&no=999>戻る</a>]\n\n";
	}
	print "<br><br><br><br><br>\n";
	exit ;
}
###<--------------------------------------------------------------
###<---   曜日算定
###<--------------------------------------------------------------
sub week_get {
	$ydat = $_[0] - $cyear;					#現在年〜1989年の年差
	$udat = $ydat /4;					#上記の年差／４
	$days = $cday * $ydat +$udat;				#365*年差+閏年の年回数=1989〜前年迄の日数が求まる
	$days2 = 0;
	if ($_[1] >= 2){
		if (($_[0] % 4) == 0){
			if (($_[0] %100) != 0){
				$cdays[2] = 29;
			}elsif (($_[0] % 400) == 0){
				$cdays[2] = 29;
			}
		}
	}
	for ($i = 1; $i < $_[1] ;$i++){				#１月〜対象月前月迄の日数を求める
		$days2 += $cdays[$i];
	}
	$days += $days2;
	$youbi = $days % 7;					#対象月１日の曜日が求まる

	return $youbi ;
}
###<--------------------------------------------------------------
###<---   エラー処理
###<--------------------------------------------------------------
sub error {
	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>$titlename</title>\n";
	print "</head>\n";
	$wk = "bgcolor=\"$bgcolor\"";
	$wk2 = "background=\"$backpicture\"";
	print "<body $wk $wk2>\n";
	print "$_[0]";
	exit;
}
###<--------------------------------------------------------------
###<---   Information(アイコン一覧)
###<--------------------------------------------------------------
sub icondisp {
	&header ;				#<<<htmlヘッダー出力
	print "<center>\n";
print <<"EOM";
<br>
<hr size=1 noshade color=$bdcolor width=700>
<table border=0 cellpadding=7 width=700>
<tr>
<td valign=top>■使い方</td>
<td>
No及びパスワードを入力すると投稿記事の修正・削除が出来ます。<br>
EOM
		if ( $minnade == 0 ) {
			print "「日記を書く」は管理人のみの機能\となります。</font>\n";
		} else {
			print "この日記はみんなで書く事が可能\です。";
		}
print <<"EOM";
<hr size=1 noshade color=$bdcolor>
</td>
</tr>
EOM

if ($findsw == 1) {
print <<"EOM";
<tr>
<td nowrap width=20% valign=top>■検索方法</td>
<td valign=top>
検索は「名前」・「タイトル」・「メッセージ」に対して行います。
検索キーワードを「半角スペース」で区切ると複数検索が可能\です(OR検索)
<hr size=1 noshade color=$bdcolor>
</td>
</tr>
EOM
}

print <<"EOM";
<tr>
<td nowrap width=20% valign=top>■メッセージの文字数</td>
<td valign=top>
メッセージ欄に記入出来る文字数は【$Maxword文字】です。※全角の場合はその半分。
<hr size=1 noshade color=$bdcolor>
</td>
</tr>
EOM

if ($dlsw == 1) {
print <<"EOM";
<tr>
<td nowrap width=20% valign=top>■ログのダウンロード</td>
<td valign=top>
Windowsのみです。Macをお使いの方はご利用頂けません。
通常は表\示されている年月の情報をダウンロードしますが、
【全ての日記を保存】にチェックする事により全ての日記を
ダウンロード出来ます。※画像はダウンロードされません。
<hr size=1 noshade color=$bdcolor>
</td>
</tr>
EOM
}

print <<"EOM";
<tr>
<td valign=top>■アイコン </td>
<td valign=top>
EOM
	if ( $kiero == 1 && $icon[0] ne '') {
		print "▼カレンダーアイコン<br>\n";
		print "<table cellpadding=5 cellspacing=0 border=0>\n";
		$i = 0 ; $j = 0 ;
		while ( 1 ) {
			print "<tr>\n";
			for ( $ln = 1 ; $j <= $#icon && $ln <= $icon_line ; ) {
				print "<td align=\"center\"><img src=\"$icon[$j]\" border=0></td>\n";
				print "<td align=\"center\" nowrap>$iconnm[$j]</td>\n";
				$j++ ; $ln++ ;
			}
			if ( $j > $#icon ) { 
				if ( $ln < $icon_line ) {
					for ( ; $ln <= $icon_line ; ) {
						print "<td align=\"center\">&nbsp;</td>\n";
						print "<td align=\"center\">&nbsp;</td>\n";
						$ln++ ;
					}
				}
				print "</tr>\n";
				last ;
			}
			print "</tr>\n";
			$i++;
		}
		print "</table>\n";
	}
	if ( $disp_icon == 1 && $onaji == 0 && $icon2[0] ne '' )	{
		print "<br>▼日記のアイコン<br>\n";
		print "<table cellpadding=5 cellspacing=0 border=0>\n";
		$i = 0 ; $j = 0 ;
		while ( 1 ) {
			print "<tr>\n";
			for ( $ln = 1 ; $j <= $#icon2 && $ln <= $icon_line ; ) {
				print "<td align=\"center\"><img src=\"$icon2[$j]\" border=0></td>\n";
				print "<td align=\"center\" nowrap>$iconnm2[$j]</td>\n";
				$j++ ; $ln++ ;
			}
			if ( $j > $#icon2 ) { 
				if ( $ln < $icon_line ) {
					for ( ; $ln <= $icon_line ; ) {
						print "<td align=\"center\">&nbsp;</td>\n";
						print "<td align=\"center\">&nbsp;</td>\n";
						$ln++ ;
					}
				}
				print "</tr>\n";
				last ;
			}
			print "</tr>\n";
			$i++;
		}
		print "</table>\n";
	}
	print "</td></tr></table>\n";
	print "<hr size=1 noshade color=$bdcolor width=700></center><br><br>";
	exit;
}
###<--------------------------------------------------------------
###<---   ファイルロック設定
###<--------------------------------------------------------------
sub filelock {
	if (-e $lockfile) {
		($ftm) = (stat($lockfile))[9];
		if ($ftm < time - 150) { unlink($lockfile); }
	}
	foreach (1 .. 5) {
		if (-e $lockfile) { sleep(1); }
		else {
			open(LOCK,">$lockfile");
			close(LOCK);
			return;
		}
	}
	&error("只今他の方が書き込み中です。ブラウザの「戻る」で戻って再度登録を行って下さい。"); 
}
###<--------------------------------------------------------------
###<---   ファイルロック解除
###<--------------------------------------------------------------
sub fileunlock {
	if (-e $lockfile) { unlink($lockfile); }
}
###<-------------------------------------------------------------
###<---   クッキー取得
###<--------------------------------------------------------------
sub cookieget	{
	$cookies = $ENV{'HTTP_COOKIE'};
	@pairs = split(/;/,$cookies);
	foreach $pair (@pairs) {
		($name, $value) = split(/=/, $pair);
		$name =~ s/ //g;
		$DUMMY{$name} = $value;
	}
	@pairs = split(/,/,$DUMMY{'tackynotesp'});
	foreach $pair (@pairs) {
		($name, $value) = split(/\!/, $pair);
		$COOKIE{$name} = $value;
	}
	$c_name = $COOKIE{'nm'} ;
	$c_color = $COOKIE{'cl'} ;
	$c_colorb = $COOKIE{'cb'} ;
	$c_colorc = $COOKIE{'cc'} ;
	$c_pass = $COOKIE{'ps'} ;
}
###<-------------------------------------------------------------
###<---   クッキー設定
###<--------------------------------------------------------------
sub cookieset { 
	($secg,$ming,$hourg,$mdayg,$mong,$yearg,$wdayg,$ydayg,$isdstg) = gmtime(time + 30*24*60*60);
	$yearg  += 1900 ;
	if ($secg  < 10)  { $secg  = "0$secg";  }
	if ($ming  < 10)  { $ming  = "0$ming";  }
	if ($hourg < 10)  { $hourg = "0$hourg"; }
	if ($mdayg < 10)  { $mdayg = "0$mdayg"; }
	$mong = ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec')[$mong];
	$youbi = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')[$wdayg];
	$date_gmt = "$youbi, $mdayg\-$mong\-$yearg $hourg:$ming:$secg GMT";
	$cook="nm\!$FORM{'name'},cl\!$FORM{'color'},cb\!$FORM{'colorb'},cc\!$FORM{'colorc'},ps\!$FORM{'pass'}";		
	print "Set-Cookie: tackynotesp=$cook; expires=$date_gmt\n";
}
###<-------------------------------------------------------------
###<---   パスワード暗号化
###<--------------------------------------------------------------
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 download {
    print "Content-type: text/download\n\n";
    print "<html><head><title>$titlename</title></head>";
	$wk = "bgcolor=\"$bgcolor\"";
	print "<body $wk text=$tcolor link=$linkcolor vlink=$vlinkcolor alink=$alinkcolor>\n";
	&view ; 
	print "</body></html>\n";
    exit;
}
###<--------------------------------------------------------------
###<---   SendMail
###<--------------------------------------------------------------
sub SMail {
	$mailbuf = "";
	$cv_ttl = $titlename;
	if ( $hiho == 1 ) {
	   	&jcode'convert(*cv_ttl,'euc');
		open(MAIL,"| $sendmail -s \"$cv_ttl\" -f $smail_address $smail_address ") || &error("Sendmail Error!!");
	} else {
	   	&jcode'convert(*ttl,'jis');
		open(MAIL,"| $sendmail -t") || &error("Sendmail Error!!");
		$mailbuf = "To: $smail_address\n";
		$mailbuf .= "From: $smail_address\n";
		$mailbuf .= "Subject: $cv_ttl\n";
		$mailbuf .= "Content-Transfer-Encoding: 7bit\n";
		$mailbuf .= "Content-type: text/plain\n";
		$mailbuf .= "\n\n";
	}
	$mailbuf .= "============================================================\n";
	$mailbuf .= "■---『$titlename』に返信がありました\n";
	$mailbuf .= "============================================================\n";
	$mailbuf .= "▼投稿日時：\n";
	$mailbuf .= "$sysdate\n\n";
	$mailbuf .= "▼返信のあった日記の日付\n";
	$mailbuf .= "$FORM{'year'}年$imonth月$iday日分\n\n";
	$mailbuf .= "▼お名前\n";
	$mailbuf .= "$FORM{'name'}\n\n";
	$mailbuf .= "▼パスワード\n";
	$mailbuf .= "$FORM{'pass'}\n\n";
	$mailbuf .= "▼コメント\n";
	$mailbuf .= "$FORM{'comment'}\n\n";
	$mailbuf .= "▼リモートホスト\n";
	$mailbuf .= "$host\n\n";
	$mailbuf .= "============================================================\n";
	#漢字コードＪＩＳ変換＆改行コードLF変換。
	$mailbuf =~ s/\r\n/\n/g;		$mailbuf =~ s/\r/\n/g;	$mailbuf =~ s/<br>/\n/g;
	$mailbuf =~ s/&amp;/&/g;	$mailbuf =~ s/&quot;/"/g;
	$mailbuf =~ s/&lt;/</g;	$mailbuf =~ s/&gt;/>/g;
   	&jcode'convert(*mailbuf,'jis');
	print MAIL $mailbuf ;
	close(MAIL);
}
###<--------------------------------------------------------------
###<---   画像アップロード処理
###<--------------------------------------------------------------
sub fileupload {
	if ( $UpFolder eq '' ) { $ImgFile = "" ; return ; }

	$upfname =~ s/\,/，/g;
	$ImgFile = $UpFolder . $upfname ;

	if ( -e $ImgFile ) { &error("同じファイル名のファイルが既に存在しています。"); }

	$ok=0;	
	$type =$upfname;
	$type =~ s/\r//g;	$type =~ s/\n//g;

	foreach $buf(@FMT){
		if ( $buf ) {
			if($type =~ /$buf/i){ $ok=1; $type = ".$buf"; }
		}
	}
	if ($ok == 0 ) { &fileunlock ; &error("このファイル形式はアップロード出来ません。"); }

	# マックバイナリ対策
	if ($mac) {
		$len = substr($FORM{'fileupload'},83,4);	$len = unpack("%N",$length);
		$FORM{'fileupload'} = substr($FORM{'fileupload'},128,$len);
	}
	# 添付データを書き込み
	if ( !(open(OUT,">$ImgFile"))) { &fileunlock ; &error("画像のアップロードに失敗しました"); }
	binmode(OUT);
	binmode(STDOUT);
	print OUT $FORM{'fileupload'};
	close(OUT);
	chmod (0666,$ImgFile);
	$ImgFile = $upfname;
}
###<--------------------------------------------------------------
###<---   GIF画像サイズ取得
###<--------------------------------------------------------------
sub GIFSizeGet {
	open(GIF,$_[0]) || return (0,0);
	seek(GIF,6,0);
	read(GIF,$size,4);
	close(GIF);
	return ( unpack("v",substr($size,0,2)) , unpack("v",substr($size,2,2)) ) ;
}
###<--------------------------------------------------------------
###<---   PNG画像サイズ取得
###<--------------------------------------------------------------
sub PNGSizeGet {
	open(PNG,$_[0]) || return (0,0);
	binmode(PNG);
	seek(PNG,16,0);
	read(PNG,$size,8);
	close(PNG);
	return ( hex(unpack("H*",substr($size,0,4))) , hex(unpack("H*",substr($size,4,4))) ) ;
}
###<--------------------------------------------------------------
###<---   JPG画像サイズ取得
###<--------------------------------------------------------------
sub JPGSizeGet {
	open(JPG, $_[0]) || return (0,0);
	binmode JPG;
	read(JPG,$t,2);
	while (1) {
		read(JPG,$size,4);
		($a, $b, $c) = unpack("a a n", $size);
		if ($a ne "\xFF") { $W = $H = 0; last; }
		elsif ((ord($b) >= 0xC0) && (ord($b) <= 0xC3)) {
			read(JPG, $size, 5);
			($H, $W) = unpack("xnn", $size);	last;
		} else {read(JPG, $size, ($c - 2));}
	}
	close(JPG);
	return ($W, $H);
}

