--- db/prgsrc/db.cgi 2003/04/20 11:44:46 1.105 +++ db/prgsrc/db.cgi 2003/04/22 10:49:32 1.114 @@ -9,9 +9,12 @@ use locale; use vars qw($opt_z); use Getopt::Std; getopts('z'); +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"; +$reklama="../reklama.html" if $opt_z; +my $HTMLDIR="/znatoki/dimrub/db/baza/"; my $realHTMLDIR; if ($^O =~ /win/i) { $realHTMLDIR="/html/znatoki/baza/"; @@ -19,7 +22,7 @@ if ($^O =~ /win/i) { { $realHTMLDIR="/home/znatoki/public_html/dimrub/db/baza/"; } -my $usehtml=1; +my $usehtml=0; my $usewas=0; my $cashednumber=500; my $outputnumber=10; @@ -35,7 +38,7 @@ $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; @@ -105,7 +108,7 @@ sub NewEnough { my ($a) = @_; my ($year, $month, $day) = split('-', $a); $month=1 if ($month<=0); - $day=1 if ($day<0); + $day=1 if ($day<=0); return (time - timelocal(0, 0, 0, $day, $month -1, $year) < $TMSECS); } @@ -224,11 +227,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; } @@ -1414,7 +1419,7 @@ 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"; @@ -1452,6 +1457,8 @@ sub PrintAll { my (%Tournament) = &GetTournament($dbh, $Id); my (@Tours) = &GetTours($dbh, $Id); + my $SingleTour = $#Tours == 0; + my ($New) = ($Id and $Tournament{'Type'} eq 'Ч' and &NewEnough($Tournament{"CreatedAt"})) ? img({src=>"/znatoki/dimrub/db/new-sml.gif", alt=>"NEW!"}) : ""; @@ -1473,7 +1480,7 @@ sub PrintAll { $output .= dd(img({src=>"/icons/folder.gif", alt=>"[*]"}) . - " " . a({href=>tourhref($textid,0,1)}, + " " . a({href=>tourhref($textid,0,!$SingleTour)}, $Tournament{'Title'}) ." " . ($Tournament{'PlayedAt'}||'') . " $New"); } if ($Id == 0 or $Tournament{'Type'} =~ /Г/ or $Tournament{'Type'} eq '') { @@ -1809,7 +1816,7 @@ MAIN: or do { print h1("Временные проблемы") . "База вопросов временно не работает. Заходите попозже."; - print &Include_virtual("../dimrub/db/reklama.html") if $url!~/localhost/; + print &Include_virtual("$reklama") if $url!~/localhost/; print end_html; die "Can't connect to DB chgk\n"; }; @@ -1874,7 +1881,7 @@ td {font-size: x-small; font-family : sa th {font-size: x-small; font-family : sans-serif} \n"; - $globaloutput.=&Include_virtual("../dimrub/db/reklama.html")||''; + $globaloutput.=&Include_virtual("$reklama")||''; } if (length ($qs)<=255 && $qs !~ /(sstr)|(rand)|(comp)|(all=)/i) { @@ -2015,10 +2022,10 @@ EOT $QuestionNumber=($sth->fetchrow)[0]||0; } if ($QuestionNumber) { - $globaloutput.= &PrintQuestion($dbh, $QuestionNumber, param('answer')||0, $qnum, 1,0,0); + $globaloutput.= &PrintQuestion($dbh, $QuestionNumber, $withanswers||0, $qnum, 1,0,0); # $dbh, $Id, $answer, $qnum, $title, $text } else { - $globaloutput.=&PrintTournament($dbh, $tour, param('answer')); + $globaloutput.=&PrintTournament($dbh, $tour, $withanswers); } } else { @@ -2053,7 +2060,7 @@ my ($sth) = $dbh->prepare("SELECT t1.Id, $fname=~s/\.txt$//; if ($type=~/Т/ || $c<=1) { - open FF, ">$realHTMLDIR$fname-q.html" or die "ERROR! - $HTMLDIR$fname-q.html\n"; + open FF, ">$realHTMLDIR$fname-q.html" or die "ERROR! - $fname-q.html\n"; my $o=$globaloutput; $o.=&PrintTournament($dbh, $Id, 0); $o.=&Bottom; @@ -2067,7 +2074,7 @@ my ($sth) = $dbh->prepare("SELECT t1.Id, close FF; } else { - open FF, ">$realHTMLDIR$fname.html" or die "ERROR! - $HTMLDIR$fname-q.html\n"; + open FF, ">$realHTMLDIR$fname.html" or die "ERROR! - $fname-q.html\n"; my $o=$globaloutput; $o.=&PrintTournament($dbh, $Id, 0); $o.=&Bottom;