version 1.45, 2001/12/06 23:39:11
|
version 1.56, 2001/12/31 18:05:16
|
Line 2
|
Line 2
|
|
|
use DBI; |
use DBI; |
use CGI ':all'; |
use CGI ':all'; |
use Text::Query; |
#use Text::Query; |
use strict; |
use strict; |
use Time::Local; |
use Time::Local; |
use POSIX qw(locale_h); |
use POSIX qw(locale_h); |
use locale; |
use locale; |
#open STDERR, ">errors1"; |
open STDERR, ">errors1"; |
my $printqueries=0; |
my $printqueries=0; |
my %forbidden=(); |
my %forbidden=(); |
my $debug=0; #added by R7 |
my $debug=0; #added by R7 |
|
if (param('debug')) {$debug=1; $printqueries=1} |
|
*STDERR=*STDOUT if $debug; |
my %fieldname= (0,'Question', 1, 'Answer', 2, 'Comments', 3, 'Authors', 4, 'Sources'); |
my %fieldname= (0,'Question', 1, 'Answer', 2, 'Comments', 3, 'Authors', 4, 'Sources'); |
my %rusfieldname=('Question','÷ÏÐÒÏÓ', 'Answer', 'ïÔ×ÅÔ', |
my %rusfieldname=('Question','÷ÏÐÒÏÓ', 'Answer', 'ïÔ×ÅÔ', |
'Comments', 'ëÏÍÍÅÎÔÁÒÉÉ', 'Authors', 'á×ÔÏÒ', |
'Comments', 'ëÏÍÍÅÎÔÁÒÉÉ', 'Authors', 'á×ÔÏÒ', |
Line 21 my $RL=qr/[êãõëåîçûýúèÿüöäìïòðá÷ùæñþóíéô
|
Line 23 my $RL=qr/[êãõëåîçûýúèÿüöäìïòðá÷ùæñþóíéô
|
my $RLrl=qr/(?:(?:${rl})|(?:${RL}))+/; |
my $RLrl=qr/(?:(?:${rl})|(?:${RL}))+/; |
my $l=qr/(?:(?:${RLrl})|(?:[\w\-]))+/; |
my $l=qr/(?:(?:${RLrl})|(?:[\w\-]))+/; |
my $Ll=qr/(?:[A-Z])|(?:${RL})/; |
my $Ll=qr/(?:[A-Z])|(?:${RL})/; |
|
my %metodchar=('rus',1,'old',2); |
|
|
|
|
|
|
my $thislocale; |
my $thislocale; |
|
|
$searchin{$_}=1 foreach param('searchin'); |
$searchin{$_}=1 foreach param('searchin'); |
#$searchin{'Question'}=param('Question'); |
my %TypeName=('children'=>'ä', 'game'=>'é', |
#$searchin{'Answer'}=param('Answer'); |
'chgk'=>'þ', 'brain'=>'â', 'beskrylka'=>'ì','ehruditka'=>'ü'); |
#$searchin{'Comments'}=param('Comments'); |
|
#$searchin{'Authors'}=param('Authors'); |
|
#$searchin{'Sources'}=param('Sources'); |
|
my $all=param('all'); |
my $all=param('all'); |
$all=0 if lc $all eq 'no'; |
$all=0 if lc $all eq 'no'; |
my ($PWD) = `pwd`; |
my ($PWD) = `pwd`; |
Line 73 sub GetTournament {
|
Line 75 sub GetTournament {
|
foreach $name (@{$sth->{NAME}}) { |
foreach $name (@{$sth->{NAME}}) { |
$Tournament{$name} = $arr[$i++]; |
$Tournament{$name} = $arr[$i++]; |
} |
} |
|
$sth->finish; |
return %Tournament; |
return %Tournament; |
} |
} |
|
|
Line 94 sub GetQuestion {
|
Line 96 sub GetQuestion {
|
$Question{$name} = $arr[$i++]; |
$Question{$name} = $arr[$i++]; |
} |
} |
|
|
|
$sth->finish; |
return %Question; |
return %Question; |
} |
} |
|
|
Line 103 sub GetTourQuestions {
|
Line 106 sub GetTourQuestions {
|
my (@arr, @Questions); |
my (@arr, @Questions); |
|
|
my ($sth) = $dbh->prepare("SELECT QuestionId FROM Questions |
my ($sth) = $dbh->prepare("SELECT QuestionId FROM Questions |
WHERE ParentId=$ParentId ORDER BY QuestionId"); |
WHERE ParentId=$ParentId"); |
|
|
$sth->execute; |
$sth->execute; |
|
|
Line 111 sub GetTourQuestions {
|
Line 114 sub GetTourQuestions {
|
push @Questions, $arr[0]; |
push @Questions, $arr[0]; |
} |
} |
|
|
|
$sth->finish; |
return @Questions; |
return @Questions; |
} |
} |
|
|
Line 127 sub GetTours {
|
Line 131 sub GetTours {
|
while (@arr = $sth->fetchrow) { |
while (@arr = $sth->fetchrow) { |
push @Tours, $arr[0]; |
push @Tours, $arr[0]; |
} |
} |
|
$sth->finish; |
return @Tours; |
return @Tours; |
} |
} |
|
|
Line 141 print "timeb=".time.br if $debug;
|
Line 145 print "timeb=".time.br if $debug;
|
$sth->execute; |
$sth->execute; |
my @a=$sth->fetchrow; |
my @a=$sth->fetchrow; |
print "timee0=".time.br if $debug; |
print "timee0=".time.br if $debug; |
|
$sth->finish; |
$a[0]||0; |
$a[0]||0; |
} |
} |
|
|
Line 151 sub printform
|
Line 156 sub printform
|
my $submit=submit(-value=>'ðÏÉÓË'); |
my $submit=submit(-value=>'ðÏÉÓË'); |
my $inputstring=textfield(-name=>'sstr', |
my $inputstring=textfield(-name=>'sstr', |
-default=>param('sstr')||'', |
-default=>param('sstr')||'', |
-size=>50); |
-size=>30, |
|
-maxlength=>30); |
|
my $qnumber="÷Ù×ÏÄÉÔØ ÐÏ".br. textfield(-name=>'kvo', |
|
-default=>param('kvo')||'150', |
|
-size=>3, |
|
-maxlength=>5). br."×ÏÐÒÏÓÏ×"; |
|
|
my @df=keys %searchin; |
my @df=keys %searchin; |
@df=('Question', 'Answer') unless @df; |
@df=('Question', 'Answer') unless @df; |
my $fields=checkbox_group('searchin',['Question','Answer','Comments','Authors','Sources'], [@df], |
my $fields=checkbox_group('searchin',['Question','Answer','Comments','Authors','Sources'], [@df], |
Line 174 table(Tr
|
Line 185 table(Tr
|
( |
( |
td({-valign=>'TOP'},$inputstring.$submit.p."íÅÔÏÄ: $metod".p."óÌÏ×Á: $all"), |
td({-valign=>'TOP'},$inputstring.$submit.p."íÅÔÏÄ: $metod".p."óÌÏ×Á: $all"), |
td({-valign=>'TOP'},(' 'x 8).'ðÏÌÑ:'), |
td({-valign=>'TOP'},(' 'x 8).'ðÏÌÑ:'), |
td({-valign=>'TOP'},$fields) |
td({-valign=>'TOP'},$fields), td(" "x5), |
|
td({-valign=>'TOP'},$qnumber) |
) |
) |
) |
) |
|
|
Line 265 print "$query",br if $printqueries;
|
Line 277 print "$query",br if $printqueries;
|
{ |
{ |
push (@{$nf[$i]},$arr[0]) |
push (@{$nf[$i]},$arr[0]) |
} |
} |
|
$sth->finish; |
} |
} |
|
|
|
|
Line 311 print STDERR "!$query\n",br if $printque
|
Line 324 print STDERR "!$query\n",br if $printque
|
{ |
{ |
@blob=(@blob,unpack 'C*',$arr[0]); |
@blob=(@blob,unpack 'C*',$arr[0]); |
} |
} |
|
$sth->finish; |
$query="select number from nf where ".(join ' OR ', @arr1); |
$query="select number from nf where ".(join ' OR ', @arr1); |
print "$query\n",br if $printqueries; |
print "$query\n",br if $printqueries; |
$sth=$dbh -> prepare($query); |
$sth=$dbh -> prepare($query); |
Line 320 print "$query\n",br if $printqueries;
|
Line 334 print "$query\n",br if $printqueries;
|
{ |
{ |
$frequence[$i]+=$arr[0]; |
$frequence[$i]+=$arr[0]; |
} |
} |
|
$sth->finish; |
|
|
|
|
if (@blob < 4) |
if (@blob < 4) |
Line 441 sub Search {
|
Line 455 sub Search {
|
my $sstr=$$s; |
my $sstr=$$s; |
my (@arr, @Questions, @fields); |
my (@arr, @Questions, @fields); |
my (@sar, $i, $sth,$where,$query); |
my (@sar, $i, $sth,$where,$query); |
my $ip=$ENV{'REMOTE_ADDR'}; |
# my $ip=$ENV{'REMOTE_ADDR'}; |
|
|
$ip=$dbh->quote($ip); |
# $ip=$dbh->quote($ip); |
$query= |
# $query= |
"INSERT into queries (query,metod,searchin,ip) |
# "INSERT into queries (query,metod,searchin,ip) |
values (". $dbh->quote($sstr).', '. |
# values (". $dbh->quote($sstr).', '. |
$dbh->quote($metod) . ', ' . |
# $dbh->quote($metod) . ', ' . |
$dbh->quote(join ' ', grep $searchin{$_}, keys %searchin) . |
# $dbh->quote(join ' ', grep $searchin{$_}, keys %searchin) . |
", $ip)"; |
# ", $ip)"; |
print $query if $printqueries; |
#print $query if $printqueries; |
$dbh -> do ($query); |
# $dbh -> do ($query); |
if ($metod eq 'rus') |
if ($metod eq 'rus') |
{ |
{ |
my @tasks=russearch($dbh,$sstr,$all,$allnf); |
my @tasks=russearch($dbh,$sstr,$all,$allnf); |
Line 527 print $query if $printqueries;
|
Line 541 print $query if $printqueries;
|
while (@arr = $sth->fetchrow) { |
while (@arr = $sth->fetchrow) { |
push @Questions, $arr[0] unless $forbidden{$arr[0]}; |
push @Questions, $arr[0] unless $forbidden{$arr[0]}; |
} |
} |
|
$sth->finish; |
print "@Questions" if $printqueries; |
print "@Questions" if $printqueries; |
return @Questions; |
return @Questions; |
} |
} |
Line 537 print "@Questions" if $printqueries;
|
Line 551 print "@Questions" if $printqueries;
|
Ðð Òò Óó Ôô Õõ Ææ Èè Ãã Þþ Ûû Ýý Øø Ùù Üü Àà Ññ/; |
Ðð Òò Óó Ôô Õõ Ææ Èè Ãã Þþ Ûû Ýý Øø Ùù Üü Àà Ññ/; |
|
|
sub NoCase { |
sub NoCase { |
my ($sstr) = shift; |
my ($sstr) = shift; |
my ($res); |
my ($res); |
|
|
if (($res) = grep(/$sstr/, @letters)) { |
if (($res) = grep(/$sstr/, @letters)) { |
Line 548 sub NoCase {
|
Line 562 sub NoCase {
|
} |
} |
|
|
sub PrintList { |
sub PrintList { |
my ($dbh,$Questions,$shablon)=@_; |
my ($dbh,$Questions,$shablon,$was)=@_; |
|
|
my $first=param('first') ||1; |
my $first=param('first') ||1; |
my $kvo=param('kvo') ||30; |
my $kvo=param('kvo') ||150; |
|
|
$first=$first-($first-1)%$kvo; |
$first=$first-($first-1)%$kvo; |
my $last=$first+$kvo-1; |
my $last=$first+$kvo-1; |
Line 561 sub PrintList {
|
Line 575 sub PrintList {
|
my $qs=query_string; |
my $qs=query_string; |
$qs=~s/\;/\&/g; |
$qs=~s/\;/\&/g; |
$qs=~s/\&first\=[^\&]+//g; |
$qs=~s/\&first\=[^\&]+//g; |
|
my $sstr=param('sstr'); |
|
$qs=~s/sstr=[^\&]+/sstr=$sstr/; |
|
$qs=~s/\&was=[^\&]+//; |
|
$qs.="&was=$was"; |
if ($first>$kvo*3+1) |
if ($first>$kvo*3+1) |
{ |
{ |
$nav.= |
$nav.= |
(" "x4). |
(" "x4). |
a({href=>url."?".$qs."\&first=1"},"<<").(" "x4). |
a({href=>url."?".$qs."\&first=1"},"<<").(" "x4). |
a({href=>(url."?".$qs."\&first=".($first-$kvo))},"<").(" "x4) |
a({href=>(url."?".$qs."\&first=".($first-$kvo))},"<").(" "x4) |
} |
} |
|
|
else {$nav.=' 'x15;} |
else {$nav.=' 'x15;} |
|
|
Line 640 sub PrintList {
|
Line 656 sub PrintList {
|
} |
} |
|
|
sub PrintSearch { |
sub PrintSearch { |
my ($dbh, $sstr, $metod) = @_; |
my ($dbh, $sstr, $metod,$was) = @_; |
|
my $t=time; |
print h2("ðÏÉÓË × ÂÁÚÅ ×ÏÐÒÏÓÏ×"); |
print h2("ðÏÉÓË × ÂÁÚÅ ×ÏÐÒÏÓÏ×"); |
print printform; |
print printform; |
my @allnf; |
my @allnf; |
my (@Questions) = &Search($dbh, \$sstr,$metod,$all,\@allnf); |
my @Questions; |
|
if ($was) |
|
{ |
|
my $sth=$dbh->prepare ("select sstr,questions,allnf from lastqueries where id=".param('was')); |
|
$sth->execute; |
|
my ($q,$nf); |
|
($sstr, $q,$nf)=($sth->fetchrow); |
|
@Questions=unpack 'S*',$q; |
|
@allnf=unpack 'S*',$nf; |
|
$sth->finish; |
|
} else |
|
{ |
|
@Questions=&Search($dbh, \$sstr,$metod,$all,\@allnf); |
|
my $tmp=$dbh->quote(pack("S*",@Questions)); |
|
my $qsstr=$dbh->quote($sstr); |
|
my $nf=$dbh->quote(pack("S*", @allnf)); |
|
my $ss=200; |
|
do |
|
{ |
|
$was=int rand(32000); |
|
} |
|
while (--$ss && (!$dbh->do ("insert into lastqueries (id,sstr,questions,allnf) |
|
values ($was, $qsstr,$tmp,$nf)"))); |
|
print "Something is wrong...".br unless $ss; |
|
} |
|
|
|
|
|
|
|
print p. "÷ÒÅÍÑ ÐÏÉÓËÁ: " . (time-$t) ." ÓÅË.".p; |
my ($output, $i, $suffix, $hits) = ('', 0, '', $#Questions + 1); |
my ($output, $i, $suffix, $hits) = ('', 0, '', $#Questions + 1); |
|
|
my $shablon; |
my $shablon; |
Line 663 print "$query" if $printqueries;
|
Line 708 print "$query" if $printqueries;
|
{ |
{ |
push @shablon,"(?:$arr[0])"; |
push @shablon,"(?:$arr[0])"; |
} |
} |
|
$sth->finish; |
$shablon= join "|", @shablon; |
$shablon= join "|", @shablon; |
$shablon=~s/[Å£]/\[å³\]/gi; |
$shablon=~s/[Å£]/\[å³\]/gi; |
# $shablon=~s/([ÊÃÕËÅÎÇÛÝÚÈßÆÙ×ÁÐÒÏÌÄÖÜÑÞÓÍÉÔØÂÀêãõëåîçûýúèÿæù÷áðòïìäöüñþóíéôøâà])/&NoCase($1)/ge; |
# $shablon=~s/([ÊÃÕËÅÎÇÛÝÚÈßÆÙ×ÁÐÒÏÌÄÖÜÑÞÓÍÉÔØÂÀêãõëåîçûýúèÿæù÷áðòïìäöüñþóíéôøâà])/&NoCase($1)/ge; |
$shablon=qr/$shablon/i; |
$shablon=qr/$shablon/i; |
print "!$shablon!",br if $printqueries; |
print "!$shablon!",br if $printqueries; |
|
|
} |
} |
|
|
|
|
Line 695 print "$query" if $printqueries;
|
Line 742 print "$query" if $printqueries;
|
(@sar) = split(' ', $sstr); |
(@sar) = split(' ', $sstr); |
$shablon=join "|",@sar; |
$shablon=join "|",@sar; |
} |
} |
PrintList($dbh,\@Questions,$shablon); |
PrintList($dbh,\@Questions,$shablon,$was); |
} |
} |
|
|
sub PrintRandom { |
sub PrintRandom { |
Line 719 sub PrintRandom {
|
Line 766 sub PrintRandom {
|
return $output; |
return $output; |
} |
} |
|
|
|
sub PrintEditor { |
|
my $t=shift; #ÓÓÙÌËÁ ÎÁ èÜÛ Ó ÐÏÌÑÍÉ |
|
my $ed=$$t{'Editors'}; |
|
my $edname=($ed=~/\,/ ) ? "òÅÄÁËÔÏÒÙ" : "òÅÄÁËÔÏÒ" ; |
|
return $ed? h4({align=>"center"},"$edname: $ed" ): ''; |
|
} |
|
|
sub PrintTournament { |
sub PrintTournament { |
my ($dbh, $Id, $answer) = @_; |
my ($dbh, $Id, $answer) = @_; |
my (%Tournament, @Tours, $i, $list, $qnum, $imgsrc, $alt, |
my (%Tournament, @Tours, $i, $list, $qnum, $imgsrc, $alt, |
Line 730 sub PrintTournament {
|
Line 784 sub PrintTournament {
|
my ($URL) = $Tournament{'URL'}; |
my ($URL) = $Tournament{'URL'}; |
my ($Info) = $Tournament{'Info'}; |
my ($Info) = $Tournament{'Info'}; |
my ($Copyright) = $Tournament{'Copyright'}; |
my ($Copyright) = $Tournament{'Copyright'}; |
|
my $fname=$Tournament{'FileName'}; |
@Tours = &GetTours($dbh, $Id); |
@Tours = &GetTours($dbh, $Id); |
|
$list=''; |
|
my $textid; |
if ($Id) { |
if ($Id) { |
for ($Tournament{'Type'}) { |
for ($Tournament{'Type'}) { |
/ç/ && do { |
/ç/ && do { |
Line 752 sub PrintTournament {
|
Line 807 sub PrintTournament {
|
|
|
$output .= h2({align=>"center"}, |
$output .= h2({align=>"center"}, |
"$title") . p . "\n"; |
"$title") . p . "\n"; |
|
$output.=&PrintEditor(\%Tournament); |
last; |
last; |
}; |
}; |
/ô/ && do { |
/ô/ && do { |
Line 786 sub PrintTournament {
|
Line 842 sub PrintTournament {
|
$alt = "[-]"; |
$alt = "[-]"; |
} |
} |
|
|
|
my $textid; |
|
if ($textid=$Tournament{'FileName'}) |
|
{ |
|
$textid=~s/\.txt//; |
|
} |
|
elsif ($textid=$Tournament{'Number'}) |
|
{ |
|
$fname=~s/\.txt//; |
|
$textid="$fname.$textid"; |
|
} |
|
else {$textid=$Tournament{'Id'}}; |
|
|
|
|
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'} . " " . |
. " " . $Tournament{'Title'} . " " . |
$Tournament{'PlayedAt'} . $qnum) . |
$Tournament{'PlayedAt'} . $qnum) . |
dl( |
dl( |
dd("[" |
dd("[" |
. a({href=>url . "?tour=$Tournament{'Id'}&answer=0"}, |
. a({href=>url . "?tour=$textid&answer=0"}, |
"×ÏÐÒÏÓÙ") . "] [" |
"×ÏÐÒÏÓÙ") . "] [" |
. a({href=>url . "?tour=$Tournament{'Id'}&answer=1"}, |
. a({href=>url . "?tour=$textid&answer=1"}, |
"×ÏÐÒÏÓÙ + ÏÔ×ÅÔÙ") . "]") |
"×ÏÐÒÏÓÙ + ÏÔ×ÅÔÙ") . "]") |
); |
); |
} else { |
} else { |
$list .= dd(a({href=>url . "?tour=$Tournament{'Id'}&comp=1"}, |
$list .= dd(a({href=>url . "?tour=$textid&comp=1"}, |
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=$textid&answer=0"}, |
$Tournament{'Title'}. " ". |
$Tournament{'Title'}. " ". |
$Tournament{'PlayedAt'}) . $qnum); |
$Tournament{'PlayedAt'}) . $qnum); |
} |
} |
Line 818 sub PrintTournament {
|
Line 887 sub PrintTournament {
|
$output .= p("ëÏÐÉÒÁÊÔ: " . $Copyright); |
$output .= p("ëÏÐÉÒÁÊÔ: " . $Copyright); |
} |
} |
|
|
|
|
|
|
if ($Info) { |
if ($Info) { |
$output .= p($Info); |
$output .= p($Info); |
} |
} |
|
|
return $output; |
return $output; |
} |
} |
|
|
Line 834 sub Suffix {
|
Line 904 sub Suffix {
|
} |
} |
|
|
sub IsTour { |
sub IsTour { |
my ($dbh, $Id) = @_; |
my ($dbh, $Id,$n) = @_; |
my ($sth) = $dbh->prepare("SELECT Type FROM Tournaments |
|
|
my ($sth) ; |
|
|
|
if (defined $n) |
|
{ $sth=$dbh->prepare ("select Id FROM Tournaments |
|
WHERE ParentId=$Id AND Number=$n"); |
|
} |
|
else |
|
{ |
|
$sth=$dbh->prepare("SELECT Id FROM Tournaments |
WHERE Id=$Id"); |
WHERE Id=$Id"); |
|
} |
$sth->execute; |
$sth->execute; |
return ($sth->fetchrow)[0] =~ /ô/; |
my $a=($sth->fetchrow)[0]; |
|
$sth->finish; |
|
return $a; |
} |
} |
|
|
# Gets a DB handler (ofcourse) and a tour Id. Prints all the |
# Gets a DB handler (ofcourse) and a tour Id. Prints all the |
Line 854 sub PrintTour {
|
Line 936 sub PrintTour {
|
return 0 |
return 0 |
if ($Tour{'Type'} !~ /ô/); |
if ($Tour{'Type'} !~ /ô/); |
|
|
|
my ($fname)=$Tournament{'FileName'}; |
|
$fname=~s/\.txt//; |
my ($qnum) = $Tour{'QuestionsNum'}; |
my ($qnum) = $Tour{'QuestionsNum'}; |
my ($suffix) = &Suffix($qnum); |
my ($suffix) = &Suffix($qnum); |
|
|
Line 861 sub PrintTour {
|
Line 945 sub PrintTour {
|
$Tournament{'PlayedAt'}, |
$Tournament{'PlayedAt'}, |
"<br>", $Tour{"Title"} . |
"<br>", $Tour{"Title"} . |
" ($qnum ×ÏÐÒÏÓ$suffix)\n") . p; |
" ($qnum ×ÏÐÒÏÓ$suffix)\n") . p; |
|
$output .=&PrintEditor(\%Tour); |
|
|
my (@Questions) = &GetTourQuestions($dbh, $Id); |
my (@Questions) = &GetTourQuestions($dbh, $Id); |
for ($q = 0; $q <= $#Questions; $q++) { |
for ($q = 0; $q <= $#Questions; $q++) { |
Line 883 sub PrintTour {
|
Line 968 sub PrintTour {
|
$output .= p($Tournament{'Info'}); |
$output .= p($Tournament{'Info'}); |
} |
} |
|
|
|
my $n=$Tour{'Number'}; |
if ($answer == 0) { |
if ($answer == 0) { |
$bottom .= |
$bottom .= |
"[" . a({href=>url . "?tour=$Id&answer=1"}, "ÏÔ×ÅÔÙ") . "] " . br; |
"[" . a({href=>url . "?tour=$fname.$n&answer=1"}, "ÏÔ×ÅÔÙ") . "] " . br; |
} |
} |
if (&IsTour($dbh, $Id - 1)) { |
if ($n>1) { |
$bottom .= |
$bottom .= |
"[" . a({href=>url . "?tour=" . ($Id - 1) . "&answer=0"}, |
"[" . a({href=>url . "?tour=$fname." . ($n - 1) . "&answer=0"}, |
"ÐÒÅÄÙÄÕÝÉÊ ÔÕÒ") . "] "; |
"ÐÒÅÄÙÄÕÝÉÊ ÔÕÒ") . "] "; |
$bottom .= |
$bottom .= |
"[" . a({href=>url . "?tour=" . ($Id - 1) . "&answer=1"}, |
"[" . a({href=>url . "?tour=$fname." . ($n - 1) . "&answer=1"}, |
"ÐÒÅÄÙÄÕÝÉÊ ÔÕÒ Ó ÏÔ×ÅÔÁÍÉ") . "] " . br; |
"ÐÒÅÄÙÄÕÝÉÊ ÔÕÒ Ó ÏÔ×ÅÔÁÍÉ") . "] " . br; |
} |
} |
if (&IsTour($dbh, $Id + 1)) { |
if (&IsTour($dbh, $Tour{'ParentId'}, $n + 1)) { |
$bottom .= |
$bottom .= |
"[" . a({href=>url . "?tour=" . ($Id + 1) . "&answer=0"}, |
"[" . a({href=>url . "?tour=$fname." . ($n + 1) . "&answer=0"}, |
"ÓÌÅÄÕÀÝÉÊ ÔÕÒ") . "] "; |
"ÓÌÅÄÕÀÝÉÊ ÔÕÒ") . "] "; |
$bottom .= |
$bottom .= |
"[" . a({href=>url . "?tour=" . ($Id + 1) . "&answer=1"}, |
"[" . a({href=>url . "?tour=$fname." . ($n + 1) . "&answer=1"}, |
"ÓÌÅÄÕÀÝÉÊ ÔÕÒ Ó ÏÔ×ÅÔÁÍÉ") . "] "; |
"ÓÌÅÄÕÀÝÉÊ ÔÕÒ Ó ÏÔ×ÅÔÁÍÉ") . "] "; |
} |
} |
|
|
Line 935 sub PrintQuestion {
|
Line 1020 sub PrintQuestion {
|
if ($title) { |
if ($title) { |
my (%Tour) = GetTournament($dbh, $Question{'ParentId'}); |
my (%Tour) = GetTournament($dbh, $Question{'ParentId'}); |
my (%Tournament) = GetTournament($dbh, $Tour{'ParentId'}); |
my (%Tournament) = GetTournament($dbh, $Tour{'ParentId'}); |
|
my $fname=$Tournament{'FileName'}; |
|
$fname=~s/\.txt//; |
$titles .= |
$titles .= |
dd(img({src=>"/icons/folder.open.gif"}) . " " . |
dd(img({src=>"/icons/folder.open.gif"}) . " " . |
a({href=>url . "?tour=$Tournament{'Id'}"}, $Tournament{'Title'}, $Tournament{'PlayedAt'})); |
a({href=>url . "?tour=$fname"}, $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=$fname.$Tour{Number}"}, $Tour{'Title'}))); |
} |
} |
$output .= dl(strong($titles)); |
$output .= dl(strong($titles)); |
} |
} |
Line 958 sub PrintQuestion {
|
Line 1045 sub PrintQuestion {
|
if ($Question{'Authors'}) { |
if ($Question{'Authors'}) { |
my $q=$Question{'Authors'}; |
my $q=$Question{'Authors'}; |
|
|
my $sth=$dbh->prepare("select Authors.Id,Name, Surname, Nicks from Authors, A2Q |
# my $sth=$dbh->prepare("select Authors.Id,Name, Surname, Nicks from Authors, A2Q |
where Authors.Id=Author And Question=$Id"); |
# where Authors.Id=Author And Question=$Id"); |
$sth->execute; |
# $sth->execute; |
my ($AuthorId,$Name, $Surname,$other,$Nicks); |
# my ($AuthorId,$Name, $Surname,$other,$Nicks); |
|
|
while ((($AuthorId,$Name, $Surname,$Nicks)=$sth->fetchrow),$AuthorId) |
# while ((($AuthorId,$Name, $Surname,$Nicks)=$sth->fetchrow),$AuthorId) |
{ |
# { |
my ($firstletter)=$Name=~m/^./g; |
# my ($firstletter)=$Name=~m/^./g; |
$Name=~s/\./\\\./g; |
# $Name=~s/\./\\\./g; |
my $sha="(?:$Name\\s+$Surname)|(?:$Surname\\s+$Name)|(?:$firstletter\\.\\s*$Surname)|(?:$Surname\\s+$firstletter\\.)|(?:$Surname)|(?:$Name)"; |
# my $sha="(?:$Name\\s+$Surname)|(?:$Surname\\s+$Name)|(?:$firstletter\\.\\s*$Surname)|(?:$Surname\\s+$firstletter\\.)|(?:$Surname)|(?:$Name)"; |
if ($Nicks) |
# if ($Nicks) |
{ |
# { |
$Nicks=~s/^\|//; |
# $Nicks=~s/^\|//; |
foreach (split /\|/, $Nicks) |
# foreach (split /\|/, $Nicks) |
{ |
# { |
s/\s+/ /g; |
# s/\s+/ /g; |
s/\s+$//; |
# s/\s+$//; |
s/ /\\s+/g; |
# s/ /\\s+/g; |
s/\./\\\./g; |
# s/\./\\\./g; |
if (s/>$//) {$sha="$sha|(?:$_)"} |
# if (s/>$//) {$sha="$sha|(?:$_)"} |
else {$sha="(?:$_)|$sha"} |
# else {$sha="(?:$_)|$sha"} |
} |
# } |
} |
# } |
$q=~s/($sha)/a({href=>url."?qofauthor=$AuthorId"},$1)/ei; |
# $q=~s/($sha)/a({href=>url."?qofauthor=$AuthorId"},$1)/ei; |
} |
# } |
|
|
$output .= &PrintField("á×ÔÏÒ(Ù)", $q, $text); |
$output .= &PrintField("á×ÔÏÒ(Ù)", $q, $text); |
|
|
Line 1007 sub GetQNum {
|
Line 1094 sub GetQNum {
|
my ($dbh) = @_; |
my ($dbh) = @_; |
my ($sth) = $dbh->prepare("SELECT COUNT(*) FROM Questions"); |
my ($sth) = $dbh->prepare("SELECT COUNT(*) FROM Questions"); |
$sth->execute; |
$sth->execute; |
return ($sth->fetchrow)[0]; |
my $tmp=($sth->fetchrow)[0]; |
|
$sth->finish; |
|
return $tmp; |
} |
} |
sub GetMaxQId { |
sub GetMaxQId { |
my ($dbh) = @_; |
my ($dbh) = @_; |
my ($sth) = $dbh->prepare("SELECT MAX(QuestionId) FROM Questions"); |
my ($sth) = $dbh->prepare("SELECT MAX(QuestionId) FROM Questions"); |
$sth->execute; |
$sth->execute; |
return ($sth->fetchrow)[0]; |
my $tmp=($sth->fetchrow)[0]; |
|
$sth->finish; |
|
return $tmp; |
|
|
} |
} |
|
|
# Returns Id's of 12 random questions |
# Returns Id's of 12 random questions |
Line 1024 sub Get12Random {
|
Line 1116 sub Get12Random {
|
my (%chosen); |
my (%chosen); |
srand; |
srand; |
|
|
for ($i = 0; $i < $num; $i++) { |
my $where=0; |
do { |
my $r=int (rand(10000)); |
$q = int(rand($qnum)); |
|
$sth = $dbh->prepare("SELECT Type FROM Questions |
foreach (split '', $type) |
WHERE QuestionId=$q"); |
{ |
$sth->execute; |
$where.= " OR (Type ='$_') OR (Type ='$_ä') "; |
$t = ($sth->fetchrow)[0]; |
} |
} until !$chosen{$q} && $t && $type =~ /[$t]/; |
$where.= "OR (Type='þâ')" if ($type=~/þ|â/); |
$chosen{$q} = 'y'; |
|
push @questions, $q; |
$q="select QuestionId, QuestionId/$r-floor(QuestionId/$r) as val |
|
from Questions where $where order by val limit $num"; |
|
|
|
# ëÏÇÄÁ ÎÁ ËÕÌÉÞËÁÈ ÐÏÑ×ÉÔÓÑ mysql >=3.23 ÎÁÄÏ ÚÁÍÅÎÉÔØ ÎÁ order by rand(); |
|
|
|
$sth=$dbh->prepare($q); |
|
$sth->execute; |
|
while (($i)=$sth->fetchrow) |
|
{ |
|
push @questions,$i; |
} |
} |
|
$sth->finish; |
|
for ($i=@questions; --$i;){ |
|
my $j=rand ($i+1); |
|
@questions[$i,$j]=@questions[$j,$i] unless $i==$j; |
|
} |
return @questions; |
return @questions; |
} |
} |
|
|
Line 1073 sub PrintArchive {
|
Line 1179 sub PrintArchive {
|
} |
} |
|
|
sub PrintAll { |
sub PrintAll { |
my ($dbh, $Id) = @_; |
my ($dbh, $Id,$fname) = @_; |
my ($output, $list, $i); |
my ($output, $list, $i); |
|
|
my (%Tournament) = &GetTournament($dbh, $Id); |
my (%Tournament) = &GetTournament($dbh, $Id); |
Line 1085 sub PrintAll {
|
Line 1191 sub PrintAll {
|
if ($Id == 0) { |
if ($Id == 0) { |
$output = h3("÷ÓÅ ÔÕÒÎÉÒÙ"); |
$output = h3("÷ÓÅ ÔÕÒÎÉÒÙ"); |
} else { |
} else { |
|
my $textid; |
|
if ($textid=$Tournament{'FileName'}) |
|
{ |
|
$textid=~s/\.txt//; |
|
} |
|
elsif ($textid=$Tournament{'Number'}) |
|
{ |
|
$fname=~s/\.txt//; |
|
$textid="$fname.$textid"; |
|
} |
|
else {$textid=$Tournament{'Id'}}; |
|
|
|
|
$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=$textid&answer=0"}, |
$Tournament{'Title'}) ." " . $Tournament{'PlayedAt'} . " $New"); |
$Tournament{'Title'}) ." " . $Tournament{'PlayedAt'} . " $New"); |
} |
} |
if ($Id == 0 or $Tournament{'Type'} =~ /ç/) { |
if ($Id == 0 or $Tournament{'Type'} =~ /ç/ or $Tournament{'Type'} eq '') { |
for ($i = 0; $i <= $#Tours; $i++) { |
for ($i = 0; $i <= $#Tours; $i++) { |
$list .= &PrintAll($dbh, $Tours[$i]); |
$list .= &PrintAll($dbh, $Tours[$i],$Tournament{'FileName'}); |
} |
} |
$output .= dl($list); |
$output .= dl($list); |
} |
} |
Line 1123 sub PrintDates {
|
Line 1242 sub PrintDates {
|
" " . a({href=>url . "?tour=$Tournament{'Id'}&answer=0"}, |
" " . a({href=>url . "?tour=$Tournament{'Id'}&answer=0"}, |
$Tournament{'Title'}, $Tournament{'PlayedAt'})); |
$Tournament{'Title'}, $Tournament{'PlayedAt'})); |
} |
} |
|
$sth->finish; |
$output .= dl($list); |
$output .= dl($list); |
return $output; |
return $output; |
} |
} |
Line 1142 sub PrintQOfAuthor
|
Line 1262 sub PrintQOfAuthor
|
my @Questions; |
my @Questions; |
while (($q)=$sth->fetchrow,$q) |
while (($q)=$sth->fetchrow,$q) |
{push @Questions,$q unless $forbidden{$q}} |
{push @Questions,$q unless $forbidden{$q}} |
|
$sth->finish; |
|
|
my ($output, $i, $suffix, $hits) = ('', 0, '', $#Questions + 1); |
my ($output, $i, $suffix, $hits) = ('', 0, '', $#Questions + 1); |
|
|
Line 1200 a({href=>url."?authors=surname"},"ÆÁÍÉÌÉ
|
Line 1321 a({href=>url."?authors=surname"},"ÆÁÍÉÌÉ
|
|
|
my $ar=$sth->fetchall_arrayref; |
my $ar=$sth->fetchall_arrayref; |
|
|
|
$sth->finish; |
|
|
|
|
foreach my $arr(@$ar) |
foreach my $arr(@$ar) |
Line 1215 a({href=>url."?authors=surname"},"ÆÁÍÉÌÉ
|
Line 1337 a({href=>url."?authors=surname"},"ÆÁÍÉÌÉ
|
} |
} |
} |
} |
$output.="</TABLE>"; |
$output.="</TABLE>"; |
|
$sth->finish; |
return $output; |
return $output; |
} |
} |
|
|
Line 1271 if ((uc 'Á') ne 'á') {print "Koi8-r loca
|
Line 1394 if ((uc 'Á') ne 'á') {print "Koi8-r loca
|
|
|
if (param('rand')) { |
if (param('rand')) { |
my ($type, $qnum) = ('', 12); |
my ($type, $qnum) = ('', 12); |
$type .= 'â' if (param('brain')); |
$type.=$TypeName{$_} foreach param('type'); |
$type .= 'þ' if (param('chgk')); |
# $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); |
$qnum = 0 if (!$type); |
if (param('email') && -x $SENDMAIL && |
my $Email; |
open(F, "| $SENDMAIL -t -n")) { |
if (($Email=param('email')) && -x $SENDMAIL && |
my ($Email) = param('email'); |
open(F, "| $SENDMAIL $Email")) { |
my ($mime_type) = $text ? "plain" : "html"; |
my ($mime_type) = $text ? "plain" : "html"; |
print F <<EOT; |
print F <<EOT; |
To: $Email |
To: $Email |
From: olegstemanov\@mail.ru |
From: olegstepanov\@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 1289 Content-type: text/$mime_type; charset="
|
Line 1413 Content-type: text/$mime_type; charset="
|
EOT |
EOT |
print F &PrintRandom($dbh, $type, $qnum, $text); |
print F &PrintRandom($dbh, $type, $qnum, $text); |
close F; |
close F; |
print "ðÁËÅÔ ÓÌÕÞÁÊÎÏ ×ÙÂÒÁÎÎÙÈ ×ÏÐÒÏÓÏ× ÐÏÓÌÁÎ. îÁÖÍÉÔÅ |
print "ðÁËÅÔ ÓÌÕÞÁÊÎÏ ×ÙÂÒÁÎÎÙÈ ×ÏÐÒÏÓÏ× ÐÏÓÌÁÎ ÐÏ ÁÄÒÅÓÕ $Email. îÁÖÍÉÔÅ |
ÎÁ <B>Reload</B> ÄÌÑ ÐÏÌÕÞÅÎÉÑ ÅÝÅ ÏÄÎÏÇÏ ÐÁËÅÔÁ"; |
ÎÁ <B>Reload</B> ÄÌÑ ÐÏÌÕÞÅÎÉÑ ÅÝÅ ÏÄÎÏÇÏ ÐÁËÅÔÁ"; |
} else { |
} else { |
print &PrintRandom($dbh, $type, $qnum, $text); |
print &PrintRandom($dbh, $type, $qnum, $text); |
Line 1301 EOT
|
Line 1425 EOT
|
elsif (param('qofauthor')){ |
elsif (param('qofauthor')){ |
&PrintQOfAuthor($dbh,param('qofauthor')); |
&PrintQOfAuthor($dbh,param('qofauthor')); |
} |
} |
elsif (param('sstr')) { |
elsif (param('sstr')||param('was')) { |
&PrintSearch($dbh, param('sstr'), param('metod')); |
&PrintSearch($dbh, param('sstr'), param('metod'),param('was')); |
|
$dbh->do("delete from lastqueries where |
|
time_to_sec(now())-time_to_sec(t) >3600") |
} |
} |
elsif (param('qid')) { |
elsif (param('qid')) { |
my $qid=param('qid'); |
my $qid=param('qid'); |
Line 1311 print $query if $printqueries;
|
Line 1437 print $query if $printqueries;
|
my $sth=$dbh->prepare($query); |
my $sth=$dbh->prepare($query); |
$sth->execute; |
$sth->execute; |
my $sstr= join ' ',$sth->fetchrow; |
my $sstr= join ' ',$sth->fetchrow; |
|
$sth->finish; |
$searchin{'Question'}=1; |
$searchin{'Question'}=1; |
$searchin{'Answer'}=1; |
$searchin{'Answer'}=1; |
$sstr=~tr/£³/Åå/; |
$sstr=~tr/£³/Åå/; |
Line 1348 $sstr=~s/[^ÊÃÕËÅÎÇÛÝÚÈßÆÙ×ÁÐÒÏÌÄÖÜÑÞÓÍÉÔ
|
Line 1475 $sstr=~s/[^ÊÃÕËÅÎÇÛÝÚÈßÆÙ×ÁÐÒÏÌÄÖÜÑÞÓÍÉÔ
|
|
|
} else { |
} else { |
$tour = (param('tour')) ? param('tour') : 0; |
$tour = (param('tour')) ? param('tour') : 0; |
|
my $sth; |
if ($tour !~ /^[0-9]*$/) { |
if ($tour !~ /^[0-9]*$/) { |
my ($sth) = $dbh->prepare("SELECT Id FROM Tournaments |
if ($tour=~/\./) |
WHERE FileName = '$tour.txt'"); |
{ |
$sth->execute; |
my ($fname,$n)= split /\./ , $tour; |
$tour = ($sth->fetchrow)[0]; |
|
|
$sth = $dbh->prepare( |
|
"SELECT t2.Id FROM Tournaments as t1, |
|
Tournaments as t2 |
|
WHERE t1.FileName = '$fname.txt' |
|
AND t1.Id=t2.ParentId AND t2.Number=$n"); |
|
} |
|
else |
|
{ |
|
$sth = $dbh->prepare("SELECT Id FROM Tournaments |
|
WHERE FileName = '$tour.txt'"); |
|
} |
|
$sth->execute; |
|
$tour = ($sth->fetchrow)[0]; |
|
$sth->finish; |
} |
} |
print &PrintTournament($dbh, $tour, param('answer')); |
print &PrintTournament($dbh, $tour, param('answer')); |
} |
} |