version 1.7, 2000/10/19 03:05:39
|
version 1.12, 2000/10/22 02:25:02
|
Line 64 sub getField {
|
Line 64 sub getField {
|
my($key); |
my($key); |
my($value) = (''); |
my($value) = (''); |
while (<$desc>) { |
while (<$desc>) { |
s/
//; |
s/[
]//g; |
if ($key && /^\s*$/) { |
if ($key && /^\s*$/) { |
chomp $value; |
chomp $value; |
chomp $key; |
chomp $key; |
if ($key eq 'Дата') { |
if ($key eq 'Дата') { |
$value =~ s/^(.*)-(.*)-(.*)$/$3-$2-$1/; |
$value =~ s/^(.*)-(.*)-(.*)$/$3-$2-$1/; |
my($month) = $RevMonths{$2}; |
my($month) = $RevMonths{$2} || '000'; |
$value =~ s/$2/$month/; |
$value =~ s/$2/$month/; |
} |
} |
$value = $dbh->quote($value); |
$value = $dbh->quote($value); |
Line 78 sub getField {
|
Line 78 sub getField {
|
} |
} |
next if (/^\s*$/); |
next if (/^\s*$/); |
|
|
if (/^(.*)[:\.]\s*$/ && !$key) { |
if (s/^(.*?)[:\.]\s*// && !$key) { |
$key = $1; |
$key = $1; |
|
$value=$_; |
next; |
next; |
} |
} |
if ($key) { |
if ($key) { |
Line 106 sub SelectGroup {
|
Line 107 sub SelectGroup {
|
print "[$arr[0]] $arr[1]\n"; |
print "[$arr[0]] $arr[1]\n"; |
} |
} |
$ParentId = <STDIN>; |
$ParentId = <STDIN>; |
|
chomp $ParentId; |
if (!$ParentId) { |
if (!$ParentId) { |
print "Пропускаем файл $source\n"; |
print "Пропускаем файл $source\n"; |
print STDERR "Файл $source отвергнут оператором\n"; |
print STDERR "Файл $source отвергнут оператором\n"; |
Line 115 sub SelectGroup {
|
Line 117 sub SelectGroup {
|
$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); |
Line 138 sub UpdateQuestion {
|
Line 140 sub UpdateQuestion {
|
} |
} |
|
|
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=$source AND Type='Ч'"); |
WHERE FileName=$source AND Type='Ч'"); |
$sth->execute or die $dbh->errstr; |
$sth->execute or die $dbh->errstr; |
Line 147 sub CheckFile {
|
Line 149 sub CheckFile {
|
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,0); |
DeleteTournament($dbh,$Id,$ParentId,$QuestionsNum,0); |
} |
} |
} |
} |
return($Id,$ParentId); |
return($Id,$ParentId); |
Line 162 sub CheckFile {
|
Line 164 sub CheckFile {
|
|
|
|
|
sub DeleteTournament { |
sub DeleteTournament { |
my ($dbh,$Id,$DeleteMyself) = @_; |
my ($dbh,$Id,$ParentId,$QuestionsNum,$DeleteMyself) = @_; |
|
if ($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,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"); |
Line 173 sub DeleteTournament {
|
Line 178 sub DeleteTournament {
|
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; |
} |
} |
} |
} |
|
|
|
sub GetTours { |
|
my ($dbh, $ParentId) = @_; |
|
my (@arr, @Tours); |
|
|
|
my ($sth) = $dbh->prepare("SELECT Id FROM Tournaments |
|
WHERE ParentId=$ParentId ORDER BY Id"); |
|
|
|
$sth->execute; |
|
|
|
while (@arr = $sth->fetchrow) { |
|
push @Tours, $arr[0]; |
|
} |
|
|
|
return @Tours; |
|
} |
|
|
|
|
MAIN: |
MAIN: |
{ |
{ |
my($key, $value, $addition); |
my($key, $value, $addition); |
Line 199 MAIN:
|
Line 223 MAIN:
|
$source =~ s/^.*\/([^\/]*)$/$1/; |
$source =~ s/^.*\/([^\/]*)$/$1/; |
$source = $dbh->quote($source); |
$source = $dbh->quote($source); |
print STDERR "Файл: $source, дата: $CreatedAt "; |
print STDERR "Файл: $source, дата: $CreatedAt "; |
|
|
while (($key, $value) = getField(\*INFD, $dbh)) { |
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=$value, Type='Ч', |
ParentId=$ParentId, |
ParentId=$ParentId, |
FileName=$source, |
FileName=$source, |
CreatedAt=$CreatedAt |
CreatedAt=$CreatedAt |
Line 227 MAIN:
|
Line 250 MAIN:
|
WHERE Id=$TourId"); |
WHERE Id=$TourId"); |
} |
} |
$qnum = 0; |
$qnum = 0; |
$qtype = 'Ч'; |
|
$sth = $dbh->prepare("INSERT INTO Tournaments |
$sth = $dbh->prepare("INSERT INTO Tournaments |
(Title, Type, ParentId, CreatedAt) |
(Title, Type, ParentId, CreatedAt) |
VALUES ($value, 'Т', $TournamentId, |
VALUES ($value, 'Т', $TournamentId, |
Line 242 MAIN:
|
Line 264 MAIN:
|
next; |
next; |
} |
} |
if ($key =~ /Вопрос/) { |
if ($key =~ /Вопрос/) { |
|
if (!$TourId) { |
|
$qnum = 0; |
|
$sth = $dbh->prepare("INSERT INTO Tournaments |
|
(Title, Type, ParentId, CreatedAt) |
|
VALUES ('1', 'Т', $TournamentId, |
|
$CreatedAt)"); |
|
$sth->execute; |
|
$TourId = $sth->{mysql_insertid}; |
|
} |
my $query = "INSERT INTO Questions |
my $query = "INSERT INTO Questions |
(ParentId, Number, Type) |
(ParentId, Number, Type) |
VALUES ($TourId, $qnum+1, \'$qtype\')"; |
VALUES ($TourId, $qnum+1, \'$qtype\')"; |