1: #!/usr/bin/perl -w
2:
3: use DBI;
4: use CGI ':all';
5: use Text::Query;
6: use strict;
7: use Time::Local;
8: use POSIX qw(locale_h);
9: use locale;
10: #open STDERR, ">errors1";
11: my $printqueries=0;
12: my %forbidden=();
13: my $debug=0; #added by R7
14: my %fieldname= (0,'Question', 1, 'Answer', 2, 'Comments', 3, 'Authors', 4, 'Sources');
15: my %rusfieldname=('Question','Вопрос', 'Answer', 'Ответ',
16: 'Comments', 'Комментарии', 'Authors', 'Автор',
17: 'Sources', 'Источник','old','Старый','rus','Новый');
18: my %searchin;
19: my $rl=qr/[йцукенгшщзхъфывапролджэячсмитьбюё]/;
20: my $RL=qr/[ЙЦУКЕНГШЩЗХЪЭЖДЛОРПАВЫФЯЧСМИТЬБЮЁ]/;
21: my $RLrl=qr/(?:(?:${rl})|(?:${RL}))+/;
22: my $l=qr/(?:(?:${RLrl})|(?:[\w\-]))+/;
23: my $Ll=qr/(?:[A-Z])|(?:${RL})/;
24:
25:
26:
27:
28: my $thislocale;
29:
30: $searchin{$_}=1 foreach param('searchin');
31: #$searchin{'Question'}=param('Question');
32: #$searchin{'Answer'}=param('Answer');
33: #$searchin{'Comments'}=param('Comments');
34: #$searchin{'Authors'}=param('Authors');
35: #$searchin{'Sources'}=param('Sources');
36: my $all=param('all');
37: $all=0 if lc $all eq 'no';
38: my ($PWD) = `pwd`;
39: chomp $PWD;
40: my ($SRCPATH) = "$PWD/../dimrub/src";
41: my ($ZIP) = "/home/piataev/bin/zip";
42: my $DUMPFILE = "/tmp/chgkdump";
43: my ($SENDMAIL) = "/usr/sbin/sendmail";
44: my ($TMSECS) = 30*24*60*60;
45: my (%RevMonths) =
46: ('Jan', '0', 'Feb', '1', 'Mar', '2', 'Apr', '3', 'May', '4', 'Jun', '5',
47: 'Jul', '6', 'Aug', '7', 'Sep', '8', 'Oct', '9', 'Nov', '10',
48: 'Dec', '11',
49: 'Янв', '0', 'Фев', 1, 'Мар', 2, 'Апр', 3, 'Май', '4',
50: 'Июн', '5', 'Июл', 6, 'Авг', '7', 'Сен', '8',
51: 'Окт', '9', 'Ноя', '19', 'Дек', '11');
52:
53: # Determine whether the given time is within 2 months from now.
54: sub NewEnough {
55: my ($a) = @_;
56: my ($year, $month, $day) = split('-', $a);
57:
58: return (time - timelocal(0, 0, 0, $day, $month -1, $year) < $TMSECS);
59: }
60:
61: # Reads one question from the DB. Gets DB handler and Question ID.
62: sub GetTournament {
63: my ($dbh, $Id) = @_;
64: my (%Tournament, $field, @arr);
65:
66: return %Tournament if ($Id == 0);
67:
68: my ($sth) = $dbh->prepare("SELECT * FROM Tournaments WHERE Id=$Id");
69: $sth->execute;
70:
71: @arr = $sth->fetchrow;
72: my($i, $name) = 0;
73: foreach $name (@{$sth->{NAME}}) {
74: $Tournament{$name} = $arr[$i++];
75: }
76:
77: return %Tournament;
78: }
79:
80: # Reads one question from the DB. Gets DB handler and Question ID.
81: sub GetQuestion {
82: my ($dbh, $QuestionId) = @_;
83: my (%Question, $field, @arr);
84:
85: my($sth) = $dbh->prepare("
86: SELECT * FROM Questions WHERE QuestionId=$QuestionId
87: ");
88:
89: $sth->execute;
90:
91: @arr = $sth->fetchrow;
92: my($i, $name) = 0;
93: foreach $name (@{$sth->{NAME}}) {
94: $Question{$name} = $arr[$i++];
95: }
96:
97: return %Question;
98: }
99:
100: # Gets numbers of all the questions from the given tour.
101: sub GetTourQuestions {
102: my ($dbh, $ParentId) = @_;
103: my (@arr, @Questions);
104:
105: my ($sth) = $dbh->prepare("SELECT QuestionId FROM Questions
106: WHERE ParentId=$ParentId ORDER BY QuestionId");
107:
108: $sth->execute;
109:
110: while (@arr = $sth->fetchrow) {
111: push @Questions, $arr[0];
112: }
113:
114: return @Questions;
115: }
116:
117: # Returns list of children of the given tournament.
118: sub GetTours {
119: my ($dbh, $ParentId) = @_;
120: my (@arr, @Tours);
121:
122: my ($sth) = $dbh->prepare("SELECT Id FROM Tournaments
123: WHERE ParentId=$ParentId ORDER BY Id");
124:
125: $sth->execute;
126:
127: while (@arr = $sth->fetchrow) {
128: push @Tours, $arr[0];
129: }
130:
131: return @Tours;
132: }
133:
134: sub count
135: {
136: my ($dbh,$word)=@_;
137: print "timeb=".time.br if $debug;
138: $word=$dbh->quote(uc $word);
139: my $query="SELECT number from nests,nf where $word=w1 AND w2=nf.id";
140: my $sth=$dbh->prepare($query);
141: $sth->execute;
142: my @a=$sth->fetchrow;
143: print "timee0=".time.br if $debug;
144: $a[0]||0;
145: }
146:
147:
148: sub printform
149: {
150:
151: my $submit=submit(-value=>'Поиск');
152: my $inputstring=textfield(-name=>'sstr',
153: -default=>param('sstr')||'',
154: -size=>50);
155: my $fields=checkbox_group('searchin',['Question','Answer','Comments','Authors','Sources'], [grep $searchin{$_}, keys %searchin],
156: 'false',\%rusfieldname);
157:
158: my $metod=radio_group(-name=>'metod',-values=>['old','rus'],
159: -default=>param('metod')||'rus',
160: -labels=>\%rusfieldname);
161: my $all=radio_group(-name=>'all',-values=>['yes','no'],
162: -default=>param('all')||'no',
163: -labels=>{'yes'=>'Все','no'=>'Любое'});
164:
165: #################################################
166: return start_form(-method=>'get',
167: -action=>url,
168: -enctype=>
169: "application/x-www-form-urlencoded"
170: ).br.
171: table(Tr
172: (
173: td({-valign=>'TOP'},$inputstring.$submit.p."Метод: $metod".p."Слова: $all"),
174: td({-valign=>'TOP'},(' 'x 8).'Поля:'),
175: td({-valign=>'TOP'},$fields)
176: )
177: )
178:
179: #$fields.
180: #$inputstring.$submit.br.$metod.$all
181: .endform
182: .hr
183:
184: }
185:
186: sub proxy
187: {
188: #print "time0=".time.br if $debug;
189: my ($dbh,$ptext,$allnf)=@_;
190: my $text=$$ptext;
191: $text=~tr/ёЁ/еЕ/;
192: $text=~s/(${RLrl})p(${RLrl})/$1p$2/gom;
193: $text=~s/p(${RLrl})/р$1/gom;
194: $text=~s/(${RLrl})p/$1р/gom;
195: $text=~s/\s+/ /gmo;
196: $text=~s/[^йцукенгшщзхъфывапролджэячсмитьбюЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮQWERTYUIOPASDFGHJKLZXCVBNM]/ /g;
197: $text=uc $text;
198: my @list= $text=~m/(?:(?:${RLrl})+)|(?:[A-Za-z0-9]+)/gom;
199: my (%c, %good,$sstr);
200: foreach (@list)
201: {
202: $c{$_}=count($dbh,$_)||10000;
203: }
204: my @words=sort {$c{$a}<=> $c{$b}} @list;
205:
206: # $good{$words[$_]}=1 foreach 0..4;
207:
208: foreach (@words)
209: {
210: $good{$_}=1 if $c{$_}<200;
211: }
212:
213: $good{$words[$_]}=0 foreach 11..$#words;
214:
215: # foreach (@list)
216: # {
217: # if ($good{$_})
218: # {
219: # $good{$_}=0;
220: # $sstr.=" $_";
221: # }
222: # }
223: $sstr.=" $_" foreach grep {$good{$_}} @list;
224: print "time05=".time.br if $debug;
225: $$ptext=$sstr;
226: return russearch($dbh,$sstr,0,$allnf);
227: }
228:
229:
230: sub russearch {
231: my ($dbh, $sstr, $all,$allnf)=@_;
232: my (@qw,@w,@tasks,$qw,@arr,$nf,$sth,@nf,$w,$where,$e,@where,%good,$i,%where,$from);
233: my($number,@good,$t,$task,@rho,$rank,%rank,$r2,$r1,$word,$n,@last,$good,@words,%number,$taskid);
234: my ($hi, $lo, $wordnumber,$query,$blob,$field,$sf,$ii);
235: my @frequence;
236: my (@arr1,@ar,@sf,@arr2);
237: my %tasks;
238: my $tasks;
239: my @verybad;
240: my %nf;
241: my %tasksof;
242: my %wordsof;
243: my %relevance;
244: my @blob;
245: my %count;
246:
247: $sstr=~tr/йцукенгшщзхъфывапролджэячсмитьбю/ЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ/;
248: @qw=@w =split (' ', uc $sstr);
249:
250: #-----------
251: foreach $i (0..$#w) # заполняем массив @nf начальных форм
252: # $nf[$i] -- ссылка на массив возможных
253: # начальных форм словоформы $i
254: {
255: $qw= $dbh->quote (uc $w[$i]);
256: $query=" select distinct w2 from nests
257: where w1=$qw";
258: print "$query",br if $printqueries;
259: $sth=$dbh -> prepare($query);
260: $sth -> execute;
261: @{$nf[$i]}=();
262: while (@arr = $sth->fetchrow)
263: {
264: push (@{$nf[$i]},$arr[0])
265: }
266: }
267:
268:
269: my @bad=grep {!@{$nf[$_]}} 0..$#w; # @bad -- номера словоформ,
270: # которых нет в словаре
271:
272: if (@bad) #есть неопознанные словоформы
273: {
274: require "cw.pl";
275: foreach $i(@bad)
276: {
277: if (@arr=checkword($dbh,$w[$i]))
278: {push (@{$nf[$i]}, @arr);}
279: else
280: {push (@verybad,$i);}
281: }
282: }
283: return () if ($all && @verybad);
284:
285:
286: my $kvo=0;
287: push @$allnf, @{$_} foreach @nf;
288: print "nf=@$allnf" if $printqueries;
289:
290: foreach $i (0..$#w) #запросы в базу...
291: {
292: @arr=@{$nf[$i]} if $nf[$i];
293: @arr2=@arr1=@arr;
294:
295:
296:
297:
298: $_= " word2question.word=".$_. ' ' foreach @arr;
299: $_= " nf.id=".$_. ' ' foreach @arr1;
300: # @arr=(0) unless @arr;
301: $query="select questions from word2question where". (join ' OR ', @arr);
302: print STDERR "!$query\n",br if $printqueries;
303:
304: $sth=$dbh -> prepare($query);
305: $sth->execute;
306:
307: @blob=();
308: while (@arr=$sth->fetchrow)
309: {
310: @blob=(@blob,unpack 'C*',$arr[0]);
311: }
312: $query="select number from nf where ".(join ' OR ', @arr1);
313: print "$query\n",br if $printqueries;
314: $sth=$dbh -> prepare($query);
315: $sth->execute;
316:
317: while (@arr=$sth->fetchrow)
318: {
319: $frequence[$i]+=$arr[0];
320: }
321:
322:
323:
324: if (@blob < 4)
325: {
326: $tasksof{$i}=undef;
327: } else
328: {
329: $kvo++;
330: $ii=0;
331: while ($ii<$#blob) # создаём хэш %tasksof, ключи которого --
332: # номера искомых словоформ, а значения --
333: # списки вопросов, в которых есть соответствующа
334: # словоформа.
335: # Каждый список в свою очередь также оформлен в
336: # виде хэша, ключи которого -- номера вопросов,
337: # а значения -- списки номеров вхождений. Вот.
338: {
339: ($field,$lo,$hi,$wordnumber)=@blob[$ii..($ii+3)];
340: $ii+=4;
341: $number=$lo+$hi*256;
342: $field=$fieldname{$field};
343: if ($searchin{$field})
344: {
345: push @{$tasksof{$i}{$number}}, $wordnumber;
346: # дополнили в хэше, висящем на
347: # словоформе $i в %tasksof список
348: # вхождений $i в вопрос $number.
349: push @{$wordsof{$number}{$i}}, $wordnumber;
350: # дополнили в хэше, висящем на
351: # вопросе $number в %wordsof список
352: # вхождений $i в вопрос $number.
353:
354:
355: }
356: } #while ($ii<$#blob)
357: }
358: } #foreach $i
359:
360: #print "keys tasksof", join ' ', keys %{$tasksof{0}};
361: #Ищем пересечение или объединение списков вопросов (значений %tasksof)
362: foreach $sf (keys %tasksof)
363: {
364: $count{$_}++ foreach keys %{$tasksof{$sf}};
365: }
366: @tasks= ($all ? (grep {$count{$_}==$kvo} keys %count) :
367: keys %count) ;
368:
369:
370: print "\n\$#tasks=",$#tasks,br if $printqueries;
371: ############ Сортировка найденных вопросов
372:
373: foreach (keys %wordsof)
374: {
375: $relevance{$_}=&relevance($#w,$wordsof{$_},\@frequence) if $_
376: }
377:
378: @tasks=sort {$relevance{$b}<=>$relevance{$a}} @tasks;
379:
380:
381: ############
382:
383: print "tasks=@tasks" if $printqueries;
384:
385: #print "$_ $relevance{$_} | " foreach @tasks;
386: #print br;
387: print "allnf=@$allnf",br if $printqueries;
388: return @tasks;
389: }
390:
391:
392: sub distance {
393: # на входе -- номера словоформ и ссылки на
394: # списки вхождений. На выходе -- расстояние,
395: # вычисляемое по формуле min(|b-a-pb+pa|)
396: # pb,pa
397: # (pb и pa -- позиции слов b и a)
398: my ($a,$b,$lista,$listb)=@_;
399: my ($pa,$pb,$min,$curmin);
400: $min=10000;
401: foreach $pa (@$lista)
402: {
403: foreach $pb (@$listb)
404: {
405: $curmin=abs($b-$a-$pb+$pa);
406: $min= $curmin if $curmin<$min;
407: }
408: }
409: return $min;
410:
411: }
412:
413: sub relevance {
414: # На входе -- количество искомых словоформ -1 и
415: # ссылка на hash, ключи которого --
416: # номера словоформ, а значения -- списки вхождений
417:
418: my ($n,$words,$frequence)=@_;
419: my $relevance=0;
420: my ($first,$second,$d);
421: foreach $first (0..$n)
422: {
423: $relevance+=scalar @{$$words{$first}}+1000+1000/$$frequence[$first]
424: if $$words{$first};
425: foreach $second ($first+1..$n)
426: {
427: $d=&distance($first,$second,$$words{$first},$$words{$second});
428: $relevance+=($d>10?0:10-$d)*10;
429: }
430: }
431: return $relevance;
432: }
433:
434:
435:
436: # Returns list of QuestionId's, that have the search string in them.
437: sub Search {
438: my ($dbh, $s,$metod,$all,$allnf) = @_;
439: my $sstr=$$s;
440: my (@arr, @Questions, @fields);
441: my (@sar, $i, $sth,$where,$query);
442: my $ip=$ENV{'REMOTE_ADDR'};
443:
444: $ip=$dbh->quote($ip);
445: $query=
446: "INSERT into queries (query,metod,searchin,ip)
447: values (". $dbh->quote($sstr).', '.
448: $dbh->quote($metod) . ', ' .
449: $dbh->quote(join ' ', grep $searchin{$_}, keys %searchin) .
450: ", $ip)";
451: print $query if $printqueries;
452: $dbh -> do ($query);
453: if ($metod eq 'rus')
454: {
455: my @tasks=russearch($dbh,$sstr,$all,$allnf);
456: return @tasks
457: }
458: elsif ($metod eq 'proxy')
459: {
460: # $searchin{'question'}=1;
461: # $searchin{'answer'}=1;
462: my @task=proxy($dbh,$s,$allnf);
463: # $$s=$sstr;
464: return @task
465: }
466:
467:
468:
469: ###Simple and advanced query processing. Added by R7
470: if ($metod eq 'simple' || $metod eq 'advanced')
471: {
472: foreach (qw/Question Answer Sources Authors Comments/) {
473: if (param($_)) {
474: push @fields, $_;
475: }
476: }
477:
478: @fields=(qw/Question Answer Sources Authors Comments/) unless scalar @fields;
479: my $fields=join ",", @fields;
480: my $q=new Text::Query($sstr,
481: -parse => 'Text::Query::'.
482: (($metod eq 'simple') ? 'ParseSimple':'ParseAdvanced'),
483: -solve => 'Text::Query::SolveSQL',
484: -build => 'Text::Query::BuildSQLMySQL',
485: -fields_searched => $fields);
486:
487: $where= $$q{'matchexp'};
488: $query= "SELECT Questionid FROM Questions
489: WHERE $where";
490: print br."Query is: $query".br if $debug;
491:
492: $sth = $dbh->prepare($query);
493: } else
494: ######
495: {
496:
497: # foreach (qw/Question Answer Sources Authors Comments/) {
498: foreach (param('searchin')) {
499: # if (param($_)) {
500: push @fields, "IFNULL($_, '')";
501: # }
502: }
503: @sar = split " ", $sstr;
504: for $i (0 .. $#sar) {
505: $sar[$i] = $dbh->quote("%${sar[$i]}%");
506: }
507:
508: my($f) = "CONCAT(" . join(',', @fields) . ")";
509: if (param('all') eq 'yes') {
510: $sstr = join " AND $f LIKE ", @sar;
511: } else {
512: $sstr = join " OR $f LIKE ", @sar;
513: }
514:
515: my $query;
516: $query="SELECT QuestionId FROM Questions
517: WHERE $f LIKE $sstr ORDER BY QuestionId";
518:
519:
520: print $query if $printqueries;
521: $sth = $dbh->prepare($query)
522: } #else -- processing old-style query (R7)
523:
524: $sth->execute;
525: while (@arr = $sth->fetchrow) {
526: push @Questions, $arr[0] unless $forbidden{$arr[0]};
527: }
528:
529: print "@Questions" if $printqueries;
530: return @Questions;
531: }
532:
533: # Substitute every letter by a pair (for case insensitive search).
534: my (@letters) = qw/аА бБ вВ гГ дД еЕ жЖ зЗ иИ йЙ кК лЛ мМ нН оО
535: пП рР сС тТ уУ фФ хХ цЦ чЧ шШ щЩ ьЬ ыЫ эЭ юЮ яЯ/;
536:
537: sub NoCase {
538: my ($sstr) = shift;
539: my ($res);
540:
541: if (($res) = grep(/$sstr/, @letters)) {
542: return "[$res]";
543: } else {
544: return $sstr;
545: }
546: }
547:
548: sub PrintList {
549: my ($dbh,$Questions,$shablon)=@_;
550:
551: my $first=param('first') ||1;
552: my $kvo=param('kvo') ||30;
553:
554: $first=$first-($first-1)%$kvo;
555: my $last=$first+$kvo-1;
556: $last=scalar @$Questions if scalar @$Questions <$last;
557: my($f,$l);
558: my $nav='';
559: my $qs=query_string;
560: $qs=~s/\;/\&/g;
561: $qs=~s/\&first\=[^\&]+//g;
562:
563:
564: if ($first>$kvo*3+1)
565: {
566: $nav.=
567: (" "x4).
568: a({href=>url."?".$qs."\&first=1"},"<<").(" "x4).
569: a({href=>(url."?".$qs."\&first=".($first-$kvo))},"<").(" "x4)
570: }
571:
572: else {$nav.=' 'x15;}
573:
574: my ($fprint,$lprint);
575: my $llprint=$#$Questions- ($#$Questions+1)%$kvo+2;
576: if ($#$Questions+1<=$kvo*7)
577: { $fprint=1;
578: $lprint=$llprint;
579: }
580: elsif ($first>$kvo*3 && $#$Questions+1-$first>$kvo*3)
581: {
582: $fprint=$first-$kvo*3;
583: $lprint=$first+$kvo*3;
584: }
585: elsif ($first<=$kvo*3)
586: {
587: $fprint=1; $lprint=6*$kvo+1;
588: }
589: else
590: {
591: $lprint=$llprint;
592: $fprint=$lprint-$kvo*6
593: }
594:
595: # my $fprint=($first>$kvo*3) ? $first-$kvo*3 : 1;
596: # my $lprint=$#$Questions+1-$fprint>$kvo*7 ? $kvo*7 :$#$Questions+1;
597: # if ($lprint-$fprint<$kvo*6 && $fprint>1)
598: # {
599: # $fprint=$lprint-$kvo*6;
600: # $fprint=1 if ($fprint<=0)
601: # }
602:
603:
604:
605: for($f=$fprint; $f<=$lprint; $f+=$kvo)
606: {
607: # next if $first-$f>$kvo*3;
608: $l=$f+$kvo-1;
609: $l=$#$Questions+1 if $l>$#$Questions+1;
610: if ($f==$first) {$nav.="[$f-$l] ";}
611: else {
612: $nav.= "[".a({href=>(url."?".$qs."\&first=$f")},"$f-$l")."] ";}
613: }
614: if ($lprint+$kvo<$#$Questions)
615: {
616: $nav.=
617: (" "x4).
618: a({href=>(url."?".$qs."\&first=".($first+$kvo))},">").(" "x4).
619: a({href=>url."?".$qs."\&first=$llprint"},">>").(" "x4)
620: }
621:
622:
623: print "$nav".br."\n";
624: for (my $i = $first; $i <= $last; $i++) {
625: my $output = &PrintQuestion($dbh, $$Questions[$i-1], 1, $i, 1);
626: if (param('metod') eq 'rus' || param('metod') eq 'proxy')
627: {
628: $output=~s/\b($shablon)\b/\<strong\>$1\<\/strong\>/gi;
629: } else {
630: $output=~s/($shablon)/\<strong\>$1\<\/strong\>/gi;
631: }
632: print $output;
633: }
634:
635:
636: print "$nav".br."\n";
637:
638: }
639:
640: sub PrintSearch {
641: my ($dbh, $sstr, $metod) = @_;
642: print h2("Поиск в базе вопросов");
643: print printform;
644: my @allnf;
645: my (@Questions) = &Search($dbh, \$sstr,$metod,$all,\@allnf);
646: my ($output, $i, $suffix, $hits) = ('', 0, '', $#Questions + 1);
647:
648: my $shablon;
649: $metod='rus' if $metod eq 'proxy';
650: if ($metod eq 'rus')
651: {
652: my $where='0';
653: $where.= " or w2=$_ " foreach @allnf;
654: my $query="select w1 from nests where $where";
655: my $sth=$dbh->prepare($query);
656: print "$query" if $printqueries;
657:
658: $sth->execute;
659: my @shablon;
660: while (my @arr = $sth->fetchrow)
661: {
662: push @shablon,"(?:$arr[0])";
663: }
664: $shablon= join "|", @shablon;
665: $shablon=~s/[её]/\[ЕЁ\]/gi;
666: # $shablon=~s/([йцукенгшщзхъфывапролджэячсмитьбюЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ])/&NoCase($1)/ge;
667: $shablon=qr/$shablon/i;
668: print "!$shablon!",br if $printqueries;
669: }
670:
671:
672:
673: if ($hits =~ /1.$/ || $hits =~ /[5-90]$/) {
674: $suffix = 'й';
675: } elsif ($hits =~ /1$/) {
676: $suffix = 'е';
677: } else {
678: $suffix = 'я';
679: }
680:
681: print p({align=>"center"}, "Результаты поиска на " . strong($sstr)
682: . " : $hits попадани$suffix.");
683:
684: if (param('word')) {
685: $sstr = '[ \.\,:;]' . $sstr . '[ \.\,:\;]';
686: }
687:
688: $sstr =~ s/(.)/&NoCase($1)/ge;
689:
690: my @sar;
691: if ($metod ne 'rus')
692: {
693: (@sar) = split(' ', $sstr);
694: $shablon=join "|",@sar;
695: }
696: PrintList($dbh,\@Questions,$shablon);
697: }
698:
699: sub PrintRandom {
700: my ($dbh, $type, $num, $text) = @_;
701: my (@Questions) = &Get12Random($dbh, $type, $num);
702: my ($output, $i) = ('', 0);
703:
704: if ($text) {
705: $output .= " $num случайных вопросов.\n\n";
706: } else {
707: $output .=
708: h2({align=>"center"}, "$num случайных вопросов.");
709: }
710:
711: for ($i = 0; $i <= $#Questions; $i++) {
712: # Passing DB handler, question ID, print answer, question
713: # number, print title, print text/html
714: $output .=
715: &PrintQuestion($dbh, $Questions[$i], 1, $i + 1, 0, $text);
716: }
717: return $output;
718: }
719:
720: sub PrintTournament {
721: my ($dbh, $Id, $answer) = @_;
722: my (%Tournament, @Tours, $i, $list, $qnum, $imgsrc, $alt,
723: $SingleTour);
724: my ($output) = '';
725:
726: %Tournament = &GetTournament($dbh, $Id) if ($Id);
727:
728: my ($URL) = $Tournament{'URL'};
729: my ($Info) = $Tournament{'Info'};
730: my ($Copyright) = $Tournament{'Copyright'};
731:
732: @Tours = &GetTours($dbh, $Id);
733:
734: if ($Id) {
735: for ($Tournament{'Type'}) {
736: /Г/ && do {
737: $output .= h2({align=>"center"},
738: "Группа: $Tournament{'Title'} ",
739: "$Tournament{'PlayedAt'}") . p . "\n";
740: last;
741: };
742: /Ч/ && do {
743: return &PrintTour($dbh, $Tours[0], $answer)
744: if ($#Tours == 0);
745:
746: my $title="Пакет: $Tournament{'Title'}";
747: if ($Tournament{'PlayedAt'}) {
748: $title .= " $Tournament{'PlayedAt'}";
749: }
750:
751: $output .= h2({align=>"center"},
752: "$title") . p . "\n";
753: last;
754: };
755: /Т/ && do {
756: return &PrintTour($dbh, $Id, $answer);
757: };
758: }
759: } else {
760: my ($qnum) = GetQNum($dbh);
761: $output .= h2("Банк Вопросов: $qnum вопросов") . p . "\n";
762: }
763:
764: for ($i = 0; $i <= $#Tours; $i++) {
765: %Tournament = &GetTournament($dbh, $Tours[$i]);
766:
767: if ($Tournament{'Type'} =~ /Ч/) {
768: $SingleTour = 0;
769: my (@Tours) = &GetTours($dbh, $Tournament{'Id'});
770: $SingleTour = 1
771: if ($#Tours == 0);
772: }
773: if ($Tournament{'QuestionsNum'} > 0) {
774: $qnum = " ($Tournament{'QuestionsNum'} вопрос" .
775: &Suffix($Tournament{'QuestionsNum'}) . ")\n";
776: } else {
777: $qnum = '';
778: }
779: if ($Tournament{'Type'} =~ /Г/) {
780: $imgsrc = "/icons/folder.gif";
781: $alt = "[*]";
782: } else {
783: $imgsrc = "/icons/folder.gif";
784: $alt = "[-]";
785: }
786:
787: if ($SingleTour or $Tournament{'Type'} =~ /Т/) {
788: $list .= dd(img({src=>$imgsrc, alt=>$alt})
789: . " " . $Tournament{'Title'} . " " .
790: $Tournament{'PlayedAt'} . $qnum) .
791: dl(
792: dd("["
793: . a({href=>url . "?tour=$Tournament{'Id'}&answer=0"},
794: "вопросы") . "] ["
795: . a({href=>url . "?tour=$Tournament{'Id'}&answer=1"},
796: "вопросы + ответы") . "]")
797: );
798: } else {
799: $list .= dd(a({href=>url . "?tour=$Tournament{'Id'}&comp=1"},
800: img({src=>'/icons/compressed.gif', alt=>'[ZIP]', border=>1}))
801: . " " . img({src=>$imgsrc, alt=>$alt})
802: . " " . a({href=>url . "?tour=$Tournament{'Id'}&answer=0"},
803: $Tournament{'Title'}. " ".
804: $Tournament{'PlayedAt'}) . $qnum);
805: }
806: }
807: $output .= dl($list);
808:
809: if ($URL) {
810: $output .=
811: p("Дополнительная информация об этом турнире - по адресу " .
812: a({-'href'=>$URL}, $URL));
813: }
814:
815: if ($Copyright) {
816: $output .= p("Копирайт: " . $Copyright);
817: }
818:
819: if ($Info) {
820: $output .= p($Info);
821: }
822:
823: return $output;
824: }
825:
826: sub Suffix {
827: my ($qnum) = @_;
828: my ($suffix) = 'а' if $qnum =~ /[234]$/;
829: $suffix = '' if $qnum =~ /1$/;
830: $suffix = 'ов' if $qnum =~ /[567890]$/ || $qnum =~ /1.$/;
831: return $suffix;
832: }
833:
834: sub IsTour {
835: my ($dbh, $Id) = @_;
836: my ($sth) = $dbh->prepare("SELECT Type FROM Tournaments
837: WHERE Id=$Id");
838: $sth->execute;
839: return ($sth->fetchrow)[0] =~ /Т/;
840: }
841:
842: # Gets a DB handler (ofcourse) and a tour Id. Prints all the
843: # question of that tour, according to the options.
844: sub PrintTour {
845: my ($dbh, $Id, $answer) = @_;
846: my ($output, $q, $bottom, $field) = ('', 0, '', '');
847:
848: my (%Tour) = &GetTournament($dbh, $Id);
849: my (@Tours) = &GetTours($dbh, $Tour{'ParentId'});
850: my (%Tournament) = &GetTournament($dbh, $Tour{'ParentId'});
851:
852: return 0
853: if ($Tour{'Type'} !~ /Т/);
854:
855: my ($qnum) = $Tour{'QuestionsNum'};
856: my ($suffix) = &Suffix($qnum);
857:
858: $output .= h2({align=>"center"}, $Tournament{"Title"},
859: $Tournament{'PlayedAt'},
860: "<br>", $Tour{"Title"} .
861: " ($qnum вопрос$suffix)\n") . p;
862:
863: my (@Questions) = &GetTourQuestions($dbh, $Id);
864: for ($q = 0; $q <= $#Questions; $q++) {
865: $output .= &PrintQuestion($dbh, $Questions[$q], $answer, 0);
866: }
867:
868: $output .= hr({-'align'=>'center', -'width'=>'80%'});
869:
870: if ($Tournament{'URL'}) {
871: $output .=
872: p("Дополнительная информация об этом турнире - по адресу " .
873: a({-'href'=>$Tournament{'URL'}}, $Tournament{'URL'}));
874: }
875:
876: if ($Tournament{'Copyright'}) {
877: $output .= p("Копирайт: " . $Tournament{'Copyright'});
878: }
879:
880: if ($Tournament{'Info'}) {
881: $output .= p($Tournament{'Info'});
882: }
883:
884:
885: if ($answer == 0) {
886: $bottom .=
887: "[" . a({href=>url . "?tour=$Id&answer=1"}, "ответы") . "] " . br;
888: }
889: if (&IsTour($dbh, $Id - 1)) {
890: $bottom .=
891: "[" . a({href=>url . "?tour=" . ($Id - 1) . "&answer=0"},
892: "предыдущий тур") . "] ";
893: $bottom .=
894: "[" . a({href=>url . "?tour=" . ($Id - 1) . "&answer=1"},
895: "предыдущий тур с ответами") . "] " . br;
896: }
897: if (&IsTour($dbh, $Id + 1)) {
898: $bottom .=
899: "[" . a({href=>url . "?tour=" . ($Id + 1) . "&answer=0"},
900: "следующий тур") . "] ";
901: $bottom .=
902: "[" . a({href=>url . "?tour=" . ($Id + 1) . "&answer=1"},
903: "следующий тур с ответами") . "] ";
904: }
905:
906: $output .=
907: p({align=>"center"}, font({size=>-1}, $bottom));
908:
909: return $output;
910: }
911:
912: sub PrintField {
913: my ($header, $value, $text) = @_;
914: if ($text) {
915: $value =~ s/<[\/\w]*>//sg;
916: } else {
917: $value =~ s/^\s+/<br> /mg;
918: $value =~ s/^\|([^\n]*)/<pre>$1<\/pre>/mg;
919: }
920:
921: return $text ? "$header:\n$value\n\n" :
922: strong("$header: ") . $value . p . "\n";
923: }
924:
925: # Gets a DB handler (ofcourse) and a question Id. Prints
926: # that question, according to the options.
927: sub PrintQuestion {
928: my ($dbh, $Id, $answer, $qnum, $title, $text) = @_;
929: my ($output, $titles) = ('', '');
930: my (%Question) = &GetQuestion($dbh, $Id);
931: if (!$text) {
932: $output .= hr({width=>"50%"});
933: if ($title) {
934: my (%Tour) = GetTournament($dbh, $Question{'ParentId'});
935: my (%Tournament) = GetTournament($dbh, $Tour{'ParentId'});
936: $titles .=
937: dd(img({src=>"/icons/folder.open.gif"}) . " " .
938: a({href=>url . "?tour=$Tournament{'Id'}"}, $Tournament{'Title'}, $Tournament{'PlayedAt'}));
939: $titles .=
940: dl(dd(img({src=>"/icons/folder.open.gif"}) . " " .
941: a({href=>url . "?tour=$Tour{'Id'}"}, $Tour{'Title'})));
942: }
943: $output .= dl(strong($titles));
944: }
945:
946: $qnum = $Question{'Number'}
947: if ($qnum == 0);
948:
949: $output .=
950: &PrintField("Вопрос $qnum", $Question{'Question'}, $text);
951:
952: if ($answer) {
953: $output .=
954: &PrintField("Ответ", $Question{'Answer'}, $text);
955:
956: if ($Question{'Authors'}) {
957: my $q=$Question{'Authors'};
958:
959: my $sth=$dbh->prepare("select Authors.Id,Name, Surname, Nicks from Authors, A2Q
960: where Authors.Id=Author And Question=$Id");
961: $sth->execute;
962: my ($AuthorId,$Name, $Surname,$other,$Nicks);
963:
964: while ((($AuthorId,$Name, $Surname,$Nicks)=$sth->fetchrow),$AuthorId)
965: {
966: my ($firstletter)=$Name=~m/^./g;
967: $Name=~s/\./\\\./g;
968: my $sha="(?:$Name\\s+$Surname)|(?:$Surname\\s+$Name)|(?:$firstletter\\.\\s*$Surname)|(?:$Surname\\s+$firstletter\\.)|(?:$Surname)|(?:$Name)";
969: if ($Nicks)
970: {
971: $Nicks=~s/^\|//;
972: foreach (split /\|/, $Nicks)
973: {
974: s/\s+/ /g;
975: s/\s+$//;
976: s/ /\\s+/g;
977: s/\./\\\./g;
978: if (s/>$//) {$sha="$sha|(?:$_)"}
979: else {$sha="(?:$_)|$sha"}
980: }
981: }
982: $q=~s/($sha)/a({href=>url."?qofauthor=$AuthorId"},$1)/ei;
983: }
984:
985: $output .= &PrintField("Автор(ы)", $q, $text);
986:
987: # $output.= &PrintField("Другие вопросы", $other);
988: }
989:
990: if ($Question{'Sources'}) {
991: $output .= &PrintField("Источник(и)", $Question{'Sources'}, $text);
992: }
993:
994: if ($Question{'Comments'}) {
995: $output .= &PrintField("Комментарии", $Question{'Comments'}, $text);
996: }
997: }
998: $output.=br.a({href=> url."?metod=proxy&qid=$Id"}, 'Близкие вопросы').p
999: if $answer;
1000: return $output;
1001: }
1002:
1003: # Returns the total number of questions currently in the DB.
1004: sub GetQNum {
1005: my ($dbh) = @_;
1006: my ($sth) = $dbh->prepare("SELECT COUNT(*) FROM Questions");
1007: $sth->execute;
1008: return ($sth->fetchrow)[0];
1009: }
1010: sub GetMaxQId {
1011: my ($dbh) = @_;
1012: my ($sth) = $dbh->prepare("SELECT MAX(QuestionId) FROM Questions");
1013: $sth->execute;
1014: return ($sth->fetchrow)[0];
1015: }
1016:
1017: # Returns Id's of 12 random questions
1018: sub Get12Random {
1019: my ($dbh, $type, $num) = @_;
1020: my ($i, @questions, $q, $t, $sth);
1021: my ($qnum) = &GetMaxQId($dbh);
1022: my (%chosen);
1023: srand;
1024:
1025: for ($i = 0; $i < $num; $i++) {
1026: do {
1027: $q = int(rand($qnum));
1028: $sth = $dbh->prepare("SELECT Type FROM Questions
1029: WHERE QuestionId=$q");
1030: $sth->execute;
1031: $t = ($sth->fetchrow)[0];
1032: } until !$chosen{$q} && $t && $type =~ /[$t]/;
1033: $chosen{$q} = 'y';
1034: push @questions, $q;
1035: }
1036: return @questions;
1037: }
1038:
1039: sub Include_virtual {
1040: my ($fn, $output) = (@_, '');
1041:
1042: open F , $fn
1043: or return; #die "Can't open the file $fn: $!\n";
1044:
1045: while (<F>) {
1046: if (/<!--#include/o) {
1047: s/<!--#include virtual="\/(.*)" -->/&Include_virtual($1)/e;
1048: }
1049: if (/<!--#exec/o) {
1050: s/<!--#exec.*cmd\s*=\s*"([^"]*)".*-->/`$1`/e;
1051: }
1052: $output .= $_;
1053: }
1054: return $output;
1055: }
1056:
1057: sub PrintArchive {
1058: my($dbh, $Id) = @_;
1059: my ($output, @list, $i);
1060:
1061: my (%Tournament) = &GetTournament($dbh, $Id);
1062: my (@Tours) = &GetTours($dbh, $Id);
1063:
1064: if ($Tournament{'Type'} =~ /Г/ || $Id == 0) {
1065: for ($i = 0; $i <= $#Tours; $i++) {
1066: push(@list ,&PrintArchive($dbh, $Tours[$i]));
1067: }
1068: return @list;
1069: }
1070: return "$SRCPATH/$Tournament{'FileName'} ";
1071: }
1072:
1073: sub PrintAll {
1074: my ($dbh, $Id) = @_;
1075: my ($output, $list, $i);
1076:
1077: my (%Tournament) = &GetTournament($dbh, $Id);
1078: my (@Tours) = &GetTours($dbh, $Id);
1079: my ($New) = ($Id and $Tournament{'Type'} eq 'Ч' and
1080: &NewEnough($Tournament{"CreatedAt"})) ?
1081: img({src=>"/znatoki/dimrub/db/new-sml.gif", alt=>"NEW!"}) : "";
1082:
1083: if ($Id == 0) {
1084: $output = h3("Все турниры");
1085: } else {
1086: $output .= dd(img({src=>"/icons/folder.gif", alt=>"[*]"}) .
1087: " " . a({href=>url . "?tour=$Tournament{'Id'}&answer=0"},
1088: $Tournament{'Title'}) ." " . $Tournament{'PlayedAt'} . " $New");
1089: }
1090: if ($Id == 0 or $Tournament{'Type'} =~ /Г/) {
1091: for ($i = 0; $i <= $#Tours; $i++) {
1092: $list .= &PrintAll($dbh, $Tours[$i]);
1093: }
1094: $output .= dl($list);
1095: }
1096: return $output;
1097: }
1098:
1099: sub PrintDates {
1100: my ($dbh) = @_;
1101: my ($from) = param('from_year') . "-" . param('from_month') .
1102: "-" . param('from_day');
1103: my ($to) = param('to_year') . "-" . param('to_month') . "-" . param('to_day');
1104: $from = $dbh->quote($from);
1105: $to = $dbh->quote($to);
1106: my ($sth) = $dbh->prepare("
1107: SELECT DISTINCT Id
1108: FROM Tournaments
1109: WHERE PlayedAt >= $from AND PlayedAt <= $to
1110: AND Type = 'Ч'
1111: ");
1112: $sth->execute;
1113: my (%Tournament, @array, $output, $list);
1114:
1115: $output = h3("Список турниров, проходивших между $from и $to.");
1116: while (@array = $sth->fetchrow) {
1117: next
1118: if (!$array[0]);
1119: %Tournament = &GetTournament($dbh, $array[0]);
1120: $list .= dd(img({src=>"/icons/folder.gif", alt=>"[*]"}) .
1121: " " . a({href=>url . "?tour=$Tournament{'Id'}&answer=0"},
1122: $Tournament{'Title'}, $Tournament{'PlayedAt'}));
1123: }
1124: $output .= dl($list);
1125: return $output;
1126: }
1127:
1128: sub PrintQOfAuthor
1129: {
1130:
1131: my ($dbh, $id) = @_;
1132: $id=$dbh->quote($id);
1133: my $sth = $dbh->prepare("SELECT Name, Surname FROM Authors WHERE Id=$id");
1134: $sth->execute;
1135: my ($name,$surname)=$sth->fetchrow;
1136:
1137: $sth = $dbh->prepare("SELECT Question FROM A2Q WHERE Author=$id");
1138: $sth->execute;
1139: my $q;
1140: my @Questions;
1141: while (($q)=$sth->fetchrow,$q)
1142: {push @Questions,$q unless $forbidden{$q}}
1143:
1144: my ($output, $i, $suffix, $hits) = ('', 0, '', $#Questions + 1);
1145:
1146: if ($hits =~ /1.$/ || $hits =~ /[5-90]$/) {
1147: $suffix = 'й';
1148: } elsif ($hits =~ /1$/) {
1149: $suffix = 'е';
1150: } else {
1151: $suffix = 'я';
1152: }
1153: print h2("Поиск в базе вопросов");
1154: print printform;
1155: print p({align=>"center"}, "Автор ".strong("$name $surname. ")
1156: . " : $hits попадани$suffix.");
1157:
1158:
1159: # for ($i = 0; $i <= $#Questions; $i++) {
1160: # $output = &PrintQuestion($dbh, $Questions[$i], 1, $i + 1, 1);
1161: # print $output;
1162: # }
1163: PrintList($dbh,\@Questions,'gdfgdfgdfgdfg');
1164: }
1165:
1166:
1167: sub PrintAuthors
1168: {
1169: my ($dbh,$sort)=@_;
1170: my($output,$out1,@array,$sth);
1171: if ($sort eq 'surname')
1172: {
1173: $sth =
1174: $dbh->prepare("SELECT Id, Name, Surname, QNumber FROM Authors order by Surname, Name");
1175: }
1176: elsif($sort eq 'name')
1177: {
1178: $sth =
1179: $dbh->prepare("SELECT Id, Name, Surname, QNumber FROM Authors order by Name, Surname");
1180: }
1181: else
1182: {
1183: $sth =
1184: $dbh->prepare("SELECT Id, Name, Surname, QNumber FROM Authors Order by QNumber DESC, Surname");
1185: }
1186:
1187: $output.=h2("Авторы вопросов")."\n";
1188: $output.="<TABLE>";
1189:
1190:
1191: $sth->execute;
1192: $output.=Tr(th[a({href=>url."?authors=name"},"Имя")
1193: .", ".
1194: a({href=>url."?authors=surname"},"фамилия")
1195: , a({href=>url."?authors=kvo"},"Количество вопросов")]);
1196:
1197: $out1='';
1198:
1199: my $ar=$sth->fetchall_arrayref;
1200:
1201:
1202:
1203: foreach my $arr(@$ar)
1204: {
1205:
1206: my ($id,$name,$surname,$kvo)=@$arr;
1207: if (!$name || !$surname) {#print "Opanki at $id\n"
1208: } else
1209: {
1210: my $add=Tr(td([a({href=>url."?qofauthor=$id"},"$name $surname"), $kvo]))."\n";
1211: print STDERR $add;
1212: $output.=$add;
1213: }
1214: }
1215: $output.="</TABLE>";
1216: return $output;
1217: }
1218:
1219:
1220:
1221: MAIN:
1222: {
1223: setlocale(LC_CTYPE,'russian');
1224: my($i, $tour);
1225: my($text) = (param('text')) ? 1 : 0;
1226:
1227: my($dbh) = DBI->connect("DBI:mysql:chgk", "piataev", "")
1228: or do {
1229: print h1("Временные проблемы") . "База данных временно не
1230: работает. Заходите попозже.";
1231: print &Include_virtual("../dimrub/db/reklama.html");
1232: print end_html;
1233: die "Can't connect to DB chgk\n";
1234: };
1235: if (!param('comp') and !param('sqldump') and !$text) {
1236: print header;
1237: print start_html(-"title"=>'Database of the questions',
1238: -author=>'dimrub@icomverse.com',
1239: -bgcolor=>'#fff0e0',
1240: -vlink=>'#800020');
1241: print &Include_virtual("../dimrub/db/reklama.html");
1242: }
1243:
1244:
1245: if ($^O =~ /win/i) {
1246: $thislocale = "Russian_Russia.20866";
1247: } else {
1248: $thislocale = "ru_RU.KOI8-R";
1249: }
1250: POSIX::setlocale( &POSIX::LC_ALL, $thislocale );
1251:
1252: if ((uc 'а') ne 'А') {print "Koi8-r locale not installed!\n"};
1253:
1254:
1255: if ($text) {
1256: print header('text/plain');
1257: }
1258:
1259: if (param('hideequal')) {
1260: my ($sth)= $dbh -> prepare("select first, second FROM equalto");
1261: $sth -> execute;
1262: while ( my ($first, $second)=$sth -> fetchrow)
1263: {
1264: $forbidden{$first}=1;
1265: }
1266: $sth->finish;
1267: }
1268:
1269:
1270: if (param('rand')) {
1271: my ($type, $qnum) = ('', 12);
1272: $type .= 'Б' if (param('brain'));
1273: $type .= 'Ч' if (param('chgk'));
1274: $qnum = param('qnum') if (param('qnum') =~ /^\d+$/);
1275: $qnum = 0 if (!$type);
1276: if (param('email') && -x $SENDMAIL &&
1277: open(F, "| $SENDMAIL -t -n")) {
1278: my ($Email) = param('email');
1279: my ($mime_type) = $text ? "plain" : "html";
1280: print F <<EOT;
1281: To: $Email
1282: From: olegstemanov\@mail.ru
1283: Subject: Sluchajnij Paket Voprosov "Chto? Gde? Kogda?"
1284: MIME-Version: 1.0
1285: Content-type: text/$mime_type; charset="koi8-r"
1286:
1287: EOT
1288: print F &PrintRandom($dbh, $type, $qnum, $text);
1289: close F;
1290: print "Пакет случайно выбранных вопросов послан. Нажмите
1291: на <B>Reload</B> для получения еще одного пакета";
1292: } else {
1293: print &PrintRandom($dbh, $type, $qnum, $text);
1294: }
1295: }
1296: elsif (param('authors')){
1297: print &PrintAuthors($dbh,param('authors'));
1298: }
1299: elsif (param('qofauthor')){
1300: &PrintQOfAuthor($dbh,param('qofauthor'));
1301: }
1302: elsif (param('sstr')) {
1303: &PrintSearch($dbh, param('sstr'), param('metod'));
1304: }
1305: elsif (param('qid')) {
1306: my $qid=param('qid');
1307: my $query="SELECT Question, Answer from Questions where QuestionId=$qid";
1308: print $query if $printqueries;
1309: my $sth=$dbh->prepare($query);
1310: $sth->execute;
1311: my $sstr= join ' ',$sth->fetchrow;
1312: $searchin{'Question'}=1;
1313: $searchin{'Answer'}=1;
1314: $sstr=~tr/ёЁ/еЕ/;
1315: $sstr=~s/[^йцукенгшщзхъфывапролджэячсмитьбюЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮa-zA-Z0-9]/ /gi;
1316: # print &PrintQuestion($dbh,$qid, 1, '!');
1317: &PrintSearch($dbh, $sstr, 'proxy');
1318: }
1319:
1320: elsif (param('all')) {
1321: print &PrintAll($dbh, 0);
1322: } elsif (param('from_year') && param('to_year')) {
1323: print &PrintDates($dbh);
1324: } elsif (param('comp')) {
1325: print header(
1326: -'Content-Type' => 'application/x-zip-compressed; name="db.zip"',
1327: -'Content-Disposition' => 'attachment; filename="db.zip"'
1328: );
1329: $tour = (param('tour')) ? param('tour') : 0;
1330: my (@files) = &PrintArchive($dbh, $tour);
1331: open F, "$ZIP -j - $SRCPATH/COPYRIGHT @files |";
1332: print (<F>);
1333: close F;
1334: $dbh->disconnect;
1335: exit;
1336: } elsif (param('sqldump')) {
1337: print header(
1338: -'Content-Type' => 'application/x-zip-compressed; name="dump.zip"',
1339: -'Content-Disposition' => 'attachment; filename="dump.zip"'
1340: );
1341: open F, "$ZIP -j - $DUMPFILE |";
1342: print (<F>);
1343: close F;
1344: $dbh->disconnect;
1345: exit;
1346:
1347: } else {
1348: $tour = (param('tour')) ? param('tour') : 0;
1349: if ($tour !~ /^[0-9]*$/) {
1350: my ($sth) = $dbh->prepare("SELECT Id FROM Tournaments
1351: WHERE FileName = '$tour.txt'");
1352: $sth->execute;
1353: $tour = ($sth->fetchrow)[0];
1354: }
1355: print &PrintTournament($dbh, $tour, param('answer'));
1356: }
1357: if (!$text) {
1358: print &Include_virtual("../dimrub/db/footer.html");
1359: print end_html;
1360: }
1361: $dbh->disconnect;
1362: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>