version 1.122, 2003/07/05 00:32:03
|
version 1.128, 2004/01/10 22:52:20
|
Line 93 my %TypeName=('children'=>'Д', 'game'=>'
|
Line 93 my %TypeName=('children'=>'Д', 'game'=>'
|
'chgk'=>'Ч', 'brain'=>'Б', 'beskrylka'=>'Л','ehruditka'=>'Э'); |
'chgk'=>'Ч', 'brain'=>'Б', 'beskrylka'=>'Л','ehruditka'=>'Э'); |
|
|
|
|
|
sub countz { |
|
my ($dbh,$type)=@_; |
|
|
|
my $sth=$dbh->prepare("select count(*) from Questions where Type LIKE '%$type%'"); |
|
$sth->execute(); |
|
my ($tmp)=$sth->fetchrow(); |
|
return $tmp; |
|
} |
|
|
my $all=param('all'); |
my $all=param('all'); |
$all=0 if lc $all eq 'no'; |
$all=0 if lc $all eq 'no'; |
Line 176 sub GetTournament {
|
Line 184 sub GetTournament {
|
sub fetchquestion { |
sub fetchquestion { |
my ($sth,$q,$WithTour)=@_; |
my ($sth,$q,$WithTour)=@_; |
if ($WithTour) { |
if ($WithTour) { |
($$q{'QuestionId'}, $$q{'Question'},$$q{'Answer'},$$q{'Comments'},$$q{'Authors'}, |
($$q{'QuestionId'}, $$q{'Question'},$$q{'Answer'},$$q{'Comments'},$$q{'Authors'},$$q{'Sources'}, |
$$q{'Number'}, |
$$q{'Number'}, |
$$q{'Title'}, $$q{'TourTitle'}, $$q{'FileName'},$$q{'PlayedAt'},$$q{'TourNumber'}) = |
$$q{'Title'}, $$q{'TourTitle'}, $$q{'FileName'},$$q{'PlayedAt'},$$q{'TourNumber'}) = |
$sth->fetchrow; |
$sth->fetchrow; |
} else { |
} else { |
($$q{'QuestionId'}, $$q{'Question'},$$q{'Answer'},$$q{'Comments'},$$q{'Authors'}, |
($$q{'QuestionId'}, $$q{'Question'},$$q{'Answer'},$$q{'Comments'},$$q{'Authors'},$$q{'Sources'}, |
$$q{'Number'})= |
$$q{'Number'})= |
$sth->fetchrow; |
$sth->fetchrow; |
} |
} |
Line 203 sub SelectQuestions {
|
Line 211 sub SelectQuestions {
|
|
|
my $query; |
my $query; |
if ($WithTour) { |
if ($WithTour) { |
$query="SELECT QuestionId, Questions.Question, Answer, Comments, Authors, |
$query="SELECT QuestionId, Questions.Question, Answer, Comments, Authors, Sources, |
Questions.Number |
Questions.Number |
, t2.Title, t1.Title, t2.FileName, t2.PlayedAt,t1.Number |
, t2.Title, t1.Title, t2.FileName, t2.PlayedAt,t1.Number |
from Questions,Tournaments as t1, Tournaments as t2 |
from Questions,Tournaments as t1, Tournaments as t2 |
WHERE $where"; |
WHERE $where"; |
} else { |
} else { |
$query="SELECT QuestionId, Questions.Question, Answer, Comments, Authors, |
$query="SELECT QuestionId, Questions.Question, Answer, Comments, Authors, Sources, |
Questions.Number from Questions |
Questions.Number from Questions |
WHERE $where"; |
WHERE $where"; |
} |
} |
Line 738 sub makewhere {
|
Line 746 sub makewhere {
|
$type .= ($_=$TypeName{$_}) foreach @type; |
$type .= ($_=$TypeName{$_}) foreach @type; |
my $where=' 0 '; |
my $where=' 0 '; |
foreach (@type) { |
foreach (@type) { |
$where.= " OR (Type ='$_') OR (Type ='$_Д') "; |
$where.= " OR (Type ='$_') OR (Type ='$_Д') OR (Type ='Д$_') "; |
} |
} |
$where.= "OR (Type='ЧБ')" if ($type=~/Ч|Б/); |
$where.= "OR (Type='ЧБ')" if ($type=~/Ч|Б/); |
return $where; |
return $where; |
Line 1050 sub PrintTournament {
|
Line 1058 sub PrintTournament {
|
}; |
}; |
} |
} |
} else { |
} else { |
my ($qnum) = GetQNum($dbh); |
my ($qnum) = GetQNum($dbh,0); |
$output .= h2("Банк Вопросов: $qnum вопрос".&Suffix($qnum)) |
my ($qnum1) = GetQNum($dbh,1); |
. p . "\n"; |
$output .= h2("База вопросов"). |
|
h3("$qnum запис".&Suffix2($qnum). |
|
" (уникальных $qnum1)"); |
|
|
|
# h4("<table>". |
|
# Tr(td("Из них:"), td("Вопросов ЧГК: ".countz($dbh,'Ч'))). |
|
# Tr(td(" "), td("Вопросов для брейна: ".countz($dbh,'Б'))). |
|
# Tr(td(" "), td("Вопросов для ЧГК и брейна: ".countz($dbh,'ЧБ'))). |
|
# Tr(td(" "), td("Интернет-вопросов: ".countz($dbh,'И'))). |
|
# Tr(td(" "), td("Бескрылок: ".countz($dbh,'Л'))). |
|
# Tr(td(" "),td("Заданий для Своей Игры: ".countz($dbh,'Я'))). |
|
# Tr(td(" "),td("Эрудиток: ".countz($dbh,'Э'))))."</table>" |
} |
} |
|
|
for ($i = 0; $i <= $#Tours; $i++) { |
for ($i = 0; $i <= $#Tours; $i++) { |
Line 1143 sub Suffix {
|
Line 1162 sub Suffix {
|
return $suffix; |
return $suffix; |
} |
} |
|
|
|
|
|
sub Suffix1 { |
|
my ($qnum) = @_; |
|
my ($suffix) = 'я' if $qnum =~ /[234]$/; |
|
$suffix = 'е' if $qnum =~ /1$/; |
|
$suffix = 'й' if $qnum =~ /[567890]$/ || $qnum =~ /1.$/; |
|
return $suffix; |
|
} |
|
|
|
sub Suffix2 { |
|
my ($qnum) = @_; |
|
my ($suffix) = 'и' if $qnum =~ /[234]$/; |
|
$suffix = 'ь' if $qnum =~ /1$/; |
|
$suffix = 'ей' if $qnum =~ /[567890]$/ || $qnum =~ /1.$/; |
|
return $suffix; |
|
} |
|
|
sub IsTour { |
sub IsTour { |
my ($dbh, $Id,$n) = @_; |
my ($dbh, $Id,$n) = @_; |
|
|
Line 1249 sub PrintField {
|
Line 1285 sub PrintField {
|
$value =~ s/<[\/\w]*?>//sg; |
$value =~ s/<[\/\w]*?>//sg; |
} else { |
} else { |
$value =~ s/^\s+/<br> /mg; |
$value =~ s/^\s+/<br> /mg; |
|
$value =~ s/(\s+)-+(\s+)/$1–$2/mg; |
|
$value =~ s/\s+\–/ \–/mg |
|
if $value !~ /^\|/; |
$value =~ s/^\|([^\n]*)/<pre>$1<\/pre>/mg; |
$value =~ s/^\|([^\n]*)/<pre>$1<\/pre>/mg; |
$value =~ s/\s+-+\s+/ – /mg; |
|
$value =~ s/(http:\/\/\S+[^\s\)\(\,\.])/<a href="$1">$1<\/a>/g if $header !~ /^Авто/; |
$value =~ s/(http:\/\/\S+[^\s\)\(\,\.])/<a href="$1">$1<\/a>/g if $header !~ /^Авто/; |
# $value =~ s/(http:\/\/(?:\w+.)+[\w\\\~]+(\?[^\s.]+)?)/<a href="$1">$1<\/a>/g if $header !~ /^Авто/; |
# $value =~ s/(http:\/\/(?:\w+.)+[\w\\\~]+(\?[^\s.]+)?)/<a href="$1">$1<\/a>/g if $header !~ /^Авто/; |
# $value =~ s/(\s)"/$1“/mg; |
# $value =~ s/(\s)"/$1“/mg; |
Line 1405 qid=$qid"}, 'Близкие вопросы').p
|
Line 1443 qid=$qid"}, 'Близкие вопросы').p
|
|
|
# Returns the total number of questions currently in the DB. |
# Returns the total number of questions currently in the DB. |
sub GetQNum { |
sub GetQNum { |
my ($dbh) = @_; |
my ($dbh,$x) = @_; |
my ($sth) = $dbh->prepare("SELECT COUNT(*) FROM Questions"); |
my ($sth) = $dbh->prepare("SELECT COUNT(*) FROM Questions"); |
$sth->execute; |
$sth->execute; |
my $tmp=($sth->fetchrow)[0]; |
my $tmp=($sth->fetchrow)[0]; |
$sth->finish; |
$sth->finish; |
return $tmp; |
($sth)= $dbh -> prepare("select distinct count(first) FROM equalto"); |
|
$sth -> execute; |
|
my ($c)=$sth->fetchrow; |
|
|
|
# $i++ while ( my ($first, $second)=$sth -> fetchrow) |
|
# { |
|
# $forbidden{$first}=1; |
|
# } |
|
$sth->finish; |
|
|
|
return $tmp-($x?$c:0); |
} |
} |
sub GetMaxQId { |
sub GetMaxQId { |
my ($dbh) = @_; |
my ($dbh) = @_; |
Line 1554 sub PrintDates {
|
Line 1602 sub PrintDates {
|
next |
next |
if (!$array[0]); |
if (!$array[0]); |
%Tournament = &GetTournament($dbh, $array[0]); |
%Tournament = &GetTournament($dbh, $array[0]); |
|
my $textid; |
|
if ($textid=$Tournament{'FileName'}) |
|
{ |
|
$textid=~s/\.txt//; |
|
} |
|
elsif ($textid=$Tournament{'Number'}) |
|
{ |
|
$fname=~s/\.txt//; |
|
$textid="$fname.$textid"; |
|
} |
|
else {$textid=$Tournament{'Id'}}; |
$list .= dd(img({src=>"/icons/folder.gif", alt=>"[*]"}) . |
$list .= dd(img({src=>"/icons/folder.gif", alt=>"[*]"}) . |
" " . a({href=>tourhref($Tournament{'FileName'},0,1)}, |
" " . a({href=>tourhref($textid,0,1)}, |
$Tournament{'Title'}, $Tournament{'PlayedAt'}||'')); |
$Tournament{'Title'}, $Tournament{'PlayedAt'}||'')); |
} |
} |
$sth->finish; |
$sth->finish; |
Line 1865 MAIN:
|
Line 1924 MAIN:
|
exit |
exit |
} |
} |
|
|
if ($tour && (!param('answers')||!param('answers')<=1)) |
if ($tour && !param('qnumber') && (!param('answers')||(param('answers')<=1))) |
{ |
{ |
my $n=param('tour'); |
my $n=param('tour'); |
$n=~s/.txt$//; |
$n=~s/.txt$//; |
Line 2127 EOT
|
Line 2186 EOT
|
# FROM Tournaments as t1, Tournaments as t2 |
# FROM Tournaments as t1, Tournaments as t2 |
# WHERE t1.CreatedAt>$d AND t2.ParentId=t1.Id GROUP BY t1.Id"); |
# WHERE t1.CreatedAt>$d AND t2.ParentId=t1.Id GROUP BY t1.Id"); |
my ($sth) = $dbh->prepare("SELECT t1.Id, t1.FileName, t1.Type, count(t2.Id) FROM Tournaments as t1 LEFT JOIN Tournaments as t2 |
my ($sth) = $dbh->prepare("SELECT t1.Id, t1.FileName, t1.Type, count(t2.Id) FROM Tournaments as t1 LEFT JOIN Tournaments as t2 |
ON t2.ParentId=t1.id WHERE t1.CreatedAt>$d GROUP BY t1.Id"); |
ON t2.ParentId=t1.id WHERE t1.CreatedAt>=$d GROUP BY t1.Id"); |
$sth->execute; |
$sth->execute; |
my ($Id,$fname,$type,$c); |
my ($Id,$fname,$type,$c); |
while (($Id,$fname,$type,$c)=$sth->fetchrow,$Id) { |
while (($Id,$fname,$type,$c)=$sth->fetchrow,$Id) { |