#!/usr/bin/perl
#!/xampp/1.8.2/perl/bin/perl
#--------------------------------------------------------
# touban.cgi
# 夜間・休日当番医表HTML出力用CGI(iモード版:Perl使用)
#
# ※リンク書式:http://...../touban.cgi?y=0&m=0&d=0
#
# ※注意事項
# Perl本体のパスは利用環境に合わせて変更して下さい。
#
#--------------------------------------------------------
# Perl本体のパス
#!/usr/local/bin/perl
#require 'D:/Inetpub/WWWROOT/i/cgi/touban/util.pl';
require './util.pl';
#
# 引数解析
#
*arg = parseInput();
$year = $arg{'y'}; # 読み込み年 2001/02/21
$month = $arg{'m'}; # 読み込み月
$day = $arg{'d'}; # 読み込み日
#
# 当番医表からの読み込み日付を設定
#
($nday, $nmonth, $nyear) = (localtime)[3,4,5];
if( $year eq 0 || $month eq 0 || $day eq 0 ){ # 呼び出し元からの指定なし
$year = $nyear + 1900; # 現在年月日とする
$day = $nday; #
$month = $nmonth + 1; #
}
#
# 当番医表データ保管パス
# ファイル保存場所:カレントディレクトリ
# ファイル名 :西暦年月.csv 例)H13年3月の場合:『200103.csv』
#
#$path = './';
#$path = 'D:/Inetpub/WWWROOT/i/data/touban/';
$path = './data/';
$file = sprintf("%s%04d%02d.csv", $path, $year, $month);
#
# メイン処理(HTMLの出力)
#
if( !open(FILE, "<$file") ){
# ファイルオープンエラー処理
print "Content-type: text/html\n\n";
print "
";
print "メンテナンス
";
print "中です・・・
";
print "";
exit(); # exit() でプログラムを終了させる
}
$flg = 0;
while()
{
if($flg eq 0) {
# CSV形式のデータを [@new] に分割格納する。
$data = $_;
@new = ();
push(@new,$+) while $data =~
m{ "([^\"\\]*(?:\\.[^\"\\]*)*)",? | ([^,]+),? | , }gx;
push(@new, undef) if substr($data,-1,1) eq ',';
}
if( $flg eq 1) {
$data = $_;
@new_next = (); # 次の行読込み
push(@new_next,$+) while $data =~
m{ "([^\"\\]*(?:\\.[^\"\\]*)*)",? | ([^,]+),? | , }gx;
push(@new_next, undef) if substr($data,-1,1) eq ',';
$flg = 2;
}
if( @new[0] eq $day && $flg eq 0 )
{
$flg = 1;
}
if ( $flg eq 2) {
last; #ループを抜ける
}
}
close(FILE);
#while()
#{
# CSV形式のデータを [@new] に分割格納する。
# $data = $_;
# @new = ();
# push(@new,$+) while $data =~
# m{ "([^\"\\]*(?:\\.[^\"\\]*)*)",? | ([^,]+),? | , }gx;
# push(@new, undef) if substr($data,-1,1) eq ',';
# if( @new[0] eq $day )
# {
$d1 = 0; #前日の日
$m1 = 0; #前日の月
$y1 = 0; #前日の年 # 2001/02/21 追加
$d2 = 0; #翌日の日
$m2 = 0; #翌日の月
$y2 = 0; #翌日の年 # 2001/02/21 追加
#
# 前日日付設定
#
if( @new[0] eq 1 ) # 日=1日
{
if( $month eq 1 ) # 月=1月
{
$m1 = 12; # 前日日付=12月31日
$d1 = 31;
$y1 = $year - 1;
}
else
{
$y1 = $year; # 2001/02/21
$m1 = $month - 1; # 月=前月
$d1 = getDaysOfMonth(@new[0], $m1); # 日=前月の最終日
}
}
else
{
$y1 = $year; # 2001/02/21
$m1 = $month; # 月=現在月
$d1 = @new[0] - 1; # 日=前日
}
#
# 翌日日付設定
#
if( @new[0] eq getDaysOfMonth($year, $month) ) # 日=現在月の最終日
{
if( $month eq 12 ) # 月=12月
{
$m2 = 1; # 翌日=1月1日
$d2 = 1;
$y2 = $year + 1;
}
else
{
$y2 = $year; # 2001/02/21
$m2 = $month + 1; # 月=翌月
$d2 = 1; # 日=1日
}
}
else
{
$y2 = $year; # 2001/02/21
$m2 = $month; # 月=現在月
$d2 = @new[0] + 1; # 日=翌日
}
# 時刻表示日(和暦)
$datebuff = sprintf("平成%02d年%02d月%02d日", $year-1988, $month, @new[0] );
# ブラウザへの出力
print "Content-type: text/html\n\n";
print "";
print '';
print '';
print "Touban";
print '';
print "";
print $datebuff;
print "(@new[1])";
print "
";
# print "";
# print "病院名
| 住所
| 電話番号
| ";
# print "
@new[8]
| @new[9]
| @new[10]
| ";
print "
";
print "昼夜区分:@new[6]
";
print "病院名:@new[8]
";
print "住所:@new[9]
";
print "TEL @new[10]
";
if (@new_next[0] eq "" && @new_next[8] ne "") {
print "
";
if( @new_next[6] eq "" ) {
print "昼夜区分:@new[6]
";
} else{
print "昼夜区分:@new_next[6]
";
}
print "病院名:@new_next[8]
";
print "住所:@new_next[9]
";
print "TEL @new_next[10]
";
}
# print "
";
# print "$data
";
# print "@new_next
";
print "
";
# print "驪前日";
# print " ";
# print "黎翌日";
print "翌日
\n";
# print " ";
print "トップページへ";
print "";
print "";
# last; #ループを抜ける
# }
#}
#close(FILE);
#----- End of touban.cgi -----------