--- db/prgsrc/db.cgi 2003/04/22 10:50:37 1.115 +++ db/prgsrc/db.cgi 2003/04/28 22:49:50 1.116 @@ -9,18 +9,28 @@ 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 $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/"; } else { - $realHTMLDIR="/home/znatoki/public_html/dimrub/db/baza/"; + $realHTMLDIR="/home/piataev/public_html/dimrub/db/baza/"; } my $usehtml=$opt_z||0; my $usewas=0; @@ -157,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; } @@ -170,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"; } @@ -388,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; @@ -396,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) { @@ -404,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; @@ -434,7 +448,7 @@ sub russearch { my %relevance; my @blob; my %count; - + POSIX::setlocale( &POSIX::LC_ALL, $thislocale ); $sstr=~tr/ÊÃÕËÅÎÇÛÝÚÈßÆÙ×ÁÐÒÏÌÄÖÜÑÞÓÍÉÔØÂÀ/êãõëåîçûýúèÿæù÷áðòïìäöüñþóíéôøâà/; @qw=@w =split (' ', uc $sstr); @@ -565,7 +579,6 @@ foreach (keys %wordsof) @tasks=sort {$relevance{$b}<=>$relevance{$a}} @tasks; - ############ @@ -732,7 +745,7 @@ sub PrintList { my ($dbh,$Questions,$shablon,$was)=@_; my $Output; my $first=param('first') ||1; - +print "shablon=$shablon".p; $first=$first-($first-1)%$outputkvo; my $fkvo=param('fkvo')||($#$Questions+1); my $last=$first+$outputkvo-1; @@ -809,14 +822,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; @@ -978,8 +998,8 @@ 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/;; + $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'}; @@ -1067,10 +1087,10 @@ sub PrintTournament { "×ÏÐÒÏÓÙ + ÏÔ×ÅÔÙ") . "]") ); } else { - $list .= dd(a({href=> - $url . "?tour=$textid&comp=1"}, - img({src=>'/icons/compressed.gif', alt=>'[ZIP]', border=>1})). - " " . + $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=>tourhref($textid,0,1)}, $Tournament{'Title'}. " ". @@ -1177,7 +1197,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) { @@ -1354,7 +1374,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 @@ -1633,7 +1654,8 @@ sub WriteFile { my $query= "SELECT Id, Title, Copyright, Info, URL, Editors, EnteredBy, PlayedAt, CreatedAt - from Tournaments where FileName=".$dbh->quote("$fname.txt"); + from Tournaments where FileName= + '$fname' OR FileName=".$dbh->quote("$fname.txt"); my $sth=$dbh->prepare($query); my (%Question,%editor,%qnumber,%copyright,%author,%vid,%tourtitle); $sth->execute; @@ -1776,8 +1798,8 @@ sub WriteFile { sub Bottom { - my $output.=&Include_virtual("../dimrub/db/footer.html")||""; - $output.=p."

ïÂÎÏ×ÌÅÎÉÅ: ".&Include_virtual("../dimrub/db/date")."
"; + my $output.=&Include_virtual("$footer")||""; + $output.=p."
ïÂÎÏ×ÌÅÎÉÅ: ".&Include_virtual("$datefooter")."
"; $output.=< function toggle(e) { @@ -1799,6 +1821,7 @@ MAIN: { setlocale(LC_CTYPE,'russian'); + POSIX::setlocale( &POSIX::LC_ALL, $thislocale ); my($i, $tour); my($text) = (param('text')) ? 1 : 0; if (param('qid') && (param('qid')=~/^\d+$/)) { @@ -1821,6 +1844,7 @@ MAIN: die "Can't connect to DB chgk\n"; }; my $sstr=param('sstr'); + $opt_z||=param("makehtml"); if (param('qid')) { my $sth; my $qid=param('qid'); @@ -1828,19 +1852,20 @@ MAIN: { my ($fname,$t,$n)= split /\./ , $qid; $n=$t,$t='' unless $n; + $t||=1; if ($t) { $sth = $dbh->prepare( "SELECT t2.Id FROM Tournaments as t1, Tournaments as t2 - WHERE t1.FileName = '$fname.txt' + WHERE (t1.FileName = '$fname.txt' OR t1.FileName='$fname') AND t1.Id=t2.ParentId AND t2.Number=$t"); } - else - { - $sth = $dbh->prepare("SELECT Id FROM Tournaments - WHERE FileName = '$fname.txt'"); - } +# else +# { +# $sth = $dbh->prepare("SELECT Id FROM Tournaments +# WHERE FileName = '$fname.txt' OR FileName = '$fname'" ); +# } $sth->execute; $tour = ($sth->fetchrow)[0]; $sth->finish; @@ -1884,7 +1909,7 @@ th {font-size: x-small; font-family : sa $globaloutput.=&Include_virtual("$reklama")||''; } - if (length ($qs)<=255 && $qs !~ /(sstr)|(rand)|(comp)|(all=)/i) { + if (!$opt_z && length ($qs)<=255 && $qs !~ /(sstr)|(rand)|(comp)|(all=)/i) { my $sth=$dbh->prepare("SELECT page,times,t from hash where query=".$dbh->quote($qs)); $sth->execute(); my ($p,$times,$t)=$sth->fetchrow(); @@ -1918,7 +1943,7 @@ th {font-size: x-small; font-family : sa $sth = $dbh->prepare( "SELECT t2.Id FROM Tournaments as t1, Tournaments as t2 - WHERE t1.FileName = '$fname.txt' + WHERE (t1.FileName = '$fname.txt' OR t1.FileName='$fname') AND t1.Id=t2.ParentId AND t2.Number=$n"); } else @@ -2012,7 +2037,7 @@ EOT exit; } - elsif (!$opt_z) { + elsif (!$opt_z && !param("makehtml")) { my $QuestionNumber=0; my $qnum; if ($qnum=param('qnumber')){ @@ -2029,6 +2054,8 @@ EOT } } else { + $opt_z=1; + $url="http://db.chgk.info/cgi-bin/db.cgi"; open TS, "timestamp"; my $d=$dbh->quote(); close TS; @@ -2062,6 +2089,7 @@ my ($sth) = $dbh->prepare("SELECT t1.Id, { open FF, ">$realHTMLDIR$fname-q.html" or die "ERROR! - $fname-q.html\n"; my $o=$globaloutput; + $paramtour=$fname; $o.=&PrintTournament($dbh, $Id, 0); $o.=&Bottom; print FF $o;