--- db/prgsrc/db.cgi 2002/01/08 23:15:31 1.57 +++ db/prgsrc/db.cgi 2002/08/01 23:14:00 1.71 @@ -2,12 +2,11 @@ use DBI; use CGI ':all'; -#use Text::Query; use strict; use Time::Local; use POSIX qw(locale_h); use locale; -open STDERR, ">errors1"; +open STDERR, ">>errors1"; my $printqueries=0; my %forbidden=(); my $debug=0; #added by R7 @@ -43,6 +42,7 @@ my ($SRCPATH) = "$PWD/../dimrub/src"; my ($ZIP) = "/home/piataev/bin/zip"; my $DUMPFILE = "/tmp/chgkdump"; my ($SENDMAIL) = "/usr/sbin/sendmail"; +my ($TMPDIR) = "/tmp"; my ($TMSECS) = 30*24*60*60; my (%RevMonths) = ('Jan', '0', 'Feb', '1', 'Mar', '2', 'Apr', '3', 'May', '4', 'Jun', '5', @@ -51,6 +51,9 @@ my (%RevMonths) = 'Янв', '0', 'Фев', 1, 'Мар', 2, 'Апр', 3, 'Май', '4', 'Июн', '5', 'Июл', 6, 'Авг', '7', 'Сен', '8', 'Окт', '9', 'Ноя', '19', 'Дек', '11'); +my @months=('000','Jan',"Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct", + "Nov","Dec"); + # Determine whether the given time is within 2 months from now. sub NewEnough { @@ -106,7 +109,7 @@ sub GetTourQuestions { my (@arr, @Questions); my ($sth) = $dbh->prepare("SELECT QuestionId FROM Questions - WHERE ParentId=$ParentId"); + WHERE ParentId=$ParentId order by Number"); $sth->execute; @@ -157,7 +160,7 @@ sub printform my $inputstring=textfield(-name=>'sstr', -default=>param('sstr')||'', -size=>30, - -maxlength=>30); + -maxlength=>50); my $qnumber="Выводить по".br. textfield(-name=>'kvo', -default=>param('kvo')||'150', -size=>3, @@ -354,8 +357,9 @@ print "$query\n",br if $printqueries; { ($field,$lo,$hi,$wordnumber)=@blob[$ii..($ii+3)]; $ii+=4; - $number=$lo+$hi*256; - $field=$fieldname{$field}; + my $addnumber=($field >> 4) << 16; + $number=(($field >> 4) << 16)+($hi << 8) + $lo; + $field=$fieldname{$field & 0xF}; if ($searchin{$field}) { push @{$tasksof{$i}{$number}}, $wordnumber; @@ -640,7 +644,7 @@ sub PrintList { print "$nav".br."\n"; 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') { $output=~s/\b($shablon)\b/\$1\<\/strong\>/gi; @@ -668,15 +672,15 @@ sub PrintSearch { $sth->execute; my ($q,$nf); ($sstr, $q,$nf)=($sth->fetchrow); - @Questions=unpack 'S*',$q; - @allnf=unpack 'S*',$nf; + @Questions=unpack 'L*',$q; + @allnf=unpack 'L*',$nf; $sth->finish; } else { @Questions=&Search($dbh, \$sstr,$metod,$all,\@allnf); - my $tmp=$dbh->quote(pack("S*",@Questions)); + my $tmp=$dbh->quote(pack("L*",@Questions)); my $qsstr=$dbh->quote($sstr); - my $nf=$dbh->quote(pack("S*", @allnf)); + my $nf=$dbh->quote(pack("L*", @allnf)); my $ss=200; do { @@ -768,7 +772,7 @@ sub PrintRandom { sub PrintEditor { my $t=shift; #ссылка на Хэш с полями - my $ed=$$t{'Editors'}; + my $ed=$$t{'Editors'}||''; my $edname=($ed=~/\,/ ) ? "Редакторы" : "Редактор" ; return $ed? h4({align=>"center"},"$edname: $ed" ): ''; } @@ -816,7 +820,8 @@ sub PrintTournament { } } else { my ($qnum) = GetQNum($dbh); - $output .= h2("Банк Вопросов: $qnum вопросов") . p . "\n"; + $output .= h2("Банк Вопросов: $qnum вопрос".&Suffix($qnum)) + . p . "\n"; } for ($i = 0; $i <= $#Tours; $i++) { @@ -835,6 +840,7 @@ sub PrintTournament { $qnum = ''; } if ($Tournament{'Type'} =~ /Г/) { + $SingleTour=0; $imgsrc = "/icons/folder.gif"; $alt = "[*]"; } else { @@ -867,9 +873,9 @@ sub PrintTournament { "вопросы + ответы") . "]") ); } else { - $list .= dd(a({href=>url . "?tour=$textid&comp=1"}, - img({src=>'/icons/compressed.gif', alt=>'[ZIP]', border=>1})) - . " " . img({src=>$imgsrc, alt=>$alt}) + $list .= dd(#a({href=>url . "?tour=$textid&comp=1"}, + #img({src=>'/icons/compressed.gif', alt=>'[ZIP]', border=>1})). " " . + img({src=>$imgsrc, alt=>$alt}) . " " . a({href=>url . "?tour=$textid&answer=0"}, $Tournament{'Title'}. " ". $Tournament{'PlayedAt'}) . $qnum); @@ -878,6 +884,7 @@ sub PrintTournament { $output .= dl($list); if ($URL) { + if (url=~/zaba\.ru/ && $URL=~/^\//){$URL="http://info.chgk.info$URL"} $output .= p("Дополнительная информация об этом турнире - по адресу " . a({-'href'=>$URL}, $URL)); @@ -999,12 +1006,17 @@ sub PrintTour { sub PrintField { my ($header, $value, $text) = @_; if ($text) { - $value =~ s/<[\/\w]*>//sg; + $value =~ s/<[\/\w]*?>//sg; } else { $value =~ s/^\s+/
    /mg; $value =~ s/^\|([^\n]*)/
$1<\/pre>/mg;
+	    $value =~ s/\s+-+\s+/ – /mg;
+#	    $value =~ s/(\s)"/$1“/mg;
+#	    $value =~ s/^"/“/mg;
+#	    $value =~ s/"/”/mg;
 	}
 
+
 	return $text ? "$header:\n$value\n\n" :
 		strong("$header: ") . $value . p . "\n";
 }
@@ -1015,6 +1027,8 @@ sub PrintQuestion {
 	my ($dbh, $Id, $answer, $qnum, $title, $text) = @_;
 	my ($output, $titles) = ('', '');
 	my (%Question) = &GetQuestion($dbh, $Id);
+	$qnum = $Question{'Number'}
+		if ($qnum == 0);
 	if (!$text) {
 		$output .= hr({width=>"50%"});
 		if ($title) {
@@ -1027,53 +1041,52 @@ sub PrintQuestion {
 					 a({href=>url . "?tour=$fname"}, $Tournament{'Title'}, $Tournament{'PlayedAt'}));
 			$titles .=
 				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));
 	}
 
-	$qnum = $Question{'Number'}
-		if ($qnum == 0);
+
+	$output.= "";
 
 	$output .=
 		&PrintField("Вопрос $qnum", $Question{'Question'}, $text);
 
-	if ($answer) {
+	if ($answer==1) {
 		$output .=
 			&PrintField("Ответ", $Question{'Answer'}, $text);
 
 		if ($Question{'Authors'}) {
                       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;
-#                         $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;
-#                      }
-
+###АВТОРА!!
+ 		      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;
+                          $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'}) {
@@ -1084,8 +1097,40 @@ sub PrintQuestion {
 			$output .= &PrintField("Комментарии", $Question{'Comments'}, $text);
 		}
 	}
-#	$output.=br.a({href=> url."?metod=proxy&qid=$Id"}, 'Близкие вопросы').p
-#             if $answer;
+	elsif ($answer==2) {
+	  my $text=$Question{'Answer'};
+	  $text=~s/\n/