version 1.6, 2000/10/18 02:01:19
|
version 1.10, 2000/10/20 01:45:46
|
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]*$/ && !$key) { |
$key = $1; |
$key = $1; |
next; |
next; |
} |
} |
Line 95 sub getField {
|
Line 95 sub getField {
|
} |
} |
|
|
sub SelectGroup { |
sub SelectGroup { |
my ($dbh, $TourName, $sth, $ParentId, $i, @arr) = @_; |
my ($dbh, $source, $TourName) = @_; |
|
my ($sth, $ParentId, $i, @arr); |
|
|
$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\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>; |
print "Вы выбрали турнир: $ParentId\n"; |
chomp $ParentId; |
return $ParentId; |
if (!$ParentId) { |
|
print "Пропускаем файл $source\n"; |
|
print STDERR "Файл $source отвергнут оператором\n"; |
|
return (0,0); |
|
} else { |
|
print "Вы выбрали турнир: $ParentId\n"; |
|
$sth = $dbh->prepare("INSERT INTO Tournaments |
|
(Title, Type, ParentId, FileName) |
|
VALUES ($TourName, 'Ч', $ParentId, |
|
$source)"); |
|
$sth->execute; |
|
my $TournamentId = $sth->{mysql_insertid}; |
|
return ($TournamentId,$ParentId); |
|
} |
|
|
|
|
} |
} |
|
|
sub UpdateTournament { |
sub UpdateTournament { |
Line 122 sub UpdateQuestion {
|
Line 138 sub UpdateQuestion {
|
or die $dbh->errstr; |
or die $dbh->errstr; |
} |
} |
|
|
|
sub CheckFile { |
|
my ($dbh, $source, $title) = @_; |
|
my $sth = $dbh->prepare("SELECT Id,ParentId,QuestionsNum FROM Tournaments |
|
WHERE FileName=$source AND Type='Ч'"); |
|
$sth->execute or die $dbh->errstr; |
|
my @arr = $sth->fetchrow; |
|
if (! scalar @arr) { |
|
return SelectGroup($dbh,$source,$title); |
|
} |
|
my($Id,$ParentId,$QuestionsNum)=@arr; |
|
if($QuestionsNum) { |
|
print "Файл $source с данными $title уже существует. ", |
|
"Заменить?[y/N]\n"; |
|
my $answer = <STDIN>; |
|
if ($answer !~ /^[yY]/) { |
|
return (0,0); |
|
} else { |
|
DeleteTournament($dbh,$Id,$ParentId,$QuestionsNum,0); |
|
} |
|
} |
|
return($Id,$ParentId); |
|
} |
|
|
|
|
|
sub DeleteTournament { |
|
my ($dbh,$Id,$ParentId,$QuestionsNum,$DeleteMyself) = @_; |
|
if ($QuestionsNum) { |
|
UpdateParents($dbh,$ParentId,-$QuestionsNum); |
|
} |
|
my (@Tours) = &GetTours($dbh, $Id); |
|
foreach my $Tour (@Tours) { |
|
DeleteTournament($dbh,$Tour,1); |
|
} |
|
my $sth = $dbh->prepare("DELETE FROM Questions |
|
WHERE ParentId=$Id"); |
|
$sth->execute or die $dbh->errstr; |
|
if($DeleteMyself) { |
|
$sth = $dbh->prepare("DELETE FROM Tournaments |
|
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 146 MAIN:
|
Line 222 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 =~ /Мета/) { |
$value =~ s/[^\d]*//g; |
next; # This is obsolete |
$sth = $dbh->prepare("SELECT Id FROM Tournaments WHERE |
|
MetaId=$value"); |
|
$sth->execute |
|
or die "Invalid Meta field: $value"; |
|
$ParentId = ($sth->fetchrow)[0]; |
|
next; |
|
} |
} |
if ($key =~ /Чемпионат/ || $key =~ /Пакет/) { |
if ($key =~ /Чемпионат/ || $key =~ /Пакет/) { |
$ParentId = &SelectGroup($dbh, $value) |
($TournamentId, $ParentId) = CheckFile($dbh,$source,$value); |
unless ($ParentId); |
if (!$TournamentId) { |
$sth = $dbh->prepare("INSERT INTO Tournaments |
last; |
(Title, Type, ParentId, FileName, |
} |
CreatedAt) |
$sth = $dbh->prepare("UPDATE Tournaments SET |
VALUES ($value, 'Ч', $ParentId, |
Title=$value, Type='Ч', |
$source, $CreatedAt)"); |
ParentId=$ParentId, |
|
FileName=$source, |
|
CreatedAt=$CreatedAt |
|
WHERE |
|
Id=$TournamentId"); |
$sth->execute; |
$sth->execute; |
$TournamentId = $sth->{mysql_insertid}; |
|
next; |
next; |
} |
} |
if ($key =~ /Тур/) { |
if ($key =~ /Тур/) { |
Line 186 MAIN:
|
Line 258 MAIN:
|
$TourId = $sth->{mysql_insertid}; |
$TourId = $sth->{mysql_insertid}; |
next; |
next; |
} |
} |
if ($key =~ /Вид/) { |
if ($key =~ /Вид/ || $key =~ /Тип/) { |
$qtype = $value; |
$qtype = $value; |
$qtype =~ s/\'//g; |
$qtype =~ s/\'//g; |
next; |
next; |
Line 208 MAIN:
|
Line 280 MAIN:
|
&UpdateQuestion($dbh, $QuestionId, "Answer", $value); |
&UpdateQuestion($dbh, $QuestionId, "Answer", $value); |
next; |
next; |
} |
} |
|
|
|
if ($key =~ /Рейтинг/) { |
|
&UpdateQuestion($dbh, $QuestionId, "Rating", $value); |
|
next; |
|
} |
|
|
|
|
if ($key =~ /Автор/) { |
if ($key =~ /Автор/) { |
Line 228 MAIN:
|
Line 305 MAIN:
|
} |
} |
|
|
|
|
if ($key =~ /URL/ || key =~ /Ссылка/) { |
if ($key =~ /URL/ || $key =~ /Ссылка/) { |
&UpdateTournament($dbh, $TournamentId, "URL", $value); |
&UpdateTournament($dbh, $TournamentId, "URL", $value); |
next; |
next; |
} |
} |