Diff for /db/prgsrc/updatedb.pl between versions 1.44 and 1.45

version 1.44, 2009/05/02 21:23:07 version 1.45, 2009/05/21 11:33:26
Line 59  my ($sth); Line 59  my ($sth);
   
 use DBI;  use DBI;
 use strict;  use strict;
 use Data::Dumper;  
 my $isunsorted=0;  my $isunsorted=0;
 sub UpdateParents {  sub UpdateParents {
     my ($dbh, $ParentId, $all_qnum,$CreatedAt) = @_;      my ($dbh, $ParentId, $all_qnum,$CreatedAt) = @_;
     if ($ParentId) {      if ($ParentId) {
         my ($sth1) = $dbh->prepare("SELECT QuestionsNum, ParentId, CreatedAt    my ($sth1) = $dbh->prepare("SELECT QuestionsNum, ParentId, CreatedAt
 FROM Tournaments WHERE Id = $ParentId");  FROM Tournaments WHERE Id = $ParentId");
         $sth1->execute;    $sth1->execute;
         my ($q, $p,$c) = ($sth1->fetchrow)[0, 1, 2];    my ($q, $p,$c) = ($sth1->fetchrow)[0, 1, 2];
         $c=$CreatedAt if $CreatedAt && ($CreatedAt gt $c);    $c=$CreatedAt if $CreatedAt && ($CreatedAt gt $c);
         my $qc=$dbh->quote($c);    my $qc=$dbh->quote($c);
         $dbh->do("UPDATE Tournaments SET     $dbh->do("UPDATE Tournaments SET 
                   QuestionsNum=$q + $all_qnum, CreatedAt=$qc                    QuestionsNum=$q + $all_qnum, CreatedAt=$qc
                   WHERE Id = $ParentId");                    WHERE Id = $ParentId");
         &UpdateParents($dbh, $p, $all_qnum,$c);    &UpdateParents($dbh, $p, $all_qnum,$c);
     }      }
 }  }
   
 sub parseDate {  
   my $value = shift;  
   my ($from, $to) = split /\s+\-+\s+/, $value;  
   $from =~ s/^(.*)-(.*)-(.*)$/$3-$2-$1/;  
   my($month) = $RevMonths{$2} || '01';  
   $from =~ s/-(.*)-/-$month-/;  
   $from =~ s/-00*$/-01/;  
   if ($to) {  
     $to =~ s/^(.*)-(.*)-(.*)$/$3-$2-$1/;  
     $month = $RevMonths{$2} || '01';      
     $to =~ s/-(.*)-/-$month-/;  
     $to =~ s/-00*$/-01/;  
   }  
   print Dumper($from, $to);  
   return ($from, $to);  
     
 }  
   
 sub getField {  sub getField {
     my($desc, $dbh) = @_;      my($desc, $dbh) = @_;
     my($key);      my($key);
     my($value) = ('');      my($value) = ('');
     while (<$desc>) {      while (<$desc>) {
         s/[    s/[ ]//g;
 ]//g;    if ($key && /^\s*$/) {
         if ($key && /^\s*$/) {        chomp $value;
             chomp $value;  
             $value =~ s/\s+$//;              $value =~ s/\s+$//;
             chomp $key;        chomp $key;
             if ($key eq 'Дата') {        if ($key eq 'Дата') {
               my ($from, $to) = parseDate($value);      $value =~ s/^(.*)-(.*)-(.*)$/$3-$2-$1/;
               $value = {'PlayedAt'=>$from, 'PlayedAt2'=>$to};      my($month) = $RevMonths{$2} || '01';
             }      $value =~ s/-(.*)-/-$month-/;
             if ($key eq 'Автор') {$value=~s/\.$//;}      $value =~ s/-00*$/-01/;
             return ($key, $value);        }
         }        if ($key eq 'Автор') {$value=~s/\.$//;}
         next if (/^\s*$/);        $value = $dbh->quote($value);
                 return ($key, $value);
         if (!$key && /^(.*?)[:\.]\s*(.*)$/s) {    }
             $key = $1;    next if (/^\s*$/);
             $value=$2;    
             next;    if (!$key && /^(.*?)[:\.]\s*(.*)$/s) {
         }        $key = $1;
         if ($key) {        $value=$2;
             $value .= $_;        next;
             next;    }
         }    if ($key) {
         $value .= $_;
         next;
     }
     }      }
     if ($key && $value) {      if ($key && $value) {
         $value=~s/\s+$//;          $value=~s/\s+$//;
               return ($key, $value);    $value = $dbh->quote($value);
     return ($key, $value);
     }      }
     return (0, 0);      return (0, 0);
 }  }
Line 137  sub SelectGroup { Line 122  sub SelectGroup {
     my ($sth, $ParentId, $i, @arr);      my ($sth, $ParentId, $i, @arr);
   
     if ($Interactive) {          if ($Interactive) {    
         $sth = $dbh->prepare("SELECT Id, Title FROM        $sth = $dbh->prepare("SELECT Id, Title FROM
                 Tournaments WHERE Type = 'Г'");      Tournaments WHERE Type = 'Г'");
         $sth->execute;        $sth->execute;
         print "Выберите группу для турнира:\n$TourName, файл $source\n\n";        print "Выберите группу для турнира:\n$TourName, файл $source\n\n";
         while (@arr=$sth->fetchrow) {        while (@arr=$sth->fetchrow) {
                 print "[$arr[0]] $arr[1]\n";      print "[$arr[0]] $arr[1]\n";
         }        }
         $ParentId = <STDIN>;        $ParentId = <STDIN>;
         chomp $ParentId;        chomp $ParentId;
         if (!$ParentId) {        if (!$ParentId) {
                 print "Пропускаем файл $source\n";      print "Пропускаем файл $source\n";
                 print STDERR "Файл $source отвергнут оператором\n";      print STDERR "Файл $source отвергнут оператором\n";
                 return (0,0);      return (0,0);
         } else {        } else {
                 print "Вы выбрали турнир: $ParentId\n";      print "Вы выбрали турнир: $ParentId\n";
                 $sth = $dbh->prepare("INSERT INTO Tournaments      $sth = $dbh->prepare("INSERT INTO Tournaments
                               (Title, Type, ParentId, FileName)               (Title, Type, ParentId, FileName) 
                                VALUES ($TourName, 'Ч', $ParentId,                VALUES ($TourName, 'Ч', $ParentId, 
                                        $source)");                                         $source)");
                 $sth->execute;      $sth->execute;
                 my $TournamentId = $sth->{mysql_insertid};      my $TournamentId = $sth->{mysql_insertid};
                 return ($TournamentId,$ParentId);      return ($TournamentId,$ParentId);
         }    }
     } else {      } else {
 # Теперь, если файла нет в дереве турниров, никаких вопросов не   # Теперь, если файла нет в дереве турниров, никаких вопросов не 
 # задаётся, а вместо этого он добавляется в группу 9999  # задаётся, а вместо этого он добавляется в группу 9999
                 $ParentId = 9999;      $ParentId = 9999;
                 my $tempsource=$source;      my $tempsource=$source;
                 my $temptname=$TourName;      my $temptname=$TourName;
                 $tempsource=~s/^\'(.*)\'$/$1/;                  $tempsource=~s/^\'(.*)\'$/$1/;
                 $temptname=~s/^\'(.*)\'$/$1/;                  $temptname=~s/^\'(.*)\'$/$1/;
                 print UNSORTED "$tempsource".((12 -length($source))x' ')."\t$temptname\n";        print UNSORTED "$tempsource".((12 -length($source))x' ')."\t$temptname\n";
                 $isunsorted=1;      $isunsorted=1;
                 $sth = $dbh->prepare("INSERT INTO Tournaments      $sth = $dbh->prepare("INSERT INTO Tournaments
                               (Title, Type, ParentId, FileName,CreatedAt)               (Title, Type, ParentId, FileName,CreatedAt) 
                                VALUES (".$dbh->quote($TourName).", 'Ч', $ParentId,                VALUES ($TourName, 'Ч', $ParentId, 
                                        $source,NOW())");                                         $source,NOW())");
                 $sth->execute;                  $sth->execute;
                 my $TournamentId = $sth->{mysql_insertid};      my $TournamentId = $sth->{mysql_insertid};
                 return ($TournamentId,$ParentId);      return ($TournamentId,$ParentId);
         }    }
                       
           
 }  }
   
 sub UpdateTournament {  sub UpdateTournament {
     my ($dbh, $TournamentId, $field, $value) = @_;      my ($dbh, $TournamentId, $field, $value) = @_;
     if (ref $value eq 'HASH') {      $dbh->do("UPDATE Tournaments SET $field=$value WHERE Id=$TournamentId")
             # It means that $value contains information about several fields    or die $dbh->errstr;
             foreach my $k(keys %$value) {  
               if ($value->{$k}) {  
           &UpdateTournament($dbh, $TournamentId, $k, $value->{$k});  
         }  
       }  
     } else {      
       my $v = $dbh->quote($value);  
       $dbh->do("UPDATE Tournaments SET $field=$v WHERE Id=$TournamentId")  
             or die $dbh->errstr;  
     }  
 }  }
   
 sub UpdateQuestion {  sub UpdateQuestion {
     my ($dbh, $QuestionId, $field, $value) = @_;      my ($dbh, $QuestionId, $field, $value) = @_;
           
     if (($field eq 'Type') && ($value eq "Д")) {      if (($field eq 'Type') && ($value eq "'Д'")) {
          $value = "ЧД";           $value = "'ЧД'";
     }      }
     my $v = $dbh->quote($value);      $dbh->do("UPDATE Questions SET $field=$value 
     $dbh->do("UPDATE Questions SET $field=$v      WHERE QuestionId=$QuestionId")
                 WHERE QuestionId=$QuestionId")    or die $dbh->errstr;
         or die $dbh->errstr;  
 }  }
   
 sub CheckFile {  sub CheckFile {
     my ($dbh, $source, $title) = @_;      my ($dbh, $source, $title) = @_;
     my $sth = $dbh->prepare("SELECT Id,ParentId,QuestionsNum FROM Tournaments      my $sth = $dbh->prepare("SELECT Id,ParentId,QuestionsNum FROM Tournaments
                              WHERE FileName=? AND Type='Ч'");                               WHERE FileName=$source AND Type='Ч'");
     $sth->execute($source) or die $dbh->errstr;      $sth->execute or die $dbh->errstr;
     my @arr = $sth->fetchrow;      my @arr = $sth->fetchrow;
     if (! scalar @arr) {      if (! scalar @arr) {
         return SelectGroup($dbh,$source,$title);    return SelectGroup($dbh,$source,$title);
     }      }
     my($Id,$ParentId,$QuestionsNum)=@arr;      my($Id,$ParentId,$QuestionsNum)=@arr;
     if($QuestionsNum) {       if($QuestionsNum) { 
         print "Файл $source с данными $title уже существует. ",    print "Файл $source с данными $title уже существует. ",
         "Заменить?[y/N]\n";    "Заменить?[y/N]\n";
         my $answer = <STDIN>;    my $answer = <STDIN>;
         if ($answer !~ /^[yY]/) {    if ($answer !~ /^[yY]/) {
             return (0,0);        return (0,0);
         } else {    } else {
             DeleteTournament($dbh,$Id,$ParentId,$QuestionsNum,0);        DeleteTournament($dbh,$Id,$ParentId,$QuestionsNum,0);
         }    }
     }       } 
     return($Id,$ParentId);            return($Id,$ParentId);  
 }  }
   
   
 sub DeleteTournament {  sub DeleteTournament {
     my ($dbh,$Id,$ParentId,$QuestionsNum,$DeleteMyself) = @_;      my ($dbh,$Id,$ParentId,$QuestionsNum,$DeleteMyself) = @_;
     if ($QuestionsNum) {      if ($QuestionsNum) {
         UpdateParents($dbh,$ParentId,-$QuestionsNum);    UpdateParents($dbh,$ParentId,-$QuestionsNum);
     }      }
     my (@Tours) = &GetTours($dbh, $Id);      my (@Tours) = &GetTours($dbh, $Id);
     foreach my $Tour (@Tours) {      foreach my $Tour (@Tours) {
         DeleteTournament($dbh,$Tour,$Id,0,1);    DeleteTournament($dbh,$Tour,$Id,0,1);
     }      }
     my $sth = $dbh->prepare("DELETE FROM Questions      my $sth = $dbh->prepare("DELETE FROM Questions
                              WHERE ParentId=$Id");                               WHERE ParentId=$Id");
     $sth->execute or die $dbh->errstr;      $sth->execute or die $dbh->errstr;
     if($DeleteMyself) {      if($DeleteMyself) {
         $sth = $dbh->prepare("DELETE FROM Tournaments    $sth = $dbh->prepare("DELETE FROM Tournaments
                              WHERE Id=$Id");                               WHERE Id=$Id");
         $sth->execute or die $dbh->errstr;    $sth->execute or die $dbh->errstr;
     }      }
 }  }
   
 sub GetTours {  sub GetTours {
         my ($dbh, $ParentId) = @_;    my ($dbh, $ParentId) = @_;
         my (@arr, @Tours);    my (@arr, @Tours);
   
         my ($sth) = $dbh->prepare("SELECT Id FROM Tournaments    my ($sth) = $dbh->prepare("SELECT Id FROM Tournaments
                 WHERE ParentId=$ParentId ORDER BY Id");      WHERE ParentId=$ParentId ORDER BY Id");
   
         $sth->execute;    $sth->execute;
   
         while (@arr = $sth->fetchrow) {    while (@arr = $sth->fetchrow) {
                 push @Tours, $arr[0];      push @Tours, $arr[0];
         }    }
   
         return @Tours;    return @Tours;
 }  }
   
 sub CreateTour {  sub CreateTour {
     my ($dbh,$title,$ParentId,$TourNum,$rh_defaults)=@_;         my ($dbh,$title,$ParentId,$TourNum,$rh_defaults)=@_;
     my $sth = $dbh->prepare("INSERT INTO Tournaments      my $sth = $dbh->prepare("INSERT INTO Tournaments
                              (Title, Type, ParentId, Number,CreatedAt)              (Title, Type, ParentId, Number,CreatedAt) 
                              VALUES (?, 'Т', $ParentId, $TourNum,NOW())");             VALUES ($title, 'Т', $ParentId, $TourNum,NOW())");
     $sth->execute($title);      $sth->execute;
     my $TourId = $sth->{mysql_insertid};      my $TourId = $sth->{mysql_insertid};
     while (my ($key,$value)=each %$rh_defaults) {      while (my ($key,$value)=each %$rh_defaults) {
             &UpdateTournament($dbh, $TourId, $key, $value);    &UpdateTournament($dbh, $TourId, $key, $value);
     }      }
     return $TourId;      return $TourId;
 }  }
                       
   
 MAIN:   MAIN: 
 {  {
Line 290  MAIN: Line 264  MAIN:
     # Inherited fields for a Tour or Tournament      # Inherited fields for a Tour or Tournament
     #      #
     my %TourFields = ('Копирайт' => 'Copyright',      my %TourFields = ('Копирайт' => 'Copyright',
                       'Инфо' => 'Info', 'URL' => 'URL',            'Инфо' => 'Info', 'URL' => 'URL',
                       'Ссылка' => 'URL', 'Редактор' => 'Editors',            'Ссылка' => 'URL', 'Редактор' => 'Editors',
                       'Обработан'=> 'EnteredBy',            'Обработан'=> 'EnteredBy',
                       'Дата'=>'PlayedAt', 'PlayedAt2'=>'PlayedAt2');            'Дата'=>'PlayedAt');
     #      #
     # Inherited fields for a Question      # Inherited fields for a Question
     #      #
     my %QuestionFields = ('Тип'=> 'Type', 'Вид'=> 'Type',       my %QuestionFields = ('Тип'=> 'Type', 'Вид'=> 'Type', 
                           'Автор' => 'Authors', 'Рейтинг'=>'Rating',           'Автор' => 'Authors', 'Рейтинг'=>'Rating', 
                           'Источник' => 'Sources',          'Источник' => 'Sources',
                           'Тема' => 'Topic');          'Тема' => 'Topic');
                                     
                                   
     my($source);      my($source);
           
     my($dbh) = DBI->connect("DBI:mysql:chgk", "piataev", "")      my($dbh) = DBI->connect("DBI:mysql:chgk", "piataev", "")
         or die "Can't connect to DB chgk\n";    or die "Can't connect to DB chgk\n";
 if ($dbh->get_info( 18 )=~/^(5|(4.1))/)  {$dbh->do("SET NAMES 'koi8r'");}  if ($dbh->get_info( 18 )=~/^(5|(4.1))/)  {$dbh->do("SET NAMES 'koi8r'");}
     my @sources;              my @sources;  
     open UNSORTED, ">$unsortedname";      open UNSORTED, ">$unsortedname";
     while ($source = shift) {      while ($source = shift) {
        push @sources,glob($source);         push @sources,glob($source);
     }      }
     foreach $source(@sources) {      foreach $source(@sources) {
         my $TourNum=0;    my $TourNum=0;
         my($PlayedAt) = '';    my($PlayedAt) = '';
         my($QuestionId, $TourId, $TournamentId, $ParentId) = (0, 0, 0, 0);    my($QuestionId, $TourId, $TournamentId, $ParentId) = (0, 0, 0, 0);
         my($tournum, $qnum, $all_qnum) = (0, 0, 0);    my($tournum, $qnum, $all_qnum) = (0, 0, 0);
         my (@d) = (localtime((stat($source))[9]))[5,4,3];    my (@d) = (localtime((stat($source))[9]))[5,4,3];
         $d[1]++;    $d[1]++;
         $d[1]=sprintf("%02d",$d[1]);    $d[1]=sprintf("%02d",$d[1]);
         $d[2]=sprintf("%02d",$d[2]);    $d[2]=sprintf("%02d",$d[2]);
         $d[0]+=1900;    $d[0]+=1900;
         my $UnquotedCreated=join('-', @d);    my $UnquotedCreated=join('-', @d);
         my ($CreatedAt) = $UnquotedCreated;    my ($CreatedAt) = $dbh->quote($UnquotedCreated);
   
         open INFD, $source     open INFD, $source 
             or die "Can't open input file: $!\n";        or die "Can't open input file: $!\n";
             
         $source =~ s/^.*\/([^\/]*)$/$1/;    $source =~ s/^.*\/([^\/]*)$/$1/;
         my $unquotedsource=$source;    my $unquotedsource=$source;
         $unquotedsource=~s/\.txt\s*$//;    $unquotedsource=~s/\.txt\s*$//;
         print STDERR "Файл: $source, дата: $CreatedAt ";    $source = $dbh->quote($source);
         my %TourDefaults=('CreatedAt'=>$CreatedAt);    print STDERR "Файл: $source, дата: $CreatedAt ";
         my %QuestionDefaults=();    my %TourDefaults=('CreatedAt'=>$CreatedAt);
         my %QuestionGlobalDefaults=('Type'=>'Ч');    my %QuestionDefaults=();
         while (($key, $value) = getField(\*INFD, $dbh)) {    my %QuestionGlobalDefaults=('Type'=>$dbh->quote('Ч'));
               while (($key, $value) = getField(\*INFD, $dbh)) {
     last if (!$key);        last if (!$key);
                     
     if ($key =~ /Мета/) {        if ($key =~ /Мета/) {
                   next;   # This is obsolete      next;   # This is obsolete
     }        }
     if ($key =~ /Чемпионат/ || $key =~ /Пакет/) {                       if ($key =~ /Чемпионат/ || $key =~ /Пакет/) {   
                   ($TournamentId, $ParentId) = CheckFile($dbh,$source,$value);      ($TournamentId, $ParentId) = CheckFile($dbh,$source,$value);
                   if (!$TournamentId)  {      if (!$TournamentId)  {
                     last;          last;
                   }           } 
       $sth = $dbh->prepare("UPDATE Tournaments SET
                   $sth = $dbh->prepare("UPDATE Tournaments SET                     Title=$value, Type='Ч', 
                                      Title=?, Type='Ч',                                        ParentId=$ParentId, 
                                      ParentId=?,                                        FileName=$source, 
                                      FileName=?,                                        CreatedAt=$CreatedAt
                                      CreatedAt=?  
                                      WHERE                                       WHERE
                                      Id=?");                                       Id=$TournamentId");
                   $sth->execute($value,$ParentId,$source,$CreatedAt,$TournamentId);      $sth->execute;
                   next;      next;
     }        }
     if ($key =~ /Тур/) {              if ($key =~ /Тур/) {
                   if ($TourId) {      if ($TourId) {
                         $dbh->do("UPDATE Tournaments SET QuestionsNum=$qnum  
                               WHERE Id=$TourId");            $dbh->do("UPDATE Tournaments SET QuestionsNum=$qnum
                   }              WHERE Id=$TourId");
                   $qnum = 0;      }
                   $TourNum++;      $qnum = 0;
                   $TourDefaults{'FileName'}= "$unquotedsource.$TourNum";      $TourNum++;
                                                       $TourDefaults{'FileName'}=$dbh->quote(
                                 "$unquotedsource.$TourNum"
                   $TourId=CreateTour($dbh,$value,$TournamentId,$TourNum,              );
                                    \%TourDefaults);      $TourId=CreateTour($dbh,$value,$TournamentId,$TourNum,
                   %QuestionDefaults=%QuestionGlobalDefaults;             \%TourDefaults);
                   $QuestionId=0;      %QuestionDefaults=%QuestionGlobalDefaults;
                   next;       $QuestionId=0;
     }      next; 
     if ($key =~ /Вопрос/) {        }
                   if (!$TourId) {        if ($key =~ /Вопрос/) {
                     $qnum = 0;      if (!$TourId) {
                     $TourNum++;               $qnum = 0;
                     $TourId=CreateTour($dbh,'1',$TournamentId,$TourNum,          $TourNum++;
                                        \%TourDefaults);          $TourId=CreateTour($dbh,'1',$TournamentId,$TourNum,
                  \%TourDefaults);
         %QuestionDefaults=%QuestionGlobalDefaults;          %QuestionDefaults=%QuestionGlobalDefaults;
                 }      }
                 my $query = "INSERT INTO Questions       my $query = "INSERT INTO Questions 
                              (ParentId, Number)              (ParentId, Number) 
                              VALUES ($TourId, $qnum+1)";             VALUES ($TourId, $qnum+1)";
                 $sth = $dbh->prepare($query);      $sth = $dbh->prepare($query);
                 $sth->execute or print $query;;      $sth->execute or print $query;;
                 $QuestionId = $sth->{mysql_insertid};      $QuestionId = $sth->{mysql_insertid};
                 &UpdateQuestion($dbh, $QuestionId, "Question", $value);      &UpdateQuestion($dbh, $QuestionId, "Question", $value);
                 while (my ($key,$value)=each %QuestionDefaults) {      while (my ($key,$value)=each %QuestionDefaults) {
                     &UpdateQuestion($dbh, $QuestionId, $key, $value);          &UpdateQuestion($dbh, $QuestionId, $key, $value);
                 }                     }   
                 $qnum++;      $qnum++;
                 $all_qnum++;      $all_qnum++;
                 next;      next;
     }        }
     if ($key =~ /Ответ/) {  
       &UpdateQuestion($dbh, $QuestionId, "Answer", $value);        if ($key =~ /Ответ/) {
                   next;      &UpdateQuestion($dbh, $QuestionId, "Answer", $value);
     }      next;
         }
     if ($key =~ /Зач[её]т/) {  
                   &UpdateQuestion($dbh, $QuestionId, "PassCriteria", $value);  
                   next;        if ($key =~ /Зач[её]т/) {
     }      &UpdateQuestion($dbh, $QuestionId, "PassCriteria", $value);
       next;
     if ($key =~ /Комментари/) {        }
                 &UpdateQuestion($dbh, $QuestionId, "Comments", $value);  
                 next;  
     }  
            if ($key =~ /Комментари/) {
     my @Fields = grep { $key =~ /$_/ } keys %QuestionFields;      &UpdateQuestion($dbh, $QuestionId, "Comments", $value);
       next;
     if (scalar @Fields) {        }
                   my $word = shift @Fields;  
                   my $field = $QuestionFields{$word};  
                   if ($QuestionId) {        
           &UpdateQuestion($dbh, $QuestionId, $field, $value);        my @Fields = grep { $key =~ /$_/ } keys %QuestionFields;
                   } elsif ($TourId) {  
                     $QuestionDefaults{$field}=$value;        if (scalar @Fields) {
                   } else {      my $word = shift @Fields;
                     $QuestionGlobalDefaults{$field}=$value;      my $field = $QuestionFields{$word};
                   }      if ($QuestionId) {
                   next;          &UpdateQuestion($dbh, $QuestionId, $field, $value);
     }      } elsif ($TourId) {
           $QuestionDefaults{$field}=$value;
     @Fields = grep { $key =~ /$_/ } keys %TourFields;      } else {
           $QuestionGlobalDefaults{$field}=$value;
     if (scalar @Fields) {      }
                 my $word = shift @Fields;      next;
                 my $field = $TourFields{$word};        }
                 my $updateId;  
                 if ($QuestionId) {        @Fields = grep { $key =~ /$_/ } keys %TourFields;
                     print STDERR "ОШИБКА: $key $value недопустимы после",  
                     " начала вопросов\n";        if (scalar @Fields) {
                 } else {      my $word = shift @Fields;
                   if ($TourId) {      my $field = $TourFields{$word};
                     $updateId = $TourId;      if ($QuestionId) {
         } else {          print STDERR "ОШИБКА: $key $value недопустимы после",
           $updateId = $TournamentId;          " начала вопросов\n";
           $TourDefaults{$field}=$value;      } elsif ($TourId) {
         }          &UpdateTournament($dbh, $TourId, $field, $value);
         &UpdateTournament($dbh, $updateId, $field, $value);      } else {
                 }          &UpdateTournament($dbh, $TournamentId, $field, $value);
                 next;          $TourDefaults{$field}=$value;
     }      }
       next;
                     }
             #  
             # If we are here, something got wrong!        
             #        #
             print STDERR "\nЯ НЕ ПОНИМАЮ: $key, $value!\n";        # If we are here, something got wrong!
                     #
         }        print STDERR "\nЯ НЕ ПОНИМАЮ: $key, $value!\n";
         $dbh->do("UPDATE Tournaments SET QuestionsNum=$qnum        
                         WHERE Id=$TourId");    }
         $dbh->do("UPDATE Tournaments SET QuestionsNum=$all_qnum    $dbh->do("UPDATE Tournaments SET QuestionsNum=$qnum
                         WHERE Id=$TournamentId");        WHERE Id=$TourId");
         &UpdateParents($dbh, $ParentId, $all_qnum,$UnquotedCreated);                $dbh->do("UPDATE Tournaments SET QuestionsNum=$all_qnum
         print STDERR "Всего вопросов: $all_qnum \n";        WHERE Id=$TournamentId");
     &UpdateParents($dbh, $ParentId, $all_qnum,$UnquotedCreated);    
     print STDERR "Всего вопросов: $all_qnum \n";
     }      }
     close UNSORTED;      close UNSORTED;
     unlink $unsortedname unless $isunsorted;      unlink $unsortedname unless $isunsorted;

Removed from v.1.44  
changed lines
  Added in v.1.45


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