#!/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;
#$INPUT{action} = "find";
#$INPUT{query} = "9500";

if ($INPUT{action} eq "find") { &find; }
else { &main; }

sub find {

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;


#zip code fix
if ($INPUT{query} =~ /^[+-]?\d+$/) { $checknumber = " OR zip LIKE '%$INPUT{query}%'"; }
if ($INPUT{query} =~ /^[+-]?\d+$/) { $checknumber_ping = " OR prop_zip LIKE '%$INPUT{query}%'"; }

#### TRANSACTION SEARCH ####
#set defaults & SQL for non default
unless ($INPUT{t_sortby}) { $INPUT{t_sortby} = "ASC"; } else { $INPUT{t_sortby} = "$INPUT{t_sortby}"; }
unless ($INPUT{t_orderby}) { $INPUT{t_orderby} = "ORDER BY status"; } else { $INPUT{t_orderby} = "ORDER BY $INPUT{t_orderby}"; }
#### END TRANSACTION SEARCH STUFF ####


#### QUERY RESULTS FOR TRANSACTIONS  ######
my $transaction_search_cnt = $dbh->prepare("select COUNT(id) from trans_board WHERE agent = '$Cook{agentid}' AND (addressnumber LIKE '%$INPUT{query}%' OR addressdirection LIKE '%$INPUT{query}%' OR addressstreet LIKE '%$INPUT{query}%' OR city LIKE '%$INPUT{query}%' OR state LIKE '%$INPUT{query}%' $checknumber) $INPUT{t_orderby} $INPUT{t_sortby}");
$transaction_search_cnt->execute;
while (($t_cnt) = $transaction_search_cnt->fetchrow_array()) {
$t_count = "$t_cnt";
}

my $transaction_search = $dbh->prepare("select id,status,addressnumber,addressdirection,addressstreet,city,state,zip from trans_board WHERE agent = '$Cook{agentid}' AND (addressnumber LIKE '%$INPUT{query}%' OR addressdirection LIKE '%$INPUT{query}%' OR addressstreet LIKE '%$INPUT{query}%' OR city LIKE '%$INPUT{query}%' OR state LIKE '%$INPUT{query}%' $checknumber) $INPUT{t_orderby} $INPUT{t_sortby}");
$transaction_search->execute;
while (($t_id,$t_status,$t_addressnumber,$t_addressdirection,$t_addressstreet,$t_city,$t_state,$t_zip) = $transaction_search->fetchrow_array()) {

if ($t_addressnumber =~ /$INPUT{query}/i) { $t_addressnumber = "<span class=highlight>$t_addressnumber</span>"; }
if ($t_addressdirection =~ /$INPUT{query}/i) { $t_addressdirection = "<span class=highlight>$t_addressdirection</span>"; }
if ($t_addressstreet =~ /$INPUT{query}/i) { $t_addressstreet = "<span class=highlight>$t_addressstreet</span>"; }
if ($t_city =~ /$INPUT{query}/i) { $t_city = "<span class=highlight>$t_city</span>"; }
if ($t_state =~ /$INPUT{query}/i) { $t_state = "<span class=highlight>$t_state</span>"; }
if ($t_zip =~ /$INPUT{query}/i) { $t_zip = "<span class=highlight>$t_zip</span>"; }

$list_found .= "<a href=\"transactions.idx?action=overview&transid=$t_id&agent=$Cook{agentid}\" class=\"search_results\">Transaction: $t_status $t_addressnumber $t_addressdirection $t_addressstreet $t_city $t_state $t_zip</a><br><br>";
}

#### END TRANSACTION QUERY #####





#### CONTACT SEARCH ####
#set defaults & SQL for non default
unless ($INPUT{c_sortby}) { $INPUT{c_sortby} = "ASC"; } else { $INPUT{c_sortby} = "$INPUT{c_sortby}"; }
unless ($INPUT{c_orderby}) { $INPUT{c_orderby} = "ORDER BY lastname"; } else { $INPUT{c_orderby} = "ORDER BY $INPUT{c_orderby}"; }
#### END CONTACTS SEARCH STUFF ####


#### QUERY RESULTS FOR CONTACTS  ######

my $contact_search_cnt = $dbh->prepare("select COUNT(id) from trans_boardcontact WHERE agent = '$Cook{agentid}' AND (firstname LIKE '%$INPUT{query}%' OR spouse LIKE '%$INPUT{query}%' OR lastname LIKE '%$INPUT{query}%' OR address LIKE '%$INPUT{query}%' OR city LIKE '%$INPUT{query}%' OR state LIKE '%$INPUT{query}%' OR phone1number LIKE '%$INPUT{query}%'  OR phone2number LIKE '%$INPUT{query}%' OR phone3number LIKE '%$INPUT{query}%' OR email LIKE '%$INPUT{query}%' OR emailtwo LIKE '%$INPUT{query}%' $checknumber) $INPUT{c_orderby} $INPUT{c_sortby}");
$contact_search_cnt->execute;
while (($c_cnt) = $contact_search_cnt->fetchrow_array()) {
$c_count = "$c_cnt";
}

my $contact_search = $dbh->prepare("select id,firstname,spouse,lastname,address,city,state,phone1number,phone2number,phone3number,faxnumber,email,emailtwo,zip from trans_boardcontact WHERE agent = '$Cook{agentid}' AND (firstname LIKE '%$INPUT{query}%' OR spouse LIKE '%$INPUT{query}%' OR lastname LIKE '%$INPUT{query}%' OR address LIKE '%$INPUT{query}%' OR city LIKE '%$INPUT{query}%' OR state LIKE '%$INPUT{query}%' OR phone1number LIKE '%$INPUT{query}%'  OR phone2number LIKE '%$INPUT{query}%' OR phone3number LIKE '%$INPUT{query}%' OR email LIKE '%$INPUT{query}%' OR emailtwo LIKE '%$INPUT{query}%' $checknumber) $INPUT{c_orderby} $INPUT{c_sortby}");
$contact_search->execute;
while (($c_id,$c_firstname,$c_spouse,$c_lastname,$c_address,$c_city,$c_state,$c_phone1number,$c_phone2number,$c_phone3number,$c_faxnumber,$c_email,$c_emailtwo,$c_zip) = $contact_search->fetchrow_array()) {

### SHOW AUTO
if ($c_firstname =~ /$INPUT{query}/i) { $c_firstname = "<span class=highlight>$c_firstname</span>"; }
if ($c_spouse =~ /$INPUT{query}/i) { $c_spouse = "<span class=highlight>$c_spouse</span>"; }
if ($c_lastname =~ /$INPUT{query}/i) { $c_lastname = "<span class=highlight>$c_lastname</span>"; }


### SHOW OR HIDE UPON SEARCH

if ($c_address =~ /$INPUT{query}/i) { $c_address = "<span class=highlight>$c_address</span>"; } else { $c_address = ""; }
if ($c_city =~ /$INPUT{query}/i) { $c_city = "<span class=highlight>$c_city</span>"; } else { $c_city = ""; }
if ($c_state =~ /$INPUT{query}/i) { $c_state = "<span class=highlight>$c_state</span>"; } else { $c_state = ""; }
if ($c_zip =~ /$INPUT{query}/i) { $c_zip = "<span class=highlight>$c_zip</span>"; } else { $c_zip = ""; }
if ($c_phone1number =~ /$INPUT{query}/i) { $c_phone1number = "<span class=highlight>Phone: $c_phone1number</span>"; } else { $c_phone1number = ""; }
if ($c_phone2number =~ /$INPUT{query}/i) { $c_phone2number = "<span class=highlight>Phone: $c_phone2number</span>"; } else { $c_phone2number = ""; }
if ($c_phone3number =~ /$INPUT{query}/i) { $c_phone3number = "<span class=highlight>Phone: $c_phone3number</span>"; } else { $c_phone3number = ""; }
if ($c_faxnumber =~ /$INPUT{query}/i) { $c_faxnumber = "<span class=highlight>Fax: $c_faxnumber</span>"; } else { $c_faxnumber = ""; }
if ($c_email =~ /$INPUT{query}/i) { $c_email = "<span class=highlight>E-Mail: $c_email</span>"; } else { $c_email = ""; }
if ($c_emailtwo =~ /$INPUT{query}/i) { $c_emailtwo = "<span class=highlight>E-Mail: $c_emailtwo</span>"; } else { $c_emailtwo = ""; }

$list_found .= "<a href=\"contacts.idx?action=overview_contact&agent=$Cook{agentid}&contactid=$c_id\" class=\"search_results\">Contact: $c_firstname $c_spouse $c_lastname $c_address $c_city $c_state $c_zip $c_phone1number $c_phone2number $c_phone3number $c_faxnumber $c_email $c_emailtwo</a><br><br>";
}


#### END CONTACT QUERY #####

#### END OFFICE DIRECTORY QUERY #####

#### PROSPECTING SEARCH ####
#set defaults & SQL for non default
unless ($INPUT{ping_sortby}) { $INPUT{ping_sortby} = "ASC"; } else { $INPUT{ping_sortby} = "$INPUT{ping_sortby}"; }
unless ($INPUT{ping_orderby}) { $INPUT{ping_orderby} = "ORDER BY contact_lastname"; } #asdf

#### END PROSPECTING SEARCH STUFF ####


#### QUERY RESULTS FOR PROSPECTING  ######

my $prospecting_search_cnt = $dbh->prepare("select COUNT(id) from trans_boardprospecting WHERE agentid = '$Cook{agentid}' AND (contact_firstname LIKE '%$INPUT{query}%' OR contact_spouse LIKE '%$INPUT{query}%' OR contact_lastname LIKE '%$INPUT{query}%' OR prop_address_street LIKE '%$INPUT{query}%' OR prop_city LIKE '%$INPUT{query}%' OR contact_phone1_num1 LIKE '%$INPUT{query}%'  OR contact_phone1_num2 LIKE '%$INPUT{query}%' OR contact_phone1_num3 LIKE '%$INPUT{query}%' OR contact_emailaddress LIKE '%$INPUT{query}%' OR message_data LIKE '%$INPUT{query}%' $checknumber_ping) $INPUT{ping_orderby} $INPUT{ping_sortby}");
$prospecting_search_cnt->execute;
while (($ping_cnt) = $prospecting_search_cnt->fetchrow_array()) {
$ping_count = "$ping_cnt";
}

my $prospecting_search = $dbh->prepare("select id,type,message_data,contact_firstname,contact_spouse,contact_lastname,prop_address_street,prop_city,contact_phone1_num1,contact_phone1_num2,contact_phone1_num3,contact_emailaddress,contact_zip from trans_boardprospecting WHERE agentid = '$Cook{agentid}' AND (contact_firstname LIKE '%$INPUT{query}%' OR contact_spouse LIKE '%$INPUT{query}%' OR contact_lastname LIKE '%$INPUT{query}%' OR prop_address_street LIKE '%$INPUT{query}%' OR prop_city LIKE '%$INPUT{query}%' OR contact_phone1_num1 LIKE '%$INPUT{query}%'  OR contact_phone1_num2 LIKE '%$INPUT{query}%' OR contact_phone1_num3 LIKE '%$INPUT{query}%' OR contact_emailaddress LIKE '%$INPUT{query}%' OR message_data LIKE '%$INPUT{query}%' $checknumber_ping) $INPUT{ping_orderby} $INPUT{ping_sortby}");
$prospecting_search->execute;
while (($p_id,$p_type,$message_data,$p_firstname,$p_spouse,$p_lastname,$p_address,$p_city,$p_phone1number,$p_phone2number,$p_phone3number,$p_email,$p_zip) = $prospecting_search->fetchrow_array()) {

### SHOW AUTO
if ($p_firstname =~ /$INPUT{query}/i) { $p_firstname = "<span class=highlight>$p_firstname</span>"; }
if ($p_spouse =~ /$INPUT{query}/i) { $p_spouse = "<span class=highlight>$p_spouse</span>"; }
if ($p_lastname =~ /$INPUT{query}/i) { $p_lastname = "<span class=highlight>$p_lastname</span>"; }


### SHOW OR HIDE UPON SEARCH

if ($p_address =~ /$INPUT{query}/i) { $p_address = "<span class=highlight>$p_address</span>"; } else { $p_address = ""; }
if ($p_city =~ /$INPUT{query}/i) { $p_city = "<span class=highlight>$p_city</span>"; } else { $p_city = ""; }
if ($p_state =~ /$INPUT{query}/i) { $p_state = "<span class=highlight>$p_state</span>"; } else { $p_state = ""; }
if ($p_zip =~ /$INPUT{query}/i) { $p_zip = "<span class=highlight>$p_zip</span>"; } else { $p_zip = ""; }
if ($p_phone1number =~ /$INPUT{query}/i) { $p_phone1number = "<span class=highlight>$p_phone1number</span>"; }
if ($p_phone2number =~ /$INPUT{query}/i) { $p_phone2number = "<span class=highlight>$p_phone2number</span>"; }
if ($p_phone3number =~ /$INPUT{query}/i) { $p_phone3number = "<span class=highlight>$p_phone3number</span>"; }
if ($message_data =~ /$INPUT{query}/i) { $message_data = "<br><i><b>Message Data:</b> <span class=highlight>$message_data</span></i>"; }

$real_number = "Phone: $p_phone1number-$p_phone2number-$p_phone3number";

if ($real_number eq "Phone: --") {
$real_number = "";
}

if ($p_faxnumber =~ /$INPUT{query}/i) { $p_faxnumber = "<span class=highlight>Fax: $p_faxnumber</span>"; } else { $p_faxnumber = ""; }
if ($p_email =~ /$INPUT{query}/i) { $p_email = "<span class=highlight>E-Mail: $p_email</span>"; } else { $p_email = ""; }
if ($p_emailtwo =~ /$INPUT{query}/i) { $p_emailtwo = "<span class=highlight>E-Mail: $p_emailtwo</span>"; } else { $p_emailtwo = ""; }

$list_found .= "<a href=\"prospecting.idx?view=details&agent=$Cook{agentid}&id=$p_id\" class=\"search_results\">Prospecting: $p_type $p_firstname $p_spouse $p_lastname $p_address $p_city $p_state $p_zip $real_number $p_email</a>$message_data<br><br>";
}


#### END PROSPECTING QUERY #####


#### PROSPECT SEARCH ####
#set defaults & SQL for non default
unless ($INPUT{p_sortby}) { $INPUT{p_sortby} = "ASC"; } else { $INPUT{p_sortby} = "$INPUT{p_sortby}"; }
unless ($INPUT{p_orderby}) { $INPUT{p_orderby} = "ORDER BY lastname"; } else { $INPUT{p_orderby} = "ORDER BY $INPUT{p_orderby}"; }
#### END PROSPECTS SEARCH STUFF ####


#### QUERY RESULTS FOR PROSPECTS  ######
my $prospect_search_cnt = $dbh->prepare("select COUNT(id) from trans_boardprospect WHERE agent = '$Cook{agentid}' AND (firstname LIKE '%$INPUT{query}%' OR spouse LIKE '%$INPUT{query}%' OR lastname LIKE '%$INPUT{query}%' OR address LIKE '%$INPUT{query}%' OR city LIKE '%$INPUT{query}%' OR state LIKE '%$INPUT{query}%' OR phone1number LIKE '%$INPUT{query}%'  OR phone2number LIKE '%$INPUT{query}%' OR phone3number LIKE '%$INPUT{query}%' OR email LIKE '%$INPUT{query}%' OR emailtwo LIKE '%INPUT{query}%' $checknumber) $INPUT{p_orderby} $INPUT{p_sortby}");
$prospect_search_cnt->execute;
while (($p_cnt) = $prospect_search_cnt->fetchrow_array()) {
$p_count = "$p_cnt";
}

my $prospect_search = $dbh->prepare("select id,firstname,spouse,lastname,address,city,state,phone1number,phone2number,phone3number,faxnumber,email,emailtwo,zip from trans_boardprospect WHERE agent = '$Cook{agentid}' AND (firstname LIKE '%$INPUT{query}%' OR spouse LIKE '%$INPUT{query}%' OR lastname LIKE '%$INPUT{query}%' OR address LIKE '%$INPUT{query}%' OR city LIKE '%$INPUT{query}%' OR state LIKE '%$INPUT{query}%' OR phone1number LIKE '%$INPUT{query}%'  OR phone2number LIKE '%$INPUT{query}%' OR phone3number LIKE '%$INPUT{query}%' OR email LIKE '%$INPUT{query}%' OR emailtwo LIKE '%$INPUT{query}%' $checknumber) $INPUT{p_orderby} $INPUT{p_sortby}");
$prospect_search->execute;
while (($p_id,$p_firstname,$p_spouse,$p_lastname,$p_address,$p_city,$p_state,$p_phone1number,$p_phone2number,$p_phone3number,$p_faxnumber,$p_email,$p_emailtwo,$p_zip) = $prospect_search->fetchrow_array()) {

### SHOW AUTO
if ($p_firstname =~ /$INPUT{query}/i) { $p_firstname = "<span class=highlight>$p_firstname</span>"; }
if ($p_spouse =~ /$INPUT{query}/i) { $p_spouse = "<span class=highlight>$p_spouse</span>"; }
if ($p_lastname =~ /$INPUT{query}/i) { $p_lastname = "<span class=highlight>$p_lastname</span>"; }


### SHOW OR HIDE UPON SEARCH

if ($p_address =~ /$INPUT{query}/i) { $p_address = "<span class=highlight>$p_address</span>"; } else { $p_address = ""; }
if ($p_city =~ /$INPUT{query}/i) { $p_city = "<span class=highlight>$p_city</span>"; } else { $p_city = ""; }
if ($p_state =~ /$INPUT{query}/i) { $p_state = "<span class=highlight>$p_state</span>"; } else { $p_state = ""; }
if ($p_zip =~ /$INPUT{query}/i) { $p_zip = "<span class=highlight>$p_zip</span>"; } else { $p_zip = ""; }
if ($p_phone1number =~ /$INPUT{query}/i) { $p_phone1number = "<span class=highlight>Phone: $p_phone1number</span>"; } else { $p_phone1number = ""; }
if ($p_phone2number =~ /$INPUT{query}/i) { $p_phone2number = "<span class=highlight>Phone: $p_phone2number</span>"; } else { $p_phone2number = ""; }
if ($p_phone3number =~ /$INPUT{query}/i) { $p_phone3number = "<span class=highlight>Phone: $p_phone3number</span>"; } else { $p_phone3number = ""; }
if ($p_faxnumber =~ /$INPUT{query}/i) { $p_faxnumber = "<span class=highlight>Fax: $p_faxnumber</span>"; } else { $p_faxnumber = ""; }
if ($p_email =~ /$INPUT{query}/i) { $p_email = "<span class=highlight>E-Mail: $p_email</span>"; } else { $p_email = ""; }
if ($p_emailtwo =~ /$INPUT{query}/i) { $p_emailtwo = "<span class=highlight>E-Mail: $p_emailtwo</span>"; } else { $p_emailtwo = ""; }

$list_found .= "<a href=\"prospects.idx?action=overview_prospect&agent=$Cook{agentid}&prospectid=$p_id\" class=\"search_results\">(OLD Prospect DB): $p_firstname $p_spouse $p_lastname $p_address $p_city $p_state $p_zip $p_phone1number $p_phone2number $p_phone3number $p_faxnumber $p_email $p_emailtwo</a><br><br>";
}


#### END PROSPECT QUERY #####


#### OFFICE DIRECTORY SEARCH ####
#set defaults & SQL for non default
unless ($INPUT{od_sortby}) { $INPUT{od_sortby} = "ASC"; } else { $INPUT{od_sortby} = "$INPUT{od_sortby}"; }
unless ($INPUT{od_orderby}) { $INPUT{od_orderby} = "ORDER BY lastname"; } else { $INPUT{od_orderby} = "ORDER BY $INPUT{od_orderby}"; }
#### END OFFICE DIRECTORY SEARCH STUFF ####


#### QUERY RESULTS FOR OFFICE DIRECTORY  ######
my $officedirectory_search_cnt = $dbh->prepare("select COUNT(id) from trans_boarddirectory WHERE (firstname LIKE '%$INPUT{query}%' OR lastname LIKE '%$INPUT{query}%' OR agent1phone LIKE '%$INPUT{query}%' OR agent2phone LIKE '%$INPUT{query}%' OR agent3phone LIKE '%$INPUT{query}%' OR agentfax LIKE '%$INPUT{query}%'  OR email LIKE '%$INPUT{query}%' OR company LIKE '%$INPUT{query}%' OR coaddress LIKE '%$INPUT{query}%' OR cocity LIKE '%INPUT{query}%' OR costate LIKE '%$INPUT{query}%' OR cophone LIKE '%$INPUT{query}%') $INPUT{od_orderby} $INPUT{od_sortby}");
$officedirectory_search_cnt->execute;
while (($od_cnt) = $officedirectory_search_cnt->fetchrow_array()) {
$od_count = "$od_cnt";
}

my $officedirectory_search = $dbh->prepare("select id,firstname,lastname,agent1phone,agent2phone,agent3phone,agentfax,email,company,coaddress,cocity,costate,cophone from trans_boarddirectory WHERE (firstname LIKE '%$INPUT{query}%' OR lastname LIKE '%$INPUT{query}%' OR agent1phone LIKE '%$INPUT{query}%' OR agent2phone LIKE '%$INPUT{query}%' OR agent3phone LIKE '%$INPUT{query}%' OR agentfax LIKE '%$INPUT{query}%'  OR email LIKE '%$INPUT{query}%' OR company LIKE '%$INPUT{query}%' OR coaddress LIKE '%$INPUT{query}%' OR cocity LIKE '%INPUT{query}%' OR costate LIKE '%$INPUT{query}%' OR cophone LIKE '%$INPUT{query}%') $INPUT{od_orderby} $INPUT{od_sortby}");
$officedirectory_search->execute;
while (($od_id,$od_firstname,$od_lastname,$od_agent1phone,$od_agent2phone,$od_agent3phone,$od_agentfax,$od_email,$od_company,$od_coaddress,$od_cocity,$od_costate,$od_cophone) = $officedirectory_search->fetchrow_array()) {

### SHOW AUTO
if ($od_firstname =~ /$INPUT{query}/i) { $od_firstname = "<span class=highlight>$od_firstname</span>"; }
if ($od_lastname =~ /$INPUT{query}/i) { $od_lastname = "<span class=highlight>$od_lastname</span>"; }
if ($od_company =~ /$INPUT{query}/i) { $od_company = "<span class=highlight>$od_company</span>"; }


### SHOW OR HIDE UPON SEARCH

if ($od_coaddress =~ /$INPUT{query}/i) { $od_coaddress = "<span class=highlight>$od_coaddress</span>"; } else { $od_coaddress = ""; }
if ($od_cocity =~ /$INPUT{query}/i) { $od_cocity = "<span class=highlight>$od_cocity</span>"; } else { $od_cocity = ""; }
if ($od_costate =~ /$INPUT{query}/i) { $od_costate = "<span class=highlight>$od_costate</span>"; } else { $od_costate = ""; }
if ($od_cophone =~ /$INPUT{query}/i) { $od_cophone = "<span class=highlight>$od_cophone</span>"; } else { $od_cophone = ""; }
if ($od_email =~ /$INPUT{query}/i) { $od_email = "<span class=highlight>E-Mail: $od_email</span>"; } else { $od_email = ""; }
if ($od_agentfax =~ /$INPUT{query}/i) { $od_agentfax = "<span class=highlight>Fax: $od_agentfax</span>"; } else { $od_agentfax = ""; }
if ($od_agent1phone =~ /$INPUT{query}/i) { $od_agent1phone = "<span class=highlight>Phone: $od_agent1phone</span>"; } else { $od_agent1phone = ""; }
if ($od_agent2phone =~ /$INPUT{query}/i) { $od_agent2phone = "<span class=highlight>Phone: $od_agent2phone</span>"; } else { $od_agent2phone = ""; }
if ($od_agent3phone =~ /$INPUT{query}/i) { $od_agent3phone = "<span class=highlight>Phone: $od_agent3phone</span>"; } else { $od_agent3phone = ""; }
if ($Cook{agentid} eq "122") {
$list_found .= "<a href=\"directoryadmin.idx?action=directory_view&agent=$Cook{agentid}&directoryid=$od_id&searchtype=contact\" class=\"search_results\">Office Directory: $od_firstname $od_lastname $od_company $od_coaddress $od_cocity $od_costate $od_cophone $od_agent1phone $od_agent2phone $od_agent3phone $od_agentfax $od_email</a><br><br>";
}
else {
$list_found .= "<a href=\"transactions.idx?action=directory_view&agent=$Cook{agentid}&directoryid=$od_id&searchtype=contact\" class=\"search_results\">Office Directory: $od_firstname $od_lastname $od_company $od_coaddress $od_cocity $od_costate $od_cophone $od_agent1phone $od_agent2phone $od_agent3phone $od_agentfax $od_email</a><br><br>";
}
}

unless ($list_found) { $list_found = "<br><span class=search_error>No Search Matches Found.... Please Try Again Using Less Information</span>"; }
$list_count = ($t_count+$c_count+$ping_count+$p_count+$od_count);



print qq~
<html>
<head>
<title>Connect.EagleSold.com Search Results for: $INPUT{query}!</title>
~;

&header;


print qq~
<td valign="top" width="581">
<img src="images/headers/searchresults.gif" height="33" width="581" alt="Search Results for $INPUT{query}"><br>
~;

print qq~
<table border="0" cellpadding="3" cellspacing="1" width="100%">
<tr>
<td valign="top" width="100%">
<span class="search_header">Your Search for "<u>$INPUT{query}</u>" Found "<u>$list_count Results</u>"!</span><br><br>
$list_found<br>
</td>
</tr>
</table>
~;
&footer;

}



sub main {

print qq~
<html>
<head>
<title>Search For?</title>
</head>
<body>

<form method="get" action="search.idx">
<input type="hidden" name="action" value="find">
<input type="text" name="query">
<input type="submit" value="Find It">
</form>

</body>
</html>


~;


}