;
close(DATA);
########分岐############################
if($FORM{'action'} eq "pass") {
if ($FORM{'pass'} eq $pass) {&edit_html;}
else {&error(bad_pass);}
}
elsif($FORM{'action'} eq "resist") {
if ($FORM{'write'} eq "書き直し"){&edit2; &edit_html;}
else {&resist; &edit_html;}
}
elsif($FORM{'action'} eq "edit") {&del; &edit; &edit_html;}
elsif($FORM{'action'} eq "pagemain"){ &main_html;}
elsif($FORM{'action'} eq "pageedit$pass"){ &edit_html;}
elsif($FORM{'action'} eq "search") {&search;}
else {&main_html;}
########################################################
#メイン表示部
########################################################
sub main_html {
$pagemode = "pagemain";
&header;
print "++ HOME ++\n";
# カウンタ処理
if ($counter) { &counter; }
print "\n";
if ($title_gif eq '') {
print "
$title\n";
}
else {
print "

\n";
}
print "
\n";
&listview;
print "\n";
print "
\n";
&footer;
}
########################################################
#編集表示部
########################################################
sub edit_html {
if ($checkdel == 1 && $checkedit == 1){&error("bad_edit");}
$pagemode = "pageedit";
if ($mode eq "edit"){
$num3 = $num2;
$date3 = $date2;
$subject3 = $subject2;
$comment3 = $comment2;
$weather3 = $weather2;
$resist = "書き直し";
}
else{
$date3 = $date_now;
$subject3 = "";
$comment3 = "";
$weather3 = -1;
$resist = "書き込み";
}
&header;
print "\n";
if ($title_gif eq '') {
print "
$title\n";
}
else {
print "

\n";
}
print "
\n";
print "\n";
if($mode ne "edit") { &listview;}
&footer;
}
########################################################
#ログ表示
########################################################
sub listview {
$count = @DATA;
if ($pagemode eq "pageedit"){
print "
\n"; }
if ($temp < $count || ($temp - $pagemax) > 0){
print "\n";
}
#表示件数
if($kensu eq "on"){
$less = $temp - $pagemax + 1;
$most = $temp;
if ($most >= $count){ $most = $count; }
print "$less件〜$most件/$count件
\n";
}
}
########################################################
#ヘッダー
########################################################
sub header {
print "\n\n";
print "\n";
print "$title\n";
print "\n";
print "$style\n";
print "\n";
print "\n";
}
########################################################
#
########################################################
sub footer {
print "\n";
print "
\n";
exit;
}
########################################################
#書き込み
########################################################
sub resist {
if($FORM{'date'} eq "" || $FORM{'subject'} eq "" || $FORM{'comment'} eq ""){
if ($FORM{'date'} eq ""){$bad_write[0] = 1;}
if ($FORM{'subject'} eq ""){$bad_write[1] = 1;}
if ($FORM{'comment'} eq ""){$bad_write[2] = 1;}
if ($FORM{'weather'} eq "noicon"){$bad_write[3] = 1;}
&error(bad_write);
}
$count = @DATA;
$FORM{'comment'} =~ s/\r/
/g;
$value = "$count\,$FORM{'date'}\,$FORM{'subject'}\,$FORM{'comment'}\,$FORM{'weather'}\,\n";
$value =~ s///ig;
unshift(@DATA,$value);
#最大保存数を越えたら削除し、順番をそろえる。
if ($count > ($max * 1.2)){
splice(@DATA,$max,$count);
$count = @DATA - 1;
foreach $line(@DATA) {
($num,$date,$subject,$comment,$weather,$d2) = split(/\,/,$line);
$value = "$count\,$date\,$subject\,$comment\,$weather\,\n";
$line = $value;
$count--;
}
}
#### 書き込み
if (!open (DATA,">$logfile")) { &error(bad_file); }
print DATA @DATA;
close(NOTE);
}
########################################################
#削除
########################################################
sub del{
$count = @DATA;
$checkdel = 1;
#削除
for ($j = 0; $j <= $count; $j++){
$i = 0;
foreach $line(@DATA) {
($num,$date,$subject,$comment,$weather,$d2) = split(/\,/,$line);
if ($FORM{"del$num"} eq "on"){
splice(@DATA,$i,1);
$checkdel = 0;
#編集のために編集対象の番号を直す。
if($FORM{'edit'} > $num){
$FORM{'edit'} = $FORM{'edit'} - 1;
}
last;
}
$i++;
}
}
#削除チェックボックスにチェックされていたら・・・
if($checkdel == 0){
$count = @DATA - 1;
foreach $line(@DATA) {
($num,$date,$subject,$comment,$weather,$d2) = split(/\,/,$line);
$value = "$count\,$date\,$subject\,$comment\,$weather\,\n";
$line = $value;
$count--;
}
####書き込み######
if (!open (DATA,">$logfile")) { &error(bad_file); }
print DATA @DATA;
close(NOTE);
}
}
########################################################
#編集
########################################################
sub edit{
$count = @DATA;
$checkedit = 1;
$i = 0;
@DATA = reverse(@DATA);
foreach $line(@DATA) {
($num,$date,$subject,$comment,$weather,$d2) = split(/\,/,$line);
if ($FORM{'edit'} eq "$num"){
($num2,$date2,$subject2,$comment2,$weather2,$d22) = split(/\,/,$DATA[$i]);
$mode ="edit";
$checkedit = 0;
$comment2 =~ s/
/\r/g;
last;
}
$i++;
}
@DATA = reverse(@DATA);
}
########################################################
#編集2
########################################################
sub edit2{
if($FORM{'date'} eq "" || $FORM{'subject'} eq "" || $FORM{'comment'} eq ""){
if ($FORM{'date'} eq ""){$bad_write[0] = 1;}
if ($FORM{'subject'} eq ""){$bad_write[1] = 1;}
if ($FORM{'comment'} eq ""){$bad_write[2] = 1;}
if ($FORM{'weather'} eq "noicon"){$bad_write[3] = 1;}
&error(bad_write);
}
$i = 0;
$FORM{'comment'} =~ s/\r/
/g;
foreach $line (@DATA) {
($num,$date,$subject,$comment,$weather,$d2) = split(/\,/,$line);
if ($FORM{'editnum'} eq "$num"){
$value = "$num\,$FORM{'date'}\,$FORM{'subject'}\,$FORM{'comment'}\,$FORM{'weather'}\,\n";
$value =~ s///ig;
$line = $value;
}
}
####書き込み######
if (!open (DATA,">$logfile")) { &error(bad_file); }
print DATA @DATA;
close(NOTE);
}
########################################################
#エラー
########################################################
sub error {
$error = $_[0];
if ($error eq "bad_pass") {
$msg[0] = "パスワードが違います。";
}
if ($error eq "bad_file") {
$msg[0] = "ファイルがオープンできません。";
$msg[1] = "ログ保存ファイル、『$logfile』 がないか、ファイルが開けません。";
}
if ($error eq "bad_edit") {
$msg[0] = "編集・削除対象の記事がチェックされてません。";
$msg[1] = "編集・削除したい記事のチェックボックスにチェックを入れてください。";
}
if ($error eq "bad_write"){
if($bad_write[0] == 1) { $msg[0] = "日付が入力されていません。";}
if($bad_write[1] == 1) { $msg[1] = "題名が入力されていません。";}
if($bad_write[2] == 1) { $msg[2] = "コメントが入力されていません。";}
if($bad_write[3] == 1) { $msg[3] = "お天気アイコンが選択されていません。";}
}
&header;
print "\n";
print "
error
\n";
foreach $errormsg(@msg) {
print "
$errormsg
\n";
}
print "
++ BACK ++
\n";
print "
\n";
&footer;
}
## --- カウンタ処理
sub counter {
# 閲覧時のみカウントアップ
$match=0;
if ($FORM{'mode'} eq '') {
# カウンタロック
if ($lockkey) { &lock3; }
$match=1;
}
# カウントファイルを読みこみ
open(NO,"$cntfile") || &error("Can't open $cntfile",'0');
$cnt = ;
close(NO);
# カウントアップ
if ($match) { $cnt++; }
# 更新
open(OUT,">$cntfile") || &error("Write Error : $cntfile");
print OUT $cnt;
close(OUT);
# カウンタロック解除
if (-e $cntlock) { unlink($cntlock); }
# 桁数調整
while(length($cnt) < $mini_fig) { $cnt = '0' . "$cnt"; }
@cnts = split(//,$cnt);
print "\n";
# GIFカウンタ表示
if ($counter == 2) {
foreach (0 .. $#cnts) {
print " ";
}
# テキストカウンタ表示
} else {
print "$cnt";
}
print " |
\n";
}