version 1.1, 2000/10/15 19:49:22
|
version 1.11, 2000/10/24 17:59:25
|
Line 9 use POSIX qw(locale_h);
|
Line 9 use POSIX qw(locale_h);
|
my ($PWD) = `pwd`; |
my ($PWD) = `pwd`; |
chomp $PWD; |
chomp $PWD; |
my ($SRCPATH) = "$PWD/../dimrub/src"; |
my ($SRCPATH) = "$PWD/../dimrub/src"; |
my ($ZIP) = "/usr/local/bin/zip"; |
my ($ZIP) = "/home/piataev/bin/zip"; |
|
my $DUMPFILE = "/tmp/chgkdump"; |
my ($SENDMAIL) = "/usr/sbin/sendmail"; |
my ($SENDMAIL) = "/usr/sbin/sendmail"; |
my ($TMSECS) = 30*24*60*60; |
my ($TMSECS) = 30*24*60*60; |
my (%RevMonths) = |
my (%RevMonths) = |
('Jan', '0', 'Feb', '1', 'Mar', '2', 'Apr', '3', 'May', '4', 'Jun', '5', |
('Jan', '0', 'Feb', '1', 'Mar', '2', 'Apr', '3', 'May', '4', 'Jun', '5', |
'Jul', '6', 'Aug', '7', 'Sep', '8', 'Oct', '9', 'Nov', '10', |
'Jul', '6', 'Aug', '7', 'Sep', '8', 'Oct', '9', 'Nov', '10', |
'Dec', '11'); |
'Dec', '11', |
|
'ñÎ×', '0', 'æÅ×', 1, 'íÁÒ', 2, 'áÐÒ', 3, 'íÁÊ', '4', |
|
'éÀÎ', '5', 'éÀÌ', 6, 'á×Ç', '7', 'óÅÎ', '8', |
|
'ïËÔ', '9', 'îÏÑ', '19', 'äÅË', '11'); |
|
|
# Determine whether the given time is within 2 months from now. |
# Determine whether the given time is within 2 months from now. |
sub NewEnough { |
sub NewEnough { |
Line 105 sub Search {
|
Line 109 sub Search {
|
my (@arr, @Questions, @fields); |
my (@arr, @Questions, @fields); |
my (@sar, $i, $sth); |
my (@sar, $i, $sth); |
|
|
push @fields, 'Question'; |
# push @fields, 'Question'; |
foreach (qw/Answer Sources Authors Comments/) { |
foreach (qw/Question Answer Sources Authors Comments/) { |
if (param($_)) { |
if (param($_)) { |
push @fields, "IFNULL($_, '')"; |
push @fields, "IFNULL($_, '')"; |
} |
} |
Line 221 sub PrintTournament {
|
Line 225 sub PrintTournament {
|
for ($Tournament{'Type'}) { |
for ($Tournament{'Type'}) { |
/ç/ && do { |
/ç/ && do { |
$output .= h2({align=>"center"}, |
$output .= h2({align=>"center"}, |
"çÒÕÐÐÁ: $Tournament{'Title'}") . p . "\n"; |
"çÒÕÐÐÁ: $Tournament{'Title'} ", |
|
"$Tournament{'PlayedAt'}") . p . "\n"; |
last; |
last; |
}; |
}; |
/þ/ && do { |
/þ/ && do { |
return &PrintTour($dbh, $Tours[0], $answer) |
return &PrintTour($dbh, $Tours[0], $answer) |
if ($#Tours == 0); |
if ($#Tours == 0); |
|
|
|
my $title="ðÁËÅÔ: $Tournament{'Title'}"; |
|
if ($Tournament{'PlayedAt'}) { |
|
$title .= " $Tournament{'PlayedAt'}"; |
|
} |
|
|
$output .= h2({align=>"center"}, |
$output .= h2({align=>"center"}, |
"þÅÍÐÉÏÎÁÔ: $Tournament{'Title'}") . p . "\n"; |
"$title") . p . "\n"; |
last; |
last; |
}; |
}; |
/ô/ && do { |
/ô/ && do { |
Line 266 sub PrintTournament {
|
Line 276 sub PrintTournament {
|
|
|
if ($SingleTour or $Tournament{'Type'} =~ /ô/) { |
if ($SingleTour or $Tournament{'Type'} =~ /ô/) { |
$list .= dd(img({src=>$imgsrc, alt=>$alt}) |
$list .= dd(img({src=>$imgsrc, alt=>$alt}) |
. " " . $Tournament{'Title'} . $qnum) . |
. " " . $Tournament{'Title'} . " " . |
|
$Tournament{'PlayedAt'} . $qnum) . |
dl( |
dl( |
dd("[" |
dd("[" |
. a({href=>url . "?tour=$Tournament{'Id'}&answer=0"}, |
. a({href=>url . "?tour=$Tournament{'Id'}&answer=0"}, |
Line 279 sub PrintTournament {
|
Line 290 sub PrintTournament {
|
img({src=>'/icons/compressed.gif', alt=>'[ZIP]', border=>1})) |
img({src=>'/icons/compressed.gif', alt=>'[ZIP]', border=>1})) |
. " " . img({src=>$imgsrc, alt=>$alt}) |
. " " . img({src=>$imgsrc, alt=>$alt}) |
. " " . a({href=>url . "?tour=$Tournament{'Id'}&answer=0"}, |
. " " . a({href=>url . "?tour=$Tournament{'Id'}&answer=0"}, |
$Tournament{'Title'}) . $qnum); |
$Tournament{'Title'}. " ". |
|
$Tournament{'PlayedAt'}) . $qnum); |
} |
} |
} |
} |
$output .= dl($list); |
$output .= dl($list); |
Line 333 sub PrintTour {
|
Line 345 sub PrintTour {
|
my ($qnum) = $Tour{'QuestionsNum'}; |
my ($qnum) = $Tour{'QuestionsNum'}; |
my ($suffix) = &Suffix($qnum); |
my ($suffix) = &Suffix($qnum); |
|
|
$output .= h2({align=>"center"}, $Tour{"Title"} . |
$output .= h2({align=>"center"}, $Tournament{"Title"}, |
|
$Tournament{'PlayedAt'}, |
|
"<br>", $Tour{"Title"} . |
" ($qnum ×ÏÐÒÏÓ$suffix)\n") . p; |
" ($qnum ×ÏÐÒÏÓ$suffix)\n") . p; |
|
|
my (@Questions) = &GetTourQuestions($dbh, $Id); |
my (@Questions) = &GetTourQuestions($dbh, $Id); |
Line 388 sub PrintTour {
|
Line 402 sub PrintTour {
|
sub PrintField { |
sub PrintField { |
my ($header, $value, $text) = @_; |
my ($header, $value, $text) = @_; |
if ($text) { |
if ($text) { |
$value =~ s/<[\/\w]*>//sg; |
$value =~ s/<[\/\w]*>//sg; |
|
} else { |
|
$value =~ s/^\s+/<br> /mg; |
|
$value =~ s/^\|([^\n]*)/<pre>$1<\/pre>/mg; |
} |
} |
return $text ? "$header:\n$value\n\n" : |
return $text ? "$header:\n$value\n\n" : |
strong("$header: ") . $value . p . "\n"; |
strong("$header: ") . $value . p . "\n"; |
Line 408 sub PrintQuestion {
|
Line 425 sub PrintQuestion {
|
my (%Tournament) = GetTournament($dbh, $Tour{'ParentId'}); |
my (%Tournament) = GetTournament($dbh, $Tour{'ParentId'}); |
$titles .= |
$titles .= |
dd(img({src=>"/icons/folder.open.gif"}) . " " . |
dd(img({src=>"/icons/folder.open.gif"}) . " " . |
a({href=>url . "?tour=$Tournament{'Id'}"}, $Tournament{'Title'})); |
a({href=>url . "?tour=$Tournament{'Id'}"}, $Tournament{'Title'}, $Tournament{'PlayedAt'})); |
$titles .= |
$titles .= |
dl(dd(img({src=>"/icons/folder.open.gif"}) . " " . |
dl(dd(img({src=>"/icons/folder.open.gif"}) . " " . |
a({href=>url . "?tour=$Tour{'Id'}"}, $Tour{'Title'}))); |
a({href=>url . "?tour=$Tour{'Id'}"}, $Tour{'Title'}))); |
Line 457 sub Get12Random {
|
Line 474 sub Get12Random {
|
my (%chosen); |
my (%chosen); |
srand; |
srand; |
|
|
for ($i = 0; $i < $num; $i++) { |
for ($i = 0; $i < $num; $i++) { |
do { |
do { |
$q = int(rand($qnum)); |
$q = int(rand($qnum)); |
$sth = $dbh->prepare("SELECT Type FROM Questions |
$sth = $dbh->prepare("SELECT Type FROM Questions |
WHERE QuestionId=$q"); |
WHERE QuestionId=$q"); |
$sth->execute; |
$sth->execute; |
$t = ($sth->fetchrow)[0]; |
$t = ($sth->fetchrow)[0]; |
} until !$chosen{$q} && $t =~ /$type/; |
} until !$chosen{$q} && $t && $type =~ /[$t]/; |
$chosen{$q} = 'y'; |
$chosen{$q} = 'y'; |
push @questions, $q; |
push @questions, $q; |
} |
} |
return @questions; |
return @questions; |
} |
} |
|
|
sub Include_virtual { |
sub Include_virtual { |
my ($fn, $output) = (@_, ''); |
my ($fn, $output) = (@_, ''); |
|
|
open F , $fn |
open F , $fn |
or die "Can't open the file $fn: $!\n"; |
or return; #die "Can't open the file $fn: $!\n"; |
|
|
while (<F>) { |
while (<F>) { |
if (/<!--#include/o) { |
if (/<!--#include/o) { |
Line 520 sub PrintAll {
|
Line 537 sub PrintAll {
|
} else { |
} else { |
$output .= dd(img({src=>"/icons/folder.gif", alt=>"[*]"}) . |
$output .= dd(img({src=>"/icons/folder.gif", alt=>"[*]"}) . |
" " . a({href=>url . "?tour=$Tournament{'Id'}&answer=0"}, |
" " . a({href=>url . "?tour=$Tournament{'Id'}&answer=0"}, |
$Tournament{'Title'}) . " $New"); |
$Tournament{'Title'}) ." " . $Tournament{'PlayedAt'} . " $New"); |
} |
} |
if ($Id == 0 or $Tournament{'Type'} =~ /ç/) { |
if ($Id == 0 or $Tournament{'Type'} =~ /ç/) { |
for ($i = 0; $i <= $#Tours; $i++) { |
for ($i = 0; $i <= $#Tours; $i++) { |
Line 554 sub PrintDates {
|
Line 571 sub PrintDates {
|
%Tournament = &GetTournament($dbh, $array[0]); |
%Tournament = &GetTournament($dbh, $array[0]); |
$list .= dd(img({src=>"/icons/folder.gif", alt=>"[*]"}) . |
$list .= dd(img({src=>"/icons/folder.gif", alt=>"[*]"}) . |
" " . a({href=>url . "?tour=$Tournament{'Id'}&answer=0"}, |
" " . a({href=>url . "?tour=$Tournament{'Id'}&answer=0"}, |
$Tournament{'Title'})); |
$Tournament{'Title'}, $Tournament{'PlayedAt'})); |
} |
} |
$output .= dl($list); |
$output .= dl($list); |
return $output; |
return $output; |
Line 573 MAIN:
|
Line 590 MAIN:
|
print end_html; |
print end_html; |
die "Can't connect to DB chgk\n"; |
die "Can't connect to DB chgk\n"; |
}; |
}; |
if (!param('comp') and !$text) { |
if (!param('comp') and !param('sqldump') and !$text) { |
print header; |
print header; |
print start_html(-"title"=>'Database of the questions', |
print start_html(-"title"=>'Database of the questions', |
-author=>'dimrub@icomverse.com', |
-author=>'dimrub@icomverse.com', |
Line 587 MAIN:
|
Line 604 MAIN:
|
} |
} |
|
|
if (param('rand')) { |
if (param('rand')) { |
my ($type, $qnum) = ('þ', 12); |
my ($type, $qnum) = ('', 12); |
$type = 'â' if (param('brain')); |
$type .= 'â' if (param('brain')); |
|
$type .= 'þ' if (param('chgk')); |
$qnum = param('qnum') if (param('qnum') =~ /^\d+$/); |
$qnum = param('qnum') if (param('qnum') =~ /^\d+$/); |
|
$qnum = 0 if (!$type); |
if (param('email') && -x $SENDMAIL && |
if (param('email') && -x $SENDMAIL && |
open(F, "| $SENDMAIL -t -n")) { |
open(F, "| $SENDMAIL -t -n")) { |
my ($Email) = param('email'); |
my ($Email) = param('email'); |
my ($mime_type) = $text ? "plain" : "html"; |
my ($mime_type) = $text ? "plain" : "html"; |
print F <<EOT; |
print F <<EOT; |
To: $Email |
To: $Email |
From: dimrub\@icomverse.com |
From: olegstemanov\@mail.ru |
Subject: Sluchajnij Paket Voprosov "Chto? Gde? Kogda?" |
Subject: Sluchajnij Paket Voprosov "Chto? Gde? Kogda?" |
MIME-Version: 1.0 |
MIME-Version: 1.0 |
Content-type: text/$mime_type; charset="koi8-r" |
Content-type: text/$mime_type; charset="koi8-r" |
Line 616 EOT
|
Line 635 EOT
|
} elsif (param('from_year') && param('to_year')) { |
} elsif (param('from_year') && param('to_year')) { |
print &PrintDates($dbh); |
print &PrintDates($dbh); |
} elsif (param('comp')) { |
} elsif (param('comp')) { |
print header( |
print header( |
-'Content-Type' => 'application/x-zip-compressed; name="db.zip"', |
-'Content-Type' => 'application/x-zip-compressed; name="db.zip"', |
-'Content-Disposition' => 'attachment; filename="db.zip"' |
-'Content-Disposition' => 'attachment; filename="db.zip"' |
); |
); |
$tour = (param('tour')) ? param('tour') : 0; |
$tour = (param('tour')) ? param('tour') : 0; |
my (@files) = &PrintArchive($dbh, $tour); |
my (@files) = &PrintArchive($dbh, $tour); |
open F, "$ZIP -j - $SRCPATH/COPYRIGHT @files |"; |
open F, "$ZIP -j - $SRCPATH/COPYRIGHT @files |"; |
print (<F>); |
print (<F>); |
close F; |
close F; |
$dbh->disconnect; |
$dbh->disconnect; |
exit; |
exit; |
|
} elsif (param('sqldump')) { |
|
print header( |
|
-'Content-Type' => 'application/x-zip-compressed; name="dump.zip"', |
|
-'Content-Disposition' => 'attachment; filename="dump.zip"' |
|
); |
|
open F, "$ZIP -j - $DUMPFILE |"; |
|
print (<F>); |
|
close F; |
|
$dbh->disconnect; |
|
exit; |
|
|
} else { |
} else { |
$tour = (param('tour')) ? param('tour') : 0; |
$tour = (param('tour')) ? param('tour') : 0; |
if ($tour !~ /^[0-9]*$/) { |
if ($tour !~ /^[0-9]*$/) { |