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

&checklogin;

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;

if ($INPUT{view} eq "details") { &details; }
elsif ($INPUT{view} eq "prospecting_linked") { &prospecting_linked; }
elsif ($INPUT{view} eq "create_prospect") { &create_prospect; }
elsif ($INPUT{view} eq "edit_prospect") { &edit_prospect; }
elsif ($INPUT{view} eq "edit_prospect_do") { &edit_prospect_do; }
elsif ($INPUT{view} eq "create_prospect_do") { &create_prospect_do; }
elsif ($INPUT{view} eq "overview_notes_show") { &overview_notes_show; }
elsif ($INPUT{view} eq "overview_documents") { &overview_documents; }
elsif ($INPUT{view} eq "search") { &search; }
elsif ($INPUT{view} eq "convert_contact") { &convert_contact; }
elsif ($INPUT{view} eq "letters") { &letters; }
elsif ($INPUT{view} eq "print") { &print; }
else { &main; }

sub convert_contact {

if ($INPUT{do} eq "yes") {


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 $basth = $dbh->prepare("select id,agent,type,firstname,lastname,address,spouse,city,state,zip,phone1type,phone1number,phone2type,phone2number,phone3type,phone3number,faxnumber,email,emailtwo,contacttype,initial_contactdate,last_contactdate,next_contactdate,source,notes from trans_boardprospect WHERE id = '$INPUT{prospectid}'");
$basth->execute;
while (($id,$agent,$type,$firstname,$lastname,$address,$spouse,$city,$state,$zip,$phone1type,$phone1number,$phone2type,$phone2number,$phone3type,$phone3number,$faxnumber,$email,$emailtwo,$contacttype,$initial_contactdate,$last_contactdate,$next_contactdate,$source,$notes) = $basth->fetchrow_array()) {

	@variables = ($agent,$type,$firstname,$lastname,$address,$spouse,$city,$state,$zip,$phone1type,$phone1number,$phone2type,$phone2number,$phone3type,$phone3number,$faxnumber,$email,$emailtwo,$contacttype,$initial_contactdate,$last_contactdate,$next_contactdate,$source,$notes);
	$sql_query = "INSERT INTO trans_boardcontact values ('',?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
	my $aasth = $dbh->do($sql_query, undef, @variables);

		my $zaasth = $dbh->prepare("select id from trans_boardcontact WHERE agent = '$INPUT{agent}' ORDER BY id DESC LIMIT 0,1");
		$zaasth->execute;
		while (($newcontactid) = $zaasth->fetchrow_array()) {

		my $getnasth = $dbh->prepare("select noteid,prospectid,datetime,addedby,note from trans_boardprospectnotes WHERE prospectid = '$INPUT{prospectid}'");
		$getnasth->execute;
		while (($noteid,$prospectid,$datetime,$addedby,$note) = $getnasth->fetchrow_array()) {

			@newnvariables = ($newcontactid,$datetime,$addedby,$note);
			$newnsql_query = "INSERT INTO trans_boardcontactnotes values ('',?,?,?,?)";
			my $newnasth = $dbh->do($newnsql_query, undef, @newnvariables);

		}

		my $getdasth = $dbh->prepare("select did from documents WHERE matchcat = 'p' AND matchid = '$INPUT{prospectid}'");
		$getdasth->execute;
		while (($did) = $getdasth->fetchrow_array()) {		

			@newdvariables = ($newcontactid);
			$newdsql_query = "UPDATE documents set matchcat = 'c', matchid = ? WHERE did = '$did'";
			my $newdasth = $dbh->do($newdsql_query, undef, @newdvariables);				

		}
		$getcontactid = $newcontactid;
		}


@delprospectvariables = ($INPUT{prospectid});
$delprospectsql_query = "DELETE FROM trans_boardprospect WHERE id = ?";
my $delprospectasth = $dbh->do($delprospectsql_query, undef, @delprospectvariables);

@delprospectnotesvariables = ($INPUT{prospectid});
$delprospectnotessql_query = "DELETE FROM trans_boardprospectnotes WHERE prospectid = ?";
my $delprospectnotesasth = $dbh->do($delprospectnotessql_query, undef, @delprospectnotesvariables);

@delprospectapvariables = ($INPUT{prospectid});
$delprospectapsql_query = "DELETE from trans_boardtask_triggers where idlink = ? and task_type = 'Prospect'";
my $delprospectapasth = $dbh->do($delprospectapsql_query, undef, @delprospectapvariables);



}

print qq~
<html>
<head>
<title>Converting Prospect To Contact</title>
<meta http-equiv="Refresh" content="1; URL=http://connect.eaglesold.com/contacts.idx?action=overview_contact&agent=$INPUT{agent}&contactid=$getcontactid">
</head>
<body bgcolor="white">
<br><br><br><br>
<center><font size="3" face="Arial" color="Red">Please wait, Processing Conversion</font><br><br>
<font color="red">
Converting Data<br>
Converting Notes Information<br>
Converting Documents<br>
Deleting Prospect Data<br>
Deleting Prospect Notes<br>
Cleaning Up Prospect Documents<br>
</font>
<br><br>
<center><font size="3" face="Arial" color="Red">Please wait, Processing</font><br>You will be redirected to when finished.  If not <a href="http://connect.eaglesold.com/contacts.idx?agent=$INPUT{agent}">Click Here</a>.</center>
</body>
</html>
~;
}
else {

print qq~
<html>
<head>
<title>Convert Prospect To Contact -- Eagle Real Estate, Inc. -  Connect.EagleSold.com</title>
~;

&header;

print qq~
<td valign="top" width="581">
<img src="images/trans_sys/my_prospects.gif" height="33" width="581" alt="My Prospects"><br><br>
<font size="4" color="red">Really Convert Prospect $INPUT{name} to Contact?</font><br>
are you sure you want to convert?<br><br>
<a href="prospects.idx?action=overview_prospect_convert&agent=$INPUT{agent}&prospectid=$INPUT{prospectid}&do=yes">Yes</a> or <a href="prospect.idx?agent=$INPUT{agent}">No [ Cancel ]</a><br><br>
If you select yes the following information will be converted to a contact:<br><br>
<font color="red">
Converting Data<br>
Converting Notes Information<br>
Converting Documents<br>
Deleting Prospect Data<br>
Deleting Prospect Notes<br>
Cleaning Up Prospect Documents<br>
Remove Any Active Action Plans<br>
</font>
</td>
~;

&footer;

}

}

sub search {

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

print qq~
<html>
<head>
<title>My Prospecting -- The ORR Home Selling Team - Connect.EagleSold.com</title>
<script language="JavScript">
function submit()
{
	 document.changestatus.submit();
}
</script>
~;

$display_full = "yes";
&header;
print qq~
<td valign="top" width="751">
<a href="index.idx"><img src="images/headers/returnhome.gif" border="0" alt="Return Home"></a><img src="images/headers/prospecting_center.gif" height="33" width="581" alt="Prospecting Center"><br><br>

~;

print qq~
<br>
<img src="images/trans_sys/my_prospects.gif" alt="My prospects"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>use the alphabet below to search your prospects</b><br><br>
<table border="0" cellpadding="6" cellspacing="1" bgcolor="navy" width="100%">
<tr>
<td bgcolor="#CCCCFF">
<table border="0" cellpadding="3" cellspacing="0" width="100%">
<tr>
<td><b><font size="3">Search your prospects by Lastname</font></b><br></td>
<td align="right">
<a href="prospects.idx?action=create_prospect&agent=$INPUT{agent}">Create A New prospect</a><br>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor="white">
<center>
<a href="prospecting.idx?agent=$INPUT{agent}&view=search&prospect=%">All</a> 
<a href="prospecting.idx?agent=$INPUT{agent}&view=search&prospect=A">A</a> | 
<a href="prospecting.idx?agent=$INPUT{agent}&view=search&prospect=B">B</a> | 
<a href="prospecting.idx?agent=$INPUT{agent}&view=search&prospect=C">C</a> | 
<a href="prospecting.idx?agent=$INPUT{agent}&view=search&prospect=D">D</a> | 
<a href="prospecting.idx?agent=$INPUT{agent}&view=search&prospect=E">E</a> | 
<a href="prospecting.idx?agent=$INPUT{agent}&view=search&prospect=F">F</a> | 
<a href="prospecting.idx?agent=$INPUT{agent}&view=search&prospect=G">G</a> | 
<a href="prospecting.idx?agent=$INPUT{agent}&view=search&prospect=H">H</a> | 
<a href="prospecting.idx?agent=$INPUT{agent}&view=search&prospect=I">I</a> | 
<a href="prospecting.idx?agent=$INPUT{agent}&view=search&prospect=J">J</a> | 
<a href="prospecting.idx?agent=$INPUT{agent}&view=search&prospect=K">K</a> | 
<a href="prospecting.idx?agent=$INPUT{agent}&view=search&prospect=L">L</a> | 
<a href="prospecting.idx?agent=$INPUT{agent}&view=search&prospect=M">M</a> | 
<a href="prospecting.idx?agent=$INPUT{agent}&view=sea10/29/2009 12:21:03 PMrch&prospect=N">N</a> | 
<a href="prospecting.idx?agent=$INPUT{agent}&view=search&prospect=O">O</a> | 
<a href="prospecting.idx?agent=$INPUT{agent}&view=search&prospect=P">P</a> | 
<a href="prospecting.idx?agent=$INPUT{agent}&view=search&prospect=Q">Q</a> | 
<a href="prospecting.idx?agent=$INPUT{agent}&view=search&prospect=R">R</a> | 
<a href="prospecting.idx?agent=$INPUT{agent}&view=search&prospect=S">S</a> | 
<a href="prospecting.idx?agent=$INPUT{agent}&view=search&prospect=T">T</a> | 
<a href="prospecting.idx?agent=$INPUT{agent}&view=search&prospect=U">U</a> | 
<a href="prospecting.idx?agent=$INPUT{agent}&view=search&prospect=V">V</a> | 
<a href="prospecting.idx?agent=$INPUT{agent}&view=search&prospect=W">W</a> | 
<a href="prospecting.idx?agent=$INPUT{agent}&view=search&prospect=X">X</a> | 
<a href="prospecting.idx?agent=$INPUT{agent}&view=search&prospect=Y">Y</a> | 
<a href="prospecting.idx?agent=$INPUT{agent}&view=search&prospect=Z">Z</a>
</center><br>
~;

if ($INPUT{prospect}) {
my $basth = $dbh->prepare("select id,agentid,type,contact_firstname,contact_lastname,contact_spouse from trans_boardprospecting WHERE agentid = '600' AND contact_lastname LIKE '$INPUT{prospect}%' ORDER by contact_lastname ASC");
$basth->execute;

		$trcount = "1";
		$totalperrow = "3";
		$rowcolor1 = "1";
		$rowcolor2 = "2";
		print qq~
		<table border="0" cellpadding="2" cellspacing="1" width="100%" bgcolor="gray">
		<tr bgcolor="#FFFFFF">
		~;

while (($prospectid,$agent,$type,$firstname,$lastname,$spouse) = $basth->fetchrow_array()) {

			if ($rowcolor1 eq $rowcolor2) {
			$color = "#FFFFFF";
			$rowcolor1 = "1";
			}
			else {
			$color = "#FFFF99";
			$rowcolor1++;
			}

	if ($spouse ne "") {
	$spouse = " & $spouse ";
	}
	else {
	$spouse = "";
	}
print qq~
<td>
<a href="prospecting.idx?view=details&id=$prospectid&agent=$Cook{agentid}&return=search">$lastname, $firstname$spouse</a>  <a href="prospects.idx?action=overview_prospect&agent=$INPUT{agent}&prospectid=$prospectid"><img src="images/trans_sys/button_view.gif" alt="View details for $lastname, $firstname$spouse" border="0"></a><br>
</td>
~;

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

$ccfound = "yes";
}

		print qq~
		</tr>
		</table>
		~;

unless ($ccfound eq "yes") {
print qq~
<font color="red" size="3" face="Arial"><b>No prospects Found, Click on the first letter in the alphabet above that corresponds with your prospects lastname to try another search.  If your prospect is not listed you can create a new prospect by clicking on the link above.</b></font><br>
~;
}
}
else {
print qq~
<font color="red" size="3" face="Arial"><b>Click on the first letter in the alphabet above that corresponds with your prospects lastname to search your prospects.</b></font><br>
~;
}


print qq~
</td>
</tr>
</table>
<br>
<font size="3"><b>Recently Added Prospects within the last 2 weeks</b><hr color="red" width="100%">
<table border="0" cellpadding="2" cellspacing="1" bgcolor="red" width="100%">
<tr>
<td><u><b>Date Added</b></u></td>
<td><u><b>Assigned To</b></u></td>
<td><u><b>Prospect Name</b></u></td>
<td><u><b>Category</b></u></td>
<td><u><b>Lead Source</b></u></td>
</tr>
~;

my $casth = $dbh->prepare("select id,contact_firstname,contact_spouse,contact_lastname,type,DATE_FORMAT(load_datetime, '%M %D, %Y'),assigned_to,lead_source from trans_boardprospecting WHERE agentid = '600' AND load_datetime BETWEEN DATE_ADD(now(), INTERVAL -14 DAY) AND now() ORDER BY load_datetime DESC");
$casth->execute;
while (($id,$firstname,$spouse,$lastname,$contacttype,$initial_contactdate,$assigned_to,$lead_source) = $casth->fetchrow_array()) {
print qq~
<tr>
<td bgcolor="white">$initial_contactdate</td>
<td bgcolor="white">$assigned_to</td>
<td bgcolor="white"><a href="http://connect.eaglesold.com/prospecting.idx?view=details&id=$id&agent=$Cook{agentid}&return=search">$firstname $spouse $lastname</a><br></td>
<td bgcolor="white">$contacttype</td>
<td bgcolor="white">$lead_source</td>
</tr>
~;
$found = "yes";
}

unless ($found eq "yes") {
print qq~No Prospects Have Saved Next Contact Dates Yet!~;
}


print qq~
</table>
<br>
</font>
</td>
</td>
~;
&footer;

}


sub prospecting_linked {
print qq~
<html>
<head>
<title></title>
<link rel="stylesheet" TYPE="text/css" href="includes/style.css">
</head>
<body bgcolor="white">
~;

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;

#passed varibles do = search   id



if ($INPUT{do} eq "add") {

	$address = "$INPUT{addressnumber} $INPUT{addressstreet}";

	@variables = ($INPUT{prospectingid},$INPUT{mlsnumber},$address,$INPUT{city},$INPUT{price},$INPUT{sqft},$INPUT{beds},$INPUT{baths},$INPUT{yrbuilt});
	$sql_query = "INSERT INTO trans_boardtranstoprospecting values ('',?,?,?,?,?,?,?,?,?)";
	my $zzaasth = $dbh->do($sql_query, undef, @variables);

		print qq~
		<html>
		<head>
		<title>Making Changes to Datebase</title>
		<meta http-equiv="Refresh" content="1; URL=http://connect.eaglesold.com/prospecting.idx?view=prospecting_linked&prospectingid=$INPUT{prospectingid}">
		</head>
		<body bgcolor="white">
		<br><br><br><br>
		<center><font size="3" face="Arial" color="Red">Please wait, Processing</font><br>You will be redirected to when finished.  If not <a href="http://connect.eaglesold.com/prospecting.idx?view=prospecting_linked&prospectingid=$INPUT{prospectingid}">Click Here</a>.</center>
		</body>
		</html>
		~;

}
elsif ($INPUT{do} eq "search") {

	print qq~<b>Choose The Listing Below to Link Prospect With</b>  | <a href="prospecting.idx?view=prospecting_linked&prospectingid=$INPUT{prospectingid}">Cancel</a><br>~;




	my $res3_prop_search = $dbh->prepare("select MLSNUM,AddressNumber,AddressStreet,City,Price,YearBuilt,TotalSqFt,Bedrooms,FullBaths,HalfBaths from listings_res3 WHERE (addressnumber LIKE '%$INPUT{query}%' OR addressstreet LIKE '%$INPUT{query}%' OR MLSNUM LIKE '%$INPUT{query}%')");
	$res3_prop_search->execute;
	while (($mlsnumber,$addressnumber,$addressstreet,$city,$price,$yrbuilt,$sqft,$beds,$fullbaths,$halfbaths) = $res3_prop_search->fetchrow_array()) {

		$s_mlsnumber = "$mlsnumber"; $s_addressnumber = "$addressnumber"; $s_addressstreet = "$addressstreet";

		$baths = ($fullbaths+$halfbaths);
		if ($mlsnumber =~ /$INPUT{query}/i) { $s_mlsnumber = "<span class=highlight>$mlsnumber</span>"; }
		if ($addressnumber =~ /$INPUT{query}/i) { $s_addressnumber = "<span class=highlight>$addressnumber</span>"; }
		if ($addressstreet =~ /$INPUT{query}/i) { $s_addressstreet = "<span class=highlight>$addressstreet</span>"; }

		print qq~Website | <a href="prospecting.idx?view=prospecting_linked&prospectingid=$INPUT{prospectingid}&do=add&mlsnumber=$mlsnumber&addressnumber=$addressnumber&addressstreet=$addressstreet&city=$city&price=$price&beds=$beds&baths=$baths&sqft=$sqft&yrbuilt=$yrbuilt">MLS#$s_mlsnumber $s_addressnumber $s_addressstreet</a><br>~;
	}

	my $trans_prop_search = $dbh->prepare("select status,mlsnumber,addressnumber,addressstreet,city,listingprice from trans_board WHERE agent = '600' AND (status = 'Active' OR status = 'Pending') AND (addressnumber LIKE '%$INPUT{query}%' OR addressstreet LIKE '%$INPUT{query}%' OR mlsnumber LIKE '%$INPUT{query}%')");
	$trans_prop_search->execute;
	while (($status,$mlsnumber,$addressnumber,$addressstreet,$city,$price) = $trans_prop_search->fetchrow_array()) {

		$baths = ($fullbaths+$halfbaths);
		if ($mlsnumber =~ /$INPUT{query}/i) { $mlsnumber = "<span class=highlight>$mlsnumber</span>"; }
		if ($addressnumber =~ /$INPUT{query}/i) { $addressnumber = "<span class=highlight>$addressnumber</span>"; }
		if ($addressstreet =~ /$INPUT{query}/i) { $addressstreet = "<span class=highlight>$addressstreet</span>"; }

		print qq~Connect | $status | <a href="prospecting.idx?view=prospecting_linked&prospectingid=$INPUT{prospectingid}&do=add&mlsnumber=$mlsnumber&addressnumber=$addressnumber&addressstreet=$addressstreet&city=$city&price=$price&beds=$beds&baths=$baths&sqft=$sqft&yrbuilt=$yrbuilt">MLS#$s_mlsnumber $s_addressnumber $s_addressstreet</a><br>~;
	}



}
elsif ($INPUT{do} eq "delete") {

	@variables = ($INPUT{id});
	$sql_query = "DELETE from trans_boardtranstoprospecting WHERE id = ?";
	my $zzaasth = $dbh->do($sql_query, undef, @variables);

		print qq~
		<html>
		<head>
		<title>Making Changes to Datebase</title>
		<meta http-equiv="Refresh" content="1; URL=http://connect.eaglesold.com/prospecting.idx?view=prospecting_linked&prospectingid=$INPUT{prospectingid}">
		</head>
		<body bgcolor="white">
		<br><br><br><br>
		<center><font size="3" face="Arial" color="Red">Please wait, Processing</font><br>You will be redirected to when finished.  If not <a href="http://connect.eaglesold.com/prospecting.idx?view=prospecting_linked&prospectingid=$INPUT{prospectingid}">Click Here</a>.</center>
		</body>
		</html>
		~;

}
else {

	my $casth = $dbh->prepare("select COUNT(id) from trans_boardtranstoprospecting where prospectingid = '$INPUT{prospectingid}'");
	$casth->execute;
		while (($cid) = $casth->fetchrow_array()) {
		$NumOfRecs = $cid;
		}

	$print_listinglist=qq~<b>Found $NumOfRecs Linked Listing(s)</b><br>~;


	# SET PROFILER NUM OF RECS
	$total_price_count = $NumOfRecs;
	$total_sqft_count = $NumOfRecs;
	$total_yearbuilt_count = $NumOfRecs;
	$total_beds_count = $NumOfRecs;
	$total_baths_count = $NumOfRecs;

	my $asth = $dbh->prepare("select id,prospectingid,mlsnumber,address,city,price,sqft,beds,baths,yrbuilt from trans_boardtranstoprospecting where prospectingid = '$INPUT{prospectingid}'");
	$asth->execute;
		while (($id,$prospectingid,$mlsnumber,$address,$city,$price,$sqft,$beds,$baths,$yrbuilt) = $asth->fetchrow_array()) {

	if ($price eq "") { $price = "0"; }
	if ($sqft eq "") { $sqft = "0"; }
	if ($beds eq "") { $beds = "0"; }
	if ($baths eq "") { $baths = "0"; }
	if ($yrbuilt eq "") { $yrbuilt = "0"; }

	$price =~ s/\,//gi;
	$sqft =~ s/\,//gi;

	## Do the Math

	$total_price = ($price+$total_price);
	if ($price eq "0" || $price eq "") { $total_price_count = ($total_price_count-1); }
	if ($total_price_count eq "0") { $avg_price = "0"; } else { $avg_price = ($total_price/$total_price_count); }
	$avg_price = sprintf("%.0f", $avg_price);

	$total_sqft = ($sqft+$total_sqft);
	if ($sqft eq "0" || $sqft eq "") { $total_sqft_count = ($total_sqft_count-1); }
	if ($total_sqft_count eq "0") { $avg_sqft = "0"; } else { $avg_sqft = ($total_sqft/$total_sqft_count); }
	$avg_sqft = sprintf("%.0f", $avg_sqft);

	$total_yearbuilt = ($yrbuilt+$total_yearbuilt);
	if ($yrbuilt eq "0" || $yrbuilt eq "") { $total_yearbuilt_count = ($total_yearbuilt_count-1); }
	if ($total_yearbuilt_count eq "0") { $avg_yearbuilt = "0"; } else {	$avg_yearbuilt = ($total_yearbuilt/$total_yearbuilt_count); }
	$avg_yearbuilt = sprintf("%.0f", $avg_yearbuilt);

	$total_beds = ($beds+$total_beds);
	if ($beds eq "0" || $beds eq "") { $total_beds_count = ($total_beds_count-1); }
	if ($total_beds_count eq "0") { $avg_beds = "0"; } else { $avg_beds = ($total_beds/$total_beds_count);}
	$avg_beds = sprintf("%.2f", $avg_beds);

	$total_baths = ($baths+$total_baths);
	if ($baths eq "0" || $baths eq "") { $total_baths_count = ($total_baths_count-1); }
	if ($total_baths_count eq "0") { $avg_baths = "0"; } else {	$avg_baths = ($total_baths/$total_baths_count); }
	$avg_baths = sprintf("%.2f", $avg_baths);

	$print_listinglist.=qq~
				$mlsnumber | $address $city <a href="prospecting.idx?view=prospecting_linked&id=$id&prospectingid=$prospectingid&do=delete"><img src="http://connect.eaglesold.com/images/trans_sys/icons/delete-page-red.gif" alt="Delete This Note" height="14" width="14" border="0"></a><br>
			~;
		$found = "yes";
		$print_profilerdata=qq~<table border="0" cellpadding="3" cellspacing="0" bgcolor="green" width="100%"><tr><td valign="top" width="100%"><font color="white"><b> -- > ORRTeam Prospect Profiler: Buyer Looking For</b><br><b>Price</b> \$$avg_price<sup>($total_price_count)</sup><b>SQFT</b> $avg_sqft<sup>($total_sqft_count)</sup><b>Beds</b> $avg_beds<sup>($total_beds_count)</sup><b>Baths</b> $avg_baths<sup>($total_baths_count)</sup><b>Year</b> $avg_yearbuilt<sup>($total_yearbuilt_count)</sup></font><br></td></tr></table>~;
		}			
	unless ($found eq "yes") {
		$print_profilerdata=qq~<table border="0" cellpadding="3" cellspacing="0" bgcolor="red" width="100%"><tr><td valign="top" width="100%"><font color="white"><b> -- > ORRTeam Prospect Profiler: Buyer Looking For</b><br><b><u>Let me work, Link some listings with the prospect first!</u></b></font><br></td></tr></table>~;
		$print_listinglist.=qq~<font color="red" face="Tahoma"><b>Prospect not linked to listings yet!</b></font><br>~;
	}

print qq~
$print_profilerdata<br>
~;
	if ($INPUT{hide} eq "list") { } else {
		print qq~$print_listinglist<br>~;
	}
}

print qq~
</body>
</html>
~;
}

sub print {

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 $basth = $dbh->prepare("SELECT id,agentid,status,message_data,type,DATE_FORMAT(load_datetime, '%b %D, %Y %h\%p'),loaded_by,assigned_to,lead_source,prop_address_number,prop_address_direction,prop_address_street,prop_address2,prop_city,prop_zip,contact_firstname,contact_spouse,contact_lastname,contact_address,contact_address2,contact_city,contact_state,contact_zip,contact_phone1type,contact_phone1_num1,contact_phone1_num2,contact_phone1_num3,contact_phone2type,contact_phone2_num1,contact_phone2_num2,contact_phone2_num3,contact_emailaddress,previous_agent,price_high,price_low,DATE_FORMAT(last_followup, '%b %D, %Y'),DATE_FORMAT(next_followup, '%b %D, %Y'),result,DATE_FORMAT(hotlist_date, '%b %D, %Y') from trans_boardprospecting where id = '$INPUT{id}'");
$basth->execute;
while (($id,$agent,$status,$message_data,$type,$load_datetime,$loaded_by,$assigned_to,$lead_source,$prop_address_number,$prop_address_direction,$prop_address_street,$prop_address2,$prop_city,$prop_zip,$contact_firstname,$contact_spouse,$contact_lastname,$contact_address,$contact_address2,$contact_city,$contact_state,$contact_zip,$contact_phone1type,$contact_phone1_num1,$contact_phone1_num2,$contact_phone1_num3,$contact_phone2type,$contact_phone2_num1,$contact_phone2_num2,$contact_phone2_num3,$contact_emailaddress,$previous_agent,$price_high,$price_low,$last_followup,$next_followup,$result,$hotlist_date) = $basth->fetchrow_array()) {




	### START CHECKS ####

		if ($next_followup eq "" || $next_followup eq "0000-00-00") { $next_followup = "Not Entered"; }
		if ($hotlist_date eq "" || $hotlist_date eq "0000-00-00") { $hotlist_date = "Not Entered"; }
		if ($contact_spouse eq "") {} else { $contact_spouse = " & $contact_spouse"; }
		if ($contact_lastname) { $contact_lastname = "$contact_lastname<br>"; }
		if ($contact_lastname eq "") { $contact_firstname = "$contact_firstname<br>"; }

		unless ($contact_address eq "") { $check_address = "<b>Address</b> $contact_address<br>"; }
		unless ($contact_address2 eq "") { $check_address2 = "$contact_address2<br>"; }
		unless ($contact_city eq "") { $check_city = "$contact_city"; }
		unless ($contact_state eq "") { $check_state = "$contact_state"; }
		unless ($contact_zip eq "0") { $check_zip = "$contact_zip<br>"; } else { $check_zip = "<br>"; }
        unless ($contact_emailaddress eq "") { $contact_emailaddress = "<b>E-Mail</b> $contact_emailaddress"; }


		unless ($prop_address_number eq "") { $check_prop_address_number = "$prop_address_number"; }
		unless ($prop_address_direction eq "") { $check_prop_address_direction = " $prop_address_direction "; }
		unless ($prop_address_street eq "") { $check_prop_address_street = "$prop_address_street "; }
		unless ($prop_address2 eq "") { $check_prop_address2 = "$prop_address2<br>"; }
		unless ($prop_city eq "") { $check_prop_city = "$prop_city"; }
		unless ($prop_zip eq "") { $check_prop_zip = "$prop_zip"; } else { $check_prop_zip = "<br>"; }

		unless ($prop_address_street eq "") {
		$complete_prop_address = "<br><b>Prospect Property</b><br>$check_prop_address_number$check_prop_address_direction$check_prop_address_street$check_prop_address2$check_prop_city $check_prop_zip";
		}

		unless ($last_followup) { $last_followup = "<font color=\"Red\">Not Entered</font>"; }
		unless ($next_followup) { $next_followup = "<font color=\"Red\">Not Entered</font>"; }
		unless ($message_data eq "") { $message_data =qq~<br><font size="1"><b>$message_data</b></font><hr width="100%"~; }



print qq~
<html>
<head>
<title>My Prospecting Overview -- The ORR Home Selling Team - Connect.EagleSold.com</title>
</head>
<body bgcolor="white">
<center>
<table border="2" cellpadding="0" cellspacing="0" width="723">
<tr>
<td valign="top" width="100%">
<center>
<img src="images/prospect_header.jpg" alt=""><br>
<table border="0" cellpadding="2" cellspacing="0" width="100%">
<tr>
<td valign="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font face="Tahoma" size="3"><b>Prospect ID # $id | Inquire Date and Time: $load_datetime</b></font><br></td>
</tr>
</table>
<table border="0" cellpadding="5" cellspacing="0" width="100%">
<tr>
<td valign="top">

<table border="0" cellpadding="3" cellspacing="0" width="100%">
<tr>
<td valign="top" width="4%">
<img src="images/contacts_icon.gif" alt="$contact_firstname$contact_spouse $contact_lastname">
</td>
<td valign="top" width="36%">
<font size="3" face="Tahoma"><b>$contact_firstname$contact_spouse $contact_lastname</b>
$check_address
$check_city $check_state $check_zip

$complete_prop_address
</font>
</td>
<td valign="top" width="35%">
<font size="3" face="Tahoma">
<b>$contact_phone1type</b> $contact_phone1_num1-$contact_phone1_num2-$contact_phone1_num3<br>
<b>$contact_phone2type</b> $contact_phone2_num1-$contact_phone2_num2-$contact_phone2_num3<br>
$contact_emailaddress<br></font>
</td>
<td valign="top" width="25%">
<font size="4" face="Tahoma">
<b>Type</b><br>
<i>$type</i><br>
<b>Agent Assigned</b><br>
<i>$assigned_to</i><br>
<b>Lead Source</b><br>
<i>$lead_source</i><br>
</font>
</td>
</tr>
</table>
<br>
<table border="0" cellpadding="1" cellspacing="1" width="100%">
<tr>
<td valign="middle" align="center" width="45%" bgcolor="navy"><font color="white" face="Tahoma"><b>Listing(s) Prospect Inquired About<br></b></font></td>
<td width="55%" valign="top">
<iframe src="prospecting.idx?view=prospecting_linked&prospectingid=$INPUT{id}&hide=list" width="100%" height="32" noresize="noresize" scrolling ="yes" name="link" frameborder="0" marginwidth="0" marginheight="0"></iframe>
</td>
</tr>
<tr>
<td valign="top" colspan="2" width="100%">
~;
		my $aasth = $dbh->prepare("select mlsnumber,address,city from trans_boardtranstoprospecting where prospectingid = '$id' GROUP BY mlsnumber ORDER BY address desc");
		$aasth->execute;
		while (($mlsnumber,$address,$city) = $aasth->fetchrow_array()) {	
			print qq~<font face="tahoma" size="3"><b>&nbsp;&nbsp;MLS\# $mlsnumber - $address, $city</b><br></font>			
			~;
		$found = "yes";
		}
		unless ($found eq "yes") { print qq~<font color="red" face="Tahoma"><b>Not linked to any listings!</b></font><br>~; }
print qq~
</td>
</tr>
</table>
<br><br>
<table border="1" cellpadding="3" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="98%" id="AutoNumber1">
  <tr>
    <td width="70%" rowspan="3" valign="top"><font face="Tahoma">&nbsp;Notes:<br>$message_data
~;
my $cbasth = $dbh->prepare("select noteid,prospectingid,DATE_FORMAT(datetime, '%b %D, %Y at %h\:%i%p'),addedby,note from trans_boardprospecting_notes WHERE prospectingid = '$INPUT{id}' ORDER by datetime DESC");
$cbasth->execute;

while (($noteid,$nprospectingid,$datetime,$addedby,$tnote) = $cbasth->fetchrow_array()) {
	print qq~
	<hr width="100%">
	<font size="1"><b>$tnote</b> <i>added $datetime by $addedby</i></font><hr width="100%">
	~;
	$notes_found = "yes";
}
unless ($notes_found eq "yes") {
print qq~
<font color="red" face="Tahoma"><b>&nbsp;&nbsp;No Notes Added!</b></font><br>
~;
}
print qq~
</font></td>
    <td width="30%" valign="top"><font face="Tahoma">&nbsp;Last Followup:<br><b>&nbsp;&nbsp;$last_followup</b><br><br>
		<center><table border="0" cellpadding="4" cellspacing="0" bgcolor="navy" width="95%"><tr><td valign="top" bgcolor="white">New:<br><br><br></td></tr></table></center><br></td>
</tr>
<tr>
    <td width="30%" valign="top"><font face="Tahoma">&nbsp;Last Result:<br><b>&nbsp;&nbsp;$result</b><br><br>
		<center><table border="0" cellpadding="4" cellspacing="0" bgcolor="navy" width="95%"><tr><td valign="top" bgcolor="white">New:<br><br><br></td></tr></table></center><br></td>
</td>
</tr>
<tr>
    <td width="30%" valign="top"><font face="Tahoma">&nbsp;Next Followup:<br><b>&nbsp;&nbsp;$next_followup</b><br><br>
		<center><table border="0" cellpadding="4" cellspacing="0" bgcolor="navy" width="95%"><tr><td valign="top" bgcolor="white">New:<br><br><br></td></tr></table></center><br></td>

</td>
</tr>

</table>
<br><br>
</center>
</td>
</tr>
</table>
</center>
<script language="JavaScript" type="text/javascript">
<!--

var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1);

function printWin()
{
    if (pr) {
        // NS4+, IE5+
        window.print();
    } else if (!mac) {
        // IE3 and IE4 on PC
        VBprintWin();
    } else {
        // everything else
        handle_error();
    }
}

function handle_error()
{
    window.alert('Your browser does not support this print option. Press Control/Option + P to print.');
    return true;
}

// -->
</script>

<script language="VBSCript" type="text/vbscript">
<!--

sub window_onunload
    on error resume next
    ' Just tidy up when we leave to be sure we aren't
    ' keeping instances of the browser control in memory
    set WB = nothing
end sub

sub VBprintWin
    OLECMDID_PRINT = 6
    on error resume next

    ' IE4 object has a different command structure
    if da then
        call WB.ExecWB(OLECMDID_PRINT, 1)
    else
        call WB.IOleCommandTarget.Exec(OLECMDID_PRINT, 1, "", "")
    end if
end sub

' -->
</script>

<script language="JavaScript" type="text/javascript">
<!--
printWin();
// -->
</script>
</body>
</html>
~;
}

}




sub letters {
	my $letters_sth = $dbh->prepare("SELECT id,subject,body FROM trans_boardprospecting_letters WHERE id = '$INPUT{letterid}' and agent = '$INPUT{agent}'");
	$letters_sth->execute;
	while (($letters_id,$letters_subject,$letters_body) = $letters_sth->fetchrow_array()) {

		my $uasth = $dbh->prepare("SELECT id,agentid,status,type,DATE_FORMAT(load_datetime, '%b %D, %Y %h\%p'),loaded_by,assigned_to,lead_source,prop_address_number,prop_address_direction,prop_address_street,prop_address2,prop_city,prop_zip,contact_firstname,contact_spouse,contact_lastname,contact_address,contact_address2,contact_city,contact_state,contact_zip,contact_phone1type,contact_phone1_num1,contact_phone1_num2,contact_phone1_num3,contact_phone2type,contact_phone2_num1,contact_phone2_num2,contact_phone2_num3,contact_emailaddress,previous_agent,price_high,price_low,next_followup,result,DATE_FORMAT(hotlist_date, '%b %D, %Y') from trans_boardprospecting where id = '$INPUT{id}' and agentid = '$INPUT{agent}'");
		$uasth->execute;
		while (($id,$agent,$status,$type,$load_datetime,$loaded_by,$assigned_to,$lead_source,$prop_address_number,$prop_address_direction,$prop_address_street,$prop_address2,$prop_city,$prop_zip,$contact_firstname,$contact_spouse,$contact_lastname,$contact_address,$contact_address2,$contact_city,$contact_state,$contact_zip,$contact_phone1type,$contact_phone1_num1,$contact_phone1_num2,$contact_phone1_num3,$contact_phone2type,$contact_phone2_num1,$contact_phone2_num2,$contact_phone2_num3,$contact_emailaddress,$previous_agent,$price_high,$price_low,$next_followup,$result,$hotlist_date) = $uasth->fetchrow_array()) {

		if ($contact_spouse eq "") {} else { $contact_spouse = " & $contact_spouse"; }
		$show_name = "$contact_firstname$contact_spouse $contact_lastname";
		$show_propertyaddress = "$prop_address_number $prop_address_direction $prop_address_street, $prop_city";

			### DO THE CHANGES TO THE LETTER
			$letters_body =~ s/\$change_fullname/$show_name/g;
			$letters_body =~ s/\$change_propertyaddress/$show_propertyaddress/g;	
			print qq~
				$letters_body
			~;
		}
	}
$dbh->disconnect;
}

sub edit_prospect_do {
@variables = ($INPUT{record_status},$INPUT{record_type},$INPUT{message_data},$INPUT{loaded_by},$INPUT{assigned_to},$INPUT{lead_source},$INPUT{prop_address_number},$INPUT{prop_address_direction},$INPUT{prop_address_street},$INPUT{prop_address2},$INPUT{prop_city},$INPUT{prop_zip},$INPUT{contact_firstname},$INPUT{contact_spouse},$INPUT{contact_lastname},$INPUT{contact_address},$INPUT{contact_address2},$INPUT{contact_city},$INPUT{contact_state},$INPUT{contact_zip},$INPUT{contact_emailaddress},$INPUT{contact_phone1type},$INPUT{contact_phone1_num1},$INPUT{contact_phone1_num2},$INPUT{contact_phone1_num3},$INPUT{contact_phone2type},$INPUT{contact_phone2_num1},$INPUT{contact_phone2_num2},$INPUT{contact_phone2_num3},$INPUT{previous_agent},$INPUT{price_high},$INPUT{price_low},$INPUT{last_followup},$INPUT{next_followup},$INPUT{result},$INPUT{hotlist_date},$INPUT{id});
$sql_query = "update trans_boardprospecting set status = ?, type = ?, message_data = ?, loaded_by = ?, assigned_to = ?, lead_source = ?, prop_address_number = ?, prop_address_direction = ?, prop_address_street = ?, prop_address2 = ?, prop_city = ?, prop_zip = ?, contact_firstname = ?, contact_spouse = ?, contact_lastname = ?, contact_address = ?, contact_address2 = ?, contact_city = ?, contact_state = ?, contact_zip = ?, contact_emailaddress = ?, contact_phone1type = ?, contact_phone1_num1 = ?, contact_phone1_num2 = ?, contact_phone1_num3 = ?, contact_phone2type = ?, contact_phone2_num1 = ?, contact_phone2_num2 = ?, contact_phone2_num3 = ?, previous_agent = ?, price_high = ?, price_low = ?, last_followup = ?, next_followup = ?, result = ?, hotlist_date = ? where id = ?";
my $asth = $dbh->do($sql_query, undef, @variables);
print qq~
<html>
<head>
<title>Making Changes to Datebase</title>
<meta http-equiv="Refresh" content="1; URL=http://connect.eaglesold.com/prospecting.idx?view=details&id=$INPUT{id}&agent=$Cook{agentid}&status=$INPUT{status}&type=$INPUT{type}&assigned_show=$INPUT{assigned_show}&enddate=$INPUT{enddate}&sortby=$INPUT{sortby}">
</head>
<body bgcolor="white">
<br><br><br><br>
<center><font size="3" face="Arial" color="Red">Please wait, Processing</font><br>You will be redirected to when finished.  If not <a href="http://connect.eaglesold.com/prospecting.idx?view=details&id=$INPUT{id}&agent=$Cook{agentid}&status=$INPUT{status}&type=$INPUT{type}&assigned_show=$INPUT{assigned_show}&enddate=$INPUT{enddate}&sortby=$INPUT{sortby}">Click Here</a>.</center>
</body>
</html>
~;
}

sub edit_prospect {

my $uasth = $dbh->prepare("SELECT id,agentid,status,type,message_data,DATE_FORMAT(load_datetime, '%b %D, %Y %h\%p'),loaded_by,assigned_to,lead_source,prop_address_number,prop_address_direction,prop_address_street,prop_address2,prop_city,prop_zip,contact_firstname,contact_spouse,contact_lastname,contact_address,contact_address2,contact_city,contact_state,contact_zip,contact_phone1type,contact_phone1_num1,contact_phone1_num2,contact_phone1_num3,contact_phone2type,contact_phone2_num1,contact_phone2_num2,contact_phone2_num3,contact_emailaddress,previous_agent,price_high,price_low,last_followup,next_followup,result,hotlist_date from trans_boardprospecting where id = '$INPUT{id}' and agentid = '$INPUT{agent}'");
$uasth->execute;
while (($id,$agent,$record_status,$record_type,$message_data,$load_datetime,$loaded_by,$assigned_to,$lead_source,$prop_address_number,$prop_address_direction,$prop_address_street,$prop_address2,$prop_city,$prop_zip,$contact_firstname,$contact_spouse,$contact_lastname,$contact_address,$contact_address2,$contact_city,$contact_state,$contact_zip,$contact_phone1type,$contact_phone1_num1,$contact_phone1_num2,$contact_phone1_num3,$contact_phone2type,$contact_phone2_num1,$contact_phone2_num2,$contact_phone2_num3,$contact_emailaddress,$previous_agent,$price_high,$price_low,$last_followup,$next_followup,$result,$hotlist_date) = $uasth->fetchrow_array()) {

	my $aasth = $dbh->prepare("select firstname,lastname,email from agents where mlsid = '$INPUT{agent}'");
	$aasth->execute;
	while (($firstname,$lastname,$email) = $aasth->fetchrow_array()) {
	$loaded_bypull .= "<option value=\"$firstname $lastname\">$firstname $lastname</option>";
	}


	$dropdown_recordstatus = "<option value=\"$record_status\">$record_status</option>\n<option value=\"$record_status\">-------</option>\n";
	$dropdown_recordtype = "<option value=\"$record_type\">$record_type</option>\n<option value=\"$record_type\">-------</option>\n";
	$dropdown_loaded_by = "<option value=\"$loaded_by\">$loaded_by</option>\n<option value=\"$loaded_by\">-------</option>\n";
	$dropdown_assigned_to = "<option value=\"$assigned_to\">$assigned_to</option>\n<option value=\"$assigned_to\">-------</option>\n";
	$dropdown_lead_source = "<option value=\"$lead_source\">$lead_source</option>\n<option value=\"$lead_source\">-------</option>\n";
	$dropdown_contact_phone1type = "<option value=\"$contact_phone1type\">$contact_phone1type</option>\n<option value=\"$lead_source\">-------</option>\n";
	$dropdown_contact_phone2type = "<option value=\"$contact_phone2type\">$contact_phone2type</option>\n<option value=\"$lead_source\">-------</option>\n";
	$dropdown_result = "<option value=\"$result\">$result</option>\n<option value=\"$result\">-------</option>\n";

print qq~
<html>
<head>
<title>The ORR Home Selling Team - Prospecting System 2010 ver:1.4</title>
<script language="JavaScript" src="calendar1.js"></script>
<script language="JavaScript" src="calendar2.js"></script>
~;
&header;
print qq~
<td valign="top" width="581">
<img src="images/headers/prospecting_center.gif" height="33" width="581" alt="Prospecting Center"><br><br>
<form method="get" action="prospecting.idx" name="edit_prospect">
<input type="hidden" name="view" value="edit_prospect_do">
<input type="hidden" name="id" value="$INPUT{id}">
<input type="hidden" name="agent" value="$INPUT{agent}">
<font size="2">Edit Prospecting File</font><br>
<table border="0" cellpadding="2" cellspacing="0">
<tr>
<td colspan="2" align="right"><input type="submit" value="Save New Prospect"></td>
</tr>
<tr>
<td valign="top"><b>Record Status</b></td>
<td valign="top">
		<select name="record_status" class="form">
		$dropdown_recordstatus
		<option value="Active - New">Active - New</option>
		<option value="Active - Hot">Active - Hot</option>
		<option value="Active - Warm">Active - Warm</option>
		<option value="Active - Cool">Active - Cool</option>
		<option value="Client">Client</option>
		<option value="Stopped">Stopped</option>
		<option value="Inactive">Inactive</option>
		</select>
</td>
</tr>
<tr>
<td valign="top"><b>Record Type</b></td>
<td valign="top">
		<select name="record_type" class="form">
		$dropdown_recordtype
		<option value="Listing">Listing</option>
		<option value="Listing FSBO">Listing FSBO</option>
		<option value="Listing Expired">Listing Expired</option>
		<option value="Listing and Buyer">Listing and Buyer</option>
		<option value="Buyer">Buyer</option>
		<option value="Buyer">Unknown</option>
		~;
		if ($INPUT{agent} eq "122") { print qq~ <option value="Recruit">Recruit</option>~; }
		print qq~
		</select>
</td>
</tr>
<tr>
<td valign="top"><b>Loaded By</b></td>
<td valign="top">
	<select name="loaded_by" class="form">
	$dropdown_loaded_by
	$loaded_bypull
	</select>
</td>
</tr>
<tr>
<td valign="top"><b>Assigned To</b></td>
<td valign="top">
	<select name="assigned_to" class="form">
	$dropdown_assigned_to
	$loaded_bypull
	</select>
</td>
</tr>
<tr>
<td valign="top"><b>Lead Source</b></td>
<td valign="top">
	<select name="lead_source" class="form">
	$dropdown_lead_source
	<option value="ORRTEAM Ad Call">ORRTEAM AD Call</option>
	<option value="MESSAGE CENTER Call">MESSAGE CENTER Call</option>
	<option value="REMAX Ad Call">REMAX Ad Call</option>
	<option value="Proquest Call">Proquest Call</option>
	<option value="FSBO Sign">FSBO Sign</option>
	<option value="Newspaper">Newspaper</option>
	<option value="Open House">Open House</option>
	<option value="Cold Calling">Cold Calling</option>
	<option value="Expired From MLS">Expired From MLS</option>
	<option value="Web-ORRHomes.com">Web-ORRHomes.com</option>
	<option value="Web-MuncieMLS.com">Web-MuncieMLS.com</option>
	<option value="Web-REMAX.com">Web-REMAX.com</option>
	<option value="Web-REALTOR.com">Web-REALTOR.com</option>
	<option value="Web-Craigslist.com">Web-Craigslist.com</option>
	<option value="Web-Trulia.com">Web-Trulia.com</option>
	<option value="Web-Zillow.com">Web-Zillow.com</option>
	</select>
</td>
</tr>
<tr>
<td valign="top"><b>Property Address</b></td>
<td valign="top">
	<input type="text" name="prop_address_number" class="form" value="$prop_address_number"> Address Number<br>
	<input type="text" name="prop_address_direction" class="form" value="$prop_address_direction"> Address Direction<br>
	<input type="text" name="prop_address_street" class="form" value="$prop_address_street"> Address Street<br>
	<input type="text" name="prop_address2" class="form" value="$prop_address2"> Address2<br>
	<input type="text" name="prop_city" class="form" value="$prop_city"> City<br>
	<input type="text" name="prop_zip" class="form" value="$prop_zip"> Zip<br>
</td>
</tr>
<tr>
<td valign="top"><b>Contact Information</b></td>
<td valign="top">
	<input type="text" name="contact_firstname" class="form" value="$contact_firstname"> Firstname<br>
	<input type="text" name="contact_spouse" class="form" value="$contact_spouse"> Spouse<br>
	<input type="text" name="contact_lastname" class="form" value="$contact_lastname"> Lastname<br>
	<input type="text" name="contact_address" class="form" value="$contact_address"> Address<br>
	<input type="text" name="contact_address2" class="form" value="$contact_address2"> Address2<br>
	<input type="text" name="contact_city" class="form" value="$contact_city"> City<br>
	<input type="text" name="contact_state" class="form" value="$contact_state"> State<br>
	<input type="text" name="contact_zip" class="form" value="$contact_zip"> Zip<br>
	<input type="text" name="contact_emailaddress" class="form" value="$contact_emailaddress"> E-Mail Address<br>
	Phone 1 <select name="contact_phone1type" class="form">
	$dropdown_contact_phone1type
	<option value="Mobile">Mobile</option>
	<option value="Home">Home</option>
	<option value="Work">Work</option>
	<option value="Pager">Pager</option>
	<option value="Other">Other</option>
	</select> Number <input class=form type="text" name="contact_phone1_num1" size="1" maxlength="3" value="$contact_phone1_num1">-<input class=form type="text" name="contact_phone1_num2" size="1" maxlength="3" value="$contact_phone1_num2">-<input class=form type="text" name="contact_phone1_num3" size="2" maxlength="4" value="$contact_phone1_num3"><br>
	Phone 2 <select name="contact_phone2type" class="form">
	$dropdown_contact_phone2type
	<option value="Mobile">Mobile</option>
	<option value="Home">Home</option>
	<option value="Work">Work</option>
	<option value="Pager">Pager</option>
	<option value="Other">Other</option>
	</select> Number <input class=form type="text" name="contact_phone2_num1" size="1" maxlength="3" value="$contact_phone2_num1">-<input class=form type="text" name="contact_phone2_num2" size="1" maxlength="3" value="$contact_phone2_num2">-<input class=form type="text" name="contact_phone2_num3" size="2" maxlength="4" value="$contact_phone2_num3"><br>	
</td>
</tr>
<tr>
<td valign="top"><b>Original Data Received<br>(Usually By E-Mail)</b></td>
<td valign="top">
	<textarea name="message_data" class="form" cols="65" rows="13">$message_data</textarea><br>
</td>
</tr>
<tr>
<td valign="top"><b>Previous Agent</b></td>
<td valign="top">
			<input type="text" name="previous_agent" class="form" value="$previous_agent">
</td>
</tr>
<tr>
<td valign="top"><b>Estimated Price</b></td>
<td valign="top">
		\$<input type="text" name="price_high" size="1" maxlength="4" class="form" value="$price_high">,<input type="text" name="price_low" size="1" maxlength="3" class="form" value="$price_low"><br>
</td>
</tr>
<tr>
<td valign="top"><b>Last Followup Date</b></td>
<td valign="top">
				<input type="Text" name="last_followup" value="$last_followup" class="form" size="10">&nbsp;<a href="javascript:cal3.popup();"><img src="images/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the date"></a> Last Follow Up<br>
</td>
</tr>
<tr>
<td valign="top"><b>Next Followup Date</b></td>
<td valign="top">
				<input type="Text" name="next_followup" value="$next_followup" class="form" size="10">&nbsp;<a href="javascript:cal1.popup();"><img src="images/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the date"></a> Next Follow Up<br>
</td>
</tr>
<tr>
<td valign="top"><b>Hot List Date</b></td>
<td valign="top">
				<input type="Text" name="hotlist_date" value="$hotlist_date" class="form" size="10">&nbsp;<a href="javascript:cal2.popup();"><img src="images/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the date"></a> Hot List Date<br>
</td>
</tr>
<tr>
<td valign="top"><b>Result</b></td>
<td valign="top">
	<select name="result" class="form">
	$dropdown_result
				<option value="Called - Spoke with">Called - Spoke with</option>
				<option value="Called - No Answer">Called - No Answer</option>
				<option value="Called - Left MSG">Called - Left MSG</option>
				<option value="Called and Sent E-Mail">Called and Sent E-Mail</option>
				<option value="Called and Sent Letter">Called and Sent Letter</option>
				<option value="Called and Sent Postcard">Called and Sent Postcard</option>
				<option value="Sent E-Mail">Sent E-Mail</option>
				<option value="Sent Letter">Sent Letter</option>
				<option value="Sent Postcard">Sent Postcard</option>
				<option value="Met in Office">Met in Office</option>
				<option value="Showed Property">Showed Property</option>
				<option value="None">None</option>
	</select>
</td>
</tr>
<input type="hidden" name="status" value="$INPUT{status}">
<input type="hidden" name="type" value="$INPUT{type}">
<input type="hidden" name="assigned_show" value="$INPUT{assigned_show}">
<input type="hidden" name="enddate" value="$INPUT{enddate}">
<input type="hidden" name="sortby" value="$INPUT{sortby}">
<tr>
<td colspan="2"><center><input type="submit" value="Save New Prospect"></center></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
			<script language="JavaScript">
			<!-- 
				var cal1 = new calendar1(document.forms['edit_prospect'].elements['next_followup']);
				cal1.year_scroll = true;
				cal1.time_comp = false;

				var cal2 = new calendar1(document.forms['edit_prospect'].elements['hotlist_date']);
				cal2.year_scroll = true;
				cal2.time_comp = false;

				var cal3 = new calendar1(document.forms['edit_prospect'].elements['last_followup']);
				cal3.year_scroll = true;
				cal3.time_comp = false;
			//-->
			</script>
~;
&footer;
}

}

sub create_prospect_do {

	my $datebasth = $dbh->prepare("select DATE_FORMAT(DATE_ADD(now(), INTERVAL 1 DAY), '%Y-%m-%d')");
	$datebasth->execute;
	while (($newstartdate) = $datebasth->fetchrow_array()) {
	$enterdate = "$newstartdate";
	}
	@variables = ($INPUT{agent},$INPUT{record_status},$INPUT{message_data},$INPUT{record_type},$INPUT{loaded_by},$INPUT{assigned_to},$INPUT{lead_source},$INPUT{prop_address_number},$INPUT{prop_address_direction},$INPUT{prop_address_street},$INPUT{prop_address2},$INPUT{prop_city},$INPUT{prop_zip},$INPUT{contact_firstname},$INPUT{contact_spouse},$INPUT{contact_lastname},$INPUT{contact_address},$INPUT{contact_address2},$INPUT{contact_city},$INPUT{contact_state},$INPUT{contact_zip},$INPUT{contact_phone1type},$INPUT{contact_phone1_num1},$INPUT{contact_phone1_num2},$INPUT{contact_phone1_num3},$INPUT{contact_phone2type},$INPUT{contact_phone2_num1},$INPUT{contact_phone2_num2},$INPUT{contact_phone2_num3},$INPUT{contact_emailaddress},$INPUT{previous_agent},$INPUT{price_high},$INPUT{price_low},$enterdate,$INPUT{last_followup},$INPUT{hotlist_date});
	$sql_query = "INSERT INTO trans_boardprospecting values ('',?,?,?,?,now(),?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,'',?)";
	my $aasth = $dbh->do($sql_query, undef, @variables);

my $zaasth = $dbh->prepare("select id from trans_boardprospecting ORDER BY id DESC LIMIT 0,1");
$zaasth->execute;
while (($pid) = $zaasth->fetchrow_array()) {
$getnewid = $pid;
}
print qq~
<html>
<head>
<title>Making Changes to Datebase</title>
<meta http-equiv="Refresh" content="1; URL=http://connect.eaglesold.com/prospecting.idx?view=details&id=$getnewid&agent=$Cook{agentid}&status=$INPUT{status}&type=$INPUT{type}&assigned_show=$INPUT{assigned_show}&startdate=$INPUT{startdate}&enddate=$INPUT{enddate}">
</head>
<body bgcolor="white">
<br><br><br><br>
<center><font size="3" face="Arial" color="Red">Please wait, Processing</font><br>You will be redirected to when finished.  If not <a href="http://connect.eaglesold.com/prospecting.idx?view=details&id=$getnewid&agent=$Cook{agentid}&status=$INPUT{status}&type=$INPUT{type}&assigned_show=$INPUT{assigned_show}&startdate=$INPUT{startdate}&enddate=$INPUT{enddate}">Click Here</a>.</center>
</body>
</html>
~;

}

sub create_prospect {

	my $aasth = $dbh->prepare("select firstname,lastname,email from agents where mlsid = '$INPUT{agent}'");
	$aasth->execute;
	while (($firstname,$lastname,$email) = $aasth->fetchrow_array()) {
	$loaded_bypull .= "<option value=\"$firstname $lastname\">$firstname $lastname</option>";
	}

print qq~
<html>
<head>
<title>The ORR Home Selling Team - Prospecting System 2010 ver:1.4</title>
<SCRIPT TYPE="text/javascript">
<!--
var downStrokeField;
function autojump(fieldName,nextFieldName,fakeMaxLength)
{
var myForm=document.forms[document.forms.length - 1];
var myField=myForm.elements[fieldName];
myField.nextField=myForm.elements[nextFieldName];

if (myField.maxLength == null)
   myField.maxLength=fakeMaxLength;

myField.onkeydown=autojump_keyDown;
myField.onkeyup=autojump_keyUp;
}

function autojump_keyDown()
{
this.beforeLength=this.value.length;
downStrokeField=this;
}

function autojump_keyUp()
{
if (
   (this == downStrokeField) && 
   (this.value.length > this.beforeLength) && 
   (this.value.length >= this.maxLength)
   )
   this.nextField.focus();
downStrokeField=null;
}
//-->
</SCRIPT>
<script language="JavaScript" src="calendar1.js"></script>
<script language="JavaScript" src="calendar2.js"></script>
~;
&header;
print qq~
<td valign="top" width="581">
<img src="images/headers/prospecting_center.gif" height="33" width="581" alt="Prospecting Center"><br><br>
<form method="get" action="prospecting.idx" name="create_prospect">
<input type="hidden" name="view" value="create_prospect_do">
<input type="hidden" name="id" value="$INPUT{id}">
<input type="hidden" name="agent" value="$INPUT{agent}">
<font size="2" face="Arial Narrow"><b>Create New Prospecting File</b></font><br><br>
<table border="0" cellpadding="2" cellspacing="0">
<tr>
<td colspan="2"><center><input type="submit" value="Save New Prospect">  [ <a href="prospecting.idx?&agent=$Cook{agentid}&status=$INPUT{status}&type=$INPUT{type}&assigned_show=$INPUT{assigned_show}&startdate=$INPUT{startdate}&enddate=$INPUT{enddate}">Cancel Create</a> ]</center></td>
</tr>
<tr>
<td valign="top"><b>Record Status</b></td>
<td valign="top">
		<select name="record_status" class="form">
		<option value="Active - New" selected>Active - New</option>
		<option value="Active - Hot">Active - Hot</option>
		<option value="Active - Warm">Active - Warm</option>
		<option value="Active - Cool">Active - Cool</option>
		<option value="Inactive">Inactive</option>
		</select>
</td>
</tr>
<tr bgcolor="#CCCCFF">
<td valign="top"><b>Record Type</b></td>
<td valign="top">
		<select name="record_type" class="form">
		<option value="Listing">Listing</option>
		<option value="Listing FSBO">Listing FSBO</option>
		<option value="Listing Expired">Listing Expired</option>
		<option value="Listing and Buyer">Listing and Buyer</option>
		<option value="Buyer">Buyer</option>
		~;
		if ($INPUT{agent} eq "122") { print qq~ <option value="Recruit">Recruit</option>~; }
		print qq~
		</select>
</td>
</tr>
<tr>
<td valign="top"><b>Message Data Received<br>(Usually By E-Mail)</b></td>
<td valign="top">
	<textarea name="message_data" class="form" cols="47" rows="8"></textarea><br>
</td>
</tr>
<tr>
<td valign="top"><b>Loaded By</b></td>
<td valign="top">
	<select name="loaded_by" class="form">
	$loaded_bypull
	</select>
</td>
</tr>
<tr bgcolor="#CCCCFF">
<td valign="top"><b>Assigned To</b></td>
<td valign="top">
	<select name="assigned_to" class="form">
	$loaded_bypull
	</select>
</td>
</tr>
<tr>
<td valign="top"><b>Lead Source</b></td>
<td valign="top">
	<select name="lead_source" class="form">
	<option value="ORRTEAM Ad Call">ORRTEAM AD CALL</option>
	<option value="MESSAGE CENTER Call">MESSAGE CENTER Call</option>
	<option value="REMAX Ad Call">REMAX Ad Call</option>
	<option value="Proquest Call">Proquest Call</option>
	<option value="FSBO Sign">FSBO Sign</option>
	<option value="Newspaper">Newspaper</option>
	<option value="Open House">Open House</option>
	<option value="Cold Calling">Cold Calling</option>
	<option value="Expired From MLS">Expired From MLS</option>
	<option value="Web-ORRHomes.com">Web-ORRHomes.com</option>
	<option value="Web-MuncieMLS.com">Web-MuncieMLS.com</option>
	<option value="Web-REMAX.com">Web-REMAX.com</option>
	<option value="Web-REALTOR.com">Web-REALTOR.com</option>
	<option value="Web-Craigslist.com">Web-Craigslist.com</option>
	<option value="Web-Trulia.com">Web-Trulia.com</option>
	<option value="Web-Zillow.com">Web-Zillow.com</option>
	</select>
</td>
</tr>
<tr bgcolor="#CCCCFF">
<td valign="top"><b>Property Address</b></td>
<td valign="top">
	<input type="text" name="prop_address_number" class="form"> Address Number<br>
	<input type="text" name="prop_address_direction" class="form"> Address Direction<br>
	<input type="text" name="prop_address_street" class="form"> Address Street<br>
	<input type="text" name="prop_address2" class="form"> Address2<br>
	<input type="text" name="prop_city" class="form"> City<br>
	<input type="text" name="prop_zip" class="form"> Zip<br>
</td>
</tr>
<tr>
<td valign="top"><b>Contact Information</b></td>
<td valign="top">
	<input type="text" name="contact_firstname" class="form"> Firstname<br>
	<input type="text" name="contact_spouse" class="form"> Spouse<br>
	<input type="text" name="contact_lastname" class="form"> Lastname<br>
	<input type="text" name="contact_address" class="form"> Address<br>
	<input type="text" name="contact_address2" class="form"> Address2<br>
	<input type="text" name="contact_city" class="form"> City<br>
	<input type="text" name="contact_state" class="form"> State<br>
	<input type="text" name="contact_zip" class="form"> Zip<br>
	<input type="text" name="contact_emailaddress" class="form"> E-Mail Address<br>
	Phone 1 <select name="contact_phone1type" class="form">
	<option value="Mobile">Mobile</option>
	<option value="Mobile">Home</option>
	<option value="Mobile">Work</option>
	<option value="Mobile">Pager</option>
	<option value="Mobile">Other</option>
	</select> Number <input class=form type="text" name="contact_phone1_num1" size="1" maxlength="3">-<input class=form type="text" name="contact_phone1_num2" size="1" maxlength="3">-<input class=form type="text" name="contact_phone1_num3" size="2" maxlength="4"><br>

	Phone 2 <select name="contact_phone2type" class="form">
	<option value="Mobile">Mobile</option>
	<option value="Mobile">Home</option>
	<option value="Mobile">Work</option>
	<option value="Mobile">Pager</option>
	<option value="Mobile">Other</option>
	</select> Number <input class=form type="text" name="contact_phone2_num1" size="1" maxlength="3">-<input class=form type="text" name="contact_phone2_num2" size="1" maxlength="3">-<input class=form type="text" name="contact_phone2_num3" size="2" maxlength="4"><br>	
</td>
</tr>
<tr bgcolor="#CCCCFF">
<td valign="top"><b>Previous Agent</b></td>
<td valign="top">
			<input type="text" name="previous_agent" class="form">
</td>
</tr>
<tr>
<td valign="top"><b>Estimated Price</b></td>
<td valign="top">
		\$<input type="text" name="price_high" size="1" maxlength="3" class="form">,<input type="text" name="price_low" size="1" maxlength="3" class="form"><br>
</td>
</tr>
<tr>
<td valign="top"><b>Last Followup Date</b></td>
<td valign="top">
				<input type="Text" name="last_followup" value="" class="form" size="10">&nbsp;<a href="javascript:cal3.popup();"><img src="images/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the date"></a> Date<br>
</td>
</tr>
<tr>
<td valign="top"><b>Next Followup Date</b></td>
<td valign="top">
				<input type="Text" name="next_followup" value="" class="form" size="10">&nbsp;<a href="javascript:cal2.popup();"><img src="images/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the date"></a> Date<br>
</td>
</tr>
<tr>
<td valign="top"><b>Hot List Date</b></td>
<td valign="top">
				<input type="Text" name="hotlist_date" value="" class="form" size="10">&nbsp;<a href="javascript:cal1.popup();"><img src="images/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the date"></a> Hot List Date<br>
</td>
</tr>
<input type="hidden" name="status" value="$INPUT{status}">
<input type="hidden" name="type" value="$INPUT{type}">
<input type="hidden" name="assigned_show" value="$INPUT{assigned_show}">
<input type="hidden" name="startdate" value="$INPUT{startdate}">
<input type="hidden" name="enddate" value="$INPUT{enddate}">
<tr>
<td colspan="2"><center><input type="submit" value="Save New Prospect">  [ <a href="prospecting.idx?&agent=$Cook{agentid}&status=$INPUT{status}&type=$INPUT{type}&assigned_show=$INPUT{assigned_show}&startdate=$INPUT{startdate}&enddate=$INPUT{enddate}">Cancel Create</a> ]</center></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
	<SCRIPT TYPE="text/javascript">
	<!--
	autojump('contact_phone1_num1', 'contact_phone1_num2', 3);
	autojump('contact_phone1_num2', 'contact_phone1_num3', 3);
	autojump('contact_phone1_num3', 'contact_phone2_num1', 4);
	autojump('contact_phone2_num1', 'contact_phone2_num2', 3);
	autojump('contact_phone2_num2', 'contact_phone2_num3', 3);
	autojump('contact_phone2_num3', 'previous_agent', 4);
	autojump('price_high', 'price_low', 3);
	//-->
	</SCRIPT>
			<script language="JavaScript">
			<!-- 
				var cal1 = new calendar1(document.forms['create_prospect'].elements['hotlist_date']);
				cal1.year_scroll = true;
				cal1.time_comp = false;

				var cal2 = new calendar1(document.forms['create_prospect'].elements['next_followup']);
				cal2.year_scroll = true;
				cal2.time_comp = false;

				var cal3 = new calendar1(document.forms['create_prospect'].elements['last_followup']);
				cal3.year_scroll = true;
				cal3.time_comp = false;
			//-->
			</script>
~;
&footer;

}

sub overview_documents {

$show_icon{pdf} = qq~<img src="http://connect.eaglesold.com/images/documents/small-pdf-icon.gif" alt="PDF Document">~;
$show_icon{doc} = qq~<img src="http://connect.eaglesold.com/images/documents/small-word-icon.jpg" alt="Microsoft Word Document">~;
$show_icon{jpg} = qq~<img src="http://connect.eaglesold.com/images/documents/small-jpg-icon.jpg" alt="JPG Photo">~;
$show_icon{efx} = qq~<img src="http://connect.eaglesold.com/images/documents/small-efx-icon.gif" alt="eFax Document">~;

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 $basth = $dbh->prepare("select * from trans_boardprospecting_documents where prospectingid = '$INPUT{prospectingid}' ORDER BY dateadded DESC");
$basth->execute;

while ($data_ref = $basth->fetchrow_hashref()) {
%documents = %$data_ref;

$doc_ext = $documents{newfileext};

$show_docs .= qq~	$show_icon{$doc_ext} <a href="http://connect.eaglesold.com/documents/prospecting/$documents{did}.$documents{newfileext}" target="_blank">$documents{name}</a><br>Added $documents{dateadded}<br>~;
$found = "yes";
}


print qq~
<html>
<head>
<title>The ORR Home Selling Team - Prospecting System 2010 ver:1.4</title>
<link rel="stylesheet" TYPE="text/css" href="includes/style.css">
<body bgcolor="white" leftMargin="0" topMargin="0" marginwidth="0" marginheight="0">
<table border="0" cellpadding="4" cellspacing="0" width="100%">
<tr>
<td valign="top">
~;
unless ($found eq "yes") {
print qq~
<font color="red"><b>No Documents have been uploaded yet!</b></font>
~;
}
else {
print qq~
$show_docs
~;
}
print qq~
</td>
</tr>
</table>
</body>
</html>
~;
}

sub details {

my $uasth = $dbh->prepare("SELECT id,agentid,status,type,message_data,DATE_FORMAT(load_datetime, '%b %D, %Y %h\%p'),loaded_by,assigned_to,lead_source,prop_address_number,prop_address_direction,prop_address_street,prop_address2,prop_city,prop_zip,contact_firstname,contact_spouse,contact_lastname,contact_address,contact_address2,contact_city,contact_state,contact_zip,contact_phone1type,contact_phone1_num1,contact_phone1_num2,contact_phone1_num3,contact_phone2type,contact_phone2_num1,contact_phone2_num2,contact_phone2_num3,contact_emailaddress,previous_agent,price_high,price_low,last_followup,DATE_FORMAT(last_followup, '%b %D, %Y'),next_followup,DATE_FORMAT(next_followup, '%b %D, %Y'),result,DATE_FORMAT(hotlist_date, '%b %D, %Y') from trans_boardprospecting where id = '$INPUT{id}' and agentid = '$INPUT{agent}'");
$uasth->execute;
while (($id,$agent,$record_status,$record_type,$message_data,$load_datetime,$loaded_by,$assigned_to,$lead_source,$prop_address_number,$prop_address_direction,$prop_address_street,$prop_address2,$prop_city,$prop_zip,$contact_firstname,$contact_spouse,$contact_lastname,$contact_address,$contact_address2,$contact_city,$contact_state,$contact_zip,$contact_phone1type,$contact_phone1_num1,$contact_phone1_num2,$contact_phone1_num3,$contact_phone2type,$contact_phone2_num1,$contact_phone2_num2,$contact_phone2_num3,$contact_emailaddress,$previous_agent,$price_high,$price_low,$last_followup,$last_followup_clean,$next_followup,$next_followup_clean,$result,$hotlist_date) = $uasth->fetchrow_array()) {




	### START CHECKS ####

		if ($next_followup eq "" || $next_followup eq "0000-00-00") { $next_followup = "Not Entered"; }
		if ($hotlist_date eq "" || $hotlist_date eq "0000-00-00") { $hotlist_date = "Not Entered"; }
		if ($prop_address2 eq "") { } else { $prop_address2 = "$prop_address2"; }
		if ($contact_address2 eq "") { } else { $contact_address2 = "$contact_address2<br>"; }
		if ($contact_spouse eq "") {} else { $contact_spouse = " & $contact_spouse"; }
		if ($contact_lastname) { $contact_lastname = "$contact_lastname<br>"; }
		if ($contact_lastname eq "") { $contact_firstname = "$contact_firstname<br>"; }

		if ($last_followup eq "0000-00-00") { $last_followup = ""; }

		unless ($result eq "") {
		$result_dropdown = "<option value=$result>$result</option><option value=\"$result\"> - - - - </option>";
		}


	### SEARCH FOR LETTERS ###

	my $letters_sth = $dbh->prepare("SELECT id,subject,body FROM trans_boardprospecting_letters WHERE agent = '$agent' order by display_order ASC");
	$letters_sth->execute;
	while (($letters_id,$letters_subject,$letters_body) = $letters_sth->fetchrow_array()) {
	$show_letters .=qq~ + <a href="prospecting.idx?view=letters&letterid=$letters_id&id=$id&agent=$agent" target="_blank">$letters_subject</a><br>~;
	$foundletter = "yes";
	}


	### SEARCH DNC LIST ###

	my $aasth = $dbh->prepare("SELECT areacode,number3,number4 FROM telemarketing WHERE areacode = '$contact_phone1_num1' AND number3 = '$contact_phone1_num2' AND number4 = '$contact_phone1_num3'");
	$aasth->execute;
	while (($phone1_areacode,$phone1_number3,$phone1_number4) = $aasth->fetchrow_array()) {
	$foundnumber1 = "yes";
	}

	if ($foundnumber1 eq "yes") {
		unless ($contact_phone1_num1 eq "") {
			$phone1_dnc = "<img src=\"http://connect.eaglesold.com/images/trans_sys/button_yield.gif\" alt=\"On DNC List\"> <font color=\"red\">$contact_phone1type <s>$contact_phone1_num1-$contact_phone1_num2-$contact_phone1_num3</s></font><br>";
		}
	}
	else {
		unless ($contact_phone1_num1 eq "") {
			unless ($contact_phone1_num1 eq "765" || $contact_phone1_num1 eq "317" || $contact_phone1_num1 eq "260" || $contact_phone1_num1 eq "812" || $contact_phone1_num1 eq "219") {
					$phone1_dnc = "<img src=\"http://connect.eaglesold.com/images/trans_sys/button_yield.gif\" alt=\"On DNC List\"> <font color=\"red\">$contact_phone1type <s><sup>($contact_phone1_num1)</sup>-$contact_phone1_num2-$contact_phone1_num3</s></font><font color=\"red\" size=\"1\"><br><i><b>(Cannot Check # Outside Indiana)</b></i></font><br>";
			}
			else {
				$phone1_dnc = "<img src=\"http://connect.eaglesold.com/images/trans_sys/button_check.gif\" alt=\"OK to Call\"> <font color=\"green\">$contact_phone1type $contact_phone1_num1-$contact_phone1_num2-$contact_phone1_num3</font><br>";
			}
		}
	}

	my $basth = $dbh->prepare("SELECT areacode,number3,number4 FROM telemarketing WHERE areacode = '$contact_phone2_num1' AND number3 = '$contact_phone2_num2' AND number4 = '$contact_phone2_num3'");
	$basth->execute;
	while (($phone2_areacode,$phone2_number3,$phone2_number4) = $basth->fetchrow_array()) {
	$foundnumber2 = "yes";
	}

	if ($foundnumber2 eq "yes") {
	unless ($contact_phone2_num1 eq "") {
		$phone2_dnc = "<img src=\"http://connect.eaglesold.com/images/trans_sys/button_yield.gif\" alt=\"On DNC List\"> <font color=\"red\">$contact_phone2type <s>$contact_phone2_num1-$contact_phone2_num2-$contact_phone2_num3</s></font><br>";
	}
	}
	else {
	unless ($contact_phone2_num1 eq "") {
			unless ($contact_phone2_num1 eq "765" || $contact_phone2_num1 eq "317" || $contact_phone2_num1 eq "260" || $contact_phone2_num1 eq "812" || $contact_phone2_num1 eq "219") {
				$phone2_dnc = "<img src=\"http://connect.eaglesold.com/images/trans_sys/button_yield.gif\" alt=\"On DNC List\"> <font color=\"red\">$contact_phone2type <s><sub>($contact_phone2_num1)</sub>-$contact_phone2_num2-$contact_phone2_num3</s></font><font color=\"red\" size=\"1\"><br><i><b>(Cannot Check # Outside Indiana)</b></i></font><br>";
			}
			else {
				$phone2_dnc = "<img src=\"http://connect.eaglesold.com/images/trans_sys/button_check.gif\" alt=\"OK to Call\"> <font color=\"green\">$contact_phone2type $contact_phone2_num1-$contact_phone2_num2-$contact_phone2_num3</font><br>";
			}
	}
	}

	$firstname_firstletter = substr("$contact_firstname", 0, 1);

	unless ($contact_address eq "") {
	$check_address =qq~$contact_address<br>$contact_address2$contact_city, $contact_state $contact_zip<br>~;
	}
	unless ($contact_emailaddress eq "") {
	$check_email =qq~E-Mail </b><a target="_blank" href="https://mail.google.com/mail/?fs=1&view=cm&shva=1&to=$contact_emailaddress&su=$status $type&body=Dear $contact_firstname$contact_spouse $contact_lastname%0a%0a     Thank you%0a%0aBest Regards%0aRyan%0a%0a Ryan P. Orr%0aREALTOR(R) Broker / Auctioneer%0aThe ORR Home Selling Team%0aRE/MAX Real Estate Groups%0aOffice 765-212-1111%0aMobile 765-744-9500%0aRyan@ORRHomes.com%0ahttp://www.ORRHomes.com%0ahttp://Blog.ORRHomes.com%0a%0aYour Referrals are Greatly Appreciated!">$contact_emailaddress</a><br>~;
	}

	unless ($contact_phone1_num1 eq "") {
	$check_phone1_reverse =qq~<b>Phone 1: <a href="http://www.whitepages.com/search/ReversePhone?full_phone=$contact_phone1_num1$contact_phone1_num2$contact_phone1_num3&localtime=survey" target="_blank">W.Pages.</a> or 	<a href="http://www.anywho.com/qry/wp_rl?npa=$contact_phone1_num1&telephone=$contact_phone1_num2$contact_phone1_num3" target="_blank">An.</a></b><br>~;
	}
	else {
	$check_phone1_reverse =qq~Enter Phone Number!<br>~;
	}

	unless ($contact_phone2_num1 eq "") {
	$check_phone2_reverse =qq~<b>Phone 2: <a href="http://www.whitepages.com/search/ReversePhone?full_phone=$contact_phone2_num1$contact_phone2_num2$contact_phone2_num3&localtime=survey" target="_blank">W.Pages.</a> or 	<a href="http://www.anywho.com/qry/wp_rl?npa=$contact_phone2_num1&telephone=$contact_phone2_num2$contact_phone2_num3" target="_blank">An.</a></b><br>~;
	}





print qq~
<html>
<head>
<title>The ORR Home Selling Team - Prospecting System 2010 ver:1.4 - Connect.EagleSold.com</title>
<script language="JavaScript" src="calendar1.js"></script>
<script language="JavaScript" src="calendar2.js"></script>
<script language="JavaScript">
function submit()
{
	 document.changestatus.submit();
}

function disableSubmit(whichButton) 
{ 
    if (document.getElementById) 
    { 
        // this is the way the standards work 
        document.getElementById(whichButton).disabled = true; 
    } 
    else if (document.all) 
    { 
        // this is the way old msie versions work 
        document.all[whichButton].disabled = true; 
    } 
    else if (document.layers) 
    { 
        // this is the way nn4 works 
        document.layers[whichButton].disabled = true; 
    } 
} 

function enableSubmit(whichButton) 
{ 
    if (document.getElementById) 
    { 
        // this is the way the standards work 
        document.getElementById(whichButton).disabled = false; 
    } 
    else if (document.all) 
    { 
        // this is the way old msie versions work 
        document.all[whichButton].disabled = false; 
    } 
    else if (document.layers) 
    { 
        // this is the way nn4 works 
        document.layers[whichButton].disabled = false; 
    } 
} 

</script>
~;
&header;
print qq~
<td valign="top" width="581">
<img src="images/headers/prospecting_center.gif" height="33" width="581" alt="Prospecting Center"><br><br>
<table border="0" cellpadding="4" cellspacing="1" bgcolor="navy" width="100%">
	<tr>
	<td width="60%" valign="top" align="left" bgcolor="white">

<table border="0" cellspacing="3" cellpadding="1" bgcolor="#009900" width="50" height="50" align="left">
	<tr>
		<td valign="middle" align="center"><font color="white" size="3"><b>$id</b></font></td>
	</tr>
</table>

<font size="2"><i>Prospecting for <b>$type</b>:</i></font><br><font size="4" color="green"><b>$contact_firstname$contact_spouse $contact_lastname$prop_address_number $prop_address_direction $prop_address_street $prop_address2 $prop_city, $prop_zip</b><br></font></td>
	<td width="40%" valign="middle" bgcolor="white">
		<center>
~;
		if ($INPUT{return} eq "search") {
		print qq~<a href="prospecting.idx?view=details&id=$INPUT{id}&agent=$INPUT{agent}&return=search">Refresh</a> | <a href="prospecting.idx?view=search">Back To Overview</a><br>~;
		}
		else {
		print qq~<a href="prospecting.idx?view=details&id=$INPUT{id}&agent=$INPUT{agent}&status=$INPUT{status}&type=$INPUT{type}&assigned_show=$INPUT{assigned_show}&enddate=$INPUT{enddate}&sortby=$INPUT{sortby}">Refresh</a> | <a href="prospecting.idx?agent=$INPUT{agent}&status=$INPUT{status}&type=$INPUT{type}&assigned_show=$INPUT{assigned_show}&enddate=$INPUT{enddate}&sortby=$INPUT{sortby}">Back To Overview</a><br>~;
		}
print qq~<br>
<a href="prospecting.idx?view=edit_prospect&id=$id&agent=$INPUT{agent}&status=$INPUT{status}&type=$INPUT{type}&assigned_show=$INPUT{assigned_show}&enddate=$INPUT{enddate}&sortby=$INPUT{sortby}">Edit This Prospect File</a><br>
		</center>
	</td>
	</tr>
	<tr>
		<td width="60%" valign="top" bgcolor="white">
		<table border="0" cellpadding="2" cellspacing="1" width="100%">
		<tr>
			<td valign="top" colspan="2"><img src="images/fileinfo.gif"><br></td>
		</tr>
		<tr>
			<td valign="top" align="right"><b><font size="2" color="gray">Status</font></b></td>
					<form method="get" action="prospecting.idx"><td valign="top"><b><font size="2">$record_status</font></b><br>
	
			<input type="hidden" name="agent" value="$INPUT{agent}">
			<input type="hidden" name="status" value="$INPUT{status}">
			<input type="hidden" name="type" value="$INPUT{type}">
			<input type="hidden" name="assigned_show" value="$INPUT{assigned_show}">			
			<input type="hidden" name="enddate" value="$INPUT{enddate}">
			<input type="hidden" name="sortby" value="$INPUT{sortby}">
			<input type="hidden" name="id" value="$id">
			<b>Status:</b> <select name="action_status" class="small_form" onChange="submit();">
			<option value="$status">Change Status To</option>
			<option value="$status">----------</option>
			<option value="Inactive">Mark as Inactive</option>
			<option value="Active - New">Mark as Active - New</option>
			<option value="Active - Hot">Mark as Active - Hot</option>
			<option value="Active - Warm">Mark as Active - Warm</option>
			<option value="Active - Cool">Mark as Active - Cool</option>
			<option value="Client">Mark as Client</option>
			<option value="Stopped">Mark as Stopped</option>
			<option value="Inactive">Mark as Inactive</option>
</td>			</form>
		</tr>
		<tr bgcolor="#FFFF99">
			<td valign="top" align="right"><b><font size="2" color="gray">Type</font></b></td>
			<td valign="top"><b><font size="2">$record_type</font></b></td>
		</tr>
		<tr>
			<td valign="top" align="right"><b><font size="2" color="gray">Load Date</font><br></b></td>
			<td valign="top"><b><font size="2">$load_datetime</font><br></b></td>
		</tr>
		<tr bgcolor="#FFFF99">
			<td valign="top" align="right"><b><font size="2" color="gray">Next Followup Date</font><br></b></td>
			<td valign="top"><b><font size="2">$next_followup_clean</font><br></b></td>
		</tr>
		<tr>
			<td valign="top" align="right"><b><font size="2" color="gray">Last Followup Date</font><br></b></td>
			<td valign="top"><b><font size="2">$last_followup_clean</font><br></b></td>
		</tr>
		<tr bgcolor="#FFFF99">
			<td valign="top" align="right"><b><font size="2" color="gray">Hot List Date</font><br></b></td>
			<td valign="top"><b><font size="2">$hotlist_date</font><br></b></td>
		</tr>
		<tr>
			<td valign="top" align="right"><b><font size="2" color="gray">Assigned To</font></b></td>
			<td valign="top"><b><font size="2">$assigned_to</font></b></td>
		</tr>
		<tr bgcolor="#FFFF99">
			<td valign="top" align="right"><b><font size="2" color="gray">Lead Source</font></b></td>
			<td valign="top"><b><font size="2">$lead_source</font></b></td>
		</tr>
		<tr>
			<td valign="top" align="right"><b><font size="2" color="gray">Price Est.</font></b></td>
			<td valign="top"><b><font size="2">\$$price_high,$price_low</font></b></td>
		</tr>
		<tr>
			<td colspan="2" valign="top" width="100%">
				<table border="0" cellpadding="3" cellspacing="0" width="100%">
				<tr>
					<td valign="top" bgcolor="navy" nowrap><font color="white" size="2"><b>Prospecting Notes</b></font><br></td>
				</tr>
				</table>
			<iframe src="prospecting.idx?view=overview_notes_show&prospectingid=$id" width="100%" height="160" name="notes_view" noresize="noresize" scrolling ="yes" frameborder="0" marginwidth="3" marginheight="3"></iframe>
			</td>
		</tr>
		<tr>
			<td colspan="2" valign="top" width="100%">

			<table border="0" cellpadding="3" cellspacing="0" width="100%">
				<tr>
					<td valign="top" bgcolor="navy" nowrap><font color="white" size="2"><b>Listing(s) Prospect Is Linked To</b></font><br></td>
				</tr>
			</table>
			<table border="0" cellpadding="0" cellspacing="0" width="100%">
				<tr>
<form method="get" action="prospecting.idx" target="link">
<input type="hidden" name="view" value="prospecting_linked">
<input type="hidden" name="do" value="search">
<input type="hidden" name="prospectingid" value="$INPUT{id}">
				<td valign="middle" width="100%" bgcolor="#ffcc00">
				<b>Link With Property</b> <input type="text" name="query" value="MLS# or Address" class="form" onfocus="value=''"> <input type="submit" class="form" value="Search">
				</td>
</form>
		</tr>
		<tr>
			<td valign="top" width="100%">
		<iframe src="prospecting.idx?view=prospecting_linked&prospectingid=$INPUT{id}" width="100%" height="115" noresize="noresize" scrolling ="yes" name="link" frameborder="0" marginwidth="0" marginheight="0"></iframe>
	</td>
	</tr>
	</table>
</td>
</tr>
~;
unless ($message_data eq "") {
		print qq~
		<tr bgcolor="#ffcc33">
			<td valign="top" colspan="2"><b><font color="black">Original Message Data<br>$message_data</font></b></td>
		</tr>
		~;
}
print qq~
		<tr>
			<td colspan="2" valign="top" width="100%">

			<table border="0" cellpadding="3" cellspacing="0" width="100%">
				<tr>
					<td valign="top" bgcolor="navy" nowrap><font color="white" size="2"><b>Prospecting Documents</b></font><br></td>
				</tr>
			</table>
			<table border="0" cellpadding="0" cellspacing="0" width="100%">
				<tr>
				<td valign="top" width="50%">
					<iframe src="prospecting.idx?view=overview_documents&prospectingid=$id" width="100%" height="90" noresize="noresize" scrolling ="yes" frameborder="0" marginwidth="0" marginheight="0" name="documents"></iframe>
				</td>
		<FORM action="upload_doc_prospecting.idx" encType="multipart/form-data" method="post" target="documents"  name="upload">
		<input type="hidden" name="prospectingid" value="$id" class="form">
			<td valign="top" width="50%">
		<center>
		<table border="0" cellpadding="4" cellspacing="0">
		<tr>
		<td valign="top">
		<center>
		<b><img src="images/trans_sys/button_view.gif"> <font size="2">Upload New Document</font></b>
		</center>
		<b>Name the file:</b><br>
		<input type="text" name="name" size="35" class="form"><br>
		<b>Find file by clicking browse:</b><br>
		<INPUT name="FILE1" type="file" class="form"><br>
		<input type="submit" value="           Upload File            " class="form">
		</td>
		</tr>
		</table>
		</center>
	</td>
	</form>
	</tr>
	</table>
</td>
</tr>
		<tr>
			<td valign="top" colspan="2" bgcolor="#CCCCFF">
				<b>Available Letters</b><br>
				<b>$show_letters</b>
			</td>
		</tr>
		</table>
	</td>
	<td valign="top" width="40%" bgcolor="#ffffcc">
<img src="images/actionbar.gif"><Br>
	<font size="2">
	<b>$contact_firstname$contact_spouse $contact_lastname
	$check_address
	$phone1_dnc
	$phone2_dnc
	$check_email
	</font>
<form method="post" action="prospecting.idx" target="_blank">
<input type="hidden" name="view" value="print">
<input type="hidden" name="id" value="$id">
<input type="submit" value="Print Opportunity Sheet">
</form>

<script language="JavaScript" type="text/javascript">
<!--
function checkform ( form )
{

  if (form.notes.value == "") {
    javascript:enableSubmit('mFormSubmit');
    alert( "You MUST Enter A Note First!" );
    form.notes.focus();
    return false ;
  }

  return true ;
}
//-->
</script>
				<form method="get" action="prospecting.idx" target="notes_view" name="pnotes" onsubmit="javascript:disableSubmit('mFormSubmit'); return checkform(this);">
				<input type="hidden" name="view" value="overview_notes_show">
				<input type="hidden" name="prospectingid" value="$INPUT{id}">
				<input type="hidden" name="addnote" value="1">
				<b><u>Enter Notes & Followup Dates Below:</u></b><br>
				<textarea cols="35" rows="8" name="notes" class="form"></textarea><br>
				<select name="viewable" class="form"><option value="no">Not Client Viewable</option><option value="yes">Client Viewable</option></select><br>
				<input type="Text" name="next_followup" value="$next_followup" class="form" size="10">&nbsp;<a href="javascript:cal1.popup();"><img src="images/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the date"></a> Next Follow Up<br>
				<input type="Text" name="last_followup" value="$last_followup" class="form" size="10">&nbsp;<a href="javascript:cal2.popup();"><img src="images/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the date"></a> Last Follow Up<br>
				<select name="result" class="form">
				$result_dropdown
				<option value="Called - Spoke with">Called - Spoke with</option>
				<option value="Called - No Answer">Called - No Answer</option>
				<option value="Called - Left MSG">Called - Left MSG</option>
				<option value="Called and Sent E-Mail">Called and Sent E-Mail</option>
				<option value="Called and Sent Letter">Called and Sent Letter</option>
				<option value="Called and Sent Postcard">Called and Sent Postcard</option>
				<option value="Sent E-Mail">Sent E-Mail</option>
				<option value="Sent Letter">Sent Letter</option>
				<option value="Sent Postcard">Sent Postcard</option>
				<option value="Met in Office">Met in Office</option>
				<option value="Showed Property">Showed Property</option>
				<option value="None">None</option>
				</select> Action<br>				
				<input type="submit" value="Save Prospecting Note" id="mFormSubmit" class="form"><A HREF="javascript:enableSubmit('mFormSubmit');">U</A><br>
				</form>
<img src="images/trackthemdown.gif"><br>


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

			<script language="JavaScript">
			<!-- 
				var cal1 = new calendar1(document.forms['pnotes'].elements['next_followup']);
				cal1.year_scroll = true;
				cal1.time_comp = false;

				var cal2 = new calendar1(document.forms['pnotes'].elements['last_followup']);
				cal2.year_scroll = true;
				cal2.time_comp = false;

			//-->
			</script>
~;

&footer;
}




}

sub main {

if ($INPUT{action_status} eq "Open") {
print qq~
<html>
<head>
<title>Opening File</title>
<meta http-equiv="Refresh" content="0; URL=http://connect.eaglesold.com/prospecting.idx?view=details&id=$INPUT{id}&agent=$INPUT{agent}&status=$INPUT{status}&type=$INPUT{type}&assigned_show=$INPUT{assigned_show}&enddate=$INPUT{enddate}&sortby=$INPUT{sortby}">
</head>
<body bgcolor="white">
<font size="2" face="Arial Narrow" color="Red">Please wait, Opening File</font>
</body>
</html>
~;
exit 0;
}

if ($INPUT{action_status} eq "Edit") {
print qq~
<html>
<head>
<title>Opening Edit Mode</title>
<meta http-equiv="Refresh" content="0; URL=http://connect.eaglesold.com/prospecting.idx?view=edit_prospect&id=$INPUT{id}&agent=$INPUT{agent}&status=$INPUT{status}&type=$INPUT{type}&assigned_show=$INPUT{assigned_show}&enddate=$INPUT{enddate}&sortby=$INPUT{sortby}">
</head>
<body bgcolor="white">
<font size="2" face="Arial Narrow" color="Red">Please wait, Opening File</font>
</body>
</html>
~;
exit 0;
}

if ($INPUT{action_status} eq "Delete") {

if ($INPUT{Verified}) {
### REMOVE NOTES
my $nasth = $dbh->do("delete from trans_boardprospecting_notes where prospectingid = '$INPUT{id}'");

### REMOVE PROSPECTING LINKS TO LISTINGS
my $aaasth = $dbh->do("delete from trans_boardtranstoprospecting where prospectingid = '$INPUT{id}'");

### 1ST REMOVE ACTUAL DOCUMENT FILES
my $asth = $dbh->prepare("select did,newfileext from trans_boardprospecting_documents WHERE prospectingid = '$INPUT{id}'");
$asth->execute;
while (($did,$dnewfileext) = $asth->fetchrow_array()) {
    unlink("/home/muncieml/public_html/connect/documents/prospecting/$did.$dnewfileext");
}

### 2ND REMOVE THE DOCUMENT DATABASE ENTRY 
my $aasth = $dbh->do("delete from trans_boardprospecting_documents where prospectingid = '$INPUT{id}'");

### REMOVE ACTUAL PROSPECT FILE
my $fasth = $dbh->do("delete from trans_boardprospecting where id = '$INPUT{id}'");

print qq~
<html>
<head>
<title>Deleting File</title>
<meta http-equiv="Refresh" content="0; URL=http://connect.eaglesold.com/prospecting.idx?agent=$INPUT{agent}&status=$INPUT{status}&type=$INPUT{type}&assigned_show=$INPUT{assigned_show}&enddate=$INPUT{enddate}&sortby=$INPUT{sortby}">
</head>
<body bgcolor="white">
<font size="2" face="Arial Narrow" color="Red">Please wait, Deleting File including notes, listing links and documents</font>
</body>
</html>
~;
exit 0;
}
else {
print qq~
<html>
<head>
<title>Deleting File</title>
</head>
<body bgcolor="white">
<center>
<br><br><br>
<font size="2" face="Arial Narrow" color="Red">Are You Sure You Wish To Delete?<br><br>Removing this file will also delete saved notes and documents.<br><br></font>
			<form method="post" action="prospecting.idx">
			<input type="hidden" name="agent" value="$INPUT{agent}">
			<input type="hidden" name="status" value="$INPUT{status}">
			<input type="hidden" name="type" value="$INPUT{type}">
			<input type="hidden" name="assigned_show" value="$INPUT{assigned_show}">
			<input type="hidden" name="enddate" value="$INPUT{enddate}">
			<input type="hidden" name="sortby" value="$INPUT{sortby}">
			<input type="hidden" name="id" value="$INPUT{id}">
			<input type="hidden" name="action_status" value="Delete">
			<input type="hidden" name="Verified" value="Yes">
			<input type="submit" value="Delete Now"> [ <a href="prospecting.idx?agent=$INPUT{agent}&status=$INPUT{status}&type=$INPUT{type}&assigned_show=$INPUT{assigned_show}&enddate=$INPUT{enddate}&sortby=$INPUT{sortby}">No Cancel</a> ]		
			<br>
			</form>
</center>
</body>
</html> 
~;
exit 0;
}
}


if ($INPUT{action_status}) {

	@variables = ($INPUT{action_status},$INPUT{id});
	$sql_query = "update trans_boardprospecting set status = ? where id = ?";
	my $asth = $dbh->do($sql_query, undef, @variables);

print qq~
<html>
<head>
<title>Changing Status</title>
<meta http-equiv="Refresh" content="0; URL=http://connect.eaglesold.com/prospecting.idx?view=details&agent=$INPUT{agent}&id=$INPUT{id}&status=$INPUT{status}&assigned_show=$INPUT{assigned_show}&type=$INPUT{type}&enddate=$INPUT{enddate}&sortby=$INPUT{sortby}">
</head>
<body bgcolor="white">
<font size="2" face="Arial Narrow" color="Red">Please wait, Changing Status for File</font>
</body>
</html>
~;
exit 0;
}


### SET DEFAULT SEARCH VALUES

unless ($INPUT{status}) { $INPUT{status} = "All Active"; }
unless ($INPUT{type}) { $INPUT{type} = "All Types"; }
unless ($INPUT{assigned_show}) { $INPUT{assigned_show} = "All"; }
$INPUT{agent} = "600";
$INPUT{orderby} = "DESC";

### BUILD SQL SEARCH STATEMENT

if ($INPUT{result}) {
	$sqlstatement = "and result = '$INPUT{result}'";
}
else {
if ($INPUT{status} eq "All Active") {
$sqlstatement .= "and (status = 'Active - New' or status = 'Active - Hot' or status = 'Active - Warm' or status = 'Active - Cool')";
}
else {
$sqlstatement .= "and status = '$INPUT{status}'";
}

if ($INPUT{type} eq "All Types") {
#$sqlstatement .= "and (type = 'Unknown' or type = 'Listing' or type = 'Listing FSBO' or type = 'Listing Expired' or type = 'Listing and Buyer' or type = 'Buyer')";
}
else {
$sqlstatement .= "and type = '$INPUT{type}'";
}

if ($INPUT{assigned_show} eq "All") {
}
elsif ($INPUT{assigned_show} eq "Patrick Orr") {
$sqlstatement .= "and assigned_to = 'Patrick Orr'";
}
elsif ($INPUT{assigned_show} eq "Ryan Orr") {
$sqlstatement .= "and assigned_to = 'Ryan Orr'";
}
elsif ($INPUT{assigned_show} eq "Aaron Orr") {
$sqlstatement .= "and assigned_to = 'Aaron Orr'";
}

unless ($INPUT{sortby}) { $INPUT{sortby} = "next_followup"; }
	if ($INPUT{sortby} eq "next_followup") { 
		$dropdown_sortby_display = "Followup";
	}
	elsif ($INPUT{sortby} eq "id") {
		$dropdown_sortby_display = "Newest";
	}
	elsif ($INPUT{sortby} eq "oldest") {
		$dropdown_sortby_display = "Oldest";
		$INPUT{sortby} = "id";
		$INPUT{orderby} = "ASC";
	}
	else {
		$dropdown_sortby_display = "$INPUT{sortby}";
	}
$dropdown_sortby = "<option value=\"$INPUT{sortby}\">$dropdown_sortby_display</option>\n";
}

$findldate = "$INPUT{enddate}";

	my $datenowasth = $dbh->prepare("select DATE_FORMAT(now(),'%Y-%m-%d')");
	$datenowasth->execute;
	while (($nowdateis) = $datenowasth->fetchrow_array()) {
	$todayrealdate = $nowdateis;
	}

	my $cleandatenowasth = $dbh->prepare("select DATE_FORMAT(now(),'%b %D %Y')");
	$cleandatenowasth->execute;
	while (($cleannowdateis) = $cleandatenowasth->fetchrow_array()) {
	$todayrealdate_clean = $cleannowdateis;
	}

	unless ($INPUT{enddate}) {
	$findldate = "$todayrealdate";
	}

$sqlstatement .= "and next_followup <= '$findldate'";


### BUILD DROP DOWNS BASED ON SEARCH
$dropdown_status = "<option value=\"$INPUT{status}\">$INPUT{status}</option>\n<option value=\"$INPUT{status}\">-------</option>\n";
$dropdown_type = "<option value=\"$INPUT{type}\">$INPUT{type}</option>\n<option value=\"$INPUT{type}\">-------</option>\n";
$dropdown_assignedshow = "<option value=\"$INPUT{assigned_show}\">$INPUT{assigned_show}</option>\n<option value=\"$INPUT{assigned_show}\"> - - </option>\n";


print qq~
<html>
<head>
<title>The ORR Home Selling Team - Prospecting System 2010 ver:1.4</title>
<script language="JavaScript" src="calendar1.js"></script>
<script language="JavaScript" src="calendar2.js"></script>
<script language="JavaScript">
function submit()
{
	 document.changestatus.submit();
}
</script>
~;
$display_full = "yes";
&header;
print qq~
<td valign="top" width="751">
<a href="index.idx"><img src="images/headers/returnhome.gif" border="0" alt="Return Home"></a><img src="images/headers/prospecting_center.gif" height="33" width="581" alt="Prospecting Center"><br><br>


<table border="0" cellpadding="1" cellspacing="1" width="751" bgcolor="#9999ff">
	<tr>
	<td valign="top" colspan="8" bgcolor="white" width="751">
		<table border="0" cellpadding="4" cellspacing="0" width="751" bgcolor="white">
			<tr>
				<td valign="top" width="60%">
					<img src="images/prospecting_searchtxt.gif"><br>
					&nbsp;&nbsp;&nbsp; <b>"If You Don't <u>A.S.K.</u>, You Don't <u>G.E.T.</u>" - Rex St. John</b><br>
				</td>
					<form method="post" action="prospecting.idx">
					<input type="hidden" name="view" value="create_prospect">
					<input type="hidden" name="agent" value="$INPUT{agent}">
					<input type="hidden" name="status" value="$INPUT{status}">
					<input type="hidden" name="type" value="$INPUT{type}">
					<input type="hidden" name="assigned_show" value="$INPUT{assigned_show}">
					<input type="hidden" name="startdate" value="$findsdate">
					<input type="hidden" name="enddate" value="$findldate">

				<td valign="middle" width="40%" align="right">
					<a href="prospecting.idx?view=search">SEARCH</a>   <input type="submit" value="Create New Prospect File">
				</td>
					</form>
			</tr>
				<form method="post" action="prospecting.idx" name="prospect_search">
				<input type="hidden" name="agent" value="$INPUT{agent}">
			<tr>
				<td valign="middle" colspan="2" bgcolor="yellow" align="center">
					<b>Status</b>
					<select name="status" class="form" onChange="submit();">
					$dropdown_status
					<option value="All Active">All Active</option>
					<option value="Active - New">Active - New</option>
					<option value="Active - Hot">Active - Hot</option>
					<option value="Active - Warm">Active - Warm</option>
					<option value="Active - Cool">Active - Cool</option>
					<option value="All Types">-------</option> 
					<option value="Client">Client</option>
					<option value="All Types">-------</option>
					<option value="Stopped">Stopped</option> 
					<option value="Inactive">Inactive</option>
					</select> <b>Type</b>
					<select name="type" class="form" onChange="submit();">
					$dropdown_type
					<option value="All Types">All Types</option>
					<option value="Listing">Listing</option>
					<option value="Listing FSBO">Listing FSBO</option>
					<option value="Listing Expired">Listing Expired</option>
					<option value="Listing and Buyer">Listing and Buyer</option>
					<option value="Buyer">Buyer</option>
					<option value="Unknown">Unknown</option>
					</select>
					<b>Assigned</b>
					<select name="assigned_show" class="form" onChange="submit();">
					$dropdown_assignedshow
					<option value="All">All</option>
					<option value="All"> - - </option>
					<option value="Patrick Orr">Patrick Orr</option>
					<option value="Ryan Orr">Ryan Orr</option>
					<option value="Aaron Orr">Aaron Orr</option>
					</select>
					<b> Followup</b>
					<input type="Text" name="enddate" value="$findldate" class="form" size="10">&nbsp;<a href="javascript:cal1.popup();"><img src="images/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the date"></a>
					<b>Sort</b> <select name="sortby" class="form" onChange="submit();">
					$dropdown_sortby
					<option value="All"> - - </option>
					<option value="next_followup">Followup</option>
					<option value="id">Newest</option>
					<option value="oldest">Oldest</option>
					</select>
			</td>
		</tr>
		</table>
	</td>
	</form>
	</tr>
	<tr>
	<td valign="top" bgcolor="navy" colspan="2"><b><font color="white">Status</font></b></td>
	<td valign="top" bgcolor="navy"><b><font color="white">Assigned</font></b></td>
	<td valign="top" bgcolor="navy"><b><font color="white">Type & Source</font></b></td>
	<td valign="top" bgcolor="navy"><b><font color="white">Property Address / Name</font></b></td>
	<td valign="top" bgcolor="navy"><b><font color="white">Next FollowUp</font></b></td>
	<td valign="top" bgcolor="navy" align="center"><b><font color="white">MLS</font></b></td>
	<td valign="top" bgcolor="navy"><b><font color="white">Actions</font></b></td>
	</tr>
~;
$trcolor = "1";
$trcolor2 = "2";
	my $uasth = $dbh->prepare("SELECT id,status,type,lead_source,assigned_to,prop_address_number,prop_address_direction,prop_address_street,prop_address2,prop_city,prop_zip,contact_firstname,contact_spouse,contact_lastname,DATE_FORMAT(next_followup,'%b %D %Y'),previous_agent,result from trans_boardprospecting where agentid = '$INPUT{agent}' $sqlstatement ORDER BY $INPUT{sortby} $INPUT{orderby}");
	$uasth->execute;
	while (($id,$record_status,$record_type,$lead_source,$assigned_to,$prop_address_number,$prop_address_direction,$prop_address_street,$prop_address2,$prop_city,$prop_zip,$contact_firstname,$contact_spouse,$contact_lastname,$next_followup,$previous_agent,$result) = $uasth->fetchrow_array()) {

		if ($next_followup eq "" || $next_followup eq "0000-00-00") { $next_followup = "Not Entered"; }

		if ($previous_agent eq "") { $previous_agent = "Not Entered"; }
		if ($assigned_to eq "") { $assigned_to = "No Assigned"; }
		$status =~ s/\-/<br>/gi;

		if ($record_type eq "Listing" || $record_type eq "Listing FSBO" || $record_type eq "Listing Expired" || $record_type eq "Listing and Buyer") {
		$show_previous_agent = "<i>Previous Agent $previous_agent</i>";
		}
		
		if ($result eq "") { $result = "N/A"; } $result = substr($result,0,8); if (length($result) >= 6) { $result .= "..."; }

		$precord_status = $record_status;
		$precord_status =~ s/ - /<br>/; 
			if ($trcolor eq $trcolor2) {
			$trcolor = "1";
			$setcolor = "darkrow";
			}
			else {
			$setcolor = "lightrow";
			$trcolor++;
			}
		if ($next_followup eq $todayrealdate_clean) {
			$setcolor = "todayrow";
			$next_followup.="<br>DUE TODAY!";}
		else {
			my $check_followup = $dbh->prepare("select id from trans_boardprospecting where id = '$id' AND next_followup < '$todayrealdate'");
			$check_followup->execute;
			while (($pastdue) = $check_followup->fetchrow_array()) {
				if ($next_followup < $todayrealdate) { $setcolor = "cautionrow"; $dot_display = "<img src=images/prospecting_dot_red.gif align=left border=0>"; $next_followup.="<br>PAST DUE!"; }
			}
		}

		$found_listing = "no";
		$found_listing_mls = "";
		my $usrdasth = $dbh->prepare("select MLSNUM from listings_res3 where AddressNumber LIKE '%$prop_address_number%' AND AddressStreet LIKE '%$prop_address_street%'");
		$usrdasth->execute;
		while (($listing_mlsnumber) = $usrdasth->fetchrow_array()) {
		$found_listing = "yes";
		$found_listing_mls = "$listing_mlsnumber";
		}

		if ($record_type eq "Unknown" || $record_type eq "Buyer") {
				$show_listing =qq~ - - - ~;
		}
		elsif ($found_listing eq "yes") {
		$show_listing =qq~<a href="http://$found_listing_mls.MuncieMLS.com" target="_blank"><img src="images/trans_sys/button_yield.gif" height="12" width="13" alt="Possibly Found in MLS" border="0"></a>~;		
		}
		else {
			if ($type eq "Buyer") {
				$show_listing =qq~ - - - ~;
			}
			else {		
				$show_listing =qq~<img src="images/trans_sys/button_check.gif" height="12" width="13" alt="Not Found in MLS">~;
			}
		}

		print qq~
		<TR class="$setcolor">
		<td valign="middle" align="center" nowrap><a href="prospecting.idx?view=details&id=$id&agent=$INPUT{agent}&status=$INPUT{status}&type=$INPUT{type}&assigned_show=$INPUT{assigned_show}&enddate=$findldate&sortby=$INPUT{sortby}">$id<br>$dot_display</a><br></td>
		<td valign="middle" align="center" nowrap><a href="prospecting.idx?view=details&id=$id&agent=$INPUT{agent}&status=$INPUT{status}&type=$INPUT{type}&assigned_show=$INPUT{assigned_show}&enddate=$findldate&sortby=$INPUT{sortby}">$precord_status</a><br></td>
		<td valign="middle" align="center" nowrap><b><font size="2"><a href="prospecting.idx?view=details&id=$id&agent=$INPUT{agent}&status=$INPUT{status}&type=$INPUT{type}&assigned_show=$INPUT{assigned_show}&enddate=$findldate&sortby=$INPUT{sortby}">$assigned_to</a></font><br></td>
		<td valign="top" nowrap><font size="2"><b>$record_type</b><br><i>from $lead_source</i></font><br></td>
		~;
		$contact_firstname = substr($contact_firstname,0,25); if (length($contact_firstname) >= 25) { $contact_firstname .= ".."; }
		$contact_spouse = substr($contact_spouse,0,25); if (length($contact_spouse) >= 25) { $contact_spouse .= ".."; }
		$contact_lastname = substr($contact_lastname,0,25); if (length($contact_lastname) >= 25) { $contact_lastname .= ".."; }
		$prop_address_street = substr($prop_address_street,0,35); if (length($prop_address_street) >= 35) { $prop_address_street .= ".."; }
		if ($record_type eq "Buyer" || $record_type eq "Unknown") {
			print qq~
			<td valign="top" nowrap><a href="prospecting.idx?view=details&id=$id&agent=$INPUT{agent}&status=$INPUT{status}&type=$INPUT{type}&assigned_show=$INPUT{assigned_show}&enddate=$findldate&sortby=$INPUT{sortby}">$contact_firstname $contact_spouse $contact_lastname</a></td>
			~;		
		}
		else {
			print qq~
			<td valign="top" nowrap><a href="prospecting.idx?view=details&id=$id&agent=$INPUT{agent}&status=$INPUT{status}&type=$INPUT{type}&assigned_show=$INPUT{assigned_show}&enddate=$findldate&sortby=$INPUT{sortby}">$contact_firstname $contact_spouse $contact_lastname<br>$prop_address_number $prop_address_direction $prop_address_street<br>$prop_address2$prop_city, IN $prop_zip</a><br>$show_previous_agent<br></td>
			~;
		}
		print qq~
		<td valign="top" nowrap><font size="2"><b>$next_followup</font><br>Last: $result</b><br></td>
		<td valign="top" align="center" nowrap><b>$show_listing</b><br></td>
			<form method="post" action="prospecting.idx">
			<input type="hidden" name="agent" value="$INPUT{agent}">
			<input type="hidden" name="status" value="$INPUT{status}">
			<input type="hidden" name="type" value="$INPUT{type}">
			<input type="hidden" name="assigned_show" value="$INPUT{assigned_show}">
			<input type="hidden" name="enddate" value="$findldate">
			<input type="hidden" name="sortby" value="$INPUT{sortby}">
			<input type="hidden" name="id" value="$id">
		<td valign="top" nowrap>
			<select name="action_status" class="small_form" onChange="submit();">
			<option value="">Choose Action</option>
			<option value="Open">------</option>
			<option value="Open">Open</option>
			<option value="Edit">Edit</option>
			<option value="Delete">Delete</option>
			<option value="Open">------</option>
			<option value="Active - New">Mark as Active-New</option>
			<option value="Active - Hot">Mark as Active-Hot</option>
			<option value="Active - Warm">Mark as Active-Warm</option>
			<option value="Active - Cool">Mark as Active-Cool</option>
			<option value="Open">------</option>
			<option value="Client">Mark as Client</option>
			<option value="Stopped">Mark as Stopped</option>
			<option value="Inactive">Mark as Inactive</option>
			</select><br></td>
			</form>
		</tr>
		~;
	$prospect_found = "yes";
	}
	
	unless ($prospect_found eq "yes") {
	print qq~
	<tr>
	<td colspan="8" bgcolor="white"><font color="red"><b>No Prospects Created Yet!  Use the link above to create one now!</b></font></td>
	</tr>
	~;
	}

$dbh->disconnect;
print qq~
</table>
</div>
			<script language="JavaScript">
			<!-- 
				var cal1 = new calendar1(document.forms['prospect_search'].elements['enddate']);
				cal1.year_scroll = true;
				cal1.time_comp = false;

			//-->
			</script>
~;
&footer;
}

sub overview_notes_show {

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;

if ($INPUT{addnote} eq "1") {

	@variables2 = ($INPUT{next_followup},$INPUT{last_followup},$INPUT{result},$INPUT{prospectingid});
	$sql_query2 = "update trans_boardprospecting set next_followup = ?, last_followup = ?, result = ? where id = ?";
	my $basth = $dbh->do($sql_query2, undef, @variables2);

	my $usrdasth = $dbh->prepare("select firstname,lastname from users where userid = '$Cook{userid}'");
	$usrdasth->execute;
	while (($afirstname,$alastname) = $usrdasth->fetchrow_array()) {
	$generateaddedby = "$afirstname $alastname";
	}

    $notes_enter = "$INPUT{notes}  |  Action: $INPUT{result}";

	@variables = ($INPUT{prospectingid},$generateaddedby,$notes_enter,$INPUT{viewable});
	$sql_query = "INSERT INTO trans_boardprospecting_notes values ('',?,now(),?,?,?)";
	my $aasth = $dbh->do($sql_query, undef, @variables);

}

if ($INPUT{viewable} eq "change") {

	@variables2 = ($INPUT{ViewChange},$INPUT{id});
	$sql_query2 = "update trans_boardprospecting_notes set viewable = ? where noteid = ?";
	my $basth = $dbh->do($sql_query2, undef, @variables2);

	&Log(qq~Note Viewable Change Prospect: $INPUT{prospectingid}~);  # routine at the bottom of config.idx

print qq~
<html>
<head>
<title>Making Changes to Datebase</title>
<meta http-equiv="Refresh" content="1; URL=http://connect.eaglesold.com/prospecting.idx?view=overview_notes_show&prospectingid=$INPUT{prospectingid}">
</head>
<body bgcolor="white">
<center><font size="3" face="Arial" color="Red">Please wait, Processing</font><br>You will be redirected to when finished.  If not <a href="http://connect.eaglesold.com/prospecting.idx?view=overview_notes_show&prospectingid=$INPUT{prospectingid}">Click Here</a>.</center>
</body>
</html>
~;

exit 0;


}


if ($INPUT{delete} eq "yes") {
print qq~
		<html>
		<head></head>
		<body>
		<form method="post" action="prospecting.idx">
		<input type="hidden" name="view" value="overview_notes_show">
		<input type="hidden" name="id" value="$INPUT{id}">
		<input type="hidden" name="prospectingid" value="$INPUT{prospectingid}">
		<input type="hidden" name="delete" value="do">
		<center><br><br>
		<font size="3" color="Red"><b>Do You Really Want to Delete This Note?</b><br>
		<input type="submit" value="Yes"> or <a href="prospecting.idx?view=overview_notes_show&id=$INPUT{id}&prospectingid=$INPUT{prospectingid}">Go Back</a><br>
		</center>
		</form>
		</body>
		</html>
~;
exit 0;
}
elsif ($INPUT{delete} eq "do") {

@variables = ($INPUT{id});
$sql_query = "DELETE FROM trans_boardprospecting_notes WHERE noteid = ?";
my $aasth = $dbh->do($sql_query, undef, @variables);

&Log(qq~Note Deleted for Prospect: $INPUT{prospectingid}~);  # routine at the bottom of config.idx

print qq~
<html>
<head>
<title>Making Changes to Datebase</title>
<meta http-equiv="Refresh" content="1; URL=http://connect.eaglesold.com/prospecting.idx?view=overview_notes_show&prospectingid=$INPUT{prospectingid}">
</head>
<body bgcolor="white">
<center><font size="3" face="Arial" color="Red">Please wait, Processing</font><br>You will be redirected to when finished.  If not <a href="http://connect.eaglesold.com/prospecting.idx?view=overview_notes_show&prospectingid=$INPUT{prospectingid}">Click Here</a>.</center>
</body>
</html>
~;

exit 0;
}


my $basth = $dbh->prepare("select noteid,prospectingid,DATE_FORMAT(datetime, '%b %D, %Y at %h\:%i%p'),addedby,note,viewable from trans_boardprospecting_notes WHERE prospectingid = '$INPUT{prospectingid}' ORDER by datetime DESC");
$basth->execute;

print qq~
<html>
<head>
<title>Notes</title>
<link rel="stylesheet" TYPE="text/css" href="includes/style.css">
</head>
<body bgcolor="white" leftMargin="0" topMargin="0" marginwidth="0" marginheight="0">
<table border="0" cellpadding="4" cellspacing="0" width="100%">
~;
$trcolor = "1";
$trcolor2 = "2";

while (($noteid,$prospectingid,$datetime,$addedby,$note,$viewable) = $basth->fetchrow_array()) {
	if ($trcolor eq $trcolor2) {
	$trcolor = "1";
	$setcolor = "#FFFFFF";
	}
	else {
	$setcolor = "#CCCCFF";
	$trcolor++;
	}

if ($viewable eq "yes") { $viewable = "Viewable"; $viewable_link = "email-green.gif"; $opp_viewable = "no"; } else { $viewable = "Not Viewable"; $viewable_link = "email-red.gif"; $opp_viewable = "yes"; }
print qq~
<tr bgcolor="$setcolor">
	<td valign="top" width="100%">
		<b>$note</b><br>
	</td>
	<td valign="middle" align="right" nowrap>
		 $viewable <a href="prospecting.idx?view=overview_notes_show&id=$noteid&prospectingid=$INPUT{prospectingid}&viewable=change&ViewChange=$opp_viewable"><img src="http://connect.eaglesold.com/images/trans_sys/icons/$viewable_link" alt="Change Viewable Status" height="14" width="14" border="0"></a> <a href="prospecting.idx?view=overview_notes_show&id=$noteid&prospectingid=$INPUT{prospectingid}&delete=yes"><img src="http://connect.eaglesold.com/images/trans_sys/icons/delete-page-red.gif" alt="Delete This Note" height="14" width="14" border="0"></a><br>
	</td>
</tr>
<tr>
<td valign="top" colspan="2" bgcolor="$setcolor">
<i>Added by $addedby on $datetime</i>
</td>
</tr>
~;
$found = "yes";
}

unless ($found eq "yes") {
print qq~
<tr>
<td>
<font color="red"><b>No notes have been added yet!  You may use the textbox to the right to save notes.</b></font>
</td>
</tr>
~;
}
print qq~
</table>
</body>
</html>
~;
}