#!/usr/bin/perl
#ver.1.0.8
############################################################
########### ZonchScheduleMakerProMX/EX ###########
# Copyright(C) おふぃす・ぞんち2004-2006 All rights reserved.
# http://www.zonch.net/CGI/
############################################################
$version = "";
require 'prefs.cgi';
require 'lib.pl';
# データの読み込み
&parse_form;
if($FORM{'show'}) {
&show_schedule;
} elsif($FORM{'day'}) {
&show_data;
} else {
&show_menu;
}
####################
#
sub show_schedule {
# データを変数に入れる
#&get_variables;
#&check_directory;
if(&load_template($ieach_temp_file) != 2) {
&error('invalid_temp');
}
local($st_month, $st_day, $st_wday) = &get_start_date;
local($en_month, $en_day) = &shift_date($st_month, $st_day, 6);
&get_day_list($st_month, $st_day, $st_wday);
$temp_head =~ s/\$mf/$st_month/g;
$temp_head =~ s/\$df/$st_day/g;
$temp_head =~ s/\$mt/$en_month/g;
$temp_head =~ s/\$dt/$en_day/g;
local(@list) = &load_member;
local($found) = 0;
foreach (@list) {
if($_ eq $FORM{'show'}) {
$found = 1;
last;
}
}
if(! $found) {
&error('not_found', $FORM{'show'});
}
$temp_head =~ s/\$name/$NAME{$FORM{'show'}}/g;
$temp_head =~ s/\$dir/$FORM{'show'}/g;
$temp_head =~ s/\$ipage/$ipage_name/g;
$temp_head =~ s//$icharset/g;
&load_sche_data(0, 1, 1, $FORM{'show'});
print "Content-type: text/html\n\n";
&print_shift_jis($temp_head);
local($i);
for($i=1; $i<=7; $i++) {
&print_shift_jis(&print_each_data($FORM{'show'}, $i));
}
#↓著作権表示:必ず表示させてください
$temp_foot =~ s//$version<\/A>/g;
#↑著作権表示:必ず表示させてください
&print_shift_jis($temp_foot);
}
####################
sub print_each_data {
local($dir, $i) = @_;
local($from, $to, $status) = split(/,/, $DATA{$dir. $i});
if($status == 1) {
local($temp) = $temp_body;
$temp =~ s/\$day/$DAY{$i}/g;
$temp =~ s/\$name/$NAME{$dir}/g;
$temp =~ s/\$pict/$image_dir\/$PICT{$dir}/g;
$temp =~ s/\$dir/$dir/g;
$temp =~ s/\$ipage/$ipage_name/g;
$temp=~ s/\$schedule/$from$ift_separator$to/g;
return $temp;
} else {
return "";
}
}
###############
sub show_menu {
if(&load_template("$itemp_file") != 2) {
&error('invalid_temp');
}
local($st_month, $st_day, $st_wday) = &get_start_date;
local($en_month, $en_day) = &shift_date($st_month, $st_day, 6);
&get_iday_list($st_month, $st_day, $st_wday);
local($num) = &load_data;
print "Content-type: text/html\n\n";
$temp_head =~ s/\$mf/$st_month/g;
$temp_head =~ s/\$df/$st_day/g;
$temp_head =~ s/\$mt/$en_month/g;
$temp_head =~ s/\$dt/$en_day/g;
$temp_head =~ s//$icharset/g;
&print_shift_jis("$temp_head");
local($day) = 1;
while($day < 8) {
if($st_wday >= 7) { $st_wday = 0; }
&print_shift_jis("$DAY{$day}日($wdays[$st_wday])
");
$day++;
$st_wday++;
}
&print_shift_jis("全て");
#↓著作権表示:必ず表示させてください
$temp_foot =~ s//
$version<\/A>/g;
#↑著作権表示:必ず表示させてください
&print_shift_jis("$temp_foot");
}
###############
sub show_data {
if(&load_template2("$itemp_file") != 2) {
&error('invalid_temp');
}
local($st_month, $st_day, $st_wday) = &get_start_date;
local($en_month, $en_day) = &shift_date($st_month, $st_day, 6);
&get_iday_list($st_month, $st_day, $st_wday);
local($num) = &load_data;
if($FORM{'day'} < 0 || $FORM{'day'} > 7) { $FORM{'day'} = 0; }
print "Content-type: text/html\n\n";
$temp_head =~ s/\$mf/$st_month/g;
$temp_head =~ s/\$df/$st_day/g;
$temp_head =~ s/\$mt/$en_month/g;
$temp_head =~ s/\$dt/$en_day/g;
$temp_head =~ s//$icharset/g;
&print_shift_jis("$temp_head");
local($day) = 1;
local($col);
for ($col=1; $col<=7; $col++) {
if($st_wday >= 7) { $st_wday = 0; }
if($day >= $FORM{'day'}) {
local($temp) = $temp_body;
$temp =~ s/\$day/$DAY{$day}日($wdays[$st_wday])/g;
for($i=1; $i<=$num; $i++) {
if($STATUS{$DIR{$i}.$col} == 1) {
$temp =~ s//$part/g;
$temp =~ s/\$ipage/$ipage_name/g;
$temp=~ s/\$name/$NAME{$DIR{$i}}/g;
$temp=~ s/\$dir/$DIR{$i}/g;
$temp=~ s/\$schedule/$FROM{$DIR{$i}.$col}$ift_separator$TO{$DIR{$i}.$col}/g;
}
}
&print_shift_jis("$temp");
if($FORM{'day'} != 0) { last; }
}
$day++;
$st_wday++;
}
#↓著作権表示:必ず表示させてください
$temp_foot =~ s//$version<\/A>/g;
#↑著作権表示:必ず表示させてください
&print_shift_jis("$temp_foot");
}
###############################
sub get_iday_list {
local($month, $day) = @_;
if($month > 0 && $day > 0) {
local($i);
local($days_in_month) = &get_days_in_month($month);
for($i=1; $i<=7; $i++) {
if($day > $days_in_month) {
$day = 1;
}
$DAY{$i} = $day;
$day++;
}
}
}
####################
sub load_template2 {
local($filename) = @_;
open(TEMP,"$temp_dir/$filename") || &error('no_temp');
flock (TEMP, 2);
local($i) = 0;
while() {
if($i == 0) {
$temp_head .= $_;
} elsif($i == 1) {
if($_ =~ //) {
chop($_);
$part = $_;
$temp_body .= "";
} else {
$temp_body .= $_;
}
} else {
$temp_foot .= $_;
}
if($_ =~ //) {
$i++;
}
}
close(TEMP);
return $i;
}
####################
sub load_data {
if(open(DATA,"$data_name")) {
flock (DATA, 2);
while() {
chop($_);
local($dir, $name, $pict) = split(/\t/, $_);
$NAME{$dir} = $name;
#$PICT{$dir} = $pict;
}
close(DATA);
}
local($i) = 0;
if(open(DATA,"$sche_data_name")) {
flock (DATA, 2);
while() {
$i++;
chop($_);
local($dir, @data) = split(/\t/, $_);
local($col) = 1;
foreach (@data) {
($FROM{$dir.$col}, $TO{$dir.$col}, $STATUS{$dir.$col}) = split(/,/, $_);
$col++;
}
$DIR{$i} = $dir;
}
close(DATA);
}
return $i;
}
####################
sub print_shift_jis {
local($msg) = $_[0];
&jcode'convert(*msg, 'sjis');
print "$msg";
}