--- db/prgsrc/db.cgi 2001/12/17 11:47:23 1.52 +++ db/prgsrc/db.cgi 2001/12/21 11:54:37 1.53 @@ -12,6 +12,7 @@ my $printqueries=0; my %forbidden=(); 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 %rusfieldname=('Question','Вопрос', 'Answer', 'Ответ', 'Comments', 'Комментарии', 'Authors', 'Автор', @@ -29,11 +30,11 @@ my $Ll=qr/(?:[A-Z])|(?:${RL})/; my $thislocale; $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 %TypeName=('children'=>'Д', 'game'=>'И', + 'chgk'=>'Ч', 'brain'=>'Б', 'beskrylka'=>'Л','ehruditka'=>'Э'); + + + my $all=param('all'); $all=0 if lc $all eq 'no'; my ($PWD) = `pwd`; @@ -732,6 +733,13 @@ sub PrintRandom { return $output; } +sub PrintEditor { + my $t=shift; #ссылка на Хэш с полями + my $ed=$$t{'Editors'}; + my $edname=($ed=~/\,/ ) ? "Редакторы" : "Редактор" ; + return h4({align=>"center"},"$edname: $ed" ); +} + sub PrintTournament { my ($dbh, $Id, $answer) = @_; my (%Tournament, @Tours, $i, $list, $qnum, $imgsrc, $alt, @@ -745,7 +753,7 @@ sub PrintTournament { my ($Copyright) = $Tournament{'Copyright'}; @Tours = &GetTours($dbh, $Id); - + $list=''; if ($Id) { for ($Tournament{'Type'}) { /Г/ && do { @@ -765,6 +773,7 @@ sub PrintTournament { $output .= h2({align=>"center"}, "$title") . p . "\n"; + $output.=&PrintEditor(\%Tournament); last; }; /Т/ && do { @@ -831,10 +840,11 @@ sub PrintTournament { $output .= p("Копирайт: " . $Copyright); } + + if ($Info) { $output .= p($Info); } - return $output; } @@ -874,6 +884,7 @@ sub PrintTour { $Tournament{'PlayedAt'}, "
", $Tour{"Title"} . " ($qnum вопрос$suffix)\n") . p; + $output .=&PrintEditor(\%Tour); my (@Questions) = &GetTourQuestions($dbh, $Id); for ($q = 0; $q <= $#Questions; $q++) { @@ -1037,18 +1048,31 @@ sub Get12Random { my (%chosen); srand; - for ($i = 0; $i < $num; $i++) { - do { - $q = int(rand($qnum)); - $sth = $dbh->prepare("SELECT Type FROM Questions - WHERE QuestionId=$q"); - $sth->execute; - $t = ($sth->fetchrow)[0]; - } until !$chosen{$q} && $t && $type =~ /[$t]/; - $sth->finish; - $chosen{$q} = 'y'; - push @questions, $q; + my $where=0; + my $r=int (rand(10000)); + + foreach (split '', $type) + { + $where.= " OR (Type ='$_') OR (Type ='$_Д') "; + } + $where.= "OR (Type='ЧБ')" if ($type=~/Ч|Б/); + + $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; } @@ -1288,12 +1312,12 @@ if ((uc 'а') ne 'А') {print "Koi8-r loca if (param('rand')) { my ($type, $qnum) = ('', 12); - $type .= 'Б' if (param('brain')); - $type .= 'Ч' if (param('chgk')); + $type.=$TypeName{$_} foreach param('type'); +# $type .= 'Б' if (param('brain')); +# $type .= 'Ч' if (param('chgk')); $qnum = param('qnum') if (param('qnum') =~ /^\d+$/); $qnum = 0 if (!$type); my $Email; - *STDERR=*STDOUT; if (($Email=param('email')) && -x $SENDMAIL && open(F, "| $SENDMAIL $Email")) { my ($mime_type) = $text ? "plain" : "html";