--- db/prgsrc/db.cgi 2002/11/10 16:10:53 1.78 +++ db/prgsrc/db.cgi 2003/02/02 13:44:06 1.87 @@ -160,51 +160,86 @@ print "timee0=".time.br if $debug; sub printform { - my $submit=submit(-value=>'Поиск'); - my $inputstring=textfield(-name=>'sstr', - -default=>param('sstr')||'', - -size=>30, - -maxlength=>50); - my $qnumber="Выводить по".br. textfield(-name=>'kvo', + my $qnumber=(" "x10)."Выводить по ". textfield(-name=>'kvo', -default=>param('kvo')||'150', -size=>3, - -maxlength=>5). br."вопросов"; - + -maxlength=>5)." вопросов"; + my $sstr=param('sstr'); my @df=keys %searchin; + my %checked; @df=('Question', 'Answer') unless @df; + $checked{lc $_}="checked" foreach @df; my $fields=checkbox_group('searchin',['Question','Answer','Comments','Authors','Sources'], [@df], 'false',\%rusfieldname); @df=param('type'); @df=('chgk','brain','igp','game','ehruditka','beskrylka') unless @df; + $checked{lc $_}="checked" foreach @df; + my $all=param('all') && param('all') eq 'yes'; - my $types=checkbox_group('type',['chgk','brain','igp','game','ehruditka','beskrylka'], [@df], - 'false',\%rusfieldname); - my $metod=radio_group(-name=>'metod',-values=>['old','rus'], - -default=>(param('metod')||'rus'), - -labels=>\%rusfieldname); - my $all=radio_group(-name=>'all',-values=>['yes','no'], - -default=>(param('all')||'no'), - -labels=>{'yes'=>'Все','no'=>'Любое'}); + $checked{'all'}=$all?"checked":""; + $checked{'any'}=$all?"":"checked"; + $checked{lc param('metod')}="checked"; + $checked{'russian'}=1 unless $checked{'russian'} || $checked{'old'}; ################################################# -return start_form(-method=>'get', - -action=>url, - -enctype=> - "application/x-www-form-urlencoded" -).br. -table(Tr -( - td({-valign=>'TOP'},$inputstring.$submit.p."Метод: $metod".p."Слова: $all"), - td({-valign=>'TOP'},(' 'x 8).'Поля:'), - td({-valign=>'TOP'},$fields), - td({-valign=>'TOP'},(' 'x 1).'Типы:'), - td({-valign=>'TOP'},$types), td(" "x5), - td({-valign=>'TOP'},$qnumber) -) -) - -#$fields. -#$inputstring.$submit.br.$metod.$all +return +< +

Поиск в базе вопросов

+ + + $qnumber +

+ + + + + + + + + + + + + +
Вариант поиска: + + Простой (старый) + + "Что? Где? Когда?" + + "Брейн-Ринг" + + "Интернет" +
+ "Своя игра" + + "Эрудитка" + + "Бескрылка" +
Расширенный (с учетом грамматики, в вопросах всех типов) +
Искать: + +Все слова + +Любое слово +
Поля для поиска: + +Вопрос + +Ответ
+
+Комментарии
+
+Автор
+
+Источник
+
+ + +EOT .endform .hr @@ -688,7 +723,7 @@ sub PrintList { sub PrintSearch { my ($dbh, $sstr, $metod,$was) = @_; my $t=time; - print h2("Поиск в базе вопросов"); +# print h2("Поиск в базе вопросов"); print printform; my @allnf; my @Questions; @@ -779,6 +814,8 @@ print "$query" if $printqueries; sub PrintRandom { my ($dbh, $type, $num, $text) = @_; + my $razd=param('razd'); + my $answer=$razd?0:1; my (@Questions) = &Get12Random($dbh, $type, $num); my ($output, $i) = ('', 0); @@ -793,8 +830,17 @@ sub PrintRandom { # Passing DB handler, question ID, print answer, question # number, print title, print text/html $output .= - &PrintQuestion($dbh, $Questions[$i], 1, $i + 1, 0, $text); + &PrintQuestion($dbh, $Questions[$i], $answer, $i + 1, 0, $text); } + unless ($answer ) + { + $output.=$text?"\n".('-'x 20)."\nОтветы\n~~~~~~\n\n":h2('Ответы'); + for ($i = 0; $i <= $#Questions; $i++) { + $output .= + &PrintQuestion($dbh, $Questions[$i], -1, $i + 1, 0, $text); + } + } + return $output; } @@ -1041,6 +1087,8 @@ sub PrintField { $value =~ s/^\s+/
    /mg; $value =~ s/^\|([^\n]*)/

$1<\/pre>/mg;
 	    $value =~ s/\s+-+\s+/ – /mg;
+	    $value =~ s/(http:\/\/\S+[^\s\)\(\,\.])/$1<\/a>/g if $header !~ /^Авто/;
+#	    $value =~ s/(http:\/\/(?:\w+.)+[\w\\\~]+(\?[^\s.]+)?)/$1<\/a>/g if $header !~ /^Авто/;
 #	    $value =~ s/(\s)"/$1“/mg;
 #	    $value =~ s/^"/“/mg;
 #	    $value =~ s/"/”/mg;
@@ -1060,12 +1108,11 @@ sub PrintQuestion {
 	$qnum = $Question{'Number'}
 		if ($qnum == 0);
 	if (!$text) {
-		$output .= hr({width=>"50%"});
+		$output .= hr({width=>"50%"}) if $answer>=0;
 		if ($title) {
 			my (%Tour) = GetTournament($dbh, $Question{'ParentId'});
 			my (%Tournament) = GetTournament($dbh, $Tour{'ParentId'});
 			my $fname=$Tournament{'FileName'};
-return "" if $fname=~/mgp0203/;
 			$fname=~s/\.txt//;
 			$titles .=
 				dd(img({src=>"/icons/folder.open.gif"}) . " " .
@@ -1078,26 +1125,26 @@ return "" if $fname=~/mgp0203/;
 	}
 
 
-	$output.= "";
-
-	$output .=
-		&PrintField("Вопрос $qnum", $Question{'Question'}, $text);
+	$output.= "" unless $text;
 
-	if ($answer==1) {
+	if ($answer>=0) {$output .=
+		&PrintField("Вопрос $qnum", $Question{'Question'}, $text);}
+	else {$output .="$qnum. "}
+	if ($answer==1|| $answer==-1) {
 		$output .=
 			&PrintField("Ответ", $Question{'Answer'}, $text);
 
-		if ($Question{'Authors'}) {
+		if ($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.CharId,Name, Surname, Nicks from Authors, A2Q
                                   where Authors.Id=Author And Question=$Id");
                        $sth->execute;
                        my ($AuthorId,$Name, $Surname,$other,$Nicks);
-
+                      if (!$text) {
                        while ((($AuthorId,$Name, $Surname,$Nicks)=$sth->fetchrow),$AuthorId)
                        {
-                         my ($firstletter)=$Name=~m/^./g;
+                          my ($firstletter)=$Name=~m/^./g;
                           $Name=~s/\./\\\./g;
                            my $sha="(?:$Name\\s+$Surname)|(?:$Surname\\s+$Name)|(?:$firstletter\\.\\s*$Surname)|(?:$Surname\\s+$firstletter\\.)|(?:$Surname)|(?:$Name)";
                            if ($Nicks)
@@ -1115,7 +1162,7 @@ return "" if $fname=~/mgp0203/;
                            }
                            $q=~s/($sha)/a({href=>url."?qofauthor=$AuthorId"},$1)/ei;
                        }
- 
+                      }
 			$output .= &PrintField("Автор(ы)", $q, $text);
 
 		}
@@ -1157,11 +1204,16 @@ EOTT
 		}
 
 
+
 $output.=""
 
 	}
-	$output.=br.a({href=> url."?metod=proxy&qid=$Id"}, 'Близкие вопросы').p
-             if $answer;
+	$output=~s/\(pic: ([^\)]*)\)/

/g unless $text; + my $qid=param('tour') ? (param('tour').".$Question{'Number'}" ): ''; + + $output.=br.a({href=> url."?metod=proxy& +qid=$qid"}, 'Близкие вопросы').p + if $answer>0 && !$text && $qid; return $output; } @@ -1325,7 +1377,15 @@ sub PrintQOfAuthor { my ($dbh, $id) = @_; - $id=$dbh->quote($id); + unless ($id=~/^\d+$/) { + $id=$dbh->quote($id); + my $sth = $dbh->prepare("SELECT Id FROM Authors WHERE CharId=$id"); + $sth->execute; + ($id)=$sth->fetchrow; + $sth->finish; + } + $id=$dbh->quote($id); + my $sth = $dbh->prepare("SELECT Name, Surname FROM Authors WHERE Id=$id"); $sth->execute; my ($name,$surname)=$sth->fetchrow; @@ -1347,7 +1407,7 @@ sub PrintQOfAuthor } else { $suffix = 'я'; } - print h2("Поиск в базе вопросов"); +# print h2("Поиск в базе вопросов"); print printform; print p({align=>"center"}, "Автор ".strong("$name $surname. ") . " : $hits попадани$suffix."); @@ -1572,21 +1632,28 @@ MAIN: setlocale(LC_CTYPE,'russian'); my($i, $tour); my($text) = (param('text')) ? 1 : 0; + if ($text) { + print header('text/plain'); + } else {print header;} my($dbh) = DBI->connect("DBI:mysql:chgk", "piataev", "") or do { - print h1("Временные проблемы") . "База данных временно не + print h1("Временные проблемы") . "База вопросов временно не работает. Заходите попозже."; print &Include_virtual("../dimrub/db/reklama.html"); print end_html; die "Can't connect to DB chgk\n"; }; if (!param('comp') and !param('sqldump') and !$text) { - print header; print start_html(-"title"=>'Database of the questions', -author=>'dimrub@icomverse.com', -bgcolor=>'#fff0e0', -vlink=>'#800020'); +print "\n"; + print &Include_virtual("../dimrub/db/reklama.html"); } @@ -1601,10 +1668,6 @@ POSIX::setlocale( &POSIX::LC_ALL, $thisl if ((uc 'а') ne 'А') {print "Koi8-r locale not installed!\n"}; - if ($text) { - print header('text/plain'); - } - if (param('hideequal')) { my ($sth)= $dbh -> prepare("select first, second FROM equalto"); $sth -> execute; @@ -1679,6 +1742,33 @@ EOT } elsif (param('qid')) { my $qid=param('qid'); + if ($qid !~ /^[0-9]*$/) { + my ($fname,$t,$n)= split /\./ , $qid; + $n=$t,$t='' unless $n; + if ($n) + { + $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=$t"); + } + else + { + $sth = $dbh->prepare("SELECT Id FROM Tournaments + WHERE FileName = '$fname.txt'"); + } + $sth->execute; + $tour = ($sth->fetchrow)[0]; + $sth->finish; + $sth = $dbh->prepare( + "SELECT QuestionId FROM + Questions + WHERE ParentId=$tour AND + Questions.Number=$n"); + $sth->execute; + $qid = ($sth->fetchrow)[0]; + } my $query="SELECT Question, Answer from Questions where QuestionId=$qid"; print $query if $printqueries; my $sth=$dbh->prepare($query);