#!/usr/bin/perl
=pod
=head1 NAME
register.cgi - a universal script for club regiter
=head1 SYNOPSIS
register.cgi?[I
END
print end_html;
exit 0;
###################################################
# Parsing included file
##################################################
sub Include_virtual {
my ($fn, $output) = (@_, '');
open F , $fn
or return; #die "Can't open the file $fn: $!\n";
while (
END
################################################
# NAVIGATION PANEL
################################################
my $self=url();
###############################################
# The navigation panel has three special lines
###############################################
print <
END
######################################################
# MAIN PANEL
######################################################
#
# First, we introduce ourselves
#
print <
ПРЕДСТАВЛЯЕТ
Реестр Клубов Интеллектуальных Игр
END
#
# Now check the parameters...
#
if (param('rid')) {
my $rid = param('rid');
$rid =~ s/(\d*)/$1/;
print ListRegions(dbh=>$dbh,rid=>$rid,
level=>param('level'),
clubs=>param('clubs'),
tag=>'h2',
self=>$self);
} elsif (param('cid')) {
my $cid = param('cid');
$cid =~ s/(\d*)/$1/;
print ClubInfo(dbh=>$dbh,cid=>$cid,
self=>$self);
} elsif (param('addclub')) {
print AddClub();
} elsif (param('Submit')) {
print SendLetter();
}
print <\n";
$sth=$args{'dbh'}->prepare("
SELECT rid FROM Regions WHERE $clause ORDER BY Name");
$sth->execute;
while (my ($kid)=$sth->fetchrow_array) {
$result .= ListRegions(
%args,'rid'=>$kid,
'level'=>$args{'level'}-1,
'tag'=>'dt');
}
}
}
return $result;
}
############################################################
# List the clubs of a given region
###########################################################
sub ListClubs {
my %args = @_;
my $sth;
if ($args{'cid'}) {
$sth = $args{'dbh'}->prepare("
SELECT Child FROM ClubClub WHERE Parent=$args{'cid'}");
} else {
$sth = $args{'dbh'}->prepare("
SELECT cid FROM ClubRegion WHERE rid=$args{'rid'}");
}
$sth->execute;
if (!$sth->rows) {
return "";
}
my $result;
if ($args{'cid'}) {
$result=<
\n
END
} else {
$result=<
\n";
}
#############################################################
# The longest subroutine in the list...
#############################################################
sub ClubInfo {
my %args = @_;
my $sth = $args{'dbh'}->prepare("
SELECT * FROM Clubs WHERE cid=$args{'cid'}");
$sth->execute;
if (!$sth->rows) {
return "";
}
my $result="";
my $club=$sth->fetchrow_hashref;
$result .= h2($club->{'Name'});
if (my $string=$club->{'Address'}) {
$string =~ s/\n/\n
END
}
my @clubs=();
while (my ($club)=$sth->fetchrow_array) {
push @clubs,"cid=$club";
}
my $clause = join(' OR ', @clubs);
$sth=$args{'dbh'}->prepare("
SELECT cid, Name FROM Clubs WHERE $clause ORDER BY Name");
$sth->execute;
while (my ($cid,$Name)=$sth->fetchrow_array) {
$result .= dt("$Name\n");
}
$result .= "
\n/g;
$result .= h3('Адрес')."\n".p($string);
}
if (my $string=$club->{'URL'}) {
$string = htmlize($string);
$result .= h3('Домашняя страничка')."\n".p($string);
}
if (my $string=$club->{'Phone'}) {
$result .= h3('Телефон')."\n".p($string);
}
if (my $string=$club->{'Fax'}) {
$result .= h3('Факс')."\n".p($string);
}
if (my $string=$club->{'Email'}) {
$string = htmlize($string,'mailto:');
$result .= h3('E-mail')."\n".p($string);
}
$result .= ListPeople(%args);
$result .= ListClubs(%args);
if (my $string=$club->{'DoB'}) {
$result .= h3('История создания клуба')."\n".p($string);
}
if (my $string=$club->{'Sponsor'}) {
$result .= h3('Спонсор')."\n".p($string);
}
if (my $string=$club->{'Meetings'}) {
$result .= h3('Форма деятельности клуба')."\n".p($string);
}
if (my $string=$club->{'AdultTeams'}) {
$result .= h3('Взрослые команды')."\n".p($string);
}
if (my $string=$club->{'KidTeams'}) {
$result .= h3('Детские команды')."\n".p($string);
}
if (my $string=$club->{'ForeignFests'}) {
$result .= h3('Иногородние фестивали, традиционно посещаемые командами клуба')."\n".p($string);
}
if (my $string=$club->{'Braglist'}) {
$result .= h3('Высшие достижения команд клуба')."\n".p($string);
}
if (my $string=$club->{'OwnFests'}) {
$result .= h3('Фестивали, организуемые клубом')."\n".p($string);
}
return $result;
}
##############################################################
# Adding a href=... The second optional argument may be
# 'mailto:'
##############################################################
sub htmlize {
my($string,$proto)=@_;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
my @entities = split /\s+/, $string;
my @hrefs=map {"$_"} @entities;
return join(", ",@hrefs);
}
##############################################################
# List the bosses....
##############################################################
sub ListPeople {
my %args = @_;
my $sth = $args{'dbh'}->prepare("
SELECT pid,Position FROM ClubPeople WHERE cid=$args{'cid'} ORDER BY Weight DESC");
$sth->execute;
if (!$sth->rows) {
return "";
}
my $result=h3('Руководство');
while (my($pid,$Position)=$sth->fetchrow_array) {
$result .= h4($Position);
$result .= ListPerson(%args,pid=>$pid);
}
return $result;
}
##############################################################
# Listing one person
#############################################################
sub ListPerson {
my %args=@_;
my $sth = $args{'dbh'}->prepare("
SELECT * FROM People WHERE pid=$args{'pid'}");
$sth->execute;
if (!$sth->rows) {
return "";
}
my @entries=();
my $person=$sth->fetchrow_hashref;
if (my $string = $person->{'Name'}) {
push @entries, $string;
}
if (my $string=$person->{'Address'}) {
push @entries, "Адрес: $string";
}
if (my $string=$person->{'URL'}) {
$string = htmlize($string);
push @entries, "Домашнаяя страничка: $string";
}
if (my $string=$person->{'Phone'}) {
push @entries, "Телефон: $string";
}
if (my $string=$person->{'Fax'}) {
push @entries, "Факс: $string";
}
if (my $string=$person->{'Email'}) {
$string = htmlize($string,'mailto:');
push @entries, "E-mail: $string";
}
return p(join('; ',@entries).".");
}
#########################################################
# Adding club
#########################################################
sub AddClub {
my $result=h2("Добавить клуб или изменить информацию о клубе");
$result .= <