version 1.128, 2004/01/10 22:52:20
|
version 1.134, 2004/05/02 20:48:30
|
Line 2
|
Line 2
|
|
|
use DBI; |
use DBI; |
use CGI ':all'; |
use CGI ':all'; |
use strict; |
#use strict; |
use Time::Local; |
use Time::Local; |
|
my $proxyredirect=1; |
use POSIX qw(locale_h); |
use POSIX qw(locale_h); |
use locale; |
use locale; |
use vars qw($opt_z); |
use vars qw($opt_z); |
use Getopt::Std; |
use Getopt::Std; |
|
#my ($dbuser,$dbname,$dbpass,$dbhost); |
|
require "dbdefs.pl"; |
|
my $url=url||''; |
|
$dbuser||="piataev"; |
|
$dbname||="chgk"; |
|
$dbpass||=""; |
|
$dbhost||="localhost"; |
getopts('z'); |
getopts('z'); |
$opt_z||=param("makehtml"); |
$opt_z||=param("makehtml"); |
my $timestamp="_timestamp.tmp"; |
my $timestamp="_timestamp.tmp"; |
|
my $usehash=0; |
my $paramtour; |
my $paramtour; |
my $withanswers=param('answer')||param('answers'); |
my $withanswers=param('answer')||param('answers'); |
open STDERR, ">/var/tmp/errors1"; |
open STDERR, ">/var/tmp/errors1"; |
my $newsurl='http://news.chgk.info/'; |
my $newsurl='http://news.chgk.info/'; |
my $reklama="../dimrub/db/reklama.html"; |
my $reklama="../dimrub/db/reklama.html"; |
my $footer="../dimrub/db/footer.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"; |
my $datefooter="../dimrub/db/date"; |
|
$datefooter="../../chgk/date" if $url=~/zaba/; |
|
|
my $fname; |
my $fname; |
$reklama="../reklama.html" if $opt_z; |
$reklama="../reklama.html" if $opt_z; |
Line 33 if ($^O =~ /win/i) {
|
Line 44 if ($^O =~ /win/i) {
|
{ |
{ |
$realHTMLDIR="/home/piataev/public_html/dimrub/db/files/"; |
$realHTMLDIR="/home/piataev/public_html/dimrub/db/files/"; |
} |
} |
|
|
|
|
my $usehtml=$opt_z||0; |
my $usehtml=$opt_z||0; |
$usehtml=1; |
$usehtml=1; |
|
$usehtml=0 if $url=~/zaba/; |
|
|
my $usewas=0; |
my $usewas=0; |
my $cashednumber=500; |
my $cashednumber=500; |
my $outputnumber=10; |
my $outputnumber=10; |
my ($proxyptext,$proxysstr); |
my ($proxyptext,$proxysstr); |
my $printqueries=0; |
my $printqueries=0; |
my $url=url||''; |
|
my $qs=query_string; |
my $qs=query_string; |
my $globaloutput; |
my $globaloutput; |
my %forbidden=(); |
my %forbidden=(); |
my $debug=0; #added by R7 |
my $debug=0; #added by R7 |
|
my $metod=param('metod')||''; |
my $outputkvo=param('kvo') ||$outputnumber; |
my $outputkvo=param('kvo') ||$outputnumber; |
$outputkvo=100 if $outputkvo>100; |
$outputkvo=100 if $outputkvo>100; |
|
|
if (param('debug')) {$debug=1; $printqueries=1} |
if (param('debug')) {$debug=1; $printqueries=1} |
*STDERR=*STDOUT if $debug; |
*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"; |
my $u="http://db.chgk.info/cgi-bin/db.cgi?$qs"; |
Redirect ($u); |
Redirect ($u); |
exit; |
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')) { |
#if (!param('sstr') && param('all')) { |
# my $destination='http://db.chgk.info/all.html'; |
# my $destination='http://db.chgk.info/all.html'; |
# Redirect($destination); |
# Redirect($destination); |
Line 268 sub tourhref {
|
Line 290 sub tourhref {
|
return $res; |
return $res; |
} else { |
} else { |
$res=$url; |
$res=$url; |
$res.="?tour=$t"; |
$res.=$a?"?answers=1&":"?"; |
$res.=$a?"&answers=1":""; |
$res.="tour=$t"; |
|
|
return $res; |
return $res; |
} |
} |
|
|
Line 406 action="/znatoki/cgi-bin/db.cgi">
|
Line 429 action="/znatoki/cgi-bin/db.cgi">
|
</td> |
</td> |
</tr> |
</tr> |
</table> |
</table> |
|
<p><i>Если при попытке поиска выдаётся сообщение об ошибке, |
|
попробуйте воспользоваться |
|
<a href="http://chgk.zaba.ru/search.html">зеркалом базы</a></i> |
</center> |
</center> |
|
|
EOT |
EOT |
Line 444 sub makeproxysstr {
|
Line 470 sub makeproxysstr {
|
# $good{$words[$_]}=1 foreach 0..4; |
# $good{$words[$_]}=1 foreach 0..4; |
foreach (@words) |
foreach (@words) |
{ |
{ |
$good{$_}=1 if $c{$_}<200; |
$good{$_}=1 if $c{$_}<200 && length $_>2; |
} |
} |
|
|
$good{$words[$_]}=0 foreach 16..$#words; |
$good{$words[$_]}=0 foreach 16..$#words; |
Line 590 $sstr=~tr/йцукенгшщзхъфывапролджэячсмить
|
Line 616 $sstr=~tr/йцукенгшщзхъфывапролджэячсмить
|
#Ищем пересечение или объединение списков вопросов (значений %tasksof) |
#Ищем пересечение или объединение списков вопросов (значений %tasksof) |
foreach $sf (keys %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) : |
@tasks= ($all ? (grep {$count{$_}==$kvo} keys %count) : |
keys %count) ; |
keys %count) ; |
Line 974 sub PrintRandom {
|
Line 1005 sub PrintRandom {
|
my %q; |
my %q; |
my $answer=$razd?0:1; |
my $answer=$razd?0:1; |
my @answers; |
my @answers; |
|
#my $t=time; |
my (@Questions) = &Get12Random($dbh, $type, $num); |
my (@Questions) = &Get12Random($dbh, $type, $num); |
my ($output, $i) = ('', 0); |
|
|
|
|
my ($output, $i) = ('', 0); |
|
#$output.="time=".(time-$t).p; |
if ($text) { |
if ($text) { |
$output .= " $num случайных вопросов.\n\n"; |
$output .= " $num случайных вопросов.\n\n"; |
} else { |
} else { |
Line 1306 sub PrintField {
|
Line 1339 sub PrintField {
|
sub PrintQuestion { |
sub PrintQuestion { |
my ($dbh, $Id, $answer, $qnum, $title, $text,$h) = @_; |
my ($dbh, $Id, $answer, $qnum, $title, $text,$h) = @_; |
my ($output, $titles) = ('', ''); |
my ($output, $titles) = ('', ''); |
|
my $fname; |
my (%Question); |
my (%Question); |
if ($h) { |
if ($h) { |
%Question=%$Id; |
%Question=%$Id; |
Line 1327 sub PrintQuestion {
|
Line 1361 sub PrintQuestion {
|
if (!$text) { |
if (!$text) { |
$output .= hr({width=>"50%"}) if $answer>=0; |
$output .= hr({width=>"50%"}) if $answer>=0; |
if ($title) { |
if ($title) { |
my $fname=$Question{'FileName'}; |
$fname=$Question{'FileName'}; |
$fname=~s/\.txt//; |
$fname=~s/\.txt//; |
$titles .= |
$titles .= |
dd(img({src=>"/icons/folder.open.gif"}) . " " . |
dd(img({src=>"/icons/folder.open.gif"}) . " " . |
Line 1433 $output.="</span>"
|
Line 1467 $output.="</span>"
|
} |
} |
$output=~s/\(pic: ([^\)]*)\)/<p><img src="\/znatoki\/images\/db\/$1"><p>/g unless $text; |
$output=~s/\(pic: ([^\)]*)\)/<p><img src="\/znatoki\/images\/db\/$1"><p>/g unless $text; |
$paramtour||=param("tour"); |
$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& |
$output.=br.a({href=> $url."?metod=proxy& |
qid=$qid"}, 'Близкие вопросы').p |
qid=$qid"}, 'Близкие вопросы').p |
Line 1479 sub Get12Random {
|
Line 1515 sub Get12Random {
|
srand; |
srand; |
my $where=0; |
my $where=0; |
my $r=int (rand(10000)); |
my $r=int (rand(10000)); |
|
my $w1=$r<5000? "QuestionId<50000 ":"QuestionId>=50000"; |
|
$w1=1 if $url=~/zaba/; |
|
$w1=1 if $type!~/Ч/; |
foreach (split '', $type) |
foreach (split '', $type) |
{ |
{ |
$where.= " OR (Type ='$_') OR (Type ='$_Д') "; |
$where.= " OR (Type ='$_') OR (Type ='$_Д') "; |
Line 1489 sub Get12Random {
|
Line 1527 sub Get12Random {
|
# $q="select QuestionId, QuestionId/$r-floor(QuestionId/$r) as val |
# $q="select QuestionId, QuestionId/$r-floor(QuestionId/$r) as val |
# from Questions where $where order by val limit $num"; |
# from Questions where $where order by val limit $num"; |
# Когда на куличках появится mysql >=3.23 надо заменить на order by rand(); |
# Когда на куличках появится mysql >=3.23 надо заменить на order by rand(); |
$q="select QuestionId from Questions where $where order by rand() limit $num"; |
$q="select QuestionId from Questions where ($w1) AND ($where) order by rand() limit $num"; |
|
|
|
|
$sth=$dbh->prepare($q); |
$sth=$dbh->prepare($q); |
Line 1906 MAIN:
|
Line 1944 MAIN:
|
$tour = (param('tour')) ? param('tour') : 0; |
$tour = (param('tour')) ? param('tour') : 0; |
my $texttour=$tour; |
my $texttour=$tour; |
my ($sth,$dbh); |
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 { |
or do { |
print h1("Временные проблемы") . "База вопросов временно не |
print header.h1("Временные проблемы") . "База вопросов временно не |
работает. Заходите попозже."; |
работает. Заходите попозже."; |
print &Include_virtual("$reklama") if $url!~/localhost/; |
print &Include_virtual("$reklama") if $url!~/localhost/; |
print end_html; |
print end_html; |
Line 1917 MAIN:
|
Line 1957 MAIN:
|
|
|
|
|
if (param('qid') && (param('qid')=~/^\d+$/) || $tour && $tour=~/^\d+$/) { |
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', |
# print header (-'Content-Type' => 'text/html', |
# -'Location:'=> 'http:\\db.chgk.info'); |
# -'Location:'=> 'http:\\db.chgk.info'); |
Redirect($destination); |
Redirect($destination); |
Line 1933 MAIN:
|
Line 1973 MAIN:
|
my $d=$destination; |
my $d=$destination; |
$d=~s/$HTMLDIR/$realHTMLDIR/; |
$d=~s/$HTMLDIR/$realHTMLDIR/; |
# print header.$destination; |
# print header.$destination; |
print header."$d|".(-e "$realHTMLDIR$n.html"); |
# print header."$d|".(-e "$realHTMLDIR$n.html"); |
if (-e $d) { |
if (-e $d) { |
Redirect($destination); |
Redirect($destination); |
exit |
exit |
} |
} |
$d=~s/\.\d+//; |
$d=~s/\.\d+//; |
$destination=~s/\.\d+//; |
$destination=~s/\.\d+//; |
print br.br.$d; |
|
if (-e $d) { |
if (-e $d) { |
Redirect($destination); |
Redirect($destination); |
exit |
exit |
Line 1973 print br.br.$d;
|
Line 2012 print br.br.$d;
|
|
|
if ($text && !param ('comp')) { |
if ($text && !param ('comp')) { |
print header('text/plain'); |
print header('text/plain'); |
} elsif (!param('comp')) {print header;} |
} elsif (!param('comp')) { |
|
print header(-charset =>'koi8-r')} |
my $sstr=param('sstr'); |
my $sstr=param('sstr'); |
$opt_z||=param("makehtml"); |
$opt_z||=param("makehtml"); |
if (param('qid')) { |
if (param('qid')) { |
Line 2027 print br.br.$d;
|
Line 2067 print br.br.$d;
|
my $title="Результаты поиска на \"". ($proxysstr||$sstr) .'"' |
my $title="Результаты поиска на \"". ($proxysstr||$sstr) .'"' |
if ($proxysstr||$sstr); |
if ($proxysstr||$sstr); |
$title||="База вопросов"; |
$title||="База вопросов"; |
|
|
$globaloutput.=start_html(-"title"=>$title, |
$globaloutput.=start_html(-"title"=>$title, |
-author=>'dimrub@icomverse.com', |
-author=>'dimrub@icomverse.com', |
-bgcolor=>'#fff0e0', |
-bgcolor=>'#fff0e0', |
-vlink=>'#800020'); |
-vlink=>'#800020');#} |
$globaloutput.="<style> |
$globaloutput.="<style> |
td {font-size: x-small; font-family : sans-serif} |
td {font-size: x-small; font-family : sans-serif} |
th {font-size: x-small; font-family : sans-serif} |
th {font-size: x-small; font-family : sans-serif} |
Line 2040 th {font-size: x-small; font-family : sa
|
Line 2079 th {font-size: x-small; font-family : sa
|
$globaloutput.=&Include_virtual("$reklama")||''; |
$globaloutput.=&Include_virtual("$reklama")||''; |
} |
} |
|
|
if (!$opt_z && length ($qs)<=255 && $qs !~ /(sstr)|(rand)|(comp)|(all=)/i) { |
if ($usehash && !$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)); |
my $sth=$dbh->prepare("SELECT page,times,t from hash where query=".$dbh->quote($qs)); |
$sth->execute(); |
$sth->execute(); |
my ($p,$times,$t)=$sth->fetchrow(); |
my ($p,$times,$t)=$sth->fetchrow(); |
Line 2066 th {font-size: x-small; font-family : sa
|
Line 2105 th {font-size: x-small; font-family : sa
|
} |
} |
|
|
|
|
|
|
if (param('rand')) { |
if (param('rand')) { |
my ($type, $qnum) = ('', 12); |
my ($type, $qnum) = ('', 12); |
$type.=$TypeName{$_} foreach param('type'); |
$type.=$TypeName{$_} foreach param('type'); |
Line 2225 my ($sth) = $dbh->prepare("SELECT t1.Id,
|
Line 2265 my ($sth) = $dbh->prepare("SELECT t1.Id,
|
} |
} |
if (!$opt_z){ |
if (!$opt_z){ |
print $globaloutput; |
print $globaloutput; |
if (($qs!~ /(rand)|(sstr)|(comp)/i) && (length $qs<=255)) { |
if (($qs!~ /(rand)|(sstr)|(comp)/i) && (length $qs<=255) && $usehash) { |
$globaloutput= $dbh->quote($globaloutput); |
$globaloutput= $dbh->quote($globaloutput); |
$dbh->do("insert into hash (query,page) values (". |
$dbh->do("insert into hash (query,page) values (". |
$dbh->quote($qs). |
$dbh->quote($qs). |