--- db/prgsrc/db.cgi 2001/12/31 18:05:16 1.56
+++ db/prgsrc/db.cgi 2002/01/15 03:34:31 1.60
@@ -43,6 +43,7 @@ my ($SRCPATH) = "$PWD/../dimrub/src";
my ($ZIP) = "/home/piataev/bin/zip";
my $DUMPFILE = "/tmp/chgkdump";
my ($SENDMAIL) = "/usr/sbin/sendmail";
+my ($TMPDIR) = "/tmp";
my ($TMSECS) = 30*24*60*60;
my (%RevMonths) =
('Jan', '0', 'Feb', '1', 'Mar', '2', 'Apr', '3', 'May', '4', 'Jun', '5',
@@ -51,6 +52,9 @@ my (%RevMonths) =
'Янв', '0', 'Фев', 1, 'Мар', 2, 'Апр', 3, 'Май', '4',
'Июн', '5', 'Июл', 6, 'Авг', '7', 'Сен', '8',
'Окт', '9', 'Ноя', '19', 'Дек', '11');
+my @months=('000','Jan',"Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct",
+ "Nov","Dec");
+
# Determine whether the given time is within 2 months from now.
sub NewEnough {
@@ -354,8 +358,9 @@ print "$query\n",br if $printqueries;
{
($field,$lo,$hi,$wordnumber)=@blob[$ii..($ii+3)];
$ii+=4;
- $number=$lo+$hi*256;
- $field=$fieldname{$field};
+ my $addnumber=($field >> 4) << 16;
+ $number=(($field >> 4) << 16)+($hi << 8) + $lo;
+ $field=$fieldname{$field & 0xF};
if ($searchin{$field})
{
push @{$tasksof{$i}{$number}}, $wordnumber;
@@ -668,15 +673,15 @@ sub PrintSearch {
$sth->execute;
my ($q,$nf);
($sstr, $q,$nf)=($sth->fetchrow);
- @Questions=unpack 'S*',$q;
- @allnf=unpack 'S*',$nf;
+ @Questions=unpack 'L*',$q;
+ @allnf=unpack 'L*',$nf;
$sth->finish;
} else
{
@Questions=&Search($dbh, \$sstr,$metod,$all,\@allnf);
- my $tmp=$dbh->quote(pack("S*",@Questions));
+ my $tmp=$dbh->quote(pack("L*",@Questions));
my $qsstr=$dbh->quote($sstr);
- my $nf=$dbh->quote(pack("S*", @allnf));
+ my $nf=$dbh->quote(pack("L*", @allnf));
my $ss=200;
do
{
@@ -867,9 +872,9 @@ sub PrintTournament {
"вопросы + ответы") . "]")
);
} else {
- $list .= dd(a({href=>url . "?tour=$textid&comp=1"},
- img({src=>'/icons/compressed.gif', alt=>'[ZIP]', border=>1}))
- . " " . img({src=>$imgsrc, alt=>$alt})
+ $list .= dd(#a({href=>url . "?tour=$textid&comp=1"},
+ #img({src=>'/icons/compressed.gif', alt=>'[ZIP]', border=>1})). " " .
+ img({src=>$imgsrc, alt=>$alt})
. " " . a({href=>url . "?tour=$textid&answer=0"},
$Tournament{'Title'}. " ".
$Tournament{'PlayedAt'}) . $qnum);
@@ -999,12 +1004,17 @@ sub PrintTour {
sub PrintField {
my ($header, $value, $text) = @_;
if ($text) {
- $value =~ s/<[\/\w]*>//sg;
+ $value =~ s/<[\/\w]*?>//sg;
} else {
$value =~ s/^\s+/
/mg;
$value =~ s/^\|([^\n]*)/
$1<\/pre>/mg; + $value =~ s/\s+-+\s+/ /mg; + $value =~ s/(\s)"/$1/mg; + $value =~ s/^"//mg; + $value =~ s/"//mg; } + return $text ? "$header:\n$value\n\n" : strong("$header: ") . $value . p . "\n"; } @@ -1175,7 +1185,8 @@ sub PrintArchive { } return @list; } - return "$SRCPATH/$Tournament{'FileName'} "; +# return "$SRCPATH/$Tournament{'FileName'} "; + return "$TMPDIR/$Tournament{'FileName'} "; } sub PrintAll { @@ -1342,6 +1353,147 @@ a({href=>url."?authors=surname"},"фамили } +sub WriteFile { + my ($dbh,$fname) = @_; + $fname=~s/\.txt$//; + $fname=~s/.*\/(\w+)/$1/; + my $query= "SELECT Id, Title, Copyright, Info, URL, + Editors, EnteredBy, PlayedAt, CreatedAt + from Tournaments where FileName=".$dbh->quote("$fname.txt"); + my $sth=$dbh->prepare($query); + my (%Question,%editor,%qnumber,%copyright,%author,%vid,%tourtitle); + $sth->execute; + my ($Id, $Title, $Copyright, $Info, $URL, + $Editors, $EnteredBy, $PlayedAt, $CreatedAt)= + $sth->fetchrow; + return -1 unless $Id; + open (OUT, ">$TMPDIR/$fname.txt"); + print OUT "Чемпионат:\n$Title\n\n"; + my $date=$PlayedAt; + my ($year,$month,$day)=split /-/, $date; +# $month=0,$date=0 if $year && $month==1 && $day==1; + my $pdate=sprintf("%02d-%3s-%4d",$day,$months[$month],$year); + + print OUT "Дата:\n$pdate\n\n" if $date; + + print OUT "URL:\n$URL\n\n" if $URL; + + print OUT "Инфо:\n$Info\n\n" if $Info; + + print OUT "Копирайт:\n$Copyright\n\n" if $Copyright; + + print OUT "Редактор:\n$Editors\n\n" if $Editors; + + + $query= "SELECT Id, Title, Copyright, Editors from Tournaments where ParentId=$Id order by Id"; + $sth=$dbh->prepare($query); + $sth->execute; + my ($tourid,$tourtitle,$cright,$editor,@tours,$vid,$author,$tourauthor); + + + while (($tourid,$tourtitle,$cright,$editor)=$sth->fetchrow,$tourid) + { +# $text{$tourid}="Тур:\n$tourtitle\n\n"; + $query= "SELECT * from Questions where ParentId=$tourid order by QuestionId"; + my $sth1=$dbh->prepare($query); + $sth1->execute; + push(@tours,$tourid); + $tourtitle{$tourid}=$tourtitle; + $copyright{$tourid}=$cright; + $editor{$tourid}=$editor; + $vid=''; + my $author=''; + my $eqauthor=1; + my $qnumber=0; + my @arr; + while ( @arr=$sth1->fetchrow, $arr[0]) + { + my($i, $name) = 0; + $qnumber++; + foreach $name (@{$sth1->{NAME}}) { + $arr[$i]=~s/^(.*?)\s*$/$1/; + $Question{$tourid}[$qnumber]{$name} = $arr[$i++]; + } + if ($vid) + { + if ($vid ne $Question{$tourid}[$qnumber]{'Type'}) {print STDERR "Warning: Different types for Tournament $tourid\n"} + } else + { + $vid=$Question{$tourid}[$qnumber]{'Type'}; + } + + if ($author) + { + if ($author ne $Question{$tourid}[$qnumber]{'Authors'}) + { + $eqauthor=0; + } + } else + { + $author=$Question{$tourid}[$qnumber]{'Authors'}; + $eqauthor=0 unless $author; + } + } + $vid{$tourid}=$vid; + $qnumber{$tourid}=$qnumber; + $author{$tourid}=$eqauthor ? $author : ''; + } + + + $vid=''; + my $eqvid=1; + my $eqauthor=1; + foreach (@tours) + { + $vid||=$vid{$_}; + if ($vid{$_} ne $vid) + { + $eqvid=0; + } + $author||=$author{$_}; + if (!$author{$_} || ($author{$_} ne $author)) + { + $eqauthor=0; + } + } + + print OUT "Вид:\n$vid\n\n" if $eqvid; + print OUT "Автор:\n$author\n\n" if $eqauthor; + + foreach my $tour(@tours) + { + print OUT "Тур:\n$tourtitle{$tour}\n\n"; + print OUT "Вид:\n$vid{$tour}\n\n" if !$eqvid; + print OUT "Копирайт:\n$copyright{$tour}\n\n" if $copyright{$tour} && ($copyright{$tour} ne $Copyright); + print OUT "Редактор:\n$editor{$tour}\n\n" if $editor{$tour} && ($editor{$tour} ne $Editors); + $tourauthor=0; + if (!$eqauthor && $author{$tour}) + { + print OUT "Автор:\n$author{$tour}\n\n"; + $tourauthor=1; + } + foreach my $q(1..$qnumber{$tour}) + { + print OUT "Вопрос $q:\n".$Question{$tour}[$q]{'Question'}."\n\n"; + print OUT "Ответ:\n".$Question{$tour}[$q]{'Answer'}."\n\n"; + print OUT "Автор:\n".$Question{$tour}[$q]{'Authors'}."\n\n" + if !$tourauthor && !$eqauthor && $Question{$tour}[$q]{'Authors'}; + print OUT "Комментарий:\n".$Question{$tour}[$q]{'Comments'}."\n\n" + if $Question{$tour}[$q]{'Comments'}; + print OUT "Источник:\n".$Question{$tour}[$q]{'Sources'}."\n\n" + if $Question{$tour}[$q]{'Sources'}; + print OUT "Рейтинг:\n".$Question{$tour}[$q]{'Rating'}."\n\n" + if $Question{$tour}[$q]{'Rating'}; + + } + } + + close OUT; + + + +} + MAIN: { @@ -1428,7 +1580,8 @@ EOT elsif (param('sstr')||param('was')) { &PrintSearch($dbh, param('sstr'), param('metod'),param('was')); $dbh->do("delete from lastqueries where - time_to_sec(now())-time_to_sec(t) >3600") + (TO_DAYS(NOW()) - TO_DAYS(t) >= 2) OR + (time_to_sec(now())-time_to_sec(t) >3600)") } elsif (param('qid')) { my $qid=param('qid'); @@ -1457,6 +1610,7 @@ $sstr=~s/[^йцукенгшщзхъфывапролджэячсмит ); $tour = (param('tour')) ? param('tour') : 0; my (@files) = &PrintArchive($dbh, $tour); + WriteFile($dbh,$_) foreach @files; open F, "$ZIP -j - $SRCPATH/COPYRIGHT @files |"; print (); close F;