1 | | #!/usr/local/bin/perl |
2 | | ################################################### |
3 | | #cntdwn.cgi カウントダウンプログラム |
4 | | # 2003.07.14 MARCO |
5 | | # edit 2003.07.15 MARCO |
6 | | # |
7 | | # パーミッション |
8 | | # cntdwn.cgi(755) |
9 | | # $file(666) |
10 | | ################################################### |
11 | | |
12 | | ############ 設定項目 ############## |
13 | | #ファイル名(パーミッションを666で設定) |
14 | | $file='cntdwn.txt'; |
15 | | #ページ背景色 |
16 | | $page_bgcolor='#003311'; |
17 | | #文字色 |
18 | | $text_color1='#aabbbb'; |
19 | | #文字色(強調) |
20 | | $text_color2='#ffaaaa'; |
21 | | #管理キー |
22 | | $masterkey='password'; |
23 | | ###################################### |
24 | | |
25 | | @dmax=(31,28,31,30,31,30,31,31,30,31,30,31); |
26 | | #今日の日付を獲得 |
27 | | ($sec,$min,$hour,$dd,$mm,$yy,$wd)=localtime(); |
28 | | $yy =1900; |
29 | | $mm ; |
30 | | #1900年から今日までの日数を算出 |
31 | | $py=$yy; |
32 | | $pm=$mm; |
33 | | $pd=$dd; |
34 | | culcdays(); |
35 | | $nowdays=$days; |
36 | | |
37 | | #入力データを獲得 |
38 | | use CGI; |
39 | | $query=new CGI; |
40 | | $iy=$query->param('YY'); |
41 | | $im=$query->param('MM'); |
42 | | $id=$query->param('DD'); |
43 | | $ttl=$query->param('TITLE'); |
44 | | $sts=$query->param("status"); |
45 | | $ilno=$query->param("IDX"); |
46 | | $ikey=$query->param("key"); |
47 | | |
48 | | #書き込み |
49 | | if($sts eq 'INS' && $iy !=0 && $im !=0 && $id !=0){ |
50 | | open(NOTE,">>$file"); |
51 | | print NOTE "$ilno\t$iy\t$im\t$id\t$ttl\t$ikey\n"; |
52 | | close(NOTE); |
53 | | } |
54 | | #削除 |
55 | | if($sts eq 'DEL'){ |
56 | | open(NOTE,"<$file"); |
57 | | @DATA=<NOTE>; |
58 | | close(NOTE); |
59 | | $i=0; |
60 | | $match=0; |
61 | | foreach(@DATA){ |
62 | | ($lno,$yy,$mm,$dd,$title,$key)=split(/\t/,$_); |
63 | | chomp($key); |
64 | | if($ilno==$lno && ($ikey eq $key || $ikey eq $masterkey)){ |
65 | | splice(@DATA,$i,1); |
66 | | $match=1; |
67 | | } |
68 | | $i ; |
69 | | } |
70 | | if($match==1){ |
71 | | open(NOTE,">$file"); |
72 | | print NOTE @DATA; |
73 | | close(NOTE); |
74 | | } |
75 | | } |
76 | | |
77 | | #HTML作成 |
78 | | print "Content-type: text/html\n\n"; |
79 | | print "<HTML>\n<HEAD>\n"; |
80 | | print "<TITLE>Count Down</TITLE>\n"; |
81 | | print "</HEAD>\n<BODY bgcolor=$page_bgcolor text=$text_color1>\n"; |
82 | | |
83 | | #ファイルを読み込んで出力 |
84 | | open(NOTE,"<$file"); |
85 | | @DATA=<NOTE>; |
86 | | close(NOTE); |
87 | | $lineno=1; |
88 | | foreach(@DATA){ |
89 | | ($lno,$yy,$mm,$dd,$title,$key)=split(/\t/,$_); |
90 | | #1900年からターゲット日までの日数を算出 |
91 | | $py=$yy; |
92 | | $pm=$mm; |
93 | | $pd=$dd; |
94 | | culcdays(); |
95 | | $targetdays=$days; |
96 | | $restdays=$targetdays-$nowdays; |
97 | | if($restdays>=0){ |
98 | | print "<font size=6>$title</font><br>"; |
99 | | print "<font size=2>($yy年$mm月$dd日)</font>"; |
100 | | print "<font size=4>まで<br>あと </font>"; |
101 | | print "<font size=8 color=$text_color2><b>$restdays</b></font>"; |
102 | | print "<font size=4> 日</font><br>\n"; |
103 | | print "<FORM ACTION=cntdwn.cgi METHOD=post>\n"; |
104 | | print "<input type=hidden name=IDX value=$lno>\n"; |
105 | | print "<input type=hidden name=status value=DEL>\n"; |
106 | | print " Key:<input type=password name=key size=8>\n"; |
107 | | print "<input type=submit value=削除><hr></FORM>\n"; |
108 | | } |
109 | | if($lno>=$lineno){$lineno=$lno 1;} |
110 | | } |
111 | | |
112 | | #入力フォームの表示 |
113 | | print "<FORM ACTION=cntdwn.cgi METHOD=post>\n"; |
114 | | print "■入力<br>"; |
115 | | print "<font size=2>西暦<input type=text name=YY size=4 value=$iy>年\n"; |
116 | | print "<input type=text name=MM size=2 value=$im>月\n"; |
117 | | print "<input type=text name=DD size=2 value=$id>日<br>\n"; |
118 | | print "タイトル<input type=text name=TITLE size=20><br>\n"; |
119 | | print "管理キー<input type=password name=key size=8></font>\n"; |
120 | | print "<input type=hidden name=IDX value=$lineno>\n"; |
121 | | print "<input type=hidden name=status value=INS>\n"; |
122 | | print "<input type=submit value=送信></FORM>\n"; |
123 | | |
124 | | print "</BODY>\n</HTML>\n"; |
125 | | exit; |
126 | | |
127 | | #1900年からの日数の計算 |
128 | | sub culcdays{ |
129 | | $days=$pd; |
130 | | for($i=$pm-1;$i>0;$i--){ |
131 | | if($i==2){ |
132 | | if(isleep($py)==1){$days =29;} |
133 | | else{$days =28;} |
134 | | } |
135 | | else{ |
136 | | $days =$dmax[$i-1]; |
137 | | } |
138 | | } |
139 | | for($i=$py-1;$i>1900;$i--){ |
140 | | if(isleep($i)==1){$days =366;} |
141 | | else{$days =365;} |
142 | | } |
143 | | } |
144 | | #閏年の判定 |
145 | | sub isleep{ |
146 | | my($y)=@_; |
147 | | if(($y%4==0 && $y0!=0) || $y@0==0){ |
148 | | return 1; |
149 | | } |
150 | | else{ |
151 | | return 0; |
152 | | } |
153 | | } |