Diff for /db/prgsrc/db.cgi between versions 1.40 and 1.53

version 1.40, 2001/12/03 13:57:20 version 1.53, 2001/12/21 11:54:37
Line 1 Line 1
 #!/perl/bin/perl -w  #!/usr/bin/perl -w
   
 use DBI;  use DBI;
 use CGI ':all';  use CGI ':all';
 use Text::Query;  #use Text::Query;
 use strict;  use strict;
 use Time::Local;  use Time::Local;
 use POSIX qw(locale_h);  use POSIX qw(locale_h);
 use locale;  use locale;
 #open STDERR, ">errors1";  open STDERR, ">errors1";
 my $printqueries=0;  my $printqueries=0;
 my %forbidden=();  my %forbidden=();
 my $debug=0; #added by R7  my $debug=0; #added by R7
   if (param('debug')) {$debug=1; $printqueries=1}
   *STDERR=*STDOUT if $debug;
 my %fieldname= (0,'Question', 1, 'Answer', 2, 'Comments', 3, 'Authors', 4, 'Sources');  my %fieldname= (0,'Question', 1, 'Answer', 2, 'Comments', 3, 'Authors', 4, 'Sources');
   my %rusfieldname=('Question','÷ÏÐÒÏÓ', 'Answer', 'ïÔ×ÅÔ', 
                     'Comments', 'ëÏÍÍÅÎÔÁÒÉÉ', 'Authors', 'á×ÔÏÒ', 
                     'Sources', 'éÓÔÏÞÎÉË','old','óÔÁÒÙÊ','rus','îÏ×ÙÊ');
 my %searchin;  my %searchin;
 my $rl=qr/[ÊÃÕËÅÎÇÛÝÚÈßÆÙ×ÁÐÒÏÌÄÖÜÑÞÓÍÉÔØÂÀ£]/;  my $rl=qr/[ÊÃÕËÅÎÇÛÝÚÈßÆÙ×ÁÐÒÏÌÄÖÜÑÞÓÍÉÔØÂÀ£]/;
 my $RL=qr/[êãõëåîçûýúèÿüöäìïòðá÷ùæñþóíéôøâà³]/;  my $RL=qr/[êãõëåîçûýúèÿüöäìïòðá÷ùæñþóíéôøâà³]/;
Line 21  my $Ll=qr/(?:[A-Z])|(?:${RL})/; Line 26  my $Ll=qr/(?:[A-Z])|(?:${RL})/;
   
   
   
   
 my $thislocale;  my $thislocale;
   
   $searchin{$_}=1 foreach param('searchin');
   my %TypeName=('children'=>'ä', 'game'=>'é',
                 'chgk'=>'þ', 'brain'=>'â', 'beskrylka'=>'ì','ehruditka'=>'ü');
   
   
   
 $searchin{'question'}=param('Question');  
 $searchin{'answer'}=param('Answer');  
 $searchin{'comments'}=param('Comments');  
 $searchin{'authors'}=param('Authors');  
 $searchin{'sources'}=param('Sources');  
 my $all=param('all');  my $all=param('all');
 $all=0 if lc $all eq 'no';  $all=0 if lc $all eq 'no';
 my ($PWD) = `pwd`;  my ($PWD) = `pwd`;
Line 69  sub GetTournament { Line 75  sub GetTournament {
         foreach $name (@{$sth->{NAME}}) {          foreach $name (@{$sth->{NAME}}) {
                 $Tournament{$name} = $arr[$i++];                  $Tournament{$name} = $arr[$i++];
         }          }
           $sth->finish;
         return %Tournament;          return %Tournament;
 }  }
   
Line 90  sub GetQuestion { Line 96  sub GetQuestion {
                 $Question{$name} = $arr[$i++];                  $Question{$name} = $arr[$i++];
         }          }
   
           $sth->finish;
         return %Question;          return %Question;
 }  }
   
Line 99  sub GetTourQuestions { Line 106  sub GetTourQuestions {
         my (@arr, @Questions);          my (@arr, @Questions);
   
         my ($sth) = $dbh->prepare("SELECT QuestionId FROM Questions          my ($sth) = $dbh->prepare("SELECT QuestionId FROM Questions
                 WHERE ParentId=$ParentId ORDER BY QuestionId");                  WHERE ParentId=$ParentId");
   
         $sth->execute;          $sth->execute;
   
Line 107  sub GetTourQuestions { Line 114  sub GetTourQuestions {
                 push @Questions, $arr[0];                  push @Questions, $arr[0];
         }          }
   
           $sth->finish;
         return @Questions;          return @Questions;
 }  }
   
Line 123  sub GetTours { Line 131  sub GetTours {
         while (@arr = $sth->fetchrow) {          while (@arr = $sth->fetchrow) {
                 push @Tours, $arr[0];                  push @Tours, $arr[0];
         }          }
           $sth->finish;
         return @Tours;          return @Tours;
 }  }
   
Line 137  print "timeb=".time.br if $debug; Line 145  print "timeb=".time.br if $debug;
   $sth->execute;    $sth->execute;
   my @a=$sth->fetchrow;    my @a=$sth->fetchrow;
 print "timee0=".time.br if $debug;  print "timee0=".time.br if $debug;
     $sth->finish;
   $a[0]||0;    $a[0]||0;
 }  }
   
   
   sub printform
   {
   
     my $submit=submit(-value=>'ðÏÉÓË');
     my $inputstring=textfield(-name=>'sstr',
                            -default=>param('sstr')||'',
                            -size=>30,
                            -maxlength=>30);
     my $qnumber="÷Ù×ÏÄÉÔØ ÐÏ".br. textfield(-name=>'kvo',
                            -default=>param('kvo')||'150',
                            -size=>3,
                            -maxlength=>5). br."×ÏÐÒÏÓÏ×";
   
     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), td(" "x5),
     td({-valign=>'TOP'},$qnumber)
   ) 
   )
    
   #$fields.
   #$inputstring.$submit.br.$metod.$all
   .endform
   .hr
   
   }
   
 sub proxy  sub proxy
 {  {
 #print "time0=".time.br if $debug;  #print "time0=".time.br if $debug;
Line 151  sub proxy Line 207  sub proxy
       $text=~s/p(${RLrl})/Ò$1/gom;        $text=~s/p(${RLrl})/Ò$1/gom;
       $text=~s/(${RLrl})p/$1Ò/gom;        $text=~s/(${RLrl})p/$1Ò/gom;
       $text=~s/\s+/ /gmo;        $text=~s/\s+/ /gmo;
       $text=~s/[^ÊÃÕËÅÎÇÛÝÚÈßÆÙ×ÁÐÒÏÌÄÖÜÑÞÓÍÉÔØÂÀêãõëåîçûýúèÿæù÷áðòïìäöüñþóíéôøâàQWERTYUIOPASDFGHJKLZXCVBNM]/ /g;        $text=~s/[^ÊÃÕËÅÎÇÛÝÚÈßÆÙ×ÁÐÒÏÌÄÖÜÑÞÓÍÉÔØÂÀêãõëåîçûýúèÿæù÷áðòïìäöüñþóíéôøâàQWERTYUIOPASDFGHJKLZXCVBNM0-9]/ /g;
       $text=uc $text;        $text=uc $text;
       my @list= $text=~m/(?:(?:${RLrl})+)|(?:[A-Za-z0-9]+)/gom;        my @list= $text=~m/(?:(?:${RLrl})+)|(?:[A-Za-z0-9]+)/gom;
       my (%c, %good,$sstr);        my (%c, %good,$sstr);
Line 168  sub proxy Line 224  sub proxy
          $good{$_}=1 if $c{$_}<200;           $good{$_}=1 if $c{$_}<200;
       }        }
   
         $good{$words[$_]}=0 foreach 16..$#words;
   
 #      foreach (@list)  #      foreach (@list)
 #      {  #      {
 #        if ($good{$_})  #        if ($good{$_})
Line 219  print "$query",br if $printqueries; Line 277  print "$query",br if $printqueries;
                 {                  {
                    push (@{$nf[$i]},$arr[0])                     push (@{$nf[$i]},$arr[0])
                 }                  }
                   $sth->finish;
             }              }
   
   
Line 265  print STDERR "!$query\n",br if $printque Line 324  print STDERR "!$query\n",br if $printque
               {                {
                 @blob=(@blob,unpack 'C*',$arr[0]);                  @blob=(@blob,unpack 'C*',$arr[0]);
               }                }
                 $sth->finish;
               $query="select number from nf where ".(join ' OR ', @arr1);                $query="select number from nf where ".(join ' OR ', @arr1);
 print "$query\n",br if $printqueries;  print "$query\n",br if $printqueries;
               $sth=$dbh -> prepare($query);                $sth=$dbh -> prepare($query);
Line 274  print "$query\n",br if $printqueries; Line 334  print "$query\n",br if $printqueries;
               {                {
                 $frequence[$i]+=$arr[0];                  $frequence[$i]+=$arr[0];
               }                }
                 $sth->finish;
   
   
               if (@blob < 4)                if (@blob < 4)
Line 296  print "$query\n",br if $printqueries; Line 356  print "$query\n",br if $printqueries;
                     $ii+=4;                      $ii+=4;
                     $number=$lo+$hi*256;                      $number=$lo+$hi*256;
                     $field=$fieldname{$field};                      $field=$fieldname{$field};
                     if ($searchin{lc $field})                      if ($searchin{$field})
                     {                      {
                       push @{$tasksof{$i}{$number}}, $wordnumber;                        push @{$tasksof{$i}{$number}}, $wordnumber;
                                       # ÄÏÐÏÌÎÉÌÉ × ÈÜÛÅ, ×ÉÓÑÝÅÍ ÎÁ                                        # ÄÏÐÏÌÎÉÌÉ × ÈÜÛÅ, ×ÉÓÑÝÅÍ ÎÁ
Line 395  sub Search { Line 455  sub Search {
         my $sstr=$$s;          my $sstr=$$s;
         my (@arr, @Questions, @fields);          my (@arr, @Questions, @fields);
         my (@sar, $i, $sth,$where,$query);          my (@sar, $i, $sth,$where,$query);
         my $ip=$ENV{'REMOTE_ADDR'};  #       my $ip=$ENV{'REMOTE_ADDR'};
   
         $ip=$dbh->quote($ip);  #        $ip=$dbh->quote($ip);
         $query=  #       $query=
           "INSERT into queries (query,metod,searchin,ip)  #          "INSERT into queries (query,metod,searchin,ip)
                     values (". $dbh->quote($sstr).', '.  #                    values (". $dbh->quote($sstr).', '.
                     $dbh->quote($metod) . ', ' .  #                    $dbh->quote($metod) . ', ' .
                     $dbh->quote(join ' ', grep $searchin{$_}, keys %searchin)  .   #                    $dbh->quote(join ' ', grep $searchin{$_}, keys %searchin)  . 
               ", $ip)";  #              ", $ip)";
 print $query if $printqueries;  #print $query if $printqueries;
         $dbh -> do ($query);  #        $dbh -> do ($query);
         if ($metod eq 'rus')          if ($metod eq 'rus')
         {          {
              my @tasks=russearch($dbh,$sstr,$all,$allnf);               my @tasks=russearch($dbh,$sstr,$all,$allnf);
Line 450  print $query if $printqueries; Line 510  print $query if $printqueries;
 ######  ######
          {           {
   
           foreach (qw/Question Answer Sources Authors Comments/) {  #         foreach (qw/Question Answer Sources Authors Comments/) {
                 if (param($_)) {            foreach (param('searchin')) {
   #               if (param($_)) {
                         push @fields, "IFNULL($_, '')";                          push @fields, "IFNULL($_, '')";
                 }  #               }
           }            }
           @sar = split " ", $sstr;            @sar = split " ", $sstr;
           for $i (0 .. $#sar) {            for $i (0 .. $#sar) {
Line 480  print $query if $printqueries; Line 541  print $query if $printqueries;
         while (@arr = $sth->fetchrow) {          while (@arr = $sth->fetchrow) {
                 push @Questions, $arr[0] unless $forbidden{$arr[0]};                  push @Questions, $arr[0] unless $forbidden{$arr[0]};
         }          }
           $sth->finish;
 print "@Questions" if $printqueries;  print "@Questions" if $printqueries;
         return @Questions;          return @Questions;
 }  }
Line 490  print "@Questions" if $printqueries; Line 551  print "@Questions" if $printqueries;
  Ðð Òò Óó Ôô Õõ Ææ Èè Ãã Þþ Ûû Ýý Øø Ùù Üü Àà Ññ/;   Ðð Òò Óó Ôô Õõ Ææ Èè Ãã Þþ Ûû Ýý Øø Ùù Üü Àà Ññ/;
   
 sub NoCase {  sub NoCase {
         my ($sstr) = shift;          my ($sstr) = shift;                     
         my ($res);          my ($res);
   
         if (($res) = grep(/$sstr/, @letters)) {          if (($res) = grep(/$sstr/, @letters)) {
Line 504  sub PrintList { Line 565  sub PrintList {
    my ($dbh,$Questions,$shablon)=@_;     my ($dbh,$Questions,$shablon)=@_;
   
         my $first=param('first') ||1;          my $first=param('first') ||1;
         my $kvo=param('kvo') ||30;          my $kvo=param('kvo') ||150;
   
         $first=$first-($first-1)%$kvo;          $first=$first-($first-1)%$kvo;
         my $last=$first+$kvo-1;          my $last=$first+$kvo-1;
         $last=scalar @$Questions if scalar @$Questions <$last;          $last=scalar @$Questions if scalar @$Questions <$last;
         my($f,$l);          my($f,$l);
         my $nav='';          my $nav='';
           my $qs=query_string;
           $qs=~s/\;/\&/g;
           $qs=~s/\&first\=[^\&]+//g;
           my $sstr=param('sstr');
           $qs=~s/sstr=[^\&]+/sstr=$sstr/;
           if ($first>$kvo*3+1)
           {
              $nav.=
               ("&nbsp;"x4).
               a({href=>url."?".$qs."\&first=1"},"<<").("&nbsp;"x4).
               a({href=>(url."?".$qs."\&first=".($first-$kvo))},"<").("&nbsp;"x4)
           }
   
           else {$nav.='&nbsp;'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=$f+$kvo-1;
           $l=$#$Questions+1 if $l>$#$Questions+1;            $l=$#$Questions+1 if $l>$#$Questions+1;
           if ($f==$first) {$nav.="[$f-$l] ";}            if ($f==$first) {$nav.="[$f-$l] ";}
           else {            else {
                   my $qs=query_string;                    $nav.= "[".a({href=>(url."?".$qs."\&first=$f")},"$f-$l")."] ";}
                   $qs=~s/\;/\&/g;  
                   $qs=~s/\&first\=[^\&]+//g;  
                   $qs.="\&first=$f";  
   
                   $nav.= "[".a({href=>(url."?".$qs)},"$f-$l")."] ";}  
         }          }
           if ($lprint+$kvo<$#$Questions)
           {
              $nav.=
               ("&nbsp;"x4).
               a({href=>(url."?".$qs."\&first=".($first+$kvo))},">").("&nbsp;"x4).
               a({href=>url."?".$qs."\&first=$llprint"},">>").("&nbsp;"x4)
           }
   
   
         print "$nav".br."\n";          print "$nav".br."\n";
         for (my $i = $first; $i <= $last; $i++) {          for (my $i = $first; $i <= $last; $i++) {
                 my $output = &PrintQuestion($dbh, $$Questions[$i-1], 1, $i, 1);                  my $output = &PrintQuestion($dbh, $$Questions[$i-1], 1, $i, 1);
Line 536  sub PrintList { Line 647  sub PrintList {
                 }                  }
                 print $output;                  print $output;
         }          }
   
   
         print "$nav".br."\n";          print "$nav".br."\n";
   
 }  }
   
 sub PrintSearch {  sub PrintSearch {
         my ($dbh, $sstr, $metod) = @_;          my ($dbh, $sstr, $metod) = @_;
           print h2("ðÏÉÓË × ÂÁÚÅ ×ÏÐÒÏÓÏ×");
           print printform;
         my @allnf;          my @allnf;
         my (@Questions) = &Search($dbh, \$sstr,$metod,$all,\@allnf);          my (@Questions) = &Search($dbh, \$sstr,$metod,$all,\@allnf);
         my ($output, $i, $suffix, $hits) = ('', 0, '', $#Questions + 1);          my ($output, $i, $suffix, $hits) = ('', 0, '', $#Questions + 1);
Line 619  sub PrintRandom { Line 733  sub PrintRandom {
         return $output;          return $output;
 }  }
   
   sub PrintEditor {
          my $t=shift; #ÓÓÙÌËÁ ÎÁ èÜÛ Ó ÐÏÌÑÍÉ
          my $ed=$$t{'Editors'};
          my $edname=($ed=~/\,/ ) ? "òÅÄÁËÔÏÒÙ"  : "òÅÄÁËÔÏÒ" ;
          return h4({align=>"center"},"$edname: $ed" );
   }
   
 sub PrintTournament {  sub PrintTournament {
    my ($dbh, $Id, $answer) = @_;     my ($dbh, $Id, $answer) = @_;
         my (%Tournament, @Tours, $i, $list, $qnum, $imgsrc, $alt,          my (%Tournament, @Tours, $i, $list, $qnum, $imgsrc, $alt,
Line 632  sub PrintTournament { Line 753  sub PrintTournament {
         my ($Copyright) = $Tournament{'Copyright'};          my ($Copyright) = $Tournament{'Copyright'};
   
         @Tours = &GetTours($dbh, $Id);          @Tours = &GetTours($dbh, $Id);
           $list='';
         if ($Id) {          if ($Id) {
                 for ($Tournament{'Type'}) {                  for ($Tournament{'Type'}) {
                         /ç/ && do {                          /ç/ && do {
Line 652  sub PrintTournament { Line 773  sub PrintTournament {
   
                                 $output .= h2({align=>"center"},                                  $output .= h2({align=>"center"},
                                         "$title") . p . "\n";                                          "$title") . p . "\n";
                                  $output.=&PrintEditor(\%Tournament);
                                 last;                                  last;
                         };                          };
                         /ô/ && do {                          /ô/ && do {
Line 718  sub PrintTournament { Line 840  sub PrintTournament {
                 $output .= p("ëÏÐÉÒÁÊÔ: " .   $Copyright);                  $output .= p("ëÏÐÉÒÁÊÔ: " .   $Copyright);
         }          }
   
   
   
         if ($Info) {          if ($Info) {
                 $output .= p($Info);                  $output .= p($Info);
         }          }
   
         return $output;          return $output;
 }  }
   
Line 761  sub PrintTour { Line 884  sub PrintTour {
                       $Tournament{'PlayedAt'},                        $Tournament{'PlayedAt'},
                       "<br>", $Tour{"Title"} .                        "<br>", $Tour{"Title"} .
                 " ($qnum ×ÏÐÒÏÓ$suffix)\n") . p;                  " ($qnum ×ÏÐÒÏÓ$suffix)\n") . p;
           $output .=&PrintEditor(\%Tour);
   
         my (@Questions) = &GetTourQuestions($dbh, $Id);          my (@Questions) = &GetTourQuestions($dbh, $Id);
         for ($q = 0; $q <= $#Questions; $q++) {          for ($q = 0; $q <= $#Questions; $q++) {
Line 858  sub PrintQuestion { Line 982  sub PrintQuestion {
                 if ($Question{'Authors'}) {                  if ($Question{'Authors'}) {
                       my $q=$Question{'Authors'};                        my $q=$Question{'Authors'};
   
                       my $sth=$dbh->prepare("select Authors.Id,Name, Surname, Nicks from Authors, A2Q  #                     my $sth=$dbh->prepare("select Authors.Id,Name, Surname, Nicks from Authors, A2Q
                                  where Authors.Id=Author And Question=$Id");  #                                 where Authors.Id=Author And Question=$Id");
                       $sth->execute;  #                      $sth->execute;
                       my ($AuthorId,$Name, $Surname,$other,$Nicks);  #                      my ($AuthorId,$Name, $Surname,$other,$Nicks);
   
                       while ((($AuthorId,$Name, $Surname,$Nicks)=$sth->fetchrow),$AuthorId)  #                      while ((($AuthorId,$Name, $Surname,$Nicks)=$sth->fetchrow),$AuthorId)
                       {  #                      {
                         my ($firstletter)=$Name=~m/^./g;  #                        my ($firstletter)=$Name=~m/^./g;
                          $Name=~s/\./\\\./g;  #                         $Name=~s/\./\\\./g;
                           my $sha="(?:$Name\\s+$Surname)|(?:$Surname\\s+$Name)|(?:$firstletter\\.\\s*$Surname)|(?:$Surname\\s+$firstletter\\.)|(?:$Surname)|(?:$Name)";  #                          my $sha="(?:$Name\\s+$Surname)|(?:$Surname\\s+$Name)|(?:$firstletter\\.\\s*$Surname)|(?:$Surname\\s+$firstletter\\.)|(?:$Surname)|(?:$Name)";
                           if ($Nicks)  #                          if ($Nicks)
                           {  #                          {
                             $Nicks=~s/^\|//;  #                            $Nicks=~s/^\|//;
                             foreach (split /\|/, $Nicks)  #                            foreach (split /\|/, $Nicks)
                             {  #                            {
                               s/\s+/ /g;  #                              s/\s+/ /g;
                               s/\s+$//;  #                              s/\s+$//;
                               s/ /\\s+/g;  #                              s/ /\\s+/g;
                               s/\./\\\./g;  #                              s/\./\\\./g;
                               if (s/>$//) {$sha="$sha|(?:$_)"}  #                              if (s/>$//) {$sha="$sha|(?:$_)"}
                               else        {$sha="(?:$_)|$sha"}  #                              else        {$sha="(?:$_)|$sha"}
                             }  #                            }
                           }  #                          }
                           $q=~s/($sha)/a({href=>url."?qofauthor=$AuthorId"},$1)/ei;  #                          $q=~s/($sha)/a({href=>url."?qofauthor=$AuthorId"},$1)/ei;
                       }  #                      }
   
                         $output .= &PrintField("á×ÔÏÒ(Ù)", $q, $text);                          $output .= &PrintField("á×ÔÏÒ(Ù)", $q, $text);
   
Line 897  sub PrintQuestion { Line 1021  sub PrintQuestion {
                         $output .= &PrintField("ëÏÍÍÅÎÔÁÒÉÉ", $Question{'Comments'}, $text);                          $output .= &PrintField("ëÏÍÍÅÎÔÁÒÉÉ", $Question{'Comments'}, $text);
                 }                  }
         }          }
         $output.=br.a({href=> url."?metod=proxy&qid=$Id"}, 'âÌÉÚËÉÅ ×ÏÐÒÏÓÙ').p  #       $output.=br.a({href=> url."?metod=proxy&qid=$Id"}, 'âÌÉÚËÉÅ ×ÏÐÒÏÓÙ').p
              if $answer;  #             if $answer;
         return $output;          return $output;
 }  }
   
Line 924  sub Get12Random { Line 1048  sub Get12Random {
         my (%chosen);          my (%chosen);
         srand;          srand;
   
    for ($i = 0; $i < $num; $i++) {          my $where=0;
        do {          my $r=int (rand(10000));
            $q = int(rand($qnum));  
            $sth = $dbh->prepare("SELECT Type FROM Questions          foreach (split '', $type)
                                 WHERE QuestionId=$q");          {
            $sth->execute;             $where.= " OR (Type ='$_') OR (Type ='$_ä') ";
            $t = ($sth->fetchrow)[0];          }
        } until !$chosen{$q} && $t && $type =~ /[$t]/;          $where.= "OR (Type='þâ')" if ($type=~/þ|â/);
        $chosen{$q} = 'y';  
        push @questions, $q;     $q="select QuestionId, QuestionId/$r-floor(QuestionId/$r) as val 
          from Questions where $where order by val limit $num";
   
   # ëÏÇÄÁ ÎÁ ËÕÌÉÞËÁÈ ÐÏÑ×ÉÔÓÑ mysql >=3.23 ÎÁÄÏ ÚÁÍÅÎÉÔØ ÎÁ order by rand();
   
      $sth=$dbh->prepare($q);
      $sth->execute;
      while (($i)=$sth->fetchrow)
      {
         push @questions,$i;
    }     }
   
       for ($i=@questions; --$i;){ 
          my $j=rand ($i+1); 
          @questions[$i,$j]=@questions[$j,$i] unless $i==$j;
       }
    return @questions;     return @questions;
 }  }
   
Line 1023  sub PrintDates { Line 1161  sub PrintDates {
       " " . a({href=>url . "?tour=$Tournament{'Id'}&answer=0"},        " " . a({href=>url . "?tour=$Tournament{'Id'}&answer=0"},
       $Tournament{'Title'}, $Tournament{'PlayedAt'}));        $Tournament{'Title'}, $Tournament{'PlayedAt'}));
         }          }
           $sth->finish;
         $output .= dl($list);          $output .= dl($list);
         return $output;          return $output;
 }  }
   
 sub PrintQOfAuthor  sub PrintQOfAuthor
 {  {
   
     my ($dbh, $id) = @_;      my ($dbh, $id) = @_;
    $id=$dbh->quote($id);     $id=$dbh->quote($id);
     my $sth =  $dbh->prepare("SELECT  Name, Surname FROM Authors WHERE Id=$id");      my $sth =  $dbh->prepare("SELECT  Name, Surname FROM Authors WHERE Id=$id");
Line 1041  sub PrintQOfAuthor Line 1181  sub PrintQOfAuthor
     my @Questions;      my @Questions;
     while (($q)=$sth->fetchrow,$q)      while (($q)=$sth->fetchrow,$q)
      {push @Questions,$q unless $forbidden{$q}}       {push @Questions,$q unless $forbidden{$q}}
       $sth->finish;
   
     my ($output, $i, $suffix, $hits) = ('', 0, '', $#Questions + 1);      my ($output, $i, $suffix, $hits) = ('', 0, '', $#Questions + 1);
   
Line 1051  sub PrintQOfAuthor Line 1192  sub PrintQOfAuthor
         } else {          } else {
                 $suffix = 'Ñ';                  $suffix = 'Ñ';
         }          }
           print h2("ðÏÉÓË × ÂÁÚÅ ×ÏÐÒÏÓÏ×");
           print printform;
         print p({align=>"center"}, "á×ÔÏÒ ".strong("$name $surname. ")          print p({align=>"center"}, "á×ÔÏÒ ".strong("$name $surname. ")
         . " : $hits ÐÏÐÁÄÁÎÉ$suffix.");          . " : $hits ÐÏÐÁÄÁÎÉ$suffix.");
   
Line 1113  a({href=>url."?authors=surname"},"ÆÁÍÉÌÉ Line 1255  a({href=>url."?authors=surname"},"ÆÁÍÉÌÉ
            }             }
      }       }
      $output.="</TABLE>";       $output.="</TABLE>";
        $sth->finish;
      return $output;       return $output;
 }  }
   
Line 1141  MAIN: Line 1284  MAIN:
                 print &Include_virtual("../dimrub/db/reklama.html");                  print &Include_virtual("../dimrub/db/reklama.html");
         }          }
   
   
 if ($^O =~ /win/i) {  if ($^O =~ /win/i) {
         $thislocale = "Russian_Russia.20866";          $thislocale = "Russian_Russia.20866";
 } else {  } else {
Line 1168  if ((uc 'Á') ne 'á') {print "Koi8-r loca Line 1312  if ((uc 'Á') ne 'á') {print "Koi8-r loca
   
         if (param('rand')) {          if (param('rand')) {
                 my ($type, $qnum) = ('', 12);                  my ($type, $qnum) = ('', 12);
                 $type .= 'â' if (param('brain'));                  $type.=$TypeName{$_} foreach param('type');
                 $type .= 'þ' if (param('chgk'));  #               $type .= 'â' if (param('brain'));
   #               $type .= 'þ' if (param('chgk'));
                 $qnum = param('qnum') if (param('qnum') =~ /^\d+$/);                  $qnum = param('qnum') if (param('qnum') =~ /^\d+$/);
                 $qnum = 0 if (!$type);                  $qnum = 0 if (!$type);
                 if (param('email') && -x $SENDMAIL &&                  my $Email;
                 open(F, "| $SENDMAIL -t -n")) {                  if (($Email=param('email')) && -x $SENDMAIL &&
                         my ($Email) = param('email');                  open(F, "| $SENDMAIL $Email")) {
                         my ($mime_type) = $text ? "plain" : "html";                          my ($mime_type) = $text ? "plain" : "html";
                         print F <<EOT;                          print F <<EOT;
 To: $Email  To: $Email
 From: olegstemanov\@mail.ru  From: olegstepanov\@mail.ru
 Subject: Sluchajnij Paket Voprosov "Chto? Gde? Kogda?"  Subject: Sluchajnij Paket Voprosov "Chto? Gde? Kogda?"
 MIME-Version: 1.0  MIME-Version: 1.0
 Content-type: text/$mime_type; charset="koi8-r"  Content-type: text/$mime_type; charset="koi8-r"
Line 1186  Content-type: text/$mime_type; charset=" Line 1331  Content-type: text/$mime_type; charset="
 EOT  EOT
                         print F &PrintRandom($dbh, $type, $qnum, $text);                          print F &PrintRandom($dbh, $type, $qnum, $text);
                         close F;                          close F;
                         print "ðÁËÅÔ ÓÌÕÞÁÊÎÏ ×ÙÂÒÁÎÎÙÈ ×ÏÐÒÏÓÏ× ÐÏÓÌÁÎ. îÁÖÍÉÔÅ                          print "ðÁËÅÔ ÓÌÕÞÁÊÎÏ ×ÙÂÒÁÎÎÙÈ ×ÏÐÒÏÓÏ× ÐÏÓÌÁÎ ÐÏ ÁÄÒÅÓÕ $Email. îÁÖÍÉÔÅ
                         ÎÁ <B>Reload</B> ÄÌÑ ÐÏÌÕÞÅÎÉÑ ÅÝÅ ÏÄÎÏÇÏ ÐÁËÅÔÁ";                          ÎÁ <B>Reload</B> ÄÌÑ ÐÏÌÕÞÅÎÉÑ ÅÝÅ ÏÄÎÏÇÏ ÐÁËÅÔÁ";
                 } else {                  } else {
                         print &PrintRandom($dbh, $type, $qnum, $text);                          print &PrintRandom($dbh, $type, $qnum, $text);
Line 1208  print $query if $printqueries; Line 1353  print $query if $printqueries;
               my $sth=$dbh->prepare($query);                my $sth=$dbh->prepare($query);
               $sth->execute;                $sth->execute;
               my $sstr= join ' ',$sth->fetchrow;                my $sstr= join ' ',$sth->fetchrow;
               $searchin{'question'}=1;                $sth->finish;
               $searchin{'answer'}=1;                $searchin{'Question'}=1;
                 $searchin{'Answer'}=1;
         $sstr=~tr/£³/Åå/;
 $sstr=~s/[^ÊÃÕËÅÎÇÛÝÚÈßÆÙ×ÁÐÒÏÌÄÖÜÑÞÓÍÉÔØÂÀêãõëåîçûýúèÿæù÷áðòïìäöüñþóíéôøâàa-zA-Z0-9]/ /gi;  $sstr=~s/[^ÊÃÕËÅÎÇÛÝÚÈßÆÙ×ÁÐÒÏÌÄÖÜÑÞÓÍÉÔØÂÀêãõëåîçûýúèÿæù÷áðòïìäöüñþóíéôøâàa-zA-Z0-9]/ /gi;
 #              print &PrintQuestion($dbh,$qid, 1, '!');  #              print &PrintQuestion($dbh,$qid, 1, '!');
               &PrintSearch($dbh, $sstr, 'proxy');                &PrintSearch($dbh, $sstr, 'proxy');
Line 1249  $sstr=~s/[^ÊÃÕËÅÎÇÛÝÚÈßÆÙ×ÁÐÒÏÌÄÖÜÑÞÓÍÉÔ Line 1396  $sstr=~s/[^ÊÃÕËÅÎÇÛÝÚÈßÆÙ×ÁÐÒÏÌÄÖÜÑÞÓÍÉÔ
                         WHERE FileName = '$tour.txt'");                          WHERE FileName = '$tour.txt'");
                         $sth->execute;                          $sth->execute;
                         $tour = ($sth->fetchrow)[0];                          $tour = ($sth->fetchrow)[0];
                           $sth->finish;
                 }                  }
                 print &PrintTournament($dbh, $tour, param('answer'));                  print &PrintTournament($dbh, $tour, param('answer'));
         }          }

Removed from v.1.40  
changed lines
  Added in v.1.53


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>