--- db/prgsrc/db.cgi 2004/02/08 00:35:29 1.129 +++ db/prgsrc/db.cgi 2004/05/02 20:48:30 1.134 @@ -2,23 +2,34 @@ use DBI; use CGI ':all'; -use strict; +#use strict; use Time::Local; +my $proxyredirect=1; use POSIX qw(locale_h); use locale; use vars qw($opt_z); use Getopt::Std; +#my ($dbuser,$dbname,$dbpass,$dbhost); +require "dbdefs.pl"; +my $url=url||''; +$dbuser||="piataev"; +$dbname||="chgk"; +$dbpass||=""; +$dbhost||="localhost"; getopts('z'); $opt_z||=param("makehtml"); my $timestamp="_timestamp.tmp"; +my $usehash=0; 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"; - +$footer="../../chgk/footer.html" if $url=~/zaba/; +$reklama="../../chgk/reklama.html" if $url=~/zaba/; my $datefooter="../dimrub/db/date"; +$datefooter="../../chgk/date" if $url=~/zaba/; my $fname; $reklama="../reklama.html" if $opt_z; @@ -33,28 +44,39 @@ if ($^O =~ /win/i) { { $realHTMLDIR="/home/piataev/public_html/dimrub/db/files/"; } + + my $usehtml=$opt_z||0; $usehtml=1; +$usehtml=0 if $url=~/zaba/; + my $usewas=0; my $cashednumber=500; my $outputnumber=10; my ($proxyptext,$proxysstr); my $printqueries=0; -my $url=url||''; my $qs=query_string; my $globaloutput; my %forbidden=(); my $debug=0; #added by R7 +my $metod=param('metod')||''; my $outputkvo=param('kvo') ||$outputnumber; $outputkvo=100 if $outputkvo>100; if (param('debug')) {$debug=1; $printqueries=1} *STDERR=*STDOUT if $debug; -if ($url !~ /db\.chgk\.info/ && $url !~ /localhost/ && $url !~ /bilbo/) { +if ($url !~ /db\.chgk\.info/ && $url !~ /localhost/ && $url !~ /bilbo/ && $url !~ /zaba/) { my $u="http://db.chgk.info/cgi-bin/db.cgi?$qs"; Redirect ($u); exit; } + +if ($proxyredirect && $metod=~/proxy/ && $url !~ /localhost/ && $url !~ /bilbo/ && $url !~ /zaba/) { + my $u="http://chgk.zaba.ru/cgi-bin/db.cgi?$qs"; + Redirect ($u); + exit; +} + #if (!param('sstr') && param('all')) { # my $destination='http://db.chgk.info/all.html'; # Redirect($destination); @@ -268,8 +290,9 @@ sub tourhref { return $res; } else { $res=$url; - $res.="?tour=$t"; - $res.=$a?"&answers=1":""; + $res.=$a?"?answers=1&":"?"; + $res.="tour=$t"; + return $res; } @@ -406,6 +429,9 @@ action="/znatoki/cgi-bin/db.cgi"> +

Если при попытке поиска выдаётся сообщение об ошибке, +попробуйте воспользоваться +зеркалом базы EOT @@ -444,7 +470,7 @@ sub makeproxysstr { # $good{$words[$_]}=1 foreach 0..4; foreach (@words) { - $good{$_}=1 if $c{$_}<200; + $good{$_}=1 if $c{$_}<200 && length $_>2; } $good{$words[$_]}=0 foreach 16..$#words; @@ -590,7 +616,12 @@ $sstr=~tr/йцукенгшщзхъфывапролджэячсмить #Ищем пересечение или объединение списков вопросов (значений %tasksof) foreach $sf (keys %tasksof) { - $count{$_}++ foreach keys %{$tasksof{$sf}}; + foreach (keys %{$tasksof{$sf}}) + { + next if $forbidden{$_}; + $count{$_}++ + } + } @tasks= ($all ? (grep {$count{$_}==$kvo} keys %count) : keys %count) ; @@ -1308,6 +1339,7 @@ sub PrintField { sub PrintQuestion { my ($dbh, $Id, $answer, $qnum, $title, $text,$h) = @_; my ($output, $titles) = ('', ''); + my $fname; my (%Question); if ($h) { %Question=%$Id; @@ -1329,7 +1361,7 @@ sub PrintQuestion { if (!$text) { $output .= hr({width=>"50%"}) if $answer>=0; if ($title) { - my $fname=$Question{'FileName'}; + $fname=$Question{'FileName'}; $fname=~s/\.txt//; $titles .= dd(img({src=>"/icons/folder.open.gif"}) . " " . @@ -1435,7 +1467,9 @@ $output.="" } $output=~s/\(pic: ([^\)]*)\)/

/g unless $text; $paramtour||=param("tour"); - my $qid=$paramtour ? ($paramtour.".$Question{'Number'}" ): ''; + $fname=$fname.".$Question{'TourNumber'}" if $fname && $Question{'TourNumber'}; +$fname||=param('tour'); + my $qid=$fname ? ($fname.".$Question{'Number'}" ): ''; $output.=br.a({href=> $url."?metod=proxy& qid=$qid"}, 'Близкие вопросы').p @@ -1481,7 +1515,8 @@ sub Get12Random { srand; my $where=0; my $r=int (rand(10000)); - my $w1=$r<5000? "QuestionId<5000 ":"QuestionId>=5000"; + my $w1=$r<5000? "QuestionId<50000 ":"QuestionId>=50000"; + $w1=1 if $url=~/zaba/; $w1=1 if $type!~/Ч/; foreach (split '', $type) { @@ -1909,9 +1944,11 @@ MAIN: $tour = (param('tour')) ? param('tour') : 0; my $texttour=$tour; my ($sth,$dbh); - $dbh = DBI->connect("DBI:mysql:chgk", "piataev", "") + my($dsn) = "DBI:mysql:database=$dbname;host=$dbhost"; + $dbh = DBI->connect($dsn, $dbuser, $dbpass) +# $dbh = DBI->connect("DBI:mysql:$dbname", $username, $dbpass) or do { - print h1("Временные проблемы") . "База вопросов временно не + print header.h1("Временные проблемы") . "База вопросов временно не работает. Заходите попозже."; print &Include_virtual("$reklama") if $url!~/localhost/; print end_html; @@ -1920,7 +1957,7 @@ MAIN: if (param('qid') && (param('qid')=~/^\d+$/) || $tour && $tour=~/^\d+$/) { - my $destination='http://db.chgk.info/search.html'; + my $destination='http://chgk.zaba.ru/search.html'; # print header (-'Content-Type' => 'text/html', # -'Location:'=> 'http:\\db.chgk.info'); Redirect($destination); @@ -1936,14 +1973,13 @@ MAIN: my $d=$destination; $d=~s/$HTMLDIR/$realHTMLDIR/; # print header.$destination; - print header."$d|".(-e "$realHTMLDIR$n.html"); +# print header."$d|".(-e "$realHTMLDIR$n.html"); if (-e $d) { Redirect($destination); exit } $d=~s/\.\d+//; $destination=~s/\.\d+//; -print br.br.$d; if (-e $d) { Redirect($destination); exit @@ -1976,7 +2012,8 @@ print br.br.$d; if ($text && !param ('comp')) { print header('text/plain'); - } elsif (!param('comp')) {print header;} + } elsif (!param('comp')) { + print header(-charset =>'koi8-r')} my $sstr=param('sstr'); $opt_z||=param("makehtml"); if (param('qid')) { @@ -2030,11 +2067,10 @@ print br.br.$d; my $title="Результаты поиска на \"". ($proxysstr||$sstr) .'"' if ($proxysstr||$sstr); $title||="База вопросов"; - $globaloutput.=start_html(-"title"=>$title, -author=>'dimrub@icomverse.com', -bgcolor=>'#fff0e0', - -vlink=>'#800020'); + -vlink=>'#800020');#} $globaloutput.="