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

version 1.52, 2001/12/17 11:47:23 version 1.53, 2001/12/21 11:54:37
Line 12  my $printqueries=0; Line 12  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}  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', 'Ответ',   my %rusfieldname=('Question','Вопрос', 'Answer', 'Ответ', 
                   'Comments', 'Комментарии', 'Authors', 'Автор',                     'Comments', 'Комментарии', 'Authors', 'Автор', 
Line 29  my $Ll=qr/(?:[A-Z])|(?:${RL})/; Line 30  my $Ll=qr/(?:[A-Z])|(?:${RL})/;
 my $thislocale;  my $thislocale;
   
 $searchin{$_}=1 foreach param('searchin');  $searchin{$_}=1 foreach param('searchin');
 #$searchin{'Question'}=param('Question');  my %TypeName=('children'=>'Д', 'game'=>'И',
 #$searchin{'Answer'}=param('Answer');                'chgk'=>'Ч', 'brain'=>'Б', 'beskrylka'=>'Л','ehruditka'=>'Э');
 #$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 732  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 745  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 765  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 831  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 874  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 1037  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=~/Ч|Б/);
        $sth->finish;  
        $chosen{$q} = 'y';     $q="select QuestionId, QuestionId/$r-floor(QuestionId/$r) as val 
        push @questions, $q;         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 1288  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);
                 my $Email;                  my $Email;
                 *STDERR=*STDOUT;  
                 if (($Email=param('email')) && -x $SENDMAIL &&                  if (($Email=param('email')) && -x $SENDMAIL &&
                 open(F, "| $SENDMAIL $Email")) {                  open(F, "| $SENDMAIL $Email")) {
                         my ($mime_type) = $text ? "plain" : "html";                          my ($mime_type) = $text ? "plain" : "html";

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


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