version 1.23, 2001/10/18 19:45:26
|
version 1.39, 2001/12/03 02:28:56
|
Line 1
|
Line 1
|
#!/usr/local/bin/perl -w |
#!/usr/bin/perl -w |
|
|
use DBI; |
use DBI; |
use CGI ':all'; |
use CGI ':all'; |
Line 7 use strict;
|
Line 7 use strict;
|
use Time::Local; |
use Time::Local; |
use POSIX qw(locale_h); |
use POSIX qw(locale_h); |
use locale; |
use locale; |
open STDERR, ">errors"; |
#open STDERR, ">errors1"; |
my $printqueries=1; |
my $printqueries=0; |
my %fieldname= (0,'Question', 1, 'Answer', 2, 'Comments'); |
my %forbidden=(); |
|
my $debug=0; #added by R7 |
|
my %fieldname= (0,'Question', 1, 'Answer', 2, 'Comments', 3, 'Authors', 4, 'Sources'); |
my %searchin; |
my %searchin; |
|
|
|
|
Line 19 my $thislocale;
|
Line 21 my $thislocale;
|
|
|
$searchin{'question'}=param('Question'); |
$searchin{'question'}=param('Question'); |
$searchin{'answer'}=param('Answer'); |
$searchin{'answer'}=param('Answer'); |
$searchin{'comment'}=param('Comment'); |
$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 29 my ($ZIP) = "/home/piataev/bin/zip";
|
Line 33 my ($ZIP) = "/home/piataev/bin/zip";
|
my $DUMPFILE = "/tmp/chgkdump"; |
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', |
'Янв', '0', 'Фев', 1, 'Мар', 2, 'Апр', 3, 'Май', '4', |
'Июн', '5', 'Июл', 6, 'Авг', '7', 'Сен', '8', |
'Июн', '5', 'Июл', 6, 'Авг', '7', 'Сен', '8', |
'Окт', '9', 'Ноя', '19', 'Дек', '11'); |
'Окт', '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. |
Line 89 sub GetTourQuestions {
|
Line 93 sub GetTourQuestions {
|
my ($dbh, $ParentId) = @_; |
my ($dbh, $ParentId) = @_; |
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 ORDER BY QuestionId"); |
|
|
$sth->execute; |
$sth->execute; |
Line 142 $sstr=~tr/йцукенгшщзхъфывапролджэячсмить
|
Line 146 $sstr=~tr/йцукенгшщзхъфывапролджэячсмить
|
foreach $i (0..$#w) # заполняем массив @nf начальных форм |
foreach $i (0..$#w) # заполняем массив @nf начальных форм |
# $nf[$i] -- ссылка на массив возможных |
# $nf[$i] -- ссылка на массив возможных |
# начальных форм словоформы $i |
# начальных форм словоформы $i |
{ |
{ |
$qw= $dbh->quote (uc $w[$i]); |
$qw= $dbh->quote (uc $w[$i]); |
$query=" select distinct w2 from nests |
$query=" select distinct w2 from nests |
where w1=$qw"; |
where w1=$qw"; |
Line 156 print "$query",br if $printqueries;
|
Line 160 print "$query",br if $printqueries;
|
} |
} |
} |
} |
|
|
my @bad=grep {!$nf[$_]} 0..$#w; # @bad -- номера словоформ, |
|
|
my @bad=grep {!@{$nf[$_]}} 0..$#w; # @bad -- номера словоформ, |
# которых нет в словаре |
# которых нет в словаре |
|
|
if (@bad) #есть неопознанные словоформы |
if (@bad) #есть неопознанные словоформы |
Line 172 print "$query",br if $printqueries;
|
Line 177 print "$query",br if $printqueries;
|
} |
} |
return () if ($all && @verybad); |
return () if ($all && @verybad); |
|
|
|
|
my $kvo=0; |
my $kvo=0; |
push @$allnf, @{$_} foreach @nf; |
push @$allnf, @{$_} foreach @nf; |
|
print "nf=@$allnf" if $printqueries; |
|
|
foreach $i (0..$#w) #запросы в базу... |
foreach $i (0..$#w) #запросы в базу... |
{ |
{ |
Line 185 print "$query",br if $printqueries;
|
Line 192 print "$query",br if $printqueries;
|
|
|
$_= " word2question.word=".$_. ' ' foreach @arr; |
$_= " word2question.word=".$_. ' ' foreach @arr; |
$_= " nf.id=".$_. ' ' foreach @arr1; |
$_= " nf.id=".$_. ' ' foreach @arr1; |
|
# @arr=(0) unless @arr; |
# $_= " nests.w2=".$_. ' ' foreach @arr2; |
|
# $query="select w1 from nests where". (join ' OR ', @arr2); |
|
#print $query if $printqueries; |
|
# $sth=$dbh -> prepare($query); |
|
# $sth->execute; |
|
# while (@ar=$sth->fetchrow) |
|
# { |
|
# $ar[0]=~s/(.)/&nocase($1)/ge; |
|
# push(@sf,'(?:'.$ar[0].')'); |
|
# } |
|
# $selectshablon=join '|',@sf; |
|
|
|
#print $selectshablon,br if $printqueries; |
|
|
|
# $selectshablon=qr/$selectshablon/i; |
|
|
|
|
|
|
|
|
|
$query="select questions from word2question where". (join ' OR ', @arr); |
$query="select questions from word2question where". (join ' OR ', @arr); |
print "$query\n",br if $printqueries; |
print STDERR "!$query\n",br if $printqueries; |
|
|
$sth=$dbh -> prepare($query); |
$sth=$dbh -> prepare($query); |
$sth->execute; |
$sth->execute; |
Line 216 print "$query\n",br if $printqueries;
|
Line 204 print "$query\n",br if $printqueries;
|
{ |
{ |
@blob=(@blob,unpack 'C*',$arr[0]); |
@blob=(@blob,unpack 'C*',$arr[0]); |
} |
} |
print "blob=@blob"; |
|
$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 229 print "$query\n",br if $printqueries;
|
Line 216 print "$query\n",br if $printqueries;
|
|
|
|
|
|
|
|
|
if (@blob < 4) |
if (@blob < 4) |
{ |
{ |
$tasksof{$i}=undef; |
$tasksof{$i}=undef; |
Line 245 print "$query\n",br if $printqueries;
|
Line 231 print "$query\n",br if $printqueries;
|
# виде хэша, ключи которого -- номера вопросов, |
# виде хэша, ключи которого -- номера вопросов, |
# а значения -- списки номеров вхождений. Вот. |
# а значения -- списки номеров вхождений. Вот. |
{ |
{ |
($field,$hi,$lo,$wordnumber)=@blob[$ii..($ii+3)]; |
($field,$lo,$hi,$wordnumber)=@blob[$ii..($ii+3)]; |
$ii+=4; |
$ii+=4; |
$number=$lo+$hi*256; |
$number=$lo+$hi*256; |
print "f1=$field\n"; |
|
$field=$fieldname{$field}; |
$field=$fieldname{$field}; |
print "f2=$field\n"; |
|
if ($searchin{lc $field}) |
if ($searchin{lc $field}) |
{ |
{ |
|
|
push @{$tasksof{$i}{$number}}, $wordnumber; |
push @{$tasksof{$i}{$number}}, $wordnumber; |
# дополнили в хэше, висящем на |
# дополнили в хэше, висящем на |
# словоформе $i в %tasksof список |
# словоформе $i в %tasksof список |
Line 269 print "f2=$field\n";
|
Line 252 print "f2=$field\n";
|
} |
} |
} #foreach $i |
} #foreach $i |
|
|
print "keys tasksof", keys %tasksof; |
#print "keys tasksof", join ' ', keys %{$tasksof{0}}; |
#Ищем пересечение или объединение списков вопросов (значений %tasksof) |
#Ищем пересечение или объединение списков вопросов (значений %tasksof) |
foreach $sf (keys %tasksof) |
foreach $sf (keys %tasksof) |
{ |
{ |
$count{$_}++ foreach keys %{$tasksof{$sf}}; |
$count{$_}++ foreach keys %{$tasksof{$sf}}; |
} |
} |
Line 279 print "keys tasksof", keys %tasksof;
|
Line 262 print "keys tasksof", keys %tasksof;
|
keys %count) ; |
keys %count) ; |
|
|
|
|
#print "\n\$#tasks=",$#tasks,br; |
print "\n\$#tasks=",$#tasks,br if $printqueries; |
############ Сортировка найденных вопросов |
############ Сортировка найденных вопросов |
|
|
foreach (keys %wordsof) |
foreach (keys %wordsof) |
Line 292 foreach (keys %wordsof)
|
Line 275 foreach (keys %wordsof)
|
|
|
############ |
############ |
|
|
print "tasks=@tasks"; |
print "tasks=@tasks" if $printqueries; |
|
|
#print "$_ $relevance{$_} | " foreach @tasks; |
#print "$_ $relevance{$_} | " foreach @tasks; |
#print br; |
#print br; |
Line 349 if $$words{$first};
|
Line 332 if $$words{$first};
|
sub Search { |
sub Search { |
my ($dbh, $sstr,$metod,$all,$allnf) = @_; |
my ($dbh, $sstr,$metod,$all,$allnf) = @_; |
my (@arr, @Questions, @fields); |
my (@arr, @Questions, @fields); |
my (@sar, $i, $sth,$where); |
my (@sar, $i, $sth,$where,$query); |
|
my $ip=$ENV{'REMOTE_ADDR'}; |
|
|
# push @fields, 'Question'; |
$ip=$dbh->quote($ip); |
|
$query= |
|
"INSERT into queries (query,metod,searchin,ip) |
|
values (". $dbh->quote($sstr).', '. |
|
$dbh->quote($metod) . ', ' . |
|
$dbh->quote(join ' ', grep $searchin{$_}, keys %searchin) . |
|
", $ip)"; |
|
print $query if $printqueries; |
|
$dbh -> do ($query); |
|
|
if ($metod eq 'rus') |
if ($metod eq 'rus') |
{ |
{ |
Line 361 sub Search {
|
Line 353 sub Search {
|
|
|
|
|
###Simple and advanced query processing. Added by R7 |
###Simple and advanced query processing. Added by R7 |
if ($metod eq 'simple' || $metod eq 'advanced') |
if ($metod eq 'simple' || $metod eq 'advanced') |
{ |
{ |
foreach (qw/Question Answer Sources Authors Comments/) { |
foreach (qw/Question Answer Sources Authors Comments/) { |
if (param($_)) { |
if (param($_)) { |
push @fields, $_; |
push @fields, $_; |
} |
} |
} |
} |
|
|
|
|
@fields=(qw/Question Answer Sources Authors Comments/) unless scalar @fields; |
@fields=(qw/Question Answer Sources Authors Comments/) unless scalar @fields; |
my $fields=join ",", @fields; |
my $fields=join ",", @fields; |
my $q=new Text::Query($sstr, |
my $q=new Text::Query($sstr, |
-parse => 'Text::Query::'. |
-parse => 'Text::Query::'. |
(($metod eq 'simple') ? 'ParseSimple':'ParseAdvanced'), |
(($metod eq 'simple') ? 'ParseSimple':'ParseAdvanced'), |
-solve => 'Text::Query::SolveSQL', |
-solve => 'Text::Query::SolveSQL', |
-build => 'Text::Query::BuildSQLMySQL', |
-build => 'Text::Query::BuildSQLMySQL', |
-fields_searched => $fields); |
-fields_searched => $fields); |
|
|
$where= $$q{'matchexp'}; |
$where= $$q{'matchexp'}; |
my $query= "SELECT Questionid FROM Questions |
$query= "SELECT Questionid FROM Questions |
WHERE $where"; |
WHERE $where"; |
print br."Query is: $query".br if $printqueries; |
print br."Query is: $query".br if $debug; |
|
|
$sth = $dbh->prepare($query); |
$sth = $dbh->prepare($query); |
} else |
} else |
###### |
###### |
{ |
{ |
|
|
|
|
foreach (qw/Question Answer Sources Authors Comments/) { |
foreach (qw/Question Answer Sources Authors Comments/) { |
if (param($_)) { |
if (param($_)) { |
push @fields, "IFNULL($_, '')"; |
push @fields, "IFNULL($_, '')"; |
} |
} |
} |
} |
|
|
@sar = split " ", $sstr; |
@sar = split " ", $sstr; |
for $i (0 .. $#sar) { |
for $i (0 .. $#sar) { |
$sar[$i] = $dbh->quote("%${sar[$i]}%"); |
$sar[$i] = $dbh->quote("%${sar[$i]}%"); |
Line 408 sub Search {
|
Line 397 sub Search {
|
$sstr = join " OR $f LIKE ", @sar; |
$sstr = join " OR $f LIKE ", @sar; |
} |
} |
|
|
my $query="SELECT QuestionId FROM Questions |
my $query; |
|
$query="SELECT QuestionId FROM Questions |
WHERE $f LIKE $sstr ORDER BY QuestionId"; |
WHERE $f LIKE $sstr ORDER BY QuestionId"; |
|
|
|
|
print $query if $printqueries; |
print $query if $printqueries; |
$sth = $dbh->prepare($query) |
$sth = $dbh->prepare($query) |
|
|
Line 417 print $query if $printqueries;
|
Line 409 print $query if $printqueries;
|
|
|
$sth->execute; |
$sth->execute; |
while (@arr = $sth->fetchrow) { |
while (@arr = $sth->fetchrow) { |
push @Questions, $arr[0]; |
push @Questions, $arr[0] unless $forbidden{$arr[0]}; |
} |
} |
|
|
return @Questions; |
return @Questions; |
} |
} |
|
|
# Substitute every letter by a pair (for case insensitive search). |
# Substitute every letter by a pair (for case insensitive search). |
my (@letters) = qw/аА бБ вВ гГ дД еЕ жЖ зЗ иИ йЙ кК лЛ мМ нН оО |
my (@letters) = qw/аА бБ вВ гГ дД еЕ жЖ зЗ иИ йЙ кК лЛ мМ нН оО |
пП рР сС тТ уУ фФ хХ цЦ чЧ шШ щЩ ьЬ ыЫ эЭ юЮ яЯ/; |
пП рР сС тТ уУ фФ хХ цЦ чЧ шШ щЩ ьЬ ыЫ эЭ юЮ яЯ/; |
|
|
sub NoCase { |
sub NoCase { |
my ($sstr) = shift; |
my ($sstr) = shift; |
my ($res); |
my ($res); |
Line 446 sub PrintSearch {
|
Line 438 sub PrintSearch {
|
|
|
my $shablon; |
my $shablon; |
|
|
|
|
if ($metod eq 'rus') |
if ($metod eq 'rus') |
{ |
{ |
my $where='0'; |
my $where='0'; |
Line 461 print "$query" if $printqueries;
|
Line 452 print "$query" if $printqueries;
|
{ |
{ |
push @shablon,"(?:$arr[0])"; |
push @shablon,"(?:$arr[0])"; |
} |
} |
$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; |
Line 475 print "$query" if $printqueries;
|
Line 466 print "$query" if $printqueries;
|
} elsif ($hits =~ /1$/) { |
} elsif ($hits =~ /1$/) { |
$suffix = 'е'; |
$suffix = 'е'; |
} else { |
} else { |
$suffix = 'я'; |
$suffix = 'я'; |
} |
} |
|
|
print p({align=>"center"}, "Результаты поиска на " . strong($sstr) |
print p({align=>"center"}, "Результаты поиска на " . strong($sstr) |
. " : $hits попадани$suffix."); |
. " : $hits попадани$suffix."); |
|
|
Line 491 print "$query" if $printqueries;
|
Line 482 print "$query" if $printqueries;
|
for ($i = 0; $i <= $#Questions; $i++) { |
for ($i = 0; $i <= $#Questions; $i++) { |
$output = &PrintQuestion($dbh, $Questions[$i], 1, $i + 1, 1); |
$output = &PrintQuestion($dbh, $Questions[$i], 1, $i + 1, 1); |
if (param('metod') eq 'rus') |
if (param('metod') eq 'rus') |
{ |
{ |
$output=~s/\b($shablon)\b/\<strong\>$1\<\/strong\>/gi; |
$output=~s/\b($shablon)\b/\<strong\>$1\<\/strong\>/gi; |
} else { |
} else { |
foreach (@sar) { |
foreach (@sar) { |
Line 516 sub PrintRandom {
|
Line 507 sub PrintRandom {
|
for ($i = 0; $i <= $#Questions; $i++) { |
for ($i = 0; $i <= $#Questions; $i++) { |
# Passing DB handler, question ID, print answer, question |
# Passing DB handler, question ID, print answer, question |
# number, print title, print text/html |
# number, print title, print text/html |
$output .= |
$output .= |
&PrintQuestion($dbh, $Questions[$i], 1, $i + 1, 0, $text); |
&PrintQuestion($dbh, $Questions[$i], 1, $i + 1, 0, $text); |
} |
} |
return $output; |
return $output; |
} |
} |
|
|
sub PrintTournament { |
sub PrintTournament { |
Line 529 sub PrintTournament {
|
Line 520 sub PrintTournament {
|
my ($output) = ''; |
my ($output) = ''; |
|
|
%Tournament = &GetTournament($dbh, $Id) if ($Id); |
%Tournament = &GetTournament($dbh, $Id) if ($Id); |
|
|
my ($URL) = $Tournament{'URL'}; |
my ($URL) = $Tournament{'URL'}; |
my ($Info) = $Tournament{'Info'}; |
my ($Info) = $Tournament{'Info'}; |
my ($Copyright) = $Tournament{'Copyright'}; |
my ($Copyright) = $Tournament{'Copyright'}; |
Line 539 sub PrintTournament {
|
Line 530 sub PrintTournament {
|
if ($Id) { |
if ($Id) { |
for ($Tournament{'Type'}) { |
for ($Tournament{'Type'}) { |
/Г/ && do { |
/Г/ && do { |
$output .= h2({align=>"center"}, |
$output .= h2({align=>"center"}, |
"Группа: $Tournament{'Title'} ", |
"Группа: $Tournament{'Title'} ", |
"$Tournament{'PlayedAt'}") . p . "\n"; |
"$Tournament{'PlayedAt'}") . p . "\n"; |
last; |
last; |
Line 547 sub PrintTournament {
|
Line 538 sub PrintTournament {
|
/Ч/ && do { |
/Ч/ && do { |
return &PrintTour($dbh, $Tours[0], $answer) |
return &PrintTour($dbh, $Tours[0], $answer) |
if ($#Tours == 0); |
if ($#Tours == 0); |
|
|
my $title="Пакет: $Tournament{'Title'}"; |
my $title="Пакет: $Tournament{'Title'}"; |
if ($Tournament{'PlayedAt'}) { |
if ($Tournament{'PlayedAt'}) { |
$title .= " $Tournament{'PlayedAt'}"; |
$title .= " $Tournament{'PlayedAt'}"; |
} |
} |
|
|
$output .= h2({align=>"center"}, |
$output .= h2({align=>"center"}, |
"$title") . p . "\n"; |
"$title") . p . "\n"; |
last; |
last; |
}; |
}; |
Line 566 sub PrintTournament {
|
Line 557 sub PrintTournament {
|
$output .= h2("Банк Вопросов: $qnum вопросов") . p . "\n"; |
$output .= h2("Банк Вопросов: $qnum вопросов") . p . "\n"; |
} |
} |
|
|
for ($i = 0; $i <= $#Tours; $i++) { |
for ($i = 0; $i <= $#Tours; $i++) { |
%Tournament = &GetTournament($dbh, $Tours[$i]); |
%Tournament = &GetTournament($dbh, $Tours[$i]); |
|
|
if ($Tournament{'Type'} =~ /Ч/) { |
if ($Tournament{'Type'} =~ /Ч/) { |
$SingleTour = 0; |
$SingleTour = 0; |
my (@Tours) = &GetTours($dbh, $Tournament{'Id'}); |
my (@Tours) = &GetTours($dbh, $Tournament{'Id'}); |
Line 592 sub PrintTournament {
|
Line 583 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'} . " " . |
. " " . $Tournament{'Title'} . " " . |
$Tournament{'PlayedAt'} . $qnum) . |
$Tournament{'PlayedAt'} . $qnum) . |
dl( |
dl( |
dd("[" |
dd("[" |
. a({href=>url . "?tour=$Tournament{'Id'}&answer=0"}, |
. a({href=>url . "?tour=$Tournament{'Id'}&answer=0"}, |
Line 601 sub PrintTournament {
|
Line 592 sub PrintTournament {
|
"вопросы + ответы") . "]") |
"вопросы + ответы") . "]") |
); |
); |
} else { |
} else { |
$list .= dd(a({href=>url . "?tour=$Tournament{'Id'}&comp=1"}, |
$list .= dd(a({href=>url . "?tour=$Tournament{'Id'}&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=$Tournament{'Id'}&answer=0"}, |
$Tournament{'Title'}. " ". |
$Tournament{'Title'}. " ". |
$Tournament{'PlayedAt'}) . $qnum); |
$Tournament{'PlayedAt'}) . $qnum); |
} |
} |
} |
} |
Line 613 sub PrintTournament {
|
Line 604 sub PrintTournament {
|
|
|
if ($URL) { |
if ($URL) { |
$output .= |
$output .= |
p("Дополнительная информация об этом турнире - по адресу " . |
p("Дополнительная информация об этом турнире - по адресу " . |
a({-'href'=>$URL}, $URL)); |
a({-'href'=>$URL}, $URL)); |
} |
} |
|
|
Line 624 sub PrintTournament {
|
Line 615 sub PrintTournament {
|
if ($Info) { |
if ($Info) { |
$output .= p($Info); |
$output .= p($Info); |
} |
} |
|
|
return $output; |
return $output; |
} |
} |
|
|
Line 638 sub Suffix {
|
Line 629 sub Suffix {
|
|
|
sub IsTour { |
sub IsTour { |
my ($dbh, $Id) = @_; |
my ($dbh, $Id) = @_; |
my ($sth) = $dbh->prepare("SELECT Type FROM Tournaments |
my ($sth) = $dbh->prepare("SELECT Type FROM Tournaments |
WHERE Id=$Id"); |
WHERE Id=$Id"); |
$sth->execute; |
$sth->execute; |
return ($sth->fetchrow)[0] =~ /Т/; |
return ($sth->fetchrow)[0] =~ /Т/; |
Line 658 sub PrintTour {
|
Line 649 sub PrintTour {
|
if ($Tour{'Type'} !~ /Т/); |
if ($Tour{'Type'} !~ /Т/); |
|
|
my ($qnum) = $Tour{'QuestionsNum'}; |
my ($qnum) = $Tour{'QuestionsNum'}; |
my ($suffix) = &Suffix($qnum); |
my ($suffix) = &Suffix($qnum); |
|
|
$output .= h2({align=>"center"}, $Tournament{"Title"}, |
$output .= h2({align=>"center"}, $Tournament{"Title"}, |
$Tournament{'PlayedAt'}, |
$Tournament{'PlayedAt'}, |
"<br>", $Tour{"Title"} . |
"<br>", $Tour{"Title"} . |
" ($qnum вопрос$suffix)\n") . p; |
" ($qnum вопрос$suffix)\n") . p; |
|
|
my (@Questions) = &GetTourQuestions($dbh, $Id); |
my (@Questions) = &GetTourQuestions($dbh, $Id); |
for ($q = 0; $q <= $#Questions; $q++) { |
for ($q = 0; $q <= $#Questions; $q++) { |
$output .= &PrintQuestion($dbh, $Questions[$q], $answer, 0); |
$output .= &PrintQuestion($dbh, $Questions[$q], $answer, 0); |
} |
} |
|
|
$output .= hr({-'align'=>'center', -'width'=>'80%'}); |
$output .= hr({-'align'=>'center', -'width'=>'80%'}); |
|
|
if ($Tournament{'URL'}) { |
if ($Tournament{'URL'}) { |
$output .= |
$output .= |
p("Дополнительная информация об этом турнире - по адресу " . |
p("Дополнительная информация об этом турнире - по адресу " . |
a({-'href'=>$Tournament{'URL'}}, $Tournament{'URL'})); |
a({-'href'=>$Tournament{'URL'}}, $Tournament{'URL'})); |
} |
} |
|
|
Line 685 sub PrintTour {
|
Line 676 sub PrintTour {
|
if ($Tournament{'Info'}) { |
if ($Tournament{'Info'}) { |
$output .= p($Tournament{'Info'}); |
$output .= p($Tournament{'Info'}); |
} |
} |
|
|
|
|
if ($answer == 0) { |
if ($answer == 0) { |
$bottom .= |
$bottom .= |
"[" . a({href=>url . "?tour=$Id&answer=1"}, "ответы") . "] " . br; |
"[" . a({href=>url . "?tour=$Id&answer=1"}, "ответы") . "] " . br; |
} |
} |
if (&IsTour($dbh, $Id - 1)) { |
if (&IsTour($dbh, $Id - 1)) { |
$bottom .= |
$bottom .= |
"[" . a({href=>url . "?tour=" . ($Id - 1) . "&answer=0"}, |
"[" . a({href=>url . "?tour=" . ($Id - 1) . "&answer=0"}, |
"предыдущий тур") . "] "; |
"предыдущий тур") . "] "; |
$bottom .= |
$bottom .= |
"[" . a({href=>url . "?tour=" . ($Id - 1) . "&answer=1"}, |
"[" . a({href=>url . "?tour=" . ($Id - 1) . "&answer=1"}, |
"предыдущий тур с ответами") . "] " . br; |
"предыдущий тур с ответами") . "] " . br; |
} |
} |
if (&IsTour($dbh, $Id + 1)) { |
if (&IsTour($dbh, $Id + 1)) { |
$bottom .= |
$bottom .= |
"[" . a({href=>url . "?tour=" . ($Id + 1) . "&answer=0"}, |
"[" . a({href=>url . "?tour=" . ($Id + 1) . "&answer=0"}, |
"следующий тур") . "] "; |
"следующий тур") . "] "; |
$bottom .= |
$bottom .= |
"[" . a({href=>url . "?tour=" . ($Id + 1) . "&answer=1"}, |
"[" . a({href=>url . "?tour=" . ($Id + 1) . "&answer=1"}, |
"следующий тур с ответами") . "] "; |
"следующий тур с ответами") . "] "; |
} |
} |
|
|
Line 722 sub PrintField {
|
Line 713 sub PrintField {
|
$value =~ s/^\s+/<br> /mg; |
$value =~ s/^\s+/<br> /mg; |
$value =~ s/^\|([^\n]*)/<pre>$1<\/pre>/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"; |
} |
} |
|
|
# Gets a DB handler (ofcourse) and a question Id. Prints |
# Gets a DB handler (ofcourse) and a question Id. Prints |
# that question, according to the options. |
# that question, according to the options. |
sub PrintQuestion { |
sub PrintQuestion { |
my ($dbh, $Id, $answer, $qnum, $title, $text) = @_; |
my ($dbh, $Id, $answer, $qnum, $title, $text) = @_; |
Line 747 sub PrintQuestion {
|
Line 739 sub PrintQuestion {
|
} |
} |
$output .= dl(strong($titles)); |
$output .= dl(strong($titles)); |
} |
} |
|
|
$qnum = $Question{'Number'} |
$qnum = $Question{'Number'} |
if ($qnum == 0); |
if ($qnum == 0); |
|
|
$output .= |
$output .= |
&PrintField("Вопрос $qnum", $Question{'Question'}, $text); |
&PrintField("Вопрос $qnum", $Question{'Question'}, $text); |
|
|
if ($answer) { |
if ($answer) { |
$output .= |
$output .= |
&PrintField("Ответ", $Question{'Answer'}, $text); |
&PrintField("Ответ", $Question{'Answer'}, $text); |
|
|
if ($Question{'Authors'}) { |
if ($Question{'Authors'}) { |
$output .= &PrintField("Автор(ы)", $Question{'Authors'}, $text); |
my $q=$Question{'Authors'}; |
|
|
|
my $sth=$dbh->prepare("select Authors.Id,Name, Surname, Nicks from Authors, A2Q |
|
where Authors.Id=Author And Question=$Id"); |
|
$sth->execute; |
|
my ($AuthorId,$Name, $Surname,$other,$Nicks); |
|
|
|
while ((($AuthorId,$Name, $Surname,$Nicks)=$sth->fetchrow),$AuthorId) |
|
{ |
|
my ($firstletter)=$Name=~m/^./g; |
|
# $other.=a({href=>url."?qofauthor=$AuthorId"},"$Name $Surname").". "; |
|
$Name=~s/\./\\\./g; |
|
my $sha="(?:$Name\\s+$Surname)|(?:$Surname\\s+$Name)|(?:$firstletter\\.\\s*$Surname)|(?:$Surname\\s+$firstletter\\.)|(?:$Surname)|(?:$Name)"; |
|
if ($Nicks) |
|
{ |
|
$Nicks=~s/^\|//; |
|
foreach (split /\|/, $Nicks) |
|
{ |
|
s/\s+/ /g; |
|
s/\s+$//; |
|
s/ /\\s+/g; |
|
s/\./\\\./g; |
|
if (s/>$//) {$sha="$sha|(?:$_)"} |
|
else {$sha="(?:$_)|$sha"} |
|
} |
|
} |
|
$q=~s/($sha)/a({href=>url."?qofauthor=$AuthorId"},$1)/ei; |
|
} |
|
|
|
$output .= &PrintField("Автор(ы)", $q, $text); |
|
|
|
# $output.= &PrintField("Другие вопросы", $other); |
} |
} |
|
|
if ($Question{'Sources'}) { |
if ($Question{'Sources'}) { |
Line 794 sub Get12Random {
|
Line 817 sub Get12Random {
|
my ($qnum) = &GetMaxQId($dbh); |
my ($qnum) = &GetMaxQId($dbh); |
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)); |
Line 814 sub Include_virtual {
|
Line 837 sub Include_virtual {
|
|
|
open F , $fn |
open F , $fn |
or return; #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) { |
s/<!--#include virtual="\/(.*)" -->/&Include_virtual($1)/e; |
s/<!--#include virtual="\/(.*)" -->/&Include_virtual($1)/e; |
Line 833 sub PrintArchive {
|
Line 856 sub PrintArchive {
|
|
|
my (%Tournament) = &GetTournament($dbh, $Id); |
my (%Tournament) = &GetTournament($dbh, $Id); |
my (@Tours) = &GetTours($dbh, $Id); |
my (@Tours) = &GetTours($dbh, $Id); |
|
|
if ($Tournament{'Type'} =~ /Г/ || $Id == 0) { |
if ($Tournament{'Type'} =~ /Г/ || $Id == 0) { |
for ($i = 0; $i <= $#Tours; $i++) { |
for ($i = 0; $i <= $#Tours; $i++) { |
push(@list ,&PrintArchive($dbh, $Tours[$i])); |
push(@list ,&PrintArchive($dbh, $Tours[$i])); |
Line 849 sub PrintAll {
|
Line 872 sub PrintAll {
|
|
|
my (%Tournament) = &GetTournament($dbh, $Id); |
my (%Tournament) = &GetTournament($dbh, $Id); |
my (@Tours) = &GetTours($dbh, $Id); |
my (@Tours) = &GetTours($dbh, $Id); |
my ($New) = ($Id and $Tournament{'Type'} eq 'Ч' and |
my ($New) = ($Id and $Tournament{'Type'} eq 'Ч' and |
&NewEnough($Tournament{"CreatedAt"})) ? |
&NewEnough($Tournament{"CreatedAt"})) ? |
img({src=>"/znatoki/dimrub/db/new-sml.gif", alt=>"NEW!"}) : ""; |
img({src=>"/znatoki/dimrub/db/new-sml.gif", alt=>"NEW!"}) : ""; |
|
|
Line 871 sub PrintAll {
|
Line 894 sub PrintAll {
|
|
|
sub PrintDates { |
sub PrintDates { |
my ($dbh) = @_; |
my ($dbh) = @_; |
my ($from) = param('from_year') . "-" . param('from_month') . |
my ($from) = param('from_year') . "-" . param('from_month') . |
"-" . param('from_day'); |
"-" . param('from_day'); |
my ($to) = param('to_year') . "-" . param('to_month') . "-" . param('to_day'); |
my ($to) = param('to_year') . "-" . param('to_month') . "-" . param('to_day'); |
$from = $dbh->quote($from); |
$from = $dbh->quote($from); |
Line 898 sub PrintDates {
|
Line 921 sub PrintDates {
|
return $output; |
return $output; |
} |
} |
|
|
|
sub PrintQOfAuthor |
|
{ |
|
my ($dbh, $id) = @_; |
|
$id=$dbh->quote($id); |
|
my $sth = $dbh->prepare("SELECT Name, Surname FROM Authors WHERE Id=$id"); |
|
$sth->execute; |
|
my ($name,$surname)=$sth->fetchrow; |
|
|
|
$sth = $dbh->prepare("SELECT Question FROM A2Q WHERE Author=$id"); |
|
$sth->execute; |
|
my $q; |
|
my @Questions; |
|
while (($q)=$sth->fetchrow,$q) |
|
{push @Questions,$q unless $forbidden{$q}} |
|
|
|
my ($output, $i, $suffix, $hits) = ('', 0, '', $#Questions + 1); |
|
|
|
if ($hits =~ /1.$/ || $hits =~ /[5-90]$/) { |
|
$suffix = 'й'; |
|
} elsif ($hits =~ /1$/) { |
|
$suffix = 'е'; |
|
} else { |
|
$suffix = 'я'; |
|
} |
|
|
|
print p({align=>"center"}, "Автор ".strong("$name $surname. ") |
|
. " : $hits попадани$suffix."); |
|
|
|
|
|
for ($i = 0; $i <= $#Questions; $i++) { |
|
$output = &PrintQuestion($dbh, $Questions[$i], 1, $i + 1, 1); |
|
print $output; |
|
} |
|
} |
|
|
|
|
|
sub PrintAuthors |
|
{ |
|
my ($dbh,$sort)=@_; |
|
my($output,$out1,@array,$sth); |
|
if ($sort eq 'surname') |
|
{ |
|
$sth = |
|
$dbh->prepare("SELECT Id, Name, Surname, QNumber FROM Authors order by Surname, Name"); |
|
} |
|
elsif($sort eq 'name') |
|
{ |
|
$sth = |
|
$dbh->prepare("SELECT Id, Name, Surname, QNumber FROM Authors order by Name, Surname"); |
|
} |
|
else |
|
{ |
|
$sth = |
|
$dbh->prepare("SELECT Id, Name, Surname, QNumber FROM Authors Order by QNumber DESC, Surname"); |
|
} |
|
|
|
$output.=h2("Авторы вопросов")."\n"; |
|
$output.="<TABLE>"; |
|
|
|
|
|
$sth->execute; |
|
$output.=Tr(th[a({href=>url."?authors=name"},"Имя") |
|
.", ". |
|
a({href=>url."?authors=surname"},"фамилия") |
|
, a({href=>url."?authors=kvo"},"Количество вопросов")]); |
|
|
|
$out1=''; |
|
|
|
my $ar=$sth->fetchall_arrayref; |
|
|
|
|
|
|
|
foreach my $arr(@$ar) |
|
{ |
|
|
|
my ($id,$name,$surname,$kvo)=@$arr; |
|
if (!$name || !$surname) {#print "Opanki at $id\n" |
|
} else |
|
{ |
|
my $add=Tr(td([a({href=>url."?qofauthor=$id"},"$name $surname"), $kvo]))."\n"; |
|
print STDERR $add; |
|
$output.=$add; |
|
} |
|
} |
|
$output.="</TABLE>"; |
|
return $output; |
|
} |
|
|
|
|
|
|
MAIN: |
MAIN: |
{ |
{ |
setlocale(LC_CTYPE,'russian'); |
setlocale(LC_CTYPE,'russian'); |
my($i, $tour); |
my($i, $tour); |
my($text) = (param('text')) ? 1 : 0; |
my($text) = (param('text')) ? 1 : 0; |
|
|
my($dbh) = DBI->connect("DBI:mysql:chgk", "piataev", "") |
my($dbh) = DBI->connect("DBI:mysql:chgk", "piataev", "") |
or do { |
or do { |
print h1("Временные проблемы") . "База данных временно не |
print h1("Временные проблемы") . "База данных временно не |
Line 934 if ((uc 'а') ne 'А') {print "Koi8-r loca
|
Line 1048 if ((uc 'а') ne 'А') {print "Koi8-r loca
|
print header('text/plain'); |
print header('text/plain'); |
} |
} |
|
|
|
if (param('hideequal')) { |
|
my ($sth)= $dbh -> prepare("select first, second FROM equalto"); |
|
$sth -> execute; |
|
while ( my ($first, $second)=$sth -> fetchrow) |
|
{ |
|
$forbidden{$first}=1; |
|
} |
|
$sth->finish; |
|
} |
|
|
|
|
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')); |
$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 && |
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"; |
Line 959 EOT
|
Line 1084 EOT
|
} else { |
} else { |
print &PrintRandom($dbh, $type, $qnum, $text); |
print &PrintRandom($dbh, $type, $qnum, $text); |
} |
} |
} elsif (param('sstr')) { |
} |
|
elsif (param('authors')){ |
|
print &PrintAuthors($dbh,param('authors')); |
|
} |
|
elsif (param('qofauthor')){ |
|
&PrintQOfAuthor($dbh,param('qofauthor')); |
|
} |
|
elsif (param('sstr')) { |
&PrintSearch($dbh, param('sstr'), param('metod')); |
&PrintSearch($dbh, param('sstr'), param('metod')); |
} elsif (param('all')) { |
} elsif (param('all')) { |
print &PrintAll($dbh, 0); |
print &PrintAll($dbh, 0); |
} 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"', |