#!/usr/bin/perl
print "Content-type: text/html\n\n";
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; }
	}
}

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 "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 "useroverview")				{ &useroverview; }
elsif ($INPUT{action} eq "userlisting")				{ &userlisting; }
elsif ($INPUT{action} eq "removeuser")				{ &removeuser; }
elsif ($INPUT{action} eq "runremoveuser")			{ &runremoveuser; }
elsif ($INPUT{action} eq "massemail")				{ &massemail; }
elsif ($INPUT{action} eq "massemailtemplate")			{ &massemailtemplate; }
elsif ($INPUT{action} eq "giveaccess")				{ &giveaccess; }
elsif ($INPUT{action} eq "addcolumn")				{ &addcolumn; }
elsif ($INPUT{action} eq "agents")				{ &agents; }
elsif ($INPUT{action} eq "agentadd")				{ &agentadd; }
elsif ($INPUT{action} eq "agentdoadd")				{ &agentdoadd; }
elsif ($INPUT{action} eq "agentedit")				{ &agentedit; }
elsif ($INPUT{action} eq "agentdoedit")				{ &agentdoedit; }
elsif ($INPUT{action} eq "agentdelete")				{ &agentdelete; }
elsif ($INPUT{action} eq "grantagentaccess")			{ &grantagentaccess; }
elsif ($INPUT{action} eq "leadcenter")				{ &leadcenter; }
elsif ($INPUT{action} eq "newagent")				{ &newagent; }
elsif ($INPUT{action} eq "leadcentercheckchanges")		{ &leadcentercheckchanges; }
elsif ($INPUT{action} eq "email")				{ &email; }
elsif ($INPUT{action} eq "openhousemm")				{ &openhousemm; }
elsif ($INPUT{action} eq "openhousemm_send")			{ &openhousemm_send; }
elsif ($INPUT{action} eq "fixusernames")			{ &fixusernames; }
elsif ($INPUT{action} eq "view_email")				{ &view_email; }
elsif ($INPUT{action} eq "detailedhits")			{ &detailedhits; }
else { &main; }

sub detailedhits {

if ($INPUT{detail} eq "yes") {
print qq~
<a href="admin.idx?action=detailedhits&detail=no">Hide Detailed Report</a><br>
~;
}
else {
print qq~
<a href="admin.idx?action=detailedhits&detail=yes">Show Detailed Report</a><br>
~;
}

my $counthsth = $dbh->prepare("select COUNT(mlsnumber) from hits");
$counthsth->execute;
while (($count_hits) = $counthsth->fetchrow_array()) {
print qq~
$count_hits Residential Property Views<br>
~;
}

my $acasth = $dbh->prepare("select userid from hits GROUP BY userid");
$acasth->execute;
while (($userid) = $acasth->fetchrow_array()) {
	my $bcasth = $dbh->prepare("select firstname,lastname from users where userid = '$userid'");
	$bcasth->execute;
	while (($firstname,$lastname) = $bcasth->fetchrow_array()) {
			my $chcasth = $dbh->prepare("select count(mlsnumber) from hits where userid = '$userid'");
			$chcasth->execute;
			while (($cmlsnumber) = $chcasth->fetchrow_array()) {
	print qq~
		<font face="Tahoma" size="2"><b><u>$firstname $lastname</u> User ID \#$userid   ( $cmlsnumber )</b><br>
	~;
	if ($INPUT{detail} eq "yes") {
		my $ccasth = $dbh->prepare("select mlsnumber,time from hits where userid = '$userid'");
		$ccasth->execute;
		while (($mlsnumber,$time) = $ccasth->fetchrow_array()) {

			my $dcasth = $dbh->prepare("select MLSNUM,Price,AddressNumber,AddressDirection,AddressStreet,City from listings_res3 where MLSNUM = '$mlsnumber'");
			$dcasth->execute;
			while (($MLSNUM,$Price,$AddressNumber,$AddressDirection,$AddressStreet,$City) = $dcasth->fetchrow_array()) {
			print qq~
			 --> $AddressNumber $AddressDirection $AddressStreet, $City  $Price  MLS\# $mlsnumber viewed on $time<br>
			~;
			}
		}
	}
	}
	}
}




}

sub view_email {
my $emailsasth = $dbh->prepare("select emaildatetime,emailfrom,subject,message from emailstousers where emailid = '$INPUT{emailid}'");
$emailsasth->execute;
while (($emailtimedate,$emailfrom,$subject,$message) = $emailsasth->fetchrow_array()) {
print qq~
<b>Sent on $emailtimedate by $emailfrom<br>Subject: $subject</b><br>
$message
~
}

}

sub fixusernames {

&header;
&startmain;

$gasth = $dbh->prepare("select userid,firstname,lastname from users");
$gasth->execute;

while (($db_userid,$db_firstname,$db_lastname) = $gasth->fetchrow_array()) {
$new_firstname = ucfirst(lc($db_firstname));
$new_lastname = ucfirst(lc($db_lastname));
$sql_query = qq~update users set firstname = ?, lastname = ? where userid = ?~;
@vars = ($new_firstname,$new_lastname,$db_userid);
$iasth = $dbh->do($sql_query, undef, @vars);
print "-- fixed $db_firstname $db_lastname<br>";
}

print "</td>";
&footer;
}

sub openhousemm_send {

my $aabasth = $dbh->prepare("select COUNT(userid) from users where email_openhouses = 'y';");
$aabasth->execute;
while (($aacountuserid) = $aabasth->fetchrow_array()) {
$aatotalcount = $aacountuserid;
}


&header;
&startmain;

print qq~
$aatotalcount E-Mails Will Be Sent!</b><br><br>

<font size="4" color="green"><b>DO NOT HIT REFRESH WHILE LOOKING AT THIS PAGE</b></font><br><br>
<a href="http://www.munciemls.com/admin.idx">CLICK HERE WHEN PAGE IS FINISHED LOADING!</a><br><br><b>A list of the Open House receipients will follow with email status</b><br><br>

~;


my $aasth = $dbh->prepare("select userid,email,firstname,lastname from users where email_openhouses = 'y'");
$aasth->execute;
while (($userid,$cemail,$cfirstname,$clastname) = $aasth->fetchrow_array()) {

		open(MAIL,"|/usr/sbin/sendmail -t");
		print MAIL "To: $cemail\n";
		#print MAIL "To: ryan\@orrhomes.com\n";
		print MAIL "From: OpenHouses\@EagleSold.com\n";
		print MAIL "Subject: Weekly Eagle OpenHouse List From MuncieMLS.com\n";
		print MAIL "Content-type: text/html\n\n";
		print MAIL qq~
		<html>
		<head>
		<title>Official Eagle Real Estate, Inc. E-Mail</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">
		<font face="Georgia" size="3"><b>$cfirstname, The latest Eagle Open Houses from <a href="http://www.MuncieMLS.com">www.MuncieMLS.com</a> are below</b></font><br><br>
		~;
		###################### GET OPENHOUSE LIST ##########################################

		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 id,status,house,agent,nday,month,day,atimehour,atimeminute,btimehour,btimeminute,timeap FROM openhouses WHERE status = 'a' ORDER BY id ASC");
		$abasth->execute;

		print MAIL qq~
		<table border="0" cellpadding="6" cellspacing="0" width="100%">
		<tr>
		~;

		$trcount = "1";
		$totalperrow = "3";  # Number of agents per row

		while (($id,$status,$house,$agent,$nday,$month,$day,$atimehour,$atimeminute,$btimehour,$btimeminute,$timeap) = $abasth->fetchrow_array()) {

		$found = "yes";

		if (-e "/home/muncieml/public_html/images/photos/thumbnail/meiarmls$house\.jpg") {
		$showpicture = "http://www.munciemls.com/images/photos/thumbnail/meiarmls$house\.jpg";
		}
		else {
		$showpicture = "http://www.munciemls.com/images/photos/search_nophoto.gif";
		}
	
		my $aasth = $dbh->prepare("select Price,AddressNumber,AddressDirection,AddressStreet,City,Zip,MLSNUM,AgentID,Directions FROM listings_res3 where MLSNUM = '$house'");
		$aasth->execute;
		my $basth = $dbh->prepare("select agentid,firstname,lastname from agents WHERE agentid = '$agent'");
		$basth->execute;

		while (($Price,$AddressNumber,$AddressDirection,$AddressStreet,$City,$Zip,$MLSNUM,$AgentID,$Directions) = $aasth->fetchrow_array()) {
		if (-e "/home/muncieml/public_html/pdf/$house\.pdf") {
		$showpdf = "
		<table border=\"0\" cellpadding=\"4\" cellspacing=\"0\">
		<tr>
		<td valign=\"top\">
		<a href=\"http://www.munciemls.com/pdf/$house.pdf\" target=\"_blank\"><img src=\"http://www.munciemls.com/images/pdficon.gif\" border=\"0\"></a><br>
		</td>
		<td valign=\"middle\">
		<a href=\"http://www.munciemls.com/pdf/$house.pdf\" target=\"_blank\">View Full Color<br>PDF Brochure</a><br>
		</td>
		</tr>
		</table>
		<br>
		";
		}
		else {
		$showpdf = "";
		}
		while (($agentid,$firstname,$lastname) = $basth->fetchrow_array()) {
			print MAIL qq~
				<td valign="top" width="193">
				<center>
				<font size="2" face="Arial" color="red"><b>Open $nday $month $day</b></font><br>
				<font size="3" color="red">
				<b>$atimehour:$atimeminute to $btimehour:$btimeminute $timeap</b></font>
				<br>
				Host <a href="http://www.munciemls.com/agents.idx?action=viewagent&agent=$agentid">$firstname $lastname</a><br>
				<img src="$showpicture"><br>
				<b><font color="navy" size="2">$AddressNumber $AddressDirection $AddressStreet<br>$City, IN $Zip</font></b><br>
				<a href="http://www.munciemls.com/showdetails_print.idx?mlsnumber=$house" target="_blank"><img src="http://www.munciemls.com/images/print_data_flyer.gif" border="0"></a><br>
				</center>
				<font size="2"><b>Directions:</b> $Directions$DirectionsContinued</font><br>$showpdf
				<br>
			   </td>
			~;
		}

		if ($trcount eq $totalperrow) {
		print MAIL qq~ 
		</tr><tr>
		~;
		$trcount = "1";
		}
		else {
		$trcount++;
		}
	
		}

		}
	unless ($found eq "yes") {
		print MAIL qq~
		<td valign="top" width="100%">
		<font size="4"><b><center>
		Were sorry, There are currently no open houses scheduled for this week.  You may login to <br><br><a href="http://OpenHouses.MuncieMLS.com/">http://OpenHouses.MuncieMLS.com/</a> to see the latest open houses.<br>
		</center></b></font>
		</td>
		~;
	}
		print MAIL qq~
		</tr>
		</table>
		~;
		###################### END GET OPENHOUSE LIST ##########################################
		print MAIL qq~
		<br><br><br>
		</font>
		</td>
		</tr>
		</table>
		You may block further e-mails from this mailing by <a href="http://www.munciemls.com/unsubscribe.idx?type=email_openhouses&userid=$cemail">clicking here</a>.<br>
		<img src="http://www.munciemls.com/images/emailfooter.gif"><br><br><br>
		</td>
		</tr>
		</table>
		</center>
		</body>
		</html>
		~;
		close(MAIL);
		print "  --> Sent To <b>$cemail</b> - <b>$cfirstname $clastname</b><br>";
}

print qq~
</td>
~;
&footer;

}

sub openhousemm {

&header;
&startmain;
print qq~

<br><br> Go ----> <a href="admin.idx?action=openhousemm_send">Preview Looks OK, Send MASS E-Mails Out Now</a><br><br>

<b>Preview Message To Send:</b><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">
		<font face="Georgia" size="3"><b>$cfirstname, The latest Eagle Open Houses from <a href="http://www.MuncieMLS.com">www.MuncieMLS.com</a> are below</b></font><br><br>
~;
###################### GET OPENHOUSE LIST ##########################################

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 id,status,house,agent,nday,month,day,atimehour,atimeminute,btimehour,btimeminute,timeap FROM openhouses WHERE status = 'a' ORDER BY id ASC");
$abasth->execute;

print qq~
<table border="0" cellpadding="6" cellspacing="0" width="100%">
<tr>
~;

$trcount = "1";
$totalperrow = "3";  # Number of agents per row

while (($id,$status,$house,$agent,$nday,$month,$day,$atimehour,$atimeminute,$btimehour,$btimeminute,$timeap) = $abasth->fetchrow_array()) {

$found = "yes";

if (-e "/home/muncieml/public_html/images/photos/thumbnail/meiarmls$house\.jpg") {
$showpicture = "http://www.munciemls.com/images/photos/thumbnail/meiarmls$house\.jpg";
}
else {
$showpicture = "http://www.munciemls.com/images/photos/search_nophoto.gif";
}


my $aasth = $dbh->prepare("select Price,AddressNumber,AddressDirection,AddressStreet,City,Zip,MLSNUM,AgentID,Directions FROM listings_res3 where MLSNUM = '$house'");
$aasth->execute;
my $basth = $dbh->prepare("select agentid,firstname,lastname from agents WHERE agentid = '$agent'");
$basth->execute;

	while (($Price,$AddressNumber,$AddressDirection,$AddressStreet,$City,$Zip,$MLSNUM,$AgentID,$Directions) = $aasth->fetchrow_array()) {
if (-e "/home/muncieml/public_html/pdf/$house\.pdf") {
$showpdf = "
<table border=\"0\" cellpadding=\"4\" cellspacing=\"0\">
<tr>
<td valign=\"top\">
<a href=\"pdf/$house.pdf\" target=\"_blank\"><img src=\"images/pdficon.gif\" border=\"0\"></a><br>
</td>
<td valign=\"middle\">
<a href=\"pdf/$house.pdf\" target=\"_blank\">View Full Color<br>PDF Brochure</a><br>
</td>
</tr>
</table>
<br>
";
}
else {
$showpdf = "";
}
		while (($agentid,$firstname,$lastname) = $basth->fetchrow_array()) {
			print qq~
				<td valign="top" width="193">
				<center>
				<font size="2" face="Arial" color="red"><b>Open $nday $month $day</b></font><br>
				<font size="3" color="red">
				<b>$atimehour:$atimeminute to $btimehour:$btimeminute $timeap</b></font>
				<br>
				Host <a href="agents.idx?action=viewagent&agent=$agentid">$firstname $lastname</a><br>
				<img src="$showpicture"><br>
				<b><font color="navy" size="2">$AddressNumber $AddressDirection $AddressStreet<br>$City, IN $Zip</font></b><br>
				<a href="showdetails_print.idx?mlsnumber=$house" target="_blank"><img src="images/print_data_flyer.gif" border="0"></a><br>
				</center>
				<font size="2"><b>Directions:</b> $Directions$DirectionsContinued</font><br>$showpdf
				<br>
			   </td>
			~;
		}

	if ($trcount eq $totalperrow) {
	print "</tr><tr>";
	$trcount = "1";
	}
	else {
	$trcount++;
	}

	}
	}
	unless ($found eq "yes") {
		print qq~
		<td valign="top" width="100%">
		<font size="4"><b><center>
		Were sorry, There are currently no open houses scheduled for this week.  You may login to <br><br><a href="http://OpenHouses.MuncieMLS.com/">http://OpenHouses.MuncieMLS.com/</a> to see the latest open houses.<br>
		</center></b></font>
		</td>
		~;
	}
print qq~
</tr>
</table>
~;

		###################### END GET OPENHOUSE LIST ##########################################
		print qq~
		<br><br><br>
		</font>
		</td>
		</tr>
		</table>
		You may block further e-mails from this mailing by <a href="http://www.munciemls.com/unsubscribe.idx?type=email_block&userid=$email">clicking here</a>.<br>
		<img src="http://www.munciemls.com/images/emailfooter.gif"><br><br><br>
		</td>
		</tr>
		</table>
		</center>
	</td>
		~;

&footer;
}

sub email {

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->do("select userid,email,password,firstname,lastname,address,city,state,zipcode,timetomove,realtor,datestamp,lastlogin,FoundBy,UserType,myERAAgent,Phone,access,tos_agreement,agentid,email_block,email_openhouses from users where email = '$INPUT{emailaddress}'");
while (($userid,$email,$password,$firstname,$lastname,$address,$city,$state,$zipcode,$timetomove,$realtor,$datestamp,$lastlogin,$FoundBy,$UserType,$myERAAgent,$Phone,$access,$tos_agreement,$agentid,$email_block,$email_openhouses) = $aasth->fetchrow_array()) {

}
$dbh->disconnect;
}

sub leadcentercheckchanges {
print qq~
<br><br>
~;
my $basth = $dbh->prepare("SELECT userid,agentassigned FROM leadtracking WHERE agentassigned != 'notassigned' ORDER BY userid ASC");
$basth->execute;
while (($userid,$agentassigned) = $basth->fetchrow_array()) {
	my $casth = $dbh->prepare("SELECT userid,firstname,lastname,myERAAgent FROM users WHERE userid = '$userid'");
	$casth->execute;
	while (($userid2,$firstname,$lastname,$myERAAgent) = $casth->fetchrow_array()) {

		if ($myERAAgent ne $agentassigned) {
		print qq~
		<font size="3"><font color="red"><b>Automatically Rerouted A Lead!</b></font></font><br>
		~;
			my $dasth = $dbh->do("update leadtracking set agentassigned = '$myERAAgent' WHERE userid = '$userid'");
		print qq~
			<font color="Red">$firstname $lastname Has Automatically Been Rerouted From $agentassigned To $myERAAgent</font><br>
		~;
		}
	}
}
}

sub leadcenter {

&header;
&startmain;

my $basth = $dbh->prepare("SELECT userid FROM leadtracking WHERE agentassigned = 'notassigned' ORDER BY userid ASC");
$basth->execute;
while (($userid) = $basth->fetchrow_array()) {
	my $casth = $dbh->prepare("SELECT userid,firstname,lastname,myERAAgent FROM users WHERE userid = '$userid'");
	$casth->execute;
	while (($userid2,$firstname,$lastname,$myERAAgent) = $casth->fetchrow_array()) {

		if ($myERAAgent) {

			my $dasth = $dbh->do("update leadtracking set agentassigned = '$myERAAgent' WHERE userid = '$userid'");
		}
		else {
		print qq~
			$userid $firstname $lastname $myERAAgent $agentassigned<br>
		~;
		}
	}
}

my $aasth = $dbh->prepare("SELECT COUNT(userid) FROM leadtracking WHERE agentassigned = 'notassigned'");
$aasth->execute;
while (($userid) = $aasth->fetchrow_array()) {
$needassignedcount = "$userid";
}

print qq~
<br><br>
Total Count $needassignedcount

~;
$dbh->disconnect;
&leadcentercheckchanges;
print qq~
</td>
~;
&footer;
}


sub grantagentaccess {

&header;
&startmain;

print qq~
<font size="3"><b>Grant Eagle Access</b></font>       <a href="admin.idx?action=grantagentaccess">Main Access Page</a><br>
<b>SEARCH USERS LASTNAME BY</b><br>
<center>
<a href="admin.idx?action=grantagentaccess&find=A">A</a> | 
<a href="admin.idx?action=grantagentaccess&find=B">B</a> | 
<a href="admin.idx?action=grantagentaccess&find=C">C</a> | 
<a href="admin.idx?action=grantagentaccess&find=D">D</a> | 
<a href="admin.idx?action=grantagentaccess&find=E">E</a> | 
<a href="admin.idx?action=grantagentaccess&find=F">F</a> | 
<a href="admin.idx?action=grantagentaccess&find=G">G</a> | 
<a href="admin.idx?action=grantagentaccess&find=H">H</a> | 
<a href="admin.idx?action=grantagentaccess&find=I">I</a> | 
<a href="admin.idx?action=grantagentaccess&find=J">J</a> | 
<a href="admin.idx?action=grantagentaccess&find=K">K</a> | 
<a href="admin.idx?action=grantagentaccess&find=L">L</a> | 
<a href="admin.idx?action=grantagentaccess&find=M">M</a> | 
<a href="admin.idx?action=grantagentaccess&find=N">N</a> | 
<a href="admin.idx?action=grantagentaccess&find=O">O</a> | 
<a href="admin.idx?action=grantagentaccess&find=P">P</a> | 
<a href="admin.idx?action=grantagentaccess&find=Q">Q</a> | 
<a href="admin.idx?action=grantagentaccess&find=R">R</a> | 
<a href="admin.idx?action=grantagentaccess&find=S">S</a> | 
<a href="admin.idx?action=grantagentaccess&find=T">T</a> | 
<a href="admin.idx?action=grantagentaccess&find=U">U</a> | 
<a href="admin.idx?action=grantagentaccess&find=V">V</a> | 
<a href="admin.idx?action=grantagentaccess&find=W">W</a> | 
<a href="admin.idx?action=grantagentaccess&find=X">X</a> | 
<a href="admin.idx?action=grantagentaccess&find=Y">Y</a> | 
<a href="admin.idx?action=grantagentaccess&find=Z">Z</a>
</center>
<br><br>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
~;

$trcount = "1";
$totalperrow = "2";

if ($INPUT{find}) {
my $aasth = $dbh->prepare("SELECT COUNT(userid) FROM users WHERE lastname LIKE '$INPUT{find}%'");
$aasth->execute;
while (($userid) = $aasth->fetchrow_array()) {
if ($userid eq "1") {
$checkgrammar = "userid";
}
else {
$checkgrammar = "userids";
}

print qq~
<td colspan="4">
<b><font color="red">Found $userid $checkgrammar for search $INPUT{find}</font><b><br><br>
</td>
</tr>
<tr>
~;
}

my $basth = $dbh->prepare("SELECT userid,email,firstname,lastname,access,agentid FROM users WHERE lastname LIKE '$INPUT{find}%'");
$basth->execute;
while (($userid,$email,$firstname,$lastname,$access,$agentid) = $basth->fetchrow_array()) {

	my $dasth = $dbh->prepare("SELECT mlsid,email from agents WHERE email = '$email'");
	$dasth->execute;
	while (($mlsid,$email2) = $dasth->fetchrow_array()) {
	$showmlsid = "$mlsid";
	}

	if ($access || $agentid) {
	$buildcolor = "red";
	}
	elsif ($showmlsid) {
	$buildcolor = "green";
	}
	else {
	$buildcolor = "silver";
	}

print "<td><b><font color=\"$buildcolor\">$lastname, $firstname</font></b> <a href=\"admin.idx?action=grantagentaccess&grant=$userid&doit=eagleagent&agentid=$showmlsid&name=$firstname $lastname\">Give Agent Access</a><br></td>\n";

	if ($trcount eq $totalperrow) {
	print "</tr><tr bgcolor=\"$color\">";
	$trcount = "1";
	}
	else {
	$trcount++;
	}

	$showmlsid = "";
}

}
else {
unless ($INPUT{grant}) {
$showusersgranted = "yes";
print "<td><font color=\"red\"><b>You Must First Choose the lastname letter to search by!</b></font><br></td>";
}
}

if ($INPUT{grant}) {
my $aasth = $dbh->do("update users set access = '$INPUT{doit}', agentid = '$INPUT{agentid}' WHERE userid = '$INPUT{grant}'");
print "<td><font color=\"red\" size=\"3\"><b><u>$INPUT{name}</u> Has Been Granted <u>$INPUT{doit}</u> Access!</b></font><br></td>";
}




print qq~
</tr>
</table>
~;
if ($showusersgranted eq "yes") {
print "<br><br><font size=\"3\" color=\"red\"><b>Users With Access</b></font><br>\n";
my $casth = $dbh->prepare("SELECT userid,firstname,lastname,access FROM users WHERE access = 'eagleagent' OR access = 'admin' ORDER BY lastname ASC");
$casth->execute;
while (($userid,$firstname,$lastname,$access) = $casth->fetchrow_array()) {
print qq~
<b>$firstname $lastname</b> ($access) <a href=\"admin.idx?action=grantagentaccess&grant=$userid&doit=&agentid=&name=$firstname $lastname\">Remove Access</a><br>
~;
}

}
print qq~
</td>
~;
&footer;
}


sub agentdoedit {

$mlsid = $INPUT{mlsid};
$newmlsid = $INPUT{newmlsid};
$firstname = $INPUT{firstname};
$lastname = $INPUT{lastname};
$title = $INPUT{title};
$phone1name = $INPUT{phone1name};
$phone1number = $INPUT{phone1number};
$phone2name = $INPUT{phone2name};
$phone2number = $INPUT{phone2number};
$phone3name = $INPUT{phone3name};
$phone3number = $INPUT{phone3number};
$phone4name = $INPUT{phone4name};
$phone4number = $INPUT{phone4number};
$email = $INPUT{email};
$homepage = $INPUT{homepage};
$profile = $INPUT{profile};
$image = $INPUT{image};
$enrollment = $INPUT{enrollment};


$firstname =~ s/\'//gi;
$firstname =~ s/\"//gi;
$lastname =~ s/\'//gi;
$lastname =~ s/\"//gi;
$title =~ s/\'//gi;
$title =~ s/\"//gi;
$phone1name =~ s/\'//gi;
$phone1number =~ s/\"//gi;
$phone2name =~ s/\'//gi;
$phone2number =~ s/\"//gi;
$phone3name =~ s/\'//gi;
$phone3number =~ s/\"//gi;
$phone4name =~ s/\'//gi;
$phone4number =~ s/\"//gi;
$email =~ s/\'//gi;
$email =~ s/\"//gi;
$homepage =~ s/\'//gi;
$homepage =~ s/\"//gi;
$profile =~ s/\'//gi;
$profile =~ s/\"//gi;
$image =~ s/\'//gi;
$image =~ s/\"//gi;
$enrollment =~ s/\'//gi;
$enrollment =~ s/\"//gi;

my $aasth = $dbh->do("update agents set mlsid = '$newmlsid', firstname = '$firstname', lastname = '$lastname', title = '$title', phone1name = '$phone1name', phone1number = '$phone1number', phone2name = '$phone2name', phone2number = '$phone2number', phone3name = '$phone3name', phone3number = '$phone3number', phone4name = '$phone4name', phone4number = '$phone4number', email = '$email', homepage = '$homepage', profile = '$profile', image = '$image', leadsystem = '$enrollment', display = '$INPUT{display}', showsales = '$INPUT{showsales}' WHERE agentid = '$INPUT{agentid}'");
$printmessage = "<font color=\"Red\">Successfully Updated Database</font><br>";
&agents;
}


sub agentedit {

my $aasth = $dbh->prepare("select agentid,mlsid,firstname,lastname,title,phone1name,phone1number,phone2name,phone2number,phone3name,phone3number,phone4name,phone4number,email,homepage,profile,image,leadsystem,display,showsales from agents WHERE agentid = '$INPUT{mlsid}'");
$aasth->execute;

&header;
&startmain;

while (($agentid,$mlsid,$firstname,$lastname,$title,$phone1name,$phone1number,$phone2name,$phone2number,$phone3name,$phone3number,$phone4name,$phone4number,$email,$homepage,$profile,$image,$leadsystem,$display,$showsales) = $aasth->fetchrow_array()) {

if ($phone2name) {
$checkphone2name = "<option value=\"$phone2name\">$phone2name</option>";
}
if ($phone3name) {
$checkphone3name = "<option value=\"$phone3name\">$phone3name</option>";
}
if ($phone4name) {
$checkphone4name = "<option value=\"$phone4name\">$phone4name</option>";
}

if ($display eq "0") {
$checkdisplay = "<option value=\"$display\">No [ Hide in Directory ]</option>";
}
else {
$checkdisplay = "<option value=\"$display\">Yes [ Show in Directory ]</option>";
}


if ($showsales eq "0") {
$checkshowsales = "<option value=\"$showsales\">No [ Hide ]</option>";
}
else {
$checkshowsales = "<option value=\"$showsales\">Yes [ Pendings & Solds ]</option>";
}

print qq~

<script language="Javascript1.2"><!-- // load htmlarea
_editor_url = "/htmlarea/";                     // URL to htmlarea files
var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
if (navigator.userAgent.indexOf('Mac')        >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Opera')      >= 0) { win_ie_ver = 0; }
if (win_ie_ver >= 5.5) {
 document.write('<scr' + 'ipt src="' +_editor_url+ 'editor.js"');
 document.write(' language="Javascript1.2"></scr' + 'ipt>');  
} else { document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); }
// --></script>

<script language="JavaScript1.2" defer>
	editor_generate('profile');
</script>

<form method="post" action="admin.idx">
<input type="hidden" name="action" value="agentdoedit">
<input type="hidden" name="mlsid" value="$mlsid">
<table border="0" cellpadding="3" cellspacing="1" border="0" bgcolor="navy">
<tr>
<td colspan="2" bgcolor="navy"><font color="white"><b>Update $firstname $lastname\'s Agent Directory</b></font></td>
</tr>
<tr>
	<td bgcolor="white">AgentID</td>
	<td bgcolor="white">
		<input type="text" name="agentid" value="$agentid">
	</td>
</tr>
<tr>
	<td bgcolor="white">MLSID</td>
	<td bgcolor="white">
		<input type="text" name="newmlsid" value="$mlsid">
	</td>
</tr>
<tr>
	<td bgcolor="white">FirstName</td>
	<td bgcolor="white"><input type="text" name="firstname" value="$firstname"></td>
</tr>
<tr>
	<td bgcolor="white">LastName</td>
	<td bgcolor="white"><input type="text" name="lastname" value="$lastname"></td>
</tr>
<tr>
	<td bgcolor="white">Title</td>
	<td bgcolor="white">
		<input type="text" name="title" value="$title">
	</td>
</tr>
<tr>
	<td bgcolor="white">Phone 1 Type<br>
	</td>
	<td bgcolor="white">
		<select name="phone1name">
		<option value="Office">Office</option>
		</select> 
		<select name="phone1number">
		<option value="765-212-1111">765-212-1111</option>
		</select>
	</td>
</tr>
<tr>
	<td bgcolor="white">Phone 2 Type<br>
	</td>
	<td bgcolor="white">
		<select name="phone2name">
		$checkphone2name
		<option value="">-- No Number --</option>
		<option value="Home Office">Home Office</option>
		<option value="Mobile">Mobile</option>
		<option value="Voicemail">Voicemail</option>
		<option value="Home">Home</option>
		<option value="Pager">Pager</option>
		</select> 
		<input type="text" name="phone2number" value="$phone2number">
	</td>
</tr>
<tr>
	<td bgcolor="white">Phone 3 Type<br>
	</td>
	<td bgcolor="white">
		<select name="phone3name">
		$checkphone3name
		<option value="">-- No Number --</option>
		<option value="Home Office">Home Office</option>
		<option value="Mobile">Mobile</option>
		<option value="Voicemail">Voicemail</option>
		<option value="Home">Home</option>
		<option value="Pager">Pager</option>
		</select> 
		<input type="text" name="phone3number" value="$phone3number">
	</td>
</tr>
<tr>
	<td bgcolor="white">Phone 4 Type<br>
	</td>
	<td bgcolor="white">
		<select name="phone4name">
		$checkphone4name
		<option value="">-- No Number --</option>
		<option value="Home Office">Home Office</option>
		<option value="Mobile">Mobile</option>
		<option value="Voicemail">Voicemail</option>
		<option value="Home">Home</option>
		<option value="Pager">Pager</option>
		</select> 
		<input type="text" name="phone4number" value="$phone4number">
	</td>
</tr>
<tr>
	<td bgcolor="white">E-Mail Address</td>
	<td bgcolor="white">
		<input type="text" name="email" value="$email">
	</td>
</tr>
<tr>
	<td bgcolor="white">Website Address</td>
	<td bgcolor="white">
		<input type="text" name="homepage" value="$homepage">
	</td>
</tr>
<tr>
	<td bgcolor="white">Profile About You</td>
	<td bgcolor="white">
		  <textarea rows="15" name="profile" cols="55">$profile</textarea>	
	</td>
</tr>
<tr>
	<td bgcolor="white">Image</td>
	<td bgcolor="white">
		<input type="text" name="image" value="$image">
	</td>
</tr>
<tr>
	<td bgcolor="white">Lead Enrollment</td>
	<td bgcolor="white">
		<input type="text" name="enrollment" value="$leadsystem">
	</td>
</tr>
<tr>
	<td bgcolor="white">Display Agent</td>
	<td bgcolor="white">
		<select name="display" class="adminform">
		$checkdisplay
		<option value="$display">--------</option>
		<option value="1">Yes [ Show In Directory ]</option>
		<option value="0">No [ Hide In Directory ]<option>
		</select>
	</td>
</tr>
<tr>
	<td bgcolor="white">Show Sales On Profile</td>
	<td bgcolor="white">
		<select name="showsales" class="adminform">
		$checkshowsales
		<option value="$showsales">--------</option>
		<option value="1">Yes [ Pendings & Solds ]</option>
		<option value="0">No [ Hide ]<option>
		</select>
	</td>
</tr>
<tr>
	<td colspan="2">
		<center>
		<input type="submit" value="Edit Agent Info Now">
		</center>
	</td>
</tr>
</table>
</form>
</td>
~;
}
&footer;
}

sub agentdelete {

my $aasth = $dbh->do("delete from agents where agentid = '$INPUT{mlsid}'");
$dbh->disconnect;
$printmessage = "<font color=\"Red\">Successfully Deleted $INPUT{tempname} Agent From Database</font><br>";
&agents;
}

sub agentadd {

#############################################


my $aasth = $dbh->prepare("select agentid,firstname,lastname FROM mlsusers WHERE officeid = '48'");
$aasth->execute;
while (($agentid,$firstname,$lastname) = $aasth->fetchrow_array()) {
$buildmatchingmls .= "<option value=\"$agentid\">$firstname $lastname</option>";
}

#############################################


&header;
&startmain;
print qq~
<script language="Javascript1.2"><!-- // load htmlarea
_editor_url = "/htmlarea/";                     // URL to htmlarea files
var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
if (navigator.userAgent.indexOf('Mac')        >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Opera')      >= 0) { win_ie_ver = 0; }
if (win_ie_ver >= 5.5) {
 document.write('<scr' + 'ipt src="' +_editor_url+ 'editor.js"');
 document.write(' language="Javascript1.2"></scr' + 'ipt>');  
} else { document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); }
// --></script>

<script language="JavaScript1.2" defer>
	editor_generate('profile');
</script>

<form method="post" action="admin.idx">
<input type="hidden" name="action" value="agentdoadd">
<table border="0" cellpadding="3" cellspacing="1" border="0" bgcolor="navy">
<tr>
<td colspan="2" bgcolor="navy"><font color="white"><b>Add New Agent</b></font></td>
</tr>
<tr>
	<td bgcolor="white">AgentID</td>
	<td bgcolor="white">Autocreated</td>
</tr>
<tr>
	<td bgcolor="white">MLSID</td>
	<td bgcolor="white">
		<select name="mlsid">
		<option value="">Select This Agent Now To Match To MLS Listings</option>
		<option value="">- - - - - - - - - - - - - -</option>
		<option value="11111">Temp Number (11111)</option>
		<option value="22222">Temp Number (22222)</option>
		<option value="33333">Temp Number (33333)</option>
		<option value="44444">Temp Number (44444)</option>
		<option value="55555">Temp Number (55555)</option>
		$buildmatchingmls
		</select>
	</td>
</tr>
<tr>
	<td bgcolor="white">FirstName</td>
	<td bgcolor="white"><input type="text" name="firstname"></td>
</tr>
<tr>
	<td bgcolor="white">LastName</td>
	<td bgcolor="white"><input type="text" name="lastname"></td>
</tr>
<tr>
	<td bgcolor="white">Title</td>
	<td bgcolor="white">
		<select name="title">
		<option value="REALTORŪ, Sales Associate">REALTORŪ, Sales Associate</option>
		<option value="BROKERŪ, Sales Associate">BROKERŪ, Sales Associate</option>
		<option value="REALTORŪ, Commercial Manager">REALTORŪ, Commercial Manager </option>
		</select>
	</td>
</tr>
<tr>
	<td bgcolor="white">Phone 1 Type<br>
	</td>
	<td bgcolor="white">
		<select name="phone1name">
		<option value="Office">Office</option>
		</select> 
		<select name="phone1number">
		<option value="765-212-1111">765-212-1111</option>
		</select>
	</td>
</tr>
<tr>
	<td bgcolor="white">Phone 2 Type<br>
	</td>
	<td bgcolor="white">
		<select name="phone2name">
		<option value="">-- No Number --</option>
		<option value="Home Office">Home Office</option>
		<option value="Mobile">Mobile</option>
		<option value="Voicemail">Voicemail</option>
		<option value="Home">Home</option>
		<option value="Pager">Pager</option>
		</select> 
		<input type="text" name="phone2number">
	</td>
</tr>
<tr>
	<td bgcolor="white">Phone 3 Type<br>
	</td>
	<td bgcolor="white">
		<select name="phone3name">
		<option value="">-- No Number --</option>
		<option value="Home Office">Home Office</option>
		<option value="Mobile">Mobile</option>
		<option value="Voicemail">Voicemail</option>
		<option value="Home">Home</option>
		<option value="Pager">Pager</option>
		</select> 
		<input type="text" name="phone3number">
	</td>
</tr>
<tr>
	<td bgcolor="white">Phone 4 Type<br>
	</td>
	<td bgcolor="white">
		<select name="phone4name">
		<option value="">-- No Number --</option>
		<option value="Home Office">Home Office</option>
		<option value="Mobile">Mobile</option>
		<option value="Voicemail">Voicemail</option>
		<option value="Home">Home</option>
		<option value="Pager">Pager</option>
		</select> 
		<input type="text" name="phone4number">
	</td>
</tr>
<tr>
	<td bgcolor="white">E-Mail Address</td>
	<td bgcolor="white">
		<input type="text" name="email">
	</td>
</tr>
<tr>
	<td bgcolor="white">Website Address</td>
	<td bgcolor="white">
		<input type="text" name="homepage">
	</td>
</tr>
<tr>
	<td bgcolor="white">Profile About You</td>
	<td bgcolor="white">
		  <textarea rows="12" name="profile" cols="49"></textarea>	
	</td>
</tr>
<tr>
	<td bgcolor="white">Image</td>
	<td bgcolor="white">
		<input type="text" name="image">
	</td>
</tr>
<tr>
	<td bgcolor="white">Lead Enrollment</td>
	<td bgcolor="white">
		<input type="text" name="leadenrollment" value="Not Enrolled">
	</td>
</tr>
<tr>
	<td bgcolor="white">Display Agent</td>
	<td bgcolor="white">
		<select name="display" class="adminform">
		<option value="1">Yes [Show In Directory]</option>
		<option value="0">No [Hide In Directory]<option>
		</select>
	</td>
</tr>
<tr>
	<td bgcolor="white">Show Sales On Profile</td>
	<td bgcolor="white">
		<select name="showsales" class="adminform">
		<option value="1">Yes [ Pendings & Solds ]</option>
		<option value="0">No [ Hide ]<option>
		</select>
	</td>
</tr>
<tr>
	<td colspan="2">
		<center>
		<input type="submit" value="Add New Agent Now">
		</center>
	</td>
</tr>
</table>
</form>
</td>
~;
&footer;
}


sub agentdoadd {


$INPUT{firstname} =~ s/\'//gi;
$INPUT{firstname} =~ s/\"//gi;
$INPUT{lastname} =~ s/\'//gi;
$INPUT{lastname} =~ s/\"//gi;
$INPUT{title} =~ s/\'//gi;
$INPUT{title} =~ s/\"//gi;
$INPUT{phone1name} =~ s/\'//gi;
$INPUT{phone1number} =~ s/\"//gi;
$INPUT{phone2name} =~ s/\'//gi;
$INPUT{phone2number} =~ s/\"//gi;
$INPUT{phone3name} =~ s/\'//gi;
$INPUT{phone3number} =~ s/\"//gi;
$INPUT{phone4name} =~ s/\'//gi;
$INPUT{phone4number} =~ s/\"//gi;
$INPUT{email} =~ s/\'//gi;
$INPUT{email} =~ s/\"//gi;
$INPUT{homepage} =~ s/\'//gi;
$INPUT{homepage} =~ s/\"//gi;
$INPUT{profile} =~ s/\'//gi;
$INPUT{profile} =~ s/\"//gi;
$INPUT{image} =~ s/\'//gi;
$INPUT{image} =~ s/\"//gi;
$INPUT{leadenrollment} =~ s/\'//gi;
$INPUT{leadenrollment} =~ s/\"//gi;

$aasth = $dbh->do("insert into agents values ('','$INPUT{mlsid}','$INPUT{firstname}','$INPUT{lastname}','$INPUT{title}','$INPUT{phone1name}','$INPUT{phone1number}','$INPUT{phone2name}','$INPUT{phone2name}','$INPUT{phone3name}','$INPUT{phone3number}','$INPUT{phone4name}','$INPUT{phone4number}','$INPUT{email}','$INPUT{homepage}','$INPUT{profile}','$INPUT{image}','$INPUT{leadenrollment}','$INPUT{display}','$INPUT{showsales}')");
$dbh->disconnect;
$printmessage = "<font color=\"Red\">Successfully Added Agent Into Database</font><br>";
&agents;
}

sub agents {

my $aasth = $dbh->prepare("select agentid,mlsid,firstname,lastname,title,phone1name,phone1number,phone2name,phone2number,phone3name,phone3number,phone4name,phone4number,email,homepage,profile,image,leadsystem,display,showsales from agents order by firstname asc");
$aasth->execute;
&header;
&startmain;
print qq~
$printmessage
<font size="4">AGENT ADMINISTRATION AREA</font><br><a href="admin.idx?action=agentadd">Add New Agent</a><br><br>
<table border="0" cellpadding="3" cellspacing="1" border="0" bgcolor="navy" width="100%">
<tr>
<td bgcolor="navy"><font color="White"><b>AGENTID</b></font></td>
<td bgcolor="navy"><font color="White"><b>MLSID</b></font></td>
<td bgcolor="navy"><font color="White"><b>AGENT NAME</b></font></td>
<td bgcolor="navy"><font color="White"><b>Lead System</b></font></td>
<td bgcolor="navy"><font color="White"><b>Display Directory</b></font></td>
<td bgcolor="navy"><font color="White"><b>Show Sales</b></font></td>
<td bgcolor="navy"><font color="White"><b>ACTIONS</b></font></td>
</tr>
~;

$trcolor = "1";
$trcolor2 = "2";

while (($agentid,$mlsid,$firstname,$lastname,$title,$phone1name,$phone1number,$phone2name,$phone2number,$phone3name,$phone3number,$phone4name,$phone4number,$email,$homepage,$profile,$image,$leadsystem,$display,$showsales) = $aasth->fetchrow_array()) {

if ($display eq "0") {
$display = "No";
}
else {
$display = "Yes";
}

if ($showsales eq "0") {
$showsales = "No";
}
else {
$showsales = "Yes";
}

if ($trcolor eq $trcolor2) {
$trcolor = "1";
$setcolor = "#FFFFFF";
}
else {
$setcolor = "#CCFFCC";
$trcolor++;
}

print qq~
<tr>
<td bgcolor="$setcolor"><a href="admin.idx?action=agentedit&mlsid=$agentid">$agentid</a></td>
<td bgcolor="$setcolor"><a href="admin.idx?action=agentedit&mlsid=$agentid">$mlsid</a></td>
<td bgcolor="$setcolor"><a href="admin.idx?action=agentedit&mlsid=$agentid">$firstname $lastname</a></td>
<td bgcolor="$setcolor"><a href="admin.idx?action=agentedit&mlsid=$agentid">$leadsystem</a></td>
<td bgcolor="$setcolor"><a href="admin.idx?action=agentedit&mlsid=$agentid">$display</a></td>
<td bgcolor="$setcolor"><a href="admin.idx?action=agentedit&mlsid=$agentid">$showsales</a></td>
<td bgcolor="$setcolor"> - <a href="agents.idx?action=viewagent&agent=$agentid" target="_new">View</a><br> - <a href="admin.idx?action=agentedit&mlsid=$agentid">Edit</a><br> - <a href="admin.idx?action=agentdelete&mlsid=$agentid">Delete</a><br></td>
</tr>
~;
}
print qq~
</table>
</td>
~;
&footer;
}


sub addcolumn {


my $aasth = $dbh->do("ALTER TABLE users ADD tos_agreement DATETIME;");
$dbh->disconnect;
print "DID IT";

}

sub giveaccess {

my $aasth = $dbh->do("update users set access = 'admin' where email = 'ryan.orr\@prodigy.net'");
$dbh->disconnect;
print "succesfully added Admin Access";

}


sub massemailtemplate {

&header;
&startmain;


if ($INPUT{save}) {
@variables = ($INPUT{name},$INPUT{display},$INPUT{subject},$INPUT{id});
$sql_query = "update emailer_templates set name = ?, template = ?, subject = ? WHERE id = ?";
my $aasth = $dbh->do($sql_query, undef, @variables);
print qq~
<font size="3" face="Arial"><b>E-Mail Templates</b></font><br>
<font color="red">Successfully Saved $INPUT{name}</font><br><br>
<a href="admin.idx?action=massemailtemplate">Return To Template Overview</a><br>
~;
}
elsif ($INPUT{newsave}) {
@variables = ($INPUT{accessid},$INPUT{type},$INPUT{name},$INPUT{subject},$INPUT{display});
$sql_query = "INSERT INTO emailer_templates values ('',?,?,?,?,?)";
my $aasth = $dbh->do($sql_query, undef, @variables);
print qq~
<font size="3" face="Arial"><b>E-Mail Templates</b></font><br>
<font color="red">Successfully Created $INPUT{name}</font><br><br>
<a href="admin.idx?action=massemailtemplate">Return To Template Overview</a><br>
~;
}
elsif ($INPUT{newtype}) {
print qq~
<font size="3" face="Arial"><b>New Template Type</b></font><br>
<b>What type of template would you like to create?</b><br><br>
>> <a href="admin.idx?action=massemailtemplate&new=office">Office Template</a>      >> <a href="admin.idx?action=massemailtemplate&new=agent">Agent Template</a><br>
~;
}



elsif ($INPUT{new}) {

if ($INPUT{new} eq "office") {
$type = qq~
<input type="hidden" name="type" value="mass">
~;
$accessid =qq~
<input type="hidden" name="accessid" value="6500">
Who's Template is This? <b>autoconfigured</b>
~;
}
else {

	my $baasth = $dbh->prepare("select agentid,firstname,lastname FROM mlsusers WHERE officeid = '48'");
	$baasth->execute;
	while (($agentid,$firstname,$lastname) = $baasth->fetchrow_array()) {
		$buildmatchingmls .= "<option value=\"$agentid\">$agentid ($firstname $lastname)</option>";
	}

$type = qq~
<input type="hidden" name="type" value="agent">
~;
$accessid =qq~
<b>Who's Template is This?</b><br> <select name="accessid" class="adminform">
$buildmatchingmls
</select><br>
~;
}

print qq~
<script language="Javascript1.2"><!-- // load htmlarea
_editor_url = "/htmlarea/";                     // URL to htmlarea files
var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
if (navigator.userAgent.indexOf('Mac')        >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Opera')      >= 0) { win_ie_ver = 0; }
if (win_ie_ver >= 5.5) {
 document.write('<scr' + 'ipt src="' +_editor_url+ 'editor.js"');
 document.write(' language="Javascript1.2"></scr' + 'ipt>');  
} else { document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); }
// --></script>
<script language="JavaScript1.2" defer>
	editor_generate('display');
</script>
<font size="3" face="Arial"><b>Creating New $INPUT{new} Template</b></font><br>
<b>Please associate the template to the database below</b><br><br>
<form method="post" action="admin.idx">
<input type="hidden" name="action" value="massemailtemplate">
<input type="hidden" name="newsave" value="1">
$accessid
$type<br>
<b>File Name Of Template:</b><br><input type="text" name="name" class="adminform" size="20"><br><br>
<b>E-Mail Subject</b><br><input type="text" name="subject" class="adminform" size="80"><br><br>
<b>Message:</b><br>
<textarea rows="26" name="display" cols="72"></textarea><br>
<input type="submit" value="Save New Template" class="adminform"><br>
</form>
~;
}
elsif ($INPUT{launch}) {

my $masth = $dbh->prepare("select id,accessid,type,name,subject,template from emailer_templates where id = '$INPUT{launch}'");
$masth->execute;
print qq~
<script language="Javascript1.2"><!-- // load htmlarea
_editor_url = "/htmlarea/";                     // URL to htmlarea files
var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
if (navigator.userAgent.indexOf('Mac')        >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Opera')      >= 0) { win_ie_ver = 0; }
if (win_ie_ver >= 5.5) {
 document.write('<scr' + 'ipt src="' +_editor_url+ 'editor.js"');
 document.write(' language="Javascript1.2"></scr' + 'ipt>');  
} else { document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); }
// --></script>
~;
while (($id,$accessid,$type,$name,$subject,$template) = $masth->fetchrow_array()) {
print qq~
<font size="3" face="Arial"><b>Viewing Template $name</b></font><br>
<b>Special Codes To Insert In Email To Show Actual User Information:<br></b>
\$email \$firstname \$lastname \$lastlogin<br><br>
<form method="post" action="admin.idx">
<input type="hidden" value="massemailtemplate" name="action">
<input type="hidden" value="yes" name="save">
<input type="hidden" value="$id" name="id">
<b>Template Filename:</b><br><input type="text" value="$name" name="name" size="20" class="adminform"><br><br>
<b>Subject:</b><br><input type="text" value="$subject" name="subject" size="80" class="adminform"><br><br>
<script language="JavaScript1.2" defer>
	editor_generate('display');
</script>
<b>Message:</b><br>
<textarea rows="26" name="display" cols="72">$template</textarea><br>
<input type="submit" value="Save" class="adminform"><br>
</form>
~;
}

}
elsif ($INPUT{preview}) {
print qq~
<font size="3" face="Arial"><b>Previewing Template</b></font> <a href="admin.idx?action=massemailtemplate">Return To Overview</a><br>
~;
my $masth = $dbh->prepare("select id,accessid,type,name,subject,template from emailer_templates where id = '$INPUT{preview}'");
$masth->execute;
while (($id,$accessid,$type,$name,$subject,$template) = $masth->fetchrow_array()) {
print qq~
<html>
<head>
<title>Eagle Email</title>
<link rel="stylesheet" TYPE="text/css" href="includes/style.css">
</head>
<body bgcolor="white" leftMargin="0" topMargin="0" marginwidth="0" marginheight="0">
<b><font size="2">$subject</font></b><br>
<b>Subject:</b> $subject<br>
<b>Message:</b><br>
$template
</body>
</html>
~;
}
}
elsif ($INPUT{delete}) {

if ($INPUT{do} eq "yes") {
my $aasth = $dbh->do("delete from emailer_templates where id = '$INPUT{delete}'");
print qq~
<font size="3" face="Arial"><b>Delete Templates</b></font><br>
<font color="red"><b>Success!</b></font><br>
<a href="admin.idx?action=massemailtemplate">Return To Overview</a><br>
~;
}

if ($INPUT{do} eq "no") {
print qq~
<font size="3" face="Arial"><b>Delete Templates</b></font><br>
<a href="admin.idx?action=massemailtemplate">Return To Overview</a><br>
~;
}

unless ($INPUT{do}) {
print qq~
Delete template $INPUT{delete}?<br>
<a href="admin.idx?action=massemailtemplate&delete=$INPUT{delete}&do=yes">Yes</a>    <a href="admin.idx?action=massemailtemplate&delete=$INPUT{delete}&do=no">No</a>
<br><br>
~;
}
}
else {
	print qq~
	<a href="admin.idx?action=massemail">Launch Mass Email Center</a><br>
	<font size="3" face="Arial"><b>Templates Currently Setup</b></font>   <a href="admin.idx?action=massemailtemplate&newtype=1">Create New Template</a><br>
	~;
		my $masth = $dbh->prepare("select id,accessid,type,name,subject,template from emailer_templates");
		$masth->execute;
		while (($id,$accessid,$type,$name,$subject,$template) = $masth->fetchrow_array()) {
			print qq~
				    --> template <b>$name</b> belongs to <b>$type $accessid</b> [ <a href="admin.idx?action=massemailtemplate&launch=$id">Launch Editor</a> ]   [ <a href="admin.idx?action=massemailtemplate&preview=$id">Preview</a> ]   [ <a href="admin.idx?action=massemailtemplate&delete=$id">Delete</a> ]<br>
			~;
		}
}
$dbh->disconnect;


print "</td>";
&footer;

}

sub massemail {

################### TOP EMAIL PART ###################################################
if ($INPUT{searchdays} eq "----") {
$printcurrentvalue = "<option value=\"????\">????</option>";
}
elsif ($INPUT{searchdays} eq "") {
$printcurrentvalue = "<option value=\"????\">????</option>";
}
else {
$printcurrentvalue = "<option value=\"$INPUT{searchdays}\">$INPUT{searchdays}</option>";
}
if ($INPUT{searchtype} eq "----") {
$buildsearchtype = "<option value=\"????\">????</option>";
}
elsif ($INPUT{searchdays} eq "") {
$buildsearchtype = "<option value=\"????\">????</option>";
}
else {
$buildsearchtype = "<option value=\"$INPUT{searchtype}\">$INPUT{searchtype}</option>";
}

	my $mesth = $dbh->prepare("select id,name from emailer_templates where type = 'mass'");
	$mesth->execute;
	while (($id,$name) = $mesth->fetchrow_array()) {
		$printmessage .= "<option value=\"$id\">$name</option>\n";
	}



&header;
&startmain;
print qq~
<a href="admin.idx?action=massemailtemplate">Launch Template Editor</a><br>
<b>To Send An E-Mail To All Users Select <u>Logged In</u> and choose <u>All</u> days</b><br>
<form method="get" action="admin.idx">
<input type="hidden" value="massemail" name="action">
<b><u>Email</u></b> <select name="searchtype" class="smallform">$buildsearchtype<option value="----">----</option><option value="<">Logged In</option><option value=">">Not Logged In</option></select> 
<select name="searchdays" class="smallform">
$printcurrentvalue
<option value="----">----</option>
<option value="10">10</option>
<option value="15">15</option>
<option value="20">20</option>
<option value="25">25</option>
<option value="30">30</option>
<option value="31">31</option>
<option value="60">60</option>
<option value="120">120</option>
<option value="180">180</option>
<option value="360">360</option>
<option value="999999">All</option>
</select> <u><b>days |  Message To Send</b></u> 
<select name="message" class="smallform">
$printmessage
</select>
<select name="do" class="smallform">
<option value="Preview">Preview</option>
<option value="Send">Send</option>
</select>
<input type="submit" value="Do It" class="smallform">
</form>
~;
################### END EMAIL PART ###################################################

my $basth = $dbh->prepare("select COUNT(userid) from users where to_days(now())-to_days(lastlogin) $INPUT{searchtype} '$INPUT{searchdays}' AND email_block = 'y'");
$basth->execute;
while (($countuserid) = $basth->fetchrow_array()) {
$totalcount = $countuserid;
}


if ($INPUT{do} eq "Preview") {
print qq~
<form method="post" action="admin.idx">
<input type="hidden" name="action" value="massemail">
<input type="hidden" name="searchtype" value="$INPUT{searchtype}">
<input type="hidden" name="searchdays" value="$INPUT{searchdays}">
<input type="hidden" name="message" value="$INPUT{message}">
<input type="hidden" name="do" value="Send">
<input type="submit" class="adminform" value="Send E-Mails Each Person Now!">
</form>              -             <b>$totalcount</b> E-Mails Will Be Sent!<br>
~;
my $aasth = $dbh->prepare("select userid,email,firstname,lastname,datestamp,lastlogin,tos_agreement from users where to_days(now())-to_days(lastlogin) $INPUT{searchtype} '$INPUT{searchdays}' AND email_block = 'y'");
$aasth->execute;

while (($userid,$email,$firstname,$lastname,$datestamp,$lastlogin,$tos_agreement) = $aasth->fetchrow_array()) {

	my $masth = $dbh->prepare("select id,template,subject from emailer_templates where id = '$INPUT{message}'");
	$masth->execute;

	while (($id,$template,$subject) = $masth->fetchrow_array()) {
		$template =~ s/\$userid/$userid/g;
		$template =~ s/\$email/$email/g;
		$template =~ s/\$firstname/$firstname/g;	
		$template =~ s/\$lastname/$lastname/g;
		$template =~ s/\$datestamp/$datestamp/g;
		$template =~ s/\$lastlogin/$lastlogin/g;
		$template =~ s/\$tos_agreement/$tos_agreement/g;
		$subject =~ s/\$userid/$userid/g;
		$subject =~ s/\$email/$email/g;
		$subject =~ s/\$firstname/$firstname/g;	
		$subject =~ s/\$lastname/$lastname/g;
		$subject =~ s/\$datestamp/$datestamp/g;
		$subject =~ s/\$lastlogin/$lastlogin/g;
		$subject =~ s/\$tos_agreement/$tos_agreement/g;
		print "<b>Subject:</b> $subject<br><b>Message:</b><br>$template";
	}

	#my $casth = $dbh->do("update users set tos_agreement = '' where userid = '$userid'");
}
}
elsif ($INPUT{do} eq "Send") {

print qq~
<font size="3" face="Arial">
<b>$totalcount E-Mails Successfully Sent!  <a href="admin.idx?action=massemail">Return To Mass Mail Center</a></b>
</font><br>
~;
my $aasth = $dbh->prepare("select userid,email,firstname,lastname,datestamp,lastlogin,tos_agreement from users where to_days(now())-to_days(lastlogin) $INPUT{searchtype} '$INPUT{searchdays}' AND email_block = 'y'");
$aasth->execute;

while (($userid,$email,$firstname,$lastname,$datestamp,$lastlogin,$tos_agreement) = $aasth->fetchrow_array()) {

	my $masth = $dbh->prepare("select id,template,subject from emailer_templates where id = '$INPUT{message}'");
	$masth->execute;

	while (($id,$template,$subject) = $masth->fetchrow_array()) {
		$template =~ s/\$userid/$userid/g;
		$template =~ s/\$email/$email/g;
		$template =~ s/\$firstname/$firstname/g;	
		$template =~ s/\$lastname/$lastname/g;
		$template =~ s/\$datestamp/$datestamp/g;
		$template =~ s/\$lastlogin/$lastlogin/g;
		$template =~ s/\$tos_agreement/$tos_agreement/g;
		$subject =~ s/\$userid/$userid/g;
		$subject =~ s/\$email/$email/g;
		$subject =~ s/\$firstname/$firstname/g;	
		$subject =~ s/\$lastname/$lastname/g;
		$subject =~ s/\$datestamp/$datestamp/g;
		$subject =~ s/\$lastlogin/$lastlogin/g;
		$subject =~ s/\$tos_agreement/$tos_agreement/g;

			open(MAIL,"|/usr/sbin/sendmail -t");
			print MAIL "To: $email\n";
			print MAIL "From: Ryan.ORR\@EagleSold.com\n";
			print MAIL "Subject: $subject\n";
			print MAIL "Content-type: text/html\n\n";
			print MAIL qq~
				<html>
				<head>
				<title>Eagle Official E-Mail</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">
				$template
				</body>	
				</html>
			~;
			close(MAIL);

		print "  --> Sent To <b>$email</b> - <b>$firstname $lastname</b><br>";
	}

	#my $casth = $dbh->do("update users set tos_agreement = '' where userid = '$userid'");
}










}
else {
print "I dont know what you want me to do!";
}




$dbh->disconnect;



print "</td>";
&footer;
}







sub buildstatisticsusers {

my $basth = $dbh->prepare("select COUNT(UserType) from users WHERE UserType <> ''");
$basth->execute;
while (($theUserType) = $basth->fetchrow_array()) {
$totalcount = "$theUserType";
}

my $aasth = $dbh->prepare("select UserType from users WHERE UserType <> '' GROUP BY UserType");
$aasth->execute;
print qq~
<table border="0" cellpadding="3" cellspacing="1" bgcolor="black">
<tr>
<td valign="top" bgcolor="navy">
<center><font color="white" size="2"><b>MuncieMLS User Types</b></font></center>
</td>
</tr>
<tr>
<td valign="top" bgcolor="white">
<table border="0" cellpadding="2" cellspacing="0">
~;
while (($UserType) = $aasth->fetchrow_array()) {
	my $basth = $dbh->prepare("select COUNT(UserType) from users WHERE UserType = '$UserType'");
	$basth->execute;
	while (($UserTypeCount) = $basth->fetchrow_array()) {
		$calculated = ($UserTypeCount/$totalcount);
		$calculated = sprintf("%.2f",$calculated);
		$calculated = substr($calculated, -2);
		$thewidth = ($calculated*1);
	print qq~
	<tr>
		<td align="right"><b>$UserType</b></td>
		<td><img src="images/admin/green_bar.gif" height="12" width="$thewidth"> (<i>$calculated%</i>)</td>
	</tr>
        ~;
	}

}
print qq~
<tr>
<td></td>
<td><br><i><b>Total Users $totalcount</b></i></td>
</tr>
</table>
</td>
</tr>
</table>
~;
}

sub buildstatistics {

my $basth = $dbh->prepare("select COUNT(FoundBy) from users WHERE FoundBy <> ''");
$basth->execute;
while (($theFoundBy) = $basth->fetchrow_array()) {
$totalcount = "$theFoundBy";
}

my $aasth = $dbh->prepare("select FoundBy from users WHERE FoundBy <> '' GROUP BY FoundBy");
$aasth->execute;
print qq~
<table border="0" cellpadding="3" cellspacing="1" bgcolor="black">
<tr>
<td valign="top" bgcolor="navy">
<center><font color="white" size="2"><b>MuncieMLS Advertising Sources</b></font></center>
</td>
</tr>
<tr>
<td valign="top" bgcolor="white">
<table border="0" cellpadding="2" cellspacing="0">
~;
while (($FoundBy) = $aasth->fetchrow_array()) {
$totalprice = ($totalprice+$price);
	my $basth = $dbh->prepare("select COUNT(FoundBy) from users WHERE FoundBy = '$FoundBy'");
	$basth->execute;
	while (($FoundByCount) = $basth->fetchrow_array()) {
		$calculated = ($FoundByCount/$totalcount);
		$calculated = sprintf("%.2f",$calculated);
		$calculated = substr($calculated, -2);
		$thewidth = ($calculated*1);
	print qq~
	<tr>
		<td align="right"><b>$FoundBy</b></td>
		<td><img src="images/admin/green_bar.gif" height="12" width="$thewidth"> (<i>$calculated%</i>)</td>
	</tr>
        ~;
	}

}
print qq~
<tr>
<td></td>
<td><br><i><b>Total Sources $totalcount</b></i></td>
</tr>
</table>
</td>
</tr>
</table>
~;
}


sub main {

my $casth = $dbh->prepare("select mlsid,firstname,lastname from agents ORDER BY firstname ASC");
$casth->execute;
while (($mlsid,$firstname,$lastname) = $casth->fetchrow_array()) {
$printagents .= "<option value=\"$mlsid\">$firstname $lastname (id $mlsid)</option>";
}

my $aasth = $dbh->prepare("select count(userid) from users");
$aasth->execute;
while (($userid) = $aasth->fetchrow_array()) {
$totalmembers = $userid;
}

my $basth = $dbh->prepare("select userid,email,password,firstname,lastname,address,city,state,zipcode,timetomove,realtor,datestamp,lastlogin,FoundBy,UserType,myERAAgent,Phone,access from users where (to_days(now()) - to_days(datestamp)) < '1' ORDER BY datestamp DESC");
$basth->execute;
my $lbasth = $dbh->prepare("select userid,email,password,firstname,lastname,address,city,state,zipcode,timetomove,realtor,datestamp,lastlogin,FoundBy,UserType,myERAAgent,Phone,access from users where (to_days(now()) - to_days(lastlogin)) < '1' ORDER BY datestamp DESC");
$lbasth->execute;

my $eaasth = $dbh->prepare("select count(userid) from users WHERE email_openhouses = 'y'");
$eaasth->execute;
while (($euserid) = $eaasth->fetchrow_array()) {
$etotalmembers = $euserid;
}

my $emaasth = $dbh->prepare("select count(userid) from users WHERE email_block = 'y'");
$emaasth->execute;
while (($emuserid) = $emaasth->fetchrow_array()) {
$emtotalmembers = $emuserid;
}

&header;
&startmain;
print qq~
<table border="0" cellpadding="4" cellspacing="0" width="581">
<tr>
<td width="100%" valign="top">
	<table border="0" cellpadding="5" cellspacing="1" width="100%" bgcolor="#cccccc">
	<tr>
	<td valign="top" bgcolor="#CCFFCC"><b><font size="2" color="#009900"><b>Total Registered Members</b></font></b></td>
	<td valign="top" bgcolor="#CCFFCC"><b><font size="2" color="#009900">$totalmembers</font></b></td>
	</tr>
	<tr>
	<td valign="top" bgcolor="#CCFFFF"><b><font size="2" color="#0066CC"><b>Total Members Allowing Mass E-Mail List</b></font></b></td>
	<td valign="top" bgcolor="#CCFFFF"><b><font size="2" color="#0066CC">$emtotalmembers</font></b></td>
	</tr>
	<tr>
	<td valign="top" bgcolor="#FFFF99"><b><font size="2" color="#FF6600"><b>Total Members Requesting Open House E-Mails</b></font></b></td>
	<td valign="top" bgcolor="#FFFF99"><b><font size="2" color="#FF6600">$etotalmembers</font></b></td>
	</tr>
	<tr>
	<td valign="top" bgcolor="white" colspan="2">
	<b><font size="2" color="#000099"><b>Users Registered Within The Last 1 Days</b></font><br>
		<table border="0" cellpadding="1" cellspacing="0" width="100%">
		<tr>
		<td><b>Name</b></td>
		<td><b>E-Mail</b></td>
		<td><b>User Type</b></td>
		<td><b>REALTOR</b></td>
		</tr>

~;
$trcolor = "1";
$trcolor2 = "2";
while (($userid,$email,$password,$firstname,$lastname,$address,$city,$state,$zipcode,$timetomove,$realtor,$datestamp,$lastlogin,$FoundBy,$UserType,$myERAAgent,$Phone,$access) = $basth->fetchrow_array()) {

		if ($trcolor eq $trcolor2) {
		$trcolor = "1";
		$setcolor = "#FFFFFF";
		}
		else {
		$setcolor = "#CCFFCC";
		$trcolor++;
		}
$nfound = "yes";
print qq~
		<tr bgcolor="$setcolor">
		<td><a href="admin.idx?action=useroverview&userid=$userid">$firstname $lastname</a></td>
		<td>$email</td>
		<td>$UserType</td>
		<td>$realtor $myERAAgent</td>
		</tr>
~;
}

if ($nfound ne "yes") {
print qq~
<tr bgcolor="white">
	<td colspan="4"><font color="red"><b>No New Users</b></font><br></td>
</tr>
~;
}

print qq~
	<tr>
	<td valign="top" bgcolor="white" colspan="2">
	<br><b><font size="2" color="#000099"><b>Users Logged In Within The Last 1 Days</b></font><br>
	</td>
	</tr>
~;

$trcolor = "1";
$trcolor2 = "2";
while (($userid,$email,$password,$firstname,$lastname,$address,$city,$state,$zipcode,$timetomove,$realtor,$datestamp,$lastlogin,$FoundBy,$UserType,$myERAAgent,$Phone,$access) = $lbasth->fetchrow_array()) {

		if ($trcolor eq $trcolor2) {
		$trcolor = "1";
		$setcolor = "#FFFFFF";
		}
		else {
		$setcolor = "#CCFFFF";
		$trcolor++;
		}
$nfound = "yes";
print qq~
		<tr bgcolor="$setcolor">
		<td><a href="admin.idx?action=useroverview&userid=$userid">$firstname $lastname</a></td>
		<td>$email</td>
		<td>$UserType</td>
		<td>$realtor $myERAAgent</td>
		</tr>
~;
}
if ($nfound ne "yes") {
print qq~
<tr bgcolor="white">
	<td colspan="4"><font color="red"><b>No Logged On Users</b></font><br></td>
</tr>
~;
}
print qq~
		</table>
	</b>
<br>
~;
print qq~
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td nowrap>
~;
&buildstatistics;
print qq~
</td>
<td nowrap>
~;
&buildstatisticsusers;
print qq~
</td>
</tr>
</table>
</td>
	</tr>
	<tr>
	<td valign="top" bgcolor="#000099" colspan="2">
	<b><font size="2" color="white"><b>Access Site Administration Areas</b></font>
	</b></td>
	</tr>
	<tr>
	<td valign="top" colspan="2" bgcolor="white">
		<table border="0" cellpadding="3" cellspacing="0" width="100%">
		<tr>
		<td valign="top" width="50%">
			- <a href="admin.idx?action=agents">Agent Administration</a><br>
		</td>
		<td valign="top" width="50%">
		- <a href="admin.idx?action=grantagentaccess">Grant Eagle Agent Access</a><br>
		</td>
		</tr>
		<tr>
		<td valign="top" width="50%">
			- <a href="admin.idx?action=newagent">New Agent Center</a><br>
		</td>
		<td valign="top" width="50%">
			- <a href="admin.idx?action=massemail">Mass E-Mail</a> <a href="admin.idx?action=massemailtemplate">[ Template Editor ]<br>
		</td>
		</tr>
		<tr>
		<td valign="top" width="50%">
			- <a href="admin.idx?action=openhouselist">Open House Center</a><br>
		</td>
		<td valign="top" width="50%">
			- <a href="admin.idx?action=openhousemm">Open House Mass Email</a><br>
		</td>
		</tr>
		<tr>
		<td valign="top" width="50%">
			- <a href="admin.idx?action=fixusernames">Fix User Names Capitalizations</a><br>
		</td>
		<td valign="top" width="50%">
			- <a href="http://www.munciemls.com/directoryadmin.idx?action=listnew_view">Office Directory Import</a><br>
		</td>
		</tr>
		</table>
	</td>
	</tr>
	<tr>
	<td valign="top" bgcolor="#000099" colspan="2">
	<b><font size="2" color="white"><b>Search For Users By</b></font>
	</b></td>
	</tr>
	<tr>
	<td valign="top" bgcolor="#33CCFF" colspan="2">
		<form method="get" action="admin.idx">
		<input type="hidden" name="action" value="userlisting">

		<table border="0" cellpadding="0" cellspacing="0" width="100%">
		<tr>
		<td><b>Run<br></b></td>
		<td>&nbsp;</td>
		</tr>
		<tr>
		<td>
			<input type="checkbox" name="a_firstname">
		</td>
		<td>
			<b><u>Firstname</u> <select name="firstname_sign" class="smallform"> <option value="">Choose Match Type</option><option value="eq">Equals</option><option value="LIKE">Like</option></select> Search For <input type="text" name="firstname" class="smallform"><br>
		</td>
		</tr>
		<tr>
		<td>
			<input type="checkbox" name="a_lastname">
		</td>
		<td>
			<b><u>Lastname</u> <select name="lastname_sign" class="smallform"> <option value="">Choose Match Type</option><option value="eq">Equals</option><option value="LIKE">Like</option></select> Search For <input type="text" name="lastname" class="smallform"><br>
		</td>
		</tr>
		<tr>
		<td>
			<input type="checkbox" name="a_myERAAgent">
		</td>
		<td>
			<b><u>Users Eagle Agents Is</u> <select name="f_myERAAgent" class="smallform">$printagents</select><br>
		</td>
		</tr>
		<tr>
		<td>
			<input type="checkbox" name="a_registered">
		</td>
		<td>
			<b><u>Show Users Registered In With The Last</u></b>
			<select name="rsearchdays" class="smallform">
			<option value="1">1</option>
			<option value="2">2</option>
			<option value="3">3</option>
			<option value="4">4</option>
			<option value="5">5</option>
			<option value="6">6</option>
			<option value="7">7</option>
			<option value="8">8</option>
			<option value="9">9</option>
			<option value="10">10</option>
			<select> <b><u>days</u></b>
		</td>
		</tr>

		<tr>
		<td>
			<input type="checkbox" name="a_lastlogged">
		</td>
		<td>
			<b><u>Show Users Logged In With The Last</u></b>
			<select name="searchdays" class="smallform">
			<option value="1">1</option>
			<option value="2">2</option>
			<option value="3">3</option>
			<option value="4">4</option>
			<option value="5">5</option>
			<option value="6">6</option>
			<option value="7">7</option>
			<option value="8">8</option>
			<option value="9">9</option>
			<option value="10">10</option>
			<select> <b><u>days</u></b>
		</td>
		</tr>

		<tr>
		<td valign="top"><img src="images/admin/arrow.gif"></td>
		<td>
				<b><u>Order Results By</u></b>
			<select name="orderby" class="smallform">
				<option value="userid">userid</option>
				<option value="firstname">firstname</option>
				<option value="lastname">lastname</option>
				<option value="city">city</option>
				<option value="state">state</option>
				<option value="zipcode">zipcode</option>
				<option value="timetomove">timetomove</option>
				<option value="datestamp">datestamp</option>
				<option value="lastlogin">lastlogin</option>
				<option value="FoundBy">FoundBy</option>
				<option value="UserType">UserType</option>
				<option value="myERAAgent">myERAAgent</option>
			</select> <b>in</b> <select name="orderbyvalue" class="smallform"><option value="DESC">Descending</option><option value="ASC">Ascending</option></select><b> Order</b><br><br>		<input type="submit" class="smallform" value="Perform Search">
		</td>
		</tr>
		</table>				
		</form>
	</td>
	</tr>
	</table>
</td>
</table>


~;
$dbh->disconnect;
&footer;
}

sub runremoveuser {

&header;
&startmain;

my $aasth = $dbh->do("delete from users where userid = '$INPUT{userid}'");
$pusers = "Cleaned up users table!";
my $basth = $dbh->do("delete from search_fav where userid = '$INPUT{userid}'");
$psearch_fav = "Cleaned up search_fav table!";
my $casth = $dbh->do("delete from home_fav where userid = '$INPUT{userid}'");
$phome_fav = "Cleaned up home_fav table!";
my $dasth = $dbh->do("delete from leadtracking where userid = '$INPUT{userid}'");
$pleadtracking = "Cleaned up leadtracking table!";
my $dasth = $dbh->do("delete from emailstousers where userid = '$INPUT{userid}'");
$pemails = "Cleaned up saved emails table!";
$dbh->disconnect;
print "<center><font color=red><strong>$INPUT{firstname} $INPUT{lastname} has been deleted from MuncieMLS.com.</strong></font><br><br><font color=red><i>$pusers<br>$psearch_fav<br>$phome_fav<br>$pleadtracking<br>$pemails</i></font></td>";
&footer;
}

sub removeuser {
my $aasth = $dbh->prepare("select userid,firstname,lastname from users WHERE userid = '$INPUT{userid}'");
$aasth->execute;
&header;
while (($userid,$firstname,$lastname) = $aasth->fetchrow_array()) {
&startmain;
print qq~
	<table border="0" cellpadding="4" cellspacing="2" width="100%">
	<tr>
	<td valign="top" width="100%">
		<font size="4" color="navy">Are you sure you want to remove <b>$firstname $lastname</b> from the munciemls system?</font>
		<form method="get" action="admin.idx">
		<input type="hidden" value="runremoveuser" name="action">
		<input type="hidden" value="$userid" name="userid">
		<input type="hidden" value="$firstname" name="firstname">
		<input type="hidden" value="$lastname" name="lastname">
		<input type="submit" value="Yes Confirm">
		</form>
	</td>
	</tr>
	</table>

~;

}
$dbh->disconnect;
&footer;
}

sub userlisting {

&header;

##### START SQL CREATION ####

$orderby = $INPUT{orderby};
$orderbyvalue = $INPUT{orderbyvalue};

	if ($INPUT{a_firstname} eq "on") {
		if ($INPUT{firstname_sign} eq "LIKE") {
			$searchfirstname = "firstname LIKE '%$INPUT{firstname}%'";
		}
		elsif ($INPUT{firstname_sign} eq "eq") {
			$searchfirstname = "firstname = '$INPUT{firstname}'";
		}
	}
	else {
			$searchfirstname = "firstname LIKE \'\%\'";
	}
	
	if ($INPUT{a_lastname} eq "on") {
		if ($INPUT{lastname_sign} eq "LIKE") {
			$searchlastname = "AND lastname LIKE '%$INPUT{lastname}%'";
		}
		elsif ($INPUT{lastname_sign} eq "eq") {
			$searchlastname = "AND lastname = '$INPUT{lastname}'";
		}
		else {
			$searchlastname = "";
		}
	}

	if ($INPUT{a_myERAAgent} eq "on") {
		$searchmyeraagent = "AND myERAAgent = '$INPUT{f_myERAAgent}'";
	}
	else {
		$searchmyeraagent = "";
	}

	if ($INPUT{a_registered}) {
		$searchregistered = "AND to_days(now())-to_days(datestamp) < '$INPUT{rsearchdays}'";
	}

	if ($INPUT{a_lastlogged}) {
		$searchlastlogged = "AND to_days(now())-to_days(lastlogin) < '$INPUT{searchdays}'";
	}

#############################

my $aasth = $dbh->prepare("select count(userid) from users WHERE $searchfirstname $searchlastname $searchmyeraagent $searchregistered $searchlastlogged");
$aasth->execute;
while (($userid) = $aasth->fetchrow_array()) {
$totalmembers = $userid;
}
my $basth = $dbh->prepare("select userid,firstname,lastname,lastlogin from users WHERE $searchfirstname $searchlastname $searchmyeraagent $searchregistered $searchlastlogged order by $orderby $orderbyvalue");
$basth->execute;
&startmain;
print qq~
<table border="0" cellpadding="1" cellspacing="0" width="581">
<tr>
<td valign="top" colspan="4"><font size="2"><b>::</b> We found <b>$totalmembers</b> users</font><br><br></td>
</tr>
<tr>
~;
$trcount = "1";
$totalperrow = "3";

while (($userid,$firstname,$lastname,$lastlogin) = $basth->fetchrow_array()) {

if ($INPUT{orderby} eq "lastname") {
$checkname = "<a href=\"admin.idx?action=useroverview&userid=$userid\">$lastname, $firstname</a>";
}
else {
$checkname = "<a href=\"admin.idx?action=useroverview&userid=$userid\">$firstname $lastname</a>";
}

print qq~
<td valign="top" width="25%">$checkname [<a href="admin.idx?action=useroverview&userid=$userid">V</a>,<a href="admin.idx?action=removeuser&userid=$userid">D</a>,<a href="admin.idx?action=edituser&userid=$userid">E</a>]</td>
~;
	if ($trcount eq $totalperrow) {
	print "</tr><tr>";
	$trcount = "1";
	}
	else {
	$trcount++;
	}
}
print qq~
</tr>
</table><br><br><br>
<center>
<a href="export_users.idx">Export User Data</a><br><br>
<a href="admin.idx">Refresh</a>
</center></td>
~;
$dbh->disconnect;
&footer;
}




sub useroverview {
&header;
&startmain;
print qq~
~;



if ($INPUT{email_block}) {
my $aaaasth = $dbh->do("UPDATE users SET email_block = '$INPUT{email_block}' WHERE userid = '$INPUT{userid}'");
}

if ($INPUT{email_openhouses}) {
my $abaaasth = $dbh->do("UPDATE users SET email_openhouses = '$INPUT{email_openhouses}' WHERE userid = '$INPUT{userid}'");
}


my $aasth = $dbh->prepare("select userid,email,password,firstname,lastname,address,city,state,zipcode,timetomove,realtor,datestamp,lastlogin,FoundBy,UserType,myERAAgent,Phone,access,tos_agreement,agentid,email_block,email_openhouses from users where userid = '$INPUT{userid}'");
$aasth->execute;
while (($userid,$email,$password,$firstname,$lastname,$address,$city,$state,$zipcode,$timetomove,$realtor,$datestamp,$lastlogin,$FoundBy,$UserType,$myERAAgent,$Phone,$access,$tos_agreement,$agentid,$email_block,$email_openhouses) = $aasth->fetchrow_array()) {


my $basth = $dbh->prepare("select userid,lender,dateclosed,price,notes,firstcontacted,lastcontacted,agentassigned,status,adminstatus from leadtracking where userid = '$userid'");
$basth->execute;
while (($userid,$lender,$dateclosed,$price,$notes,$firstcontacted,$lastcontacted,$agentassigned,$status,$adminstatus) = $basth->fetchrow_array()) {

if ($email_block eq "y") {
$email_block = "OK <a href=\"admin.idx?action=useroverview&userid=$INPUT{userid}&email_block=n\">Turn Block On</a>";
}
elsif ($email_block eq "n") {
$email_block = "BLOCKED <a href=\"admin.idx?action=useroverview&userid=$INPUT{userid}&email_block=y\">Turn Block Off</a>";
}
else {
$email_block = "UNDEF <a href=\"admin.idx?action=useroverview&userid=$INPUT{userid}&email_block=n\">Turn Block On</a>";
}

if ($email_openhouses eq "y") {
$email_openhouses = "OK <a href=\"admin.idx?action=useroverview&userid=$INPUT{userid}&email_openhouses=n\">Turn Block On</a>";
}
elsif ($email_openhouses eq "n") {
$email_openhouses = "BLOCKED <a href=\"admin.idx?action=useroverview&userid=$INPUT{userid}&email_openhouses=y\">Turn Block Off</a>";
}
else {
$email_openhouses = "UNDEF <a href=\"admin.idx?action=useroverview&userid=$INPUT{userid}&email_openhouses=n\">Turn Block On</a>";
}

unless ($timetomove) {
$timetomove = "<font color=\"red\">unspecified</font>";
}
unless ($access) {
$access = "<font color=\"red\">unspecified</font>";
}
unless ($Foundby) {
$Foundby = "<font color=\"red\">unspecified</font>";
}
unless ($Phone) {
$Phone = "<font color=\"red\">Phone # Not Given</font>";
}
print qq~

<table border="0" cellpadding="1" cellspacing="3" 100%>
<tr>
	<td valign="top" width="40%">
		<table border="0" cellpadding="1" cellspacing="0">
		<tr>
		<td valign="top">
			<img src="images/admin/dude.gif"><br>
		</td>
		<td valign="top">
			<font size="2" color="navy">
			<b>$firstname $lastname<br>
			<b>$address<br>
			$city, $state $zipcode</b><br>
			<b>$Phone</b><br>
			<a href="mailto:$email">$email</a><br>
			I am a <b>$UserType</b><br>
			</font>
		</td>
		</tr>
		</table>
	</td>
	<td valign="top" width="60%">
		<table border="0" cellpadding="2" cellspacing="1" width="100%" bgcolor="navy">
		<tr>
		<td valign="top" colspan="2"><font color="white"><b>User Information</b></font></td>
		</tr>
		<td bgcolor="white">Next Transaction Time</td><td bgcolor="white"><b>$timetomove</b><br></td>
		</tr>
		<tr>
		<td bgcolor="#A2E8FF">Working With A REALTOR?</td><td bgcolor="#A2E8FF"><b>$realtor $myERAAgent</b><br></td>
		</tr>
		<tr>
		<td bgcolor="white">Special Access Granted</td><td bgcolor="white"><b>$access</b><br></td>
		</tr>
		<tr>
		<td bgcolor="#A2E8FF">How User Found MuncieMLS</td><td bgcolor="#A2E8FF"><b>$FoundBy</b><br></td>
		</tr>
		<tr>
		<td bgcolor="white">Last Login<br></td><td bgcolor="white"><b>$lastlogin<Br></b></td>
		</tr>
		<tr>
		<td bgcolor="#A2E8FF">Registration Date<br></td><td bgcolor="#A2E8FF"><b>$datestamp<Br></b></td>
		</tr>
		<tr>
		<td bgcolor="white">TOS Agree Date<br></td><td bgcolor="white"><b>$tos_agreement<Br></b></td>
		</tr>
		<tr>
		<td bgcolor="white">User Actions<br></td><td bgcolor="white"><b><a href="admin.idx?action=removeuser&userid=$userid">Delete User & All Databases</a><br></td>
		</tr>
		<tr>
		<td bgcolor="white">E-Mail Blocks<br></td><td bgcolor="white"><b>All Mail $email_block - OpenHouse $email_openhouses<br></b></td>
		</tr>
		</table><br>
~;

		if ($INPUT{lead} eq "show") {
		print qq~
		<a href="admin.idx?action=useroverview&userid=$INPUT{userid}">Hide Lead Information</a><img src="http://www.munciemls.com/images/myhomes/hide.gif"><br><br>
		<table border="0" cellpadding="2" cellspacing="1" width="100%" bgcolor="navy">
		<tr>
		<td valign="top" colspan="2"><font color="white"><b>Lead Information</b></font></td>
		</tr>
		<td bgcolor="white">First Contacted</td><td bgcolor="white"><b>$firstcontacted</b><br></td>
		</tr>
		<tr>
		<td bgcolor="#A2E8FF">Agent Assigned</td><td bgcolor="#A2E8FF"><b>$agentassigned</b><br></td>
		</tr>
		</tr>
		<td bgcolor="white">Status</td><td bgcolor="white"><b>Agent $status<br>Admin $adminstatus</b><br></td>
		</tr>
		</tr>
		<td bgcolor="white">Last Contacted</td><td bgcolor="white"><b>$lastcontacted</b><br></td>
		</tr>
		<tr>
		<td bgcolor="#A2E8FF">Notes</td><td bgcolor="#A2E8FF"><b>$notes</b><br></td>
		</tr>
		<tr>
		<td bgcolor="white">Closing Info<br></td><td bgcolor="white"><b>$lender<br>$dateclosed<br>$price</b></td>
		</tr>
		</table><br><br>
		~;
		}
		else {
		print qq~
		<a href="admin.idx?action=useroverview&userid=$INPUT{userid}&lead=show">Show Lead Information</a><img src="http://www.munciemls.com/images/myhomes/show.gif"><br>
		~;
		}
print qq~
	</td>
</tr>
</table>
<br><br>
~;
}
$dbh->disconnect;
print qq~
<table border="0" cellspacing="0" cellpadding="2" width="100%">
	<tr>
		<td valign="top" bgcolor="navy" width="100%">
			<b><font color="white" size="2">User Saved Favorite Searches</font></b>
		</td>
	</tr>
</table>
~;
my $basth = $dbh->prepare("select * from search_fav where userid = '$INPUT{userid}' order by favid asc");
$basth->execute;
while (($userid,$favid,$searchstring,$searchname,$searchtype,$status) = $basth->fetchrow_array()) {
$foundsearch = "Yes";
if ($searchtype eq "res") {
$extension = "";
}
else {
$extension = "\_$searchtype";
}
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";
}
print qq~
<b>$searchname | $favid | $showstatus</b> | <a href="admin.idx?action=deletesearch&searchid=$favid&userid=$INPUT{userid}">Delete</a><br>
<br>
~;
}
unless ($foundsearch) {
print qq~
<font color="red"><b>No Saved Searches</b></font><br><br>
~;
}
print qq~
<table border="0" cellspacing="0" cellpadding="2" width="100%">
	<tr>
		<td valign="top" bgcolor="navy" width="100%">
			<b><font color="white" size="2">Properties Viewed</font></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="admin.idx?action=detailedhits&userid=$INPUT{userid}">View Detailed Viewed</a>
		</td>
	</tr>
</table>
~;
my $acasth = $dbh->prepare("select COUNT(userid) from hits where userid = '$INPUT{userid}'");
$acasth->execute;
while (($hitscount) = $acasth->fetchrow_array()) {
print qq~
$hitscount
~;
}
print qq~
<br><br>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
	<tr>
		<td valign="top" bgcolor="navy" width="100%">
			<b><font color="white" size="2">User Saved Favorite Homes</font></b>
		</td>
	</tr>
</table>
<table border="0" cellpadding="2" cellspacing="0" width="579">
<tr>
~;
my $casth = $dbh->prepare("select * from home_fav where userid = '$INPUT{userid}' order by favid asc");
$casth->execute;
$startcount = "1";
while (($userid,$favid,$mlsnumber,$listingtype,$notes) = $casth->fetchrow_array()) {
	$jasth = $dbh->prepare("select AddressNumber,AddressDirection,AddressStreet,City,Zip,State,Remarks from listings_$listingtype where MLSNUM = '$mlsnumber'");
	$jasth->execute;
	while (($AddressNumber,$AddressDirection,$AddressStreet,$City,$Zip,$state,$remarks_public) = $jasth->fetchrow_array()) {
$foundhomes = "yes";
if ($startcount eq "2") {
$startcount = "1";
$bgcolor = "FFFF99";
}
else {
$startcount++;
$bgcolor = "white";
}
$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 {
}
print qq~
<tr bgcolor="$bgcolor">
	<td valign="top">
		$AddressNumber $AddressDirection $AddressStreet<br>
	</td>
	<td valign="top">
		$City, $state $Zip<br>
	</td>
	<td valign="top">
		MLS #<a href="showdetails$extension.idx?mlsnumber=$mlsnumber">$mlsnumber</a>
	</td>
	</tr>
	<tr bgcolor="$bgcolor">
	<td valign="top" width="275" colspan="3">
		<b>User Notes: $notes</b><br>
	</td>
</tr>
~;
}
}
}
unless ($foundhomes) {
print qq~
<tr>
<td valign="top">
<font color="red"><b>No Saved Homes</b></font><br>
</td>
</tr>
~;
}
print qq~
</table><br><br>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
	<tr>
		<td valign="top" bgcolor="navy" width="100%" colspan="3">
			<b><font color="white" size="2">E-Mails Sent History Since Feb 14th, 2005</font></b>
		</td>
	</tr>
	<tr>
		<td><b>Date/Time Sent</b></td>
		<td><b>From</b></td>
		<td><b>Subject</b></td>
	</tr>
~;
my $emailsasth = $dbh->prepare("select emailid,emaildatetime,emailfrom,subject from emailstousers where userid = '$INPUT{userid}' order by emailid desc");
$emailsasth->execute;
while (($emailid,$emailtimedate,$emailfrom,$subject) = $emailsasth->fetchrow_array()) {
print qq~
<tr>
<td valign="top">Sent $emailtimedate</td>
<td valign="top">$emailfrom</td>
<td valign="top"><a href="admin.idx?action=view_email&emailid=$emailid" target="_blank">$subject</a></td>
</tr>
~;
}
print qq~
</table>
~;




print qq~
</td>
~;
&footer;
}

sub newagent {
&header;
&startmain;
print qq~
	New Agent Data Input Form<br>
<center>
	<table border="0" cellpadding="3" cellspacing="0" width="600">
		<tr>
			<td colspan="2" bgcolor="navy"><font color="white">Contact / Business Card Information</font></td>
		</tr>
		<tr>
			<td valign="top" width="300">First & Last Name</td>
			<td valign="top" width="300"><input type="text" class="textbox" name="firstname"> <input type="text" class="textbox" name="lastname"></td>
		</tr>
		<tr>
			<td bgcolor="white">Title</td>
			<td bgcolor="white">
				<select name="title">
				<option value="REALTORŪ, Sales Associate">REALTORŪ, Sales Associate</option>
				<option value="BROKERŪ, Sales Associate">BROKERŪ, Sales Associate</option>
				</select>
			</td>
		</tr>
		<tr>
			<td bgcolor="white">Designations</td>
			<td bgcolor="white">
				<input type="text" class="textbox" name="designations"> <a href="designations.html"> [ Types of Designations ]</a><br>
			</td>
		</tr>
		<tr>
			<td bgcolor="white" width="300">Phone 1 Type<br></td>
			<td bgcolor="white" width="300">
				<select name="phone1name">
				<option value="Office">Office</option>
				</select> 
				<select name="phone1number">
				<option value="765-741-9111">765-741-9111</option>
				</select>
			</td>
		</tr>
		<tr>
			<td bgcolor="white" width="300">VoiceMail Ext.<br></td>
			<td bgcolor="white" width="300">
				Extension: <input type="text" name="vmext"><br>
			</td>
		</tr>
		<tr>
			<td bgcolor="white" width="300">Phone 2 Type<br></td>
			<td bgcolor="white" width="300">
				<select name="phone2name">
				<option value="">-- No Number --</option>
				<option value="Home Office">Home Office</option>
				<option value="Mobile">Mobile</option>
				<option value="Home">Home</option>
				<option value="Pager">Pager</option>
				</select> 
				<input type="text" name="phone2number">
			</td>
		</tr>
		<tr>
			<td bgcolor="white" width="300">Phone 3 Type<br></td>
			<td bgcolor="white" width="300">
				<select name="phone3name">
				<option value="">-- No Number --</option>
				<option value="Home Office">Home Office</option>
				<option value="Mobile">Mobile</option>
				<option value="Home">Home</option>
				<option value="Pager">Pager</option>
				</select> 
				<input type="text" name="phone3number">
			</td>
		</tr>
		<tr>
			<td bgcolor="white" width="300">Phone 4 Type<br></td>
			<td bgcolor="white" width="300">
				<select name="phone4name">
				<option value="">-- No Number --</option>
				<option value="Home Office">Home Office</option>
				<option value="Mobile">Mobile</option>
				<option value="Home">Home</option>
				<option value="Pager">Pager</option>
				</select> 
				<input type="text" name="phone4number">
			</td>
		</tr>
		<tr>
			<td valign="top" width="300">E-Mail Address</td>
			<td valign="top" width="300">
				<input type="text" class="textbox" name="email" value="user\@host.com"><br>
			</td>
		</tr>
		
		<tr>
			<td valign="top" width="300">Website Address</td>
			<td valign="top" width="300">
				<input type="text" class="textbox" name="website" value="http://www.MuncieMLS.com"><br>
			</td>
		</tr>
		<tr>
			<td colspan="2" bgcolor="navy"><font color="white">E-Mail Options</font></td>
		</tr>
		<tr>
			<td valign="top" width="300">Use Eagle Office Email or Forward Office Email to Other Email Address?</td>
			<td valign="top" width="300">
				   * Setup Office Email : <input type="checkbox" name="Setup_Office_Email"><br>
				   * Forward E-Mail: <input type="checkbox" class="textbox" name="Forward_Email"><br>
			</td>
		</tr>

		<tr>
			<td colspan="2" bgcolor="navy"><font color="white">Agent Login Information</font></td>
		</tr>
		<tr>
			<td valign="top" width="300">Eagle Network</td>
			<td valign="top" width="300">
				username: <input type="text" class="textbox" name="network_user" value="firstname.lastname"><br>
				password: <input type="text" class="textbox" name="network_pass"><br>
			</td>
		</tr>
		<tr>
			<td valign="top" width="300">Paragon Online<br><br>* Assigned By Board Office</td>
			<td valign="top" width="300">
				username: <input type="text" class="textbox" name="paragon_user"><br>
				password: <input type="text" class="textbox" name="paragon_pass"><br>
			</td>
		</tr>

		<tr>
			<td valign="top" width="300">ZipForm Online</td>
			<td valign="top" width="300">
				username: <input type="text" class="textbox" name="zipform_user"><br>
				password: <input type="text" class="textbox" name="zipform_pass"><br>
			</td>
		</tr>
		<tr>
			<td valign="top" width="300">TeamEagle.com</td>
			<td valign="top" width="300">
				username: <input type="text" class="textbox" name="teameagle_user"><br>
				password: <input type="text" class="textbox" name="teameagle_pass"><br>
			</td>
		</tr>
		<tr>
			<td valign="top" width="300">Long Distance / Copier / Alarm</td>
			<td valign="top" width="300">
				code: <input type="text" class="textbox" name="longdistance_pass"><br>
			</td>
		</tr>
	</table>
</center>
</td>
~;
&footer;
}

sub startmain {
print qq~
<td width="581" valign="top">
<img src="images/headers/admin.gif" height="33" width="581" alt="Administration"><br>
~;
if ($INPUT{action}) {
print qq~
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td valign="top" align="right"><a href="admin.idx">Return Home</a></td>
</tr>
</table>
~;
}
}