#! /usr/bin/perl 


$| = 1;

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

# Print a title and initial heading
print "<HTML>";
print "<Head><Title>Real Estate</Title></Head>";
print "<Body BGCOLOR =#FFFFFF>\n";

require listing_header;


print "<center>";

print "<table><tr><td>\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 "</center>";


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


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

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

  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}";
  }

# print "$input<P>";
# print "no. variables = $#input";


$PG = 'share';

# banner!


print "<P>\n";




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

my $cursor_s = $dbh->prepare("select s.unit_no, s.location, s.address,
		s.bed_bath, s.price, r.region
		from rent_share s, region r, login l
		where r.region_id = s.region_id
                and s.username = l.username
		and s.region_id = '$input{'REGION_ID'}'
		and s.rent_or_share = 'S'
		and l.acct_status = 'A'
		order by s.location, s.price ");

$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][5];

print "<center><h2><font face=Ariel>$region Timeshare</font></h2></center>";
     print "<TABLE BORDER=5 CELLPADDING=8 CELLSPACING=5>";
     print "<TH><font face=Ariel>Address</font></TH>";
     print "<TH><font face=Ariel>Bed-Bath</font></TH>";
     print "<TH><font face=Ariel>Price</font></TH>";

     for $i ( 0 .. $#{$table} ) {
	     if ($table->[$i][1] ne $old_location)
		{ print "<TR><TD colspan=6 align=center><font face=Ariel>$table->[$i][1]";
		  print "</font></TD></TR>\n";
		  $old_location = $table->[$i][1];
		}

             print "<TR>";

	     print "<td><a href=\"/cgi-bin/show_share_detail.cgi?entry=$table->[$i][0]\">";
	     print "<font face=Ariel>$table->[$i][2]</font></a></td>";

             for $j ( 3 .. 4 ) {
		     if ($j == 4)
			{ print "<TD align=right>"; }
		     else
                        { print "<TD>"; }

                     if ($table->[$i][$j]) {
                         print "<font face=Ariel>$table->[$i][$j]</font>\t";
                     }
                     else {
                         print " ";
                     }
                     print "</TD>\n"; 
             
             }
		

             print "</TR>\n";
     }
      
     my $rc1 = $cursor_s->finish;

     $region_id = $input{'REGION_ID'};

     print "</TABLE>\n";
     print "</font>\n";
      
     my $rc1 = $cursor_s->finish;

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


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



my $rc2 = $dbh->disconnect;
