#!/usr/bin/perl

require "config.idx";

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


&checklogin;

if ($INPUT{action} eq "deletesearch") { &deletesearch; }
elsif ($INPUT{action} eq "login") { &login; }
elsif ($INPUT{action} eq "logoff") { &logout; }
else { &main; }

sub login {

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 userid from users where email = '$INPUT{Email}' AND password = PASSWORD('$INPUT{Password}') AND agentid != ''");
$fasth->execute;


while (($uid) = $fasth->fetchrow_array()) {
$userid = $uid;

my $uasth = $dbh->do("update users set lastlogin = now() where userid = '$userid'");
my $pasth = $dbh->prepare("select DATE_FORMAT(DATE_ADD(NOW(), INTERVAL 1 DAY), '%a\, %d\-%b\-%Y %T')");
$pasth->execute;

while (($nextmonthsdate) = $pasth->fetchrow_array()) {
$setcookiedate = "$nextmonthsdate";
}


print "Set-cookie: userid=$userid\|$INPUT{Email}; expires=$setcookiedate GMT\n";
print "Content-type: text/html\n\n";

print qq~

<html><head><title>Loading Your MY HOMES Data...</title>
<meta http-equiv="Refresh" content="3; URL=$theurl">
</head>
<body>
<br><br><br><br><br>
<center>
<table border="0" cellpadding="12" cellspacing="1" bgcolor="navy">
<tr>
<td valign="middle" bgcolor="white">
<br>
<center>
<img src="images/StatusBar4.gif" alt="Loading"><br>
<img src="images/nowloading.gif"><br>
</center>
</td>
</tr>
</table>
</center>
~;

$dbh->disconnect;

exit 0;

}

print "Set-cookie: userid=\n";
print "Content-type: text/html\n\n";

print qq~
<html><head><title>Connect.EagleSold.com</title>


~;

&header;

print qq~

		<td valign="top" width="581">
		<br>
		<table border="0" cellpadding="5" cellspacing="0" width="100%">
		<tr>
		<td valign="top">
		<font face="Arial, Helvetica, sans-serif"><font size="4" color="Red">Sorry, An Authorization Error Has Occured....</b></font></font><br><br>
<center>
<table border="0" cellspacing="1" cellpadding="3" bgcolor="#CC0000">
	<form method=post action=index.idx>
	<input type=hidden name=action value=login>
<tr>
<td valign="top" colspan="2" bgcolor="white"><center><font size="3" color="maroon" face="Arial"><b>Connect.EagleSold.com</b></font><br><b><i>Access Center</i></b></center></td>
</tr>
<tr>
<td valign="middle" align="right" bgcolor="white"><b>Login</b></td>
<td valign="middle" bgcolor="white"><input type="text" name="Email" value="$INPUT{Email}" size="30" class="form"></td>
</tr>
<tr>
<td valign="middle" align="right" bgcolor="white"><b>Password</b></td>
<td valign="middle" bgcolor="white"><input type="password" name="Password" size="30" class="form"></td>
</tr>
<tr>
<td valign="top">&nbsp;</td>
<td valign="top"><input type="submit" value="Login" class="form"><br></td>
</tr>
</table>
</center>
		</td>
		</tr>
		</table>
		</td>




~;


&footer;

}

sub logout {


print "Set-cookie: userid=\n";
print "Content-type: text/html\n\n";

print qq~


<html><head><title>Logging out...</title>
<meta http-equiv="Refresh" content="2; URL=index.idx">
</head>
<body>
<br><br><br><br><br>
<center>
<table border="0" cellpadding="12" cellspacing="1" bgcolor="navy">
<tr>
<td valign="middle" bgcolor="white">
<br>
<center><font face=Arial size=3>
<img src="images/StatusBar4.gif" alt="Loading"><br>
You Are Now Being Logged out....
</center>
</td>
</tr>
</table>
</center>
~;
}

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;

print qq~
<html>
<head>
<title>My Eagle prospect Manager -- Eagle Real Estate, Inc. - Connect.EagleSold.com</title>
<script language="JavScript">
function submit()
{
	 document.changestatus.submit();
}
</script>
~;

&header;


print qq~
<td valign="top" width="581">
<img src="images/headers/intranet.gif" height="33" width="581" alt="Eagle Intranet"><br><br>
~;

print qq~
<br>
<table border="0" cellpadding="3" cellspacing="1" width="100%">
<tr>
<td valign="top" width="80%">
<font color="green" size="4"><b><u>Eagle Intranet System Changes/Updates Log</u></b></font><br>
	Over the next couple of months we are going to making changes to our technologies at Eagle.   All new features and changes will be posted below as the changes occur.<br><br>
	<table border="0" cellpadding="2" cellspacing="1" width="100%" bgcolor="navy">
		<tr>
			<td valign="top" bgcolor="navy"><b><font color="white">DATE</font></b></td>
			<td valign="top" bgcolor="navy"><b><font color="white">AREA</font></b></td>
			<td valign="top" bgcolor="navy">
				<b><font color="white">NOTES / DESCRIPTION</font></b>
			</td>
		</tr>
		<tr>
			<td valign="top" bgcolor="white"><b>Feb. 2nd, 2007</b></td>
			<td valign="top" bgcolor="white"><b>Transaction System Showing Tab</b></td>
			<td valign="top" bgcolor="white">
				<i>	The Showing Information Box in the Transaction System now correctly shows wether feedback was received or not.   When you hit details you can read the feedback.</i><br>
			</td>
		</tr>
		<tr>
			<td valign="top" bgcolor="white"><b>Feb. 2nd, 2007</b></td>
			<td valign="top" bgcolor="white"><b>Showing & Feedback System</b></td>
			<td valign="top" bgcolor="white">
				<i>	We have redesigned our feedback system.   We now only ask for "Comments" in our requests.   Also our system can send a total of 4 requests for feedback before giving up!</i><br>
			</td>
		</tr>
		<tr>
			<td valign="top" bgcolor="white"><b>Feb. 1st, 2007</b></td>
			<td valign="top" bgcolor="white"><b>Prospecting System</b></td>
			<td valign="top" bgcolor="white">
				<i>	You can now choose "Delete" as an option to delete your entire prospect file including saved documents and notes.</i><br>
			</td>
		</tr>
		<tr>
			<td valign="top" bgcolor="white"><b>Jan. 31st, 2007</b></td>
			<td valign="top" bgcolor="white"><b>MuncieMLS Leads</b></td>
			<td valign="top" bgcolor="white">
				<i>	We are in the process of moving all MuncieMLS leads and tools into this site.   You can click on the "Web Clients/Leads" link to the left under navigation to view your leads from now on.   In the next couple weeks we are going to completely phase out viewing your web clients and leads from the MuncieMLS website.</i><br>
			</td>
		</tr>
	</table>
</td>
<td valign="top" width="20%" bgcolor="green">
&nbsp;
</td>
</tr>
</table>
</td>
</tr>
</table>
~;
&footer;

}




