Free CGI Perl PHP Script Olive Design CGI

万年カレンダー

ツェラーの公式を利用した万年カレンダー

ファイル名calender.cgiを作成し、下のソースを貼り付けてパーミションを755にします。

サンプル

ソース calender.cgi

#!/usr/bin/perl

#本日のバックカラー
$today_color  = '#FFC3CE';
#それ以外のバックカラー
$day_bgcolor = '#ffffff';
#数字のフォントカラー
$font_color = 'black';
#土曜日のフォントカラー
$sat_color = '#0000FF';
#日曜日、祝日のフォントカラー
$sun_color  = '#FF0000';
#現在時間取得
&time;
#月始めの曜日所得
&wday_no;
#月最後の日所得
&lastday;
#カレンダー表示
&html;

sub html{
print <<"HTML";
Content-type: text/html


<html>
<head>
<title>カレンダー</title>
<meta http-equiv="Content-Type" 
content="text/html; charset=Shift_JIS"> </head> <body bgcolor="#FFFFFF" text="#000000"> <table border="1" height="200" width="180"> <tr> <td colspan="7"> <div align="center"> $year年$mon月</div> </td> </tr> <tr> HTML foreach $i(@week){ if ($i eq $week[0]){ $color = $sun_color;} elsif ($i eq $week[6]){ $color = $sat_color;} else { $color = $font_color; } print "<td align=center><font color=$color>
$i</font></td>\n"; } print "</tr>\n"; foreach (1..42){ ++$c; if ($c == 7 ){$c = 0;} if (($c < $wday_no +1) && ($start_flag == 0)
|| ($a == $lastday)){ $day_count = ' '; $bgcolor = $day_bgcolor; } else { $day_count = ++$a; $start_flag = 1; } if (($start_flag == 1)&&($c == 2)){++$flag ;} if (($c == 1) && ($flag > 2) &&
( $day_count eq ' ')){last;} $bgcolor = $day_bgcolor; $color = $font_color; if ($c == 1 ) { $color = $sun_color; $bgcolor = $day_bgcolor; } if ($c == 2 ) { $bgcolor = $day_bgcolor; $color = $font_color; } if (($c == 2) && ($next_flag==1)){ $color = $sun_color; $next_flag = 0; } if ($c == 7 ) { $color = $sat_color; $bgcolor = $day_bgcolor; } if ($a == $day){ if ($c == 7 ){ $bgcolor = $today_color; } elsif ($c == 1 ) { $bgcolor = $today_color; } elsif ($c == 2 ) { $bgcolor = $today_color; } else{ $bgcolor = $today_color; } } if ($c == 1) {print "<tr>\n";} print "<td bgcolor=$bgcolor align=center><font
color=$color>$day_count</font></td>\n"; if ($c == 7 ) {print "</tr>\n";} } print <<"HTML"; </table> </body></html> HTML exit; } #月最後の日所得 sub lastday{ $lastday = (31,28,31,30,31,30,31,31,30,31,30,31) [$mon-1] + ($mon == 2 && (($year % 4 == 0 && $year % 100 != 0) || $year % 400 == 0)) ; } #現在時間所得 sub time{ ($sec,$min ,$hour,$day,$mon,$year,$wday) = localtime(time); @week = ('日','月','火','水','木','金','土'); $week = $weekday[$wday]; $mon++; $year = 1900 + $year; } #ツェラーの公式を利用、毎月1日の曜日所得 sub wday_no { if ($mon == 1 || $mon == 2) { $year--; $mon += 12; } $wday_no=int ($year + int ($year/4) - int ($year/100) + int ($year/400) + int(2.6*$mon+1.6) + 1) % 7; } __END__
Perl PHP Free CGI Script OliveDesign CGI

Perl PHP Free CGI Script OliveDesign CGI

プライバシーポリシー / 特定商取引法に基づく表示