📄 vote.pl
字号:
if (@data) {
print "<link href=\"/cgi.css\" rel=\"STYLESHEET\" type=\"text/css\">";
print "<h2>删除下列话题或选择</h2><ul>\n<form method=\"POST\">";
print "\n<input type=\"hidden\" name=\"action\" value=\"delete\">\n";
print "<input type=\"hidden\" name=\"uref\" value=\"$user_ref\">\n";
foreach $line(@data) {
($topic, $numt, $others) = split(/\|/,$line);
print "<input type=\"radio\" name=\"which\" value=\"t|$numt|x\">\n";
print "$topic<ul>\n";
open (FILE, "$data_path/ch$numt.txt");
@choices = <FILE>;
close(FILE);
foreach $choice(@choices) {
($name,$votes,$numc) = split(/\|/, $choice);
print "<li><input type=\"radio\" name=\"which\" value=\"c|$numc|$numt\">";
print "$name ($votes 票)\n";
}
print "</ul>\n";
}
print "<link href=\"/cgi.css\" rel=\"STYLESHEET\" type=\"text/css\">";
print "</ul><input type=\"hidden\" name=\"password\" value=\"$FORM{'password'}\">\n";
print "<input type=\"submit\" value=\" 删除 \"></form><p><hr color=\"#BB6713\" size=\"1\">\n";
print "<center><h2>允许/禁止加入选择</h2><form method=\"POST\">\n";
print "<input type=\"hidden\" name=\"action\" value=\"others\">\n";
print "<input type=\"hidden\" name=\"uref\" value=\"$user_ref\">\n";
print "<input type=\"hidden\" name=\"password\" value=\"$FORM{'password'}\">\n";
print "<table border=\"1\" width=\"500\" cellpadding=\"0\" cellspacing=\"0\" bordercolorlight=\"#BB6713\" bordercolordark=\"#FFF3E8\"><tr><td><table cols=\"2\>\n";
foreach $line(@data) {
chomp($line);
($topic, $num, $others) = split(/\|/,$line);
print "<tr><td align=\"right\" width=\"400\">$topic</td>";
print "<td width=\"110\"><input type=\"radio\" name=\"$num\"";
print " value=\"yes\"";
if ($others eq "yes") { print " checked"; }
print ">允许<input type=\"radio\" name=\"$num\" value=\"no\" ";
if ($others eq "no") { print " checked"; }
print ">禁止</td></tr>\n";
}
print "</table><center><input type=\"submit\"><input type=\"reset\"></form></td></tr></table>\n";
}
else { print "<p><center><b>怎么可能呢?竟然会无话可说!</b></center><p>\n"; }
&addtopic;
print "</body></html>\n";
exit;
}
sub others {
&checkpassword;
open (FILE, ">$data_path/vote.txt");
foreach $line(@data) {
($topic, $num, $others) = split(/\|/,$line);
print FILE "$topic|$num|$FORM{$num}\n";
}
close(FILE);
&admin;
}
sub showvote {
# Get the information for the topic
foreach $line(@data) {
($topic,$num,$others) = split(/\|/, $line);
if ($num == $FORM{'topic'}) { last }
}
# print out the beginning of the page
print "<link href=\"/cgi.css\" rel=\"STYLESHEET\" type=\"text/css\">";
print "<center><table border=\"1\" width=\"500\" cellpadding=\"0\" cellspacing=\"0\" bordercolorlight=\"#BB6713\" bordercolordark=\"#FFF3E8\"><tr><td bgcolor=\"#CC9966\" height=\"25\">\n";
print "<center><b>$topic</b></center></tr></td></table>\n";
print "<center><table border=\"1\" width=\"500\" cellpadding=\"0\" cellspacing=\"0\" bordercolorlight=\"#BB6713\" bordercolordark=\"#FFF3E8\"><tr><td><table cols=\"2\">\n";
print "<form method=\"POST\"><input type=\"hidden\" name=\"action\" ";
print "value=\"vote\">\n<input type=\"hidden\" name=\"topic\" value=\"$num\">\n";
print "<input type=\"hidden\" name=\"uref\" value=\"$user_ref\">\n";
# print the choices
open(FILE,"$data_path/ch$num.txt");
@lines = <FILE>;
close(FILE);
$first = 0;
foreach $line(@lines) {
($choice, $x, $num) = split(/\|/, $line);
print "<tr><td width=\"10\"><input type=\"radio\" name=\"choice\"";
print " value=\"$num\"";
if ($first == 0) { print " CHECKED"; $first = 1; }
print "></td><td width=\"460\">$choice";
print "</td></tr>\n";
}
if ($others eq "yes\n") {
print "<tr><td width=\"10\"><input type=\"radio\" name=\"choice\"";
print " value=\"add_choice\"></td><td width=\"490\"><input type=";
print "\"text\" name=\"new_choice\">(如果这里还有没列出的选择,请你添加)</td></tr>\n";
}
print "</table><p align=\"center\"><input type=\"submit\" value=\"投票!\"></p>\n";
print "</form></td></tr></table>\n";
exit;
}
sub vote {
open (FILE, "$data_path/vote.txt");
@data = <FILE>;
close(FILE);
foreach $line(@data) {
($topic, $numt, $others, $faction) = split(/\|/,$line);
}
if (($UserFaction ne $faction)&&($faction ne "")) {
print "<html><head>\n";
print "Faction Error<P>对不起,你不是长乐帮帮中同仁!\n";
print "<script Language=\"JavaScript\">\n";
print " alert(\"对不起,请不要干涉长乐帮内政!\");\n";
print "</script></head></html>\n";
exit;
}
open (FILE, "$data_path/ip$FORM{'topic'}.txt");
@ips = <FILE>;
close(FILE);
foreach $ip(@ips) {
chomp($ip);
if ($ip eq $ENV{'REMOTE_ADDR'}) {
print "<link href=\"/cgi.css\" rel=\"STYLESHEET\" type=\"text/css\">";
print "<body><center>对不起!针对这一个事件,你只能作出一次选择……\n";
print "<p>这个IP地址 $ENV{'REMOTE_ADDR'} 已经投过票了.\n";
print "请返回.</center></body></html>\n";
exit;
}
}
open (FILE, "$data_path/name$FORM{'topic'}.txt");
@names = <FILE>;
close(FILE);
foreach $name(@names) {
chomp($name);
if ($name eq $UserName) {
print "<link href=\"/cgi.css\" rel=\"STYLESHEET\" type=\"text/css\">";
print "<body><center>对不起!针对这一个事件,你只能作出一次选择……\n";
print "<p>这个人物ID $UserName 已经投过票了.\n";
print "请返回.</center></body></html>\n";
exit;
}
}
open (FILE, "$data_path/ch$FORM{'topic'}.txt");
@choices = <FILE>;
close(FILE);
if ($FORM{'choice'} eq "add_choice") {
unless ($FORM{'new_choice'}) {
print "<link href=\"/cgi.css\" rel=\"STYLESHEET\" type=\"text/css\">";
print "<html><center>缺少信息<head><body>\n";
print "你正尝试加入一个其他的选择, 但你并\n";
print "没有在表单中填入一个选择!\n";
print "<p>请返回再试一遍</center></body></html>\n";
exit;
}
chomp($choices[$#choices]);
($x,$y,$last) = split(/\|/, $choices[$#choices]);
$last++;
open (FILE, ">>$data_path/ch$FORM{'topic'}.txt");
print FILE "$FORM{'new_choice'}|1|$last\n";
close(FILE);
open (FILE, ">>$data_path/ip$FORM{'topic'}.txt");
print FILE "$ENV{'REMOTE_ADDR'}\n";
close(FILE);
&results;
}
open (FILE, ">$data_path/ch$FORM{'topic'}.txt");
foreach $choice(@choices) {
chomp($choice);
($x,$y,$last) = split(/\|/, $choice);
if ($last == $FORM{'choice'}) { $y++; }
print FILE "$x|$y|$last\n";
}
close(FILE);
open (FILE, ">>$data_path/ip$FORM{'topic'}.txt");
print FILE "$ENV{'REMOTE_ADDR'}\n";
close(FILE);
open (FILE, ">>$data_path/name$FORM{'topic'}.txt");
print FILE "$UserName\n";
close(FILE);
&results;
}
sub results {
foreach $line(@data) {
($topic, $num, $others) = split(/\|/, $line);
if ($num eq $FORM{'topic'}) { last }
}
print "<link href=\"/cgi.css\" rel=\"STYLESHEET\" type=\"text/css\">";
print "<center><table border=\"1\" width=\"500\" cellpadding=\"0\" cellspacing=\"0\" bordercolorlight=\"#BB6713\" bordercolordark=\"#FFF3E8\"><tr><td bgcolor=\"#CC9966\" height=\"25\">\n";
print "<html><center><b>$topic</b></center></tr></td></table><body>\n";
print "<table border=\"1\" width=\"500\" cellpadding=\"0\" cellspacing=\"0\" bordercolorlight=\"#BB6713\" bordercolordark=\"#FFF3E8\" cols=\"3\"><tr><td width=\"260\"><center>网 友 选 择</td>\n";
print "<td width=\"50\"><center>票 数</center></td><td width=\"50\">\n";
print "<center>%</center></td></tr>\n";
open (FILE, "$data_path/ch$FORM{'topic'}.txt");
@lines = <FILE>;
close(FILE);
$i = 0;
foreach $line(@lines) {
($topic,$votes,$num) = split(/\|/, $line);
$i = $i + $votes;
}
foreach $line(@lines) {
($topic,$votes,$num) = split(/\|/, $line);
if ($i > 0) { $percent = sprintf("%.2f",100 * ($votes / $i)); }
else { $percent = "NA"; }
print "<tr><td width=\"500\">$topic</td>";
print "<td width=\"50\"><center>$votes</center></td>";
print "<td width=\"50\"><center>$percent</center></td></tr>\n";
}
print "</table></td></tr></table></center>\n";
print "</body></html>\n";
exit;
}
sub delete {
&checkpassword;
($type,$num,$topic) = split(/\|/, $FORM{'which'});
if ($type eq "c") {
open (FILE, "$data_path/ch$topic.txt");
@lines = <FILE>;
close(FILE);
open (FILE, ">$data_path/ch$topic.txt");
foreach $line(@lines) {
chomp($line);
($name,$votes,$numc) = split(/\|/, $line);
unless ($numc == $num) { print FILE "$line\n"; }
}
close(FILE);
}
if ($type eq "t") {
open (FILE, "$data_path/vote.txt");
@lines = <FILE>;
close(FILE);
open (FILE, ">$data_path/vote.txt");
foreach $line(@lines) {
chomp($line);
($topic, $numt, $others) = split(/\|/,$line);
unless ($numt == $num) { print FILE "$line\n"; }
}
close(FILE);
unlink("$data_path/ch$num.txt");
unlink("$data_path/ip$num.txt");
unlink("$data_path/name$num.txt");
}
&admin;
}
###############################################################################
# DecodeDBOutput #
###############################################################################
sub DecodeDBOutput {
my ($Output) = @_;
my (@Outputs);
chomp ($Output);
@Outputs=split(/\Q$Spliter\E/, $Output);
for (my($i)=0;$i<=$#Outputs;$i++){
$Outputs[$i]=~s/\|\&\^\&\|/$Spliter/g;
}
@Outputs=&DecodeHTML(@Outputs);
return wantarray ? @Outputs : $Outputs[0];
}
###############################################################################
# DecodeHTML #
###############################################################################
sub DecodeHTML {
my (@Decode) = @_;
for (my($i)=0;$i<=$#Decode;$i++){
$Decode[$i] =~ s/\&\;/\&/g;
$Decode[$i] =~ s/\+/ /g;
$Decode[$i] =~ s/\|EQU\|/\=/g;
$Decode[$i] =~ s/\|PLS\|/\+/g;
$Decode[$i] =~ s/\|APO\|/\'/g;
$Decode[$i] =~ s/\"\;/\"/g;
$Decode[$i]=~s/\\n/\n/g;
}
return wantarray ? @Decode : $Decode[0];
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -