Diff for /db/prgsrc/db.cgi between versions 1.10 and 1.13

version 1.10, 2000/10/23 01:24:59 version 1.13, 2001/01/26 12:09:32
Line 10  my ($PWD) = `pwd`; Line 10  my ($PWD) = `pwd`;
 chomp $PWD;  chomp $PWD;
 my ($SRCPATH) = "$PWD/../dimrub/src";  my ($SRCPATH) = "$PWD/../dimrub/src";
 my ($ZIP) = "/home/piataev/bin/zip";  my ($ZIP) = "/home/piataev/bin/zip";
 my $DUMPFILE = "/tmp/dump.sql";  my $DUMPFILE = "/tmp/chgkdump";
 my ($SENDMAIL) = "/usr/sbin/sendmail";  my ($SENDMAIL) = "/usr/sbin/sendmail";
 my ($TMSECS) = 30*24*60*60;  my ($TMSECS) = 30*24*60*60;
 my (%RevMonths) =   my (%RevMonths) = 
Line 176  sub PrintSearch { Line 176  sub PrintSearch {
   
         $sstr =~ s/(.)/&NoCase($1)/ge;          $sstr =~ s/(.)/&NoCase($1)/ge;
   
         my(@sar) = split(/\s/, $sstr);          my(@sar) = split(' ', $sstr);
         for ($i = 0; $i <= $#Questions; $i++) {          for ($i = 0; $i <= $#Questions; $i++) {
                 $output = &PrintQuestion($dbh, $Questions[$i], 1, $i + 1, 1);                  $output = &PrintQuestion($dbh, $Questions[$i], 1, $i + 1, 1);
                 foreach  (@sar) {                  foreach  (@sar) {
Line 465  sub GetQNum { Line 465  sub GetQNum {
         $sth->execute;          $sth->execute;
         return ($sth->fetchrow)[0];          return ($sth->fetchrow)[0];
 }  }
   sub GetMaxQId {
           my ($dbh) = @_;
           my ($sth) = $dbh->prepare("SELECT MAX(QuestionId) FROM Questions");
           $sth->execute;
           return ($sth->fetchrow)[0];
   }
   
 # Returns Id's of 12 random questions  # Returns Id's of 12 random questions
 sub Get12Random {  sub Get12Random {
    my ($dbh, $type, $num) = @_;     my ($dbh, $type, $num) = @_;
         my ($i, @questions, $q, $t, $sth);          my ($i, @questions, $q, $t, $sth);
         my ($qnum) = &GetQNum($dbh);          my ($qnum) = &GetMaxQId($dbh);
         my (%chosen);          my (%chosen);
         srand;          srand;
                   
         for ($i = 0; $i < $num; $i++) {     for ($i = 0; $i < $num; $i++) {
                 do {         do {
                         $q = int(rand($qnum));             $q = int(rand($qnum));
                         $sth = $dbh->prepare("SELECT Type FROM Questions             $sth = $dbh->prepare("SELECT Type FROM Questions
                                 WHERE QuestionId=$q");                                  WHERE QuestionId=$q");
                         $sth->execute;             $sth->execute;
                         $t = ($sth->fetchrow)[0];             $t = ($sth->fetchrow)[0];
                 } until !$chosen{$q} && $type =~ /[$t]/;         } until !$chosen{$q} && $t && $type =~ /[$t]/;
                 $chosen{$q} = 'y';         $chosen{$q} = 'y';
                 push @questions, $q;         push @questions, $q;
         }     }
         return @questions;     return @questions;
 }  }
   
 sub Include_virtual {  sub Include_virtual {
Line 590  MAIN: Line 596  MAIN:
                     print end_html;                      print end_html;
                         die "Can't connect to DB chgk\n";                          die "Can't connect to DB chgk\n";
                 };                  };
         if (!param('comp') and !$text) {          if (!param('comp') and !param('sqldump') and !$text) {
            print header;             print header;
            print start_html(-"title"=>'Database of the questions',             print start_html(-"title"=>'Database of the questions',
                    -author=>'dimrub@icomverse.com',                     -author=>'dimrub@icomverse.com',
Line 651  EOT Line 657  EOT
                          -'Content-Type' => 'application/x-zip-compressed; name="dump.zip"',                           -'Content-Type' => 'application/x-zip-compressed; name="dump.zip"',
                          -'Content-Disposition' => 'attachment; filename="dump.zip"'                           -'Content-Disposition' => 'attachment; filename="dump.zip"'
                          );                           );
             if (! -f $DUMPFILE) {  
                 `mysqldump -u piataev chgk > $DUMPFILE`;  
             }  
             open F, "$ZIP -j - $DUMPFILE |";              open F, "$ZIP -j - $DUMPFILE |";
             print (<F>);              print (<F>);
             close F;              close F;

Removed from v.1.10  
changed lines
  Added in v.1.13


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