#!/usr/bin/perl

require "config.idx";

print "Content-type: text/html\n\n";

$long = $ENV{'QUERY_STRING'};

if ($long) {
	@pairs=split(/&/,$long);
	foreach $item(@pairs) {
		($name,$content)=split (/=/,$item,2);
		$content=~tr/+/ /;
		$content=~ s/%(..)/pack("c",hex($1))/ge;
		if ($INPUT{$name}) { $INPUT{$name} = $INPUT{$name}.",".$content; }
		else { $INPUT{$name} = $content; }
	}
}
else {
	read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
	@pairs = split(/&/, $buffer);
	foreach $pair (@pairs) {
		($name, $value) = split(/=/, $pair);
		$value =~ tr/+/ /;
		$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
		if ($INPUT{$name}) { $INPUT{$name} = $INPUT{$name}.",".$value; }
		else { $INPUT{$name} = $value; }
	}
}

use DBI;
my $dsn = "DBI:mysql:database=$d_name;host=localhost";
my $dbh = DBI->connect($dsn, $d_username, $d_pass, {RaiseError => 1}) || die $DBI::errstr;

my $fasth = $dbh->prepare("SELECT access FROM users WHERE email = '$Cook{email}'");
$fasth->execute;
while (($access) = $fasth->fetchrow_array()) {
$gotaccess = $access;
}

unless ($gotaccess eq "officestaf" || $gotaccess eq "admin") {
print qq~
<head><title></title>
</head>
~;
&header;
print qq~
		<td valign="top" width="581">
		<img src="images/headers/admin.gif" height="33" width="581" alt="MY HOMES Account"><br>
		<br>
		<table border="0" cellpadding="5" cellspacing="0" width="100%">
		<tr>
		<td valign="top">
			<font face="Arial, Helvetica, sans-serif"><font size="3" color="#990000"><b>You Do Not Have Permission To Access This Area!</b></font><br><font size="2" color="black">You may login to your existing account or create a <b>FREE</b> MuncieMLS.com MyHomes account below.</font></font><br><br><br>
<table>
<tr>
<td valign=top width="50%">
<form method=post action=register.idx>
<font size="3" face="Arial"><b>If you are new to MuncieMLS.com you must create a MyHomes account.</b></font><br><br><font size="2">A MuncieMLS.com <b>MyHomes</b> account will enable you to save listings, save searches, view additions and updates to listings, and receive e-mail and wireless notifications when new listings meet your search criteria all for FREE!</font><br><br>
<input type=submit value="Create An Account Now">
</form>
</td>
<td valign="top" width="50%">
<table border="0" cellpadding="8" cellspacing="3" bgcolor="#CCCCCC">
<tr>
	<form method=post action=myhomes.idx>
	<input type=hidden name=action value=login>
<td valign="top" bgcolor="white">
<center><font size="2" face="Arial" color="#000066"><b>ALREADY HAVE A<br><b>MYHOMES</b> ACCOUNT?</b></font><br><font size="2" face="Arial">You may login below</font><br><br></center>
	<table border="0" cellpadding="2" cellspacing="0" width="100%">
	<tr>
	<td align="right">E-Mail Address:</td><td><input type="text" name=Email></td>
	</tr><tr>
	<td align="right">Password:</td><td><input type="password" name=Password></td>
	</tr>
	</table>	
	<center><a href="lostpassword.idx">Lost Your Password? Click Here</a><br><br><input type="submit" value="Login Now"></center>
</td>
</form></tr>

</table>

</td>
</tr>
</table>

		</td>
		</tr>
		</table>
</td>

~;
&footer;
exit 0;
}

if ($INPUT{action} eq "directory_view") { &directory_view; }
elsif ($INPUT{action} eq "directory_edit") { &directory_edit; }
elsif ($INPUT{action} eq "listnew_view") { &listnew_view; }
elsif ($INPUT{action} eq "listnew_save") { &listnew_save; }
else { &main; }

sub main {

use DBI;
my $dsn = "DBI:mysql:database=$d_name;host=localhost";
my $dbh = DBI->connect($dsn, $d_username, $d_pass, {RaiseError => 1}) || die $DBI::errstr;

my $abasth = $dbh->prepare("select company from trans_boarddirectory GROUP BY company ASC");
$abasth->execute;

while (($company) = $abasth->fetchrow_array()) {
$buildcompany .= "<option value=\"$company\">$company</option>";
}

print qq~
<html>
<head>
<title>Company Directory -- ERA Eagle Real Estate MuncieMLS.com</title>
~;

&header;


print qq~

<td valign="top" width="581">
<img src="images/headers/transaction_manager.gif" height="33" width="581" alt="My Transaction Manager"><br><br>
<img src="images/trans_sys/company_directory.gif" alt="ERA Eagle Company Directory"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>view contacts and information the directory</b><br><br>
<br>
</td>
~;
&footer;
}
