version 1.127, 2003/12/19 08:05:01
|
version 1.130, 2004/03/11 07:14:14
|
Line 8 use POSIX qw(locale_h);
|
Line 8 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"; |
|
$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"; |
Line 33 if ($^O =~ /win/i) {
|
Line 40 if ($^O =~ /win/i) {
|
{ |
{ |
$realHTMLDIR="/home/piataev/public_html/dimrub/db/files/"; |
$realHTMLDIR="/home/piataev/public_html/dimrub/db/files/"; |
} |
} |
|
my $url=url||''; |
|
|
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 ($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 746 sub makewhere {
|
Line 764 sub makewhere {
|
$type .= ($_=$TypeName{$_}) foreach @type; |
$type .= ($_=$TypeName{$_}) foreach @type; |
my $where=' 0 '; |
my $where=' 0 '; |
foreach (@type) { |
foreach (@type) { |
$where.= " OR (Type ='$_') OR (Type ='$_Д') "; |
$where.= " OR (Type ='$_') OR (Type ='$_Д') OR (Type ='Д$_') "; |
} |
} |
$where.= "OR (Type='ЧБ')" if ($type=~/Ч|Б/); |
$where.= "OR (Type='ЧБ')" if ($type=~/Ч|Б/); |
return $where; |
return $where; |
Line 974 sub PrintRandom {
|
Line 992 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 1479 sub Get12Random {
|
Line 1499 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 1511 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 1928 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 1941 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 1973 print br.br.$d;
|
Line 1997 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 2040 th {font-size: x-small; font-family : sa
|
Line 2065 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 2225 my ($sth) = $dbh->prepare("SELECT t1.Id,
|
Line 2250 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). |