--- db/prgsrc/db.cgi 2001/12/03 13:57:20 1.40 +++ db/prgsrc/db.cgi 2001/12/11 12:30:23 1.50 @@ -1,17 +1,21 @@ -#!/perl/bin/perl -w +#!/usr/bin/perl -w use DBI; use CGI ':all'; -use Text::Query; +#use Text::Query; use strict; use Time::Local; use POSIX qw(locale_h); use locale; -#open STDERR, ">errors1"; +open STDERR, ">errors1"; my $printqueries=0; my %forbidden=(); my $debug=0; #added by R7 +if (param('debug')) {$debug=1; $printqueries=1} my %fieldname= (0,'Question', 1, 'Answer', 2, 'Comments', 3, 'Authors', 4, 'Sources'); +my %rusfieldname=('Question','÷ÏÐÒÏÓ', 'Answer', 'ïÔ×ÅÔ', + 'Comments', 'ëÏÍÍÅÎÔÁÒÉÉ', 'Authors', 'á×ÔÏÒ', + 'Sources', 'éÓÔÏÞÎÉË','old','óÔÁÒÙÊ','rus','îÏ×ÙÊ'); my %searchin; my $rl=qr/[ÊÃÕËÅÎÇÛÝÚÈßÆÙ×ÁÐÒÏÌÄÖÜÑÞÓÍÉÔØÂÀ£]/; my $RL=qr/[êãõëåîçûýúèÿüöäìïòðá÷ùæñþóíéôøâà³]/; @@ -21,14 +25,15 @@ my $Ll=qr/(?:[A-Z])|(?:${RL})/; -my $thislocale; +my $thislocale; -$searchin{'question'}=param('Question'); -$searchin{'answer'}=param('Answer'); -$searchin{'comments'}=param('Comments'); -$searchin{'authors'}=param('Authors'); -$searchin{'sources'}=param('Sources'); +$searchin{$_}=1 foreach param('searchin'); +#$searchin{'Question'}=param('Question'); +#$searchin{'Answer'}=param('Answer'); +#$searchin{'Comments'}=param('Comments'); +#$searchin{'Authors'}=param('Authors'); +#$searchin{'Sources'}=param('Sources'); my $all=param('all'); $all=0 if lc $all eq 'no'; my ($PWD) = `pwd`; @@ -69,7 +74,7 @@ sub GetTournament { foreach $name (@{$sth->{NAME}}) { $Tournament{$name} = $arr[$i++]; } - + $sth->finish; return %Tournament; } @@ -90,6 +95,7 @@ sub GetQuestion { $Question{$name} = $arr[$i++]; } + $sth->finish; return %Question; } @@ -107,6 +113,7 @@ sub GetTourQuestions { push @Questions, $arr[0]; } + $sth->finish; return @Questions; } @@ -123,7 +130,7 @@ sub GetTours { while (@arr = $sth->fetchrow) { push @Tours, $arr[0]; } - + $sth->finish; return @Tours; } @@ -137,10 +144,52 @@ print "timeb=".time.br if $debug; $sth->execute; my @a=$sth->fetchrow; print "timee0=".time.br if $debug; + $sth->finish; $a[0]||0; } +sub printform +{ + + my $submit=submit(-value=>'ðÏÉÓË'); + my $inputstring=textfield(-name=>'sstr', + -default=>param('sstr')||'', + -size=>30, + -maxlength=>30); + my @df=keys %searchin; + @df=('Question', 'Answer') unless @df; + my $fields=checkbox_group('searchin',['Question','Answer','Comments','Authors','Sources'], [@df], + 'false',\%rusfieldname); + + my $metod=radio_group(-name=>'metod',-values=>['old','rus'], + -default=>(param('metod')||'rus'), + -labels=>\%rusfieldname); + my $all=radio_group(-name=>'all',-values=>['yes','no'], + -default=>(param('all')||'no'), + -labels=>{'yes'=>'÷ÓÅ','no'=>'ìÀÂÏÅ'}); + +################################################# +return start_form(-method=>'get', + -action=>url, + -enctype=> + "application/x-www-form-urlencoded" +).br. +table(Tr +( + td({-valign=>'TOP'},$inputstring.$submit.p."íÅÔÏÄ: $metod".p."óÌÏ×Á: $all"), + td({-valign=>'TOP'},(' 'x 8).'ðÏÌÑ:'), + td({-valign=>'TOP'},$fields) +) +) + +#$fields. +#$inputstring.$submit.br.$metod.$all +.endform +.hr + +} + sub proxy { #print "time0=".time.br if $debug; @@ -151,7 +200,7 @@ sub proxy $text=~s/p(${RLrl})/Ò$1/gom; $text=~s/(${RLrl})p/$1Ò/gom; $text=~s/\s+/ /gmo; - $text=~s/[^ÊÃÕËÅÎÇÛÝÚÈßÆÙ×ÁÐÒÏÌÄÖÜÑÞÓÍÉÔØÂÀêãõëåîçûýúèÿæù÷áðòïìäöüñþóíéôøâàQWERTYUIOPASDFGHJKLZXCVBNM]/ /g; + $text=~s/[^ÊÃÕËÅÎÇÛÝÚÈßÆÙ×ÁÐÒÏÌÄÖÜÑÞÓÍÉÔØÂÀêãõëåîçûýúèÿæù÷áðòïìäöüñþóíéôøâàQWERTYUIOPASDFGHJKLZXCVBNM0-9]/ /g; $text=uc $text; my @list= $text=~m/(?:(?:${RLrl})+)|(?:[A-Za-z0-9]+)/gom; my (%c, %good,$sstr); @@ -168,6 +217,8 @@ sub proxy $good{$_}=1 if $c{$_}<200; } + $good{$words[$_]}=0 foreach 16..$#words; + # foreach (@list) # { # if ($good{$_}) @@ -219,6 +270,7 @@ print "$query",br if $printqueries; { push (@{$nf[$i]},$arr[0]) } + $sth->finish; } @@ -265,6 +317,7 @@ print STDERR "!$query\n",br if $printque { @blob=(@blob,unpack 'C*',$arr[0]); } + $sth->finish; $query="select number from nf where ".(join ' OR ', @arr1); print "$query\n",br if $printqueries; $sth=$dbh -> prepare($query); @@ -274,7 +327,7 @@ print "$query\n",br if $printqueries; { $frequence[$i]+=$arr[0]; } - + $sth->finish; if (@blob < 4) @@ -296,7 +349,7 @@ print "$query\n",br if $printqueries; $ii+=4; $number=$lo+$hi*256; $field=$fieldname{$field}; - if ($searchin{lc $field}) + if ($searchin{$field}) { push @{$tasksof{$i}{$number}}, $wordnumber; # ÄÏÐÏÌÎÉÌÉ × ÈÜÛÅ, ×ÉÓÑÝÅÍ ÎÁ @@ -395,17 +448,17 @@ sub Search { my $sstr=$$s; my (@arr, @Questions, @fields); my (@sar, $i, $sth,$where,$query); - my $ip=$ENV{'REMOTE_ADDR'}; +# my $ip=$ENV{'REMOTE_ADDR'}; - $ip=$dbh->quote($ip); - $query= - "INSERT into queries (query,metod,searchin,ip) - values (". $dbh->quote($sstr).', '. - $dbh->quote($metod) . ', ' . - $dbh->quote(join ' ', grep $searchin{$_}, keys %searchin) . - ", $ip)"; -print $query if $printqueries; - $dbh -> do ($query); +# $ip=$dbh->quote($ip); +# $query= +# "INSERT into queries (query,metod,searchin,ip) +# values (". $dbh->quote($sstr).', '. +# $dbh->quote($metod) . ', ' . +# $dbh->quote(join ' ', grep $searchin{$_}, keys %searchin) . +# ", $ip)"; +#print $query if $printqueries; +# $dbh -> do ($query); if ($metod eq 'rus') { my @tasks=russearch($dbh,$sstr,$all,$allnf); @@ -450,10 +503,11 @@ print $query if $printqueries; ###### { - foreach (qw/Question Answer Sources Authors Comments/) { - if (param($_)) { +# foreach (qw/Question Answer Sources Authors Comments/) { + foreach (param('searchin')) { +# if (param($_)) { push @fields, "IFNULL($_, '')"; - } +# } } @sar = split " ", $sstr; for $i (0 .. $#sar) { @@ -480,7 +534,7 @@ print $query if $printqueries; while (@arr = $sth->fetchrow) { push @Questions, $arr[0] unless $forbidden{$arr[0]}; } - + $sth->finish; print "@Questions" if $printqueries; return @Questions; } @@ -490,7 +544,7 @@ print "@Questions" if $printqueries; Ðð Òò Óó Ôô Õõ Ææ Èè Ãã Þþ Ûû Ýý Øø Ùù Üü Àà Ññ/; sub NoCase { - my ($sstr) = shift; + my ($sstr) = shift; my ($res); if (($res) = grep(/$sstr/, @letters)) { @@ -511,20 +565,70 @@ sub PrintList { $last=scalar @$Questions if scalar @$Questions <$last; my($f,$l); my $nav=''; + my $qs=query_string; + $qs=~s/\;/\&/g; + $qs=~s/\&first\=[^\&]+//g; + + + if ($first>$kvo*3+1) + { + $nav.= + (" "x4). + a({href=>url."?".$qs."\&first=1"},"<<").(" "x4). + a({href=>(url."?".$qs."\&first=".($first-$kvo))},"<").(" "x4) + } + + else {$nav.=' 'x15;} + + my ($fprint,$lprint); + my $llprint=$#$Questions- ($#$Questions+1)%$kvo+2; + if ($#$Questions+1<=$kvo*7) + { $fprint=1; + $lprint=$llprint; + } + elsif ($first>$kvo*3 && $#$Questions+1-$first>$kvo*3) + { + $fprint=$first-$kvo*3; + $lprint=$first+$kvo*3; + } + elsif ($first<=$kvo*3) + { + $fprint=1; $lprint=6*$kvo+1; + } + else + { + $lprint=$llprint; + $fprint=$lprint-$kvo*6 + } + +# my $fprint=($first>$kvo*3) ? $first-$kvo*3 : 1; +# my $lprint=$#$Questions+1-$fprint>$kvo*7 ? $kvo*7 :$#$Questions+1; +# if ($lprint-$fprint<$kvo*6 && $fprint>1) +# { +# $fprint=$lprint-$kvo*6; +# $fprint=1 if ($fprint<=0) +# } + - for($f=1; $f<=@$Questions; $f+=$kvo) + + for($f=$fprint; $f<=$lprint; $f+=$kvo) { +# next if $first-$f>$kvo*3; $l=$f+$kvo-1; $l=$#$Questions+1 if $l>$#$Questions+1; if ($f==$first) {$nav.="[$f-$l] ";} else { - my $qs=query_string; - $qs=~s/\;/\&/g; - $qs=~s/\&first\=[^\&]+//g; - $qs.="\&first=$f"; - - $nav.= "[".a({href=>(url."?".$qs)},"$f-$l")."] ";} + $nav.= "[".a({href=>(url."?".$qs."\&first=$f")},"$f-$l")."] ";} } + if ($lprint+$kvo<$#$Questions) + { + $nav.= + (" "x4). + a({href=>(url."?".$qs."\&first=".($first+$kvo))},">").(" "x4). + a({href=>url."?".$qs."\&first=$llprint"},">>").(" "x4) + } + + print "$nav".br."\n"; for (my $i = $first; $i <= $last; $i++) { my $output = &PrintQuestion($dbh, $$Questions[$i-1], 1, $i, 1); @@ -536,13 +640,16 @@ sub PrintList { } print $output; } + + print "$nav".br."\n"; } sub PrintSearch { my ($dbh, $sstr, $metod) = @_; - + print h2("ðÏÉÓË × ÂÁÚÅ ×ÏÐÒÏÓÏ×"); + print printform; my @allnf; my (@Questions) = &Search($dbh, \$sstr,$metod,$all,\@allnf); my ($output, $i, $suffix, $hits) = ('', 0, '', $#Questions + 1); @@ -858,31 +965,31 @@ sub PrintQuestion { if ($Question{'Authors'}) { my $q=$Question{'Authors'}; - my $sth=$dbh->prepare("select Authors.Id,Name, Surname, Nicks from Authors, A2Q - where Authors.Id=Author And Question=$Id"); - $sth->execute; - my ($AuthorId,$Name, $Surname,$other,$Nicks); - - while ((($AuthorId,$Name, $Surname,$Nicks)=$sth->fetchrow),$AuthorId) - { - my ($firstletter)=$Name=~m/^./g; - $Name=~s/\./\\\./g; - my $sha="(?:$Name\\s+$Surname)|(?:$Surname\\s+$Name)|(?:$firstletter\\.\\s*$Surname)|(?:$Surname\\s+$firstletter\\.)|(?:$Surname)|(?:$Name)"; - if ($Nicks) - { - $Nicks=~s/^\|//; - foreach (split /\|/, $Nicks) - { - s/\s+/ /g; - s/\s+$//; - s/ /\\s+/g; - s/\./\\\./g; - if (s/>$//) {$sha="$sha|(?:$_)"} - else {$sha="(?:$_)|$sha"} - } - } - $q=~s/($sha)/a({href=>url."?qofauthor=$AuthorId"},$1)/ei; - } +# my $sth=$dbh->prepare("select Authors.Id,Name, Surname, Nicks from Authors, A2Q +# where Authors.Id=Author And Question=$Id"); +# $sth->execute; +# my ($AuthorId,$Name, $Surname,$other,$Nicks); + +# while ((($AuthorId,$Name, $Surname,$Nicks)=$sth->fetchrow),$AuthorId) +# { +# my ($firstletter)=$Name=~m/^./g; +# $Name=~s/\./\\\./g; +# my $sha="(?:$Name\\s+$Surname)|(?:$Surname\\s+$Name)|(?:$firstletter\\.\\s*$Surname)|(?:$Surname\\s+$firstletter\\.)|(?:$Surname)|(?:$Name)"; +# if ($Nicks) +# { +# $Nicks=~s/^\|//; +# foreach (split /\|/, $Nicks) +# { +# s/\s+/ /g; +# s/\s+$//; +# s/ /\\s+/g; +# s/\./\\\./g; +# if (s/>$//) {$sha="$sha|(?:$_)"} +# else {$sha="(?:$_)|$sha"} +# } +# } +# $q=~s/($sha)/a({href=>url."?qofauthor=$AuthorId"},$1)/ei; +# } $output .= &PrintField("á×ÔÏÒ(Ù)", $q, $text); @@ -897,8 +1004,8 @@ sub PrintQuestion { $output .= &PrintField("ëÏÍÍÅÎÔÁÒÉÉ", $Question{'Comments'}, $text); } } - $output.=br.a({href=> url."?metod=proxy&qid=$Id"}, 'âÌÉÚËÉÅ ×ÏÐÒÏÓÙ').p - if $answer; +# $output.=br.a({href=> url."?metod=proxy&qid=$Id"}, 'âÌÉÚËÉÅ ×ÏÐÒÏÓÙ').p +# if $answer; return $output; } @@ -932,6 +1039,7 @@ sub Get12Random { $sth->execute; $t = ($sth->fetchrow)[0]; } until !$chosen{$q} && $t && $type =~ /[$t]/; + $sth->finish; $chosen{$q} = 'y'; push @questions, $q; } @@ -1023,12 +1131,14 @@ sub PrintDates { " " . a({href=>url . "?tour=$Tournament{'Id'}&answer=0"}, $Tournament{'Title'}, $Tournament{'PlayedAt'})); } + $sth->finish; $output .= dl($list); return $output; } sub PrintQOfAuthor { + my ($dbh, $id) = @_; $id=$dbh->quote($id); my $sth = $dbh->prepare("SELECT Name, Surname FROM Authors WHERE Id=$id"); @@ -1041,6 +1151,7 @@ sub PrintQOfAuthor my @Questions; while (($q)=$sth->fetchrow,$q) {push @Questions,$q unless $forbidden{$q}} + $sth->finish; my ($output, $i, $suffix, $hits) = ('', 0, '', $#Questions + 1); @@ -1051,7 +1162,8 @@ sub PrintQOfAuthor } else { $suffix = 'Ñ'; } - + print h2("ðÏÉÓË × ÂÁÚÅ ×ÏÐÒÏÓÏ×"); + print printform; print p({align=>"center"}, "á×ÔÏÒ ".strong("$name $surname. ") . " : $hits ÐÏÐÁÄÁÎÉ$suffix."); @@ -1113,6 +1225,7 @@ a({href=>url."?authors=surname"},"ÆÁÍÉÌÉ } } $output.=""; + $sth->finish; return $output; } @@ -1141,6 +1254,7 @@ MAIN: print &Include_virtual("../dimrub/db/reklama.html"); } + if ($^O =~ /win/i) { $thislocale = "Russian_Russia.20866"; } else { @@ -1208,8 +1322,10 @@ print $query if $printqueries; my $sth=$dbh->prepare($query); $sth->execute; my $sstr= join ' ',$sth->fetchrow; - $searchin{'question'}=1; - $searchin{'answer'}=1; + $sth->finish; + $searchin{'Question'}=1; + $searchin{'Answer'}=1; + $sstr=~tr/£³/Åå/; $sstr=~s/[^ÊÃÕËÅÎÇÛÝÚÈßÆÙ×ÁÐÒÏÌÄÖÜÑÞÓÍÉÔØÂÀêãõëåîçûýúèÿæù÷áðòïìäöüñþóíéôøâàa-zA-Z0-9]/ /gi; # print &PrintQuestion($dbh,$qid, 1, '!'); &PrintSearch($dbh, $sstr, 'proxy'); @@ -1249,6 +1365,7 @@ $sstr=~s/[^ÊÃÕËÅÎÇÛÝÚÈßÆÙ×ÁÐÒÏÌÄÖÜÑÞÓÍÉÔ WHERE FileName = '$tour.txt'"); $sth->execute; $tour = ($sth->fetchrow)[0]; + $sth->finish; } print &PrintTournament($dbh, $tour, param('answer')); }