version 1.61, 2002/01/15 12:13:55
|
version 1.71, 2002/08/01 23:14:00
|
Line 2
|
Line 2
|
|
|
use DBI; |
use DBI; |
use CGI ':all'; |
use CGI ':all'; |
#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 |
Line 110 sub GetTourQuestions {
|
Line 109 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"); |
WHERE ParentId=$ParentId order by Number"); |
|
|
$sth->execute; |
$sth->execute; |
|
|
Line 161 sub printform
|
Line 160 sub printform
|
my $inputstring=textfield(-name=>'sstr', |
my $inputstring=textfield(-name=>'sstr', |
-default=>param('sstr')||'', |
-default=>param('sstr')||'', |
-size=>30, |
-size=>30, |
-maxlength=>30); |
-maxlength=>50); |
my $qnumber="Выводить по".br. textfield(-name=>'kvo', |
my $qnumber="Выводить по".br. textfield(-name=>'kvo', |
-default=>param('kvo')||'150', |
-default=>param('kvo')||'150', |
-size=>3, |
-size=>3, |
Line 645 sub PrintList {
|
Line 644 sub PrintList {
|
|
|
print "$nav".br."\n"; |
print "$nav".br."\n"; |
for (my $i = $first; $i <= $last; $i++) { |
for (my $i = $first; $i <= $last; $i++) { |
my $output = &PrintQuestion($dbh, $$Questions[$i-1], 1, $i, 1); |
my $output = &PrintQuestion($dbh, $$Questions[$i-1], 1, 0, 1); |
if (param('metod') eq 'rus' || param('metod') eq 'proxy') |
if (param('metod') eq 'rus' || param('metod') eq 'proxy') |
{ |
{ |
$output=~s/\b($shablon)\b/\<strong\>$1\<\/strong\>/gi; |
$output=~s/\b($shablon)\b/\<strong\>$1\<\/strong\>/gi; |
Line 773 sub PrintRandom {
|
Line 772 sub PrintRandom {
|
|
|
sub PrintEditor { |
sub PrintEditor { |
my $t=shift; #ссылка на Хэш с полями |
my $t=shift; #ссылка на Хэш с полями |
my $ed=$$t{'Editors'}; |
my $ed=$$t{'Editors'}||''; |
my $edname=($ed=~/\,/ ) ? "Редакторы" : "Редактор" ; |
my $edname=($ed=~/\,/ ) ? "Редакторы" : "Редактор" ; |
return $ed? h4({align=>"center"},"$edname: $ed" ): ''; |
return $ed? h4({align=>"center"},"$edname: $ed" ): ''; |
} |
} |
Line 821 sub PrintTournament {
|
Line 820 sub PrintTournament {
|
} |
} |
} else { |
} else { |
my ($qnum) = GetQNum($dbh); |
my ($qnum) = GetQNum($dbh); |
$output .= h2("Банк Вопросов: $qnum вопросов") . p . "\n"; |
$output .= h2("Банк Вопросов: $qnum вопрос".&Suffix($qnum)) |
|
. p . "\n"; |
} |
} |
|
|
for ($i = 0; $i <= $#Tours; $i++) { |
for ($i = 0; $i <= $#Tours; $i++) { |
Line 840 sub PrintTournament {
|
Line 840 sub PrintTournament {
|
$qnum = ''; |
$qnum = ''; |
} |
} |
if ($Tournament{'Type'} =~ /Г/) { |
if ($Tournament{'Type'} =~ /Г/) { |
|
$SingleTour=0; |
$imgsrc = "/icons/folder.gif"; |
$imgsrc = "/icons/folder.gif"; |
$alt = "[*]"; |
$alt = "[*]"; |
} else { |
} else { |
Line 883 sub PrintTournament {
|
Line 884 sub PrintTournament {
|
$output .= dl($list); |
$output .= dl($list); |
|
|
if ($URL) { |
if ($URL) { |
|
if (url=~/zaba\.ru/ && $URL=~/^\//){$URL="http://info.chgk.info$URL"} |
$output .= |
$output .= |
p("Дополнительная информация об этом турнире - по адресу " . |
p("Дополнительная информация об этом турнире - по адресу " . |
a({-'href'=>$URL}, $URL)); |
a({-'href'=>$URL}, $URL)); |
Line 1025 sub PrintQuestion {
|
Line 1027 sub PrintQuestion {
|
my ($dbh, $Id, $answer, $qnum, $title, $text) = @_; |
my ($dbh, $Id, $answer, $qnum, $title, $text) = @_; |
my ($output, $titles) = ('', ''); |
my ($output, $titles) = ('', ''); |
my (%Question) = &GetQuestion($dbh, $Id); |
my (%Question) = &GetQuestion($dbh, $Id); |
|
$qnum = $Question{'Number'} |
|
if ($qnum == 0); |
if (!$text) { |
if (!$text) { |
$output .= hr({width=>"50%"}); |
$output .= hr({width=>"50%"}); |
if ($title) { |
if ($title) { |
Line 1037 sub PrintQuestion {
|
Line 1041 sub PrintQuestion {
|
a({href=>url . "?tour=$fname"}, $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=$fname.$Tour{Number}"}, $Tour{'Title'}))); |
a({href=>url . "?tour=$fname.$Tour{Number}#$qnum"}, $Tour{'Title'}))); |
} |
} |
$output .= dl(strong($titles)); |
$output .= dl(strong($titles)); |
} |
} |
|
|
$qnum = $Question{'Number'} |
|
if ($qnum == 0); |
$output.= "<a NAME=\"$qnum\">"; |
|
|
$output .= |
$output .= |
&PrintField("Вопрос $qnum", $Question{'Question'}, $text); |
&PrintField("Вопрос $qnum", $Question{'Question'}, $text); |
|
|
if ($answer) { |
if ($answer==1) { |
$output .= |
$output .= |
&PrintField("Ответ", $Question{'Answer'}, $text); |
&PrintField("Ответ", $Question{'Answer'}, $text); |
|
|
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); |
|
|
# $output.= &PrintField("Другие вопросы", $other); |
|
} |
} |
|
|
if ($Question{'Sources'}) { |
if ($Question{'Sources'}) { |
Line 1094 sub PrintQuestion {
|
Line 1097 sub PrintQuestion {
|
$output .= &PrintField("Комментарии", $Question{'Comments'}, $text); |
$output .= &PrintField("Комментарии", $Question{'Comments'}, $text); |
} |
} |
} |
} |
# $output.=br.a({href=> url."?metod=proxy&qid=$Id"}, 'Близкие вопросы').p |
elsif ($answer==2) { |
# if $answer; |
my $text=$Question{'Answer'}; |
|
$text=~s/\n/<option>/mg; |
|
$output.="<select><option selected>Ответ:<option>$text</select>"; |
|
$text=$Question{'Comments'}||''; |
|
if ($text) { |
|
$text=~s/\n/<option>/mg; |
|
$output.="<select><option selected>Комментарий:<option>$text</select>" |
|
} |
|
} |
|
elsif ($answer==3) { |
|
$output.= <<EOTT |
|
<div align=right STYLE="cursor:hand;" OnStart="toggle(document.all.HideShow$qnum);" OnClick="toggle(document.all.HideShow$qnum);"> |
|
<font size=-2 color=red> Показать/убрать ответ</font></div> |
|
<span style="display:none" id=HideShow$qnum> |
|
EOTT |
|
.&PrintField("Ответ", $Question{'Answer'}, $text); |
|
if ($Question{'Authors'}) { |
|
$output .= &PrintField("Автор(ы)", $Question{'Authors'}, $text); |
|
} |
|
if ($Question{'Sources'}) { |
|
$output .= &PrintField("Источник(и)", $Question{'Sources'}, $text); |
|
} |
|
|
|
if ($Question{'Comments'}) { |
|
$output .= &PrintField("Комментарии", $Question{'Comments'}, $text); |
|
} |
|
|
|
|
|
$output.="</span>" |
|
|
|
} |
|
$output.=br.a({href=> url."?metod=proxy&qid=$Id"}, 'Близкие вопросы').p |
|
if $answer; |
return $output; |
return $output; |
} |
} |
|
|
Line 1125 sub Get12Random {
|
Line 1160 sub Get12Random {
|
my ($qnum) = &GetMaxQId($dbh); |
my ($qnum) = &GetMaxQId($dbh); |
my (%chosen); |
my (%chosen); |
srand; |
srand; |
|
|
my $where=0; |
my $where=0; |
my $r=int (rand(10000)); |
my $r=int (rand(10000)); |
|
|
Line 1137 sub Get12Random {
|
Line 1171 sub Get12Random {
|
|
|
$q="select QuestionId, QuestionId/$r-floor(QuestionId/$r) as val |
$q="select QuestionId, QuestionId/$r-floor(QuestionId/$r) as val |
from Questions where $where order by val limit $num"; |
from Questions where $where order by val limit $num"; |
|
|
# Когда на куличках появится mysql >=3.23 надо заменить на order by rand(); |
# Когда на куличках появится mysql >=3.23 надо заменить на order by rand(); |
|
|
$sth=$dbh->prepare($q); |
$sth=$dbh->prepare($q); |
Line 1650 $sstr=~s/[^йцукенгшщзхъфывапролджэячсмит
|
Line 1683 $sstr=~s/[^йцукенгшщзхъфывапролджэячсмит
|
$tour = ($sth->fetchrow)[0]; |
$tour = ($sth->fetchrow)[0]; |
$sth->finish; |
$sth->finish; |
} |
} |
print &PrintTournament($dbh, $tour, param('answer')); |
my $QuestionNumber=0; |
|
my $qnum; |
|
if ($qnum=param('qnumber')){ |
|
my ($sth) = $dbh->prepare("SELECT QuestionId FROM Questions |
|
WHERE ParentId=$tour AND Number=$qnum"); |
|
$sth->execute; |
|
$QuestionNumber=($sth->fetchrow)[0]||0; |
|
} |
|
if ($QuestionNumber) { |
|
print &PrintQuestion($dbh, $QuestionNumber, param('answer')||0, $qnum, 1); |
|
# $dbh, $Id, $answer, $qnum, $title, $text |
|
} else { |
|
print &PrintTournament($dbh, $tour, param('answer')); |
|
} |
} |
} |
if (!$text) { |
if (!$text) { |
print &Include_virtual("../dimrub/db/footer.html"); |
print &Include_virtual("../dimrub/db/footer.html"); |
|
print <<EEE |
|
<SCRIPT LANGUAGE="JavaScript"> |
|
function toggle(e) { |
|
if (e.style.display == "none") { |
|
e.style.display=""; |
|
} else { |
|
e.style.display = "none"; |
|
} |
|
} |
|
</SCRIPT> |
|
EEE |
|
; |
print end_html; |
print end_html; |
} |
} |
$dbh->disconnect; |
$dbh->disconnect; |