--- register/prgsrc/register.cgi 2001/09/03 21:45:32 1.1 +++ register/prgsrc/register.cgi 2002/12/25 21:36:01 1.15 @@ -20,10 +20,783 @@ Boris Veytsman =head1 DATE -$Date: 2001/09/03 21:45:32 $ +$Date: 2002/12/25 21:36:01 $ =head1 REVISION -$Revision: 1.1 $ +$Revision: 1.15 $ -=cut \ No newline at end of file +=cut + + +################################################### +# Starting up +################################################### + + use strict; +use vars qw(%ENV); +use CGI qw(:standard); +use DBI; +use POSIX qw(locale_h); + +setlocale(LC_CTYPE,'russian'); +$ENV{'LANG'}='ru_RU.KOI8-R'; +my ($SENDMAIL) = "mail"; +my $TO = 'borisv@lk.net, igra@gorlovka.net, erudit@mail.od.ua'; +my $FROM = 'borisv@lk.net'; + +my $date='$Date: 2002/12/25 21:36:01 $'; +$date =~ s/[^ ]* ([^ ]*) .*/$1/; + + +my $dbh = DBI->connect("DBI:mysql:chgk", "piataev", "") + or do { + print h1("Временные проблемы") . "База данных временно не + работает. Заходите попозже."; + print &Include_virtual("../dimrub/db/reklama.html"); + print end_html; + die "Can't connect to DB chgk\n"; + }; + +print header(-charset=>'koi8-r'); + + +################################################## +# Printing top +################################################## +print start_html(-"title"=>'Register of Clubs', + -author=>'borisv@lk.net', + -background=>"../images/map.jpg"); +print &Include_virtual("../dimrub/db/reklama.html"); +print < + + +END + +################################################ +# NAVIGATION PANEL +################################################ + +my $self=url(); + + + +############################################### +# The navigation panel has three special lines +############################################### +print < +
  • Home
  • +
  • Все регионы
  • +
  • Все клубы
  • +
  • Добавить клуб
  • +
  • Кто есть кто
  • +END + +################################################# +# And the navpanel itself +################################################## + + print ListRegions(dbh=>$dbh,rid=>1,level=>1,tag=>'li', + self=>$self); + +print < +END + + + + 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('pid')) { + my $pid = param('pid'); + $pid =~ s/(\d*)/$1/; + print ListPerson(dbh=>$dbh,pid=>$pid, + self=>$self, + positions=>1, + displayperson=>1); + } elsif (param('whoiswho')) { + print PrintWhoIsWho(dbh=>$dbh, + self=>$self); + } elsif (param('addclub')) { + print AddClub(); + } elsif (param('Submit')) { + print SendLetter(); + } else { + print < +
    Все регионы
    +
    Все клубы
    +
    Добавить клуб или изменить сведения +о клубе
    +
    Кто есть кто
    + +

    +END +print &Include_virtual("../boris/register/regions.html"); +print < +END +} + +#################################################################### +# And the bottom of the page +################################################################### + my $sth=$dbh->prepare("select count(*) from Clubs"); + $sth->execute; + my ($count) = $sth->fetchrow_array; + $sth->finish; + + print "

    "; + print "Всего клубов: $count

    \n"; + + print < +
    +owl + +Boris Veytsman, $date +
    + + +END + + + print < + + +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 () { + if (//&Include_virtual($1)/e; + } + if (//`$1`/e; + } + $output .= $_; + } + return $output; +} + + + +############################################################# +# Listing the given region and optionally its children +############################################################# + + +sub ListRegions { + my %args = @_; + my $sth = $args{'dbh'}->prepare(" +SELECT Name FROM Regions WHERE RID=$args{'rid'}"); + $sth->execute; + if (!$sth->rows) { + return ""; + } + my ($name)=$sth->fetchrow_array; + $name="$name"; + my $result="<$args{'tag'}>$name\n"; + if ($args{'level'}>0) { # Print children + + # Frist, we print clubs + if ($args{'clubs'}) { + $result .= ListRegionURLs(%args); + $result .= ListClubs(%args); + } + $sth=$args{'dbh'}->prepare(" +SELECT Child FROM RegionRegion WHERE Parent=$args{'rid'}"); + $sth->execute; + if ($sth->rows) { + my @kids=(); + while (my ($kid)=$sth->fetchrow_array) { + push @kids,"rid=$kid"; + } + my $clause = join(' OR ', @kids); + $result .= "
      \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'=>'li'); + } + $result .= "
    \n"; + } + } + return $result; +} + +############################################################ +# List the URLs of a given region +########################################################### +sub ListRegionURLs { + my %args = @_; + my $sth; + $sth = $args{'dbh'}->prepare(" +SELECT URL FROM Regions WHERE rid=$args{'rid'} and NOT ISNULL(URL)"); + + $sth->execute; + + if (!$sth->rows) { + return ""; + } + + my $result; + + $result=<
    Странички:
    +
    \n +END + + while (my ($string)=$sth->fetchrow_array) { + $string=htmlize($string); + $result .= p($string); + } + $result .= "
    \n"; + return $result; +} + + +############################################################ +# List the clubs of a given region or a given association +########################################################### +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 +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 .= li("$Name\n"); + } + $result .= "
    \n"; +} + + +############################################################ +# List the association a given club belongs to +########################################################### +sub ListParents { + my %args = @_; + my $sth; + + $sth = $args{'dbh'}->prepare(" +SELECT Parent FROM ClubClub WHERE Child=$args{'cid'}"); + + $sth->execute; + + if (!$sth->rows) { + return ""; + } + + my $result; + + $result=<Коллективный член ассоциаций: +
    \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"; +} + +############################################################# +# 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/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 .= ListParents(%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 $result=""; + my @entries=(); + my $person=$sth->fetchrow_hashref; + if (my $string = $person->{'Name'}) { + if ($args{'displayperson'}) { + $result=h2($string); + } else { + 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"; + } + + $result.=p(join('; ',@entries)."."); + if ($args{'positions'}) { + my $sth=$dbh->prepare("SELECT cid,Position FROM ClubPeople +WHERE pid=$args{'pid'} ORDER by Weight"); + $sth->execute; + $result .= "
    \n"; + while (my ($cid,$Position)=$sth->fetchrow_array) { + my $sth1=$dbh->prepare("Select Name from Clubs where +cid=$cid"); + $sth1->execute; + my ($Name)=$sth1->fetchrow_array; + $sth1->finish; + $result .= "
    $Position, "; + $result .= "$Name
    \n"; + } + $sth->finish; + $result .= "
    \n"; + } + return $result; + +} + + +######################################################### +# Adding club +######################################################### +sub AddClub { + my $result=h2("Добавить клуб или изменить информацию о клубе"); + + + $result .= start_form; + + $result .= h3("Контактная информация"); + $result .= p("Адрес, телефон, email и т.д. ниже -- НЕ адреса руководства +клуба (их Вы введёте ниже), +а официальные адреса самого клуба. Если отдельного адреса, +телефона, и т.д. у клуба нет, просто оставьте +поля пустыми"); + $result .= table(Tr(td(["Название клуба", + textfield(-name=>'Name', + -size=>60)])), + Tr(td(["Официальный адрес клуба", + textarea(-name=>'Address', + -rows=>5, + -columns=>60)])), + Tr(td(["Страничка клуба", + textfield(-name=>'URL', + -size=>60)])), + Tr(td(["Телефон клуба", + textfield(-name=>'Phone', + -size=>60)])), + Tr(td(["Факс клуба", + textfield(-name=>'Fax', + -size=>60)])), + Tr(td(["E-mail клуба", + textfield(-name=>'Email', + -size=>60)])), + ); + $result .= h3("Руководство клуба"); + $result .= p("Адреса и телефоны ниже будут опубликованы. Если Вы не хотите +афишировать чьи-то адреса и телефоны, просто оставьте соответствующие поля +пустыми"); + $result .= "
      \n"; + for(my $i=1;$i<=5;$i++) { + $result .=li; + $result .= table( + + Tr(td(["Должность", + textfield(-name=>"Position$i", + -size=>50)])), + Tr(td(["ФИО", + textfield(-name=>"Name$i", + -size=>50)])), + Tr(td(["Адрес", + textarea(-name=>"Address$i", + -columns=>50, + -rows=>5)])), + Tr(td(["Телефон", + textfield(-name=>"Phone$i", + -size=>50)])), + Tr(td(["Факс", + textfield(-name=>"Fax$i", + -size=>50)])), + Tr(td(["Email", + textfield(-name=>"Email$i", + -size=>50)])), + Tr(td(["Домашняя страничка", + textfield(-name=>"URL$i", + -size=>50)])), + ); + } + $result .= "
    \n"; + $result .= h3("Ассоциации и объединения"); + $result .= table( + Tr(td(["Ассоциации, членом котрых является клуб", + textarea(-name=>'Parents', + -rows=>5, + -columns=>60)])), + Tr(td(["Для ассоциаций: коллективные члены ассоциации", + textarea(-name=>'Members', + -rows=>5, + -columns=>60)])), + ); + $result .= h3("Жизнь клуба"); + $result .= table( + Tr(td(["История создания клуба", + textarea(-name=>'DoB', + -rows=>5, + -columns=>60)])), + Tr(td(["Основной спонсор клуба", + textarea(-name=>'Sponsor', + -rows=>5, + -columns=>60)])), + Tr(td(["Основные формы деятельности клуба", + textarea(-name=>'Meetings', + -rows=>5, + -columns=>60)])), + Tr(td(["Взрослые команды", + textarea(-name=>'AdultTeams', + -rows=>5, + -columns=>60)])), + Tr(td(["Детские команды", + textarea(-name=>'KidTeams', + -rows=>5, + -columns=>60)])), + Tr(td(["Иногородние фестивали, на которые ездят команды клуба", + textarea(-name=>'ForeignFests', + -rows=>5, + -columns=>60)])), + Tr(td(["Высшие достижения команд клуба", + textarea(-name=>'Braglist', + -rows=>5, + -columns=>60)])), + Tr(td(["Фестивали, которые организовывает клуб", + textarea(-name=>'OwnFests', + -rows=>5, + -columns=>60)])), + ); + + $result .= h3("География клуба (для будущей карты)"); + $result .= table( + Tr(td(["Долгота", + textfield(-name=>"Longitude", + -size=> 60)])), + Tr(td(["Широта", + textfield(-name=>"Latitude", + -size=> 60)])), + ); + + $result .= h3("Дополнительные вопросы"); + $result .= table( + + Tr(td(["Что вам больше всего нравится в журнале 'Игра'?", + textarea(-name=>'IgraA', + -rows=>5, + -columns=>60)])), + Tr(td(["Что вам больше всего не нравится в журнале 'Игра'?", + textarea(-name=>'IgraB', + -rows=>5, + -columns=>60)])), + Tr(td(["Что бы вы хотели увидеть в журнале 'Игра' - то +чего нет в настоящее время?", + textarea(-name=>'IgraC', + -rows=>5, + -columns=>60)])), + ); + + $result .= h3("Кто регистрировал"); + $result .= table( + Tr(td(["Имя", + textfield(-name=>'RegistrarName', + -size=>60)])), + Tr(td(["Email", + textfield(-name=>'RegistrarEmail', + -size=>60)])), + ); + + $result .= p("Нажав кнопку 'Submit', Вы отправите Вашу регистрационную +карточку службе поддержки регистра. Пожалуйста, подождите несколько дней, пока +Ваша информация будет обработана и попадёт в регистр"); + $result .= submit(-name=>'Submit'); + $result .= end_form; + return $result; +} + +################################################################### +# Sending the letter with results +##################################################################### +sub SendLetter { + open(MAIL,"| $SENDMAIL -s 'Registracionnaya kartochka kluba' $TO"); + print MAIL <prepare("SELECT pid,Name FROM People ORDER BY Name"); + $sth->execute; + while (my($pid,$Name)=$sth->fetchrow_array) { + $result .= dd("$Name"); + $result .= "\n"; + } + $sth->finish; + $result .= "\n"; + return $result; +}