#! /usr/bin/perl 


$| = 1;

# Print out a content-type for HTTP/1.0 compatibility
print "Content-type:text/html\n\n";

  # Read in text
  $input = $ENV{'QUERY_STRING'};

  @input = split(/&/,$input);

#  print "$ENV{'QUERY_STRING'} <P>";

  foreach $i (0 .. $#input) {
    # Convert plus's to spaces
    $input[$i] =~ s/\+/ /g;

    # Convert %XX from hex numbers to alphanumeric
    $input[$i] =~ s/%(..)/pack("c",hex($1))/ge;

    # Split into key and value.
    $loc = index($input[$i],"=");
    $key = uc substr($input[$i],0,$loc);     ### uc function added by E.T.
    $val = substr($input[$i],$loc+1);
    $input{$key} .= '\0' if (defined($input{$key})); # \0 is the multiple separator
    $input{$key} .= $val;
#    print "key = $key, $input{$key}<BR>";
  }

#print "$input<P>";
#print "no. variables = $#input";
$region_id = $input{'R_ID'};

# Print a title and initial heading
print "<HTML>";
print "<Head><Title>Company Information</Title>";

use DBI;
use Config;
use Cwd;
#use strict;

my $dbh = DBI->connect('DBI:mysql:computercar', 'rclee', '0419') || 
	die ("can't connect to the database: $!");

$category = $input{'CAT'}; 

my $cursor_k = $dbh->prepare("select keywords
			      from keywords
			      where category = \"$category\" ");
$cursor_k->execute or die "can't execute the query";

my $table_k = $cursor_k->fetchall_arrayref or die "$cursor_k->errstr\n";
$keywords = $table_k->[0][0];
 
print "<meta name=\"keywords\" content=\"$keywords\">\n";
print "</Head>";
print "<Body BGCOLOR =#FFFFFF>\n";


#print "<center><img src=\"/images/header1.gif\" border=0 ";
#print "alt=\"Buy Resort Properties\"><br><img src=\"/images/home-nav.gif\" ";
#print "border=0 usemap=\"#brpmap\" alt=\"Buy Resort Properties\"><br>";


print "<font face=arial, helvetica color=blue size=6><b>Buy Resort Properties</font>";
print "<font color=red size=6 face=arial, helvetica>.com</b></font>";
print "<p><font face=arial size=3>";
print "<a href=http://www.buyresortproperties.com/index.html>Real Estate</a> | ";
print "<a href=http://www.buyresortproperties.com/rental_index.html>Rental Property</a> | ";
print "<a href=http://www.buyresortproperties.com/share_index.html>Timeshare</a> | ";
print "<a href=http://www.buyresortproperties.com/rv_index.html>Campgrounds & RVs</a> | ";
print "<a href=http://www.buyresortproperties.com/store/>BRP Shopping Mall</a><p>";


my $cursor_s = $dbh->prepare("select distinct c.url, c.company_id
		from company c, region r
		where c.category = \"$category\"
		and r.region_id = \"$input{'R_ID'}\" 
		and (r.region_id = c.region_id or c.region_id = 1)
		order by c.company_id");

     $cursor_s->execute or die "can't execute the query";

     my $table = $cursor_s->fetchall_arrayref or die "$cursor_s->errstr\n";
     my($i, $j);

     $region = $table->[0][8];
     print "<h2>$input{'CAT'}</h2><P>"; 

     if ($input{'CAT'} eq "Realtors  Directory")
        { print "<table width=600><tr><td>"; }

     for $i ( 0 .. $#{$table} ) {

     
	if ($table->[$i][0])
	  {print "$table->[$i][0]<P>"; }

    }
     if ($input{'CAT'} eq "Realtors Directory")
        { print "</td></tr></table>\n";}
     my $rc1 = $cursor_s->finish;

my $rc2 = $dbh->disconnect;

print "</td></tr></table>\n";



print "</body>\n</html>\n";




