Diff for /db/prgsrc/db.cgi between versions 1.99 and 1.100

version 1.99, 2003/04/19 22:50:06 version 1.100, 2003/04/20 07:59:41
Line 6  use strict; Line 6  use strict;
 use Time::Local;  use Time::Local;
 use POSIX qw(locale_h);  use POSIX qw(locale_h);
 use locale;  use locale;
   use vars qw($opt_z);
   use Getopt::Std;
   getopts('z');
 open STDERR, ">/var/tmp/errors1";  open STDERR, ">/var/tmp/errors1";
 my $newsurl='http://news.chgk.info/';  my $newsurl='http://news.chgk.info/';
   my $HTMLDIR="/!!!/";
   my $realHTMLDIR="c:/html/!!!/";
   my $usehtml=1;
 my $usewas=0;  my $usewas=0;
 my $cashednumber=500;  my $cashednumber=500;
 my $outputnumber=10;  my $outputnumber=10;
 my ($proxyptext,$proxysstr);  my ($proxyptext,$proxysstr);
 my $printqueries=0;  my $printqueries=0;
 my $url=url;  my $url=url||'';
 my $qs=query_string;  my $qs=query_string;
 my $globaloutput;  my $globaloutput;
 my %forbidden=();  my %forbidden=();
Line 23  $outputkvo=100 if $outputkvo>100; Line 29  $outputkvo=100 if $outputkvo>100;
   
 if (param('debug')) {$debug=1; $printqueries=1}  if (param('debug')) {$debug=1; $printqueries=1}
 *STDERR=*STDOUT if $debug;  *STDERR=*STDOUT if $debug;
 if ($url !~ /db\.chgk\.info/ && $url !~ /(localhost)||(bilbo)/ ) {  if ($url !~ /db\.chgk\.info/ && $url !~ /localhost/ ) {
    my $u="http://db.chgk.info/cgi-bin/db.cgi?$qs";     my $u="http://db.chgk.info/cgi-bin/db.cgi?$qs";
    Redirect ($u);     Redirect ($u);
    exit;     exit;
Line 142  sub fetchquestion { Line 148  sub fetchquestion {
         my ($sth,$q,$WithTour)=@_;          my ($sth,$q,$WithTour)=@_;
         if ($WithTour) {          if ($WithTour) {
                 ($$q{'Question'},$$q{'Answer'},$$q{'Comments'},$$q{'Authors'},                  ($$q{'Question'},$$q{'Answer'},$$q{'Comments'},$$q{'Authors'},
                 $$q{'Sources'},  
                 $$q{'Number'},                   $$q{'Number'}, 
                 $$q{'Title'}, $$q{'TourTitle'}, $$q{'FileName'},$$q{'PlayedAt'},$$q{'TourNumber'}) =                   $$q{'Title'}, $$q{'TourTitle'}, $$q{'FileName'},$$q{'PlayedAt'},$$q{'TourNumber'}) = 
                 $sth->fetchrow;                  $sth->fetchrow;
         } else {          } else {
                 ($$q{'Question'},$$q{'Answer'},$$q{'Comments'},$$q{'Authors'},                  ($$q{'Question'},$$q{'Answer'},$$q{'Comments'},$$q{'Authors'},
                 $$q{'Sources'},  
                 $$q{'Number'})=                   $$q{'Number'})= 
                 $sth->fetchrow;                  $sth->fetchrow;
         }          }
Line 167  sub SelectQuestions { Line 171  sub SelectQuestions {
   
         my $query;          my $query;
         if ($WithTour) {          if ($WithTour) {
                 $query="SELECT Questions.Question, Answer, Comments, Authors, Sources,                  $query="SELECT Questions.Question, Answer, Comments, Authors,
                         Questions.Number                          Questions.Number
                         , t2.Title, t1.Title, t2.FileName,  t2.PlayedAt,t1.Number                          , t2.Title, t1.Title, t2.FileName,  t2.PlayedAt,t1.Number
                         from Questions,Tournaments as t1, Tournaments as t2                           from Questions,Tournaments as t1, Tournaments as t2 
                         WHERE $where";                          WHERE $where";
         } else {          } else {
                 $query="SELECT Questions.Question, Answer, Comments, Authors,Sources,                  $query="SELECT Questions.Question, Answer, Comments, Authors,
                         Questions.Number from Questions                           Questions.Number from Questions 
                         WHERE $where";                          WHERE $where";
         }          }
Line 184  sub SelectQuestions { Line 188  sub SelectQuestions {
         return $sth;          return $sth;
 }  }
   
   
 # Reads one question from the DB. Gets DB handler and Question ID.  # Reads one question from the DB. Gets DB handler and Question ID.
 sub GetQuestion {  sub GetQuestion {
         my ($dbh, $QuestionId) = @_;          my ($dbh, $QuestionId) = @_;
Line 205  sub GetQuestion { Line 210  sub GetQuestion {
         return %Question;          return %Question;
 }  }
   
   sub tourhref {
      my ($t,$a,$gr)=@_;
      my $res;
      if ($usehtml) {
           $res=$t;
           $res.=$a?"-a":"-q" unless $gr;
           $res.=".html";
           return $res;
      } else {
           $res=$url;
           $res.="?tour=$t";
           $res.=$a?"?answers=1":"";
           return $res;
      }
   
   }
   
 # Gets numbers of all the questions from the given tour.  # Gets numbers of all the questions from the given tour.
 sub GetTourQuestions {  sub GetTourQuestions {
         my ($dbh, $ParentId) = @_;          my ($dbh, $ParentId) = @_;
Line 719  sub PrintList { Line 741  sub PrintList {
         {          {
            $nav.=             $nav.=
             (" "x4).              (" "x4).
             a({href=>url."?".$qs."\&first=1"},"<<").("&nbsp;"x4).              a({href=>$url."?".$qs."\&first=1"},"<<").("&nbsp;"x4).
             a({href=>(url."?".$qs."\&first=".($first-$outputkvo))},"<").("&nbsp;"x4)              a({href=>($url."?".$qs."\&first=".($first-$outputkvo))},"<").("&nbsp;"x4)
         }          }
         else {$nav.='&nbsp;'x15;}          else {$nav.='&nbsp;'x15;}
   
Line 762  sub PrintList { Line 784  sub PrintList {
           $l=$fkvo if $l>$fkvo+1;            $l=$fkvo if $l>$fkvo+1;
           if ($f==$first) {$nav.="[$f-$l] ";}            if ($f==$first) {$nav.="[$f-$l] ";}
           else {            else {
                   $nav.= "[".a({href=>(url."?".$qs."\&first=$f")},"$f-$l")."] ";}                    $nav.= "[".a({href=>($url."?".$qs."\&first=$f")},"$f-$l")."] ";}
         }          }
         if ($lprint+$outputkvo<$fkvo)          if ($lprint+$outputkvo<$fkvo)
         {          {
            $nav.=             $nav.=
             ("&nbsp;"x4).              ("&nbsp;"x4).
             a({href=>(url."?".$qs."\&first=".($first+$outputkvo))},">").("&nbsp;"x4).              a({href=>($url."?".$qs."\&first=".($first+$outputkvo))},">").("&nbsp;"x4).
             a({href=>url."?".$qs."\&first=$llprint"},">>").("&nbsp;"x4)              a({href=>$url."?".$qs."\&first=$llprint"},">>").("&nbsp;"x4)
         }          }
         $Output.= "$nav".br."\n";          $Output.= "$nav".br."\n";
         my @q=@$Questions[$first-1..$last-1];          my @q=@$Questions[$first-1..$last-1];
Line 944  sub PrintTournament { Line 966  sub PrintTournament {
         %Tournament = &GetTournament($dbh, $Id) if ($Id);          %Tournament = &GetTournament($dbh, $Id) if ($Id);
   
         my ($URL) = $Tournament{'URL'};          my ($URL) = $Tournament{'URL'};
         $URL=~s/http:\/znatoki\/boris\/reports\//$newsurl/ if url=~/kulichki/;          $URL=~s/http:\/znatoki\/boris\/reports\//$newsurl/ if $url=~/kulichki/;
         $URL=~s/\/znatoki\/boris\/reports\//$newsurl/ if url=~/kulichki/;;          $URL=~s/\/znatoki\/boris\/reports\//$newsurl/ if url=~/kulichki/;;
         my ($Info) = $Tournament{'Info'};          my ($Info) = $Tournament{'Info'};
         my ($Copyright) = $Tournament{'Copyright'};          my ($Copyright) = $Tournament{'Copyright'};
Line 999  sub PrintTournament { Line 1021  sub PrintTournament {
                 } else {                  } else {
                         $qnum = '';                          $qnum = '';
                 }                  }
                 if ($Tournament{'Type'} =~ /Г/) {                  if ($Tournament{'Type'} !~ /[ТЧ]/) {
                     $SingleTour=0;                      $SingleTour=0;
                         $imgsrc = "/icons/folder.gif";                          $imgsrc = "/icons/folder.gif";
                         $alt = "[*]";                          $alt = "[*]";
Line 1027  sub PrintTournament { Line 1049  sub PrintTournament {
                                     $Tournament{'PlayedAt'} . $qnum) .                                      $Tournament{'PlayedAt'} . $qnum) .
                                 dl(                                  dl(
                                         dd("["                                          dd("["
                                                 . a({href=>url .  "?tour=$textid&answer=0"},                                                  . a({href=>tourhref($textid,0)},
                                                 "вопросы") . "] ["                                                  "вопросы") . "] ["
                   . a({href=>url .  "?tour=$textid&answer=1"},                    . a({href=>tourhref($textid,1)},
                   "вопросы + ответы") . "]")                    "вопросы + ответы") . "]")
                                 );                                  );
                 } else {                  } else {
                         $list .= dd(a({href=>url . "?tour=$textid&comp=1"},                          $list .= dd(a({href=>
                                    $url . "?tour=$textid&comp=1"},
                                 img({src=>'/icons/compressed.gif', alt=>'[ZIP]', border=>1})). " " .                                   img({src=>'/icons/compressed.gif', alt=>'[ZIP]', border=>1})). " " . 
                                 img({src=>$imgsrc, alt=>$alt})                                  img({src=>$imgsrc, alt=>$alt})
                                 . " " . a({href=>url . "?tour=$textid&answer=0"},                                  . " " . a({href=>tourhref($textid,0,1)},
                                 $Tournament{'Title'}. " ".                                  $Tournament{'Title'}. " ".
                                           $Tournament{'PlayedAt'}||'') . $qnum);                                            $Tournament{'PlayedAt'}||'') . $qnum);
                 }                  }
Line 1044  sub PrintTournament { Line 1067  sub PrintTournament {
         $output .= dl($list);          $output .= dl($list);
   
         if ($URL) {          if ($URL) {
                 if (url=~/zaba\.ru/ && $URL=~/^\//){$URL="http://info.chgk.info$URL"}                  if ($url=~/zaba\.ru/ && $URL=~/^\//){$URL="http://info.chgk.info$URL"}
                 $output .=                  $output .=
                 p("Дополнительная информация об этом турнире - по адресу " .                  p("Дополнительная информация об этом турнире - по адресу " .
                         a({-'href'=>$URL}, $URL));                          a({-'href'=>$URL}, $URL));
Line 1141  sub PrintTour { Line 1164  sub PrintTour {
         my $n=$Tour{'Number'};          my $n=$Tour{'Number'};
         if ($answer == 0) {          if ($answer == 0) {
                 $bottom .=                  $bottom .=
                         "[" . a({href=>url . "?tour=$fname.$n&answer=1"}, "ответы") .  "] " . br;                          "[" . a({href=>tourhref($fname,1)}, 
                            "ответы") .  "] " . br;
         }          }
         if ($n>1) {          if ($n>1) {
                 $bottom .=                  $bottom .=
                         "[" . a({href=>url . "?tour=$fname." . ($n - 1) . "&answer=0"},                          "[" . a({href=>tourhref("$fname.".($n-1),0)},
                         "предыдущий тур") . "] ";                          "предыдущий тур") . "] ";
                 $bottom .=                  $bottom .=
                         "[" . a({href=>url . "?tour=$fname." . ($n - 1) . "&answer=1"},                          "[" . a({href=>tourhref("$fname.".($n-1),1)},
                         "предыдущий тур с ответами") . "] " . br;                          "предыдущий тур с ответами") . "] " . br;
         }          }
         if (&IsTour($dbh, $Tour{'ParentId'}, $n + 1)) {          if (&IsTour($dbh, $Tour{'ParentId'}, $n + 1)) {
                 $bottom .=                  $bottom .=
                         "[" . a({href=>url . "?tour=$fname." . ($n + 1) . "&answer=0"},                          "[" . a({href=>tourhref("$fname.".($n+1),0)},
                         "следующий тур") . "] ";                          "следующий тур") . "] ";
                 $bottom .=                  $bottom .=
                         "[" . a({href=>url . "?tour=$fname." . ($n + 1) . "&answer=1"},                          "[" . a({href=>tourhref("$fname.".($n+1),1)},
                         "следующий тур с ответами") . "] ";                          "следующий тур с ответами") . "] ";
         }          }
   
Line 1216  sub PrintQuestion { Line 1240  sub PrintQuestion {
                         $fname=~s/\.txt//;                          $fname=~s/\.txt//;
                         $titles .=                          $titles .=
                                 dd(img({src=>"/icons/folder.open.gif"}) . " " .                                  dd(img({src=>"/icons/folder.open.gif"}) . " " .
                                          a({href=>url . "?tour=$fname"}, $Question{'Title'}, $Question{'PlayedAt'}||''));                                           a({href=>tourhref($fname,0,1)}, 
                                  $Question{'Title'}, $Question{'PlayedAt'}||''));
                         $titles .=                          $titles .=
                                 dl(dd(img({src=>"/icons/folder.open.gif"}) . " " .                                  dl(dd(img({src=>"/icons/folder.open.gif"}) . " " .
                                         a({href=>url . "?tour=$fname.$Question{TourNumber}#$qnum"}, $Question{'TourTitle'})));                                          a({href=>tourhref("$fname.$Question{'TourNumber'}#$qnum",1)}, 
                             $Question{'TourTitle'})));
                 }                  }
                 $output .= dl(strong($titles));                  $output .= dl(strong($titles));
         }          }
Line 1317  $output.="</span>" Line 1343  $output.="</span>"
         $output=~s/\(pic: ([^\)]*)\)/<p><img src="\/znatoki\/images\/db\/$1"><p>/g unless $text;          $output=~s/\(pic: ([^\)]*)\)/<p><img src="\/znatoki\/images\/db\/$1"><p>/g unless $text;
         my $qid=param('tour') ? (param('tour').".$Question{'Number'}" ): '';          my $qid=param('tour') ? (param('tour').".$Question{'Number'}" ): '';
   
         $output.=br.a({href=> url."?metod=proxy&          $output.=br.a({href=> $url."?metod=proxy&
 qid=$qid"}, 'Близкие вопросы').p  qid=$qid"}, 'Близкие вопросы').p
              if $answer>0 && !$text && $qid;               if $answer>0 && !$text && $qid;
         return $output;          return $output;
Line 1439  sub PrintAll { Line 1465  sub PrintAll {
   
   
                 $output .= dd(img({src=>"/icons/folder.gif", alt=>"[*]"}) .                  $output .= dd(img({src=>"/icons/folder.gif", alt=>"[*]"}) .
       " " . a({href=>url . "?tour=$textid&answer=0"},        " " . a({href=>tourhref($textid,0,1)},
       $Tournament{'Title'}) ." " . ($Tournament{'PlayedAt'}||'') . " $New");        $Tournament{'Title'}) ." " . ($Tournament{'PlayedAt'}||'') . " $New");
         }          }
         if ($Id == 0 or $Tournament{'Type'} =~ /Г/ or $Tournament{'Type'} eq '') {          if ($Id == 0 or $Tournament{'Type'} =~ /Г/ or $Tournament{'Type'} eq '') {
Line 1473  sub PrintDates { Line 1499  sub PrintDates {
                         if (!$array[0]);                          if (!$array[0]);
                 %Tournament = &GetTournament($dbh, $array[0]);                  %Tournament = &GetTournament($dbh, $array[0]);
       $list .= dd(img({src=>"/icons/folder.gif", alt=>"[*]"}) .        $list .= dd(img({src=>"/icons/folder.gif", alt=>"[*]"}) .
       " " . a({href=>url . "?tour=$Tournament{'Id'}&answer=0"},        " " . a({href=>tourhref($Tournament{'FileName'},0,1)},
       $Tournament{'Title'}, $Tournament{'PlayedAt'}||''));        $Tournament{'Title'}, $Tournament{'PlayedAt'}||''));
         }          }
         $sth->finish;          $sth->finish;
Line 1554  sub PrintAuthors Line 1580  sub PrintAuthors
   
   
      $sth->execute;       $sth->execute;
      $output.=Tr(th[a({href=>url."?authors=name"},"Имя")       $output.=Tr(th[a({href=>$url."?authors=name"},"Имя")
 .", ".  .", ".
 a({href=>url."?authors=surname"},"фамилия")  a({href=>$url."?authors=surname"},"фамилия")
      , a({href=>url."?authors=kvo"},"Количество вопросов")]);       , a({href=>$url."?authors=kvo"},"Количество вопросов")]);
   
      $out1='';       $out1='';
   
Line 1573  a({href=>url."?authors=surname"},"фамили Line 1599  a({href=>url."?authors=surname"},"фамили
            if (!$name || !$surname) {             if (!$name || !$surname) {
               } else                } else
            {             {
              my $add=Tr(td([a({href=>url."?qofauthor=$id"},"$name $surname"), $kvo]))."\n";               my $add=Tr(td([a({href=>$url."?qofauthor=$id"},"$name $surname"), $kvo]))."\n";
              $output.=$add;               $output.=$add;
            }             }
      }       }
Line 1733  sub WriteFile { Line 1759  sub WriteFile {
   
 }  }
   
   sub Bottom
   {
           my $output.=&Include_virtual("../dimrub/db/footer.html");
           $output.=p."<center><font size=-2>Обновление: ".&Include_virtual("../dimrub/db/date")."</center></font>";
           $output.=<<EEE
   <SCRIPT LANGUAGE="JavaScript">
   function toggle(e) {
     if (e.style.display == "none") {
        e.style.display="";
     } else {
        e.style.display = "none";
    }
   }
   </SCRIPT>
   EEE
   ;
           $output.=end_html;
           return $output;
   }
   
   
 MAIN:  MAIN:
 {  {
Line 1820  td {font-size: x-small; font-family : sa Line 1866  td {font-size: x-small; font-family : sa
 th      {font-size: x-small; font-family : sans-serif}  th      {font-size: x-small; font-family : sans-serif}
 </style>\n";  </style>\n";
   
                 $globaloutput.=&Include_virtual("../dimrub/db/reklama.html");                  $globaloutput.=&Include_virtual("../dimrub/db/reklama.html")||'';
         }          }
   
        if (length ($qs)<=255 && $qs !~ /(sstr)|(rand)|(comp)|(all=)/i) {         if (length ($qs)<=255 && $qs !~ /(sstr)|(rand)|(comp)|(all=)/i) {
Line 1950  EOT Line 1996  EOT
             $dbh->disconnect;              $dbh->disconnect;
             exit;              exit;
   
         } else {          } 
           elsif (!$opt_z) {
                 my $QuestionNumber=0;                  my $QuestionNumber=0;
                 my $qnum;                  my $qnum;
                 if ($qnum=param('qnumber')){                  if ($qnum=param('qnumber')){
Line 1966  EOT Line 2013  EOT
                    $globaloutput.=&PrintTournament($dbh, $tour, param('answer'));                     $globaloutput.=&PrintTournament($dbh, $tour, param('answer'));
                 }                  }
         }          }
           else {
                     open TS, "timestamp";
                     my $d=$dbh->quote(<TS>);
                     close TS;
                     my ($sth) = $dbh->prepare("SELECT t1.Id, t1.FileName, t1.Type, 
                           count(t2.Id) 
                        FROM Tournaments as t1, Tournaments as t2
                        WHERE t1.CreatedAt>$d AND t2.ParentId=t1.Id GROUP BY t1.Id");
                     $sth->execute;
                     my ($Id,$fname,$type,$c);
                     while (($Id,$fname,$type,$c)=$sth->fetchrow,$Id) {
                        print "$fname\n";
                        $fname=~s/\.txt$//;
   print "  c=$c\n";       
                        if ($type=~/Т/ || $c<=1)
                        {
                          open FF, ">$realHTMLDIR$fname-q.html" or die "ERROR! - $HTMLDIR$fname-q.html\n";
                          my $o=$globaloutput;
                          $o.=&PrintTournament($dbh, $Id, 0);
                          $o.=&Bottom;
                          print FF $o;
                          close FF;
                          open FF, ">$realHTMLDIR$fname-a.html";
                          $o=$globaloutput;
                          $o.=&PrintTournament($dbh, $Id, 1);
                          $o.=&Bottom;
                          print FF $o;
                          close FF;
                        }
                        else {
                          open FF, ">$realHTMLDIR$fname.html" or die "ERROR! - $HTMLDIR$fname-q.html\n";
                          my $o=$globaloutput;
                          $o.=&PrintTournament($dbh, $Id, 0);
                          $o.=&Bottom;
                          print FF $o;
                          close FF;
   
                        }
                     }
           }
         if (!$text) {          if (!$text) {
                 $globaloutput.=&Include_virtual("../dimrub/db/footer.html");                  $globaloutput.=&Bottom;
                 $globaloutput.=p."<center><font size=-2>Обновление: ".&Include_virtual("../dimrub/db/date")."</center></font>";  
 print <<EEE  
   <SCRIPT LANGUAGE="JavaScript">  
 function toggle(e) {  
   if (e.style.display == "none") {  
      e.style.display="";  
   } else {  
      e.style.display = "none";  
  }  
 }  
 </SCRIPT>  
 EEE  
 ;  
                 print end_html;  
         }          }
         print $globaloutput;          if (!$opt_z){ 
         if (($qs!~ /(rand)|(sstr)|(comp)/i) && (length $qs<=255)) {            print $globaloutput;
             if (($qs!~ /(rand)|(sstr)|(comp)/i) && (length $qs<=255)) {
                 $globaloutput=  $dbh->quote($globaloutput);                  $globaloutput=  $dbh->quote($globaloutput);
                 $dbh->do("insert into hash (query,page) values (".                  $dbh->do("insert into hash (query,page) values (".
                 $dbh->quote($qs).                  $dbh->quote($qs).
                     ",$globaloutput)");                      ",$globaloutput)");
             }
         }          }
   
         $dbh->disconnect;          $dbh->disconnect;

Removed from v.1.99  
changed lines
  Added in v.1.100


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