#!/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; }
	}
}

unless ($INPUT{action} eq "logoff" || $INPUT{action} eq "login") {
print "Content-type: text/html\n\n";
}


unless ($INPUT{action} eq "login") {

@rawCookies = split(/;/,$ENV{'HTTP_COOKIE'});
foreach (@rawCookies) {
	($cookieName, $cookieValue) = split(/=/,$_);
	$cookieName =~ s/ //gi;
	$Cookies{$cookieName}=$cookieValue;
}

if ($Cookies{userid} =~ /\|/) {
($Cook{userid},$Cook{email}) = split(/\|/,$Cookies{userid});
}
else {
($Cook{userid},$Cook{email}) = split(/\-/,$Cookies{userid});
}

if ($Cook{userid} eq "" || $Cook{userid} eq "none") {
print qq~

<html>
<head>
<LINK REL="SHORTCUT ICON" HREF="images/eaglerealestate.ico">
<title>Muncie Real Estate - Search Homes Located in Muncie, Ball State, Albany, Eaton, Dunkirk, Yorktown, Daleville, Gaston, Parker City, Winchester, Farmland, Cowan</title>
<meta NAME="Description" CONTENT="Specializing in Muncie real estate, Ball State, Yorktown, Albany, Eaton, Dunkirk, Hartford City, Winchester and Delaware County.">
<meta http-equiv="set-cookie" content="userid=; expires=; path=/"> 
~;
&header;
print qq~

		<td valign="top" width="581">
		<img src="images/headers/myhomes_account.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="green"><b>You must have a MyHome account to access this feature.</b></font><br><font size="2" color="black">You may login to your existing account or create a <b>FREE</b> Eagle Real Estate 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 Eagle Real Estate MuncieMLS.com you must create a MyHomes account.</b></font><br><br><font size="2">A Eagle Real Estate 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>
	<input type=hidden name=referrer value=$INPUT{referrer}>
<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>
</tr>
</form>
</table>


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


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

~;
&footer;
exit 0;
}
}


## CHECK TOS

my $iasth = $dbh->prepare("select tos_agreement from users where userid = '$Cook{userid}'");
$iasth->execute;
while (($usr_tos) = $iasth->fetchrow_array()) {
	if ($usr_tos eq "0000-00-00 00:00:00") {
	print qq~
	<html>
	<head>
	<title>Loading TOS...</title>
	<meta http-equiv="Refresh" content="3; URL=http://www.MuncieMLS.com/tos.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>
	<img src="images/StatusBar4.gif" alt="Loading"><br>
	<img src="images/LoadingMyHomes.gif"><br>
	</center>
	</td>
	</tr>
	</table>
	</center>
	</body>
	</html>
	~;
	exit 0;
	}
}

if ($INPUT{action} eq "deletesearch") { &deletesearch; }
elsif ($INPUT{action} eq "deletehome") { &deletehome; }
elsif ($INPUT{action} eq "login") { &login; }
elsif ($INPUT{action} eq "logoff") { &logout; }
elsif ($INPUT{action} eq "updateprofile") { &updateprofile; }
elsif ($INPUT{action} eq "saveprofile") { &saveprofile; }
elsif ($INPUT{action} eq "savetogglenotify") { &savetogglenotify; }
elsif ($INPUT{action} eq "changepassword") { &changepassword; }
elsif ($INPUT{action} eq "savedlistings") { &savedlistings; }
elsif ($INPUT{action} eq "savedsearches") { &savedsearches; }
elsif ($INPUT{action} eq "notifications" || $INPUT{action} eq "togglenotify") { &notifications; }
elsif ($INPUT{action} eq "userupdate") { &userupdate; }
else { &main; }

sub updatepassword {
&header;
&startmain;

print qq~
<table border="0" cellpadding="8" cellspacing="3" bgcolor="#CCCCCC" width="461">
<tr>
	<form method=post action=myhomes.idx>
	<input type=hidden name=action value=changepassword>
	<td valign="top" bgcolor="white" width="461">
	<font size="2" face="Arial" color="#000066"><b>UPDATE YOUR PASSWORD</b></font>
	<table border="0" cellpadding="2" cellspacing="0" width="100%">
	<tr>
	<td><b>Current Password:</b></td><td><b>New Password:</b></td><td><b>New Password:</b></td>
	</tr><tr>
	<td><input type=password name=current size=17></td><td><input type=password name=new1 size=17></td><td><input type=password name=new2 size=17></td>
	</tr>
	</table>	
	<center><br><br><input type=submit value="Update Password"></center>
</td>
</tr>
</form>
</table>
</td>

~;

}

sub startmain {
print qq~
<td width="581" valign="top">
<img src="images/headers/myhomes_account.gif" height="33" width="581" alt="My Homes Account"><br>
~;
if ($INPUT{action}) {
print qq~
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td valign="top" align="right"><a href="javascript:history.back()">Return To List</a></td>
</tr>
</table>
~;
}
}


sub changepassword {


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 $aasth = $dbh->prepare("select password from users where userid = '$Cook{userid}' and password = PASSWORD('$INPUT{current}')");
$aasth->execute;

	my $cqasth = $dbh->prepare("select userid,email,firstname,lastname,access from users where userid = '$Cook{userid}'");
	$cqasth->execute;
	while (($ruserid,$remail,$rfirstname,$rlastname) = $cqasth->fetchrow_array()) {
	$sendto = "$remail";
	$fullname = "$rfirstname $rlastname";
	$admin = "$access";
	}

while (($itsgood) = $aasth->fetchrow_array()) {
	unless ($INPUT{new1} && $INPUT{new2}) {
	$status = "Please enter and verify your new passwords as well as your new password.";
	}

	unless ($INPUT{new1} eq $INPUT{new2}) {
	$status = "New passwords don't match";
	}

	&header;
	&startmain;


		print qq~
		<font size="3" face="arial" color="red"><b>$status</b></font><br>
		~;

		if ($status) {
print qq~
<table border="0" cellpadding="8" cellspacing="3" bgcolor="#CCCCCC" width="461">
<tr>
	<form method=post action=myhomes.idx>
	<input type=hidden name=action value=changepassword>
	<td valign="top" bgcolor="white" width="461">
	<font size="2" face="Arial" color="#000066"><b>UPDATE YOUR PASSWORD</b></font>
	<table border="0" cellpadding="2" cellspacing="0" width="100%">
	<tr>
	<td><b>Current Password:</b></td><td><b>New Password:</b></td><td><b>New Password:</b></td>
	</tr><tr>
	<td><input type=password name=current size=17></td><td><input type=password name=new1 size=17></td><td><input type=password name=new2 size=17></td>
	</tr>
	</table>	
	<center><br><br><input type=submit value="Update Password"></center>
</td>
</tr>
</form>
</table>
~;

}
else {
		my $basth = $dbh->do("update users set password = PASSWORD('$INPUT{new1}') where userid = '$Cook{userid}'");
		print qq~
		<font size="2" color="#000066">Your password has been successfully changed to <b>$INPUT{new1}</b>. Please keep your new password for your records.   An e-mail has also been sent to $sendto 			with your new login email and password!  Thank you for your continued use of the MuncieMLS.com home search website.</font>
		~;

open(MAIL,"|/usr/sbin/sendmail -t");
print MAIL "To: $sendto\n";
print MAIL "From: Admin\@MuncieMLS.com\n";
print MAIL "Subject: Your MuncieMLS.com Password Has Been Changed!\n";
print MAIL "Content-type: text/html\n\n";
print MAIL qq~
<html>
<head>
<title>E-Mailer</title>
<link rel="stylesheet" TYPE="text/css" href="http://www.munciemls.com/includes/style.css">
</head>
<body bgcolor="white" leftMargin="0" topMargin="0" marginwidth="0" marginheight="0">
<br><br>
<center>
<table border="0" cellspacing="0" cellpadding="0" width="600">
<tr>
<td valign="top" width="600">
<img src="http://www.munciemls.com/images/emailheader.gif"><br>
<table border="0" cellspacing="0" cellpadding="15" width="100%">
<tr>
<td valign="top" width="100%">
<font size="2">
$fullname,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;We thought we would send you a note to remind you of your new password at www.MuncieMLS.com!<br><br>
<b>Your new login information and password for future reference is:</b><br>
<table border="0" cellpadding="4" cellspacing="0">
<tr>
<td><b>E-Mail</b></td>
<td>$sendto</td>
</tr>
<tr>
<td><b>Password</b></td>
<td>$INPUT{new1}</td>
</tr>
</table>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;We hope you are enjoying your experience with the www.MuncieMLS.com website and property search.<br><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp Eagle Real Estate, Inc. looks forward to serving you.    If at anytime you have questions or comments regarding the use of MuncieMLS.com please email <a href="mailto:info\@eagle-online.com">info\@eagle-online.com</a> or call us 765-741-9111.<br><br>Thank You,<br>Eagle<br>
</font>
</td>
</tr>
</table>
<img src="http://www.munciemls.com/images/emailfooter.gif"><br><br><br>
</td>
</tr>
</table>
</center>
</body>
</html>
~;
close(MAIL);

$send_body =qq~
<html>
<head>
<title>E-Mailer</title>
<link rel="stylesheet" TYPE="text/css" href="http://www.munciemls.com/includes/style.css">
</head>
<body bgcolor="white" leftMargin="0" topMargin="0" marginwidth="0" marginheight="0">
<br><br>
<center>
<table border="0" cellspacing="0" cellpadding="0" width="600">
<tr>
<td valign="top" width="600">
<img src="http://www.munciemls.com/images/emailheader.gif"><br>
<table border="0" cellspacing="0" cellpadding="15" width="100%">
<tr>
<td valign="top" width="100%">
<font size="2">
$fullname,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;I thought I would send you a note to remind you of your new password at www.MuncieMLS.com!<br><br>
<b>Your new login information and password for future reference is:</b><br>
<table border="0" cellpadding="4" cellspacing="0">
<tr>
<td><b>E-Mail</b></td>
<td>$sendto</td>
</tr>
<tr>
<td><b>Password</b></td>
<td>$INPUT{new1}</td>
</tr>
</table>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;I hope you are enjoying your experience with the www.MuncieMLS.com website and property search.<br><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Eagle Real Estate, Inc. looks forward to serving you.    If at anytime you have questions or comments regarding the use of MuncieMLS.com please email webmaster direct at webmaster\@MuncieMLS.com or call 765-744-9500.<br><br>Thank You,<br>MuncieMLS.com<br>
</font>
</td>
</tr>
</table>
<img src="http://www.munciemls.com/images/emailfooter.gif"><br><br><br>
</td>
</tr>
</table>
</center>
</body>
</html>
~;

######## RECORD COPY OF EMAIL IN DATABASE #################
@evariables = ("$Cook{userid}","webmaster\@MuncieMLS.com","Password Change -> Your MuncieMLS.com Password Has Been Changed!","$send_body");
$esql_query = "INSERT INTO emailstousers values ('',?,now(),?,?,?)";
my $zzaasth = $dbh->do($esql_query, undef, @evariables);
###########################################################

		}

		print qq~
		</td>
		~;
	
	
$found = "yes";
}



unless ($found eq "yes") {

	&header;
	&startmain;
	
	print qq~
	<font size="2" color="#000066">Your current password does not match the current password we have on file for $sendto.  Please try again below<br><br><br></font>
<table border="0" cellpadding="8" cellspacing="3" bgcolor="#CCCCCC" width="461">
<tr>
	<form method=post action=myhomes.idx>
	<input type=hidden name=action value=changepassword>
	<td valign="top" bgcolor="white" width="461">
	<font size="2" face="Arial" color="#000066"><b>UPDATE YOUR PASSWORD</b></font>
	<table border="0" cellpadding="2" cellspacing="0" width="100%">
	<tr>
	<td><b>Current Password:</b></td><td><b>New Password:</b></td><td><b>New Password:</b></td>
	</tr><tr>
	<td><input type=password name=current size=17></td><td><input type=password name=new1 size=17></td><td><input type=password name=new2 size=17></td>
	</tr>
	</table>	
	<center><br><br><input type=submit value="Update Password"></center>
</td>
</tr>
</form>
</table>
</td>
~;
}

&footer;



exit 0;



}










sub savetogglenotify {


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 $hasth = $dbh->do("update search_fav set status = '1', wireless = '$INPUT{wireless}', email = '$INPUT{email}' where favid = '$INPUT{searchid}' and userid = '$Cook{userid}'");

$dbh->disconnect;

$turnedon = "yes";

&notifications;

}








sub saveprofile {



$INPUT{FirstName} =~ s/\"/CHR2/gi;
$INPUT{FirstName} =~ s/\'/CHR1/gi;
$INPUT{LastName} =~ s/\"/CHR2/gi;
$INPUT{LastName} =~ s/\'/CHR1/gi;
$INPUT{Address} =~ s/\"/CHR2/gi;
$INPUT{Address} =~ s/\'/CHR1/gi;
$INPUT{City} =~ s/\"/CHR2/gi;
$INPUT{City} =~ s/\'/CHR1/gi;
$INPUT{State} =~ s/\"/CHR2/gi;
$INPUT{State} =~ s/\'/CHR1/gi;
$INPUT{Zip} =~ s/\"/CHR2/gi;
$INPUT{Zip} =~ s/\'/CHR1/gi;
$INPUT{Email} =~ s/\"/CHR2/gi;
$INPUT{Email} =~ s/\'/CHR1/gi;
$INPUT{TimeToMove} =~ s/\"/CHR2/gi;
$INPUT{TimeToMove} =~ s/\'/CHR1/gi;
$INPUT{realtor} =~ s/\"/CHR2/gi;
$INPUT{realtor} =~ s/\'/CHR1/gi;
$INPUT{FoundBy} =~ s/\"/CHR2/gi;
$INPUT{FoundBy} =~ s/\'/CHR1/gi;
$INPUT{UserType} =~ s/\"/CHR2/gi;
$INPUT{UserType} =~ s/\'/CHR1/gi;
$INPUT{myERAAgent} =~ s/\"/CHR2/gi;
$INPUT{myERAAgent} =~ s/\'/CHR1/gi;
$INPUT{Phone} =~ s/\"/CHR2/gi;
$INPUT{Phone} =~ s/\'/CHR1/gi;



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 $yasth = $dbh->do("update users set firstname = '$INPUT{FirstName}', lastname = '$INPUT{LastName}', address = '$INPUT{Address}', city = '$INPUT{City}', state = '$INPUT{State}', zipcode = '$INPUT{zipcode}', timetomove = '$INPUT{TimeToMove}', realtor = '$INPUT{realtor}', email = '$INPUT{Email}', FoundBy = '$INPUT{FoundBy}', zipcode = '$INPUT{Zip}', UserType = '$INPUT{UserType}', myERAAgent = '$INPUT{myERAAgent}', Phone = '$INPUT{Phone}', email_block = '$INPUT{email_block}', email_openhouses = '$INPUT{email_openhouses}' where userid = '$Cook{userid}'");


if ($INPUT{myERAAgent}) {

my $basth = $dbh->prepare("select agentassigned from leadtracking where userid = ?");
$basth->execute($Cook{userid});
while (($agentassigned) = $basth->fetchrow_array()) {

	if ($agentassigned ne "$INPUT{myERAAgent}") {
	my $hasth = $dbh->do("update leadtracking set agentassigned = '$INPUT{myERAAgent}' where userid = '$Cook{userid}' limit 1");
	}

}

}



$dbh->disconnect;




print qq~

<html><head><title>Updating profile...</title>
<meta http-equiv="Refresh" content="1; URL=myhomes.idx">
</head>
<body>
<br><br><br><br><br><center>
Updating profile...
</center>

~;



}


sub updateprofile {


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 $hasth = $dbh->prepare("select userid,email,password,firstname,lastname,address,city,state,zipcode,timetomove,realtor,datestamp,lastlogin,FoundBy,UserType,myERAAgent,Phone,email_block,email_openhouses from users where userid = '$Cook{userid}'");
$hasth->execute;

while (($userid,$email,$password,$_firstname,$_lastname,$address,$city,$state,$zipcode,$timetomove,$realtor,$datejoined,$lastlogin,$foundby,$usertype,$myeraagent,$phone,$email_block,$email_openhouses) = $hasth->fetchrow_array()) {

my $zasth = $dbh->prepare("select mlsid,firstname,lastname from agents where display = '1' order by lastname asc");
$zasth->execute;
while (($mlsid,$firstname,$lastname) = $zasth->fetchrow_array()) {
$agentbuildlist .= "<option value=\"$mlsid\">$lastname, $firstname</option>\n";
}

my $qasth = $dbh->prepare("select mlsid,firstname,lastname from agents where mlsid = '$myeraagent' order by agentid desc");
$qasth->execute;
while (($mlsid,$firstname,$lastname) = $qasth->fetchrow_array()) {
$buildmyeraagent = "<option value=\"$mlsid\">$lastname, $firstname</option>\n";
}

if ($foundby) {
$buildfoundby = "<option value=\"$foundby\">$foundby</option>";
}

if ($usertype) {
$buildusertype = "<option value=\"$usertype\">$usertype</option>";
}

if ($timetomove) {
$buildtimetomove = "<option value=\"$timetomove\">$timetomove</option>";
}

if ($realtor eq "Yes") {
$checkYesrealtor = " checked";
}
else {
$checkNorealtor = " checked";
}

if ($email_openhouses eq "y") {
$checkYESemail_openhouses = " checked";
}
else {
$checkNOemail_openhouses = " checked";
}

if ($email_block eq "y") {
$checkYESemail_block = " checked";
}
else {
$checkNOemail_block = " checked";
}

$_firstname =~ s/CHR2/\&quot\;/gi;
$_lastname =~ s/CHR2/\&quot\;/gi;
$address =~ s/CHR2/\&quot\;/gi;
$city =~ s/CHR2/\&quot\;/gi;
$state =~ s/CHR2/\&quot\;/gi;
$zipcode =~ s/CHR2/\&quot\;/gi;

print <<"TITLE";
<html>
<head>
<LINK REL="SHORTCUT ICON" HREF="images/eaglerealestate.ico">
<title>Eagle Real Estate, Inc - MuncieMLS.com</title>
TITLE

&header;
print <<"UPDATEYOURPROFILE";
<td valign="top" width="581">
<table border="0" cellpadding="0" cellspacing="0" width="581">
<tr>
<td>
<img src="images/headers/myhomes_account.gif" height="33" width="581" alt="Update My Homes Account"><Br>
<img src="images/myhomes/menu/left.gif" width="61" height="20"><a href="myhomes.idx"><img src="images/myhomes/menu/summary.gif" width="86" height="20" border="0" alt="Summary"></a><img src="images/myhomes/menu/divider1.gif" width="3" height="20"><a href="myhomes.idx?action=savedlistings"><img src="images/myhomes/menu/savedlistings.gif" width="113" height="20" border="0" alt="My Saved Listings"></a><img src="images/myhomes/menu/divider1.gif" width="3" height="20"><a href="myhomes.idx?action=savedsearches"><img src="images/myhomes/menu/savedsearches.gif" width="120" height="20" border="0" alt="My Saved Searches"></a><img src="images/myhomes/menu/divider1.gif" width="3" height="20"><a href="myhomes.idx?action=notifications"><img src="images/myhomes/menu/notifications.gif" width="83" height="20" border="0" alt="My Notifications"></a><img src="images/myhomes/menu/divider1.gif" width="3" height="20"><a href="myhomes.idx?action=updateprofile"><img src="images/myhomes/menu/updateaccount_b.gif" width="106" height="20" border="0" alt="Update Account"></a><br>
</td>
</tr>
</table>
<br><br>
<table border="0" cellpadding="3" width="581" cellspacing="0">
<tr>
<td valign="top" width="100%">
<font size="2"><b>You may use the following form to update your account<br></b></font>
</font>
</td>
</tr>
<tr>
<td valign="top" width="100%">
<br>
<form method=post action=myhomes.idx>
<input type=hidden name=action value=saveprofile>
		<table border="0" cellspacing="0" cellpadding="0" width="100%">
		<tr>
		<td>
			<table border="0" cellpadding="3" cellspacing="0" width="100%">
				<tr>
					<td width="50%"><font size="2"><b>How Did You Find MuncieMLS?</b></font></td>
					<td width="50%">
						<select name="FoundBy">
						$buildfoundby
						<option value="">-- Choose One --</option>
						<option value="Search Engine">Search Engine</option>
						<option value="Business card">Business Card</option>
						<option value="REALTOR Recommendation">REALTOR Recommendation</option>
						<option value="Homes and Lifestyles Magazine">Homes and Lifestyles Magazine</option>
						<option value="The Star Press">The Star Press</option>
						<option value="Other">Other</option>
						</select> 
					</td>
				</tr>
				<tr>
					<td width="50%" bgcolor="#e2e2e2">
						<font size="2"><b>I Am A
					</td>
					<td width="50%" bgcolor="#e2e2e2">
							<select name="UserType">
							$buildusertype
							<option value="">-- Choose Type --</option>
							<option value="Buyer">Buyer</option>
							<option value="Seller">Seller</option>
							<option value="Seller & Buyer">Seller & Buyer</option>
							<option value="Investor">Investor</option>
							<option value="Real Estate Professional">Real Estate Professional</option>
							<option value="Other">Other</option>
						</select>
 					</td>
				</tr>
				<tr>
					<td><font size="2"><b>First Name</b></font></td><td><input type="text" name="FirstName" value="$_firstname"></td>
				</tr>
				<tr>
					<td bgcolor="#e2e2e2"><font size="2"><b>Last Name</b></font></td><td bgcolor="#e2e2e2"><input type="text" name="LastName" value="$_lastname"></td>
				</tr>
				<tr>
					<td><font size="2"><b>Phone Number</b></font></td><td><input type="text" name="Phone" value="$phone"></td>
				</tr>
				<tr>
					<td bgcolor="#e2e2e2"><font size="2"><b>Email</b></font></td><td bgcolor="#e2e2e2"><input type="text" name="Email" onFocusOut="javascript:checkMail();" value="$email"></td>
				</tr>
				<tr>
					<td><font size="2"><b>Address</b></font></td><td><input type="text" name="Address" value="$address"></td>
				</tr>
				<tr>
					<td bgcolor="#e2e2e2"><font size="2"><b>City</b></font></td><td bgcolor="#e2e2e2"><input type="text" name="City" value="$city"></td>
				</tr>
				<tr>
					<td><font size="2"><b>State</b></font></td><td><input type="text" name="State" value="$state"></td>
				</tr>
				<tr>
					<td bgcolor="#e2e2e2"><font size="2"><b>Zip Code</b></font></td><td bgcolor="#e2e2e2"><input type="text" name="Zip" value="$zipcode"></td>
				</tr>
				<tr>
					<td><font size="2"><b>What Is Your Time Frame For Your Next Real Estate Transaction?</b></font></td>
					<td>
						<select name="TimeToMove">
						$buildtimetomove
						<option value="Immediately">Immediately</option>
						<option value="1-2Months">1 - 2 Months</option>
						<option value="3-4Months">3 - 4 Months</option>
						<option value="5-6Months">5 - 6 Months</option>
						<option value="6-1YrMonths">6 Months - 1 Year</option>
						<option value="1YrUp">1 Year or Longer</option>
						</select>
					</td>
				</tr>
				<tr>
					<td bgcolor="#e2e2e2"><font size="2"><b>Your Agent or Preferred Eagle Agent</b></font></td>
					<td bgcolor="#e2e2e2"><input type="radio" value="Yes" Name="realtor"$checkYesrealtor> Yes  	<input type="radio" value="No" Name="realtor"$checkNorealtor> No<br>

					<select name="myERAAgent">
					$buildmyeraagent
					<option value="">-- If Yes, Choose Agent --</option>
					<option value="">==========================</option>
					$agentbuildlist
					</select>
				</td>
				</tr>
				<tr>
					<td><font size="2"><b>MuncieMLS.com and Eagle Real Estate may periodically send our users electronic newletters.  You may receive one email every 1 - 4 months.  May we please include you in this mailing?  You may unsubscribe at any time.</b></font></td>
					<td><input type="radio" value="y" Name="email_block"$checkYESemail_block> Yes  	<input type="radio" value="n" Name="email_block"$checkNOemail_block> No<br>
				</td>
				</tr>				
				<tr>
					<td bgcolor="#e2e2e2"><font size="2"><b>Could we remind you when new open houses posted on our website?</b></font></td>
					<td bgcolor="#e2e2e2"><input type="radio" value="y" Name="email_openhouses"$checkYESemail_openhouses> Yes  	<input type="radio" value="n" Name="email_openhouses"$checkNOemail_openhouses> No<br>
				</td>
				</tr>
				<tr>
					<td colspan="2"><center><br><input type=submit value="Update Account Profile"></center></td>
				</tr>
			</table>

</td>
</tr>
</table>
</form>
<br>

<font size="2" face="Arial" color="#000066">Update your password has been moved!  Look for it under MyHomes Account on the left navigational menu.</font><br>



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

UPDATEYOURPROFILE
&footer;
$dbh->disconnect;
exit 0;
}


}

sub userupdate {


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 $hasth = $dbh->prepare("select * from users where userid = '$Cook{userid}'");
$hasth->execute;



$dbh->disconnect;


while (($userid,$email,$password,$_firstname,$_lastname,$address,$city,$state,$zipcode,$timetomove,$realtor,$datejoined,$lastlogin,$foundby,$usertype,$myeraagent,$phone) = $hasth->fetchrow_array()) {

my $zasth = $dbh->prepare("select mlsid,firstname,lastname from agents where display = '1' order by lastname asc");
$zasth->execute;
while (($mlsid,$firstname,$lastname) = $zasth->fetchrow_array()) {
$agentbuildlist .= "<option value=\"$mlsid\">$lastname, $firstname</option>\n";
}

my $qasth = $dbh->prepare("select mlsid,firstname,lastname from agents where mlsid = '$myeraagent'");
$qasth->execute;
while (($mlsid,$firstname,$lastname) = $qasth->fetchrow_array()) {
$buildmyeraagent = "<option value=\"$mlsid\">$firstname $lastname</option>\n";
}

if ($foundby) {
$buildfoundby = "<option value=\"$foundby\">$foundby</option>";
}

if ($usertype) {
$buildusertype = "<option value=\"$usertype\">$usertype</option>";
}

if ($timetomove) {
$buildtimetomove = "<option value=\"$timetomove\">$timetomove</option>";
}

if ($realtor eq "Yes") {
$checkYesrealtor = " checked";
}
else {
$checkNorealtor = " checked";
}

$_firstname =~ s/CHR2/\&quot\;/gi;
$_lastname =~ s/CHR2/\&quot\;/gi;
$address =~ s/CHR2/\&quot\;/gi;
$city =~ s/CHR2/\&quot\;/gi;
$state =~ s/CHR2/\&quot\;/gi;
$zipcode =~ s/CHR2/\&quot\;/gi;

print <<"TITLE";
<html>
<head>
<LINK REL="SHORTCUT ICON" HREF="images/eaglerealestate.ico">
<title>Eagle Real Estate, Inc. - MuncieMLS.com</title>
TITLE

&header;
print <<"UPDATEYOURPROFILE";
<td valign="top" width="581">
<table border="0" cellpadding="0" cellspacing="0" width="581">
<tr>
<td>
<img src="images/headers/myhomes_account.gif" height="33" width="581" alt="Update My Homes Account"><Br>
<img src="images/myhomes/menu/left.gif" width="61" height="20"><a href="myhomes.idx"><img src="images/myhomes/menu/summary.gif" width="86" height="20" border="0" alt="Summary"></a><img src="images/myhomes/menu/divider1.gif" width="3" height="20"><a href="myhomes.idx?action=savedlistings"><img src="images/myhomes/menu/savedlistings.gif" width="113" height="20" border="0" alt="My Saved Listings"></a><img src="images/myhomes/menu/divider1.gif" width="3" height="20"><a href="myhomes.idx?action=savedsearches"><img src="images/myhomes/menu/savedsearches.gif" width="120" height="20" border="0" alt="My Saved Searches"></a><img src="images/myhomes/menu/divider1.gif" width="3" height="20"><a href="myhomes.idx?action=notifications"><img src="images/myhomes/menu/notifications.gif" width="83" height="20" border="0" alt="My Notifications"></a><img src="images/myhomes/menu/divider1.gif" width="3" height="20"><a href="myhomes.idx?action=updateprofile"><img src="images/myhomes/menu/updateaccount_b.gif" width="106" height="20" border="0" alt="Update Account"></a><br>
</td>
</tr>
</table>
<br><br>
<table border="0" cellpadding="3" width="581" cellspacing="0">
<tr>
<td valign="top" width="100%">
<font size="4" color="red"><b>Thank you for coming back to MuncieMLS.com.  Please take a second to update your information.<br></b></font>
</font>
</td>
</tr>
<tr>
<td valign="top" width="100%">
<br>
<form method=post action=myhomes.idx>
<input type=hidden name=action value=saveprofile>
		<table border="0" cellspacing="0" cellpadding="0" width="100%">
		<tr>
		<td>
			<table border="0" cellpadding="3" cellspacing="0" width="100%">
				<tr>
					<td width="50%"><font size="2"><b>How Did You Find MuncieMLS?</b></font></td>
					<td width="50%">
						<select name="FoundBy">
						$buildfoundby
						<option value="">-- Choose One --</option>
						<option value="Search Engine">Search Engine</option>
						<option value="Business card">Business Card</option>
						<option value="REALTOR Recommendation">REALTOR Recommendation</option>
						<option value="Homes and Lifestyles Magazine">Homes and Lifestyles Magazine</option>
						<option value="The Star Press">The Star Press</option>
						<option value="Other">Other</option>
						</select> 
					</td>
				</tr>
				<tr>
					<td width="50%" bgcolor="#e2e2e2">
						<font size="2"><b>I Am A
					</td>
					<td width="50%" bgcolor="#e2e2e2">
							<select name="UserType">
							$buildusertype
							<option value="">-- Choose Type --</option>
							<option value="Buyer">Buyer</option>
							<option value="Seller">Seller</option>
							<option value="Seller & Buyer">Seller & Buyer</option>
							<option value="Investor">Investor</option>
							<option value="Real Estate Professional">Real Estate Professional</option>
							<option value="Other">Other</option>
						</select>
 					</td>
				</tr>
				<tr>
					<td><font size="2"><b>First Name</b></font></td><td><input type="text" name="FirstName" value="$_firstname"></td>
				</tr>
				<tr>
					<td bgcolor="#e2e2e2"><font size="2"><b>Last Name</b></font></td><td bgcolor="#e2e2e2"><input type="text" name="LastName" value="$_lastname"></td>
				</tr>
				<tr>
					<td><font size="2"><b>Phone Number</b></font></td><td><input type="text" name="Phone" value="$phone"></td>
				</tr>
				<tr>
					<td bgcolor="#e2e2e2"><font size="2"><b>Email</b></font></td><td bgcolor="#e2e2e2"><input type="text" name="Email" onFocusOut="javascript:checkMail();" value="$email"></td>
				</tr>
				<tr>
					<td><font size="2"><b>Address</b></font></td><td><input type="text" name="Address" value="$address"></td>
				</tr>
				<tr>
					<td bgcolor="#e2e2e2"><font size="2"><b>City</b></font></td><td bgcolor="#e2e2e2"><input type="text" name="City" value="$city"></td>
				</tr>
				<tr>
					<td><font size="2"><b>State</b></font></td><td><input type="text" name="State" value="$state"></td>
				</tr>
				<tr>
					<td bgcolor="#e2e2e2"><font size="2"><b>Zip Code</b></font></td><td bgcolor="#e2e2e2"><input type="text" name="Zip" value="$zipcode"></td>
				</tr>
				<tr>
					<td><font size="2"><b>What Is Your Time Frame For Your Next Real Estate Transaction?</b></font></td>
					<td>
						<select name="TimeToMove">
						$buildtimetomove
						<option value="Immediately">Immediately</option>
						<option value="1-2Months">1 - 2 Months</option>
						<option value="3-4Months">3 - 4 Months</option>
						<option value="5-6Months">5 - 6 Months</option>
						<option value="6-1YrMonths">6 Months - 1 Year</option>
						<option value="1YrUp">1 Year or Longer</option>
						</select>
					</td>
				</tr>
				<tr>
					<td bgcolor="#e2e2e2"><font size="2"><b>Your Agent or Preferred Eagle Agent</b></font></td>
					<td bgcolor="#e2e2e2"><input type="radio" value="Yes" Name="realtor"$checkYesrealtor> Yes  	<input type="radio" value="No" Name="realtor"$checkNorealtor> No<br>

					<select name="myERAAgent">
					$buildmyeraagent
					<option value="">-- If Yes, Choose Agent --</option>
					<option value="">==========================</option>
					$agentbuildlist
					</select>
				</td>
				</tr>
				<tr>
					<td colspan="2"><center><br><input type=submit value="Looks Correct, Start Searching"></center></td>
				</tr>
			</table>

</td>
</tr>
</table>
</form>
<br>

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

UPDATEYOURPROFILE
&footer;

exit 0;
}


}



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 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}')");
$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 31 DAY), '%a\, %d\-%b\-%Y %T')");
$pasth->execute;

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

my $zasth = $dbh->prepare("select Phone from users where userid = '$userid'");
$zasth->execute;
while (($Phone) = $zasth->fetchrow_array()) {
if ($Phone) {
$theurl = "myhomes.idx";
}
else {
$theurl = "myhomes.idx?action=userupdate";
}
}



#my $azasth = $dbh->prepare("select firstname,lastname,email from users where userid = '$userid'");
#$azasth->execute;
#while (($firstname,$lastname,$email) = $azasth->fetchrow_array()) {
#open(MAIL,"|/usr/sbin/sendmail -t");
#print MAIL "To: 7657449500\@vtext.com\n";
#print MAIL "From: $email\n";
#print MAIL "Subject: $firstname $lastname (userid $userid) Logged Back In\n\n";
#print MAIL "";
#close(MAIL);
#}

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

if ($INPUT{referrer}) {
print qq~

<html><head><title>Loading Listing ID $INPUT{referrer}...</title>
<meta http-equiv="Refresh" content="3; URL=http://$INPUT{referrer}.MuncieMLS.com">
</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/LoadingMyHomes.gif"><br>
</center>
</td>
</tr>
</table>
</center>

~;
}
else {
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/LoadingMyHomes.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>
<LINK REL="SHORTCUT ICON" HREF="images/eaglerealestate.ico">
<title>Eagle Real Estate, Inc. - MuncieMLS.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>
		Possible reasons include:<br><br>
		1) <b>You need to create an account before saving listing information</b><br><br>
		2) <b>You have not logged in with your correct email address and password</b><br><br>
		3) <b>Your session has expired and you may need to relogin again.</b><br><br>
		4) <b>Your browser does not accept cookies.   You may need to enable them.</b><br><br>
		5) <b>If you see Welcome Guest instead of your name in the menu bar above you are not logged in.</b><Br><br>
		Please <a href="register.idx">Register Instantly for a Free Eagle Real Estate, Inc. MuncieMLS.com Account</a> Or Login With Your Existing Account Before Accessing The MyHomes Area.<br><br>
		If you lost your password please <a href="lostpassword.idx">Click Here To Retrieve It</a><br>
		</td>
		</tr>
		</table>
		</td>




~;


&footer;


}


sub deletesearch {

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 $oasth = $dbh->do("delete from search_fav where favid = '$INPUT{ID}' and userid = '$Cook{userid}'");

$dbh->disconnect;

print qq~

<html><head><title>Deleting search...</title>
<meta http-equiv="Refresh" content="4; URL=myhomes.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>
<img src="images/StatusBar4.gif" alt="Loading"><br>
<img src="images/Removing.gif"><br>
</center>

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

~;


}




sub deletehome {

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 $oasth = $dbh->do("delete from home_fav where favid = '$INPUT{ID}' and userid = '$Cook{userid}'");

$dbh->disconnect;

print qq~

<html><head><title>Deleting home...</title>
<meta http-equiv="Refresh" content="4; URL=myhomes.idx?action=savedlistings">
</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/Removing.gif"><br>
</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;

my $uasth = $dbh->prepare("select * from users where userid = '$Cook{userid}'");
$uasth->execute;

my $iasth = $dbh->prepare("select COUNT(userid) from home_fav where userid = '$Cook{userid}'");
$iasth->execute;

while (($userid) = $iasth->fetchrow_array()) {
$savelistingcount = $userid;
}

my $pasth = $dbh->prepare("select COUNT(userid) from search_fav where userid = '$Cook{userid}'");
$pasth->execute;

while (($userid) = $pasth->fetchrow_array()) {
$savesearchcount = $userid;
}

my $basth = $dbh->prepare("select COUNT(userid) from search_fav where userid = '$Cook{userid}' AND status = '1'");
$basth->execute;

while (($userid) = $basth->fetchrow_array()) {
$savenotificationscount = $userid;
}

my $qasth = $dbh->prepare("select * from updated_listings");
$qasth->execute;

my $tasth = $dbh->prepare("select * from new_listings");
$tasth->execute;

while (($updatedmls,$updatedtype) = $qasth->fetchrow_array()) {
$updatedcount{$updatedtype}++;
}

while (($newmls,$newtype) = $tasth->fetchrow_array()) {
$newcount{$newtype}++;
}

if ($newcount{res} eq "") {
$newcount{res} = "0";
}
if ($newcount{comm} eq "") {
$newcount{comm} = "0";
}
if ($newcount{inv} eq "") {
$newcount{inv} = "0";
}
if ($newcount{lan} eq "") {
$newcount{lan} = "0";
}

if ($updatedcount{res} eq "") {
$updatedcount{res} = "0";
}
if ($updatedcount{comm} eq "") {
$updatedcount{comm} = "0";
}
if ($updatedcount{inv} eq "") {
$updatedcount{inv} = "0";
}
if ($updatedcount{lan} eq "") {
$updatedcount{lan} = "0";
}

while (($userid,$email,$_password,$myfirstname,$mylastname,$address,$city,$state,$zipcode,$timetomove,$realtor,$datestamp,$lastlogin,$foundby,$usertype,$myeraagent,$phone,$access,$email_stamp,$agentid) = $uasth->fetchrow_array())  {

$savefirstname = $myfirstname;
$savelastname = $mylastname;

$savefirstname =~ s/CHR2/\"/gi;
$savelastname =~ s/CHR2/\"/gi;
$savefirstname =~ s/CHR1/\'/gi;
$savelastname =~ s/CHR1/\'/gi;

print <<"TITLE";
<html>
<head>
<title>Eagle Real Estate, Inc. - MuncieMLS.com</title>
TITLE

&header;


print qq~
<td valign="top" width="581">
<table border="0" cellpadding="0" cellspacing="0" width="581">
<tr>
<td valign="top" colspan="2" width="581">
<img src="images/headers/myhomes_account.gif" height="33" width="581" alt="MY HOMES Account"><br>
<img src="images/myhomes/menu/left.gif" width="61" height="20"><a href="myhomes.idx"><img src="images/myhomes/menu/summary_b.gif" width="86" height="20" border="0"></a><img src="images/myhomes/menu/divider1.gif" width="3" height="20"><a href="myhomes.idx?action=savedlistings"><img src="images/myhomes/menu/savedlistings.gif" width="113" height="20" border="0"></a><img src="images/myhomes/menu/divider1.gif" width="3" height="20"><a href="myhomes.idx?action=savedsearches"><img src="images/myhomes/menu/savedsearches.gif" width="120" height="20" border="0"></a><img src="images/myhomes/menu/divider1.gif" width="3" height="20"><a href="myhomes.idx?action=notifications"><img src="images/myhomes/menu/notifications.gif" width="83" height="20" border="0"></a><img src="images/myhomes/menu/divider1.gif" width="3" height="20"><a href="myhomes.idx?action=updateprofile"><img src="images/myhomes/menu/updateaccount.gif" width="106" height="20" border="0"></a><br>
</td>
</tr>
<tr>
<td colspan="2" valign="Top"><img src="images/line_spacer.gif" width="581" height="4"><br></td>
</tr>
<tr>
<td width="361" valign="top">
<br>
<a href="propertysearch.idx"><img src="images/myhomes/search.gif" alt="Search Properties" border="0" height="23" width="250"></a>
<br><Br>
<table border="0" cellpadding="3" cellspacing="0" width="300">
<tr>
<td valign="middle"><a href="feedback.idx"><img src="images/feedback_icon.gif" border="0"></a></td>
<td valign="top">
<b>We want to hear from you!  Please take a few seconds and fill out the <a href="feedback.idx">Feedback Form Here</a> and let us know how we can further improve MuncieMLS</b><br>
</td>
</tr>
</table>
<br>
<table border="0" cellpadding="1" cellspacing="0" width="95%">
<tr>
	<td colspan="2" width="100%"><font size="3"><b>Account Summary</b></font><br></td>
</tr>
<tr>
	<td width="10%">&nbsp;</td>
	<td width="90%" colspan="2"><b>$myfirstname $mylastname<br>$address<br>$city $state, $zipcode<br><a href="$email">$email</a><br>$usertype</b><br><br><br><b><font size="2">The ORR Team</font></b><br></td>
</tr>
~;
if ($myeraagent) {
my $zasth = $dbh->prepare("select agentid,mlsid,firstname,lastname,title,phone1name,phone1number,email,homepage,profile,image from agents where mlsid = '$myeraagent' and display = '1'");
$zasth->execute;
while (($realagentid,$mlsid,$firstname,$lastname,$title,$phone1name,$phone1number,$email,$homepage,$profile,$image) = $zasth->fetchrow_array()) {
print qq~
	<tr>
		<td width="100%" colspan="2">
			<table border="0" cellpadding="3" cellspacing="0" width="100%">
			<tr>
			<td valign="top">
				<img src="images/agentpics/$image" width="40" height="56">
			</td>
			<td valign="top">
				
				<b><font size="3" color="navy">$firstname $lastname</font><br>
				$title<br>
				$phone1name $phone1number<br>
				Email $email<br>
				<a href="agents.idx?action=viewagent&agent=$realagentid">View My Profile</a><br>
				</b></font>
			</td>
			</tr>
			</table>
	</td>
	</tr>
~;
}
}
print qq~
</table>
<br>
</td>
<td width="220" valign="top">
<br>
<img src="images/myhomes/mls_monitor.gif" alt="MLS Monitor" height="25" width="220"><br>
<table border="0" cellpadding="0" cellspacing="1" width="220" bgcolor="#999999">
<tr>
<td valign="top" width="100%" bgcolor="#FFFF99">


<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr bgcolor="#CCCCCC">
<td colspan="3">View Current MLS Market</td>
</tr>
<tr bgcolor="#000099">
<td valign="top"><b><font color="white">Property Type</font></b></td>
<td valign="top"><b><font color="white"><center>New/Ext.</center></font></b></td>
<td valign="top"><b><font color="white"><center>Updated</center></font></b></td>
</tr>
<tr>
<td valign="top"><b>Residential</b></td>
<td valign="top"><b><center><a href="newsearch.idx">$newcount{res}</a> <a href="newsearch.idx"><img src="images/view.gif" border="0" alt="Search New Listings"></a></center></td>
<td valign="top"><b><center><a href="updatedsearch.idx">$updatedcount{res}</a> <a href="updatedsearch.idx"><img src="images/view.gif" border="0" alt="Search Updated Listings"></a></center></td>
</tr>
<tr>
<td colspan="3"><img src="images/black_fill.gif" height="1" width="220"><br></td>
</tr>
<tr>
<td valign="top"><b>Commercial</b></td>
<td valign="top"><b><center><a href="newsearch.idx">$newcount{comm}</a> <a href="newsearch.idx"><img src="images/view.gif" border="0" alt="Search New Listings"></a></center></td>
<td valign="top"><b><center><a href="updatedsearch.idx">$updatedcount{comm}</a> <a href="updatedsearch.idx"><img src="images/view.gif" border="0" alt="Search Updated Listings"></a></center></td>
</tr>
<tr>
<td colspan="3"><img src="images/black_fill.gif" height="1" width="220"><br></td>
</tr>
<tr>
<td valign="top"><b>Investment</b></td>
<td valign="top"><b><center><a href="newsearch.idx">$newcount{inv}</a> <a href="newsearch.idx"><img src="images/view.gif" border="0" alt="Search New Listings"></a></center></td>
<td valign="top"><b><center><a href="updatedsearch.idx">$updatedcount{inv}</a> <a href="updatedsearch.idx"><img src="images/view.gif" border="0" alt="Search Updated Listings"></a></center></td>
</tr>
<tr>
<td colspan="3"><img src="images/black_fill.gif" height="1" width="220"><br></td>
</tr>
<tr>
<td valign="top"><b>Lots & Land</b></td>
<td valign="top"><b><center><a href="newsearch.idx">$newcount{lan}</a> <a href="newsearch.idx"><img src="images/view.gif" border="0" alt="Search New Listings"></a></center></td>
<td valign="top"><b><center><a href="updatedsearch.idx">$updatedcount{lan}</a> <a href="updatedsearch.idx"><img src="images/view.gif" border="0" alt="Search Updated Listings"></a></center></td>
</tr>

</table>

</td>
</tr>
</table>
<img src="images/line_spacer.gif" height="6" width="1"><Br>
<img src="images/myhomes/my_activity.gif" alt="Activity" height="25" width="220"><br>
<table border="0" cellpadding="0" cellspacing="1" width="220" bgcolor="#999999">
<tr>
<td valign="top" width="100%" bgcolor="#FFFF99">


<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr bgcolor="#000099">
<td colspan="3"><font color="white"><b>My Current Activity</b></font></td>
</tr>
<tr bgcolor="#FFFFFF">
<td valign="top"><b><a href="myhomes.idx?action=savedlistings">My Current Saved Listings</a></b></td>
<td valign="top"><center><b>$savelistingcount</b></center></td>
</tr>
<tr bgcolor="#E2E2E2">
<td valign="top"><b><a href="myhomes.idx?action=savedsearches">My Current Saved Searches</a></b></td>
<td valign="top"><center><b>$savesearchcount</b></center></td>
</tr>
<tr bgcolor="#FFFFFF">
<td valign="top"><b><a href="myhomes.idx?action=notifications">My Notifications</a></b></td>
<td valign="top"><center><b>$savenotificationscount</b></center></td>
</tr>
</table>

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






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

</td>



~;

&footer;

}
#}
}


sub savedlistings {

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 $uasth = $dbh->prepare("select * from users where userid = '$Cook{userid}'");
$uasth->execute;

my $iasth = $dbh->prepare("select * from home_fav where userid = '$Cook{userid}' order by favid desc");
$iasth->execute;

while (($userid,$email,$_password,$myfirstname,$mylastname,$address,$city,$state,$zipcode,$timetomove,$realtor,$datestamp,$lastlogin) = $uasth->fetchrow_array()) {
$savefirstname = $myfirstname;
$savelastname = $mylastname;

$savefirstname =~ s/CHR2/\"/gi;
$savelastname =~ s/CHR2/\"/gi;
$savefirstname =~ s/CHR1/\'/gi;
$savelastname =~ s/CHR1/\'/gi;
print <<"TITLE";
<html>
<head>
<title>Eagle Real Estate, Inc. - MuncieMLS.com</title>
TITLE

&header;


print qq~
<td valign="top" width="581">
<table border="0" cellpadding="0" cellspacing="0" width="581">
<tr>
<td valign="top" colspan="2" width="581">
<img src="images/headers/myhomes_account.gif" height="33" width="581" alt="MY HOMES Account"><br>
<img src="images/myhomes/menu/left.gif" width="61" height="20"><a href="myhomes.idx"><img src="images/myhomes/menu/summary.gif" width="86" height="20" border="0" alt="Summary"></a><img src="images/myhomes/menu/divider1.gif" width="3" height="20"><a href="myhomes.idx?action=savedlistings"><img src="images/myhomes/menu/savedlistings_b.gif" width="113" height="20" border="0" alt="My Saved Listings"></a><img src="images/myhomes/menu/divider1.gif" width="3" height="20"><a href="myhomes.idx?action=savedsearches"><img src="images/myhomes/menu/savedsearches.gif" width="120" height="20" border="0" alt="My Saved Searches"></a><img src="images/myhomes/menu/divider1.gif" width="3" height="20"><a href="myhomes.idx?action=notifications"><img src="images/myhomes/menu/notifications.gif" width="83" height="20" border="0" alt="My Notifications"></a><img src="images/myhomes/menu/divider1.gif" width="3" height="20"><a href="myhomes.idx?action=updateprofile"><img src="images/myhomes/menu/updateaccount.gif" width="106" height="20" border="0" alt="Update Account"></a><br>
</td>
</tr>
<tr>
<td valign="Top"><img src="images/line_spacer.gif" width="581" height="4"><br></td>
</tr>
<tr>
<td width="581" valign="top"><br>
<img src="images/myhomes/saved_listings.gif" width="350" height="25" alt="Saved Listings"><br>


<table border="0" cellpadding="0" cellspacing="0" width="581">
  <tr>
    <td width="581"><img src="images/myhomes/myhomes_line.gif" height="1" width="581"><br></td>
  </tr>
</table>


<table border="0" cellpadding="0" cellspacing="1" width="581" bgcolor="#999999">
<tr>
<td valign="top" width="100%">

<table border="0" cellpadding="2" cellspacing="0" width="579">
  <tr bgcolor="#CCCCCC">
	<td valign="top" width="55"><img src="images/line_spacer.gif" height="1" width="55" alt="spacer"><br></td>
	<td valign="top"><b>Listing Overview</b><br></td>
	<td valign="top"><b>Description</b><br></td>
	<td valign="top"><b>Actions</b><br></td>
  </tr>
<tr>
~;


$startcount = "1";

while (($userid,$favid,$mlsnumber,$listingtype,$notes) = $iasth->fetchrow_array()) {
$jasth = $dbh->prepare("select AddressNumber,AddressDirection,AddressStreet,City,Zip,Remarks from listings_$listingtype where MLSNUM = '$mlsnumber'");
$jasth->execute;

if ($startcount eq "2") {
$startcount = "1";
$bgcolor = "FFFF99";
}
else {
$startcount++;
$bgcolor = "white";
}

$foundlistings = "yes";

while (($AddressNumber,$AddressDirection,$AddressStreet,$City,$Zip,$Remarks) = $jasth->fetchrow_array()) {
$found_it{$mlsnumber} = "yes";




$notes =~ s/CHR1/\'/gi;
$notes =~ s/CHR2/\"/gi;


if ($listingtype eq "res") {
$extension = "";
}
elsif ($listingtype eq "comm") {
$extension = "\_commercial";
}
elsif ($listingtype eq "inv") {
$extension = "\_investment";
}
elsif ($listingtype eq "lan") {
$extension = "\_land";
}
else {
}


if (-e "/home/muncieml/public_html/images/photos/myhomes/meiarmls$mlsnumber.jpg") {
$showpicture = "images/photos/myhomes/meiarmls$mlsnumber.jpg";
}
else {
$showpicture = "images/myhomes_nophoto.jpg";
}

print qq~

<tr bgcolor="$bgcolor">
	<td rowspan="2" width="55" valign="top">
	<a href="showdetails$extension.idx?mlsnumber=$mlsnumber">
	<img src="$showpicture" border="0" width="55" height="38">
	</a>
	</td>
	<td valign="top" width="150">
		$AddressNumber $AddressDirection $AddressStreet<br>
		$City, $state $Zip<br>
		MLS #<a href="showdetails$extension.idx?mlsnumber=$mlsnumber">$mlsnumber</a>
	</td>
	<td valign="top" width="275">
		$Remarks
	</td>
	<td valign="top" width="99">
		
		<a href="myhomes.idx?action=deletehome&ID=$favid"><img src="images/myhomes/deletelisting.gif" border="0"></a><br>
		<a href="showdetails.idx?mlsnumber=$mlsnumber#requestshowing"><img src="images/myhomes/requestashowing.gif" border="0"></a><br>
		
	</td>
</tr>
<tr bgcolor="$bgcolor">
<td colspan="3" valign="top">Notes: <b>$notes</b>
</td>
</tr>

~;
}

unless ($found_it{$mlsnumber} eq "yes") {
print qq~<tr bgcolor="$bgcolor"><td colspan=3 valign=middle><center><font size=1><b>MLS # $mlsnumber is no longer on the market</td><td valign=middle><a href="myhomes.idx?action=deletehome&ID=$favid"><img src="images/myhomes/deletelisting.gif" border="0" alt="Delete Favorite"></a></td></tr>~;
}

}

unless ($foundlistings eq "yes") {
print "<tr><td><font color=white><b>You have not saved any listings yet!</b></font></td></tr>";
}

print qq~

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



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

</td>



~;

&footer;

}
}

sub savedsearches {



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 $uasth = $dbh->prepare("select * from users where userid = '$Cook{userid}'");
$uasth->execute;

my $pasth = $dbh->prepare("select * from search_fav where userid = '$Cook{userid}' order by favid asc");
$pasth->execute;

while (($userid,$email,$_password,$myfirstname,$mylastname,$address,$city,$state,$zipcode,$timetomove,$realtor,$datestamp,$lastlogin) = $uasth->fetchrow_array()) {
$savefirstname = $myfirstname;
$savelastname = $mylastname;

$savefirstname =~ s/CHR2/\"/gi;
$savelastname =~ s/CHR2/\"/gi;
$savefirstname =~ s/CHR1/\'/gi;
$savelastname =~ s/CHR1/\'/gi;

print <<"TITLE";
<html>
<head>
<title>Eagle Real Estate, Inc. - MuncieMLS.com</title>
TITLE

&header;


print qq~
<td valign="top" width="581">
<table border="0" cellpadding="0" cellspacing="0" width="581">
<tr>
<td valign="top" colspan="2" width="581">
<img src="images/headers/myhomes_account.gif" height="33" width="581" alt="MY HOMES Account"><br>
<img src="images/myhomes/menu/left.gif" width="61" height="20"><a href="myhomes.idx"><img src="images/myhomes/menu/summary.gif" width="86" height="20" border="0" alt="Summary"></a><img src="images/myhomes/menu/divider1.gif" width="3" height="20"><a href="myhomes.idx?action=savedlistings"><img src="images/myhomes/menu/savedlistings.gif" width="113" height="20" border="0" alt="My Saved Listings"></a><img src="images/myhomes/menu/divider1.gif" width="3" height="20"><a href="myhomes.idx?action=savedsearches"><img src="images/myhomes/menu/savedsearches_b.gif" width="120" height="20" border="0" alt="My Saved Searches"></a><img src="images/myhomes/menu/divider1.gif" width="3" height="20"><a href="myhomes.idx?action=notifications"><img src="images/myhomes/menu/notifications.gif" width="83" height="20" border="0" alt="My Notifications"></a><img src="images/myhomes/menu/divider1.gif" width="3" height="20"><a href="myhomes.idx?action=updateprofile"><img src="images/myhomes/menu/updateaccount.gif" width="106" height="20" border="0" alt="Update Account"></a><br>
</td>
</tr>
<tr>
<td colspan="2" valign="Top"><img src="images/line_spacer.gif" width="581" height="4"><br></td>
</tr>
<tr>
<td width="581" valign="top">

<br><br>
<img src="images/myhomes/saved_searches.gif" alt="Saved Searches" width="350" height="25"><br>
<table border="0" cellpadding="0" cellspacing="1" width="581" bgcolor="#999999">
<tr>
<td valign="top" width="100%">

<table border="0" cellpadding="3" cellspacing="0" width="100%">
<tr bgcolor="#CCCCCC">
<td>Search Name</td>
<td>Do Search</td>
<td>Notification</td>
<td>Delete</td>
</tr>

~;

$startcountingit = "1";

while (($userid,$favid,$searchstring,$searchname,$searchtype,$status) = $pasth->fetchrow_array()) {

unless ($searchname) {
$searchname = "Favorite Search";
}


if ($status eq "0") {
$showstatus = "<font color=\"red\"><b>Stopped</b></font>";
$showtoggle = "Start";
$showstyle = "green";
}
else {
$showstatus = "<font color=\"green\"><b>Running</b></font>";
$showtoggle = "Stop";
$showstyle = "red";
}

$foundsearch = "Yes";


if ($status eq "1") {
$notifications = "<font color=green><b>Running</b> <a href=\"myhomes.idx?action=togglenotify&searchid=$favid\">Stop</a></font>"
}
else {
$notifications = "<font color=red><b>Stopped</b> <a href=\"myhomes.idx?action=togglenotify&searchid=$favid\">Start</a></font>"
}


if ($startcountingit eq "2") {
$showbgcolor = "FFFF99";
$startcountingit = "1";
}
else {
$showbgcolor = "white";
$startcountingit++;
}

if ($searchtype eq "res") {
$extension = "";
}
else {
$extension = "\_$searchtype";
}

print qq~

<tr bgcolor="$showbgcolor">
<td><b>$searchname</b></td>
<td><a href="search$extension.idx?$searchstring">Click To Search</a></td>
<td>$notifications</td>
<td>
<a href="myhomes.idx?action=deletesearch&ID=$favid"><img src="images/myhomes_delete.gif" border="0" alt="Delete Search"></a>
</td>
</tr>

~;
}

if ($foundsearch eq "Yes") {
}
else {
$mynotifystuff = "<tr><td><b>A Search Must Be Saved To Enable Notifications</b></td></tr>";
}

unless ($foundsearch eq "Yes") {
print "<tr><td><font color=white><b>You have not saved any searches yet!</b></font></td></tr>";
}

print qq~

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


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

</td>



~;

&footer;

}
}

sub notifications {

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 $uasth = $dbh->prepare("select * from users where userid = '$Cook{userid}'");
$uasth->execute;


if ($INPUT{searchid}) {

my $oasth = $dbh->prepare("select wireless,email,status from search_fav where favid = '$INPUT{searchid}'");
$oasth->execute;

while (($wireless,$email,$stat) = $oasth->fetchrow_array()) {
$statusi = $stat;
#print "Status is $statusi<br>";
}

}

if ($statusi eq "1" && $turnedon ne "yes") {
my $yasth = $dbh->do("update search_fav set status = '0' where favid = '$INPUT{searchid}'");
#print "Changed $INPUT{searchid} to 0<br>";
$waslive = "yes";
}



my $pasth = $dbh->prepare("select * from search_fav where userid = '$Cook{userid}' order by favid asc");
$pasth->execute;

print <<"TITLE";
<html>
<head>
<title>Eagle Real Estate, Inc. - MuncieMLS.com</title>
TITLE

&header;


print qq~
<td valign="top" width="581">

<table border="0" cellpadding="0" cellspacing="0" width="581">
<tr>
<td valign="top" colspan="2" width="581">
<img src="images/headers/myhomes_account.gif" height="33" width="581" alt="MY HOMES Account"><br>
<img src="images/myhomes/menu/left.gif" width="61" height="20"><a href="myhomes.idx"><img src="images/myhomes/menu/summary.gif" width="86" height="20" border="0" alt="Summary"></a><img src="images/myhomes/menu/divider1.gif" width="3" height="20"><a href="myhomes.idx?action=savedlistings"><img src="images/myhomes/menu/savedlistings.gif" width="113" height="20" border="0" alt="My Saved Listings"></a><img src="images/myhomes/menu/divider1.gif" width="3" height="20"><a href="myhomes.idx?action=savedsearches"><img src="images/myhomes/menu/savedsearches.gif" width="120" height="20" border="0" alt="My Saved Searches"></a><img src="images/myhomes/menu/divider1.gif" width="3" height="20"><a href="myhomes.idx?action=notifications"><img src="images/myhomes/menu/notifications_b.gif" width="83" height="20" border="0" alt="My Notifications"></a><img src="images/myhomes/menu/divider1.gif" width="3" height="20"><a href="myhomes.idx?action=updateprofile"><img src="images/myhomes/menu/updateaccount.gif" width="106" height="20" border="0" alt="Update Account"></a><br>
</td>
</tr>
<tr>
<td colspan="2" valign="Top"><img src="images/line_spacer.gif" width="581" height="4"><br></td>
</tr>
<tr>
<td width="290" valign="top">
<br><br>

~;

$startcountingit = "1";

while (($userid,$favid,$searchstring,$searchname,$searchtype,$status) = $pasth->fetchrow_array()) {

unless ($searchname) {
$searchname = "Favorite Search";
}


if ($status eq "0") {
$showstatus = "<font color=\"red\"><b>Stopped</b></font>";
$showtoggle = "Start";
$showstyle = "green";
}
else {
$showstatus = "<font color=\"green\"><b>Running</b></font>";
$showtoggle = "Stop";
$showstyle = "red";
}

$foundsearch = "Yes";

$mynotifystuff .= "<tr><td valign=\"top\"><b>$searchname</td><td valign=\"top\">$showstatus<br></td><td valign=\"top\"><center><a href=\"myhomes.idx?action=togglenotify&searchid=$favid\" class=\"$showstyle\">$showtoggle</a></center></td></tr>\n\n";

if ($startcountingit eq "2") {
$showbgcolor = "FFFF99";
$startcountingit = "1";
}
else {
$showbgcolor = "white";
$startcountingit++;
}

if ($searchtype eq "res") {
$extension = "";
}
else {
$extension = "\_$searchtype";
}

}

if ($foundsearch eq "Yes") {
}
else {
$mynotifystuff = "<tr><td><b>A Search Must Be Saved To Enable Notifications</b></td></tr>";
}

unless ($foundsearch eq "Yes") {
#print "<tr><td><font color=white><b>You have not saved any searches yet!</b></font></td></tr>";
}

print qq~

<img src="images/myhomes/my_notifications.gif" alt="My Notifications"><br>


<table border="0" cellpadding="0" cellspacing="1" width="290" bgcolor="#999999">
<tr>
<td valign="top" width="100%" bgcolor="#FFFF99">
	<table border="0" width="100%" cellpadding="1" cellspacing="0">
	<tr bgcolor="#CCCCCC">
	<td colspan="3">View/Edit Your E-Mail Or Wireless Notifications</td>
	</tr>
	<tr bgcolor="#000099">
	<td valign="top"><b><font color="white">Name</font></b></td>
	<td valign="top"><b><font color="white">Status</font></b></td>
	<td valign="top"><center><b><font color="white"></font></b></td>
	</tr>
	$mynotifystuff
	</table>
</td>
</tr>
</table>



</td>
<td width="290" valign="top">
<br><br>


~;






if ($INPUT{action} eq "notifications" || $statusi eq "1" || $INPUT{action} eq "savetogglenotify" || $turnedon eq "yes") {



print qq~

<font size="3"><b>Update Box</b></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<b>You may change your notification settings by clicking on the start and stop buttons in the notification box to the left</b><br>

</td>


~;
}


#print "Action: $INPUT{action}<br>Statusi: $statusi<br>Was Live: $waslive<br>Turned on: $turnedon<br>";


if ($INPUT{action} eq "togglenotify" && $statusi eq "0" && $waslive ne "yes") {

#stopped and needs information

if ($email) {
$showemail = "$email";
}
else {
$showemail = "$Cook{email}";
}

if ($wireless eq "y") {
$checkedyes = " checked";
$checkedno = "";
}
else {
$checkedyes = "";
$checkedno = " checked";
}


my $apasth = $dbh->prepare("select searchname from search_fav where favid = '$INPUT{searchid}'");
$apasth->execute;
while (($searchname) = $apasth->fetchrow_array()) {
$sname = $searchname;
}

print qq~
<table border="0" cellpadding="5" cellspacing="0" width="290">
<tr>
<td valign=top width="100%">
<form method=post action=myhomes.idx>
<input type=hidden name=action value=savetogglenotify>
<input type=hidden name=searchid value="$INPUT{searchid}">
	<table border="0" cellpadding="1" cellspacing="0" width="100%" bgcolor="white">
	<tr>
	<td bgcolor="white" valign="top" colspan="2"><font size="2" color="navy"><b>Setup Notification For</b></font><br><b><font color="red"><u>$sname</u></font></b><br><br></td>
	</tr><tr>
	<td bgcolor="white" valign="top"><b><font color="navy"><u>E-Mail Address Notifications Will Be Sent To:</u></font></b><br>$showemail<input type=hidden name=email size=25 value="$showemail"><br>
	<input type="hidden" name="wireless" value="n">
	<center><br><input type=submit value="Start Notification"></center>
	</td>
	</tr>
	</table>
</form>
</td>
</tr>
</table>
</td>

~;



}

&footer;

}

