#!/usr/local/bin/perl ;# WebVOTE v3.6 is Free. (c)rescue.ne.jp ;# Scripts Found at: http://www.rescue.ne.jp/ # History # v3.2 29-Aug-98 浮動小数点(小数点1桁固定小数点形式)処理 # v3.3 06-Sep-98 投票方式およびグラフ処理の変更 # v3.4 07-Jul-99 小数点以下処理のバグ修正 # v3.5 23-Dec-99 2000年対応 # v3.6 22-Apr-02 グラフのサイズが0になった場合に異常表示される不具合の修正(Netscape 4.7x) #初期設定 ########################################################################################### #●日本語コード変換ライブラリの指定(別に用意します) require './jcode.pl'; #●設置したURL(http://から正しく記入します) $cgi = 'http://設置したURL/vote.cgi'; #●データを記録するファイル $an_file = "./vote.dat"; #●画像バーのURL(このCGIから見たパス位置、または http:// から書く) $gif = './bar.gif'; #●画面設定 $body = ''; #●バータイトル $title = '投票'; #●画面冒頭に入れる画面(HTML式) $an_title = '

投票

最近読んだ本を投票してください

みなさんからの投票をお待ちしています。

'; #●クッキーを使った簡易2重投稿防止処理をする=1 しない=0 $wck = 1; #●アンケートファイルが大きくなりすぎないようにする為の最大アンケート可能件数の設定 # ソート処理を扱うために大きなデータファイルはサーバに多大な負荷を与えてしまいます. # それを防止するために記録件数の上限を設定してください. 1000以下のご利用が推奨です. $rescue = 1000; #●入力処理方式 標準:post 直接:get $method = 'post'; ########################################################################################### #時刻取得 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $year += 1900; if ($sec < 10) { $sec = "0$sec"; } if ($min < 10) { $min = "0$min"; } if ($hour < 10) { $hour = "0$hour"; } $month = ($mon + 1); #データ記録用時刻フォーマット $date = "$hour\:$min\:$sec $month\:$mday\:$year"; #現在時刻表示用 $date_now = "$year年$month月$mday日 $hour時$min分$sec秒"; #データ入力 if ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } else { $buffer = $ENV{'QUERY_STRING'}; } #処理 if ($buffer eq "") { &html_header; &html_form; &html_trailer; } else { $tnx = "1"; &an_w; &html_header; &html_trailer; } sub html_header { if (!open(DB,"$an_file")) { &error('エラー','データファイルを読み出せません.'); } @lines = ; close(DB); $accesses = @lines; #集計最初のデータの投票時刻 if ($lines[0] =~ /\[(.*)\] (.*)/) { $first_date = $1; ($clock,$day) = split(/ /,$first_date); ($hour,$minute,$second) = split(/:/,$clock); ($month,$mday,$year) = split(/:/,$day); if ($year < 100) { $year += 1900; } $first_date = "$year年$month月$mday日 $hour時$minute分"; } else { $first_date = 0; } #集計最後のデータの投票時刻 if ($lines[($accesses - 1)] =~ /\[(.*)\] (.*)/) { $last_date = $1; ($clock,$day) = split(/ /,$last_date); ($hour,$minute,$second) = split(/:/,$clock); ($month,$mday,$year) = split(/:/,$day); if ($year < 100) { $year += 1900; } $last_date = "$year年$month月$mday日 $hour時$minute分"; } else { $last_date = 0; } foreach $line (@lines) { if ($line =~ /\[(.*)\] (.*)/) { $an = $2; if ($an ne ' ' && $an ne '') { push(@AN, $an); } } } $i = 0; foreach (@AN) { $ans{($_)[0]}++; $i++; } print "Content-type: text/html\n\n"; print "$title\n"; print "$body\n"; print "$an_title


\n"; print "全投票数:$accesses 有効回答数(白票以外):$i

\n"; print "\n"; if ($tnx ne "1") { print "\n"; } else { print "\n"; } foreach (sort { $ans{$b} <=> $ans{$a} } keys %ans) { print "\n"; $total_ans += $ans{$_}; $percent_ans = 100 * ($ans{$_} / $i); $percent_ans = sprintf("%2.1f",$percent_ans); $img = int($percent_ans) * 3 + 1; if ($tnx ne "1") { print "\n"; print "\n"; print "\n"; print "\n"; } else { print "\n"; } print "\n"; } print "
項目名選択数投票割合グラフ
項目名選択数割合グラフ
$_$ans{$_}$percent_ans\%$_$ans{$_}$percent_ans\%

\n"; print "・$date_now 現在のアンケート集計結果です。
\n"; if ($first_date != 0 && $last_date != 0) { print "・これらは[$first_date]から[$last_date]までの集計結果です。
\n"; print "・最大アンケート集計件数: $rescue 件分(これを超えると最新の$rescue件分の集計になります)

\n"; } } sub html_trailer { print "

\n"; if ($tnx eq "1") { print "

ありがとうございました。

\n"; } #著作表示(削除禁止) print "

WebVOTE
\n"; print "\n"; } sub html_form { print "
\n"; print "\n"; if ($i == 0) { print "現在何も登録されていませんので項目を作成してください \n"; } else { print "該当がなければ追加してください \n"; } print "

\n"; } sub an_w { @pairs = split(/&/,$buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; &jcode'convert(*value,'sjis'); $value =~ s//>/g; if ($name ne "write") { $FORM{$name} = $value; } } if ($FORM{'an'} ne "" && $FORM{'an2'} ne "") { $write = ""; } elsif ($FORM{'an'} ne "") { $write = $FORM{'an'}; } elsif ($FORM{'an2'} ne "") { $write = $FORM{'an2'}; } #重複チェックへ if ($wck) { &wcheck; } if (!open(LOG,"$an_file")) { &error('エラー','データファイルを読み出せません.'); } @lines=; close(LOG); $axs=@lines; $rescue2 = ($rescue - 1); if ($axs >= $rescue) { if (!open(LOG,">$an_file")) { &error('エラー','データファイルに記録できません.'); } foreach $axs (1..$rescue2) { print LOG $lines[$axs]; } } else { if (!open(LOG,">>$an_file")) { &error('エラー','データファイルに記録できません.'); } } print LOG "[$date] $write\n"; close(LOG); } sub error { print "Content-type: text/html\n\n"; print "$title\n"; print "$body\n"; print "

$_[0]

\n"; print "$_[1]\n"; print '

' . "\n"; exit; } sub wcheck { #(簡易)複数回投稿防止処理 @pairs = split(/;/,$ENV{'HTTP_COOKIE'}); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $name =~ s/ //g; $COOKIE{$name} = $value; } if ($COOKIE{$cgi} eq 'repost_check') { &error('複数投票できません','あなたは既に投票されました.'); } print "Set-Cookie: $cgi=repost_check;\n"; } # end of script.