#!/usr/local/bin/perl #ver.1.0.4 ############################################################ ########### ZonchScheduleMakerMX Plus ############# # Copyright(C) おふぃす・ぞんち2003-2004 All rights reserved. # http://www.zonch.net/CGI/ ############################################################ $version = "ZonchScheduleMakerMX Plus"; require 'prefs.cgi'; require 'lib+.pl'; # データの読み込み &parse_form; &get_cookie; if(! $FORM{'cmd'}) { &show_menu; } elsif($FORM{'cmd'} eq "form") { &show_form; } elsif($FORM{'cmd'} eq "dform") { &show_delete_form; } else { if($FORM{'pass'} ne $password) { &error('not_user'); } else { if($FORM{'cmd'} eq "update") { &update; } elsif($FORM{'cmd'} eq "confirm") { &confirm_update; } elsif($FORM{'cmd'} eq "delete") { &delete($FORM{'edit'}); &show_menu; } else { &show_menu; } } } #################### sub update { local($y, $m, $d, $dir_name) = &get_edit_info($FORM{'edit'}); if(&load_template("$temp_file") != 2) { &error('invalid_temp'); } # 日時を文字列で取得 &get_date; if(! -e "$data_dir/$dir_name" && ! mkdir("$data_dir/$dir_name", 0757)) { &error('dir_not_created'); } #データをファイルに書き込む &update_data($dir_name); # ファイルを更新する &update_html($dir_name, $y, $m, $d); &clear_old_data; local($ft); if($FORM{'ft'}) { $ft = "&ft=$FORM{'ft'}"; } #書き込みが成功したことをユーザーに伝えます。 &set_cookie; print "Content-type: text/html\n\n"; print "成功しました。

やり直す ページを開く トップ"; } #################### sub show_menu { local($dir, $pos) = &get_default_dir_info; local($year, $month, $mday) = split(/,/, $pos); if(! $FORM{'y'} && ! $FORM{'m'}) { $FORM{'y'} = $year; $FORM{'m'} = $month; } print "Content-type: text/html\n\n"; print < 長崎デリヘル イリュージョン

End_Of_Return local($i); if($show_list_to < 2) { $show_list_to = 2; } for($i=0; $i<$show_list_to; $i++) { &show_each_menu($FORM{'y'}, $FORM{'m'}+$i, $mday); $mday = 0; } local($ft); if($input_type == 1) { $ft = "&ft=1"; } local($copy_option) = "
T-BACK・スケジュール
作成済 日付 操作
今週の予定表(PC) 今週の予定表(携帯)
End_Of_Return } #################### sub show_each_menu { local($y, $m, $d) = @_; if($m > 12) { $y++; $m -= 12; } local($day, $wday); if($d > 0) { $day = $d; $wday = 1; } else { $day = 1; $wday = &get_wday_of_top_of_month($y, $m); } if($wday > 1) { $day += 7 - $wday + 1; } elsif($wday == 0) { $day++; } local($mark); local($days_in_month) = &get_days_in_month($y, $m); while($day <= $days_in_month) { local($st_date) = sprintf("%02d月%02d日〜", $m, $day); local($dir) = sprintf("%04d%02d%02d", $y, $m, $day); if(-e "$data_dir/$dir" && -d "$data_dir/$dir") { $mark = "*"; } else { $mark = ""; } print < $mark $st_date 編集 削除 表示 End_Of_Return $day += 7; } } #################### sub get_wday_of_top_of_month { local($y, $m) = @_; if($m > 12) { $y++; $m -= 12; } local($sec,$min,$hour,$mday,$month,$year,$wday) = gmtime(time+9*60*60); $year += 1900; $month++; local($target_month) = $m; if($m < $month) { $target_month += 12 ; } local($days_in_month) = &get_days_in_month($y, $m); local($shift_days, $top_wday); if($m != $month) { $shift_days = &get_days_in_month($year, $month) - $mday + 1; while(++$month < $target_month) { $shift_days += &get_days_in_month($year, $month); } $top_wday = $wday + $shift_days % 7; if($top_wday >= 7) { $top_wday -= 7; } } else { $shift_days = $mday - 1; $top_wday = $wday - $shift_days % 7; if($top_wday < 0) { $top_wday += 7; } } return $top_wday; } #################### sub show_form { if(&load_template("$form_temp_file") != 2) { &error('invalid_temp'); } local($y, $m, $d, $dir_name) = &get_edit_info($FORM{'edit'}); if($FORM{'ft'}) { $input_type = 1; } &get_day_list($y, $m, $d); $temp_head =~ s/\$edit/$FORM{'edit'}/g; $temp_head =~ s/\$yf/$y/g; $temp_head =~ s/\$mf/$m/g; $temp_head =~ s/\$df/$d/g; $temp_head =~ s/\$cgi_name/$cgi_name/g; local($load_dir_name); if($FORM{'load'}) { ($y, $m, $d, $load_dir_name) = &get_edit_info($FORM{'load'}); } local($options) = &get_copy_options($dir_name, $load_dir_name); $temp_head =~ s/\$options/$options/g; if($input_type == 1) { $temp_head =~ s/\$type/true/g; } else { $temp_head =~ s/\$type/false/g; } print "Content-type: text/html\n\n"; print "$temp_head"; if($load_dir_name) { $dir_name = $load_dir_name; } if(open(DATA,"$data_dir/$dir_name/$data_file_name")) { flock (DATA, 2); while() { chop($_); local($dir, $name, $pict) = split(/\t/, $_); $NAME{$dir} = $name; $PICT{$dir} = $pict; } close(DATA); } local($index) = 0; if(open(DATA,"$data_dir/$dir_name/$sche_data_name")) { flock (DATA, 2); while() { chop($_); ($dir, $DATA{'1'}, $DATA{'2'}, $DATA{'3'}, $DATA{'4'}, $DATA{'5'}, $DATA{'6'}, $DATA{'7'}) = split(/\t/, $_); &print_each_form($dir, ++$index); } close(DATA); undef %DATA; } if($index > 0) { $add = $add_forms; } else { $add = $add_forms_when_no_data; } for($i=0; $i<$add; $i++) { &print_each_form("", ++$index); } $temp_foot =~ s/\$index/$index/g; $temp_foot =~ s/\$ft/$FORM{'ft'}/g; $temp_foot =~ s/\$pass/$COOKIE{'admn'}/g; $temp_foot =~ s/\$date//g; $temp_foot =~ s/\$cgi_name/$cgi_name/g; $temp_foot =~ s//

$version<\/A><\/P>/g; print "$temp_foot"; } #################### sub print_each_form { local($dir, $index) = @_; local($check_from) = $check_top + ($index -1)*($each_item_num - 14*$input_type); local($temp) = $temp_body; $temp =~ s/\$index/$index/g; $temp =~ s/\$name/$NAME{$dir}/g; $temp =~ s/\$pict/$PICT{$dir}/g; $temp =~ s/\$dir/$dir/g; local($i); if($input_type == 1) { $temp =~ s/\$check_from/$check_from/g; } else { for($i=0; $i<=2; $i++) { $temp =~ s/\$check_from/$check_from/; $check_from++; } } for($i=1; $i<=7; $i++) { $temp =~ s/\$day$i/$DAY{$i}/g; local($from, $to, $status) = split(/,/, $DATA{$i}); $temp =~ s/\$from$i/$from/g; $temp =~ s/\$to$i/$to/g; if($input_type) { $options = &get_popup_options($index, $i, $status); } else { $options = &get_radio_options($index, $i, $status); } $temp =~ s/\$data$i/$options/g; } print "$temp"; } #################### sub get_copy_options { local($dir_name, $load_dir_name) = @_; local($options) = "

ファイルを削除

$FORM{'edit'}.htmlを削除します。よろしいですか?
パスワード:

 
End_Of_Return } #################### sub confirm_update { local($year, $month, $day, $dir_name) = &get_edit_info($FORM{'edit'}); local($year_to, $month_to, $day_to) = &shift_date($year, $month, $day, 6); &check_directory; if(&load_template("$temp_file") != 2) { &error('invalid_temp'); } local($temp, $index); &get_day_list($year, $month, $day); $temp_head =~ s/\$yf/$year/g; $temp_head =~ s/\$mf/$month/g; $temp_head =~ s/\$df/$day/g; $temp_head =~ s/\$yt/$year_to/g; $temp_head =~ s/\$mt/$month_to/g; $temp_head =~ s/\$dt/$day_to/g; $temp_head =~ s/\$cgi_name/$show_cgi_name/g; $temp_head =~ s/\$pos/$FORM{'edit'}/g; print "Content-type: text/html\n\n"; print "$temp_head"; for($index=1; $index<=$FORM{'num'}; $index++) { if($FORM{'name'. $index}) { print &print_each_data($index); } } local($fields) = &get_hidden_fields; $temp_foot =~ s/\$date//g; $temp_foot =~ s/\$pos/$FORM{'edit'}/g; $temp_foot =~ s/\$cgi_name/$show_cgi_name/g; $temp_foot =~ s//$fields/g; print "$temp_foot"; } #################### sub get_hidden_fields { local($index, $i); local($fields) = "
"; for($index=1; $index<=$FORM{'num'}; $index++) { if($FORM{'name'. $index}) { $fields .= "\n"; $fields .="\n"; $fields .="\n"; for($i=1; $i<=7; $i++) { $fields .= "\n"; $fields .= "\n"; $fields .= "\n"; } } } if($FORM{'ft'}) { $fields .= "\n"; } $fields .= " 
"; return $fields; } #################### sub print_each_data { local($index) = @_; local($temp) = $temp_body; $temp =~ s/\$name/$FORM{'name'. $index}/g; $temp =~ s/\$pict/$image_dir\/$FORM{'pict'. $index}/g; $temp =~ s/\$dir/$FORM{'dir'. $index}/g; $temp =~ s/\$page/$page_name/g; local($i); for($i=1; $i<=7; $i++) { $temp =~ s/\$day$i/$DAY{$i}/g; if($FORM{'data'. $i. $index} == 1) { $temp =~ s/\$data$i/$FORM{'from'. $i. $index} 〜 $FORM{'to'. $i. $index}/g; } elsif($FORM{'data'. $i. $index} == 2) { $temp =~ s/\$data$i/$no_mark/g; } else { $temp =~ s/\$data$i/$mitei_mark/g; } } return "$temp"; } ############################### #日時を文字列で取得 sub get_date { local($sec,$min,$hour,$mday,$month,$year,$wday,$yday,$isdst) = gmtime(time+9*60*60); $month++; $year += 1900; $date = sprintf("更新日時:%04d年%02d月%02d日 %02d:%02d:%02d", $year, $month, $mday, $hour, $min, $sec); } ############################### #データをファイルに書き込む sub update_data { local($dir_name) = @_; local($index, $data, $i); open(DATA,">$data_dir/$dir_name/$data_file_name") || &error('file_error', "$data_dir/$dir_name/$data_file_name"); flock (DATA, 2); for($index=1; $index<=$FORM{'num'}; $index++) { if($FORM{'name'. $index}) { print DATA "$FORM{'dir'. $index}\t$FORM{'name'. $index}\t$FORM{'pict'. $index}\n"; } } close(DATA); open(DATA,">$data_dir/$dir_name/$sche_data_name") || &error('file_error', "$data_dir/$dir_name/$sche_data_name"); flock (DATA, 2); for($index=1; $index<=$FORM{'num'}; $index++) { if($FORM{'name'. $index}) { $data = "$FORM{'dir'. $index}\t"; for($i=1; $i<=7; $i++) { #if($FORM{$_. $index}) { $data .= "$FORM{'from'. $i. $index},$FORM{'to'. $i. $index},$FORM{'data'. $i. $index}\t"; #} } chop($data); print DATA "$data\n"; } } close(DATA); } #################### # sub update_html { local($file_name, $year, $month, $day) = @_; local($temp, $index); &get_day_list($year, $month, $day); local($year_to, $month_to, $day_to) = &shift_date($year, $month, $day, 6); open(DATA,">$file_name.html") || &error('file_error', "$file_name.html"); flock (DATA, 2); $temp_head =~ s/\$yf/$year/g; $temp_head =~ s/\$mf/$month/g; $temp_head =~ s/\$df/$day/g; $temp_head =~ s/\$yt/$year_to/g; $temp_head =~ s/\$mt/$month_to/g; $temp_head =~ s/\$dt/$day_to/g; $temp_head =~ s/\$cgi_name/$show_cgi_name/g; $temp_head =~ s/\$pos/$year,$month,$day/g; print DATA "$temp_head"; for($index=1; $index<=$FORM{'num'}; $index++) { if($FORM{'name'. $index}) { print DATA &print_each_data($index); } } $temp_foot =~ s/\$cgi_name/$show_cgi_name/g; $temp_foot =~ s/\$pos/$year,$month,$day/g; #↓著作権表示:必ず表示させてください $temp_foot =~ s/\$date/$date

$version<\/A>/g; #↑著作権表示:必ず表示させてください print DATA "$temp_foot"; close(DATA); } #################### sub dir_exists { local($dir) = @_; local(@allfiles); local($exists) = 0; opendir(ETC, "$data_dir/") || &error('dir'); @allfiles = grep(!/^\./, readdir(ETC)); closedir(ETC); foreach (@allfiles) { if($_ eq $dir) { $exists = 1; last; } } return $exists; } #################### sub delete { local($dir) = @_; if(! $dir || ! &dir_exists($dir)) { &error('no_file_name'); } opendir(ETC, "$data_dir/$dir") || &error('dir'); local(@allfiles) = grep(!/^\./, readdir(ETC)); closedir(ETC); foreach (@allfiles) { unlink("$data_dir/$dir/$_"); } rmdir("$data_dir/$dir"); unlink("./$dir.html"); } #################### sub clear_old_data { if($keep_weeks > 5) { $keep_weeks = 5; } if($keep_weeks > 0) { local($dir, $pos) = &get_default_dir_info; local($i); for($i=0; $i<$keep_weeks; $i++) { ($dir, $pos) = &get_dir_info($pos); } local($year, $month, $mday) = split(/,/, $pos); #print "Content-type: text/html\n\n$year, $month, $mday,"; opendir(ETC, "$data_dir/") || &error('dir'); local(@allfiles) = grep(!/^\./, readdir(ETC)); closedir(ETC); foreach (@allfiles) { if(-d "$data_dir/$_" && $_ =~ /(\d{4})(\d{2})(\d{2})/) { #print "$1, $2, $3"; if($year >$1 || ($year == $1 && ($month > $2 || ($month == $2 && $mday > $3)))) { &delete($_); } } } } } #################### sub set_cookie { local(@week, @mons, $date_g, $cookie); local($secg,$ming,$hourg,$mdayg,$mong,$yearg,$wdayg) = gmtime(time + 60*60*24*365); @week = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat'); @mons = ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); $date_g = sprintf("%s\, %02d-%s-%04d %02d:%02d:%02d GMT", $week[$wdayg],$mdayg,$mons[$mong],$yearg+1900,$hourg,$ming,$secg); $cookie="admn<>$password"; print "Set-Cookie: ZSM=$cookie; expires=$date_g\n"; } #################### sub get_cookie { local($cookie, @cookies, @pairs, $name, $value); $cookie = $ENV{'HTTP_COOKIE'}; @cookies = split(/; /, $cookie); foreach (@cookies) { if ($_ =~ /ZSM=(.*)/) { $cookie=$1; last; } } @pairs = split(/,/, $cookie); foreach(@pairs) { ($name, $value) = split(/<>/, $_); $COOKIE{$name} = $value; } } #################### sub get_radio_options { local($row, $col, $status) = @_; local($options) = ""; local(@sel) = ("", "", ""); if($status >= 0 && $status <= 2) { $sel[$status] = " checked"; } else { $sel[0] = " checked"; } $options .= "$status[1]
\n"; $options .= "$status[2]
\n"; $options .= "$status[0]
\n"; return $options; } #################### sub get_popup_options { local($row, $col, $status) = @_; local($options) = "

\n"; return $options; } #################### sub check_directory { local($error) = 0; local($i) = 1; while($i <= $FORM{'num'}) { if(! $FORM{'dir'. $i}) { if($FORM{'name'. $i}) { $error = 2; last; } } elsif(&count_directory($FORM{'dir'. $i}) > 1) { $error = 1; last; } $i++; } if($error == 1) { &error('dir_input_err', $FORM{'dir'. $i}); } elsif($error == 2) { &error('dir_not_input', $FORM{'name'. $i}); } } #################### sub count_directory { local($dir) = @_; local($count) = 0; local($i) = 1; while($i <= $FORM{'num'}) { if($FORM{'dir'. $i} && ($FORM{'dir'. $i} eq $dir) ) { $count++; } $i++; } return $count; }