--- db/prgsrc/db.cgi 2001/12/04 01:17:12 1.41 +++ db/prgsrc/db.cgi 2001/12/11 12:30:23 1.50 @@ -2,15 +2,16 @@ 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', 'á×ÔÏÒ', @@ -73,7 +74,7 @@ sub GetTournament { foreach $name (@{$sth->{NAME}}) { $Tournament{$name} = $arr[$i++]; } - + $sth->finish; return %Tournament; } @@ -94,6 +95,7 @@ sub GetQuestion { $Question{$name} = $arr[$i++]; } + $sth->finish; return %Question; } @@ -111,6 +113,7 @@ sub GetTourQuestions { push @Questions, $arr[0]; } + $sth->finish; return @Questions; } @@ -127,7 +130,7 @@ sub GetTours { while (@arr = $sth->fetchrow) { push @Tours, $arr[0]; } - + $sth->finish; return @Tours; } @@ -141,6 +144,7 @@ print "timeb=".time.br if $debug; $sth->execute; my @a=$sth->fetchrow; print "timee0=".time.br if $debug; + $sth->finish; $a[0]||0; } @@ -151,15 +155,18 @@ sub printform my $submit=submit(-value=>'ðÏÉÓË'); my $inputstring=textfield(-name=>'sstr', -default=>param('sstr')||'', - -size=>50); - my $fields=checkbox_group('searchin',['Question','Answer','Comments','Authors','Sources'], [grep $searchin{$_}, keys %searchin], + -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', + -default=>(param('metod')||'rus'), -labels=>\%rusfieldname); my $all=radio_group(-name=>'all',-values=>['yes','no'], - -default=>param('all')||'no', + -default=>(param('all')||'no'), -labels=>{'yes'=>'÷ÓÅ','no'=>'ìÀÂÏÅ'}); ################################################# @@ -193,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); @@ -210,7 +217,7 @@ sub proxy $good{$_}=1 if $c{$_}<200; } - $good{$words[$_]}=0 foreach 11..$#words; + $good{$words[$_]}=0 foreach 16..$#words; # foreach (@list) # { @@ -263,6 +270,7 @@ print "$query",br if $printqueries; { push (@{$nf[$i]},$arr[0]) } + $sth->finish; } @@ -309,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); @@ -318,7 +327,7 @@ print "$query\n",br if $printqueries; { $frequence[$i]+=$arr[0]; } - + $sth->finish; if (@blob < 4) @@ -439,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); @@ -525,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; } @@ -535,7 +544,7 @@ print "@Questions" if $printqueries; Ðð Òò Óó Ôô Õõ Ææ Èè Ãã Þþ Ûû Ýý Øø Ùù Üü Àà Ññ/; sub NoCase { - my ($sstr) = shift; + my ($sstr) = shift; my ($res); if (($res) = grep(/$sstr/, @letters)) { @@ -956,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); @@ -995,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; } @@ -1030,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; } @@ -1121,6 +1131,7 @@ sub PrintDates { " " . a({href=>url . "?tour=$Tournament{'Id'}&answer=0"}, $Tournament{'Title'}, $Tournament{'PlayedAt'})); } + $sth->finish; $output .= dl($list); return $output; } @@ -1140,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); @@ -1213,6 +1225,7 @@ a({href=>url."?authors=surname"},"ÆÁÍÉÌÉ } } $output.=""; + $sth->finish; return $output; } @@ -1309,6 +1322,7 @@ print $query if $printqueries; my $sth=$dbh->prepare($query); $sth->execute; my $sstr= join ' ',$sth->fetchrow; + $sth->finish; $searchin{'Question'}=1; $searchin{'Answer'}=1; $sstr=~tr/£³/Åå/; @@ -1351,6 +1365,7 @@ $sstr=~s/[^ÊÃÕËÅÎÇÛÝÚÈßÆÙ×ÁÐÒÏÌÄÖÜÑÞÓÍÉÔ WHERE FileName = '$tour.txt'"); $sth->execute; $tour = ($sth->fetchrow)[0]; + $sth->finish; } print &PrintTournament($dbh, $tour, param('answer')); }