--- db/prgsrc/db.cgi 2003/04/20 08:21:12 1.102 +++ db/prgsrc/db.cgi 2003/05/01 20:46:59 1.118 @@ -9,17 +9,30 @@ use locale; use vars qw($opt_z); use Getopt::Std; getopts('z'); +$opt_z||=param("makehtml"); +my $paramtour; +my $withanswers=param('answer')||param('answers'); open STDERR, ">/var/tmp/errors1"; my $newsurl='http://news.chgk.info/'; -my $HTMLDIR=""; +my $reklama="../dimrub/db/reklama.html"; +my $footer="../dimrub/db/footer.html"; + +my $datefooter="../dimrub/db/date"; + +my $fname; +$reklama="../reklama.html" if $opt_z; +$footer="../footer.html" if $opt_z; +$datefooter="../date" if $opt_z; +my $HTMLDIR="/znatoki/dimrub/db/baza/"; +$HTMLDIR="/baza/"; my $realHTMLDIR; if ($^O =~ /win/i) { - $realHTMLDIR="/html/znatoki/baza"; + $realHTMLDIR="/html/znatoki/baza/"; } else { - $realHTMLDIR="/home/znatoki/public_html/dimrub/db/baza/"; + $realHTMLDIR="/home/piataev/public_html/dimrub/db/baza/"; } -my $usehtml=1; +my $usehtml=$opt_z||0; my $usewas=0; my $cashednumber=500; my $outputnumber=10; @@ -35,16 +48,16 @@ $outputkvo=100 if $outputkvo>100; if (param('debug')) {$debug=1; $printqueries=1} *STDERR=*STDOUT if $debug; -if ($url !~ /db\.chgk\.info/ && $url !~ /localhost/ ) { +if ($url !~ /db\.chgk\.info/ && $url !~ /localhost/ && $url !~ /bilbo/) { my $u="http://db.chgk.info/cgi-bin/db.cgi?$qs"; Redirect ($u); exit; } -if (!param('sstr') && param('all')) { - my $destination='http://db.chgk.info/all.html'; - Redirect($destination); - exit; -} +#if (!param('sstr') && param('all')) { +# my $destination='http://db.chgk.info/all.html'; +# Redirect($destination); +# exit; +#} my $thislocale; if ($^O =~ /win/i) { $thislocale = "Russian_Russia.20866"; @@ -104,7 +117,8 @@ my @months=('000','Jan',"Feb","Mar","Apr sub NewEnough { my ($a) = @_; my ($year, $month, $day) = split('-', $a); - + $month=1 if ($month<=0); + $day=1 if ($day<=0); return (time - timelocal(0, 0, 0, $day, $month -1, $year) < $TMSECS); } @@ -153,12 +167,12 @@ sub GetTournament { sub fetchquestion { my ($sth,$q,$WithTour)=@_; if ($WithTour) { - ($$q{'Question'},$$q{'Answer'},$$q{'Comments'},$$q{'Authors'}, + ($$q{'QuestionId'}, $$q{'Question'},$$q{'Answer'},$$q{'Comments'},$$q{'Authors'}, $$q{'Number'}, $$q{'Title'}, $$q{'TourTitle'}, $$q{'FileName'},$$q{'PlayedAt'},$$q{'TourNumber'}) = $sth->fetchrow; } else { - ($$q{'Question'},$$q{'Answer'},$$q{'Comments'},$$q{'Authors'}, + ($$q{'QuestionId'}, $$q{'Question'},$$q{'Answer'},$$q{'Comments'},$$q{'Authors'}, $$q{'Number'})= $sth->fetchrow; } @@ -166,24 +180,27 @@ sub fetchquestion { + sub SelectQuestions { my ($dbh,$q,$WithTour) = @_; my %q=(); - $_ = "QuestionId=$_" foreach @$q; - my $where=join " OR ",@$q; +# $_ = "QuestionId=$_" foreach @$q; +# my $where=join " OR ",@$q; + my $where=join ',',@$q; + $where &&= "QuestionId IN (".(join ',',$where).")"; $where||=1; $where="($where) AND Questions.ParentId=t1.Id AND t1.ParentId=t2.Id" if $WithTour; my $query; if ($WithTour) { - $query="SELECT Questions.Question, Answer, Comments, Authors, + $query="SELECT QuestionId, Questions.Question, Answer, Comments, Authors, Questions.Number , t2.Title, t1.Title, t2.FileName, t2.PlayedAt,t1.Number from Questions,Tournaments as t1, Tournaments as t2 WHERE $where"; } else { - $query="SELECT Questions.Question, Answer, Comments, Authors, + $query="SELECT QuestionId, Questions.Question, Answer, Comments, Authors, Questions.Number from Questions WHERE $where"; } @@ -223,11 +240,13 @@ sub tourhref { $res=$t; $res.=$a?"-a":"-q" unless $gr; $res.=".html"; + $res=~s/(\#\d+)(.*)$/$2$1/; + $res="$HTMLDIR$res" unless $opt_z; return $res; } else { $res=$url; $res.="?tour=$t"; - $res.=$a?"?answers=1":""; + $res.=$a?"&answers=1":""; return $res; } @@ -382,6 +401,7 @@ sub proxy sub makeproxysstr { my ($dbh,$ptext)=@_; my $text=$$ptext; + POSIX::setlocale( &POSIX::LC_ALL, $thislocale ); $text=~tr/£³/Åå/; $text=~s/(${RLrl})p(${RLrl})/$1p$2/gom; $text=~s/p(${RLrl})/Ò$1/gom; @@ -390,6 +410,7 @@ sub makeproxysstr { $text=~s/[^ÊÃÕËÅÎÇÛÝÚÈßÆÙ×ÁÐÒÏÌÄÖÜÑÞÓÍÉÔØÂÀêãõëåîçûýúèÿæù÷áðòïìäöüñþóíéôøâàQWERTYUIOPASDFGHJKLZXCVBNM0-9]/ /g; $text=uc $text; my @list= $text=~m/(?:(?:${RLrl})+)|(?:[A-Za-z0-9]+)/gom; + my (%c, %good,$sstr); foreach (@list) { @@ -398,7 +419,6 @@ sub makeproxysstr { my @words=sort {$c{$a}<=> $c{$b}} @list; # $good{$words[$_]}=1 foreach 0..4; - foreach (@words) { $good{$_}=1 if $c{$_}<200; @@ -428,7 +448,7 @@ sub russearch { my %relevance; my @blob; my %count; - + POSIX::setlocale( &POSIX::LC_ALL, $thislocale ); $sstr=~tr/ÊÃÕËÅÎÇÛÝÚÈßÆÙ×ÁÐÒÏÌÄÖÜÑÞÓÍÉÔØÂÀ/êãõëåîçûýúèÿæù÷áðòïìäöüñþóíéôøâà/; @qw=@w =split (' ', uc $sstr); @@ -559,7 +579,6 @@ foreach (keys %wordsof) @tasks=sort {$relevance{$b}<=>$relevance{$a}} @tasks; - ############ @@ -726,7 +745,6 @@ sub PrintList { my ($dbh,$Questions,$shablon,$was)=@_; my $Output; my $first=param('first') ||1; - $first=$first-($first-1)%$outputkvo; my $fkvo=param('fkvo')||($#$Questions+1); my $last=$first+$outputkvo-1; @@ -803,14 +821,21 @@ sub PrintList { my @q=@$Questions[$first-1..$last-1]; my %q=(); my $sth=SelectQuestions($dbh,\@q,1); + my $qq; + my @Q; + for (0..$#q) { + %{$Q[$_]}=(); + fetchquestion($sth,$Q[$_],1); + $q{$Q[$_]{'QuestionId'}}=$Q[$_]; + } + for (my $i = $first; $i <= $last; $i++) { - fetchquestion($sth,\%q,1); + my $q=$q{$$Questions[$i-1]}; my $output; - $output = &PrintQuestion($dbh, \%q, 1, 0, 1,0,1 ); - if (param('metod') && (param('metod') eq 'rus' || param('metod') eq 'proxy')) + $output = &PrintQuestion($dbh, $q, 1, 0, 1,0,1 ); +# if (param('metod') && (param('metod') eq 'rus' || param('metod') eq 'proxy')) { $output=~s/\b($shablon)\b/\$1\<\/strong\>/gi; - } else { $output=~s/($shablon)/\$1\<\/strong\>/gi; } $Output.= $output; @@ -971,9 +996,9 @@ sub PrintTournament { %Tournament = &GetTournament($dbh, $Id) if ($Id); - my ($URL) = $Tournament{'URL'}; - $URL=~s/http:\/znatoki\/boris\/reports\//$newsurl/ if $url=~/kulichki/; - $URL=~s/\/znatoki\/boris\/reports\//$newsurl/ if url=~/kulichki/;; + my ($URL) = $Tournament{'URL'}||''; + $URL=~s/http:\/znatoki\/boris\/reports\//$newsurl/ if $url=~/kulichki/ || $url=~/db.chgk.info/; + $URL=~s/\/znatoki\/boris\/reports\//$newsurl/ if url=~/kulichki/ || $url=~/db.chgk.info/; my ($Info) = $Tournament{'Info'}; my ($Copyright) = $Tournament{'Copyright'}; my $fname=$Tournament{'FileName'}; @@ -1049,10 +1074,10 @@ sub PrintTournament { else {$textid=$Tournament{'Id'}}; - if ($SingleTour or $Tournament{'Type'} =~ /ô/) { + if ($SingleTour or ($Tournament{'Type'} =~ /ô/)) { $list .= dd(img({src=>$imgsrc, alt=>$alt}) . " " . $Tournament{'Title'} . " " . - $Tournament{'PlayedAt'} . $qnum) . + ($Tournament{'PlayedAt'}||"") . $qnum) . dl( dd("[" . a({href=>tourhref($textid,0)}, @@ -1063,11 +1088,12 @@ sub PrintTournament { } else { $list .= dd(a({href=> $url . "?tour=$textid&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}) . " " . a({href=>tourhref($textid,0,1)}, $Tournament{'Title'}. " ". - $Tournament{'PlayedAt'}||'') . $qnum); + ($Tournament{'PlayedAt'}||'')) . $qnum); } } $output .= dl($list); @@ -1170,7 +1196,7 @@ sub PrintTour { my $n=$Tour{'Number'}; if ($answer == 0) { $bottom .= - "[" . a({href=>tourhref($fname,1)}, + "[" . a({href=>tourhref("$fname.$n",1)}, "ÏÔ×ÅÔÙ") . "] " . br; } if ($n>1) { @@ -1347,7 +1373,8 @@ $output.="" } $output=~s/\(pic: ([^\)]*)\)/

/g unless $text; - my $qid=param('tour') ? (param('tour').".$Question{'Number'}" ): ''; + $paramtour||=param("tour"); + my $qid=$paramtour ? ($paramtour.".$Question{'Number'}" ): ''; $output.=br.a({href=> $url."?metod=proxy& qid=$qid"}, 'âÌÉÚËÉÅ ×ÏÐÒÏÓÙ').p @@ -1412,9 +1439,9 @@ sub Get12Random { sub Include_virtual { my ($fn, $output) = (@_, ''); - + return "" if ($opt_z); open F , $fn - or return; #die "Can't open the file $fn: $!\n"; + or return ""; #die "Can't open the file $fn: $!\n"; while () { if (/