#! c:/perl/bin/perl # # evcal.cgi # イベントカレンダー # # 1.007 : 9/25/06 : テンポラリファイルが残るバグを修正 # 1.006 : 9/19/05 : 更新リンクを更新者にするオプションを追加 # その際のURLの自動リンク機能を追加 # 1.005 : 8/29/05 : デコードを修正 # 1.004 : 8/25/05 : cryptを修正 # 1.003 : 8/22/05 : 更新者欄の幅を変更できるオプションを追加 # 1.002 : 8/12/05 : データファイルが無い時のエラー処理を追加 # 1.001 : 8/9/05 : SSIモード追加 # 1.0 : 8/8/05 : 一般公開のために大幅改良 # # $Id: evcal.cgi,v 1.30 2005/09/25 02:37:03 Hideki Kanayama Exp $ # use File::Basename; use Time::Local; use strict; use CGI::Carp qw(fatalsToBrowser); use CGI qw(:cgi-lib); my $lastupdatedyear = 2005; my $version = "1.007"; my $script = basename($0); my $setupfile = "evcal_setup.pl"; my $admindat = "adminpwd.dat"; ##################################### # データファイル名 our $datafile = "eventcal.dat"; # lockfile our $lockfile = "lockfile.dat"; # 戻りリンク 1:on 0:off our $backlink_en = 1; our $backlink = "../evcal.html"; our $backlink_name = '【戻る】'; # バックグラウンド our $bgimage_en = 0; our $bgcolor = 'white'; our $bgimage_file = ''; # カレンダーの色 # ヘッダの背景 our $table_head_bgcolor = 'white'; # ヘッダの文字 our $table_head_color = 'black'; # 更新者の色 our $post_name_color = 'black'; # 更新日の色 our $post_update_color = 'black'; # 平日の背景 our $weekday_bgcolor = 'white'; # 土曜日の背景 our $sat_bgcolor = '#ccffff'; # 日曜日の背景 our $sun_bgcolor = '#ffcccc'; # 日付、内容の文字色はスタイルシートのリンク色の設定で行ってください。 # 日付はclass=daylink, コメントはclass=comlinkとなっています。 # 更新リンク 0:内容 1:更新者 our $update_link = 0; # 更新者を内容更新のリンクに設定した場合はスタイルシートで色の設定を # 行ってください。class=namelinkとなっています。 # その場合の内容の色 our $post_com_color = 'black'; # 本文中のリンクを文字列に置き換える 1:on 0:off # この機能をONにするには更新リンクを更新者に設定してください。 our $link_replace_en = 1; our $link_replace = 'リンクはこちら'; our $link_replace_top_en = 0; # 表の幅 our $body_width = 100; # 更新者欄の幅 our $name_width = 10; # 表示する月数 our $disp_length = 12; our $disp_length_other = ''; # タイトル our %title = ( display => { text => 'イベントカレンダー', image => '', color => 'black', size => '+1', face => '', style => '', sel => 0, # 0:デフォルト、1:テキスト、2:ロゴ、3:スタイルシート loc => 1, # 0:左、1:中、2:右 }, register => { text => 'のイベント登録', image => '', color => 'black', size => '+1', face => '', style => '', sel => 0, # 0:デフォルト、1:テキスト、2:ロゴ、3:スタイルシート loc => 1, # 0:左、1:中、2:右 }, modify => { text => 'のイベントの変更', image => '', color => 'black', size => '+1', face => '', style => '', sel => 0, # 0:デフォルト、1:テキスト、2:ロゴ、3:スタイルシート loc => 1, # 0:左、1:中、2:右 }, setadminpwd => { text => '管理人用パスワードを設定してください。', sel => 4, }, setup => { text => '管理人セットアップ', sel => 4, }, ); # ジャンプリンク 1:on 0:off our $jumplink_en = 1; our $jumplink_name = '【「今日」へジャンプ】'; # セットアップリンク 1:on 0:off our $setup_en = 1; our $setup_name = '【管理用】'; #スタイルシート 1:on 0:off our $style_sheet_en = 1; our $style_sheet = ' A:link {text-decoration: none} A:visited {text-decoration: none} A:active {text-decoration: none} '; #
〜内に挿入できる構文 1:on, 0:off our $head_insert_en = 0; our $head_insert = ''; #使い方 our $usage_en = 1; our $usage_name = '【使い方】'; our $usage = '| 日付 | \n"; print "内容 | \n"; print "更新者 | \n"; print "更新日 | \n"; print "|
|---|---|---|---|---|
| "; if ($in{mode} eq 'past'){ print "$mon月$day日 | \n"; } else { print "$mon月$day日\n"; } print "$weekday[$wday]"; print " | \n"; my $j; for ($j=0;$j<=$#comment;$j++){ chomp($comment[$j]); next if ($comment[$j] eq ''); print ""; if ($comment[$j] ne ' ' && $in{mode} ne 'past') { if ($update_link == 0){ print "$comment[$j]"; } else { $comment[$j] = &link_replace($comment[$j]); print "$comment[$j]"; } } else { $comment[$j] = &link_replace($comment[$j]); print "$comment[$j]"; } print " | \n"; print ""; if ($update_link == 0){ print "$name[$j]\n"; } else { print "$name[$j]"; } print " | \n"; my $updatedate; $updatedate = &calupdate($update[$j]); print "$updatedate | \n"; print "
| \n";
}
sub htmltail {
print " $script Ver. $version \n";
print "Copyright(C) 1997-$lastupdatedyear, Hideki \n";
print " |
パスワード \n";
} else {
print "イベントが更新された日は、$newestです。 \n";
}
}
sub inputform {
my $now = shift;
my $n;
my $nn;
my ($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst)=gmtime($now);
print " \n";
}
sub usage {
if ($usage_en == 1){
print <
HTMLOUT
&htmltail;
}
sub evwrite {
&error('名前とパスワードは必ず入力してください。') if ($in{name} eq '' || $in{pwd} eq '');
&lockfile;
my ($id) = &getevdata(-lastid);
$id++;
my $pwd = &makecrypt($in{pwd});
my $now = time+$offset*3600;
open WR, ">> $datafile" or &error("データファイル$datafileが開けません。");
print WR "$id,$in{year},$in{month},$in{day},$in{name},$now,$pwd,$host,$ip,$in{comment}\n";
close WR;
&unlockfile;
print "Location: $script#${in{year}}_${in{month}}_$in{day}\n\n";
}
sub evreplace {
&error('名前とパスワードは必ず入力してください。') if ($in{name} eq '' || $in{pwd} eq '');
&lockfile;
my $now = time+$offset*3600;
my ($dyear,$dmonth,$dday,$dname,$dnow,$dpwd,$dhost,$dip,$dcomment);
my $id;
open DATA, "< $datafile" or &error("データファイル$datafileが開けません。");
open WR, "> tmp.$$" or &error("テンポラリファイルが開けません。");
while (){
chomp;
($id,$dyear,$dmonth,$dday,$dname,$dnow,$dpwd,$dhost,$dip,$dcomment) = split /,/;
chomp;
if ($id == $in{id}){
if (!checkcrypt($in{pwd}, $dpwd)){
close(WR);
&error('パスワードが違います。');
}
print WR "$in{id},$in{year},$in{month},$in{day},$in{name},$now,$dpwd,$host,$ip,$in{comment}\n";
} else {
print WR "$id,$dyear,$dmonth,$dday,$dname,$dnow,$dpwd,$dhost,$dip,$dcomment\n";
}
}
close WR;
close DATA;
rename("tmp.$$","$datafile");
&unlockfile;
print "Location: $script#${in{year}}_${in{month}}_${in{day}}\n\n";
}
sub calupdate {
my $now = shift;
return $now if ($now eq ' ');
my ($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst)=gmtime($now);
$mon++;
$year += 1900;
my $update = "$mon/$day/$year";
return $update;
}
sub getevdata {
# options
# -lastid : Return the last id in the data file
# -latest : Return the latest update information in the data file
# -alldta : Retrun hash reference for all registered contents in the data file
# (default)
my @options = @_;
my %caldata;
my %calname;
my %caldate;
my %calid;
my $id;
my ($dyear,$dmonth,$dday,$dname,$dnow,$dpwd,$dcomment);
my $host;
my $ip;
my $data_day;
my $latest;
my ($lid,$lyear,$lmonth,$lday,$lname,$lnow);
my @pastyear;
if (open DATA, "< $datafile"){
while (){
chomp;
($id,$dyear,$dmonth,$dday,$dname,$dnow,$dpwd,$host,$ip,$dcomment) = split /,/;
if (grep /-alldata/, @options or $#options == -1) {
$data_day = timegm(0,0,0,$dday,--$dmonth,$dyear);
if ($data_day < $start_day || $in{mode} eq 'past') {
push @pastyear, $dyear if (! grep /$dyear/, @pastyear);
}
next if ($data_day < $start_day or $data_day > $end_day);
$dmonth++;
if (exists $caldata{$dyear}{$dmonth}{$dday}) {
next if ($dcomment eq '');
$caldata{$dyear}{$dmonth}{$dday} .= "
\n";
my ($nsec,$nmin,$nhour,$nday,$nmon,$nyear,$nwday,$nyday,$nisdst)=gmtime($now);
my $start_table_date = timegm(0,0,0,1,$nmon,$nyear);
my $dmonth_n = $dmonth - 1 if ($dmonth != 0);
$dday = 1 if ($dday eq '');
my $last_written_date = timegm(0,0,0,$dday,$dmonth_n,$dyear);
if ($last_written_date < $start_table_date){
print "イベントが更新された日は、$newestです。
\n"; } sub monthdaycheck { my ($year,$month,$day) = @_; my @monthdays = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); my $md = $monthdays[$month]; ++$md unless $month != 1 or $year % 4 or !($year % 400); $month++; &error("日付が適切ではありません。$month月$day日") if $day > $md or $day < 1; } sub setup { my $subname = 'setup'; &setadminpwd if ($in{pwd} eq ''); &error('管理用パスワードが違います。') unless &checkadmin($in{pwd}); &htmlhead($title{$subname}{text}); my %check; $check{backlink}[$backlink_en] = "checked"; $check{bgimage}[$bgimage_en] = "checked"; $check{title}{display}{sel}[$title{display}{sel}] = "checked"; $check{title}{display}{loc}[$title{display}{loc}] = "checked"; $check{title}{register}{sel}[$title{register}{sel}] = "checked"; $check{title}{register}{loc}[$title{register}{loc}] = "checked"; $check{title}{modify}{sel}[$title{modify}{sel}] = "checked"; $check{title}{modify}{loc}[$title{modify}{loc}] = "checked"; $check{style_sheet}[$style_sheet_en] = "checked"; $check{head_insert}[$head_insert_en] = "checked"; $check{usage}[$usage_en] = "checked"; $check{jumplink}[$jumplink_en] = "checked"; $check{setup}[$setup_en] = "checked"; $check{disp_length}[$disp_length] = "checked"; $check{disp_length}[13] = "checked" if (!grep /checked/, $check{disp_length}[1,3,6,12]); $check{body_insert1}[$body_insert1_en] = "checked"; $check{body_insert2}[$body_insert2_en] = "checked"; $check{body_insert3}[$body_insert3_en] = "checked"; $check{body_insert4}[$body_insert4_en] = "checked"; $check{body_insert5}[$body_insert5_en] = "checked"; $check{body_insert6}[$body_insert6_en] = "checked"; $check{update_link}[$update_link] = "checked"; $check{link_replace_en}[$link_replace_en] = "checked"; $check{link_replace_top_en}[$link_replace_top_en] = "checked"; print "
"; &htmltail; } sub setupwrite { $in{title_display_size} =~ s/ /+/; $in{title_register_size} =~ s/ /+/; $in{title_modify_size} =~ s/ /+/; foreach (keys(%in)){ $in{$_} =~ s/