#!/usr/bin/perl -w
#use strict;

use DBI ;
my $user = "postgres" ;
my $passwd = "DBSkeletor" ;

my $pdbh = DBI->connect("dbi:Pg:dbname=pgpr;host=mole", $user, $passwd);

$action = $pdbh->prepare("SELECT name, pgemail, office_phone, cell_phone, UPPER(continent) as con, region,
                         url FROM contacts WHERE verified ORDER BY continent, region, name;") ;
$action->execute() ;
$action->bind_columns( undef, \$name, \$pgemail, \$office, \$cell, \$continent, \$region, \$url );


open CONTACTS, ">/home/josh/Documents/oss/postgres/80_release/contact.html";
print CONTACTS "<!-- BEGIN page_title_block -->
Press Contacts
<!-- END page_title_block -->

<div id=\"pgPressContacts\">
<h1>Press Contacts</h1>

<p>Please refer to the list of country contacts below for press enquiries.</p>
<p>For general press enquiries in English, see <a href=\"#USA\">USA &amp; General Enquiries</a>.</p>\n";

my $last_region;
my $last_continent;

while ( $action->fetch ) {
    if ( $continent ne $last_continent ) {
        if ( defined $last_continent ) {
            print CONTACTS "</dl>\n";
        }
        print CONTACTS "\n<h2>$continent</h2>\n";
        print CONTACTS "<dl>\n";
        $last_continent = $continent;
    }
      
    if ( $region ne $last_region ) {
        if ( $region =~ "USA" ) {
            print CONTACTS "<a name=\"USA\"></a>";
        }
        print CONTACTS "<dt>$region</dt>\n";
        $last_region = $region;
    }
    print CONTACTS "<dd>$name\n";
    print CONTACTS "<br /><a href=\"mailto:$pgemail\">$pgemail</a>\n";
    $office and print CONTACTS "<br />Phone: $office\n";
    $cell and print CONTACTS "<br />Cell: $cell\n";
    $url and print CONTACTS "<br /><a href=\"$url\">$url</a>\n";
    print CONTACTS "</dd>\n";
}

print CONTACTS "</dl>\n</div>\n";

$pdbh->disconnect;
close CONTACTS;

exit(0);
