#! /usr/bin/perl
#
# chkbox2.cgi
#
# 2.007 : 12/5/07 : オプション削除&チェック保存機能を追加
# 2.006 : 11/20/07 : ヘッダを繰り返し表示するオプションを追加
# 2.005 : 6/10/07 : 管理設定の項目登録ファイル表記を修正
# 2.004 : 12/11/06 : 項目削除時に以前のチェック状態を継承するよう修正
# 2.003 : 11/13/06 : 項目名の再挿入オプションを追加
# 2.002 : 10/20/06 : オプション名に
を入れられるように修正
# 2.001 : 3/6/06 : 項目作成、body_head, body_tailのバグを修正
# 2.0 : 1/19/06 : Created.
#
# http://www.hidekik.com
#
# $Id: chkbox2.cgi,v 1.12 2007/12/05 04:35:34 Hideki Kanayama Exp $
# Copyright 2005-2007 Hideki Kanayama, All rights reserved
use CGI qw(:cgi-lib);
use strict;
use CGI::Carp qw(fatalsToBrowser);
use File::Basename;
my $version = "2.007";
my $lastupdatedyear = "2007";
my $admindat = "adminpwd.dat";
my $setupfile = "chkbox2_setup.pl";
my $script = basename($0);
my $lang = 0;
my $charset = ("Shift_JIS","ISO-8859-1")[$lang];
########## 環境設定 ここから ###########################
our $datafile = "checkbox.dat";
our $items = "items.lst";
# lockfile
our $lockfile = "lockfile.dat";
# Title
our $title = 'チェックボックス2';
# Background
our $bgimage_en = 0;
our $bgimage_file = '';
our $bgcolor = "#ffffff";
# Back link
our $backlink_en = 1;
our $backlink = '..';
our $backlink_name = '戻る';
# Body width
our $body_width = '100';
# option cell back ground color
our $option_bg_color = "#ffcc33";
# option cell font color
our $option_font_color = "black";
# item cell back ground color
our $item_bg_color = "#66ff99";
# item cell font color
our $item_font_color = "black";
#表示テーブルのカラム数
our $table_colms = 1;
#参加者設定の初期登録可能人数
our $default_max = 15;
#管理用リンク表示 1:有効 0:無効
our $setup_en = 1;
#変更日表示 1:有効 0:無効
our $update_en = 0;
#パスワード保護 1:有効 0:無効
our $password_en = 0;
#カウント 1:有効 0:無効
our $count_en = 0;
#管理人オンリーモード 1:有効 0:無効
our $adminonly_en = 1;
#オプション オプション名,背景色
our $options = '日曜日,red
月曜日,blue
火曜日,green
水曜日,lightgreen
木曜日,black
金曜日,orange
土曜日,lightblue
';
#項目名の再挿入 指定数のカラム毎に項目名表示
our $repeat_item = 10;
#ヘッダの繰り返し表示
our $header_repeat = 20;
# body_head
our $body_head = "
"; # body_tail our $body_tail = ' '; # Style Sheet our $style_sheet_en = 0; our $style_sheet = ' '; # Head insert our $head_insert_en = 0; our $head_insert = ' '; #時間設定 1:localtime, 0:offset from GMT our $localtime_en = 1; our $offset_from_gmt = 9; #予備のアップデートファイル # 1: on, 0: off our $update1_file_en = 0; our $update2_file_en = 0; our $update1_file = "update1.log"; our $update2_file = "update2.log"; ########## 環境設定 ここまで ########################### require "$setupfile" if (-e "$setupfile"); my $q = CGI->new; my $cgierror = $q->cgi_error; &error($cgierror) if ($cgierror); my %in = $q->Vars; if (! -e "$admindat"){ if ($in{mode} ne 'wradminpwd'){ &setadminpwd; } else { &wradminpwd($in{pwd}); } } my @option_list = grep !/^\s*$/, split /[\r\n]/, $options; if ($in{mode} eq 'atwrite'){ &atwrite; } elsif ($in{mode} eq 'setup'){ &setup; } elsif ($in{mode} eq 'setup_update'){ &setup_update; } else { &display; } ###################### 書き込み ############################ sub atwrite { &error('管理用パスワードが違います。') if (!&checkadmin($in{pwd}) and $adminonly_en == 1); &error('名前は必ず入れてください')if ($in{name} eq "" and $adminonly_en == 0); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)= $localtime_en ? localtime(time) : gmtime(time + 3600 * $offset_from_gmt); my $update = sprintf("%s_%s_%s_%02s_%02s",$year+1900,$mon+1,$mday,$hour,$min); my @items = &get_items; my ($date, $lastname, $name, $status, $count, $eachpwd, $eachmod) = &get_data; my (@name, @status, @count, @eachpwd, @eachmod); @name = @{$name}; @status = @{$status}; @count = @{$count}; @eachpwd = @{$eachpwd}; @eachmod = @{$eachmod}; &lockfile; my $tmpfile = "tmp.$$"; open(WRDAT,">$tmpfile"); print WRDAT "0,$in{name},$update,\n"; my $endatt = $#items + 1; my $i; for ($i=1;$i<=$endatt;$i=$i+1){ my $pwdi = "pwd_$i"; chomp($items[$i-1]); my $incheck = join('-', map {$in{"${i}_$_"}} (0 .. $#option_list)); my $stcheck = join('-', map {$status[$i][$_]} (0 .. $#option_list)); if ($incheck ne $stcheck) { $eachmod[$i] = "$update"; if ($password_en == 1 && "$eachpwd[$i]" ne '' && !&checkcrypt("$in{$pwdi}","$eachpwd[$i]")) { close(WRDAT); unlink("$tmpfile"); &error("$name[$i]を変更しようとしていますが、そのパスワードが違います。"); } } if ($password_en == 1 && ("$in{$pwdi}" ne '' && "$eachpwd[$i]" eq '')){ $eachpwd[$i] = &makecrypt("$in{$pwdi}"); } print WRDAT "$i,$items[$i-1],$in{\"count_$i\"},$eachmod[$i],$eachpwd[$i],"; my $x; for ($x=0;$x<=$#option_list;$x++) { my $tmpix = "${i}_$x"; print WRDAT "$in{$tmpix}," ; } print WRDAT "\n"; } close(WRDAT); rename("$tmpfile","$datafile"); chmod(0666,"$datafile"); &unlockfile; &extraupdate; print "Location: $script\n\n"; } ###################### 表示 ############################ sub display { &htmlhead($title); my ($date, $lastname, $name, $status, $count, $eachpwd, $eachmod) = &get_data; my (@name, @status, @count, @eachpwd, @eachmod); @name = @{$name}; @status = @{$status}; @count = @{$count}; @eachpwd = @{$eachpwd}; @eachmod = @{$eachmod}; my @items_list = &get_items; print "$body_head"; print "
"; print "$body_tail"; &htmltail; } ###################### セットアップ ############################ sub setup { &setadminpwd if ($in{pwd} eq ''); &error('管理用パスワードが違います。') unless &checkadmin($in{pwd}); &htmlhead('管理用セットアップ'); print "\n"; print "| \n"; } sub copyright { my $mysite = ('http://www.hidekik.com/','http://www.hidekik.com/en/')[$lang]; print "chkbox2.cgi Ver. $version\n"; print "Copyright(C) 2005-$lastupdatedyear, hidekik.com\n"; } sub htmltail { print " |