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

#&overview_tasks;
#exit 0;

if ( $INPUT{action} eq "create_transaction" ) { &create_transaction; }
elsif ( $INPUT{action} eq "create_transaction_verify" ) {
    &create_transaction_verify;
}
elsif ( $INPUT{action} eq "create_transaction_do" ) { &create_transaction_do; }
elsif ( $INPUT{action} eq "edit_transaction" )      { &edit_transaction; }
elsif ( $INPUT{action} eq "edit_transaction_do" )   { &edit_transaction_do; }
elsif ( $INPUT{action} eq "delete_transaction" )    { &delete_transaction; }
elsif ( $INPUT{action} eq "assign_contact" )        { &assign_contact; }
elsif ( $INPUT{action} eq "assign_contact_do" )     { &assign_contact_do; }
elsif ( $INPUT{action} eq "unassign_contact" )      { &unassign_contact; }
elsif ( $INPUT{action} eq "create_contact" )        { &create_contact; }
elsif ( $INPUT{action} eq "create_contact_verify" ) { &create_contact_verify; }
elsif ( $INPUT{action} eq "create_contact_do" )     { &create_contact_do; }
elsif ( $INPUT{action} eq "overview" )              { &overview; }
elsif ( $INPUT{action} eq "overview_notes_show" )   { &overview_notes_show; }
elsif ( $INPUT{action} eq "overview_contact_notes_show" ) {
    &overview_contact_notes_show;
}
elsif ( $INPUT{action} eq "overview_tasks" )     { &overview_tasks; }
elsif ( $INPUT{action} eq "overview_documents" ) { &overview_documents; }
elsif ( $INPUT{action} eq "overview_documents_contact" ) {
    &overview_documents_contact;
}
elsif ( $INPUT{action} eq "overview_mortgage" ) { &overview_mortgage; }
elsif ( $INPUT{action} eq "overview_mortgage_edit" ) {
    &overview_mortgage_edit;
}
elsif ( $INPUT{action} eq "overview_mortgage_fa" ) { &overview_mortgage_fa; }
elsif ( $INPUT{action} eq "overview_stats" )       { &overview_stats; }
elsif ( $INPUT{action} eq "overview_inspections" ) { &overview_inspections; }
elsif ( $INPUT{action} eq "overview_inspections_view" ) {
    &overview_inspections_view;
}
elsif ( $INPUT{action} eq "overview_inspections_edit" ) {
    &overview_inspections_edit;
}
elsif ( $INPUT{action} eq "overview_contacts_smallaz" ) {
    &overview_contacts_smallaz;
}
elsif ( $INPUT{action} eq "overview_titlework" ) { &overview_titlework; }
elsif ( $INPUT{action} eq "overview_titlework_edit" ) {
    &overview_titlework_edit;
}
elsif ( $INPUT{action} eq "overview_survey" )      { &overview_survey; }
elsif ( $INPUT{action} eq "overview_survey_edit" ) { &overview_survey_edit; }
elsif ( $INPUT{action} eq "overview_showings" )    { &overview_showings; }
elsif ( $INPUT{action} eq "overview_prospects" )   { &overview_prospects; }
elsif ( $INPUT{action} eq "overview_prospects_add" ) {
    &overview_prospects_add;
}
elsif ( $INPUT{action} eq "overview_prospects_adddo" ) {
    &overview_prospects_adddo;
}
elsif ( $INPUT{action} eq "directory" )          { &directory; }
elsif ( $INPUT{action} eq "directory_view" )     { &directory_view; }
elsif ( $INPUT{action} eq "myemailer" )          { &myemailer; }
elsif ( $INPUT{action} eq "myemailer_send" )     { &myemailer_send; }
elsif ( $INPUT{action} eq "showingadmin" )       { &showingadmin; }
elsif ( $INPUT{action} eq "transaction_report" ) { &transaction_report; }
elsif ( $INPUT{action} eq "runsql" )             { &runsql; }
elsif ( $INPUT{action} eq "upload_document" )    { &upload_document; }
elsif ( $INPUT{action} eq "document_progress" )  { &document_progress; }
else                                             { &main; }

sub document_progress {

}

sub upload_document {

    if ( $INPUT{cat} eq "c" ) {
        $upload_for = "Contact";
    }
    else {
        $upload_for = "Transaction";
    }

    print qq~<b>Upload New $upload_for Document</b>
<br><br>
<FORM action="upload_doc.idx" encType=multipart/form-data method=post>
<input type=hidden name=matchid value="$INPUT{id}">
<input type=hidden name=matchcat value="$INPUT{cat}">
Title: <input type=text name=name size=34><br>
File: <INPUT name=FILE1 type=file> <br>
<INPUT type=submit value=" Upload File ">
</form>
~;

}

sub overview_documents {

    $show_icon{pdf} =
qq~<img src="http://connect.eaglesold.com/documents/small-pdf-icon.gif" alt="PDF Document">~;
    $show_icon{doc} =
qq~<img src="http://connect.eaglesold.com/documents/small-word-icon.jpg" alt="Microsoft Word Document">~;
    $show_icon{jpg} =
qq~<img src="http://connect.eaglesold.com/documents/small-jpg-icon.jpg" alt="JPG Photo">~;
    $show_icon{efx} =
qq~<img src="http://connect.eaglesold.com/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 documents where matchid = '$INPUT{transid}' and matchcat = 't' 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/$documents{did}.$documents{newfileext}" target="_blank">$documents{name}</a><br>Added $documents{dateadded}<br>~;
        $found = "yes";
    }

    print qq~
<html>
<head>
<title>Eagle Real Estate, Inc. - Connect.EagleSold.com</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 overview_documents_contact {

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

    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 documents where matchid = '$INPUT{contactid}' and matchcat = 'c' 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/$documents{did}.$documents{newfileext}" target="_blank">$documents{name}</a><br>Added $documents{dateadded}<br>~;
        $found = "yes";
    }

    print qq~
<html>
<head>
<title>Eagle Real Estate, Inc. - Connect.EagleSold.com</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 transaction_report {

    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" ) {

        @variables = ( $INPUT{transid}, $INPUT{notes} );
        $sql_query = "INSERT INTO trans_boardnotes values ('',?,now(),?)";
        my $aasth = $dbh->do( $sql_query, undef, @variables );

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

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

            $notes = "<i>Listing note added to $INPUT{address}:</i><br>";
            $notes .= "$INPUT{notes}";

            @insert_vars =
              ( $Cook{agentid}, TransactionSystem, None, $good_date, $notes );

            $tsql_query =
              "insert into todo values ('',?,?,?,?,?,'$INPUT{todo_mark}')";
            $yasth = $dbh->do( $tsql_query, undef, @insert_vars );
        }

    }

    print qq~
<html>
<head>
<title>Eagle Real Estate, Inc. - Connect.EagleSold.com</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="0" cellspacing="0" width="581">
<tr>
<td valign="top" width="581">
<img src="images/trans_sys/my_transactionoverview.gif" alt="My Transaction Overview"><br>
~;

    my $aasth =
      $dbh->prepare(
"select id,agent,mlsnumber,selleragent,sellercoagent,buyeragent,buyercoagent,type,status,addressnumber,addressdirection,addressstreet,city,state,zip,listingdate,expiredate,listingprice,showinginstructions,notes,pendingdate,inspectionresponsedays,estimatedclosingdate,soldprice,solddate from trans_board WHERE id = '$INPUT{transid}'"
      );
    $aasth->execute;
    while (
        (
            $id,                   $agent,
            $mlsnumber,            $selleragent,
            $sellercoagent,        $buyeragent,
            $buyercoagent,         $type,
            $status,               $addressnumber,
            $addressdirection,     $addressstreet,
            $city,                 $state,
            $zip,                  $listingdate,
            $expiredate,           $listingprice,
            $showinginstructions,  $notes,
            $pendingdate,          $inspectionresponsedays,
            $estimatedclosingdate, $soldprice,
            $solddate
        )
        = $aasth->fetchrow_array()
      )
    {

        my $zaasth =
          $dbh->prepare(
"select id,firstname,lastname,company from trans_boarddirectory where id = '$selleragent'"
          );
        $zaasth->execute;

        my $azaasth =
          $dbh->prepare(
"select id,firstname,lastname,company from trans_boarddirectory where id = '$sellercoagent'"
          );
        $azaasth->execute;

        my $bzaasth =
          $dbh->prepare(
"select id,firstname,lastname,company from trans_boarddirectory where id = '$buyeragent'"
          );
        $bzaasth->execute;

        my $czaasth =
          $dbh->prepare(
"select id,firstname,lastname,company from trans_boarddirectory where id = '$buyercoagent'"
          );
        $czaasth->execute;

        my $bkasth =
          $dbh->prepare(
"select ADDDATE('$pendingdate', INTERVAL $inspectionresponsedays DAY)"
          );
        $bkasth->execute;
        while ( ($newdate) = $bkasth->fetchrow_array() ) {
            $inspectionresponsedate = $newdate;
        }

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

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

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

        if ( $listingprice eq "" ) {
            $listingprice = "Not Entered";
        }

        if ( $soldprice eq "" ) {
            $soldprice = "Not Entered";
        }

        if ( $inspectionresponsedate eq "" ) {
            $inspectionresponsedate = "Not Avail.";
        }

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

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

        print qq~
<br>

<table border="0" cellpadding="3" cellspacing="0" width="100%">
<tr>
~;

        if ( -e "/photos/muncie_in_meiar/thumbnail/meiarmls$mlsnumber\.jpg" ) {
            print qq~
<td valign="top">
<img src="http://www.munciemls.com/images/photos/thumbnail/meiarmls$mlsnumber.jpg"><br>
</td>
~;
        }
        print qq~
<td valign="top"><font size="4" face="Arial"><b>$addressnumber $addressdirection $addressstreet<br>$city, $state $zip</b></font><br></td>
<td valign="top">
	<table border="0" cellpadding="3" cellspacing="0" width="100%">
	<tr>
	<td valign="top" bgcolor="navy" nowrap><font color="white" size="2"><b>Buyer(s)</b></font><br></td>
	</tr>
	</table>
~;
######### GET BUYER INFORMATION #####################

        my $bbaasth =
          $dbh->prepare(
"select contactid from trans_boardtranstocontact WHERE transid = '$INPUT{transid}' AND type = 'Buyer'"
          );
        $bbaasth->execute;
        while ( ($tempcontactid) = $bbaasth->fetchrow_array() ) {

            my $ddasth =
              $dbh->prepare(
"select id,agent,type,firstname,lastname,address,spouse,city,state,zip,phone1type,phone1number,phone2type,phone2number,phone3type,phone3number,faxnumber,email,emailtwo,notes from trans_boardcontact WHERE id = '$tempcontactid'"
              );
            $ddasth->execute;

            while (
                (
                    $b_contactid,    $b_agent,        $b_type,
                    $b_firstname,    $b_lastname,     $b_address,
                    $b_spouse,       $b_city,         $b_state,
                    $b_zip,          $b_phone1type,   $b_phone1number,
                    $b_phone2type,   $b_phone2number, $b_phone3type,
                    $b_phone3number, $b_faxnumber,    $b_email,
                    $b_emailtwo,     $b_notes
                )
                = $ddasth->fetchrow_array()
              )
            {

                if ( $b_spouse ne "" ) {
                    $b_spouse = " & $b_spouse ";
                }
                else {
                    $b_spouse = "";
                }
                print qq~
			<a href="transactions.idx?action=unassign_contact&transid=$id&agent=$agent&contactid=$b_contactid"><img src="images/unlink_contact.gif" height="8" width="10" border="0" alt="Unlink Contact From This Transaction"></a> <a href="transactions.idx?action=overview_contact&agent=$agent&contactid=$b_contactid">$b_firstname$b_spouse $b_lastname</a><br>
		~;
            }
            $bfound = "yes";
        }

        unless ( $bfound eq "yes" ) {
            print qq~
	<a href="transactions.idx?action=assign_contact&transid=$id&agent=$agent&contact_type=Buyer&address=$addressnumber $addressdirection $addressstreet">Assign Buyer</a>
~;
        }
#####################################################
        print qq~
</td>
<td valign="top">
	<table border="0" cellpadding="3" cellspacing="0" width="100%">
	<tr>
	<td valign="top" bgcolor="navy" nowrap><font color="white" size="2"><b>Seller(s)</b></font><br></td>
	</tr>
	</table>
~;
######### GET SELLER INFORMATION #####################

        my $sbaasth =
          $dbh->prepare(
"select contactid from trans_boardtranstocontact WHERE transid = '$INPUT{transid}' AND type = 'Seller'"
          );
        $sbaasth->execute;
        while ( ($tempcontactid) = $sbaasth->fetchrow_array() ) {

            my $sddasth =
              $dbh->prepare(
"select id,agent,type,firstname,lastname,address,spouse,city,state,zip,phone1type,phone1number,phone2type,phone2number,phone3type,phone3number,faxnumber,email,emailtwo,notes from trans_boardcontact WHERE id = '$tempcontactid'"
              );
            $sddasth->execute;

            while (
                (
                    $s_contactid,    $s_agent,        $s_type,
                    $s_firstname,    $s_lastname,     $s_address,
                    $s_spouse,       $s_city,         $s_state,
                    $s_zip,          $s_phone1type,   $s_phone1number,
                    $s_phone2type,   $s_phone2number, $s_phone3type,
                    $s_phone3number, $s_faxnumber,    $s_email,
                    $s_emailtwo,     $s_notes
                )
                = $sddasth->fetchrow_array()
              )
            {

                if ( $s_spouse ne "" ) {
                    $s_spouse = " & $s_spouse ";
                }
                else {
                    $s_spouse = "";
                }

                print qq~
			<a href="transactions.idx?action=unassign_contact&transid=$id&agent=$agent&contactid=$s_contactid"><img src="images/unlink_contact.gif" height="8" width="10" border="0" alt="Unlink This Contact From This Transaction"></a> <a href="transactions.idx?action=overview_contact&agent=$agent&contactid=$s_contactid">$s_firstname$s_spouse $s_lastname</a><br>
		~;
            }
            $sfound = "yes";
        }

        unless ( $sfound eq "yes" ) {
            print qq~
	<a href="transactions.idx?action=assign_contact&transid=$id&agent=$agent&contact_type=Seller&address=$addressnumber $addressdirection $addressstreet">Assign Seller</a>
~;
        }
#####################################################
        print qq~
</td>
</tr>
</table>
<br>
<table border="0" cellpadding="4" cellspacing="0" width="581">
<tr>
<td valign="top" width="131" bgcolor="#CCFFCC" align="right">
<font color="#009900">
<b>Type</b><br>
<a href="http://connect.eaglesold.com/transactions.idx?action=edit_transaction&transid=$id&agent=$Cook{agentid}">$type</a><br>
<b>Status</b><br>
<a href="http://connect.eaglesold.com/transactions.idx?action=edit_transaction&transid=$id&agent=$Cook{agentid}">$status</a><br>
<b>MLS Number</b><br>
<a href="http://connect.eaglesold.com/transactions.idx?action=edit_transaction&transid=$id&agent=$Cook{agentid}">$mlsnumber</a><br>
<b>Listing Date</b><br>
<a href="http://connect.eaglesold.com/transactions.idx?action=edit_transaction&transid=$id&agent=$Cook{agentid}">$listingdate</a><br>
<b>Expire Date</b><br>
<a href="http://connect.eaglesold.com/transactions.idx?action=edit_transaction&transid=$id&agent=$Cook{agentid}">$expiredate</a><br>
<b>Listing Price</b><br>
<a href="http://connect.eaglesold.com/transactions.idx?action=edit_transaction&transid=$id&agent=$Cook{agentid}">$listingprice</a><br>
<b>Pending Date</b><br>
<a href="http://connect.eaglesold.com/transactions.idx?action=edit_transaction&transid=$id&agent=$Cook{agentid}">$pendingdate</a><br>
<b>Inspection Response</b><br>
<a href="http://connect.eaglesold.com/transactions.idx?action=edit_transaction&transid=$id&agent=$Cook{agentid}">$inspectionresponsedate</a><br>
<b>Estimated Closing Date</b><br>
<a href="http://connect.eaglesold.com/transactions.idx?action=edit_transaction&transid=$id&agent=$Cook{agentid}">$estimatedclosingdate</a><br>
<b>Sold Price</b><br>
<a href="http://connect.eaglesold.com/transactions.idx?action=edit_transaction&transid=$id&agent=$Cook{agentid}">$soldprice</a><br>
<b>Sold Date</b><br>
<a href="http://connect.eaglesold.com/transactions.idx?action=edit_transaction&transid=$id&agent=$Cook{agentid}">$solddate</a><br>
<b>Notes</b><br>
<a href="http://connect.eaglesold.com/transactions.idx?action=edit_transaction&transid=$id&agent=$Cook{agentid}">$notes</a><br>
<b>Seller Agent</b><br>
~;
        if ( $selleragent eq "0" ) {
            print qq~
<a href="http://connect.eaglesold.com/transactions.idx?action=edit_transaction&transid=$id&agent=$Cook{agentid}">$selleragent</a><br>
~;
        }
        else {
            while (
                (
                    $listagentid,       $listagentfirstname,
                    $listagentlastname, $listagentcompany
                )
                = $zaasth->fetchrow_array()
              )
            {
                print qq~
<a href="http://connect.eaglesold.com/transactions.idx?action=directory_view&agent=$Cook{agentid}&directoryid=$listagentid">$listagentfirstname $listagentlastname</a><br>
~;
            }
        }

        if ( $sellercoagent eq "0" ) {
            print qq~
~;
        }
        else {
            while (
                (
                    $sclistagentid,       $sclistagentfirstname,
                    $sclistagentlastname, $sclistagentcompany
                )
                = $azaasth->fetchrow_array()
              )
            {
                print qq~
<a href="http://connect.eaglesold.com/transactions.idx?action=directory_view&agent=$Cook{agentid}&directoryid=$sclistagentid">$sclistagentfirstname $sclistagentlastname</a><br>
~;
            }
        }
        print qq~
<b>Buyer Agent</b><br>
~;
        if ( $buyeragent eq "0" ) {
            print qq~
<a href="http://connect.eaglesold.com/transactions.idx?action=edit_transaction&transid=$id&agent=$Cook{agentid}">No Agent Assigned</a><br>
~;
        }
        else {
            while (
                (
                    $blistagentid,       $blistagentfirstname,
                    $blistagentlastname, $blistagentcompany
                )
                = $bzaasth->fetchrow_array()
              )
            {
                print qq~
<a href="http://connect.eaglesold.com/transactions.idx?action=directory_view&agent=$Cook{agentid}&directoryid=$blistagentid">$blistagentfirstname $blistagentlastname</a><br>
~;
            }
        }

        if ( $buyercoagent eq "0" ) {
            print qq~
~;
        }
        else {
            while (
                (
                    $bclistagentid,       $bclistagentfirstname,
                    $bclistagentlastname, $bclistagentcompany
                )
                = $czaasth->fetchrow_array()
              )
            {
                print qq~
<a href="http://connect.eaglesold.com/transactions.idx?action=directory_view&agent=$Cook{agentid}&directoryid=$bclistagentid">$bclistagentfirstname $bclistagentlastname</a><br>
~;
            }
        }
        print qq~
</font>
</td>
<td valign="top" width="450">
<center>
<table border="0" cellpadding="2" cellspacing="0" width="100%">
<tr>
<td colspan="2">
	<table border="0" cellpadding="1" cellspacing="0" width="100%">
	<tr>
	<td valign="top" width="65%">
		<table border="0" cellpadding="3" cellspacing="0" width="100%">
<tr>
<td valign="top" bgcolor="navy" nowrap><font color="white" size="2"><b>My Notes</b></font><br></td>
<td valign="top" bgcolor="navy" align="right">
<table border="0" cellspacing="1" cellpadding="2" bgcolor="white">
<tr>
<td valign="top" bgcolor="silver">
View Notes Below<br>
</td>
</tr>
</table>
</td>
</tr>
</table>
		<iframe src="transactions.idx?action=overview_notes_show&transid=$id" width="100%" height="115" noresize="noresize" scrolling ="yes" frameborder="0" marginwidth="3" marginheight="3"></iframe>
	</td>
	<td valign="top" width="35%">
		<form method="get" action="transactions.idx">
		<input type="hidden" name="action" value="overview">
		<input type="hidden" name="transid" value="$INPUT{transid}">
		<input type="hidden" name="agent" value="$Cook{agentid}">
		<input type="hidden" name="addnote" value="1">
		<input type="hidden" name="address" value="$addressnumber $addressdirection $addressstreet">
		<textarea cols="35" rows="8" name="notes" class="form"></textarea><br>
		<select name="todo" class="form">
		<option value="yes">ToDo</option>
		<option value="no">Hide</option></select><select name="todo_mark" class="form"><option value="y">Mark Done</option><option value="n">Not Done</option></select><input type="submit" value="Save" class="form">
		</form>		
	</td>
	</tr>
	</table>
</td>
</tr>
~;
        if ( $type eq 'BSP' or $type eq 'Listing' or $type eq 'SP' ) {
            print qq~
<tr>
<td colspan="2">
	<table border="0" cellpadding="3" cellspacing="0" width="440">
	<tr>
	<td valign="top" bgcolor="navy" nowrap><font color="white" size="2"><b>Showing Information</b></font><br></td>
	<td valign="top" bgcolor="navy" align="right">
	<table border="0" cellspacing="1" cellpadding="2" bgcolor="white">
	<tr>
	<td valign="top" bgcolor="silver">
	Print Showing Report | Add Showing<br>
	</td>
	</tr>
	</table>
	</td>
	</tr>
	</table>
	<iframe src="transactions.idx?action=overview_showings&mlsnumber=$mlsnumber" width="440" height="150" noresize="noresize" scrolling ="yes" frameborder="0" marginwidth="0" marginheight="0"></iframe>
<br><b>Showing Instructions:</b> $showinginstructions<br><br>
</td>
</tr>
~;
        }
        print qq~
<tr>
<td valign="top" width="50%">
	<iframe src="transactions.idx?action=overview_mortgage&transid=$id&agent=$agent" width="220" height="160" noresize="noresize" scrolling ="no" frameborder="0" marginwidth="0" marginheight="0"></iframe>
</td>
<td valign="top" width="50%">
	<iframe src="transactions.idx?action=overview_titlework&transid=$id&agent=$agent" width="220" height="160" noresize="noresize" scrolling ="no" frameborder="0" marginwidth="0" marginheight="0"></iframe>
</td>
</tr>
<tr>
<td valign="top" width="50%">
	<iframe src="transactions.idx?action=overview_inspections&transid=$id" width="220" height="220" noresize="noresize" scrolling ="no" frameborder="0" marginwidth="0" marginheight="0"></iframe>
</td>
<td valign="top" width="50%">
	<iframe src="transactions.idx?action=overview_survey&transid=$id&agent=$agent" width="220" height="220" noresize="noresize" scrolling ="no" frameborder="0" marginwidth="0" marginheight="0"></iframe>
</td>
</tr>
</table>
</center>
</td>
</tr>
</table>

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

}

sub overview_tasks {

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

### ACTION PLANS ####

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

        #do the triggers

        my $asth =
          $dbh->prepare(
"select * from trans_boardtask_triggers where template_id = '$INPUT{template_id}' AND idlink = '$INPUT{idlink}' AND task_type = 'Transaction' LIMIT 0,1"
          );
        $asth->execute;
        while ( $data_ref = $asth->fetchrow_hashref() ) {
            %task_templates = %$data_ref;
            $temp_found     = "yes";
        }
        if ( $temp_found eq "yes" ) {

            print
qq~<font size="2" color="red"><b>CANNOT APPLY THIS TEMPLATE: This template was already applied and stopped!   If you plan to re-apply please delete completed template items first!~;

        }
        else {

            my $asth =
              $dbh->prepare(
"select listingdate,pendingdate from trans_board WHERE id = '$INPUT{idlink}'"
              );
            $asth->execute;
            while ( $data_ref = $asth->fetchrow_hashref() ) {
                %dates       = %$data_ref;
                $listingdate = "$dates{listingdate}";
                $pendingdate = "$dates{pendingdate}";

                if ( $INPUT{date_type} eq "Now" ) {
                    $usedate = "now()";
                }
                elsif ( $INPUT{date_type} eq "Listing" ) {
                    $usedate = "'$listingdate'";
                }
                elsif ( $INPUT{date_type} eq "Pending" ) {
                    $usedate = "'$pendingdate'";
                }

            }
            ### 1. SELECT DATA FROM AGENT TASK TEMPLATE
            my $asth =
              $dbh->prepare(
"select * from trans_boardtask_templates where id = '$INPUT{template_id}'"
              );
            $asth->execute;
            while ( $data_ref = $asth->fetchrow_hashref() ) {
                %task_templates = %$data_ref;

                ### 2. LOOP THROUGH agent_task_ids

                @agent_trigger_tasks =
                  split( /\,/, $task_templates{agent_task_ids} );
                foreach $agent_task_item (@agent_trigger_tasks) {

                    ### 3. OPEN THE DATA FOR EACH ITEM AND TRIGGER

                    my $bsth =
                      $dbh->prepare(
"select * from trans_boardtask_agents where id = '$agent_task_item'"
                      );
                    $bsth->execute;
                    while ( $data_ref = $bsth->fetchrow_hashref() ) {
                        %task_agents = %$data_ref;

                        ### 4. CALCULATE TRIGGER DATE

                        my $csth =
                          $dbh->prepare(
"SELECT DATE_FORMAT(DATE_ADD($usedate, INTERVAL $task_agents{num_days} DAY), '%Y-%m-%d')"
                          );
                        $csth->execute;
                        while ( ($tempdate) = $csth->fetchrow_array() ) {

                            ### 5. ENTER INTO TRIGGER DATABASE!
                            @variables = (
                                $INPUT{idlink},      $INPUT{template_id},
                                $Cook{agentid},      $task_agents{task_type},
                                $task_agents{title}, $task_agents{activity},
                                $task_agents{id},    $tempdate
                            );
                            $sql_query =
"INSERT INTO trans_boardtask_triggers values ('',?,?,?,?,?,?,?,?,'','','')";
                            my $dsth =
                              $dbh->do( $sql_query, undef, @variables );

                        }
                    }
                    $message_status =
"<font color=\"green\"><b>Successfully Applied $task_templates{template_name}!</b></font><br>";
                }
            }
        }
    }

    print qq~
<html>
<head>
<title>Action Plan Tasks Overview</title>
<link rel="stylesheet" TYPE="text/css" href="includes/style.css">
<script language="javscript">
var newwindow;
function poptastic(url)
{
	newwindow=window.open(url,'name','height=400,width=200');
	if (window.focus) {newwindow.focus()}
}
</script>
</head>
<body bgcolor="white" leftMargin="0" topMargin="0" marginwidth="0" marginheight="0">
~;

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

        my $asth =
          $dbh->prepare(
"select * from trans_boardtask_templates where agent_id = '$Cook{agentid}' AND task_type = '$INPUT{type}'"
          );
        $asth->execute;
        while ( $data_ref = $asth->fetchrow_hashref() ) {
            %task_templates = %$data_ref;
            $build_template_dropdowns .=
"<option value=\"$task_templates{id}\">$task_templates{template_name}</option>";
        }

        print qq~
<center>
<table border="0" cellpadding="3" cellspacing="1" width="100%">
<tr>
<form method="post" action="transactions.idx">
<input type="hidden" name="action" value="overview_tasks">
<input type="hidden" name="idlink" value="$INPUT{idlink}">
<input type="hidden" name="agent" value="$INPUT{agent}">
<input type="hidden" name="apply" value="yes">
<td valign="top" colspan="3" bgcolor="white">
<center><font size="3" face="Arial"><b>Apply The Following Action Plan For $INPUT{type}.</b></font><br>
<select name="template_id" class="form">
$build_template_dropdowns
</select><br>Start From <select name="date_type" class="form"><option value="Now">Today</option><option value="Listing">Listing Date</option><option value="Pending">Pending Date</option> <input type="submit" class="form" value="Apply Template Now">
</center>
</td>
</form>
</tr>
</table>
</center>
~;

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

        my $usrdasth =
          $dbh->prepare(
"select firstname,lastname from users where userid = '$Cook{userid}'"
          );
        $usrdasth->execute;
        while ( ( $afirstname, $alastname ) = $usrdasth->fetchrow_array() ) {
            $generateaddedby = "$afirstname $alastname";
        }
        @variables = ( $generateaddedby, $INPUT{id} );
        $sql_query =
"update trans_boardtask_triggers set date_completed = now(), completed_by = ? where id = ?";
        my $aasth = $dbh->do( $sql_query, undef, @variables );

        print qq~
<html>
<head>
<title>Making Changes to Datebase</title>
<meta http-equiv="Refresh" content="1; URL=transactions.idx?action=overview_tasks&idlink=$INPUT{idlink}&agent=$Cook{agentid}">
</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="transactions.idx?action=overview_tasks&idlink=$INPUT{idlink}&agent=$Cook{agentid}">Click Here</a>.</center>
</body>
</html>
~;
    }
    elsif ( $INPUT{do} eq "Notes" ) {

        my $basth =
          $dbh->prepare(
"select id,idlink,task_type,title,agent_task_id,DATE_FORMAT(date_trigger, '%b %D, %Y'),DATE_FORMAT(date_completed, '%b %D, %Y at %h\:%i%p'),completed_by,notes from trans_boardtask_triggers where id = '$INPUT{id}'"
          );
        $basth->execute;
        while (
            (
                $task_triggers_id,             $task_triggers_idlink,
                $task_triggers_task_type,      $task_triggers_title,
                $task_triggers_agent_task_id,  $task_triggers_date_trigger,
                $task_triggers_date_completed, $task_triggers_completed_by,
                $task_triggers_notes
            )
            = $basth->fetchrow_array()
          )
        {

            print qq~
<html>
<head>
<title></title>
</head>
<body bgcolor="white">
<form method="post" action="transactions.idx">
<input type="hidden" name="action" value="overview_tasks">
<input type="hidden" name="id" value="$INPUT{id}">
<input type="hidden" name="idlink" value="$INPUT{idlink}">
<input type="hidden" name="do" value="SaveNotes">
<b>$task_triggers_title</b><br>
Enter Notes Below:<br>
<textarea cols="70" rows="2" name="notes" class="form">$task_triggers_notes</textarea><br>
<input type="submit" value="Save / Edit Note">
</form>
</body>
</html>
~;
        }
    }
    elsif ( $INPUT{do} eq "SaveNotes" ) {
        @variables = ( $INPUT{notes}, $INPUT{id} );
        $sql_query =
          "update trans_boardtask_triggers set notes = ? where id = ?";
        my $aasth = $dbh->do( $sql_query, undef, @variables );

        print qq~
<html>
<head>
<title>Making Changes to Datebase</title>
<meta http-equiv="Refresh" content="1; URL=transactions.idx?action=overview_tasks&idlink=$INPUT{idlink}&agent=$Cook{agentid}">
</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="transactions.idx?action=overview_tasks&idlink=$INPUT{idlink}&agent=$Cook{agentid}">Click Here</a>.</center>
</body>
</html>
~;
    }
    elsif ( $INPUT{do} eq "Stop" ) {

        @variables = ( $INPUT{template_id} );
        $sql_query =
"DELETE FROM trans_boardtask_triggers WHERE template_id = '$INPUT{template_id}' AND date_completed = '0000-00-00 00:00:00'";
        my $aasth = $dbh->do( $sql_query, undef, @variables );

        print qq~
<html>
<head>
<title>Making Changes to Datebase</title>
<meta http-equiv="Refresh" content="1; URL=transactions.idx?action=overview_tasks&idlink=$INPUT{idlink}&agent=$Cook{agentid}">
</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="transactions.idx?action=overview_tasks&idlink=$INPUT{idlink}&agent=$Cook{agentid}">Click Here</a>.</center>
</body>
</html>
~;

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

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

        print qq~
<html>
<head>
<title>Making Changes to Datebase</title>
<meta http-equiv="Refresh" content="1; URL=transactions.idx?action=overview_tasks&idlink=$INPUT{idlink}&agent=$Cook{agentid}">
</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="transactions.idx?action=overview_tasks&idlink=$INPUT{idlink}&agent=$Cook{agentid}">Click Here</a>.</center>
</body>
</html>
~;
    }
    elsif ( $INPUT{do} eq "ActionLetter" ) {
        print qq~
<font size="4" face="Arial Black" color="Navy">Action Plan Letter Launcher</font>
~;
        if ( $INPUT{type} eq "Transaction" ) {

            my $countbaasth =
              $dbh->prepare(
"select count(contactid) from trans_boardtranstocontact WHERE transid = '$INPUT{idlink}'"
              );
            $countbaasth->execute;
            while ( ($tempcountnumber) = $countbaasth->fetchrow_array() ) {
                $contactcount = $tempcountnumber;
            }

            if ( $contactcount > 1 ) {
                print
qq~<br><font size="4" face="Arial Black" color="red">Multiple Contacts Found!</font>~;
            }
            print
qq~<br><b>Choose Which Contact(s) To Print Letter To Below:</b><br><br>
<SCRIPT language="JavaScript"> 
<!-- 
function closynoshowsme() 
{ 
window.opener='X'; 
window.open('','_parent',''); 
window.close();
} 
//--> 
</SCRIPT> 
~;

            if ( $contactcount eq 0 ) {
                print
qq~<br><font size="4" face="Arial Black" color="red">You Must Assign A Contact First!</font><br>~;
            }
            my $sbaasth =
              $dbh->prepare(
"select contactid,type from trans_boardtranstocontact WHERE transid = '$INPUT{idlink}' order by type DESC"
              );
            $sbaasth->execute;
            while ( ( $tempcontactid, $tempcontacttype ) =
                $sbaasth->fetchrow_array() )
            {

                my $sddasth =
                  $dbh->prepare(
"select id,agent,type,firstname,lastname,address,spouse,city,state,zip,phone1type,phone1number,phone2type,phone2number,phone3type,phone3number,faxnumber,email,emailtwo,notes from trans_boardcontact WHERE id = '$tempcontactid'"
                  );
                $sddasth->execute;
                while (
                    (
                        $s_contactid,    $s_agent,        $s_type,
                        $s_firstname,    $s_lastname,     $s_address,
                        $s_spouse,       $s_city,         $s_state,
                        $s_zip,          $s_phone1type,   $s_phone1number,
                        $s_phone2type,   $s_phone2number, $s_phone3type,
                        $s_phone3number, $s_faxnumber,    $s_email,
                        $s_emailtwo,     $s_notes
                    )
                    = $sddasth->fetchrow_array()
                  )
                {

                    if ( $s_spouse ne "" ) {
                        $s_spouse = " & $s_spouse ";
                    }
                    else {
                        $s_spouse = "";
                    }

                    print qq~
<form method="post" target="_blank" action="transactions.idx">
<input type="hidden" name="action" value="overview_tasks">
<input type="hidden" name="do" value="GenerateLetter">
<input type="hidden" name="type" value="Transaction">
<input type="hidden" name="agent_task_id" value="$INPUT{agent_task_id}">
<input type="hidden" name="idlink" value="$INPUT{idlink}">
<input type="hidden" name="contactid" value="$s_contactid">
<input type="submit" value="$tempcontacttype ( $s_firstname$s_spouse $s_lastname )" onClick="closynoshowsme();"> <input type="checkbox" name="LogAsSent" value="Yes" checked> <b>Log As Sent In Contact Database</b>
</form>
<br>
~;
                }
            }
        }
        elsif ( $INPUT{type} eq "Contact" || $INPUT{type} eq "Prospect" ) {

            if ( $INPUT{type} eq "Contact" ) { $sqlcp = "trans_boardcontact"; }
            if ( $INPUT{type} eq " Prospect" ) {
                $sqlcp = "trans_boardprospect";
            }

            my $sddasth =
              $dbh->prepare(
"select id,agent,type,firstname,lastname,address,spouse,city,state,zip,phone1type,phone1number,phone2type,phone2number,phone3type,phone3number,faxnumber,email,emailtwo,notes from $sqlcp WHERE id = '$INPUT{idlink}'"
              );
            $sddasth->execute;
            while (
                (
                    $s_contactid,    $s_agent,        $s_type,
                    $s_firstname,    $s_lastname,     $s_address,
                    $s_spouse,       $s_city,         $s_state,
                    $s_zip,          $s_phone1type,   $s_phone1number,
                    $s_phone2type,   $s_phone2number, $s_phone3type,
                    $s_phone3number, $s_faxnumber,    $s_email,
                    $s_emailtwo,     $s_notes
                )
                = $sddasth->fetchrow_array()
              )
            {

                if ( $s_spouse ne "" ) {
                    $s_spouse = " & $s_spouse ";
                }
                else {
                    $s_spouse = "";
                }

                print qq~
					<form method="get" target="_blank" action="transactions.idx">
					<input type="hidden" name="action" value="overview_tasks">
					<input type="hidden" name="do" value="GenerateLetter">
					<input type="hidden" name="type" value="Contact">
					<input type="hidden" name="agent_task_id" value="$INPUT{agent_task_id}">
					<input type="hidden" name="idlink" value="$INPUT{idlink}">
					<input type="hidden" name="contactid" value="$s_contactid">
					<input type="submit" value="$tempcontacttype ( $s_firstname$s_spouse $s_lastname )" onClick="closynoshowsme();"> <input type="checkbox" name="LogAsSent" value="Yes" checked> <b>Log As Sent In Contact Database</b>
					</form>
					<br>
					~;
            }
        }

    }
    elsif ( $INPUT{do} eq "GenerateLetter" ) {
        my $dasth = $dbh->prepare("select DATE_FORMAT(now(), '%M %D, %Y')");
        $dasth->execute;
        while ( ($gnow) = $dasth->fetchrow_array() ) {
            $good_date = $gnow;
        }

        my $basth =
          $dbh->prepare(
"select message from trans_boardtask_agents where id = '$INPUT{agent_task_id}'"
          );
        $basth->execute;
        while ( ($task_message) = $basth->fetchrow_array() ) {

            ### START CHANGES IF TRANSACTION

            if ( $INPUT{type} eq "Transaction" ) {
                my $uasth =
                  $dbh->prepare(
"select addressnumber,addressdirection,addressstreet,city,state,zip,listingdate,expiredate from trans_board where id = '$INPUT{idlink}'"
                  );
                $uasth->execute;
                while (
                    (
                        $listing_addressnumber, $listing_addressdirection,
                        $listing_addressstreet, $listing_city,
                        $listing_state,         $listing_zip,
                        $listing_listingdate,   $listing_expiredate
                    )
                    = $uasth->fetchrow_array()
                  )
                {

                    $show_propertyaddress =
"$listing_addressnumber $listing_addressdirection $listing_addressstreet, $listing_city";

                    my $sbaasth =
                      $dbh->prepare(
"select contactid from trans_boardtranstocontact WHERE contactid = '$INPUT{contactid}' AND transid = '$INPUT{idlink}' AND type = 'Seller'"
                      );
                    $sbaasth->execute;
                    while ( ($tempcontactid) = $sbaasth->fetchrow_array() ) {
                        my $sddasth =
                          $dbh->prepare(
"select id,agent,type,firstname,lastname,address,spouse,city,state,zip,phone1type,phone1number,phone2type,phone2number,phone3type,phone3number,faxnumber,email,emailtwo,notes from trans_boardcontact WHERE id = '$tempcontactid'"
                          );
                        $sddasth->execute;
                        while (
                            (
                                $s_contactid,  $s_agent,
                                $s_type,       $s_firstname,
                                $s_lastname,   $s_address,
                                $s_spouse,     $s_city,
                                $s_state,      $s_zip,
                                $s_phone1type, $s_phone1number,
                                $s_phone2type, $s_phone2number,
                                $s_phone3type, $s_phone3number,
                                $s_faxnumber,  $s_email,
                                $s_emailtwo,   $s_notes
                            )
                            = $sddasth->fetchrow_array()
                          )
                        {

                            if ( $s_spouse ne "" ) {
                                $s_spouse = " & $s_spouse ";
                            }
                            else {
                                $s_spouse = "";
                            }

                            $seller_fullname =
                              "$s_firstname$s_spouse $s_lastname";
                            $seller_address =
                              "$s_address<br>$s_city, $s_state $s_zip";
                        }
                    }

                    my $baasth =
                      $dbh->prepare(
"select contactid from trans_boardtranstocontact WHERE contactid = '$INPUT{contactid}' AND transid = '$INPUT{idlink}' AND type = 'Buyer'"
                      );
                    $baasth->execute;
                    while ( ($tempcontactid) = $baasth->fetchrow_array() ) {

                        my $bddasth =
                          $dbh->prepare(
"select id,agent,type,firstname,lastname,address,spouse,city,state,zip,phone1type,phone1number,phone2type,phone2number,phone3type,phone3number,faxnumber,email,emailtwo,notes from trans_boardcontact WHERE id = '$tempcontactid'"
                          );
                        $bddasth->execute;
                        while (
                            (
                                $b_contactid,  $b_agent,
                                $b_type,       $b_firstname,
                                $b_lastname,   $b_address,
                                $b_spouse,     $b_city,
                                $b_state,      $b_zip,
                                $b_phone1type, $b_phone1number,
                                $b_phone2type, $b_phone2number,
                                $b_phone3type, $b_phone3number,
                                $b_faxnumber,  $b_email,
                                $b_emailtwo,   $b_notes
                            )
                            = $bddasth->fetchrow_array()
                          )
                        {

                            if ( $b_spouse ne "" ) {
                                $b_spouse = " & $b_spouse ";
                            }
                            else {
                                $b_spouse = "";
                            }

                            $buyer_fullname =
                              "$b_firstname$b_spouse $b_lastname";
                            $buyer_address =
                              "$b_address<br>$b_city, $b_state $b_zip";
                        }
                    }

                    ### DO THE CHANGES TO THE LETTER
                    $task_message =~ s/\$change_date/$good_date/g;
                    $task_message =~
                      s/\$change_propertyaddress/$show_propertyaddress/g;
                    $task_message =~
                      s/\$change_sellerfullname/$seller_fullname/g;
                    $task_message =~ s/\$change_selleraddress/$seller_address/g;
                    $task_message =~ s/\$change_buyerfullname/$buyer_fullname/g;
                    $task_message =~ s/\$change_buyeraddress/$buyer_address/g;
                }
            }
            elsif ( $INPUT{type} eq "Contact" ) {

                ### START CHANGES IF CONTACT

                my $sddasth =
                  $dbh->prepare(
"select id,agent,type,firstname,lastname,address,spouse,city,state,zip,phone1type,phone1number,phone2type,phone2number,phone3type,phone3number,faxnumber,email,emailtwo,notes from trans_boardcontact WHERE id = '$INPUT{contactid}'"
                  );
                $sddasth->execute;
                while (
                    (
                        $s_contactid,    $s_agent,        $s_type,
                        $s_firstname,    $s_lastname,     $s_address,
                        $s_spouse,       $s_city,         $s_state,
                        $s_zip,          $s_phone1type,   $s_phone1number,
                        $s_phone2type,   $s_phone2number, $s_phone3type,
                        $s_phone3number, $s_faxnumber,    $s_email,
                        $s_emailtwo,     $s_notes
                    )
                    = $sddasth->fetchrow_array()
                  )
                {

                    if ( $s_spouse ne "" ) {
                        $s_spouse = " & $s_spouse ";
                    }
                    else {
                        $s_spouse = "";
                    }

                    $contact_fullname = "$s_firstname$s_spouse $s_lastname";
                    $contact_address = "$s_address<br>$s_city, $s_state $s_zip";
                }

                ### DO THE CHANGES TO THE LETTER
                $task_message =~ s/\$change_date/$good_date/g;
                $task_message =~ s/\$change_fullname/$contact_fullname/g;
                $task_message =~ s/\$change_address/$contact_address/g;

            }

            print qq~
<style>
	td	{ font-family: Arial; font-size: 16px; color: #000000; text-decoration: none; line-height:21px; }
	table	{ font-family: Arial; font-size: 16px; color: #000000; text-decoration: none; line-height:21px; }
	body 	{ font-family: Arial; font-size: 16px; color: #000000; text-decoration: none; line-height:21px; background-image: url('images/eagle_letterhead.jpg'); background-repeat: no-repeat;}
</style>
<script>
function printpr()
{
var OLECMDID = 7;
/* OLECMDID values:
* 6 - print
* 7 - print preview
* 1 - open window
* 4 - Save As
*/

var PROMPT = 1; // 2 DONTPROMPTUSER
var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser);

WebBrowser1.ExecWB(OLECMDID, PROMPT);
WebBrowser1.outerHTML = "";
}
</script>
<SCRIPT language="JavaScript"> 
<!-- 
function closynoshowsme() 
{ 
window.opener='X'; 
window.open('','_parent',''); 
window.close();
} 
//--> 
</SCRIPT> 
<center>
<table border="0" cellpadding="33" cellspacing="0" width="100%">
<tr>
<td valign="top" width="100%">
				$task_message
</td>
</tr>
</table>
<script language="JavaScript" type="text/javascript">
<!--
printpr();

// -->
</script>
			~;

        }
    }

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

        my $countbaasth =
          $dbh->prepare(
"select count(contactid) from trans_boardtranstocontact WHERE transid = '$INPUT{idlink}'"
          );
        $countbaasth->execute;
        while ( ($tempcountnumber) = $countbaasth->fetchrow_array() ) {
            $contactcount = $tempcountnumber;
        }
        print qq~
<font size="4" face="Arial Black" color="Navy">Action Plan E-Mail Launcher</font>
<SCRIPT language="JavaScript"> 
<!-- 
function closynoshowsme() 
{ 
window.opener='X'; 
window.open('','_parent',''); 
window.close();
} 
//--> 
</SCRIPT> 
~;

        if ( $contactcount > 1 ) {
            print
qq~<br><font size="4" face="Arial Black" color="red">Multiple Contacts Found!</font>~;
        }
        print
qq~<br><b>Choose Which Contact(s) To E-Mail Message To Below:</b><br><br>
<ul>~;

        if ( $contactcount eq 0 ) {
            print
qq~<br><font size="4" face="Arial Black" color="red">You Must Assign A Contact First!</font><br>~;
        }
        my $sbaasth =
          $dbh->prepare(
"select contactid,type from trans_boardtranstocontact WHERE transid = '$INPUT{idlink}' order by type DESC"
          );
        $sbaasth->execute;
        while ( ( $tempcontactid, $tempcontacttype ) =
            $sbaasth->fetchrow_array() )
        {

            my $sddasth =
              $dbh->prepare(
"select id,agent,type,firstname,lastname,address,spouse,city,state,zip,phone1type,phone1number,phone2type,phone2number,phone3type,phone3number,faxnumber,email,emailtwo,notes from trans_boardcontact WHERE id = '$tempcontactid'"
              );
            $sddasth->execute;
            while (
                (
                    $s_contactid,    $s_agent,        $s_type,
                    $s_firstname,    $s_lastname,     $s_address,
                    $s_spouse,       $s_city,         $s_state,
                    $s_zip,          $s_phone1type,   $s_phone1number,
                    $s_phone2type,   $s_phone2number, $s_phone3type,
                    $s_phone3number, $s_faxnumber,    $s_email,
                    $s_emailtwo,     $s_notes
                )
                = $sddasth->fetchrow_array()
              )
            {

                if ( $s_spouse ne "" ) {
                    $s_spouse = " & $s_spouse ";
                }
                else {
                    $s_spouse = "";
                }

                print qq~
<form method="post" target="_blank" action="transactions.idx">
<input type="hidden" name="action" value="overview_tasks">
<input type="hidden" name="do" value="GenerateEMail">
<input type="hidden" name="agent_task_id" value="$INPUT{agent_task_id}">
<input type="hidden" name="idlink" value="$INPUT{idlink}">
<input type="hidden" name="contactid" value="$s_contactid">
<input type="submit" value="$tempcontacttype ( $s_firstname$s_spouse $s_lastname )" onClick="closynoshowsme();">
</form>
<br>
~;

            }
        }

    }
    elsif ( $INPUT{do} eq "GenerateEMail" ) {
        my $dasth = $dbh->prepare("select DATE_FORMAT(now(), '%M %D, %Y')");
        $dasth->execute;
        while ( ($gnow) = $dasth->fetchrow_array() ) {
            $good_date = $gnow;
        }

        my $basth =
          $dbh->prepare(
"select task_type,category,title,message from trans_boardtask_agents where id = '$INPUT{agent_task_id}'"
          );
        $basth->execute;
        while (
            (
                $default_task_type, $default_category,
                $default_title,     $task_message
            )
            = $basth->fetchrow_array()
          )
        {
            my $uasth =
              $dbh->prepare(
"select addressnumber,addressdirection,addressstreet,city,state,zip,listingdate,expiredate from trans_board where id = '$INPUT{idlink}'"
              );
            $uasth->execute;
            while (
                (
                    $listing_addressnumber, $listing_addressdirection,
                    $listing_addressstreet, $listing_city,
                    $listing_state,         $listing_zip,
                    $listing_listingdate,   $listing_expiredate
                )
                = $uasth->fetchrow_array()
              )
            {

                $show_propertyaddress =
"$listing_addressnumber $listing_addressdirection $listing_addressstreet, $listing_city";

                my $sbaasth =
                  $dbh->prepare(
"select contactid from trans_boardtranstocontact WHERE contactid = '$INPUT{contactid}' AND transid = '$INPUT{idlink}' AND type = 'Seller'"
                  );
                $sbaasth->execute;
                while ( ($tempcontactid) = $sbaasth->fetchrow_array() ) {
                    my $sddasth =
                      $dbh->prepare(
"select id,agent,type,firstname,lastname,address,spouse,city,state,zip,phone1type,phone1number,phone2type,phone2number,phone3type,phone3number,faxnumber,email,emailtwo,notes from trans_boardcontact WHERE id = '$tempcontactid'"
                      );
                    $sddasth->execute;
                    while (
                        (
                            $s_contactid,    $s_agent,        $s_type,
                            $s_firstname,    $s_lastname,     $s_address,
                            $s_spouse,       $s_city,         $s_state,
                            $s_zip,          $s_phone1type,   $s_phone1number,
                            $s_phone2type,   $s_phone2number, $s_phone3type,
                            $s_phone3number, $s_faxnumber,    $s_email,
                            $s_emailtwo,     $s_notes
                        )
                        = $sddasth->fetchrow_array()
                      )
                    {

                        if ( $s_spouse ne "" ) {
                            $s_spouse = " & $s_spouse ";
                        }
                        else {
                            $s_spouse = "";
                        }
                        $seller_email    = "$s_email";
                        $seller_email2   = "$s_emailtwo";
                        $seller_fullname = "$s_firstname$s_spouse $s_lastname";
                        $seller_address =
                          "$s_address<br>$s_city, $s_state $s_zip";
                    }
                }

                my $baasth =
                  $dbh->prepare(
"select contactid from trans_boardtranstocontact WHERE contactid = '$INPUT{contactid}' AND transid = '$INPUT{idlink}' AND type = 'Buyer'"
                  );
                $baasth->execute;
                while ( ($tempcontactid) = $baasth->fetchrow_array() ) {

                    my $bddasth =
                      $dbh->prepare(
"select id,agent,type,firstname,lastname,address,spouse,city,state,zip,phone1type,phone1number,phone2type,phone2number,phone3type,phone3number,faxnumber,email,emailtwo,notes from trans_boardcontact WHERE id = '$tempcontactid'"
                      );
                    $bddasth->execute;
                    while (
                        (
                            $b_contactid,    $b_agent,        $b_type,
                            $b_firstname,    $b_lastname,     $b_address,
                            $b_spouse,       $b_city,         $b_state,
                            $b_zip,          $b_phone1type,   $b_phone1number,
                            $b_phone2type,   $b_phone2number, $b_phone3type,
                            $b_phone3number, $b_faxnumber,    $b_email,
                            $b_emailtwo,     $b_notes
                        )
                        = $bddasth->fetchrow_array()
                      )
                    {

                        if ( $b_spouse ne "" ) {
                            $b_spouse = " & $b_spouse ";
                        }
                        else {
                            $b_spouse = "";
                        }
                        $buyer_email    = "$b_email";
                        $buyer_email2   = "$b_emailtwo";
                        $buyer_fullname = "$b_firstname$b_spouse $b_lastname";
                        $buyer_address =
                          "$b_address<br>$b_city, $b_state $b_zip";
                    }
                }

                ### DO THE CHANGES TO THE MESSAGE
                $task_message =~ s/\$change_date/$good_date/g;
                $task_message =~
                  s/\$change_propertyaddress/$show_propertyaddress/g;
                $task_message =~ s/\$change_sellerfullname/$seller_fullname/g;
                $task_message =~ s/\$change_selleraddress/$seller_address/g;
                $task_message =~ s/\$change_buyerfullname/$buyer_fullname/g;
                $task_message =~ s/\$change_buyeraddress/$buyer_address/g;

                if ( $seller_email2 ne "" || $buyer_email2 ne "" ) {
                    $check_emailtwo = qq~
		<b>To: Other Email</b><br>
		<input type="text" name="emailtotwo" size="85" value="$buyer_email2$seller_email2"><br>
	~;
                }

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

                print qq~
<style>
	td	{ font-family: Arial; font-size: 16px; color: #000000; text-decoration: none; line-height:21px; }
	table	{ font-family: Arial; font-size: 16px; color: #000000; text-decoration: none; line-height:21px; }
	body 	{ font-family: Arial; font-size: 16px; color: #000000; text-decoration: none; line-height:21px; background-image: url('images/eagle_letterhead.jpg'); background-repeat: no-repeat;}
</style>
<script language="Javascript1.2"><!-- // load htmlarea
	_editor_url = "/htmlarea/";                     // URL to htmlarea files
	var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
	if (navigator.userAgent.indexOf('Mac')        >= 0) { win_ie_ver = 0; }
	if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
	if (navigator.userAgent.indexOf('Opera')      >= 0) { win_ie_ver = 0; }
	if (win_ie_ver >= 5.5) {
	 document.write('<scr' + 'ipt src="' +_editor_url+ 'editor.js"');
	 document.write(' language="Javascript1.2"></scr' + 'ipt>');  
	} else { document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); }
	// --></script>

			<script language="JavaScript1.2" defer>
			editor_generate('message');
			</script>
<center>
<table border="0" cellpadding="33" cellspacing="0" width="100%">
<tr>
<td valign="top" width="100%">
<br><br><br>
<font size="4" face="Arial Black">Compose New E-Mail Message For:</font><br>
<font size="4">$buyer_fullname$seller_fullname ($buyer_email$seller_email $buyer_email2$seller_email2)</font><br>
<form method="post" action="transactions.idx">
<input type="hidden" name="action" value="overview_tasks">
<input type="hidden" name="do" value="SendEMail">
<input type="hidden" name="agent_task_id" value="$INPUT{agent_task_id}">
<input type="hidden" name="idlink" value="$INPUT{idlink}">
<input type="hidden" name="contactid" value="$INPUT{contactid}">
<input type="submit" value="Send E-Mail Now!"><br><br>
<b>From:</b><br>
<select name="emailfrom">
$print_fromemail
</select> <input type="checkbox" value="yes" name="copyself" checked> <b>Copy Myself</b><br>
<b>To:</b><br>
<input type="text" name="emailto" size="85" value="$buyer_email$seller_email"><br>
$check_emailtwo
<b>Subject:</b><br>
<input type="text" name="subject" size="85" value="$default_title: $show_propertyaddress"><br>
<b>Message:</b><br>
<textarea rows="30" name="message" cols="85">$task_message</textarea><br>
</form>
</td>
</tr>
</table>
			~;

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

        open( MAIL, "|/usr/sbin/sendmail -t" );
        print MAIL "To: $INPUT{emailto}\n";
        unless ( $INPUT{emailtotwo} eq "" ) {
            print MAIL "To: $INPUT{emailtotwo}\n";
        }
        if ( $INPUT{copyself} eq "yes" ) {
            print MAIL "CC: $INPUT{emailfrom}\n";
        }
        print MAIL "From: $INPUT{emailfrom}\n";
        print MAIL "Subject: $INPUT{subject}\n";
        print MAIL "Content-type: text/html\n\n";
        print MAIL qq~
					<html>
					<head>
					<title>Eagle Real Estate, Inc. Email From $agent_name</title>
					<link rel="stylesheet" TYPE="text/css" href="http://www.munciemls.com/includes/style.css">
					</head>
					<body bgcolor="white" leftMargin="0" topMargin="0" marginwidth="0" marginheight="0">
					<br><br>
					<center>
					<table border="0" cellspacing="0" cellpadding="0" width="600">
					<tr>
					<td valign="top" width="600">
					<img src="http://www.munciemls.com/images/emailheader.gif"><br>
					<table border="0" cellspacing="0" cellpadding="15" width="100%">
					<tr>
					<td valign="top" width="100%">
					$INPUT{message}<br><br><br>
					<img src="http://www.munciemls.com/images/emailfooter.gif"><br><br><br>
					</td>
					</tr>
					</table>
					</center>
					</body>
					</html>
					~;
        close(MAIL);

        print
qq~<br><br><br><center><font size="4" color="red">E-Mail Successfully Sent!<br><a href="javascript:self.close()" class="closelink">Close Window Now</a></font></center>~;

    }
    else {

### 2. FIND TASKS DUE TODAY OR OVERDUE!

        my $ssth =
          $dbh->prepare(
"select id,idlink,template_id from trans_boardtask_triggers where idlink = '$INPUT{idlink}' group by template_id order by id DESC"
          );
        $ssth->execute;
        while (
            (
                $stask_triggers_id, $stask_triggers_idlink,
                $stask_triggers_template_id
            )
            = $ssth->fetchrow_array()
          )
        {

            my $tsth =
              $dbh->prepare(
"select id,template_name from trans_boardtask_templates where id = '$stask_triggers_template_id'"
              );
            $tsth->execute;
            while ( ( $stask_template_id, $stask_template_name ) =
                $tsth->fetchrow_array() )
            {
                $display_task_list .=
qq~<tr><td valign="top" bgcolor="#ffffcc" colspan="3"><font color="green" size="2"><b>Action Plan: $stask_template_name</b></font></td><td valign="top" bgcolor="#ffffcc" align="center"><a class="action_plan" href="transactions.idx?action=overview_tasks&idlink=$stask_triggers_idlink&template_id=$stask_template_id&agent=$Cook{agentid}&do=Stop"><img src="images/trans_sys/icons/restrict-page-red.gif" alt="Stop Action Plan" border="0"></a>  <a class="action_plan" href="transactions.idx?action=overview_tasks&idlink=$stask_triggers_idlink&template_id=$stask_template_id&agent=$Cook{agentid}&do=Delete"><img src="images/trans_sys/icons/delete-page-red.gif" border="0" alt="Delete Action Plan"></a></td></tr>~;
            }

            my $basth =
              $dbh->prepare(
"select id,idlink,task_type,title,activity,agent_task_id,DATE_FORMAT(date_trigger, '%b %D, %Y'),notes from trans_boardtask_triggers where idlink = '$INPUT{idlink}' AND template_id = '$stask_triggers_template_id' AND date_trigger <= now() AND date_completed = '0000-00-00 00:00:00' order by date_trigger ASC"
              );
            $basth->execute;
            while (
                (
                    $task_triggers_id,           $task_triggers_idlink,
                    $task_triggers_task_type,    $task_triggers_title,
                    $task_triggers_activity,     $task_triggers_agent_task_id,
                    $task_triggers_date_trigger, $task_triggers_notes
                )
                = $basth->fetchrow_array()
              )
            {
                unless ( $task_triggers_notes eq "" ) {
                    $display_note = "<br>(Note: $task_triggers_notes)";
                }

                if ( $task_triggers_activity eq "Letter" ) {
                    $task_triggers_activityl =
"<br><a target=\"_blank\" href=\"transactions.idx?action=overview_tasks&do=ActionLetter&type=$task_triggers_task_type&agent_task_id=$task_triggers_agent_task_id&idlink=$task_triggers_idlink\">[ Print Letter ]</a>";
                }
                elsif ( $task_triggers_activity eq "E-Mail" ) {
                    $task_triggers_activityl =
"<br><a target=\"_blank\" href=\"transactions.idx?action=overview_tasks&do=ActionEMail&type=$task_triggers_task_type&agent_task_id=$task_triggers_agent_task_id&idlink=$task_triggers_idlink\">[ Send E-Mail ]</a>";
                }
                else {
                    $task_triggers_activityl = "";
                }

                $display_task_list .= qq~
				<tr>
				<td valign="top" bgcolor="#ffcccc" align="center"><b>$task_triggers_activity</b></td>
				<td valign="top" bgcolor="#ffcccc"><b>$task_triggers_title</b>$task_triggers_activityl$display_note</td>
				<td valign="top" bgcolor="#ffcccc" nowrap><b>$task_triggers_date_trigger</b></td>
				<td valign="top" bgcolor="#ffcccc" align="center"><a class="action_plan" href="transactions.idx?action=overview_tasks&id=$task_triggers_id&idlink=$INPUT{idlink}&do=MarkDone"><img src="images/trans_sys/icons/edit-page-green.gif" border="0" alt="Mark as Completed"></a>  <a href="transactions.idx?action=overview_tasks&id=$task_triggers_id&idlink=$INPUT{idlink}&do=Notes"><img src="images/trans_sys/icons/add-comment-green.gif" border="0" alt="Enter Notes"></a></td>
				</tr>
			~;
                $task_triggers_activityl = "";
                $display_note            = "";
                $found                   = "yes";
            }

            my $basth =
              $dbh->prepare(
"select id,idlink,task_type,title,activity,agent_task_id,DATE_FORMAT(date_trigger, '%b %D, %Y'),notes from trans_boardtask_triggers where idlink = '$INPUT{idlink}' AND template_id = '$stask_triggers_template_id' AND date_trigger > now() AND date_completed = '0000-00-00 00:00:00' order by date_trigger ASC"
              );
            $basth->execute;
            while (
                (
                    $task_triggers_id,           $task_triggers_idlink,
                    $task_triggers_task_type,    $task_triggers_title,
                    $task_triggers_activity,     $task_triggers_agent_task_id,
                    $task_triggers_date_trigger, $task_triggers_notes
                )
                = $basth->fetchrow_array()
              )
            {
                unless ( $task_triggers_notes eq "" ) {
                    $display_note = "<br>(Note: $task_triggers_notes)";
                }

                if ( $task_triggers_activity eq "Letter" ) {
                    $task_triggers_activityl =
"<br><a target=\"_blank\" href=\"transactions.idx?action=overview_tasks&do=ActionLetter&type=$task_triggers_task_type&agent_task_id=$task_triggers_agent_task_id&idlink=$task_triggers_idlink\">[ Print Letter ]</a>";
                }
                elsif ( $task_triggers_activity eq "E-Mail" ) {
                    $task_triggers_activityl =
"<br><a target=\"_blank\" href=\"transactions.idx?action=overview_tasks&do=ActionEMail&type=$task_triggers_task_type&agent_task_id=$task_triggers_agent_task_id&idlink=$task_triggers_idlink\">[ Send E-Mail ]</a>";
                }
                else {
                    $task_triggers_activityl = "";
                }

                $display_task_list .= qq~
			<tr>
			<td valign="middle" bgcolor="#ccffcc" align="center"><b>$task_triggers_activity</b></td>
			<td valign="middle" bgcolor="#ccffcc"><b>$task_triggers_title</b>$task_triggers_activityl$display_note</td>
			<td valign="middle" bgcolor="#ccffcc" nowrap><b>$task_triggers_date_trigger</b></td>
			<td valign="middle" bgcolor="#ccffcc" align="center"><a class="action_plan" href="transactions.idx?action=overview_tasks&id=$task_triggers_id&idlink=$INPUT{idlink}&do=MarkDone"><img src="images/trans_sys/icons/edit-page-green.gif" border="0" alt="Mark as Completed"></a>  <a href="transactions.idx?action=overview_tasks&id=$task_triggers_id&idlink=$INPUT{idlink}&do=Notes"><img src="images/trans_sys/icons/add-comment-green.gif" border="0" alt="Enter Notes"></a></td>
			</tr>
		~;
                $task_triggers_activityl = "";
                $display_note            = "";
                $found                   = "yes";
            }

            my $basth =
              $dbh->prepare(
"select id,idlink,task_type,title,activity,agent_task_id,DATE_FORMAT(date_trigger, '%b %D, %Y'),DATE_FORMAT(date_completed, '%b %D, %Y at %h\:%i%p'),completed_by,notes from trans_boardtask_triggers where idlink = '$INPUT{idlink}' AND template_id = '$stask_triggers_template_id' AND date_completed != '0000-00-00 00:00:00' order by date_trigger ASC"
              );
            $basth->execute;
            while (
                (
                    $task_triggers_id,
                    $task_triggers_idlink,
                    $task_triggers_task_type,
                    $task_triggers_title,
                    $task_triggers_activity,
                    $task_triggers_agent_task_id,
                    $task_triggers_date_trigger,
                    $task_triggers_date_completed,
                    $task_triggers_completed_by,
                    $task_triggers_notes
                )
                = $basth->fetchrow_array()
              )
            {
                unless ( $task_triggers_notes eq "" ) {
                    $display_note = "<br>(Note: $task_triggers_notes)";
                }

                if ( $task_triggers_activity eq "Letter" ) {
                    $task_triggers_activityl =
"<br><a target=\"_blank\" href=\"transactions.idx?action=overview_tasks&do=ActionLetter&type=$task_triggers_task_type&agent_task_id=$task_triggers_agent_task_id&idlink=$task_triggers_idlink\">[ Print Letter ]</a>";
                }
                elsif ( $task_triggers_activity eq "E-Mail" ) {
                    $task_triggers_activityl =
"<br><a target=\"_blank\" href=\"transactions.idx?action=overview_tasks&do=ActionEMail&type=$task_triggers_task_type&agent_task_id=$task_triggers_agent_task_id&idlink=$task_triggers_idlink\">[ Send E-Mail ]</a>";
                }
                else {
                    $task_triggers_activityl = "";
                }

                $display_task_list .= qq~
			<tr>
			<td valign="middle" bgcolor="#99ccff" align="center"><b>$task_triggers_activity</b></td>
			<td valign="middle" bgcolor="#99ccff"><b>$task_triggers_title</b>$task_triggers_activityl$display_note<br><i>Completed $task_triggers_date_completed By $task_triggers_completed_by</i></td>
			<td valign="middle" bgcolor="#99ccff" nowrap><b>$task_triggers_date_trigger</b></td>
			<td valign="middle" bgcolor="#99ccff" align="center"><a href="transactions.idx?action=overview_tasks&id=$task_triggers_id&idlink=$INPUT{idlink}&do=Notes"><img src="images/trans_sys/icons/add-comment-green.gif" border="0" alt="Enter Notes"></a></td>
			</tr>
		~;
                $task_triggers_activityl = "";
                $display_note            = "";
                $found                   = "yes";
            }

        }    ## END MAIN TASK CHECKER

        print qq~
$message_status
<table border="0" cellpadding="1" cellspacing="1" width="100%">
<tr>
<td valign="top" bgcolor="navy"><font color="white"><b>Activity</b></font></td>
<td valign="top" bgcolor="navy"><font color="white"><b>Description</b></font></td>
<td valign="top" bgcolor="navy"><font color="white"><b>Due Date</b></font></td>
<td valign="top" bgcolor="navy" align="center"><font color="white"><b>Actions</b></font></td>
</tr>
~;
        unless ( $found eq "yes" ) {
            print qq~
<tr><td colspan="4" align="center"><br><font color="red" size="3">You Have Not Setup Any Action Plans!</font><br><b>Click the <u>Apply Plan</u> Link Above To Apply Template!</b></td></tr>~;
        }
        else {
            print qq~
$display_task_list
~;
        }
        print qq~
</table>
~;
    }

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

}

sub overview_showings {

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

#showingid,mlsnumber,status,enteredby,showingagent,appointmentdate,timerange1,timerange2,confirmeddatetime,confirmedwith,feedback
    print qq~
<html>
<head>
<title>Showing Information in Overview</title>
<link rel="stylesheet" TYPE="text/css" href="includes/style.css">
</head>
<body bgcolor="white" leftMargin="0" topMargin="0" marginwidth="0" marginheight="0">
~;

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

        my $aasth =
          $dbh->prepare(
"select showingid,mlsnumber,status,enteredby,showingagent,appointmentdate,timerange1,timerange2,confirmeddatetime,confirmedwith from trans_boardshowings where showingid = '$INPUT{showingid}'"
          );
        $aasth->execute;
        while (
            (
                $showingid,  $mlsnumber,    $status,
                $enteredby,  $showingagent, $appointmentdate,
                $timerange1, $timerange2,   $confirmeddatetime,
                $confirmedwith
            )
            = $aasth->fetchrow_array()
          )
        {

            print qq~
<a href="transactions.idx?action=overview_showings&mlsnumber=$INPUT{mlsnumber}">Return To Showing List</a><br>
<table border="0" cellpadding="3" cellspacing="0" width="100%">
<tr>
<td valign="top" bgcolor="#CCCCFF" width="100%" colspan="2">
<b>Entered By</b> $enteredby <b>Date</b> $appointmentdate  <b>Showing Time</b> $timerange1 - $timerange2<br>
</td>
</tr>
<tr>
<td valign="top" width="35%">
<b>Status</b> $status<br>
<b>Confirmed</b><br>$confirmeddatetime<br>
<b>With</b> $confirmedwith<br>
<b>Agent</b>
~;
            my $baasth =
              $dbh->prepare(
"select firstname,lastname,agent1phone from trans_boarddirectory where id = '$showingagent'"
              );
            $baasth->execute;
            while (
                (
                    $firstname,  $lastname,    $agent1type, $agent1phone,
                    $agent2type, $agent2phone, $agent3type, $agent3phone
                )
                = $baasth->fetchrow_array()
              )
            {
                $sagent = "$firstname $lastname";
                print qq~
	$firstname $lastname<br>$agent1type $agent1phone<br>$agent2type $agent2phone<br>$agent3type $agent3phone<br>
	~;
            }

            print qq~
<br>
</td>
<td valign="top" width="65%">
<b>Feedback from $sagent:</b><br>
~;
            my $gasth =
              $dbh->prepare(
"SELECT comments FROM trans_boardfeedback WHERE sid = '$showingid'"
              );
            $gasth->execute;
            while ( ($thecomments) = $gasth->fetchrow_array() ) {
                $iffound = "yes";
                print qq~
		$thecomments
		~;
            }
            unless ( $iffound eq "yes" ) {
                print qq~
		<font color="red">No Feedback Received!</font>
		~;
            }

            print qq~
<br>
<b>All Comments:</b><br>
~;
            my $gasth =
              $dbh->prepare(
"SELECT comments FROM trans_boardfeedback WHERE mlsnumber = '$mlsnumber' order by dateentered DESC"
              );
            $gasth->execute;
            while ( ($thecomments) = $gasth->fetchrow_array() ) {
                $affound = "yes";
                print qq~
				+ $thecomments<hr color="navy" height="1" width="100%">
			~;
            }
            unless ( $affound eq "yes" ) {
                print qq~
		<font color="red">No Feedback Received!</font>
		~;
            }

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

        }
    }
    else {
        print qq~
<table border="0" cellpadding="3" cellspacing="1" width="100%">
<tr bgcolor="#CCCCFF">
<td valign="top"><b>Status</b></td>
<td valign="top"><b>Date</b></td>
<td valign="top"><b>Time Range</b></td>
<td valign="top"><b>Agent</b></td>
<td valign="top"><b>Feedback</b></td>
<td valign="top" bgcolor="silver"><b>Actions</b></td>
</tr>
~;

        my $aasth =
          $dbh->prepare(
"select showingid,mlsnumber,status,enteredby,showingagent,appointmentdate,timerange1,timerange2,confirmeddatetime,confirmedwith from trans_boardshowings where mlsnumber = '$INPUT{mlsnumber}' order by appointmentdate desc"
          );
        $aasth->execute;

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

        while (
            (
                $showingid,  $mlsnumber,    $status,
                $enteredby,  $showingagent, $appointmentdate,
                $timerange1, $timerange2,   $confirmeddatetime,
                $confirmedwith
            )
            = $aasth->fetchrow_array()
          )
        {

            my $feedasth =
              $dbh->prepare(
"select sid,comments from trans_boardfeedback where sid = '$showingid'"
              );
            $feedasth->execute;
            while ( ( $showing_sid, $showing_comments ) =
                $feedasth->fetchrow_array() )
            {
                $checkfeedback = "yes";
            }

            if ( $checkfeedback eq "yes" ) {
                $feedback = "Yes";
            }
            else {
                $feedback = "No";
            }

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

            print qq~
<tr bgcolor="$setcolor">
<td valign="top">$status</td>
<td valign="top">$appointmentdate</td>
<td valign="top">$timerange1 - $timerange2</td>
<td valign="top">
~;
            my $baasth =
              $dbh->prepare(
"select firstname,lastname from trans_boarddirectory where id = '$showingagent'"
              );
            $baasth->execute;
            while ( ( $firstname, $lastname ) = $baasth->fetchrow_array() ) {
                $firstname = substr( $firstname, 0, 1 );
                $lastname  = substr( $lastname,  0, 5 );
                print qq~
	$firstname.$lastname
	~;
            }
            print qq~
</td>
<td valign="top">$feedback</td>
<td valign="top"><a href="transactions.idx?action=overview_showings&do=showdetails&showingid=$showingid&mlsnumber=$mlsnumber">View</a></td>
</tr>
~;
            $found         = "yes";
            $checkfeedback = "no";
        }

        unless ( $found eq "yes" ) {
            print qq~
<tr>
<td colspan="6">
<font color="red"><b>No Showings Have Been Setup Yet!</b><br>
</td>
</tr>
~;
        }

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

}

sub overview_prospects_add {
    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>Prospect Information in Overview</title>
<link rel="stylesheet" TYPE="text/css" href="includes/style.css">
<script language="JavaScript" src="calendar1.js"></script>
<script language="JavaScript" src="calendar2.js"></script>
</head>
<body bgcolor="white" leftMargin="0" topMargin="0" marginwidth="0" marginheight="0">
<table border="0" cellpadding="2" cellspacing="0" width="100%">
<form method="get" action="transactions.idx" name="prospects">
<input type="hidden" name="action" value="overview_showings_adddo">
<input type="hidden" name="mlsnumber" value="$INPUT{mlsnumber}">
<input type="hidden" name="agent" value="$Cook{agentid}">
<tr>
<td valign="top">
Firstname <input type="text" name="firstname"><br>
Lastname <input type="text" name="lastname"><br>
Address <input type="text" name="address"><br>
City <input type="text" name="city"><br>
</td>
<td valign="top">
State <input type="text" name="state"><br>
Zip <input type="text" name="zip"><br>
Source <select name="source"><option value="">-- Select Source --</option><option value="">---------</option><option value="Yard Sign">Yard Sign</option><option value="Internet">Internet</option></select><br>
				Select Date<br>
				<input type="Text" name="dateofcontact" value="" class="form">
				<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><br>
<input type="submit" value="Save"><br>
</td>
</tr>
</table>
</form>
<script language="JavaScript
	var cal1 = new calendar1(document.forms['prospects'].elements['dateofcontact']);
	cal1.year_scroll = true;
	cal1.time_comp = false;
</script>
</body>
</html>
~;

}

sub overview_stats {

    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>Website Stat Information in Overview</title>
<link rel="stylesheet" TYPE="text/css" href="includes/style.css">
</head>
<body bgcolor="white" leftMargin="0" topMargin="0" marginwidth="0" marginheight="0">
~;

    if ( $INPUT{do} eq "showdetails" ) {
        print qq~
<b><font size="2" face="Arial">MuncieMLS User Info</font></b>  [ <a href="javascript:history.back()">Return</a> ]<br>
~;

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

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

            print qq~

			<b>$firstname $lastname<br>
			<b>$address<br>
			$city, $state $zipcode</b><br>
			<b>$Phone</b><br>
			$email<br>
			I am a <b>$UserType</b><br>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
	<tr>
		<td valign="top" bgcolor="navy" width="100%">
			<b><font color="white" size="2">User Saved Favorite Searches</font></b>
		</td>
	</tr>
</table>
~;
            my $basth =
              $dbh->prepare(
"select * from search_fav where userid = '$INPUT{userid}' order by favid asc"
              );
            $basth->execute;
            while (
                (
                    $userid,     $favid,      $searchstring,
                    $searchname, $searchtype, $status
                )
                = $basth->fetchrow_array()
              )
            {
                $foundsearch = "Yes";
                if ( $searchtype eq "res" ) {
                    $extension = "";
                }
                else {
                    $extension = "\_$searchtype";
                }
                if ( $status eq "0" ) {
                    $showstatus = "<font color=\"red\"><b>Stopped</b></font>";
                    $showtoggle = "Start";
                    $showstyle  = "green";
                }
                else {
                    $showstatus = "<font color=\"green\"><b>Running</b></font>";
                    $showtoggle = "Stop";
                    $showstyle  = "red";
                }
                print qq~
<b>$searchname | $favid | $showstatus</b> | <a href="admin.idx?action=deletesearch&searchid=$favid&userid=$INPUT{userid}">Delete</a><br>
<br>
~;
            }
            unless ($foundsearch) {
                print qq~
<font color="red"><b>No Saved Searches</b></font><br><br>
~;
            }
            print qq~
<table border="0" cellspacing="0" cellpadding="2" width="100%">
	<tr>
		<td valign="top" bgcolor="navy" width="100%">
			<b><font color="white" size="2">User Saved Favorite Homes</font></b>
		</td>
	</tr>
</table>
<table border="0" cellpadding="2" cellspacing="0" width="100%">
<tr>
~;
            my $casth =
              $dbh->prepare(
"select * from home_fav where userid = '$INPUT{userid}' order by favid asc"
              );
            $casth->execute;
            $startcount = "1";
            while ( ( $userid, $favid, $mlsnumber, $listingtype, $notes ) =
                $casth->fetchrow_array() )
            {
                $jasth =
                  $dbh->prepare(
"select AddressNumber,AddressDirection,AddressStreet,City,Zip,State,Remarks from listings_$listingtype where MLSNUM = '$mlsnumber'"
                  );
                $jasth->execute;
                while (
                    (
                        $AddressNumber, $AddressDirection, $AddressStreet,
                        $City,          $Zip,              $state,
                        $remarks_public
                    )
                    = $jasth->fetchrow_array()
                  )
                {
                    $foundhomes = "yes";
                    if ( $startcount eq "2" ) {
                        $startcount = "1";
                        $bgcolor    = "FFFF99";
                    }
                    else {
                        $startcount++;
                        $bgcolor = "white";
                    }
                    $notes =~ s/CHR1/\'/gi;
                    $notes =~ s/CHR2/\"/gi;
                    if ( $listingtype eq "res" ) {
                        $extension = "";
                    }
                    elsif ( $listingtype eq "comm" ) {
                        $extension = "\_commercial";
                    }
                    elsif ( $listingtype eq "inv" ) {
                        $extension = "\_investment";
                    }
                    elsif ( $listingtype eq "lan" ) {
                        $extension = "\_land";
                    }
                    else {
                    }
                    print qq~
<tr bgcolor="$bgcolor">
	<td valign="top">
		$AddressNumber $AddressDirection $AddressStreet<br>
	</td>
	<td valign="top">
		$City, $state $Zip<br>
	</td>
	<td valign="top">
		MLS #<a href="showdetails$extension.idx?mlsnumber=$mlsnumber">$mlsnumber</a>
	</td>
	</tr>
	<tr bgcolor="$bgcolor">
	<td valign="top" width="275" colspan="3">
		<b>User Notes: $notes</b><br>
	</td>
</tr>
~;
                }
            }
            unless ($foundhomes) {
                print qq~
<tr>
<td valign="top">
<font color="red"><b>No Saved Homes</b></font><br>
</td>
</tr>
~;
            }
            print qq~
</table>
<br><br>
~;

        }

    }
    else {
        print qq~
<table border="0" cellpadding="3" cellspacing="1" width="100%">
<tr bgcolor="#CCCCFF">
<td valign="top"><b>Name</b></td>
<td valign="top"><b>Notes</b></td>
<td valign="top" bgcolor="silver"></td>
</tr>
~;

        my $aasth =
          $dbh->prepare(
"select userid,favid,mlsnumber,notes from home_fav where mlsnumber = '$INPUT{mlsnumber}'"
          );
        $aasth->execute;

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

        while ( ( $userid, $favid, $mlsnumber, $notes ) =
            $aasth->fetchrow_array() )
        {

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

            if ( $notes eq "" ) {
                $notes = "None";
            }

            my $basth =
              $dbh->prepare(
                "select firstname,lastname from users where userid = '$userid'"
              );
            $basth->execute;
            while ( ( $firstname, $lastname ) = $basth->fetchrow_array() ) {

                print qq~
<tr bgcolor="$setcolor">
<td valign="top"><a href="transactions.idx?action=overview_stats&do=showdetails&userid=$userid&agent=$Cook{agentid}">$firstname $lastname</a></td>
<td valign="top">$notes</td>
<td valign="top"><a href="transactions.idx?action=overview_stats&do=showdetails&userid=$userid&agent=$Cook{agentid}"><img src="images/trans_sys/button_view.gif" height="13" width="11" border="0" alt="View $firstname $lastname details"></a></td>
</tr>
~;
                $found = "yes";
            }
        }

        unless ( $found eq "yes" ) {
            print qq~
<tr>
<td colspan="4">
<font color="red"><b>No Prospects Have Been Entered Yet!</b><br>
</td>
</tr>
~;
        }

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

}

sub overview_prospects {

    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>Prospect Information in Overview</title>
<link rel="stylesheet" TYPE="text/css" href="includes/style.css">
</head>
<body bgcolor="white" leftMargin="0" topMargin="0" marginwidth="0" marginheight="0">
~;

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

        my $casth =
          $dbh->prepare(
"select id,agent,type,firstname,lastname,address,spouse,city,state,zip,phone1type,phone1number,phone2type,phone2number,phone3type,phone3number,faxnumber,email,email_block,contacttype,DATE_FORMAT(initial_contactdate, '%b %D, %Y'),DATE_FORMAT(last_contactdate, '%b %D, %Y'),DATE_FORMAT(next_contactdate, '%b %D, %Y'),source,notes from trans_boardprospect WHERE id = '$INPUT{prospectid}'"
          );
        $casth->execute;
        while (
            (
                $id,               $agent,            $type,
                $firstname,        $lastname,         $address,
                $spouse,           $city,             $state,
                $zip,              $phone1type,       $phone1number,
                $phone2type,       $phone2number,     $phone3type,
                $phone3number,     $faxnumber,        $email,
                $email_block,      $contacttype,      $initial_contactdate,
                $last_contactdate, $next_contactdate, $source,
                $notes
            )
            = $casth->fetchrow_array()
          )
        {

            $contacttype =~ s/\,/ - /gi;

            unless ($initial_contactdate) {
                $initial_contactdate = "<font color=\"Red\">Not Entered</font>";
            }

            unless ($last_contactdate) {
                $last_contactdate = "<font color=\"Red\">Not Entered</font>";
            }

            unless ($next_contactdate) {
                $next_contactdate = "<font color=\"Red\">Not Entered</font>";
            }

            if ( $spouse ne "" ) {
                $spouse = " & $spouse ";
            }
            else {
                $spouse = "";
            }

            print qq~
<b><font size="2" face="Arial">Prospect Info</font></b>  [ <a href="javascript:history.back()">Return</a> ]<br>
<img src="images/contacts_icon.gif" alt="$firstname$spouse $lastname"><font size="4" face="Arial Black">$firstname$spouse $lastname<br></font>
<b>$phone1type</b> $phone1number<br>
<b>$phone2type</b> $phone2number<br>
<b>$phone3type</b> $phone3number<br>
<b>Fax</b> $faxnumber<br>
<b>E-Mail</b> <a href="prospects.idx?action=myemailer&agent=$Cook{agentid}&prospectid=$id">$email</a><br>
<b>Initial Contact Date</b><br>
<i>$initial_contactdate</i><br>
<b>Last Contact Date</b><br>
<i>$last_contactdate</i><br>
<b>Next Contact Date</b><br>
<i>$next_contactdate</i><br>
<b>Referal Source</b><br>
<i>$source</i><br>
<b>Contact Type(s)</b><br>
$contacttype<br>
<b>Note(s)</b><br>
~;
            my $basth =
              $dbh->prepare(
"select noteid,prospectid,DATE_FORMAT(datetime, '%b %D, %Y at %h\:%i%p'),addedby,note from trans_boardprospectnotes WHERE prospectid = '$INPUT{prospectid}' ORDER by datetime DESC"
              );
            $basth->execute;
            while ( ( $noteid, $prospectid, $datetime, $addedby, $note ) =
                $basth->fetchrow_array() )
            {
                print qq~
<b>$note</b> <i>Added by $addedby on $datetime</i><hr width="60%">
~;
            }
            print qq~
<br>
[ <a href="javascript:history.back()">Return</a> ]
<br>
~;
        }

    }
    else {
        print qq~
<table border="0" cellpadding="3" cellspacing="1" width="100%">
<tr bgcolor="#CCCCFF">
<td valign="top"><b>T</b></td>
<td valign="top"><b>Name</b></td>
<td valign="top"><b>Date</b></td>
<td valign="top" bgcolor="silver"></td>
</tr>
~;

        my $aasth =
          $dbh->prepare(
"select transid,prospectid from trans_boardtranstoprospect where transid = '$INPUT{transid}' order by prospectid desc"
          );
        $aasth->execute;

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

        while ( ( $transid, $prospectid ) = $aasth->fetchrow_array() ) {

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

            my $basth =
              $dbh->prepare(
"select id,type,firstname,lastname,DATE_FORMAT(initial_contactdate, '%b %D, %Y') from trans_boardprospect where id = '$prospectid'"
              );
            $basth->execute;
            while (
                ( $id, $type, $firstname, $lastname, $initial_contactdate ) =
                $basth->fetchrow_array() )
            {

                if ( $type eq "office" ) {
                    $ptype = "O";
                }
                else {
                    $ptype = "A";
                }

                print qq~
<tr bgcolor="$setcolor">
<td valign="top">$ptype</td>
<td valign="top"><a href="transactions.idx?action=overview_prospects&do=showdetails&prospectid=$prospectid&agent=$Cook{agentid}">$firstname $lastname</a></td>
<td valign="top">$initial_contactdate</td>
<td valign="top"><a href="transactions.idx?action=overview_prospects&do=showdetails&prospectid=$prospectid&agent=$Cook{agentid}"><img src="images/trans_sys/button_view.gif" height="13" width="11" border="0" alt="View $firstname $lastname details"></a></td>
</tr>
~;
                $found = "yes";
            }
        }

        unless ( $found eq "yes" ) {
            print qq~
<tr>
<td colspan="4">
<font color="red"><b>No Prospects Have Been Entered Yet!</b><br>
</td>
</tr>
~;
        }

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

}

sub showingadmin {

    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;

}

sub myemailer_send {

    $mailto   = $INPUT{mailto};
    $mailfrom = $INPUT{mailfrom};
    $subject  = $INPUT{subject};
    $message  = $INPUT{message};

    $temp_message = $message;
    $temp_message =~ s/\"/\&quot;/g;

    unless ( $INPUT{send} eq "yes" ) {

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

        &header;

        print qq~
<td valign="top" width="581">
<img src="images/headers/transaction_manager.gif" width="581" height="33" alt="My Transaction Manager"><br><br>

<form method="post" action="transactions.idx">
<input type="hidden" name="action" value="myemailer_send">
<input type="hidden" name="send" value="yes">
<input type="hidden" name="agent" value="$Cook{agentid}">
<input type="hidden" name="contactid" value="$INPUT{contactid}">
<input type="hidden" name="mailto" value="$mailto">
<input type="hidden" name="mailfrom" value="$mailfrom">
<input type="hidden" name="subject" value="$subject">
<input type="hidden" name="message" value="$temp_message">
<input type="submit" value="Send This E-Mail NOW!">
</form>


PREVIEW OF EMAIL BEING SENT<br><br>
To: $mailto<br>
From: $mailfrom<br>
Subject: $subject<br>
<br>
<center>
<table border="0" cellspacing="0" cellpadding="0" width="600">
<tr>
<td valign="top" width="600">
<img src="http://connect.eaglesold.com/images/emailheader.gif"><br>
<table border="0" cellspacing="0" cellpadding="15" width="100%">
<tr>
<td valign="top" width="100%">
<font size="2">
$message
<br><br><br>
</font>
</td>
</tr>
</table>
<img src="http://connect.eaglesold.com/images/emailfooter.gif"><br><br><br>
</td>
</tr>
</table>
</center>

</td>

~;

        &footer;

    }

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

        $message =~ s/\&quot;/\"/g;

        open( MAIL, "|/usr/sbin/sendmail -t" );
        print MAIL "To: $mailto\n";
        print MAIL "From: $mailfrom\n";
        print MAIL "Subject: $subject\n";
        print MAIL "Content-type: text/html\n\n";
        print MAIL qq~
<html>
<head>
<title>Official Eagle Real Estate, Inc. E-Mail</title>
<link rel="stylesheet" TYPE="text/css" href="http://connect.eaglesold.com/includes/style.css">
</head>
<body bgcolor="white" leftMargin="0" topMargin="0" marginwidth="0" marginheight="0">
<br><br>
<center>
<table border="0" cellspacing="0" cellpadding="0" width="600">
<tr>
<td valign="top" width="600">
<img src="http://connect.eaglesold.com/images/emailheader.gif"><br>
<table border="0" cellspacing="0" cellpadding="15" width="100%">
<tr>
<td valign="top" width="100%">
<font size="2">
$message
<br><br><br>
</font>
</td>
</tr>
</table>
<img src="http://connect.eaglesold.com/images/emailfooter.gif"><br><br><br>
</td>
</tr>
</table>
</center>
</body>
</html>
~;
        close(MAIL);

        print qq~
<html>
<head>
<title>E-Mail Sent</title>
</head>
~;

        &header;

        print qq~
<td valign="top" width="581">
<img src="images/headers/transaction_manager.gif" width="581" height="33" alt="My Transaction Manager"><br><br>
Email Was sent to $mailto<br><br>
<a href="transactions.idx?action=overview_contact&agent=$Cook{agentid}&contactid=$INPUT{contactid}">Return to Client Overview</a><br>
</td>
~;

        &footer;
    }
}

sub myemailer {

    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 $baasth = $dbh->prepare(
        "select COUNT(mlsid) from agents where mlsid = '$Cook{agentid}'");
    $baasth->execute;
    while ( ($mlsidc) = $baasth->fetchrow_array() ) {
        $mlsidcount = "$mlsidc";
    }

    my $aasth =
      $dbh->prepare(
"select mlsid,firstname,lastname,email from agents where mlsid = '$Cook{agentid}'"
      );
    $aasth->execute;

    my $casth =
      $dbh->prepare(
"select email,firstname,lastname from trans_boardcontact where id = '$INPUT{contactid}' AND emailtwo != 'yes' LIMIT 0,1"
      );
    $casth->execute;
    while ( ( $email, $firstname, $lastname ) = $casth->fetchrow_array() ) {
        $emailblocked = "no";
        $cemail       = "$email";
        $cfirstname   = "$firstname";
        $clastname    = "$lastname";
    }

    unless ( $emailblocked eq "no" ) {
        $cemail =
"<b><font size=6 color=red>THIS USER HAS BLOCKED EMAILS FROM You!  Your E-Mail Will Not Be Received By This Contact!!!!!</font></b>";
    }

    &header;

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

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

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

<img src="images/headers/transaction_manager.gif" width="581" height="33" alt="My Transaction Manager"><br><br>
Return To <a href="transactions.idx?action=overview_contact&agent=$Cook{agentid}&contactid=$INPUT{contactid}">Return TO Client Overview</a><br><br>
~;
    my $bcasth =
      $dbh->prepare(
"select COUNT(id) from emailer_templates where type = 'agent' AND accessid = '$Cook{agentid}'"
      );
    $bcasth->execute;
    while ( ($idcount) = $bcasth->fetchrow_array() ) {
        $counttemp = "$idcount";
    }

    print qq~
	<b>We found $counttemp agent email templates for you.  You may choose office or agent templates below to load into email now!</b><br>
	~;

    my $acasth =
      $dbh->prepare(
"select id,name,subject,template from emailer_templates where type = 'agent' AND accessid = '$Cook{agentid}' OR id = '1' ORDER BY id ASC"
      );
    $acasth->execute;
    while ( ( $id, $name, $subject, $template ) = $acasth->fetchrow_array() ) {
        print qq~
<a href="transactions.idx?action=myemailer&agent=$Cook{agentid}&contactid=$INPUT{contactid}&template=$id">$name</a> -- 
~;

    }

    print qq~
<br>
<form method="post" action="transactions.idx">
<input type="hidden" name="action" value="myemailer_send">
<input type="hidden" name="mailto" value="$cemail">
<input type="hidden" value="no" name="send">
<input type="hidden" name="agent" value="$Cook{agentid}">
<input type="hidden" name="contactid" value="$INPUT{contactid}">
~;
    if ( $mlsidcount > "1" ) {
        print qq~
	<b>E-Mail To:<br> $cemail</b><br><br>
	<b>E-Mail From:</b><br>
	<select name="mailfrom"><br><br>
	~;
    }

    while ( ( $mlsid, $firstname, $lastname, $email ) =
        $aasth->fetchrow_array() )
    {

        $afirstname = "$firstname";
        $alastname  = "$lastname";
        $aemail     = "$email";

        if ( $mlsidcount > "1" ) {
            print qq~
	<option value="$email">$email -- $firstname $lastname</option>
	~;
        }
        else {
            print qq~
		<input type="hidden" value="$email" name="mailfrom">
		<b>E-Mail To:<br>$cfirstname $clastname <$cemail></b><br><br>
		<b>E-Mail From:<br> $email</b><br><br>
~;
            if ( $INPUT{template} ) {
                my $sbcasth =
                  $dbh->prepare(
"select id,name,subject,template from emailer_templates where id = '$INPUT{template}'"
                  );
                $sbcasth->execute;
                while ( ( $wid, $wname, $wsubject, $wtemplate ) =
                    $sbcasth->fetchrow_array() )
                {
                    $wsubject =~ s/\$cfirstname/$cfirstname/g;
                    $wsubject =~ s/\$clastname/$clastname/g;
                    $wsubject =~ s/\$cemail/$cemail/g;
                    $wsubject =~ s/\$afirstname/$afirstname/g;
                    $wsubject =~ s/\$alastname/$alastname/g;
                    $wsubject =~ s/\$aemail/$aemail/g;
                    $pwsubject = "$wsubject";
                }
            }
            else {
                $pwsubject =
                  "Hello $cfirstname $clastname -- From MuncieMLS.com";
            }

            print qq~
		<b>Subject:<br></b> <input type="text" name="subject" maxlength="60" size="60" value="$pwsubject"><br><br>
		<b>Message:</b><br> <textarea rows="18" name="message" cols="80">
	~;

            if ( $INPUT{template} ) {
                my $bcasth =
                  $dbh->prepare(
"select id,name,subject,template from emailer_templates where id = '$INPUT{template}'"
                  );
                $bcasth->execute;
                while ( ( $wid, $wname, $wsubject, $wtemplate ) =
                    $bcasth->fetchrow_array() )
                {
                    $wtemplate =~ s/\$cfirstname/$cfirstname/g;
                    $wtemplate =~ s/\$clastname/$clastname/g;
                    $wtemplate =~ s/\$cemail/$cemail/g;
                    $wtemplate =~ s/\$afirstname/$afirstname/g;
                    $wtemplate =~ s/\$alastname/$alastname/g;
                    $wtemplate =~ s/\$aemail/$aemail/g;
                    print qq~
	$wtemplate
	~;
                }
            }
            else {
                print qq~
Hello $cfirstname $clastname<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
~;
            }
            print qq~
</textarea><br>
	~;
        }

    }

    if ( $mlsidcount > "1" ) {
        print qq~
	</select><br><br>
		<b>Subject:</b><br>
~;

        if ( $INPUT{template} ) {
            my $sbcasth =
              $dbh->prepare(
"select id,name,subject,template from emailer_templates where id = '$INPUT{template}'"
              );
            $sbcasth->execute;
            while ( ( $wid, $wname, $wsubject, $wtemplate ) =
                $sbcasth->fetchrow_array() )
            {
                $wsubject =~ s/\$cfirstname/$cfirstname/g;
                $wsubject =~ s/\$clastname/$clastname/g;
                $wsubject =~ s/\$cemail/$cemail/g;
                $wsubject =~ s/\$afirstname/$afirstname/g;
                $wsubject =~ s/\$alastname/$alastname/g;
                $wsubject =~ s/\$aemail/$aemail/g;
                $pwsubject = "$wsubject";
            }
        }
        else {
            $pwsubject = "Hello $cfirstname $clastname -- From MuncieMLS.com";
        }

        print qq~
		<input type="text" name="subject" maxlength="60" size="60" value="$pwsubject"><br><br>
		<b>Message:</b><br>
		<textarea rows="18" name="message" cols="80">
~;
        if ( $INPUT{template} ) {
            my $bcasth =
              $dbh->prepare(
"select id,name,subject,template from emailer_templates where id = '$INPUT{template}'"
              );
            $bcasth->execute;
            while ( ( $wid, $wname, $wsubject, $wtemplate ) =
                $bcasth->fetchrow_array() )
            {
                $wtemplate =~ s/\$cfirstname/$cfirstname/g;
                $wtemplate =~ s/\$clastname/$clastname/g;
                $wtemplate =~ s/\$cemail/$cemail/g;
                $wtemplate =~ s/\$afirstname/$afirstname/g;
                $wtemplate =~ s/\$alastname/$alastname/g;
                $wtemplate =~ s/\$aemail/$aemail/g;
                print qq~
	$wtemplate
	~;
            }
        }
        else {
            print qq~
Hello $cfirstname $clastname<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
~;
        }
    }
    print qq~
</textarea><br><br>
<input type="submit" Value="Next - Preview Message">
</form>
</td>
~;
    &footer;
}

sub directory_view {

    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,type,firstname,lastname,agent1type,agent1phone,agent2type,agent2phone,agent3type,agent3phone,agentfax,email,company,coaddress,cocity,costate,cozip,cophone from trans_boarddirectory WHERE id = '$INPUT{directoryid}'"
      );
    $basth->execute;

    print qq~
<html>
<head>
<title>Company Directory -- Eagle Real Estate, Inc. - Connect.EagleSold.com</title>
~;

    &header;

    if ( $INPUT{searchtype} eq "company" ) {
        $buildlink =
"transactions.idx?action=directory&company=$INPUT{company}&agent=$Cook{agentid}";
    }
    elsif ( $INPUT{searchtype} eq "contact" ) {
        $buildlink =
"transactions.idx?action=directory&contact=$INPUT{contact}&agent=$Cook{agentid}";
    }

    print qq~

<td valign="top" width="581">
<img src="images/headers/transaction_manager.gif" height="33" width="581" alt="My Transaction Manager"><br><br>
<img src="images/trans_sys/company_directory.gif" alt="Eagle Company Directory"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Navigation:</b> <a href="$buildlink">Return To Directory Search Results</a><br><br>
<br>
<img src="images/trans_sys/contact_information.gif" alt="Contact Information"><br>
~;
    while (
        (
            $id,         $type,        $firstname,  $lastname,
            $agent1type, $agent1phone, $agent2type, $agent2phone,
            $agent3type, $agent3phone, $agentfax,   $email,
            $company,    $coaddress,   $cocity,     $costate,
            $cozip,      $cophone
        )
        = $basth->fetchrow_array()
      )
    {
        print qq~
<table border="0" cellpadding="2" cellspacing="0">
<tr>
<td valign="top"><img src="images/admin/dude.gif"><br></td>
<td valign="top">
<font size="4" face="Arial">
$firstname $lastname<br>
$agent1type $agent1phone<br>
$agent2type $agent2phone<br>
$agent3type $agent3phone<br>
Fax: $agentfax<br>
E-Mail: $email<br><br><br>
Contact Type: $type<br><br>
</font>
<b>Company Information:</b><br>
<font size="4" face="Arial">
$company<br>
$coaddress<br>
$cocity, $costate $cozip<br>
Company Phone: $cophone<br><br><br>
</font>
</td>
</tr>
</table>
<font size="3" face="Arial"><b>Transaction(s) History as of December 1st, 2004</b></font><br>
<table border="0" cellpadding="2" cellspacing="0" width="100%">
<tr bgcolor="navy">
<td valign="top">&nbsp;</td>
<td valign="top"><b><font color="white">Address</font></b></td>
<td valign="top"><b><font color="white">City</font></b></td>
<td valign="top"><b><font color="white">Sold Date</font></b></td>
<td valign="top"><b><font color="white">How Involved In Transaction</font></b></td>
</tr>
~;

        my $casth =
          $dbh->prepare(
"select id,agent,selleragent,sellercoagent,buyeragent,buyercoagent,addressnumber,addressdirection,addressstreet,city,state,zip,solddate from trans_board WHERE agent = '$Cook{agentid}' AND (buyeragent = '$id' or buyercoagent = '$id' or sellercoagent = '$id' or selleragent = '$id') ORDER BY solddate desc"
          );
        $casth->execute;

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

        while (
            (
                $transid,       $transagent,       $selleragent,
                $sellercoagent, $buyeragent,       $buyercoagent,
                $addressnumber, $addressdirection, $addressstreet,
                $city,          $state,            $zip,
                $solddate
            )
            = $casth->fetchrow_array()
          )
        {

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

            if ( $solddate eq '0000-00-00' ) {
                $solddate = "Not Sold Yet";
            }

            if ( $selleragent eq "$id" ) {
                $transtype = "Seller Agent";
            }
            if ( $sellercoagent eq "$id" ) {
                $transtype = "Seller Co Agent";
            }
            if ( $buyeragent eq "$id" ) {
                $transtype = "Buyer Agent";
            }
            if ( $buyercoagent eq "$id" ) {
                $transtype = "Buyer Co Agent";
            }
            if ( $selleragent eq $buyeragent ) {
                $transtype = "Buyer & Seller Agent";
            }

            print qq~
<tr bgcolor="$setcolor">
<td valign="top"><a href="transactions.idx?action=overview&transid=$transid&agent=$transagent">View</a></td>
<td valign="top"><a href="transactions.idx?action=overview&transid=$transid&agent=$transagent">$addressnumber $addressdirection $addressstreet</a></td>
<td valign="top"><a href="transactions.idx?action=overview&transid=$transid&agent=$transagent">$city</a></td>
<td valign="top"><b><center>$solddate</center></b></td>
<td valign="top"><b><center>$transtype</center></b></td>
</tr>
~;
            $found = "yes";
        }
        unless ( $found eq "yes" ) {
            print qq~
<tr>
<td colspan="5">
<font color="red"><b>No History Found For This Contact</b></font>
</td>
</tr>
~;
        }
        print qq~
</table>
~;
    }

    print qq~
</td>
~;

    &footer;

}

sub directory {

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

    my $abasth = $dbh->prepare(
        "select company from trans_boarddirectory GROUP BY company ASC");
    $abasth->execute;

    while ( ($company) = $abasth->fetchrow_array() ) {
        $buildcompany .= "<option value=\"$company\">$company</option>";
    }

    print qq~
<html>
<head>
<title>Company Directory -- Eagle Real Estate, Inc. - Connect.EagleSold.com</title>
~;

    &header;

    print qq~

<td valign="top" width="581">
<img src="images/headers/transaction_manager.gif" height="33" width="581" alt="My Transaction Manager"><br><br>
<img src="images/trans_sys/company_directory.gif" alt="Eagle Company Directory"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>view contacts and information the directory</b><br><br>
<br>
<font size="4" face="Arial">Contacts</font><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 By Company</font></b><br>
</td>
<form method="post" action="transactions.idx">
<td align="right">
<input type="hidden" name="action" value="directory">
<input type="hidden" name="agent" value="$Cook{agentid}">
<select name="company" class="form">
$buildcompany
</select> <input type="submit" value="Search!" class="form">
</td>
</form>
</tr>
</table>
</td>
</tr>
</table>
<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 Company Directory By Lastname</font></b><br></td>
<td align="right">
<br>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor="white">
<center>
<a href="transactions.idx?action=directory&agent=$Cook{agentid}&contact=%">All</a> 
<a href="transactions.idx?action=directory&agent=$Cook{agentid}&contact=A">A</a> | 
<a href="transactions.idx?action=directory&agent=$Cook{agentid}&contact=B">B</a> | 
<a href="transactions.idx?action=directory&agent=$Cook{agentid}&contact=C">C</a> | 
<a href="transactions.idx?action=directory&agent=$Cook{agentid}&contact=D">D</a> | 
<a href="transactions.idx?action=directory&agent=$Cook{agentid}&contact=E">E</a> | 
<a href="transactions.idx?action=directory&agent=$Cook{agentid}&contact=F">F</a> | 
<a href="transactions.idx?action=directory&agent=$Cook{agentid}&contact=G">G</a> | 
<a href="transactions.idx?action=directory&agent=$Cook{agentid}&contact=H">H</a> | 
<a href="transactions.idx?action=directory&agent=$Cook{agentid}&contact=I">I</a> | 
<a href="transactions.idx?action=directory&agent=$Cook{agentid}&contact=J">J</a> | 
<a href="transactions.idx?action=directory&agent=$Cook{agentid}&contact=K">K</a> | 
<a href="transactions.idx?action=directory&agent=$Cook{agentid}&contact=L">L</a> | 
<a href="transactions.idx?action=directory&agent=$Cook{agentid}&contact=M">M</a> | 
<a href="transactions.idx?action=directory&agent=$Cook{agentid}&contact=N">N</a> | 
<a href="transactions.idx?action=directory&agent=$Cook{agentid}&contact=O">O</a> | 
<a href="transactions.idx?action=directory&agent=$Cook{agentid}&contact=P">P</a> | 
<a href="transactions.idx?action=directory&agent=$Cook{agentid}&contact=Q">Q</a> | 
<a href="transactions.idx?action=directory&agent=$Cook{agentid}&contact=R">R</a> | 
<a href="transactions.idx?action=directory&agent=$Cook{agentid}&contact=S">S</a> | 
<a href="transactions.idx?action=directory&agent=$Cook{agentid}&contact=T">T</a> | 
<a href="transactions.idx?action=directory&agent=$Cook{agentid}&contact=U">U</a> | 
<a href="transactions.idx?action=directory&agent=$Cook{agentid}&contact=V">V</a> | 
<a href="transactions.idx?action=directory&agent=$Cook{agentid}&contact=W">W</a> | 
<a href="transactions.idx?action=directory&agent=$Cook{agentid}&contact=X">X</a> | 
<a href="transactions.idx?action=directory&agent=$Cook{agentid}&contact=Y">Y</a> | 
<a href="transactions.idx?action=directory&agent=$Cook{agentid}&contact=Z">Z</a>
</center><br>
~;

    if ( $INPUT{contact} or $INPUT{company} ) {

        if ( $INPUT{contact} ) {
            $sql        = "lastname LIKE '$INPUT{contact}%' ORDER by lastname";
            $searchtype = "contact";
        }
        elsif ( $INPUT{company} ) {
            $sql        = "company = '$INPUT{company}' ORDER by company";
            $searchtype = "company";
        }
        my $basth =
          $dbh->prepare(
"select id,firstname,lastname,company from trans_boarddirectory WHERE showhide = 'active' AND $sql ASC"
          );
        $basth->execute;

        $rowcolor{on}  = "#FFFFFF";
        $rowcolor{off} = "#FFFF99";
        $color_count   = "0";
        $row_switch    = "on";

        print qq~
		<table border="0" cellpadding="2" cellspacing="1" width="100%" bgcolor="gray">
		<tr>
		~;

        while ( ( $directoryid, $firstname, $lastname, $company ) =
            $basth->fetchrow_array() )
        {
            $company = substr( $company, 0, 16 );
            print qq~
<td bgcolor="$rowcolor{$row_switch}">
<img src="images/dude_small.gif"> <a href="transactions.idx?action=directory_view&agent=$Cook{agentid}&directoryid=$directoryid&searchtype=$searchtype&contact=$INPUT{contact}&company=$INPUT{company}">$lastname, $firstname - $company</a><br>
</td>
~;

            if ( $color_count eq "1" ) {
                print qq~</tr><tr>~;
                $color_count = "0";
            }
            else {
                $color_count = "1";
            }

            if ( $color_count eq "0" ) {
                if ( $row_switch eq "on" ) {
                    $row_switch = "off";
                }
                else {
                    $row_switch = "on";
                }
            }

            $ccfound = "yes";
        }

        print qq~<td bgcolor="$rowcolor{$row_switch}"> </td>~
          if ( $color_count eq "1" );

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

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

}

sub overview_contacts_smallaz {

#id,agent,type,firstname,lastname,phone1type,phone1number,phone2type,phone2number,phone3type,phone3number,faxnumber,email,emailtwo,notes

    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>Contacts Small A-Z</title>
<link rel="stylesheet" TYPE="text/css" href="includes/style.css">
</head>
<body bgcolor="white" leftMargin="0" topMargin="0" marginwidth="0" marginheight="0">

<b>SEARCH USERS LASTNAME BY</b><br>
<center>
<a href="transactions.idx?action=overview_contacts_smallaz&transid=$INPUT{transid}&agent=$Cook{agentid}&find=A">A</a> | 
<a href="transactions.idx?action=overview_contacts_smallaz&transid=$INPUT{transid}&agent=$Cook{agentid}&find=B">B</a> | 
<a href="transactions.idx?action=overview_contacts_smallaz&transid=$INPUT{transid}&agent=$Cook{agentid}&find=C">C</a> | 
<a href="transactions.idx?action=overview_contacts_smallaz&transid=$INPUT{transid}&agent=$Cook{agentid}&find=D">D</a> | 
<a href="transactions.idx?action=overview_contacts_smallaz&transid=$INPUT{transid}&agent=$Cook{agentid}&find=E">E</a> | 
<a href="transactions.idx?action=overview_contacts_smallaz&transid=$INPUT{transid}&agent=$Cook{agentid}&find=F">F</a> | 
<a href="transactions.idx?action=overview_contacts_smallaz&transid=$INPUT{transid}&agent=$Cook{agentid}&find=G">G</a> | 
<a href="transactions.idx?action=overview_contacts_smallaz&transid=$INPUT{transid}&agent=$Cook{agentid}&find=H">H</a> | 
<a href="transactions.idx?action=overview_contacts_smallaz&transid=$INPUT{transid}&agent=$Cook{agentid}&find=I">I</a> | 
<a href="transactions.idx?action=overview_contacts_smallaz&transid=$INPUT{transid}&agent=$Cook{agentid}&find=J">J</a> | 
<a href="transactions.idx?action=overview_contacts_smallaz&transid=$INPUT{transid}&agent=$Cook{agentid}&find=K">K</a> | 
<a href="transactions.idx?action=overview_contacts_smallaz&transid=$INPUT{transid}&agent=$Cook{agentid}&find=L">L</a> | 
<a href="transactions.idx?action=overview_contacts_smallaz&transid=$INPUT{transid}&agent=$Cook{agentid}&find=M">M</a> | 
<a href="transactions.idx?action=overview_contacts_smallaz&transid=$INPUT{transid}&agent=$Cook{agentid}&find=N">N</a> | 
<a href="transactions.idx?action=overview_contacts_smallaz&transid=$INPUT{transid}&agent=$Cook{agentid}&find=O">O</a> | 
<a href="transactions.idx?action=overview_contacts_smallaz&transid=$INPUT{transid}&agent=$Cook{agentid}&find=P">P</a> | 
<a href="transactions.idx?action=overview_contacts_smallaz&transid=$INPUT{transid}&agent=$Cook{agentid}&find=Q">Q</a> | 
<a href="transactions.idx?action=overview_contacts_smallaz&transid=$INPUT{transid}&agent=$Cook{agentid}&find=R">R</a> | 
<a href="transactions.idx?action=overview_contacts_smallaz&transid=$INPUT{transid}&agent=$Cook{agentid}&find=S">S</a> | 
<a href="transactions.idx?action=overview_contacts_smallaz&transid=$INPUT{transid}&agent=$Cook{agentid}&find=T">T</a> | 
<a href="transactions.idx?action=overview_contacts_smallaz&transid=$INPUT{transid}&agent=$Cook{agentid}&find=U">U</a> | 
<a href="transactions.idx?action=overview_contacts_smallaz&transid=$INPUT{transid}&agent=$Cook{agentid}&find=V">V</a> | 
<a href="transactions.idx?action=overview_contacts_smallaz&transid=$INPUT{transid}&agent=$Cook{agentid}&find=W">W</a> | 
<a href="transactions.idx?action=overview_contacts_smallaz&transid=$INPUT{transid}&agent=$Cook{agentid}&find=X">X</a> | 
<a href="transactions.idx?action=overview_contacts_smallaz&transid=$INPUT{transid}&agent=$Cook{agentid}&find=Y">Y</a> | 
<a href="transactions.idx?action=overview_contacts_smallaz&transid=$INPUT{transid}&agent=$Cook{agentid}&find=Z">Z</a>
</center>
<br><br>
~;
    my $basth =
      $dbh->prepare(
"select id,agent,type,firstname,lastname from trans_boardcontact WHERE agent = '$Cook{agentid}' AND lastname LIKE '$INPUT{find}%' ORDER by lastname ASC"
      );
    $basth->execute;

    while ( ( $id, $agent, $type, $firstname, $lastname ) =
        $basth->fetchrow_array() )
    {
        print qq~
$id - $agent - $type - $firstname - $lastname<br>
~;
    }

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

}

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;

    my $basth =
      $dbh->prepare(
"select noteid,transid,DATE_FORMAT(datetime, '%b %D, %Y at %h\:%i%p'),addedby,note from trans_boardnotes WHERE transid = '$INPUT{transid}' 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, $transid, $datetime, $addedby, $note ) =
        $basth->fetchrow_array() )
    {

        if ( $trcolor eq $trcolor2 ) {
            $trcolor  = "1";
            $setcolor = "#FFFFFF";
        }
        else {
            $setcolor = "#CCCCFF";
            $trcolor++;
        }
        print qq~
<tr bgcolor="$setcolor">
<td valign="top">
<b>$note</b><br><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>
~;
}

sub overview_contact_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;

    my $basth =
      $dbh->prepare(
"select noteid,contactid,DATE_FORMAT(datetime, '%b %D, %Y at %h\:%i%p'),addedby,note from trans_boardcontactnotes WHERE contactid = '$INPUT{contactid}' 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, $contactid, $datetime, $addedby, $note ) =
        $basth->fetchrow_array() )
    {

        if ( $trcolor eq $trcolor2 ) {
            $trcolor  = "1";
            $setcolor = "#FFFFFF";
        }
        else {
            $setcolor = "#CCCCFF";
            $trcolor++;
        }
        print qq~
<tr bgcolor="$setcolor">
<td valign="top">
<b>$note</b><br>
<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>
~;
}

sub main {

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

    if ( $INPUT{viewtypeclass} eq "All" ) {
        $viewtypeoptionclass = "<option value=\"All\">All Classes</option>";
        $viewtypeoptionclass .= "<option value=\"\">-----------</option>";
        $viewtypeclasssql = "";
        $status           = "";
    }
    elsif ( $INPUT{viewtypeclass} eq "Residential" ) {
        $viewtypeoptionclass =
          "<option value=\"Residential\">Residential</option>";
        $viewtypeoptionclass .= "<option value=\"\">-----------</option>";
        $viewtypeclasssql = "AND listingclass = 'Residential'";
        $status           = "";
    }
    elsif ( $INPUT{viewtypeclass} eq "Commercial" ) {
        $viewtypeoptionclass =
          "<option value=\"Commercial\">Commercial</option>";
        $viewtypeoptionclass .= "<option value=\"\">-----------</option>";
        $viewtypeclasssql = "AND listingclass = 'Commercial'";
        $status           = "";
    }
    elsif ( $INPUT{viewtypeclass} eq "Investment" ) {
        $viewtypeoptionclass =
          "<option value=\"Investment\">Investment</option>";
        $viewtypeoptionclass .= "<option value=\"\">-----------</option>";
        $viewtypeclasssql = "AND listingclass = 'Investment'";
        $status           = "";
    }
    elsif ( $INPUT{viewtypeclass} eq "LotsLand" ) {
        $viewtypeoptionclass =
          "<option value=\"LotsLand\">Lots and Land</option>";
        $viewtypeoptionclass .= "<option value=\"\">-----------</option>";
        $viewtypeclasssql = "AND listingclass = 'LotsLand'";
        $status           = "";
    }

    if ( $INPUT{viewtype} eq "Listing" ) {
        $viewtypeoption = "<option value=\"Listing\">Listings</option>";
        $viewtypeoption .= "<option value=\"\">-----------</option>";
        $viewtypesql =
          "AND type = 'Listing' and (status = 'Active' or status = 'Pending')";
        $status = "";
    }
    if ( $INPUT{viewtype} eq "Prospect" ) {
        $viewtypeoption =
          "<option value=\"Prospect\">Listing Prospects</option>";
        $viewtypeoption .= "<option value=\"\">-----------</option>";
        $viewtypesql = "AND status = 'Prospect'";
        $status      = "";
    }
    elsif ( $INPUT{viewtype} eq "BP" ) {
        $viewtypeoption = "<option value=\"BP\">Buyer Side Sales</option>";
        $viewtypeoption .= "<option value=\"\">-----------</option>";
        $viewtypesql = "AND (type = 'BP' and status = 'Active')";
        $status      = "";
    }
    elsif ( $INPUT{viewtype} eq "BSP" ) {
        $viewtypeoption =
          "<option value=\"BSP\">Buyer & Seller  Side Sales</option>";
        $viewtypeoption .= "<option value=\"\">-----------</option>";
        $viewtypesql = "AND (type = 'BSP' and status = 'Pending')";
        $status      = "";
    }
    elsif ( $INPUT{viewtype} eq "Expired" ) {
        $viewtypeoption = "<option value=\"Expired\">Expired Listings</option>";
        $viewtypeoption .= "<option value=\"\">-----------</option>";
        $viewtypesql = "AND status = 'Expired'";
        $status      = "";
    }
    elsif ( $INPUT{viewtype} eq "CLSD" ) {
        $viewtypeoption = "<option value=\"CLSD\">Closed (SOLD)</option>";
        $viewtypeoption .= "<option value=\"\">-----------</option>";
        $viewtypesql = "AND status = 'CLSD'";
        $status      = "";
    }
    elsif ( $INPUT{viewtype} eq "WTHD" ) {
        $viewtypeoption = "<option value=\"WTHD\">Withdrawn (Release)</option>";
        $viewtypeoption .= "<option value=\"\">-----------</option>";
        $viewtypesql = "AND status = 'WTHD'";
        $status      = "";
    }
    elsif ( $INPUT{viewtype} eq "DEAD" ) {
        $viewtypeoption =
          "<option value=\"DEAD\">Dead Deal (Not Closing)</option>";
        $viewtypeoption .= "<option value=\"\">-----------</option>";
        $viewtypesql = "AND status = 'DEAD'";
        $status      = "";
    }
    elsif ( $INPUT{viewtype} eq "Pending" ) {
        $viewtypeoption = "<option value=\"Pending\">Pendings</option>";
        $viewtypeoption .= "<option value=\"\">-----------</option>";
        $viewtypesql = "AND status = 'Pending'";
        $status      = "";
    }
    elsif ( $INPUT{viewtype} eq "notactive" ) {
        $viewtypeoption = "<option value=\"notactive\">All Not Active</option>";
        $viewtypeoption .= "<option value=\"\">-----------</option>";
        $viewtypesql =
"AND (status = 'WTHD' or status = 'CLSD' or status = 'Expired' or status = 'DEAD')";
        $status = "";
    }
    elsif ( $INPUT{viewtype} eq "allactive" ) {
        $viewtypeoption = "<option value=\"allactive\">All Actives</option>";
        $viewtypeoption .= "<option value=\"\">-----------</option>";
        $viewtypesql = "AND status = 'Active'";
        $status      = "";
    }
    elsif ( $INPUT{viewtype} eq "allpending" ) {
        $viewtypeoption = "<option value=\"allpending\">All Pendings</option>";
        $viewtypeoption .= "<option value=\"\">-----------</option>";
        $viewtypesql = "AND status = 'Pending'";
        $status      = "";
    }
    elsif ( $INPUT{viewtype} eq "allap" ) {
        $viewtypeoption =
          "<option value=\"allap\">All Actives & Pendings</option>";
        $viewtypeoption .= "<option value=\"\">-----------</option>";
        $viewtypesql = "AND (status = 'Active' or status = 'Pending')";
        $status      = "";
    }
    elsif ( $INPUT{viewtype} eq "all" ) {
        $viewtypeoption = "<option value=\"all\">All Transactions</option>";
        $viewtypeoption .= "<option value=\"\">-----------</option>";
        $viewtypesql = "";
        $status      = "";
    }
    else {
        $viewtypeoption = "<option value=\"\">All Actives & Pendings</option>";
        $viewtypeoption .= "<option value=\"\">-----------</option>";
        $viewtypesql = "AND (status = 'Active' or status = 'Pending')";
        $status      = "";
    }

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

    &header;

    print qq~
<td valign="top" width="581">
<img src="images/headers/transaction_manager.gif" height="33" width="581" alt="My Transaction Manager"><br><br>
<img src="images/trans_sys/my_transactions.gif" alt="My Transaction Search"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>use the drop down box below to search your transactions</b><br><br>
<table border="0" cellpadding="6" cellspacing="1" bgcolor="navy" width="100%">
<tr>
<td bgcolor="#CCCCFF">
<form method="post" action="transactions.idx">
<input type="hidden" name="agent" value="$Cook{agentid}">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<td width="50%" nowrap>
<font size="2" face="Arial"><b>View</b> 
<select name="viewtypeclass" class="form" onChange="submit();">
$viewtypeoptionclass
<option value="All">All Classes</option>
<option value="">-----------</option>
<option value="Residential">Residential</option>
<option value="Commercial">Commercial</option>
<option value="LotsLand">Lots and Land</option>
<option value="Investment">Investment</option>
</select>
<select name="viewtype" class="form" onChange="submit();">
$viewtypeoption
<option value="allap">All Actives & Pendings</option>
<option value="allactive">All Actives</option>
<option value="allpending">All Pendings</option>
<option value="">-----------</option>
<option value="Listing">Listings</option>
<option value="Prospect">Listing Prospects</option>
<option value="">-----------</option>
<option value="BP">Buyer Side Sale</option>
<option value="BSP">Buyer & Seller Side Sales</option>
<option value="">-----------</option>
<option value="notactive">Not Active</option>
<option value="">-----------</option>
<option value="Expired">Expired Listings</option>
<option value="CLSD">Closed (SOLD)</option>
<option value="WTHD">Withdrawn (Release)</option>
<option value="DEAD">Dead Deal (Not Closing)</option>
<option value="">-----------</option>
<option value="all">ALL Transactions</option>
</select> <b>Transactions</b></font><br>
</td>
<td align="right">
<a href="transactions.idx?action=create_transaction&agent=$Cook{agentid}">Create New Transaction</a><br>
</td>
</table>
</td>
</tr>
</form>
</table>
<table border="0" cellspacing="0" cellpadding="3" width="100%">
<tr>
<td valign="top" bgcolor="black"><font color="white" size="2"><b>Status</b></font></td>
<td valign="top" bgcolor="black"><font color="white" size="2"><b>Address</b></font></td>
<td valign="top" bgcolor="black"><font color="white" size="2"><b>Buyer</b></font></td>
<td valign="top" bgcolor="black"><font color="white" size="2"><b>Seller</b></font></td>
<td valign="top" bgcolor="black"><font color="white" size="2"><b></b></font></td>
</tr>
~;

    my $aasth =
      $dbh->prepare(
"select id,agent,selleragent,sellercoagent,buyeragent,buyercoagent,type,status,addressnumber,addressdirection,addressstreet,city,state,zip,pendingdate,estimatedclosingdate from trans_board WHERE agent = '$Cook{agentid}'$viewtypeclasssql$viewtypesql ORDER BY status DESC"
      );
    $aasth->execute;
    $trcolor  = "1";
    $trcolor2 = "2";
    while (
        (
            $id,               $agent,         $selleragent,
            $sellercoagent,    $buyeragent,    $buyercoagent,
            $type,             $status,        $addressnumber,
            $addressdirection, $addressstreet, $city,
            $state,            $zip,           $pendingdate,
            $estimatedclosingdate
        )
        = $aasth->fetchrow_array()
      )
    {

        $bfound = "no";
        $sfound = "no";

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

        print qq~
<tr bgcolor="$setcolor">
<td valign="top"><font color="navy"><b><center>$status<br></center></b></font></td>
<td valign="top" nowrap><font color="navy"><b><a href="transactions.idx?action=overview&transid=$id&agent=$agent">$addressnumber $addressdirection $addressstreet</a></b></font><br></td>
<td valign="top"><font color="navy"><b>
~;
######### GET BUYER INFORMATION #####################

        my $bbaasth =
          $dbh->prepare(
"select contactid from trans_boardtranstocontact WHERE transid = '$id' AND type = 'Buyer'"
          );
        $bbaasth->execute;
        while ( ($tempcontactid) = $bbaasth->fetchrow_array() ) {

            my $ddasth =
              $dbh->prepare(
"select id,agent,type,firstname,lastname,address,spouse,city,state,zip,phone1type,phone1number,phone2type,phone2number,phone3type,phone3number,faxnumber,email,emailtwo,notes from trans_boardcontact WHERE id = '$tempcontactid'"
              );
            $ddasth->execute;

            while (
                (
                    $b_contactid,    $b_agent,        $b_type,
                    $b_firstname,    $b_lastname,     $b_address,
                    $b_spouse,       $b_city,         $b_state,
                    $b_zip,          $b_phone1type,   $b_phone1number,
                    $b_phone2type,   $b_phone2number, $b_phone3type,
                    $b_phone3number, $b_faxnumber,    $b_email,
                    $b_emailtwo,     $b_notes
                )
                = $ddasth->fetchrow_array()
              )
            {

                $b_firstname = substr( $b_firstname, 0, 5 );
                $b_spouse    = substr( $b_spouse,    0, 5 );
                if ($b_spouse) {
                    $b_lastname = substr( $b_lastname, 0, 1 );
                    $b_lastname .= ".";
                }
                else {
                    $b_lastname = substr( $b_lastname, 0, 8 );
                }

                if ( $b_spouse ne "" ) {
                    $b_spouse = " & $b_spouse ";
                }
                else {
                    $b_spouse = "";
                }
                print qq~
			<img src="images/dot.gif" height="7" width="15"> <a href="contacts.idx?action=overview_contact&agent=$Cook{agentid}&contactid=$b_contactid">$b_firstname$b_spouse $b_lastname</a><br>
		~;
                $bfound = "yes";
            }
        }

        unless ( $bfound eq "yes" ) {
            print qq~
	<img src="images/myhomes/show.gif" width="10" height="8"> <a href="transactions.idx?action=assign_contact&transid=$id&agent=$agent&contact_type=Buyer&address=$addressnumber $addressdirection $addressstreet">Create/Assign</a>
~;
        }

#####################################################
        print qq~
</b></font></td>
<td valign="top"><font color="navy"><b>
~;
######### GET SELLER INFORMATION #####################

        my $sbaasth =
          $dbh->prepare(
"select contactid from trans_boardtranstocontact WHERE transid = '$id' AND type = 'Seller'"
          );
        $sbaasth->execute;
        while ( ($tempcontactid) = $sbaasth->fetchrow_array() ) {

            my $sddasth =
              $dbh->prepare(
"select id,agent,type,firstname,lastname,address,spouse,city,state,zip,phone1type,phone1number,phone2type,phone2number,phone3type,phone3number,faxnumber,email,emailtwo,notes from trans_boardcontact WHERE id = '$tempcontactid'"
              );
            $sddasth->execute;

            while (
                (
                    $s_contactid,    $s_agent,        $s_type,
                    $s_firstname,    $s_lastname,     $s_address,
                    $s_spouse,       $s_city,         $s_state,
                    $s_zip,          $s_phone1type,   $s_phone1number,
                    $s_phone2type,   $s_phone2number, $s_phone3type,
                    $s_phone3number, $s_faxnumber,    $s_email,
                    $s_emailtwo,     $s_notes
                )
                = $sddasth->fetchrow_array()
              )
            {

                $s_firstname = substr( $s_firstname, 0, 5 );
                $s_spouse    = substr( $s_spouse,    0, 5 );
                if ($s_spouse) {
                    $s_lastname = substr( $s_lastname, 0, 1 );
                    $s_lastname .= ".";
                }
                else {
                    $s_lastname = substr( $s_lastname, 0, 8 );
                }

                if ( $s_spouse ne "" ) {
                    $s_spouse = " & $s_spouse ";
                }
                else {
                    $s_spouse = "";
                }

                $sfound = "no";
                print qq~
			<img src="images/dot.gif" height="7" width="15"> <a href="contacts.idx?action=overview_contact&agent=$Cook{agentid}&contactid=$s_contactid">$s_firstname$s_spouse $s_lastname</a><br>
		~;
                $sfound = "yes";
            }
        }

        unless ( $sfound eq "yes" ) {
            print qq~
	<img src="images/myhomes/show.gif" width="10" height="8"> <a href="transactions.idx?action=assign_contact&transid=$id&agent=$agent&contact_type=Seller&address=$addressnumber $addressdirection $addressstreet">Create/Assign</a><br>
~;
        }

#####################################################
        print qq~</b></font></td>
<td valign="top"><font color="navy"><b><center><a href="transactions.idx?action=overview&transid=$id&agent=$agent"><img src="images/trans_sys/button_view.gif" alt="View $addressnumber $addressdirection $addressstreet" border="0"></a> <a href="transactions.idx?action=edit_transaction&transid=$id&agent=$agent"><img src="images/trans_sys/button_edit.gif" alt="Edit $addressnumber $addressdirection $addressstreet" border="0"></a><br></center></b></font></td>
</tr>
~;
        $found = "yes";
    }

    unless ( $found eq "yes" ) {
        print qq~
<tr>
<td colspan="6">
	<font size="3" face="Arial" color="Red"><b>No transactions found.  You may try another search.</b></font>
</td>
</tr>
~;
    }

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

}

sub overview {

    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" ) {

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

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

        &Log(qq~Note Added For Transaction: $INPUT{address} - $INPUT{notes}~)
          ;    # routine at the bottom of config.idx

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

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

            $notes =
"<i>Listing note added to $INPUT{address} by $generateaddedby:</i><br>";
            $notes .= "$INPUT{notes}";

            @insert_vars =
              ( $Cook{agentid}, TransactionSystem, None, $good_date, $notes );

            $tsql_query =
              "insert into todo values ('',?,?,?,?,?,'$INPUT{todo_mark}')";
            $yasth = $dbh->do( $tsql_query, undef, @insert_vars );
        }

    }

    print qq~
<html>
<head>
<title>My Transactions Overview -- Eagle Real Estate, Inc. - Connect.EagleSold.com</title>
~;

    &header;

    print qq~
<td valign="top" width="581">
<img src="images/headers/transaction_manager.gif" height="33" width="581" alt="My Transaction Manager"><br><br>
<img src="images/trans_sys/my_transactionoverview.gif" alt="My Transaction Overview"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Navigation:</b> <a href="transactions.idx?agent=$Cook{agentid}">go to transactions</a><br>
~;

    my $aasth =
      $dbh->prepare(
"select id,agent,mlsnumber,selleragent,sellercoagent,buyeragent,buyercoagent,type,status,listingclass,addressnumber,addressdirection,addressstreet,city,state,zip,listingdate,expiredate,listingprice,showinginstructions,notes,pendingdate,earnestmoneyreceived,earnestmoneydollar,earnestmoneyheldat,inspectionresponsedays,estimatedclosingdate,soldprice,solddate from trans_board WHERE id = '$INPUT{transid}'"
      );
    $aasth->execute;
    while (
        (
            $id,                   $agent,
            $mlsnumber,            $selleragent,
            $sellercoagent,        $buyeragent,
            $buyercoagent,         $type,
            $status,               $listingclass,
            $addressnumber,        $addressdirection,
            $addressstreet,        $city,
            $state,                $zip,
            $listingdate,          $expiredate,
            $listingprice,         $showinginstructions,
            $notes,                $pendingdate,
            $earnestmoneyreceived, $earnestmoneydollar,
            $earnestmoneyheldat,   $inspectionresponsedays,
            $estimatedclosingdate, $soldprice,
            $solddate
        )
        = $aasth->fetchrow_array()
      )
    {

        my $zaasth =
          $dbh->prepare(
"select id,firstname,lastname,company from trans_boarddirectory where id = '$selleragent'"
          );
        $zaasth->execute;

        my $azaasth =
          $dbh->prepare(
"select id,firstname,lastname,company from trans_boarddirectory where id = '$sellercoagent'"
          );
        $azaasth->execute;

        my $bzaasth =
          $dbh->prepare(
"select id,firstname,lastname,company from trans_boarddirectory where id = '$buyeragent'"
          );
        $bzaasth->execute;

        my $czaasth =
          $dbh->prepare(
"select id,firstname,lastname,company from trans_boarddirectory where id = '$buyercoagent'"
          );
        $czaasth->execute;

        my $bkasth =
          $dbh->prepare(
"select ADDDATE('$pendingdate', INTERVAL $inspectionresponsedays DAY)"
          );
        $bkasth->execute;
        while ( ($newdate) = $bkasth->fetchrow_array() ) {
            $inspectionresponsedate = $newdate;
        }

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

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

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

        if ( $listingprice eq "" ) {
            $listingprice = "Not Entered";
        }

        if ( $earnestmoneyreceived eq "0000-00-00 00:00:00" ) {
            $earnestmoneyreceived = "Not Received";
        }

        if ( $soldprice eq "" ) {
            $soldprice = "Not Entered";
        }

        if ( $inspectionresponsedate eq "" ) {
            $inspectionresponsedate = "Not Avail.";
        }

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

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

        print qq~
<br>

<table border="0" cellpadding="3" cellspacing="0" width="100%">
<tr>
~;

        if ( -e "/photos/muncie_in_meiar/thumbnail/meiarmls$mlsnumber\.jpg" ) {
            print qq~
<td valign="top">
<img src="http://www.munciemls.com/images/photos/thumbnail/meiarmls$mlsnumber.jpg"><br>
</td>
~;
        }
        print qq~
<td valign="top"><font size="4" face="Arial"><b>$addressnumber $addressdirection $addressstreet<br>$city, $state $zip</b></font><br><a href="http://connect.eaglesold.com/transactions.idx?action=edit_transaction&transid=$id&agent=$Cook{agentid}">Edit Transaction</a></td>
<td valign="top">
	<table border="0" cellpadding="3" cellspacing="0" width="100%">
	<tr>
	<td valign="top" bgcolor="navy" nowrap><font color="white" size="2"><b>Buyer(s)</b></font><br></td>
	</tr>
	</table>
~;
######### GET BUYER INFORMATION #####################

        my $bbaasth =
          $dbh->prepare(
"select contactid from trans_boardtranstocontact WHERE transid = '$INPUT{transid}' AND type = 'Buyer'"
          );
        $bbaasth->execute;
        while ( ($tempcontactid) = $bbaasth->fetchrow_array() ) {

            my $ddasth =
              $dbh->prepare(
"select id,agent,type,firstname,lastname,address,spouse,city,state,zip,phone1type,phone1number,phone2type,phone2number,phone3type,phone3number,faxnumber,email,emailtwo,notes from trans_boardcontact WHERE id = '$tempcontactid'"
              );
            $ddasth->execute;

            while (
                (
                    $b_contactid,    $b_agent,        $b_type,
                    $b_firstname,    $b_lastname,     $b_address,
                    $b_spouse,       $b_city,         $b_state,
                    $b_zip,          $b_phone1type,   $b_phone1number,
                    $b_phone2type,   $b_phone2number, $b_phone3type,
                    $b_phone3number, $b_faxnumber,    $b_email,
                    $b_emailtwo,     $b_notes
                )
                = $ddasth->fetchrow_array()
              )
            {

                if ( $b_spouse ne "" ) {
                    $b_spouse = " & $b_spouse ";
                }
                else {
                    $b_spouse = "";
                }
                print qq~
			<a href="transactions.idx?action=unassign_contact&transid=$id&agent=$agent&contactid=$b_contactid"><img src="images/unlink_contact.gif" height="8" width="10" border="0" alt="Unlink Contact From This Transaction"></a> <a href="contacts.idx?action=overview_contact&agent=$agent&contactid=$b_contactid">$b_firstname$b_spouse $b_lastname</a><br>
		~;
            }
            $bfound = "yes";
        }
        if ( $bfound eq "yes" ) {
            print qq~
			<br><a href="transactions.idx?action=assign_contact&transid=$id&agent=$agent&contact_type=Buyer&address=$addressdirection $addressnumber $addressstreet">Assign Another Buyer</a><br>
		~;
        }

        unless ( $bfound eq "yes" ) {
            print qq~
	<a href="transactions.idx?action=assign_contact&transid=$id&agent=$agent&contact_type=Buyer&address=$addressnumber $addressdirection $addressstreet">Assign Buyer</a>
~;
        }
#####################################################
        print qq~
</td>
<td valign="top">
	<table border="0" cellpadding="3" cellspacing="0" width="100%">
	<tr>
	<td valign="top" bgcolor="navy" nowrap><font color="white" size="2"><b>Seller(s)</b></font><br></td>
	</tr>
	</table>
~;
######### GET SELLER INFORMATION #####################

        my $sbaasth =
          $dbh->prepare(
"select contactid from trans_boardtranstocontact WHERE transid = '$INPUT{transid}' AND type = 'Seller'"
          );
        $sbaasth->execute;
        while ( ($tempcontactid) = $sbaasth->fetchrow_array() ) {

            my $sddasth =
              $dbh->prepare(
"select id,agent,type,firstname,lastname,address,spouse,city,state,zip,phone1type,phone1number,phone2type,phone2number,phone3type,phone3number,faxnumber,email,emailtwo,notes from trans_boardcontact WHERE id = '$tempcontactid'"
              );
            $sddasth->execute;

            while (
                (
                    $s_contactid,    $s_agent,        $s_type,
                    $s_firstname,    $s_lastname,     $s_address,
                    $s_spouse,       $s_city,         $s_state,
                    $s_zip,          $s_phone1type,   $s_phone1number,
                    $s_phone2type,   $s_phone2number, $s_phone3type,
                    $s_phone3number, $s_faxnumber,    $s_email,
                    $s_emailtwo,     $s_notes
                )
                = $sddasth->fetchrow_array()
              )
            {

                if ( $s_spouse ne "" ) {
                    $s_spouse = " & $s_spouse ";
                }
                else {
                    $s_spouse = "";
                }

                print qq~
			<a href="transactions.idx?action=unassign_contact&transid=$id&agent=$agent&contactid=$s_contactid"><img src="images/unlink_contact.gif" height="8" width="10" border="0" alt="Unlink This Contact From This Transaction"></a> <a href="contacts.idx?action=overview_contact&agent=$agent&contactid=$s_contactid">$s_firstname$s_spouse $s_lastname</a><br>
		~;
            }
            $sfound = "yes";
        }
        if ( $sfound eq "yes" ) {
            print qq~
			<br><a href="transactions.idx?action=assign_contact&transid=$id&agent=$agent&contact_type=Seller&address=$addressnumber $addressdirection $addressstreet">Assign Another Seller</a><br>
		~;
        }

        unless ( $sfound eq "yes" ) {
            print qq~
	<a href="transactions.idx?action=assign_contact&transid=$id&agent=$agent&contact_type=Seller&address=$addressnumber $addressdirection $addressstreet">Assign Seller</a>
~;
        }
#####################################################
        print qq~
</td>
</tr>
</table>
<br>
<table border="0" cellpadding="4" cellspacing="0" width="581">
<tr>
<td valign="top" width="131" bgcolor="#CCFFCC" align="right">
<font color="#009900">
<b>Type</b><br>
<a href="http://connect.eaglesold.com/transactions.idx?action=edit_transaction&transid=$id&agent=$Cook{agentid}">$type</a><br>
<b>Status</b><br>
<a href="http://connect.eaglesold.com/transactions.idx?action=edit_transaction&transid=$id&agent=$Cook{agentid}">$status</a><br>
<b>Listing Class</b><br>
<a href="http://connect.eaglesold.com/transactions.idx?action=edit_transaction&transid=$id&agent=$Cook{agentid}">$listingclass</a><br>
<b>MLS Number</b><br>
<a href="http://connect.eaglesold.com/transactions.idx?action=edit_transaction&transid=$id&agent=$Cook{agentid}">$mlsnumber</a><br>
<b>Listing Date</b><br>
<a href="http://connect.eaglesold.com/transactions.idx?action=edit_transaction&transid=$id&agent=$Cook{agentid}">$listingdate</a><br>
<b>Expire Date</b><br>
<a href="http://connect.eaglesold.com/transactions.idx?action=edit_transaction&transid=$id&agent=$Cook{agentid}">$expiredate</a><br>
<b>Listing Price</b><br>
<a href="http://connect.eaglesold.com/transactions.idx?action=edit_transaction&transid=$id&agent=$Cook{agentid}">$listingprice</a><br>
<b>Pending Date</b><br>
<a href="http://connect.eaglesold.com/transactions.idx?action=edit_transaction&transid=$id&agent=$Cook{agentid}">$pendingdate</a><br>
<b>Earnest Money</b><br>
Received<br>
<a href="http://connect.eaglesold.com/transactions.idx?action=edit_transaction&transid=$id&agent=$Cook{agentid}">$earnestmoneyreceived</a><br>
~;
        unless ( $earnestmoneyreceived eq "Not Received" ) {
            print qq~
Amount<br><a href="http://connect.eaglesold.com/transactions.idx?action=edit_transaction&transid=$id&agent=$Cook{agentid}">\$$earnestmoneydollar</a><br>
Held At<br><a href="http://connect.eaglesold.com/transactions.idx?action=edit_transaction&transid=$id&agent=$Cook{agentid}">$earnestmoneyheldat</a><br>
~;
        }
        print qq~
<b>Inspection Response</b><br>
<a href="http://connect.eaglesold.com/transactions.idx?action=edit_transaction&transid=$id&agent=$Cook{agentid}">$inspectionresponsedate</a><br>
<b>Estimated Closing Date</b><br>
<a href="http://connect.eaglesold.com/transactions.idx?action=edit_transaction&transid=$id&agent=$Cook{agentid}">$estimatedclosingdate</a><br>
<b>Sold Price</b><br>
<a href="http://connect.eaglesold.com/transactions.idx?action=edit_transaction&transid=$id&agent=$Cook{agentid}">$soldprice</a><br>
<b>Sold Date</b><br>
<a href="http://connect.eaglesold.com/transactions.idx?action=edit_transaction&transid=$id&agent=$Cook{agentid}">$solddate</a><br>
<b>Notes</b><br>
<a href="http://connect.eaglesold.com/transactions.idx?action=edit_transaction&transid=$id&agent=$Cook{agentid}">$notes</a><br>
<b>Seller Agent</b><br>
~;
        if ( $selleragent eq "0" ) {
            print qq~
<a href="http://connect.eaglesold.com/transactions.idx?action=edit_transaction&transid=$id&agent=$Cook{agentid}">$selleragent</a><br>
~;
        }
        else {
            while (
                (
                    $listagentid,       $listagentfirstname,
                    $listagentlastname, $listagentcompany
                )
                = $zaasth->fetchrow_array()
              )
            {
                print qq~
<a href="http://connect.eaglesold.com/transactions.idx?action=directory_view&agent=$Cook{agentid}&directoryid=$listagentid">$listagentfirstname $listagentlastname</a><br>
~;
            }
        }

        if ( $sellercoagent eq "0" ) {
            print qq~
~;
        }
        else {
            while (
                (
                    $sclistagentid,       $sclistagentfirstname,
                    $sclistagentlastname, $sclistagentcompany
                )
                = $azaasth->fetchrow_array()
              )
            {
                print qq~
<a href="http://connect.eaglesold.com/transactions.idx?action=directory_view&agent=$Cook{agentid}&directoryid=$sclistagentid">$sclistagentfirstname $sclistagentlastname</a><br>
~;
            }
        }
        print qq~
<b>Buyer Agent</b><br>
~;
        if ( $buyeragent eq "0" ) {
            print qq~
<a href="http://connect.eaglesold.com/transactions.idx?action=edit_transaction&transid=$id&agent=$Cook{agentid}">No Agent Assigned</a><br>
~;
        }
        else {
            while (
                (
                    $blistagentid,       $blistagentfirstname,
                    $blistagentlastname, $blistagentcompany
                )
                = $bzaasth->fetchrow_array()
              )
            {
                print qq~
<a href="http://connect.eaglesold.com/transactions.idx?action=directory_view&agent=$Cook{agentid}&directoryid=$blistagentid">$blistagentfirstname $blistagentlastname</a><br>
~;
            }
        }

        if ( $buyercoagent eq "0" ) {
            print qq~
~;
        }
        else {
            while (
                (
                    $bclistagentid,       $bclistagentfirstname,
                    $bclistagentlastname, $bclistagentcompany
                )
                = $czaasth->fetchrow_array()
              )
            {
                print qq~
<a href="http://connect.eaglesold.com/transactions.idx?action=directory_view&agent=$Cook{agentid}&directoryid=$bclistagentid">$bclistagentfirstname $bclistagentlastname</a><br>
~;
            }
        }
        print qq~
</font>
</td>
<td valign="top" width="450">
<center>
<table border="0" cellpadding="2" cellspacing="0" width="100%">
<tr>
<td colspan="2">
	<table border="0" cellpadding="1" cellspacing="0" width="100%">
	<tr>
	<td valign="top" width="65%">
		<table border="0" cellpadding="3" cellspacing="0" width="100%">
<tr>
<td valign="top" bgcolor="navy" nowrap><font color="white" size="2"><b>My Notes</b></font><br></td>
<td valign="top" bgcolor="navy" align="right">
<table border="0" cellspacing="1" cellpadding="2" bgcolor="white">
<tr>
<td valign="top" bgcolor="silver">
View Notes Below<br>
</td>
</tr>
</table>
</td>
</tr>
</table>
		<iframe src="transactions.idx?action=overview_notes_show&transid=$id" width="100%" height="125" noresize="noresize" scrolling ="yes" frameborder="0" marginwidth="3" marginheight="3"></iframe>
	</td>
	<td valign="top" width="35%">
		<form method="get" action="transactions.idx">
		<input type="hidden" name="action" value="overview">
		<input type="hidden" name="transid" value="$INPUT{transid}">
		<input type="hidden" name="agent" value="$Cook{agentid}">
		<input type="hidden" name="addnote" value="1">
		<input type="hidden" name="address" value="$addressnumber $addressdirection $addressstreet">
		<textarea cols="35" rows="8" name="notes" class="form"></textarea><br>
		<b>Web Viewable:</b> <select name="viewable" class="form"><option value="BuyerSeller">Buyer&Seller</option><option value="Buyer">Buyer Only</option><option value="Seller">Seller Only</option><option value="Hidden">Hidden</option></select><br>
		<select name="todo" class="form">
		<option value="yes">ToDo</option>
		<option value="no">Hide</option></select><select name="todo_mark" class="form"><option value="y">Mark Done</option><option value="n">Not Done</option></select><input type="submit" value="Save" class="form">
		</form>		
	</td>
	</tr>
	</table>
</td>
</tr>
<tr>
<td colspan="2">
	<table border="0" cellpadding="1" cellspacing="0" width="440">
	<tr>
	<td valign="middle" bgcolor="navy" nowrap><font color="white" size="2"><b>Action Plans</b></font><br></td>
	<td valign="middle" bgcolor="navy" align="right">
	<table border="0" cellspacing="0" cellpadding="0" bgcolor="white">
	<tr>
	<td valign="top" bgcolor="white">
		<table border="0" cellpadding="2" cellspacing="1" width="100%">
			<tr>
				<td valign="top" bgcolor="white">
					<a href="transactions.idx?action=overview_tasks&idlink=$id&type=transaction&do=Apply" target="action_plans">Apply New Plan</a>
				</td>
				<td valign="top" bgcolor="white" align="right"><b>&nbsp;&nbsp;&nbsp;</b></td>
				<td valign="top" bgcolor="#ffcccc"><b>Due or Past Due</b></td>
				<td valign="top" bgcolor="#ccffcc"><b>Not Due</b></td>
				<td valign="top" bgcolor="#99ccff"><b>Completed</b></td>

			</tr>
		</table>
	</td>
	</tr>
	</table>
	</td>
	</tr>
	</table>
	<iframe src="transactions.idx?action=overview_tasks&idlink=$id&type=transaction&agent=$agent" width="440" height="110" name="action_plans" noresize="noresize" scrolling ="yes" frameborder="0" marginwidth="0" marginheight="0"></iframe>
</td>
</tr>
<tr>
<td colspan="2">
	<table border="0" cellpadding="3" cellspacing="0" width="440">
	<tr>
	<td valign="top" bgcolor="navy" nowrap><font color="white" size="2"><b>Document Center</b></font><br></td>
	<td valign="top" bgcolor="navy" align="right">
	<table border="0" cellspacing="1" cellpadding="2" bgcolor="white">
	<tr>
	<td valign="top" bgcolor="silver">
	View or Upload Documents<br>
	</td>
	</tr>
	</table>
	</td>
	</tr>
	</table>
	<table border="0" cellpadding="0" cellspacing="0" width="440">
	<tr>
	<td valign="top" width="220">
		<iframe src="transactions.idx?action=overview_documents&transid=$id" width="220" height="90" noresize="noresize" scrolling ="yes" frameborder="0" marginwidth="0" marginheight="0" name="documents"></iframe>
	</td>
		<FORM action="upload_doc.idx" encType="multipart/form-data" method="post" target="documents"  name="upload">
		<input type="hidden" name="matchid" value="$id" class="form">
		<input type="hidden" name="matchcat" value="t" class="form">
	<td valign="top" width="220">
<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>
~;
        if ( $type eq 'BSP' or $type eq 'Listing' or $type eq 'SP' ) {
            print qq~
<tr>
<td colspan="2">
	<table border="0" cellpadding="3" cellspacing="0" width="440">
	<tr>
	<td valign="top" bgcolor="navy" nowrap><font color="white" size="2"><b>Showing Information</b></font><br></td>
	<td valign="top" bgcolor="navy" align="right">
	<table border="0" cellspacing="1" cellpadding="2" bgcolor="white">
	<tr>
	<td valign="top" bgcolor="silver">
	<br>
	</td>
	</tr>
	</table>
	</td>
	</tr>
	</table>
	<iframe src="transactions.idx?action=overview_showings&mlsnumber=$mlsnumber" width="440" height="110" noresize="noresize" scrolling ="yes" frameborder="0" marginwidth="0" marginheight="0"></iframe>
<br><b>Showing Instructions:</b> $showinginstructions<br><br>
</td>
</tr>
~;
        }
        if ( $type eq 'BSP' or $type eq 'Listing' or $type eq 'SP' ) {
            print qq~
<tr>
<td colspan="2">
	<table border="0" cellpadding="0" cellspacing="2" width="440" bgcolor="navy">
		<tr>
			<td colspan="2" valign="top" bgcolor="navy" nowrap><font color="white" size="2"><b>Listing Prospects</b></font><br></td>
		</tr>
		<tr>
			<td valign="top" bgcolor="navy" align="right">
				<table border="0" cellspacing="1" cellpadding="2" width="100%" bgcolor="white">
				<tr>
				<td valign="top" bgcolor="silver">
				<b>AD Call Prospects</b>
				<br>
				</td>
				</tr>
				</table>
			</td>
			<td valign="top" bgcolor="navy" align="right">
				<table border="0" cellspacing="1" cellpadding="2" width="100%" bgcolor="white">
				<tr>
				<td valign="top" bgcolor="silver">
				<b>MuncieMLS Prospects
~;

            my $countasth =
              $dbh->prepare(
                "select count(userid) from hits where mlsnumber = '$mlsnumber'"
              );
            $countasth->execute;
            while ( ($hits) = $countasth->fetchrow_array() ) {
                print qq~
				[ $hits Views ]
				~;
            }
            print qq~
</b>
				<br>
				</td>
				</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td valign="top" bgcolor="white" align="right">
	<iframe src="transactions.idx?action=overview_prospects&transid=$id&agent=$agent" width="220" height="110" noresize="noresize" scrolling ="yes" frameborder="0" marginwidth="0" marginheight="0"></iframe>
			</td>
			<td valign="top" bgcolor="white" align="right">
	<iframe src="transactions.idx?action=overview_stats&mlsnumber=$mlsnumber&agent=$agent" width="220" height="110" noresize="noresize" scrolling ="yes" frameborder="0" marginwidth="0" marginheight="0"></iframe>
			</td>
		</tr>
	</table>
<br><br>
</td>
</tr>
~;
        }

        print qq~
<tr>
<td valign="top" width="50%">
	<iframe src="transactions.idx?action=overview_mortgage&transid=$id&agent=$agent" width="220" height="160" noresize="noresize" scrolling ="no" frameborder="0" marginwidth="0" marginheight="0"></iframe>
</td>
<td valign="top" width="50%">
	<iframe src="transactions.idx?action=overview_titlework&transid=$id&agent=$agent" width="220" height="160" noresize="noresize" scrolling ="no" frameborder="0" marginwidth="0" marginheight="0"></iframe>
</td>
</tr>
<tr>
<td valign="top" width="50%">
	<iframe src="transactions.idx?action=overview_inspections&transid=$id" width="220" height="220" noresize="noresize" scrolling ="no" frameborder="0" marginwidth="0" marginheight="0"></iframe>
</td>
<td valign="top" width="50%">
	<iframe src="transactions.idx?action=overview_survey&transid=$id&agent=$agent" width="220" height="220" noresize="noresize" scrolling ="no" frameborder="0" marginwidth="0" marginheight="0"></iframe>
</td>
</tr>
</table>
</center>
</td>
</tr>
</table>
~;
    }
    print qq~
</td>
~;
    &footer;

}

sub overview_mortgage_fa {

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

    my $aasth = $dbh->prepare(
        "select id from trans_boardmortgage WHERE id = '$INPUT{transid}'");
    $aasth->execute;
    while ( ($id) = $aasth->fetchrow_array() ) {
        $found = "yes";
    }

    unless ( $found ne "yes" ) {
        $btntype =
"<a href=\"transactions.idx?action=overview_mortgage_edit&transid=$INPUT{transid}&edit=1\">Edit</a>";
    }
    else {
        $btntype =
"<a href=\"transactions.idx?action=overview_mortgage&transid=$INPUT{transid}&add=1\">Add</a>";
    }

    print qq~
<html>
<head>
<title>Mortgage Information in Overview</title>
<link rel="stylesheet" TYPE="text/css" href="includes/style.css">
<script language="JavaScript" src="calendar1.js"></script>
<script language="JavaScript" src="calendar2.js"></script>
</head>
<body bgcolor="white" leftMargin="0" topMargin="0" marginwidth="0" marginheight="0">
<table border="0" cellpadding="3" cellspacing="0" width="100%">
<tr>
<td valign="top" bgcolor="navy" nowrap><font color="white" size="2"><b>Mortgage Information</b></font><br></td>
<td valign="top" bgcolor="navy" align="right">
<table border="0" cellspacing="1" cellpadding="2" bgcolor="white">
<tr>
<td valign="top" bgcolor="silver">
$btntype<br>
</td>
</tr>
</table>
</td>
</tr>
</table>
~;

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

        @variables = ( $INPUT{finalapprovaldate}, $INPUT{transid} );
        $sql_query =
          "update trans_boardmortgage set finalapproval = ? where id = ?";
        my $aasth = $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/transactions.idx?action=overview_mortgage&transid=$INPUT{transid}">
</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/transactions.idx?action=overview_mortgage&transid=$INPUT{transid}">Click Here</a>.</center>
</body>
</html>
~;

    }
    else {
        print qq~
<font size="3"><b>Select Final Approval Date</b>
				<form method="get" name="transactions" action="transactions.idx">
				<input type="hidden" name="action" value="overview_mortgage_fa">
				<input type="hidden" name="transid" value="$INPUT{transid}">
				<input type="hidden" name="do" value="1">
				Select Date<br>
				<input type="Text" name="finalapprovaldate" value="" class="form">
				<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><br>
				<input type="submit" value="Submit Date" class="form">
				</form>
			<script language="JavaScript">

				var cal1 = new calendar1(document.forms['transactions'].elements['finalapprovaldate']);
				cal1.year_scroll = true;
				cal1.time_comp = false;

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

~;
}

sub overview_mortgage_edit {

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

    my $aasth = $dbh->prepare(
        "select id from trans_boardmortgage WHERE id = '$INPUT{transid}'");
    $aasth->execute;
    while ( ($id) = $aasth->fetchrow_array() ) {
        $found = "yes";
    }

    unless ( $found ne "yes" ) {
        $btntype =
"<a href=\"transactions.idx?action=overview_mortgage_edit&transid=$INPUT{transid}&edit=1\">Edit</a>";
    }
    else {
        $btntype =
"<a href=\"transactions.idx?action=overview_mortgage&transid=$INPUT{transid}&add=1\">Add</a>";
    }

    print qq~
<html>
<head>
<title>Mortgage Information in Overview</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="3" cellspacing="0" width="100%">
<tr>
<td valign="top" bgcolor="navy" nowrap><font color="white" size="2"><b>Mortgage Information</b></font><br></td>
<td valign="top" bgcolor="navy" align="right">
<table border="0" cellspacing="1" cellpadding="2" bgcolor="white">
<tr>
<td valign="top" bgcolor="silver">
$btntype<br>
</td>
</tr>
</table>
</td>
</tr>
</table>
~;

    if ( $INPUT{edit} eq "1" ) {
        my $aasth =
          $dbh->prepare(
"select id,loantype,company,phone,fax,loanofficer,lophone,processor,finalapproval,notes from trans_boardmortgage WHERE id = '$INPUT{transid}'"
          );
        $aasth->execute;
        while (
            (
                $id,            $loantype,    $company, $phone,
                $fax,           $loanofficer, $lophone, $processor,
                $finalapproval, $notes
            )
            = $aasth->fetchrow_array()
          )
        {
            print qq~
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2"><b><font size="3" face="Arial">Step 1 of 3</font></b></td>
</tr>
<tr>
<td><b>Company</b></td>
<td><form method="get" action="transactions.idx">
<input type="hidden" name="action" value="overview_mortgage_edit">
<input type="hidden" name="transid" value="$INPUT{transid}">
<input type="hidden" name="edit" value="2"><input type="text" name="company" value="$company" class="form"><br></td>
</tr>
<tr>
<td><b>Loan Officer</b></td>
<td><input type="text" name="loanofficer" value="$loanofficer" class="form"><br></td>
</tr>
<tr>
<td><b>Co Phone</b></td>
<td><input type="text" name="phone" value="$phone" class="form"><br></td>
</tr>
<td><b>Co Fax</b></td>
<td><input type="text" name="fax" value="$fax" class="form"><br></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="Next / Step 2" class="form"></form><br></td>
</tr>
</table>
~;
        }
    }
    elsif ( $INPUT{edit} eq "2" ) {
        my $aasth =
          $dbh->prepare(
"select id,loantype,company,phone,fax,loanofficer,lophone,processor,finalapproval,notes from trans_boardmortgage WHERE id = '$INPUT{transid}'"
          );
        $aasth->execute;
        while (
            (
                $id,            $loantype,    $company, $phone,
                $fax,           $loanofficer, $lophone, $processor,
                $finalapproval, $notes
            )
            = $aasth->fetchrow_array()
          )
        {
            print qq~
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2"><b><font size="3" face="Arial">Step 2 of 3</font></b></td>
</tr>
<tr>
<td><b>Lo Phone</b></td>
<td><form method="get" action="transactions.idx">
<input type="hidden" name="action" value="overview_mortgage_edit">
<input type="hidden" name="transid" value="$INPUT{transid}">
<input type="hidden" name="edit" value="3">
<input type="hidden" name="company" value="$INPUT{company}">
<input type="hidden" name="loanofficer" value="$INPUT{loanofficer}">
<input type="hidden" name="phone" value="$INPUT{phone}">
<input type="hidden" name="fax" value="$INPUT{fax}">
<input type="text" name="lophone" value="$lophone" class="form"><br>
</td>
</tr>
<tr>
<td><b>Processor</b></td>
<td><input type="text" name="processor" value="$processor" class="form"><br></td>
</tr>
<tr>
<td><b>Loan Type</b></td>
<td><input type="text" name="loantype" value="$loantype" class="form"><br></td>
</tr>
<td valign="top"><b>Notes</b></td>
<td><textarea cols="23" rows="2" name="notes" class="form">$notes</textarea><br></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="Next / Step 3" class="form"></form><br></td>
</tr>
</table>
~;
        }
    }
    elsif ( $INPUT{edit} eq "3" ) {

        $INPUT{loantype}    =~ s/\"//gi;
        $INPUT{loantype}    =~ s/\'//gi;
        $INPUT{company}     =~ s/\"//gi;
        $INPUT{company}     =~ s/\'//gi;
        $INPUT{phone}       =~ s/\"//gi;
        $INPUT{phone}       =~ s/\'//gi;
        $INPUT{fax}         =~ s/\"//gi;
        $INPUT{fax}         =~ s/\'//gi;
        $INPUT{loanofficer} =~ s/\"//gi;
        $INPUT{loanofficer} =~ s/\'//gi;
        $INPUT{lophone}     =~ s/\"//gi;
        $INPUT{lophone}     =~ s/\'//gi;
        $INPUT{processor}   =~ s/\"//gi;
        $INPUT{processor}   =~ s/\'//gi;
        $INPUT{notes}       =~ s/\"//gi;
        $INPUT{notes}       =~ s/\'//gi;

        @variables = (
            $INPUT{loantype},  $INPUT{company},     $INPUT{phone},
            $INPUT{fax},       $INPUT{loanofficer}, $INPUT{lophone},
            $INPUT{processor}, $INPUT{notes},       $INPUT{transid}
        );
        $sql_query =
"update trans_boardmortgage set loantype = ?, company = ?, phone = ?, fax = ?, loanofficer = ?, lophone = ?, processor = ?, notes = ? where id = ?";
        my $aasth = $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/transactions.idx?action=overview_mortgage&transid=$INPUT{transid}">
</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/transactions.idx?action=overview_mortgage&transid=$INPUT{transid}">Click Here</a>.</center>
</body>
</html>
~;
    }
    else {
        my $aasth =
          $dbh->prepare(
"select id,loantype,company,phone,fax,loanofficer,lophone,processor,finalapproval,notes from trans_boardmortgage WHERE id = '$INPUT{transid}'"
          );
        $aasth->execute;
        while (
            (
                $id,            $loantype,    $company, $phone,
                $fax,           $loanofficer, $lophone, $processor,
                $finalapproval, $notes
            )
            = $aasth->fetchrow_array()
          )
        {
            if ( $finalapproval eq "0000-00-00" ) {
                $finalapproval =
                  "<a href=\"transactions.idx\">[ Received ]</a>";
            }
            print qq~
	<b>Loan Type</b> $loantype<br>
	<b>$company</b> $loanofficer<br>
	<b>Co Phone</b> $phone<br>
	<b>Loan Officer Phone</b> $lophone<br>
	<b>Fax</b> $fax<br>
	<b>Processor</b> $processor<br>
	<b>Final Approval Date</b> $finalapproval<br>
	<b>Notes</b> $notes<br>
	~;
            $found = "yes";
        }

        unless ( $found eq "yes" ) {
            print qq~
	Mortgage Information Has Not Been Entered Yet.  <a href="transactions.idx?action=overview_mortgage&transid=$INPUT{transid}&add=1">Add Info</a>
	~;
        }
    }

    print qq~
</body>
</html>

~;

}

sub overview_mortgage {

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

    my $aasth = $dbh->prepare(
        "select id from trans_boardmortgage WHERE id = '$INPUT{transid}'");
    $aasth->execute;
    while ( ($id) = $aasth->fetchrow_array() ) {
        $found = "yes";
    }

    unless ( $found ne "yes" ) {
        $btntype =
"<a href=\"transactions.idx?action=overview_mortgage_edit&transid=$INPUT{transid}&edit=1\">Edit</a>";
    }
    else {
        $btntype =
"<a href=\"transactions.idx?action=overview_mortgage&transid=$INPUT{transid}&add=1\">Add</a>";
    }

    print qq~
<html>
<head>
<title>Mortgage Information in Overview</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="3" cellspacing="0" width="100%">
<tr>
<td valign="top" bgcolor="navy" nowrap><font color="white" size="2"><b>Mortgage Information</b></font><br></td>
<td valign="top" bgcolor="navy" align="right">
<table border="0" cellspacing="1" cellpadding="2" bgcolor="white">
<tr>
<td valign="top" bgcolor="silver">
$btntype<br>
</td>
</tr>
</table>
</td>
</tr>
</table>
~;

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

        print qq~
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2"><b><font size="3" face="Arial">Step 1 of 3</font></b></td>
</tr>
<tr>
<td><b>Company</b></td>
<td><form method="get" action="transactions.idx">
<input type="hidden" name="action" value="overview_mortgage">
<input type="hidden" name="transid" value="$INPUT{transid}">
<input type="hidden" name="add" value="2"><input type="text" name="company" class="form"><br></td>
</tr>
<tr>
<td><b>Loan Officer</b></td>
<td><input type="text" name="loanofficer" class="form"><br></td>
</tr>
<tr>
<td><b>Co Phone</b></td>
<td><input type="text" name="phone" class="form"><br></td>
</tr>
<td><b>Co Fax</b></td>
<td><input type="text" name="fax" class="form"><br></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="Next / Step 2" class="form"></form><br></td>
</tr>
</table>
~;

    }
    elsif ( $INPUT{add} eq "2" ) {
        print qq~
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2"><b><font size="3" face="Arial">Step 2 of 3</font></b></td>
</tr>
<tr>
<td><b>Lo Phone</b></td>
<td><form method="get" action="transactions.idx">
<input type="hidden" name="action" value="overview_mortgage">
<input type="hidden" name="transid" value="$INPUT{transid}">
<input type="hidden" name="add" value="3">
<input type="hidden" name="company" value="$INPUT{company}">
<input type="hidden" name="loanofficer" value="$INPUT{loanofficer}">
<input type="hidden" name="phone" value="$INPUT{phone}">
<input type="hidden" name="fax" value="$INPUT{fax}">
<input type="text" name="lophone" class="form"><br>
</td>
</tr>
<tr>
<td><b>Processor</b></td>
<td><input type="text" name="processor" class="form"><br></td>
</tr>
<tr>
<td><b>Loan Type</b></td>
<td><input type="text" name="loantype" class="form"><br></td>
</tr>
<td valign="top"><b>Notes</b></td>
<td><textarea cols="23" rows="2" name="notes" class="form"></textarea><br></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="Next / Step 3" class="form"></form><br></td>
</tr>
</table>
~;
    }
    elsif ( $INPUT{add} eq "3" ) {

        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;

        @variables = (
            $INPUT{transid}, $INPUT{loantype},  $INPUT{company},
            $INPUT{phone},   $INPUT{fax},       $INPUT{loanofficer},
            $INPUT{lophone}, $INPUT{processor}, $INPUT{notes}
        );

        $sql_query =
          "INSERT INTO trans_boardmortgage values (?,?,?,?,?,?,?,?,'',?)";
        my $aasth = $dbh->do( $sql_query, undef, @variables );
        print qq~
Successfully Entered!<br>
<br>
<center><a href="transactions.idx?action=overview_mortgage&transid=$INPUT{transid}">FINISH</a></center>
~;
    }
    else {
        my $aasth =
          $dbh->prepare(
"select id,loantype,company,phone,fax,loanofficer,lophone,processor,finalapproval,notes from trans_boardmortgage WHERE id = '$INPUT{transid}'"
          );
        $aasth->execute;
        while (
            (
                $id,            $loantype,    $company, $phone,
                $fax,           $loanofficer, $lophone, $processor,
                $finalapproval, $notes
            )
            = $aasth->fetchrow_array()
          )
        {
            if ( $finalapproval eq "0000-00-00" ) {
                $finalapproval =
"<a href=\"transactions.idx?action=overview_mortgage_fa&transid=$id\">[ Received ]</a>";
            }
            print qq~
	<table border="0" cellpadding="1" cellspacing="0" width="100%">

	<tr>
	<td><b>Loan Type</b></td>
	<td>$loantype<br></td>
	</tr>

	<tr bgcolor="#CCCCFF">
	<td><b>$company</b></td>
	<td>$loanofficer<br></td>
	</tr>

	<tr>
	<td><b>Co Phone</b></td>
	<td>$phone<br></td>
	</tr>

	<tr bgcolor="#CCCCFF">
	<td><b>Loan Officer Phone</b></td>
	<td>$lophone<br></td>
	</tr>

	<tr>
	<td><b>Fax</b></td>
	<td>$fax<br></td>
	</tr>

	<tr bgcolor="#CCCCFF">
	<td><b>Processor</b></td>
	<td>$processor<br></td>
	</tr>

	<tr>
	<td><b>Final Approval Date</b></td>
	<td>$finalapproval<br></td>
	</tr>

	<tr bgcolor="#CCCCFF">
	<td><b>Notes</b></td>
	<td>$notes<br></td>
	</tr>
	</table>
	~;
            $found = "yes";
        }

        unless ( $found eq "yes" ) {
            print qq~
	Mortgage Information Has Not Been Entered Yet.  <a href="transactions.idx?action=overview_mortgage&transid=$INPUT{transid}&add=1">Add Info</a>
	~;
        }
    }

    print qq~
</body>
</html>

~;

}

sub create_transaction {
#####VALUES id,agent,selleragent,sellercoagent,buyeragent,buyercoagent,type,status,addressnumber,addressdirection,addressstreet,city,state,zip,listingdate,expiredate,listingprice,notes,pendingdate,inspectionresponsedays,estimatedclosingdate,soldprice,solddate ####

    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>Create New Transaction -- Eagle Real Estate, Inc. - Connect.EagleSold.com</title>
~;

    &header;

    print qq~
<script language="JavaScript" src="calendar1.js"></script><!-- Date only with year scrolling -->
<script language="JavaScript" src="calendar2.js"></script><!-- Date only with year scrolling -->
<td valign="top" width="581">
<img src="images/headers/transaction_manager.gif" height="33" width="581" alt="My Transaction Manager"><br><br>
<img src="images/trans_sys/create_newtransheader.gif" alt="Create New Transaction"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>fill out the form below to create a new transaction</b><br><br>
<form method="post" name="transactions" action="transactions.idx">
<input type="hidden" name="action" value="create_transaction_verify">
<input type="hidden" name="agent" value="$Cook{agentid}">
	<table border="0" width="500" cellpadding="3" cellspacing="1">	
	<tr>
	<td colspan="2" bgcolor="black"><font color="white" size="2"><b><center>Transaction / Listing Information</b></font></td>
	</tr>
	<tr>
	<td valign="top"><b>Transaction</b></td>
	<td valign="top">
		<b>Status</b><br>
		<select name="status" class="form">
		<option value="Active">Active</option>
		<option value="Pending">Pending</option>
		<option value="Prospect">Listing Prospect</option>
		<option value="CLSD">Closed (SOLD)</option>
		<option value="Expired">Expired Listing</option>
		<option value="WTHD">Withdrawn (Release)</option>
		<option value="DEAD">Dead Deal (Not Closing)</option>
		</select><br>
		<b>Type</b><br>
		<select name="type" class="form">
		<option value="Listing">Listing</option>
		<option value="">-----------</option>
		<option value="BP">Buyer Side Sale</option>
		<option value="BSP">Buyer & Seller Side Sale</option>
		</select><br>
		<b>Listing Class</b><br>
		<select name="listingclass" class="form">
		<option value="Residential">Residential</option>
		<option value="Commercial">Commercial</option>
		<option value="LotsLand">Lots and Land</option>
		<option value="Investment">Investment</option>
		</select><br>
		<b>MLS Number</b><br>
		<input type="text" name="mlsnumber" size="10" class="form">
	</td>
	</tr>
	<tr>
	<td valign="top" bgcolor="#CCCCFF"><b>Property Address</b></td>
	<td valign="top" bgcolor="#CCCCFF">
		<b>Address</b><br>
		<input type="text" name="addressnumber" size="5" class="form"> <select name="addressdirection" class="form">
<option value="N">N</option>
<option value="NE">NE</option>
<option value="NW">NW</option>
<option value="S">S</option>
<option value="SE">SE</option>
<option value="SW">SW</option>
<option value="E">E</option>
<option value="W">W</option><option value="">None</option></select> <select name="addressstreet" class="form">
~;
    my $aaasth =
      $dbh->prepare("select address from address ORDER BY address ASC");
    $aaasth->execute;
    while ( ($pulladdress) = $aaasth->fetchrow_array() ) {
        $printaddress .=
          "<option value=\"$pulladdress\">$pulladdress</option>\n";
    }
    print qq~
$printaddress
</select><br>
		<b>City</b><br>
		<input type="text" name="city" size="20" class="form"><br>
		<b>State</b><br>
				<select name="state" class="form"><option value="Alabama">Alabama</option>
<option value="Alaska">Alaska</option>
<option value="Arizona">Arizona</option>
<option value="Arkansas">Arkansas</option>
<option value="California">California</option>
<option value="Colorado">Colorado</option> 
<option value="Connecticut">Connecticut</option>
<option value="Delaware">Delaware</option>
<option value="District of Columbia">District of Columbia</option>
<option value="Florida">Florida</option>
<option value="Georgia">Georgia</option>
<option value="Hawaii">Hawaii</option>
<option value="Idaho">Idaho</option>
<option value="Illinois">Illinois</option>
<option value="Indiana" selected>Indiana</option>
<option value="Iowa">Iowa</option>
<option value="Kansas">Kansas</option>
<option value="Kentucky">Kentucky</option>
<option value="Louisiana">Louisiana</option>
<option value="Maine">Maine</option>
<option value="Maryland">Maryland</option>
<option value="Massachusetts">Massachusetts</option>
<option value="Michigan">Michigan</option>
<option value="Minnesota">Minnesota</option>
<option value="Mississippi">Mississippi</option>
<option value="Missouri">Missouri</option>
<option value="Montana">Montana</option>
<option value="Nebraska">Nebraska</option>
<option value="Nevada">Nevada</option>
<option value="New Hampshire">New Hampshire</option>
<option value="New Jersey">New Jersey</option>
<option value="New Mexico">New Mexico</option>
<option value="New York">New York</option>
<option value="North Carolina">North Carolina</option>
<option value="North Dakota">North Dakota</option>
<option value="Ohio">Ohio</option>
<option value="Oklahoma">Oklahoma</option>
<option value="Oregon">Oregon</option>
<option value="Pennsylvania">Pennsylvania</option>
<option value="Rhode Island">Rhode Island</option>
<option value="South Carolina">South Carolina</option>
<option value="South Dakota">South Dakota</option>
<option value="Tennessee">Tennessee</option>
<option value="Texas">Texas</option>
<option value="Utah">Utah</option>
<option value="Vermont">Vermont</option>
<option value="Virgin Islands">Virgin Islands</option>
<option value="Virginia">Virginia</option>
<option value="Washington">Washington</option>
<option value="West Virginia">West Virginia</option>
<option value="Wisconsin">Wisconsin</option>
<option value="Wyoming">Wyoming</option></select><br>
		<b>Zip</b><br>
		<input type="text" name="zip" value="" size="5" class="form"><br>
	</td>
	</tr>
	<tr>
	<td valign="top"><b>Listing Date</b></td>
	<td valign="top">
				Select Date<br>
				<input type="Text" name="listingdate" value="" class="form">
				<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><br>
	</td>
	</tr>
	<tr>
	<td valign="top"><b>Expire Date</b></td>
	<td valign="top">
				Select Date<br>
				<input type="Text" name="expiredate" value="" class="form">
				<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><br>
	</td>
	</tr>
	<tr>
	<td valign="top"><b>Listing Price</b><br>If this property is not pending yet please skip.</td>
	<td valign="top">\$<input type="text" name="listingprice" class="form"></td>
	</tr>
	<tr>
	<td valign="top" bgcolor="#CCCCFF"><b>Listing Agent(s)</b><br>Choose To The Left</td>
	<td valign="top" bgcolor="#CCCCFF"><b>Primary Agent</b><br>
		<select name="selleragent" class="form">
		<option value="0">Select Agent From List Below</option>
		<option value="0">---------------------</option>
		~;
    my $zaasth =
      $dbh->prepare(
"select id,firstname,lastname,company from trans_boarddirectory ORDER BY company"
      );
    $zaasth->execute;
    while ( ( $sellerid, $sfirstname, $slastname, $scompany ) =
        $zaasth->fetchrow_array() )
    {

        if ( $slastname eq "Inactive Agent" ) {
        }
        else {
            print qq~
		<option value=\"$sellerid\">$scompany -- $slastname, $sfirstname</option>
		~;
        }
    }
    print qq~
		</select><br><br>

		<b>Listing Co Agent</b><br>
		<select name="sellercoagent" class="form">
		<option value="0">Select Or Leave Blank If No Co Agent</option>
		<option value="0">---------------------</option>
		~;
    my $azaasth =
      $dbh->prepare(
"select id,firstname,lastname,company from trans_boarddirectory ORDER BY company"
      );
    $azaasth->execute;
    while ( ( $csellerid, $csfirstname, $cslastname, $cscompany ) =
        $azaasth->fetchrow_array() )
    {

        if ( $cslastname eq "Inactive Agent" ) {
        }
        else {
            print qq~
		<option value=\"$csellerid\">$cscompany -- $cslastname, $csfirstname</option>
		~;
        }
    }
    print qq~
		</select>
	<br><br>
	</td>
	</tr>
	<tr>
	<td valign="top" bgcolor="#CCCCFF"><b>Buyer(s) Agent</b><br>Choose To The Left</td>
	<td valign="top" bgcolor="#CCCCFF">
		<b>Primary Agent</b><br>
		<select name="buyeragent" class="form">
		<option value="0">Select Or Leave Blank If No Buyer Agent Yet</option>
		<option value="0">---------------------</option>
	~;

    my $azaasth =
      $dbh->prepare(
"select id,firstname,lastname,company from trans_boarddirectory ORDER BY company"
      );
    $azaasth->execute;
    while ( ( $buyerid, $bfirstname, $blastname, $bcompany ) =
        $azaasth->fetchrow_array() )
    {
        if ( $blastname eq "Inactive Agent" ) {
        }
        else {
            print qq~
		<option value=\"$buyerid\">$bcompany -- $blastname, $bfirstname</option>
		~;
        }
    }

    print qq~
		</select><br><br>

		<b>Buyers Co Agent</b><br>
		<select name="buyercoagent" class="form">
		<option value="0">Select Or Leave Blank If No Buyer Co Agent</option>
		<option value="0">---------------------</option>
		~;
    my $cazaasth =
      $dbh->prepare(
"select id,firstname,lastname,company from trans_boarddirectory ORDER BY company"
      );
    $cazaasth->execute;
    while ( ( $cbellerid, $cbfirstname, $cblastname, $cbcompany ) =
        $cazaasth->fetchrow_array() )
    {

        if ( $cblastname eq "Inactive Agent" ) {
        }
        else {
            print qq~
		<option value=\"$cbellerid\">$cbcompany -- $cblastname, $cbfirstname</option>
		~;
        }
    }
    print qq~
		</select>
	<br><br>
	</td>
	</tr>
	<tr>
	<td valign="top"><b>Showing Instructions</b><br>You <u><b>MUST</b></u> enter detailed showing instructions for all listings.  Please include names and numbers of people who should be notified to setup showing.</td>
	<td valign="top">
		<textarea rows="6" name="showinginstructions" cols="50" class="form"></textarea>
	</td>
	</tr>
	<tr>
	<td valign="top"><b>Transaction Notes</b><br>You may keep track of notes about this transaction in this area for later viewing</td>
	<td valign="top">
		<textarea rows="6" name="notes" cols="50" class="form"></textarea>
	</td>
	</tr>
	<tr>
	<td colspan="2" bgcolor="black"><font color="white" size="2"><b><center>Pending / Sold Information</b></font></td>
	</tr>
	<tr>
	<td valign="top"><b>Pending Date</b><br>If this property is not pending yet please skip.</td>
	<td valign="top">
				Select Date<br>
				<input type="Text" name="pendingdate" value="" class="form">
				<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><br>
	</td>
	</tr>
	<tr>
	<td valign="top"><b>Earnest Money</b><br>If this property is not pending yet please skip this section.</td>
	<td valign="top">
				Received Date & Time<br>
				<input type="Text" name="earnestmoneyreceived" value="" class="form">
				<a href="javascript:cal7.popup();"><img src="images/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the date"></a><br>
				Dollar Amount:<br>
				\$ <input type="text" name="earnestmoneydollar" class="form"><br>
				Held At:<br>
				<input type="text" name="earnestmoneyheldat" class="form"><br>
	</td>
	</tr>
	<tr>
	<td valign="top" bgcolor="#CCCCFF"><b>Inspection Response Days</b><br>How many days are allowed for inspections to be completed?</td>
	<td valign="top" bgcolor="#CCCCFF">
				<input type="Text" name="inspectionresponsedays" class="form" size="2"><br>
	</td>
	</tr>
	<tr>
	<td valign="top"><b>Estimated Closing Date</b></td>
	<td valign="top">
				Select Date<br>
				<input type="Text" name="estimatedclosingdate" value="" class="form">
				<a href="javascript:cal5.popup();"><img src="images/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the date"></a><br>
	</td>
	</tr>
	<tr>
	<td valign="top" bgcolor="#CCCCFF"><b>Sold Price</b></td>
	<td valign="top" bgcolor="#CCCCFF">\$<input type="text" name="soldprice" class="form"></td>
	</tr>
	<tr>
	<td valign="top"><b>Sold Date</b></td>
	<td valign="top">
				Select Date<br>
				<input type="Text" name="solddate" value="" class="form">
				<a href="javascript:cal6.popup();"><img src="images/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the date"></a><br>
	</td>
	</tr>
	<tr>
	<td colspan="2"><center><input type="submit" value="Submit / Next Page" class="form">&nbsp;&nbsp;&nbsp;<a href="transactions.idx?agent=$Cook{agentid}">Cancel</a></center></td>
	</tr>
	</table>
</form>
			<script language="JavaScript">
			<!-- // create calendar object(s) just after form tag closed
				 // specify form element as the only parameter (document.forms['formname'].elements['inputname']);
				 // note: you can have as many calendar objects as you need for your application

				var cal1 = new calendar1(document.forms['transactions'].elements['listingdate']);
				cal1.year_scroll = true;
				cal1.time_comp = false;

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

				var cal3 = new calendar1(document.forms['transactions'].elements['pendingdate']);
				cal3.year_scroll = true;
				cal3.time_comp = false;

				var cal4 = new calendar1(document.forms['transactions'].elements['inspectionresponsedays']);
				cal4.year_scroll = true;
				cal4.time_comp = false;

				var cal5 = new calendar1(document.forms['transactions'].elements['estimatedclosingdate']);
				cal5.year_scroll = true;
				cal5.time_comp = false;

				var cal6 = new calendar1(document.forms['transactions'].elements['solddate']);
				cal6.year_scroll = true;
				cal6.time_comp = false;

				var cal7 = new calendar1(document.forms['transactions'].elements['earnestmoneyreceived']);
				cal7.year_scroll = true;
				cal7.time_comp = true;

			//-->
			</script>

</td>
~;

    &footer;

}

sub create_transaction_verify {

    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;

    $INPUT{showinginstructions}    =~ s/\"//gi;
    $INPUT{showinginstructions}    =~ s/\'//gi;
    $INPUT{mlsnumber}              =~ s/\"//gi;
    $INPUT{mlsnumber}              =~ s/\'//gi;
    $Cook{agentid}                 =~ s/\"//gi;
    $Cook{agentid}                 =~ s/\'//gi;
    $INPUT{selleragent}            =~ s/\"//gi;
    $INPUT{selleragent}            =~ s/\'//gi;
    $INPUT{buyeragent}             =~ s/\"//gi;
    $INPUT{buyeragent}             =~ s/\'//gi;
    $INPUT{type}                   =~ s/\"//gi;
    $INPUT{type}                   =~ s/\'//gi;
    $INPUT{addressstreet}          =~ s/\"//gi;
    $INPUT{addressstreet}          =~ s/\'//gi;
    $INPUT{city}                   =~ s/\"//gi;
    $INPUT{city}                   =~ s/\'//gi;
    $INPUT{state}                  =~ s/\"//gi;
    $INPUT{state}                  =~ s/\'//gi;
    $INPUT{zip}                    =~ s/\"//gi;
    $INPUT{zip}                    =~ s/\'//gi;
    $INPUT{listingdate}            =~ s/\"//gi;
    $INPUT{listingdate}            =~ s/\'//gi;
    $INPUT{expiredate}             =~ s/\"//gi;
    $INPUT{expiredate}             =~ s/\'//gi;
    $INPUT{listingprice}           =~ s/\"//gi;
    $INPUT{listingprice}           =~ s/\'//gi;
    $INPUT{notes}                  =~ s/\"//gi;
    $INPUT{notes}                  =~ s/\'//gi;
    $INPUT{pendingdate}            =~ s/\"//gi;
    $INPUT{pendingdate}            =~ s/\'//gi;
    $INPUT{inspectionresponsedays} =~ s/\"//gi;
    $INPUT{inspectionresponsedays} =~ s/\'//gi;
    $INPUT{estimatedclosingdate}   =~ s/\"//gi;
    $INPUT{estimatedclosingdate}   =~ s/\'//gi;
    $INPUT{soldprice}              =~ s/\"//gi;
    $INPUT{soldprice}              =~ s/\'//gi;
    $INPUT{solddate}               =~ s/\"//gi;
    $INPUT{solddate}               =~ s/\'//gi;

    #$INPUT{listingprice} =~ s/\,//gi;
    #$INPUT{soldprice} =~ s/\,//gi;

    if ( $INPUT{type} eq "AL" ) {
        $typename = "Active Listing";
    }
    elsif ( $INPUT{type} eq "EL" ) {
        $typename = "Expired Listing";
    }
    elsif ( $INPUT{type} eq "BP" ) {
        $typename = "Buyer Pending";
    }
    elsif ( $INPUT{type} eq "SP" ) {
        $typename = "Seller Pending";
    }
    elsif ( $INPUT{type} eq "BSP" ) {
        $typename = "Buyer & Seller Pending";
    }
    elsif ( $INPUT{type} eq "CLSD" ) {
        $typename = "Closed (SOLD)";
    }
    else {
        $typename = "Other";
    }

    my $zaasth =
      $dbh->prepare(
"select id,firstname,lastname,company from trans_boarddirectory where id = '$INPUT{selleragent}'"
      );
    $zaasth->execute;

    my $azaasth =
      $dbh->prepare(
"select id,firstname,lastname,company from trans_boarddirectory where id = '$INPUT{sellercoagent}'"
      );
    $azaasth->execute;

    my $bzaasth =
      $dbh->prepare(
"select id,firstname,lastname,company from trans_boarddirectory where id = '$INPUT{buyeragent}'"
      );
    $bzaasth->execute;

    my $czaasth =
      $dbh->prepare(
"select id,firstname,lastname,company from trans_boarddirectory where id = '$INPUT{buyercoagent}'"
      );
    $czaasth->execute;

    print qq~
<html>
<head>
<title>Verify New Transaction -- Eagle Real Estate, Inc. - Connect.EagleSold.com</title>
~;

    &header;

    print qq~
<td valign="top" width="581">
<img src="images/headers/transaction_manager.gif" height="33" width="581" alt="My Transaction Manager"><br><br>
<img src="images/trans_sys/verify_transaction.gif" alt="Verify New Transaction"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Verify the information below to create a new transaction</b><br><br>
<form method="post" action="transactions.idx">
<input type="hidden" name="action" value="create_transaction_do">
<input type="hidden" name="agent" value="$Cook{agentid}">
<input type="hidden" name="mlsnumber" value="$INPUT{mlsnumber}">
<input type="hidden" name="listingclass" value="$INPUT{listingclass}">
<input type="hidden" name="selleragent" value="$INPUT{selleragent}">
<input type="hidden" name="sellercoagent" value="$INPUT{sellercoagent}">
<input type="hidden" name="buyeragent" value="$INPUT{buyeragent}">
<input type="hidden" name="buyercoagent" value="$INPUT{buyercoagent}">
<input type="hidden" name="type" value="$INPUT{type}">
<input type="hidden" name="status" value="$INPUT{status}">
<input type="hidden" name="addressnumber" value="$INPUT{addressnumber}">
<input type="hidden" name="addressdirection" value="$INPUT{addressdirection}">
<input type="hidden" name="addressstreet" value="$INPUT{addressstreet}">
<input type="hidden" name="city" value="$INPUT{city}">
<input type="hidden" name="state" value="$INPUT{state}">
<input type="hidden" name="zip" value="$INPUT{zip}">
<input type="hidden" name="listingdate" value="$INPUT{listingdate}">
<input type="hidden" name="expiredate" value="$INPUT{expiredate}">
<input type="hidden" name="listingprice" value="$INPUT{listingprice}">
<input type="hidden" name="showinginstructions" value="$INPUT{showinginstructions}">
<input type="hidden" name="notes" value="$INPUT{notes}">
<input type="hidden" name="pendingdate" value="$INPUT{pendingdate}">
<input type="hidden" name="earnestmoneyreceived" value="$INPUT{earnestmoneyreceived}">
<input type="hidden" name="earnestmoneydollar" value="$INPUT{earnestmoneydollar}">
<input type="hidden" name="earnestmoneyheldat" value="$INPUT{earnestmoneyheldat}">
<input type="hidden" name="inspectionresponsedays" value="$INPUT{inspectionresponsedays}">
<input type="hidden" name="estimatedclosingdate" value="$INPUT{estimatedclosingdate}">
<input type="hidden" name="soldprice" value="$INPUT{soldprice}">
<input type="hidden" name="solddate" value="$INPUT{solddate}">
	<table border="0" cellpadding="3" cellspacing="1">	
	<tr>
	<td colspan="2" bgcolor="black"><font color="white" size="2"><b><center>Transaction / Listing Information</b></font></td>
	</tr>
	<tr>
	<td valign="top" width="50%"><b>Transaction</b></td>
	<td valign="top" width="50%">
	<b>Status</b><br>
	<font size="3">$INPUT{status}</font><br>
	<b>Type</b><br>
	<font size="3">$INPUT{type}</font><br>
	<b>Listing Class</b><br>
	<font size="3">$INPUT{listingclass}</font><br>
	<b>MLS Number</b><br>
	<font size="3">$INPUT{mlsnumber}</font><br>
	</td>
	</tr>
	<tr>
	<td valign="top" bgcolor="#CCCCFF"><b>Property Address</b></td>
	<td valign="top" bgcolor="#CCCCFF">
		<b>Address</b><br>
		<font size="3">$INPUT{addressnumber} $INPUT{addressdirection} $INPUT{addressstreet}</font><br>
		<b>City</b><br>
		<font size="3">$INPUT{city}</font><br>
		<b>State</b><br>
		<font size="3">$INPUT{state}</font><br>
		<b>Zip</b><br>
		<font size="3">$INPUT{zip}</font><br>
	</td>
	</tr>
	<tr>
	<td valign="top"><b>Listing Date</b></td>
	<td valign="top"><font size="3">$INPUT{listingdate}</font></td>
	</tr>
	<tr>
	<td valign="top"><b>Expire Date</b></td>
	<td valign="top"><font size="3">$INPUT{expiredate}</font></td>
	</tr>
	<tr>
	<td valign="top"><b>Listing Price</b><br>If this property is not pending yet please skip.</td>
	<td valign="top"><font size="3">\$$INPUT{listingprice}</font></td>
	</tr>
	<tr>
	<td valign="top" bgcolor="#CCCCFF"><b>Listing Agent(s)</b></td>
	<td valign="top" bgcolor="#CCCCFF">
		<b>Primary Agent</b><br>
	~;
    if ( $INPUT{selleragent} eq "0" ) {
        print qq~
		<font size="3">None</font><br>
		~;
    }
    else {
        while (
            (
                $listagentid,       $listagentfirstname,
                $listagentlastname, $listagentcompany
            )
            = $zaasth->fetchrow_array()
          )
        {
            print qq~
		<font size="3">$listagentfirstname $listagentlastname</font><br>
		~;
        }
    }
    print qq~
		<b>Listing Co Agent</b><br>
	~;
    if ( $INPUT{sellercoagent} eq "0" ) {
        print qq~
		<font size="3">None</font><br>
		~;
    }
    else {
        while (
            (
                $sclistagentid,       $sclistagentfirstname,
                $sclistagentlastname, $sclistagentcompany
            )
            = $azaasth->fetchrow_array()
          )
        {
            print qq~
		<font size="3">$sclistagentfirstname $sclistagentlastname</font><br>
		~;
        }
    }
    print qq~
	</td>
	</tr>
	<tr>
	<td valign="top" bgcolor="#CCCCFF"><b>Buyers Agent(s)</b></td>
	<td valign="top" bgcolor="#CCCCFF">
		<b>Primary Agent</b><br>
	~;
    if ( $INPUT{buyeragent} eq "0" ) {
        print qq~
		<font size="3">None</font><br>
		~;
    }
    else {
        while (
            (
                $blistagentid,       $blistagentfirstname,
                $blistagentlastname, $blistagentcompany
            )
            = $bzaasth->fetchrow_array()
          )
        {
            print qq~
		<font size="3">$blistagentfirstname $blistagentlastname</font><br>
		~;
        }
    }
    print qq~
		<b>Buyers Co Agent</b><br>
	~;
    if ( $INPUT{buyercoagent} eq "0" ) {
        print qq~
		<font size="3">None</font><br>
		~;
    }
    else {
        while (
            (
                $bclistagentid,       $bclistagentfirstname,
                $bclistagentlastname, $bclistagentcompany
            )
            = $czaasth->fetchrow_array()
          )
        {
            print qq~
		<font size="3">$bclistagentfirstname $bclistagentlastname</font><br>
		~;
        }
    }
    print qq~
	</td>
	</tr>
	<tr>
	<td valign="top"><b>Showing Instructions</b><br>You <u><b>MUST</b></u> enter detailed showing instructions for this property.  Please include names and numbers of people who should be notified to setup showing.</td>
	<td valign="top">
		<font size="3">$INPUT{showinginstructions}</font><br>
	</td>
	</tr>
	<tr>
	<td valign="top"><b>Transaction Notes</b><br>You may keep track of notes about this transaction in this area for later viewing</td>
	<td valign="top">
		<font size="3">$INPUT{notes}</font><br>
	</td>
	</tr>
	<tr>
	<td colspan="2" bgcolor="black"><font color="white" size="2"><b><center>Pending / Sold Information</b></font></td>
	</tr>
	<tr>
	<td valign="top"><b>Pending Date</b><br>If this property is not pending yet please skip.</td>
	<td valign="top"><font size="3">$INPUT{pendingdate}</font></td>
	</tr>
	<tr>
	<td valign="top"><b>Pending Date</b><br>If this property is not pending yet please skip.</td>
	<td valign="top"><font size="3">$INPUT{pendingdate}</font></td>
	</tr>
	<tr>
	<td valign="top"><b>Earnest Money Received</b><br></td>
	<td valign="top">
		Date Received<br>
		<font size="3">$INPUT{earnestmoneyreceived}</font><br>
		Amount of Money<br>
		<font size="3">$INPUT{earnestmoneydollar}</font><br>
		Held At<br>
		<font size="3">$INPUT{earnestmoneyheldat}</font><br>
	</td>
	</tr>
	<tr>
	<td valign="top" bgcolor="#CCCCFF"><b>Inspection Response Date</b></td>
	<td valign="top" bgcolor="#CCCCFF"><font size="3">$INPUT{inspectionresponsedays}</font></td>
	</tr>
	<tr>
	<td valign="top"><b>Estimated Closing Date</b></td>
	<td valign="top"><font size="3">$INPUT{estimatedclosingdate}</font></td>
	</tr>
	<tr>
	<td valign="top" bgcolor="#CCCCFF"><b>Sold Price</b></td>
	<td valign="top" bgcolor="#CCCCFF"><font size="3">$INPUT{soldprice}</font></td>
	</tr>
	<tr>
	<td valign="top"><b>Sold Date</b></td>
	<td valign="top"><font size="3">$INPUT{solddate}</font></td>
	</tr>
	<tr>
	<td colspan="2"><center><input type="submit" value="Save New Transaction" class="form"> <input type="button" value="Make Changes" onClick="history.back()" class="form"></center></td>
	</tr>
	</table>
</form>
</td>
~;

    &footer;

}

sub create_transaction_do {

    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;

    @variables = (
        $Cook{agentid},                 $INPUT{mlsnumber},
        $INPUT{selleragent},            $INPUT{sellercoagent},
        $INPUT{buyeragent},             $INPUT{buyercoagent},
        $INPUT{type},                   $INPUT{status},
        $INPUT{listingclass},           $INPUT{addressnumber},
        $INPUT{addressdirection},       $INPUT{addressstreet},
        $INPUT{city},                   $INPUT{state},
        $INPUT{zip},                    $INPUT{listingdate},
        $INPUT{expiredate},             $INPUT{listingprice},
        $INPUT{showinginstructions},    $INPUT{notes},
        $INPUT{pendingdate},            $INPUT{earnestmoneyreceived},
        $INPUT{earnestmoneydollar},     $INPUT{earnestmoneyheldat},
        $INPUT{inspectionresponsedays}, $INPUT{estimatedclosingdate},
        $INPUT{soldprice},              $INPUT{solddate}
    );

    $sql_query =
"INSERT INTO trans_board values ('',?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
    my $aasth = $dbh->do( $sql_query, undef, @variables );

    my $basth =
      $dbh->prepare(
"SELECT id FROM trans_board WHERE agent = '$Cook{agentid}' ORDER BY id DESC LIMIT 0,1"
      );
    $basth->execute;
    while ( ($id) = $basth->fetchrow_array() ) {
        $newid = $id;
    }

    $status =
"Successfully Created New Transaction For $INPUT{addressnumber} $INPUT{addressdirection} $INPUT{addressstreet} in $INPUT{city}";

    &main;

}

sub assign_contact_do {

    #$INPUT{transid}
    #$INPUT{contactid}
    #$Cook{agentid}
    #INPUT{contact_type}

    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;

    @variables = ( $INPUT{transid}, $INPUT{contactid}, $INPUT{contact_type} );
    $sql_query = "INSERT INTO trans_boardtranstocontact values (?,?,?)";
    my $aasth = $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/transactions.idx?action=overview&transid=$INPUT{transid}&agent=$Cook{agentid}">
</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/transactions.idx?action=overview&transid=$INPUT{transid}&agent=$Cook{agentid}">Click Here</a>.</center>
</body>
</html>
~;

}

sub unassign_contact {

    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;

    @variables = ( $INPUT{transid}, $INPUT{contactid} );
    $sql_query =
"DELETE FROM trans_boardtranstocontact WHERE transid = ? AND contactid = ?";
    my $aasth = $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/transactions.idx?action=overview&transid=$INPUT{transid}&agent=$Cook{agentid}">
</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/transactions.idx?action=overview&transid=$INPUT{transid}&agent=$Cook{agentid}">Click Here</a>.</center>
</body>
</html>
~;

}

sub assign_contact {

    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;

    $find = $INPUT{find};

    unless ( $INPUT{find} ) {
        $find = "-";
    }

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

    &header;

    print qq~
<td valign="top" width="581">
<img src="images/headers/transaction_manager.gif" height="33" width="581" alt="My Transaction Manager"><br><br>
<img src="images/trans_sys/assign_contact.gif" alt="Assign Contact"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>contact will be assigned to $INPUT{address}</b><br><br><br>
<table>
<tr>
<td valign=top width="100%">
<font size="3" face="Arial" color="green"><b>Create A New Contact</b></font><br><br><font size="2">Once you create this new contact, they will automatically be linked as a $INPUT{contact_type} to the $INPUT{address} transaction.</font><br><br>
<form method="get" action="transactions.idx">
<input type="hidden" name="action" value="create_contact">
<input type="hidden" name="transid" value="$INPUT{transid}">
<input type="hidden" name="agent" value="$Cook{agentid}">
<input type="hidden" name="contact_type" value="$INPUT{contact_type}">
<input type="hidden" name="address" value="$INPUT{address}">
<input type="submit" value="Create New $INPUT{contact_type} for $INPUT{address}">
</form>
</td>
</tr>
</table>
<table border="0" cellpadding="6" cellspacing="1" bgcolor="navy" width="100%">
<tr>
<td bgcolor="#CCCCFF">
<center>
<b><font size="3">Search your contacts by Lastname</font></b><br>
<a href="transactions.idx?action=assign_contact&transid=$INPUT{transid}&agent=$Cook{agentid}&find=%&contact_type=$INPUT{contact_type}&address=$INPUT{address}">All</a> 
<a href="transactions.idx?action=assign_contact&transid=$INPUT{transid}&agent=$Cook{agentid}&find=A&contact_type=$INPUT{contact_type}&address=$INPUT{address}">A</a> | 
<a href="transactions.idx?action=assign_contact&transid=$INPUT{transid}&agent=$Cook{agentid}&find=B&contact_type=$INPUT{contact_type}&address=$INPUT{address}">B</a> | 
<a href="transactions.idx?action=assign_contact&transid=$INPUT{transid}&agent=$Cook{agentid}&find=C&contact_type=$INPUT{contact_type}&address=$INPUT{address}">C</a> | 
<a href="transactions.idx?action=assign_contact&transid=$INPUT{transid}&agent=$Cook{agentid}&find=D&contact_type=$INPUT{contact_type}&address=$INPUT{address}">D</a> | 
<a href="transactions.idx?action=assign_contact&transid=$INPUT{transid}&agent=$Cook{agentid}&find=E&contact_type=$INPUT{contact_type}&address=$INPUT{address}">E</a> | 
<a href="transactions.idx?action=assign_contact&transid=$INPUT{transid}&agent=$Cook{agentid}&find=F&contact_type=$INPUT{contact_type}&address=$INPUT{address}">F</a> | 
<a href="transactions.idx?action=assign_contact&transid=$INPUT{transid}&agent=$Cook{agentid}&find=G&contact_type=$INPUT{contact_type}&address=$INPUT{address}">G</a> | 
<a href="transactions.idx?action=assign_contact&transid=$INPUT{transid}&agent=$Cook{agentid}&find=H&contact_type=$INPUT{contact_type}&address=$INPUT{address}">H</a> | 
<a href="transactions.idx?action=assign_contact&transid=$INPUT{transid}&agent=$Cook{agentid}&find=I&contact_type=$INPUT{contact_type}&address=$INPUT{address}">I</a> | 
<a href="transactions.idx?action=assign_contact&transid=$INPUT{transid}&agent=$Cook{agentid}&find=J&contact_type=$INPUT{contact_type}&address=$INPUT{address}">J</a> | 
<a href="transactions.idx?action=assign_contact&transid=$INPUT{transid}&agent=$Cook{agentid}&find=K&contact_type=$INPUT{contact_type}&address=$INPUT{address}">K</a> | 
<a href="transactions.idx?action=assign_contact&transid=$INPUT{transid}&agent=$Cook{agentid}&find=L&contact_type=$INPUT{contact_type}&address=$INPUT{address}">L</a> | 
<a href="transactions.idx?action=assign_contact&transid=$INPUT{transid}&agent=$Cook{agentid}&find=M&contact_type=$INPUT{contact_type}&address=$INPUT{address}">M</a> | 
<a href="transactions.idx?action=assign_contact&transid=$INPUT{transid}&agent=$Cook{agentid}&find=N&contact_type=$INPUT{contact_type}&address=$INPUT{address}">N</a> | 
<a href="transactions.idx?action=assign_contact&transid=$INPUT{transid}&agent=$Cook{agentid}&find=O&contact_type=$INPUT{contact_type}&address=$INPUT{address}">O</a> | 
<a href="transactions.idx?action=assign_contact&transid=$INPUT{transid}&agent=$Cook{agentid}&find=P&contact_type=$INPUT{contact_type}&address=$INPUT{address}">P</a> | 
<a href="transactions.idx?action=assign_contact&transid=$INPUT{transid}&agent=$Cook{agentid}&find=Q&contact_type=$INPUT{contact_type}&address=$INPUT{address}">Q</a> | 
<a href="transactions.idx?action=assign_contact&transid=$INPUT{transid}&agent=$Cook{agentid}&find=R&contact_type=$INPUT{contact_type}&address=$INPUT{address}">R</a> | 
<a href="transactions.idx?action=assign_contact&transid=$INPUT{transid}&agent=$Cook{agentid}&find=S&contact_type=$INPUT{contact_type}&address=$INPUT{address}">S</a> | 
<a href="transactions.idx?action=assign_contact&transid=$INPUT{transid}&agent=$Cook{agentid}&find=T&contact_type=$INPUT{contact_type}&address=$INPUT{address}">T</a> | 
<a href="transactions.idx?action=assign_contact&transid=$INPUT{transid}&agent=$Cook{agentid}&find=U&contact_type=$INPUT{contact_type}&address=$INPUT{address}">U</a> | 
<a href="transactions.idx?action=assign_contact&transid=$INPUT{transid}&agent=$Cook{agentid}&find=V&contact_type=$INPUT{contact_type}&address=$INPUT{address}">V</a> | 
<a href="transactions.idx?action=assign_contact&transid=$INPUT{transid}&agent=$Cook{agentid}&find=W&contact_type=$INPUT{contact_type}&address=$INPUT{address}">W</a> | 
<a href="transactions.idx?action=assign_contact&transid=$INPUT{transid}&agent=$Cook{agentid}&find=X&contact_type=$INPUT{contact_type}&address=$INPUT{address}">X</a> | 
<a href="transactions.idx?action=assign_contact&transid=$INPUT{transid}&agent=$Cook{agentid}&find=Y&contact_type=$INPUT{contact_type}&address=$INPUT{address}">Y</a> | 
<a href="transactions.idx?action=assign_contact&transid=$INPUT{transid}&agent=$Cook{agentid}&find=Z&contact_type=$INPUT{contact_type}&address=$INPUT{address}">Z</a>
</center>
</td>
</tr>
</table>
<br>
~;

    my $basth =
      $dbh->prepare(
"select id,agent,type,firstname,lastname,spouse from trans_boardcontact WHERE agent = '$Cook{agentid}' AND lastname LIKE '$find%' ORDER by lastname ASC"
      );
    $basth->execute;

    while ( ( $id, $agent, $type, $firstname, $lastname, $spouse ) =
        $basth->fetchrow_array() )
    {
        if ( $spouse ne "" ) {
            $spouse = " & $spouse ";
        }
        else {
            $spouse = "";
        }
        print qq~
<a href="transactions.idx?action=assign_contact_do&agent=$Cook{agentid}&transid=$INPUT{transid}&contactid=$id&contact_type=$INPUT{contact_type}&address=$INPUT{address}">$lastname, $firstname$spouse [ Link as $INPUT{address} $INPUT{contact_type} ]</a><br>
~;
        $found = "yes";
    }
    unless ( $found eq "yes" ) {
        print qq~
<font color="gray" size="3" face="Arial"><b>No Contacts Found, Click on the first letter in the alphabet above that corresponds with your contacts lastname.</b></font><br>
~;
    }
    print qq~
</td>
~;

#id,agent,type,firstname,lastname,phone1type,phone1number,phone2type,phone2number,phone3type,phone3number,faxnumber,email,emailtwo,notes
    &footer;

}

sub edit_transaction {

    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>Edit Transaction -- Eagle Real Estate, Inc. - Connect.EagleSold.com</title>
~;

    &header;

    my $aasth =
      $dbh->prepare(
"select id,agent,mlsnumber,selleragent,sellercoagent,buyeragent,buyercoagent,type,status,listingclass,addressnumber,addressdirection,addressstreet,city,state,zip,listingdate,expiredate,listingprice,showinginstructions,notes,pendingdate,earnestmoneyreceived,earnestmoneydollar,earnestmoneyheldat,inspectionresponsedays,estimatedclosingdate,soldprice,solddate from trans_board WHERE id = '$INPUT{transid}'"
      );
    $aasth->execute;
    while (
        (
            $id,                   $agent,
            $mlsnumber,            $selleragent,
            $sellercoagent,        $buyeragent,
            $buyercoagent,         $type,
            $status,               $listingclass,
            $addressnumber,        $addressdirection,
            $addressstreet,        $city,
            $state,                $zip,
            $listingdate,          $expiredate,
            $listingprice,         $showinginstructions,
            $notes,                $pendingdate,
            $earnestmoneyreceived, $earnestmoneydollar,
            $earnestmoneyheldat,   $inspectionresponsedays,
            $estimatedclosingdate, $soldprice,
            $solddate
        )
        = $aasth->fetchrow_array()
      )
    {

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

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

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

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

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

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

        if ( $listingclass eq "Residential" ) {
            $viewtypeoptionclass =
              "<option value=\"Residential\">Residential</option>";
            $viewtypeoptionclass .= "<option value=\"\">-----------</option>";
        }
        elsif ( $listingclass eq "Commercial" ) {
            $viewtypeoptionclass =
              "<option value=\"Commercial\">Commercial</option>";
            $viewtypeoptionclass .= "<option value=\"\">-----------</option>";
        }
        elsif ( $listingclass eq "Investment" ) {
            $viewtypeoptionclass =
              "<option value=\"Investment\">Investment</option>";
            $viewtypeoptionclass .= "<option value=\"\">-----------</option>";
        }
        elsif ( $listingclass eq "LotsLand" ) {
            $viewtypeoptionclass =
              "<option value=\"LotsLand\">Lots and Land</option>";
            $viewtypeoptionclass .= "<option value=\"\">-----------</option>";
        }

        my $aabuyeragent =
          $dbh->prepare(
"select id,firstname,lastname,company from trans_boarddirectory where id = '$buyeragent'"
          );
        $aabuyeragent->execute;
        while ( ( $gbid, $gbfirstname, $gblastname, $gbcompany ) =
            $aabuyeragent->fetchrow_array() )
        {
            $getbuyeragent =
"<option value=\"$gbid\">$gbcompany -- $gblastname, $gbfirstname</option>";
        }

        my $aabuyercoagent =
          $dbh->prepare(
"select id,firstname,lastname,company from trans_boarddirectory where id = '$buyercoagent'"
          );
        $aabuyercoagent->execute;
        while ( ( $gbcid, $gbcfirstname, $gbclastname, $gbccompany ) =
            $aabuyercoagent->fetchrow_array() )
        {
            $getbuyercoagent =
"<option value=\"$gbcid\">$gbccompany -- $gbclastname, $gbcfirstname</option>";
        }

        my $aaselleragent =
          $dbh->prepare(
"select id,firstname,lastname,company from trans_boarddirectory where id = '$selleragent'"
          );
        $aaselleragent->execute;
        while ( ( $gsid, $gsfirstname, $gslastname, $gscompany ) =
            $aaselleragent->fetchrow_array() )
        {
            $getselleragent =
"<option value=\"$gsid\">$gscompany -- $gslastname, $gsfirstname</option>";
        }

        my $aasellercoagent =
          $dbh->prepare(
"select id,firstname,lastname,company from trans_boarddirectory where id = '$sellercoagent'"
          );
        $aasellercoagent->execute;
        while ( ( $gscid, $gscfirstname, $gsclastname, $gsccompany ) =
            $aasellercoagent->fetchrow_array() )
        {
            $getsellercoagent =
"<option value=\"$gscid\">$gsccompany -- $gsclastname, $gscfirstname</option>";
        }

        if ( $type eq "Listing" ) {
            $viewtypeoption = "<option value=\"Listing\">Listing</option>";
            $viewtypeoption .= "<option value=\"\">-----------</option>";
        }
        elsif ( $type eq "BP" ) {
            $viewtypeoption = "<option value=\"BP\">Buyer Side Sale</option>";
            $viewtypeoption .= "<option value=\"\">-----------</option>";
        }
        elsif ( $type eq "BSP" ) {
            $viewtypeoption =
              "<option value=\"BSP\">Buyer & Seller Side Sale</option>";
            $viewtypeoption .= "<option value=\"\">-----------</option>";
        }

        if ( $status eq "CLSD" ) {
            $viewstatusoption = "<option value=\"CLSD\">Closed (SOLD)</option>";
            $viewstatusoption .= "<option value=\"\">-----------</option>";
        }
        elsif ( $status eq "WTHD" ) {
            $viewstatusoption =
              "<option value=\"WTHD\">Withdrawn (Release)</option>";
            $viewstatusoption .= "<option value=\"\">-----------</option>";
        }
        elsif ( $status eq "Active" ) {
            $viewstatusoption = "<option value=\"Active\">Active</option>";
            $viewstatusoption .= "<option value=\"\">-----------</option>";
        }
        elsif ( $status eq "Pending" ) {
            $viewstatusoption = "<option value=\"Pending\">Pending</option>";
            $viewstatusoption .= "<option value=\"\">-----------</option>";
        }
        elsif ( $status eq "Prospect" ) {
            $viewstatusoption = "<option value=\"Prospect\">Prospect</option>";
            $viewstatusoption .= "<option value=\"\">-----------</option>";
        }
        elsif ( $status eq "Expired" ) {
            $viewstatusoption = "<option value=\"Expired\">Expired</option>";
            $viewstatusoption .= "<option value=\"\">-----------</option>";
        }
        elsif ( $status eq "DEAD" ) {
            $viewstatusoption =
              "<option value=\"DEAD\">Dead Deal (Not Closing)</option>";
            $viewstatusoption .= "<option value=\"\">-----------</option>";
        }

        if ($listingclass) {
            $viewclassoption =
              "<option value=\"$listingclass\">$listingclass</option>";
            $viewclassoption .= "<option value=\"\">-----------</option>";
        }

        if ($addressdirection) {
            $getaddressdirection =
"<option value=\"$addressdirection\">$addressdirection<option><option value=\"\">--</option>";
        }
        else {
            $getaddressdirection =
              "<option value=\"\">None<option><option value=\"\">--</option>";
        }

        if ($addressstreet) {
            $getaddressstreet =
"<option value=\"$addressstreet\">$addressstreet<option><option value=\"\">----------------</option>";
        }
        print qq~
<script language="JavaScript" src="calendar1.js"></script><!-- Date only with year scrolling -->
<script language="JavaScript" src="calendar2.js"></script><!-- Date only with year scrolling -->
<td valign="top" width="581">
<img src="images/headers/transaction_manager.gif" height="33" width="581" alt="My Transaction Manager"><br><br>
<img src="images/trans_sys/edit_transaction.gif" alt="Edit Transaction"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>fill out the form below to create a new transaction</b><br><br>
<form method="get" name="transactions" action="transactions.idx">
<input type="hidden" name="action" value="edit_transaction_do">
<input type="hidden" name="transid" value="$INPUT{transid}">
<input type="hidden" name="agent" value="$Cook{agentid}">
	<table border="0" width="500" cellpadding="3" cellspacing="1">	
	<tr>
	<td colspan="2" bgcolor="black"><font color="white" size="2"><b><center>Transaction / Listing Information</b></font></td>
	</tr>
	<tr>
	<td valign="top"><b>Transaction</b></td>
	<td valign="top">
		<b>Status</b><br>
		<select name="status" class="form">
		$viewstatusoption
		<option value="Active">Active</option>
		<option value="Pending">Pending</option>
		<option value="Prospect">Listing Prospect</option>
		<option value="CLSD">Closed (SOLD)</option>
		<option value="Expired">Expired Listing</option>
		<option value="WTHD">Withdrawn (Release)</option>
		<option value="DEAD">Dead Deal (Not Closing)</option>
		</select><br>
		<b>Type</b><br>
		<select name="type" class="form">
		$viewtypeoption
		<option value="Listing">Listing</option>
		<option value="">-----------</option>
		<option value="BP">Buyer Side Sale</option>
		<option value="BSP">Buyer & Seller Side Sale</option>
		</select><br>
		<b>Listing Class</b><br>
		<select name="listingclass" class="form">
		$viewtypeoptionclass
		<option value="Residential">Residential</option>
		<option value="Commercial">Commercial</option>
		<option value="LotsLand">Lots and Land</option>
		<option value="Investment">Investment</option>
		</select><br>
		<b>MLS Number</b><br>
		<input type="text" name="mlsnumber" size="10" value="$mlsnumber" class="form"><br>
		<input type="hidden" name="old_mls" value="$mlsnumber"><br>
	</td>
	</tr>
	<tr>
	<td valign="top" bgcolor="#CCCCFF"><b>Property Address</b></td>
	<td valign="top" bgcolor="#CCCCFF">
		<b>Address</b><br>
		<input type="text" name="addressnumber" size="5" value="$addressnumber" class="form"> <select name="addressdirection" class="form">
$getaddressdirection
<option value="N">N</option>
<option value="NE">NE</option>
<option value="NW">NW</option>
<option value="S">S</option>
<option value="SE">SE</option>
<option value="SW">SW</option>
<option value="E">E</option>
<option value="W">W</option><option value="">None</option></select> <select name="addressstreet" class="form">
$getaddressstreet
~;
        my $aaasth =
          $dbh->prepare("select address from address ORDER BY address ASC");
        $aaasth->execute;
        while ( ($pulladdress) = $aaasth->fetchrow_array() ) {
            $printaddress .=
              "<option value=\"$pulladdress\">$pulladdress</option>\n";
        }
        print qq~
$printaddress
</select><br>
		<b>City</b><br>
		<input type="text" name="city" size="20" value="$city" class="form"><br>
		<b>State</b><br>
		<input type="text" name="state" value="$state" size="15" class="form"><br>
		<b>Zip</b><br>
		<input type="text" name="zip" value="$zip" size="5" class="form"><br>
	</td>
	</tr>
	<tr>
	<td valign="top"><b>Listing Date</b></td>
	<td valign="top">
				Select Date<br>
				<input type="Text" name="listingdate" value="$listingdate" class="form">
				<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><br>
	</td>
	</tr>
	<tr>
	<td valign="top"><b>Expire Date</b></td>
	<td valign="top">
				Select Date<br>
				<input type="Text" name="expiredate" value="$expiredate" class="form">
				<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><br>
	</td>
	</tr>
	<tr>
	<td valign="top"><b>Listing Price</b><br>If this property is not pending yet please skip.</td>
	<td valign="top">\$<input type="text" name="listingprice" value="$listingprice" class="form"></td>
	</tr>
	<tr>
	<td valign="top" bgcolor="#CCCCFF"><b>Listing Agent(s)</b><br></td>
	<td valign="top" bgcolor="#CCCCFF"><b>Primary Agent</b><br>
		<select name="selleragent" class="form">
		$getselleragent
		<option value="0">Select Agent From List Below</option>
		<option value="0">---------------------</option>
		~;
        my $zaasth =
          $dbh->prepare(
"select id,firstname,lastname,company from trans_boarddirectory ORDER BY company"
          );
        $zaasth->execute;
        while ( ( $sellerid, $sfirstname, $slastname, $scompany ) =
            $zaasth->fetchrow_array() )
        {

            if ( $slastname eq "Inactive Agent" ) {
            }
            else {
                print qq~
		<option value=\"$sellerid\">$scompany -- $slastname, $sfirstname</option>
		~;
            }
        }
        print qq~
		</select><br><br>

		<b>Listing Co Agent</b><br>
		<select name="sellercoagent" class="form">
		$getsellercoagent
		<option value="0">Select Or Leave Blank If No Co Agent</option>
		<option value="0">---------------------</option>
		~;
        my $azaasth =
          $dbh->prepare(
"select id,firstname,lastname,company from trans_boarddirectory ORDER BY company"
          );
        $azaasth->execute;
        while ( ( $csellerid, $csfirstname, $cslastname, $cscompany ) =
            $azaasth->fetchrow_array() )
        {

            if ( $cslastname eq "Inactive Agent" ) {
            }
            else {
                print qq~
		<option value=\"$csellerid\">$cscompany -- $cslastname, $csfirstname</option>
		~;
            }
        }
        print qq~
		</select>
	<br><br>
	</td>
	</tr>
	<tr>
	<td valign="top" bgcolor="#CCCCFF"><b>Buyers Agent</b><br>Choose To The Left</td>
	<td valign="top" bgcolor="#CCCCFF">
		<select name="buyeragent" class="form">
		$getbuyeragent
		<option value="0">Select Or Leave Blank If No Buyer Agent Yet</option>
		<option value="0">---------------------</option>
	~;

        my $azaasth =
          $dbh->prepare(
"select id,firstname,lastname,company from trans_boarddirectory ORDER BY company"
          );
        $azaasth->execute;
        while ( ( $buyerid, $bfirstname, $blastname, $bcompany ) =
            $azaasth->fetchrow_array() )
        {
            if ( $blastname eq "Inactive Agent" ) {
            }
            else {
                print qq~
		<option value=\"$buyerid\">$bcompany -- $blastname, $bfirstname</option>
		~;
            }
        }

        print qq~
		</select><br><br>

		<b>Buyer Co Agent</b><br>
		<select name="buyercoagent" class="form">
		$getbuyercoagent
		<option value="0">Select Or Leave Blank If No Buyer Co Agent</option>
		<option value="0">---------------------</option>
		~;
        my $cazaasth =
          $dbh->prepare(
"select id,firstname,lastname,company from trans_boarddirectory ORDER BY company"
          );
        $cazaasth->execute;
        while ( ( $cbellerid, $cbfirstname, $cblastname, $cbcompany ) =
            $cazaasth->fetchrow_array() )
        {

            if ( $cblastname eq "Inactive Agent" ) {
            }
            else {
                print qq~
		<option value=\"$cbellerid\">$cbcompany -- $cblastname, $cbfirstname</option>
		~;
            }
        }
        print qq~
		</select>
	<br><br>
	</td>
	</tr>
	<tr>
	<td valign="top"><b>Showing Instructions</b><br>You <u><b>MUST</b></u> enter detailed showing instructions for all listings.  Please include names and numbers of people who should be notified to setup showings.</td>
	<td valign="top">
		<textarea rows="6" name="showinginstructions" cols="50" class="form">$showinginstructions</textarea>
	</td>
	</tr>
	<tr>
	<td valign="top"><b>Transaction Notes</b><br>You may keep track of notes about this transaction in this area for later viewing</td>
	<td valign="top">
		<textarea rows="6" name="notes" cols="50" class="form">$notes</textarea>
	</td>
	</tr>
	<tr>
	<td colspan="2" bgcolor="black"><font color="white" size="2"><b><center>Pending / Sold Information</b></font></td>
	</tr>
	<tr>
	<td valign="top"><b>Pending Date</b><br>If this property is not pending yet please skip.</td>
	<td valign="top">
				Select Date<br>
				<input type="Text" name="pendingdate" value="$pendingdate" class="form">
				<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><br>
	</td>
	</tr>
	<tr>
	<td valign="top"><b>Earnest Money</b><br>If this property is not pending yet please skip this section.</td>
	<td valign="top">
				Received Date & Time<br>
				<input type="Text" name="earnestmoneyreceived" value="$earnestmoneyreceived" class="form">
				<a href="javascript:cal7.popup();"><img src="images/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the date"></a><br>
				Dollar Amount:<br>
				\$ <input type="text" name="earnestmoneydollar" value="$earnestmoneydollar" class="form"><br>
				Held At:<br>
				<input type="text" name="earnestmoneyheldat" value="$earnestmoneyheldat" class="form"><br>
	</td>
	</tr>
	<tr>
	<td valign="top" bgcolor="#CCCCFF"><b>Inspection Response Days</b><br>How many days are allowed for inspections to be completed?</td>
	<td valign="top" bgcolor="#CCCCFF">
				<input type="Text" name="inspectionresponsedays" value="$inspectionresponsedays" class="form" size="2"><br>
	</td>
	</tr>
	<tr>
	<td valign="top"><b>Estimated Closing Date</b></td>
	<td valign="top">
				Select Date<br>
				<input type="Text" name="estimatedclosingdate" value="$estimatedclosingdate" class="form">
				<a href="javascript:cal5.popup();"><img src="images/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the date"></a><br>
	</td>
	</tr>
	<tr>
	<td valign="top" bgcolor="#CCCCFF"><b>Sold Date</b></td>
	<td valign="top" bgcolor="#CCCCFF">
				Select Date<br>
				<input type="Text" name="solddate" value="$solddate" class="form">
				<a href="javascript:cal6.popup();"><img src="images/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the date"></a><br>
	</td>
	</tr>
	<tr>
	<td valign="top"><b>Sold Price</b></td>
	<td valign="top">\$<input type="text" name="soldprice" value="$soldprice" class="form"></td>
	</tr>
	<tr>
	<td colspan="2"><center><input type="submit" value="Save Changes To This Transaction" class="form">&nbsp;&nbsp;&nbsp;<a href="transactions.idx?action=overview&transid=$INPUT{transid}&agent=$Cook{agentid}">Cancel</a></center></td>
	</tr>
	</table>
</form>
			<script language="JavaScript">
			<!-- // create calendar object(s) just after form tag closed
				 // specify form element as the only parameter (document.forms['formname'].elements['inputname']);
				 // note: you can have as many calendar objects as you need for your application

				var cal1 = new calendar1(document.forms['transactions'].elements['listingdate']);
				cal1.year_scroll = true;
				cal1.time_comp = false;

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

				var cal3 = new calendar1(document.forms['transactions'].elements['pendingdate']);
				cal3.year_scroll = true;
				cal3.time_comp = false;

				var cal4 = new calendar1(document.forms['transactions'].elements['inspectionresponsedays']);
				cal4.year_scroll = true;
				cal4.time_comp = false;

				var cal5 = new calendar1(document.forms['transactions'].elements['estimatedclosingdate']);
				cal5.year_scroll = true;
				cal5.time_comp = false;

				var cal6 = new calendar1(document.forms['transactions'].elements['solddate']);
				cal6.year_scroll = true;
				cal6.time_comp = false;

				var cal7 = new calendar1(document.forms['transactions'].elements['earnestmoneyreceived']);
				cal7.year_scroll = true;
				cal7.time_comp = true;

			//-->
			</script>

</td>
~;
    }
    &footer;
}

sub edit_transaction_do {

    $INPUT{mlsnumber}              =~ s/\"//gi;
    $INPUT{mlsnumber}              =~ s/\'//gi;
    $Cook{agentid}                 =~ s/\"//gi;
    $Cook{agentid}                 =~ s/\'//gi;
    $INPUT{selleragent}            =~ s/\"//gi;
    $INPUT{selleragent}            =~ s/\'//gi;
    $INPUT{buyeragent}             =~ s/\"//gi;
    $INPUT{buyeragent}             =~ s/\'//gi;
    $INPUT{type}                   =~ s/\"//gi;
    $INPUT{type}                   =~ s/\'//gi;
    $INPUT{addressstreet}          =~ s/\"//gi;
    $INPUT{addressstreet}          =~ s/\'//gi;
    $INPUT{city}                   =~ s/\"//gi;
    $INPUT{city}                   =~ s/\'//gi;
    $INPUT{state}                  =~ s/\"//gi;
    $INPUT{state}                  =~ s/\'//gi;
    $INPUT{zip}                    =~ s/\"//gi;
    $INPUT{zip}                    =~ s/\'//gi;
    $INPUT{listingdate}            =~ s/\"//gi;
    $INPUT{listingdate}            =~ s/\'//gi;
    $INPUT{expiredate}             =~ s/\"//gi;
    $INPUT{expiredate}             =~ s/\'//gi;
    $INPUT{listingprice}           =~ s/\"//gi;
    $INPUT{listingprice}           =~ s/\'//gi;
    $INPUT{notes}                  =~ s/\"//gi;
    $INPUT{notes}                  =~ s/\'//gi;
    $INPUT{pendingdate}            =~ s/\"//gi;
    $INPUT{pendingdate}            =~ s/\'//gi;
    $INPUT{inspectionresponsedays} =~ s/\"//gi;
    $INPUT{inspectionresponsedays} =~ s/\'//gi;
    $INPUT{estimatedclosingdate}   =~ s/\"//gi;
    $INPUT{estimatedclosingdate}   =~ s/\'//gi;
    $INPUT{soldprice}              =~ s/\"//gi;
    $INPUT{soldprice}              =~ s/\'//gi;
    $INPUT{solddate}               =~ s/\"//gi;
    $INPUT{solddate}               =~ s/\'//gi;
    $INPUT{listingclass}           =~ s/\"//gi;
    $INPUT{listingclass}           =~ s/\'//gi;
    $INPUT{earnestmoneyreceived}   =~ s/\"//gi;
    $INPUT{earnestmoneyreceived}   =~ s/\'//gi;
    $INPUT{earnestmoneyheldat}     =~ s/\"//gi;
    $INPUT{earnestmoneyheldat}     =~ s/\'//gi;
    $INPUT{earnestmoneydollar}     =~ s/\"//gi;
    $INPUT{earnestmoneydollar}     =~ s/\'//gi;

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

## Save Transaction Info ##
    @variables = (
        $INPUT{mlsnumber},            $INPUT{selleragent},
        $INPUT{sellercoagent},        $INPUT{buyeragent},
        $INPUT{buyercoagent},         $INPUT{type},
        $INPUT{status},               $INPUT{listingclass},
        $INPUT{addressnumber},        $INPUT{addressdirection},
        $INPUT{addressstreet},        $INPUT{city},
        $INPUT{state},                $INPUT{zip},
        $INPUT{listingdate},          $INPUT{expiredate},
        $INPUT{listingprice},         $INPUT{showinginstructions},
        $INPUT{notes},                $INPUT{pendingdate},
        $INPUT{earnestmoneyreceived}, $INPUT{earnestmoneydollar},
        $INPUT{earnestmoneyheldat},   $INPUT{inspectionresponsedays},
        $INPUT{estimatedclosingdate}, $INPUT{soldprice},
        $INPUT{solddate},             $INPUT{transid}
    );
    $sql =
"update trans_board set mlsnumber = ?, selleragent = ?, sellercoagent = ?, buyeragent = ?, buyercoagent = ?, type = ?, status = ?, listingclass = ?, addressnumber = ?, addressdirection = ?, addressstreet = ?, city = ?, state = ?, zip = ?, listingdate = ?, expiredate = ?, listingprice = ?, showinginstructions = ?, notes = ?, pendingdate = ?, earnestmoneyreceived = ?, earnestmoneydollar = ?, earnestmoneyheldat = ?, inspectionresponsedays = ?, estimatedclosingdate = ?, soldprice = ?, solddate = ? WHERE id = ?";
    my $aasth = $dbh->do( $sql, undef, @variables );

## CHECK AND UPdate MLS Numbers ##

    @mlsvariables = ( $INPUT{mlsnumber}, $INPUT{old_mls} );
    $mls1sql =
      "UPDATE trans_boardshowings set mlsnumber = ? where mlsnumber = ?";
    $mls2sql =
      "UPDATE trans_boardfeedback set mlsnumber = ? where mlsnumber = ?";
    $mls3sql = "UPDATE hits set mlsnumber = ? where mlsnumber = ?";
    $mls4sql = "UPDATE home_fav set mlsnumber = ? where mlsnumber = ?";
    my $basth = $dbh->do( $mls1sql, undef, @mlsvariables );
    my $casth = $dbh->do( $mls2sql, undef, @mlsvariables );
    my $dasth = $dbh->do( $mls3sql, undef, @mlsvariables );
    my $easth = $dbh->do( $mls4sql, undef, @mlsvariables );

    &Log(
qq~Information Edited for Transaction: $INPUT{addressnumber} $INPUT{addressdirection} $INPUT{addressstreet}~
    );    # 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/transactions.idx?action=overview&transid=$INPUT{transid}&agent=$Cook{agentid}">
</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/transactions.idx?action=overview&transid=$INPUT{transid}&agent=$Cook{agentid}">Click Here</a>.</center>
</body>
</html>
~;

}

sub delete_transaction {

    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{do} eq "yes" ) {
        my $aasth =
          $dbh->do("DELETE FROM trans_board where id = '$INPUT{transid}'");
        my $basth = $dbh->do(
            "DELETE FROM trans_boardinspections where id = '$INPUT{transid}'");
        my $casth = $dbh->do(
            "DELETE FROM trans_boardmortgage where id = '$INPUT{transid}'");
        my $dasth =
          $dbh->do("DELETE FROM trans_boardnotes where id = '$INPUT{transid}'");
        my $easth = $dbh->do(
            "DELETE FROM trans_boardsurvey where id = '$INPUT{transid}'");
        my $fasth = $dbh->do(
            "DELETE FROM trans_boardtitlework where id = '$INPUT{transid}'");

        $status =
"Successfully removed transaction,inspections,mortgage,notes,survey, and titlework info from database!";
        &main;

        exit 0;

    }
    else {

        print qq~
<html>
<head>
<title>Delete Transaction -- Eagle Real Estate, Inc. - Connect.EagleSold.com</title>
~;

        &header;

        print qq~
<td valign="top" width="581">
<img src="images/headers/transaction_manager.gif" height="33" width="581" alt="My Transaction Manager"><br><br>
<font size="4" face="Arial">Really Delete $INPUT{addressdirection} $INPUT{addressnumber} $INPUT{addressstreet} Transaction?</font><br>
are you sure you want to remove?<br>
<a href="transactions.idx?action=delete_transaction&transid=$INPUT{transid}&agent=$Cook{agentid}&do=yes">Yes</a> or <a href="transactions.idx?agent=$Cook{agentid}">No [ Cancel ]</a><br>
~;

        print qq~
</td>
~;

        &footer;

    }

}

sub create_contact {

#####id,agent,firstname,lastname,phone1type,phone1number,phone2type,phone2number,phone3type,phone3number,faxnumber,email,emailtwo,notes

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

    &header;

    print qq~

<td valign="top" width="581">
<img src="images/headers/transaction_manager.gif" height="33" width="581" alt="My Transaction Manager"><br><br>
<img src="images/trans_sys/create_contact.gif" alt="Create New Contact"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>fill out the form below to create a new contact</b><br><br>
<form method="post" name="transactions" action="transactions.idx">
<input type="hidden" name="action" value="create_contact_verify">
<input type="hidden" name="agent" value="$Cook{agentid}">
<input type="hidden" name="type" value="trans_sys">

	<table border="0" width="500" cellpadding="3" cellspacing="1">	
	<tr>
	<td valign="top"><b>Contact Information</b></td>
	<td valign="top"><b>Firstname</b><br>
	<input type="text" name="firstname" class="form"><br>
	<b>Spouse Name</b><br>
	<input type="text" name="spouse" class="form"><br>
	<b>Lastname</b><br>
	<input type="text" name="lastname" class="form"><br>
</td>
	</tr>
	<tr bgcolor="#CCCCFF">
	<td valign="top"><b>Current Address</b></td>
	<td valign="top">
		<b>Address</b><br>
		<input type="text" name="address" size="40" class="form"><br>
		<b>City</b><br>
		<input type="text" name="city" size="12" class="form"><br>
		<b>State</b><br>
		<select name="state" class="form"><option value="Alabama">Alabama</option>
<option value="Alaska">Alaska</option>
<option value="Arizona">Arizona</option>
<option value="Arkansas">Arkansas</option>
<option value="California">California</option>
<option value="Colorado">Colorado</option> 
<option value="Connecticut">Connecticut</option>
<option value="Delaware">Delaware</option>
<option value="District of Columbia">District of Columbia</option>
<option value="Florida">Florida</option>
<option value="Georgia">Georgia</option>
<option value="Hawaii">Hawaii</option>
<option value="Idaho">Idaho</option>
<option value="Illinois">Illinois</option>
<option value="Indiana" selected>Indiana</option>
<option value="Iowa">Iowa</option>
<option value="Kansas">Kansas</option>
<option value="Kentucky">Kentucky</option>
<option value="Louisiana">Louisiana</option>
<option value="Maine">Maine</option>
<option value="Maryland">Maryland</option>
<option value="Massachusetts">Massachusetts</option>
<option value="Michigan">Michigan</option>
<option value="Minnesota">Minnesota</option>
<option value="Mississippi">Mississippi</option>
<option value="Missouri">Missouri</option>
<option value="Montana">Montana</option>
<option value="Nebraska">Nebraska</option>
<option value="Nevada">Nevada</option>
<option value="New Hampshire">New Hampshire</option>
<option value="New Jersey">New Jersey</option>
<option value="New Mexico">New Mexico</option>
<option value="New York">New York</option>
<option value="North Carolina">North Carolina</option>
<option value="North Dakota">North Dakota</option>
<option value="Ohio">Ohio</option>
<option value="Oklahoma">Oklahoma</option>
<option value="Oregon">Oregon</option>
<option value="Pennsylvania">Pennsylvania</option>
<option value="Rhode Island">Rhode Island</option>
<option value="South Carolina">South Carolina</option>
<option value="South Dakota">South Dakota</option>
<option value="Tennessee">Tennessee</option>
<option value="Texas">Texas</option>
<option value="Utah">Utah</option>
<option value="Vermont">Vermont</option>
<option value="Virgin Islands">Virgin Islands</option>
<option value="Virginia">Virginia</option>
<option value="Washington">Washington</option>
<option value="West Virginia">West Virginia</option>
<option value="Wisconsin">Wisconsin</option>
<option value="Wyoming">Wyoming</option></select><br>
<b>Zip</b><br><input type="text" name="zip" size="5" class="form">
	</td>
	</tr>
	<tr>
	<td bgcolor="white"><b>Phone 1 Type</b><br>
	</td>
	<td bgcolor="white">
		<select name="phone1type" class="form">
		<option value="">-- No Number --</option>
		<option value="Home">Home</option>
		<option value="Work">Work</option>
		<option value="Home Office">Home Office</option>
		<option value="Mobile">Mobile</option>
		<option value="Voicemail">Voicemail</option>
		<option value="Pager">Pager</option>
		</select> 
		<input type="text" name="phone1number" class="form">
	</td>
	</tr>
	<tr>
	<td bgcolor="white"><b>Phone 2 Type</b><br>
	</td>
	<td bgcolor="white">
		<select name="phone2type" class="form">
		<option value="">-- No Number --</option>
		<option value="Home">Home</option>
		<option value="Work">Work</option>
		<option value="Home Office">Home Office</option>
		<option value="Mobile">Mobile</option>
		<option value="Voicemail">Voicemail</option>
		<option value="Pager">Pager</option>
		</select> 
		<input type="text" name="phone2number" class="form">
	</td>
	</tr>
	<tr>
	<td bgcolor="white"><b>Phone 3 Type</b><br>
	</td>
	<td bgcolor="white">
		<select name="phone3type" class="form">
		<option value="">-- No Number --</option>
		<option value="Home">Home</option>
		<option value="Work">Work</option>
		<option value="Home Office">Home Office</option>
		<option value="Mobile">Mobile</option>
		<option value="Voicemail">Voicemail</option>
		<option value="Pager">Pager</option>
		</select> 
		<input type="text" name="phone3number" class="form">
	</td>
	</tr>
	<tr>
	<td valign="top"><b>Fax Number</b></td>
	<td valign="top">
		<input type="text" name="faxnumber" size="20" class="form"><br>
	</td>
	</tr>
	<tr>
	<td valign="top"><b>E-Mail Address</b></td>
	<td valign="top">
				<input type="Text" name="email" value="" size="40" class="form"><br>
	</td>
	</tr>
	<tr>
	<td valign="top"><b>E-Mail Block</b></td>
	<td valign="top">
		<b>Block E-Mail <select name="emailtwo" class="form"><option value="no">No [ Allow ]</option><option value="yes">Yes [ Block ]</option></select> ?</b><br>
	</td>
	</tr>
	<tr bgcolor="#CCCCFF">
	<td valign="top"><b>Check all Contact Types that apply</b></td>
	<td valign="top">
		<table border="0" cellpadding="1" cellspacing="0" width="100%">
		<tr>
		<td valign="top">
			<label for="contacttype_buyerpast"><input id="contacttype_buyerpast" type="checkbox" name="contacttype" value="buyerpast"> <b><u>Buyer - Past</u></b></label><br>
			<label for="contacttype_buyerprospective"><input id="contacttype_buyerprospective" type="checkbox" name="contacttype" value="buyerprospective"> <b><u>Buyer - Prospective</u></b></label><br>
			<label for="contacttype_sellerpast"><input id="contacttype_sellerpast" type="checkbox" name="contacttype" value="sellerprospective"> <b><u>Seller - Prospective</u></b></label><br>
			<label for="contacttype_sellerprospective"><input id="contacttype_sellerprospective" type="checkbox" name="contacttype" value="sellerpast"> <b><u>Seller - Past</u></b></label><br>
			<label for="contacttype_sphereofinfluence"><input id="contacttype_sphereofinfluence" type="checkbox" name="contacttype" value="sphereofinfluence"> <b><u>Sphere of Influence</u></b></label><br>
			<label for="contacttype_familymember"><input id="contacttype_familymember" type="checkbox" name="contacttype" value="familymember"> <b><u>Family Member</u></b></label><br>
			<label for="contacttype_friend"><input id="contacttype_friend" type="checkbox" name="contacttype" value="friend"> <b><u>Friend</u></b></label><br>
		</td>
		<td valign="top">
			<label for="contacttype_appraiser"><input id="contacttype_appraiser" type="checkbox" name="contacttype" value="appraiser"> <b><u>Appraiser</u></b></label><br>
			<label for="contacttype_inspector"><input id="contacttype_inspector" type="checkbox" name="contacttype" value="inspector"> <b><u>Inspector</u></b></label><br>
			<label for="contacttype_insuranceagent"><input id="contacttype_insuranceagent" type="checkbox" name="contacttype" value="insuranceagent"> <b><u>Insurance Agent</u></b></label><br>
			<label for="contacttype_lender"><input id="contacttype_lender" type="checkbox" name="contacttype" value="lender"> <b><u>Lender</u></b></label><br>
			<label for="contacttype_attorney"><input id="contacttype_attorney" type="checkbox" name="contacttype" value="attorney"> <b><u>Attorney</u></b></label><br>
			<label for="contacttype_titleagent"><input id="contacttype_titleagent" type="checkbox" name="contacttype" value="titleagent"> <b><u>Title Agent</u></b></label><br>
 		</td>
		</tr>
		</table>
	</td>
	</tr>
	<tr>
	<td valign="top"><b>Initial Contact Date</b><br></td>
	<td valign="top">
		<input type="text" size="10" name="initial_contactdate" value="$findsdate" class="form">&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><br>
	</td>
	</tr>
	<tr bgcolor="#CCCCFF">
	<td valign="top"><b>Last Contact Date</b></td>
	<td valign="top">
		<input type="text" size="10" name="last_contactdate" class="form">&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><br><br>
	</td>
	</tr>
	<tr>
	<td valign="top"><b>Next Contact Date</b><br><br>
	<td valign="top">
		<input type="text" size="10" name="next_contactdate" class="form">&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><br>
	</td>
	</tr>
			<script language="JavaScript">
			<!-- //
				var cal1 = new calendar1(document.forms['ccontact'].elements['initial_contactdate']);
				cal1.year_scroll = true;
				cal1.time_comp = false;

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

				var cal3 = new calendar1(document.forms['ccontact'].elements['next_contactdate']);
				cal3.year_scroll = true;
				cal3.time_comp = false;

			//-->
			</script>
	<tr bgcolor="#CCCCFF">
	<td valign="top"><b>Referral Source</b></td>
	<td valign="top">
		<select name="source" class="form">
		<option value="Not Selected">-- Select Lead Source --</option>
		<option value="Yard Sign Call">Yard Sign Call</option>
		<option value="The Star Press">The Star Press</option>
		<option value="Quincy Place Billboard">Quincy Place Billboard</option>
		<option value="Homes and Lifestyles">Homes and Lifestyles</option>
		<option value="Homes Guide - HC">Homes Guide - HC</option>
		<option value="MuncieMLS Website">MuncieMLS Website</option>
		<option value="Cold Calling">Cold Calling</option>
		<option value="Prospecting">Prospecting</option>
		<option value="Past Client">Past Client</option>
		<option value="Referal">Referal</option>
		<option value="Family">Family</option>
		<option value="Friend">Friend</option>
		</select>
		<br>
	</td>
	</tr>
	<tr>
	<td valign="top"><b>Contact Notes</b><br>You may keep track of notes about this contact in this area for later viewing</td>
	<td valign="top">
		<textarea rows="6" name="notes" cols="50" class="form"></textarea>
	</td>
	</tr>
	<tr bgcolor="#CCCCFF">
	<td valign="top"><b>Link To Transaction</b><br>This is where you will link the client to a transaction.  If you do not have a transaction to link this client to at this time, choose Do Not Link To Transaction.</td>
	<td valign="top">
~;

    if ( $INPUT{transid} ) {
        print qq~
<input type="hidden" name="contact_type" value="$INPUT{contact_type}">
<input type="hidden" name="transid" value="$INPUT{transid}">
		AUTO Linked to transaction $INPUT{transid} as $INPUT{contact_type}<Br>
~;
    }
    else {

        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~
<b>Select Transaction</b><br>
<select name="transid" class="form">
<option value="no">Do Not Link To Transaction</option>
<option value="">-------------------------</option>
~;
        my $aasth =
          $dbh->prepare(
"select id,type,status,addressnumber,addressdirection,addressstreet,city,state,zip from trans_board where (status = 'Active' or status = 'Pending' or status = 'Prospect') AND agent = '$Cook{agentid}' ORDER BY status ASC"
          );
        $aasth->execute;
        while (
            (
                $id, $type, $status, $addressnumber, $addressdirection,
                $addressstreet, $city, $state, $zip
            )
            = $aasth->fetchrow_array()
          )
        {
            print qq~
<option value="$id">$status -  $addressnumber $addressdirection $addressstreet - $city, $state $zip</option>
~;
        }
        print qq~
</select><br>
<b>as</b> <select name="contact_type" class="form"><option value="Buyer">Buyer</option><option value="Seller">Seller</option></select> <b>to transaction</b>.

~;
    }

    print qq~
	</td>
	</tr>
	<tr>
	<td colspan="2"><center><input type="submit" value="Submit / Next Page" class="form"></center></td>
	</tr>
	</table>
</form>
</td>
~;

    &footer;

}

sub create_contact_verify {

#####id,agent,firstname,lastname,phone1type,phone1number,phone2type,phone2number,phone3type,phone3number,faxnumber,email,emailtwo,notes

    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>Verify New Contact -- Eagle Real Estate, Inc. - Connect.EagleSold.com</title>
~;

    &header;

    print qq~

<td valign="top" width="581">
<img src="images/headers/transaction_manager.gif" height="33" width="581" alt="My Transaction Manager"><br><br>
<img src="images/trans_sys/verify_contact.gif" alt="Create New Contact"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>verify new contact information</b><br><br>
<form method="post" name="transactions" action="transactions.idx">
<input type="hidden" name="action" value="create_contact_do">
<input type="hidden" name="agent" value="$Cook{agentid}">
<input type="hidden" name="contact_type" value="$INPUT{contact_type}">
~;
    if ( $INPUT{transid} eq "no" ) {
        print qq~
~;
    }
    else {
        print qq~
<input type="hidden" name="transid" value="$INPUT{transid}">
~;
    }
    print qq~
<input type="hidden" name="firstname" value="$INPUT{firstname}">
<input type="hidden" name="lastname" value="$INPUT{lastname}">
<input type="hidden" name="type" value="$INPUT{type}">
<input type="hidden" name="address" value="$INPUT{address}">
<input type="hidden" name="spouse" value="$INPUT{spouse}">
<input type="hidden" name="city" value="$INPUT{city}">
<input type="hidden" name="state" value="$INPUT{state}">
<input type="hidden" name="zip" value="$INPUT{zip}">
<input type="hidden" name="phone1type" value="$INPUT{phone1type}">
<input type="hidden" name="phone1number" value="$INPUT{phone1number}">
<input type="hidden" name="phone2type" value="$INPUT{phone2type}">
<input type="hidden" name="phone2number" value="$INPUT{phone2number}">
<input type="hidden" name="phone3type" value="$INPUT{phone3type}">
<input type="hidden" name="phone3number" value="$INPUT{phone3number}">
<input type="hidden" name="faxnumber" value="$INPUT{faxnumber}">
<input type="hidden" name="email" value="$INPUT{email}">
<input type="hidden" name="emailtwo" value="$INPUT{emailtwo}">
<input type="hidden" name="contacttype" value="$INPUT{contacttype}">
<input type="hidden" name="initial_contactdate" value="$INPUT{initial_contactdate}">
<input type="hidden" name="last_contactdate" value="$INPUT{last_contactdate}">
<input type="hidden" name="next_contactdate" value="$INPUT{next_contactdate}">
<input type="hidden" name="source" value="$INPUT{source}">
<input type="hidden" name="notes" value="$INPUT{notes}">

	<table border="0" width="500" cellpadding="3" cellspacing="1">	
	<tr>
	<td valign="top" width="45%"><b>Contact Information</b></td>
	<td valign="top" width="55%">
	<b>Firstname</b><br>
	<font size="3">$INPUT{firstname}</font><br>
	<b>Spouse</b><br>
	<font size="3">$INPUT{spouse}</font><br>
	<b>Lastname</b><br>
	<font size="3">$INPUT{lastname}</font><br></td>
	</tr>
	<tr>
	<td valign="top" bgcolor="#CCCCFF"><b>Current Address</b></td>
	<td valign="top" bgcolor="#CCCCFF">
		<b>Address</b><br>
		<font size="3">$INPUT{address}</font><br>
		<b>City</b><br>
		<font size="3">$INPUT{city}</font><br>
		<b>State</b><br>
		<font size="3">$INPUT{state}</font><br>
		<b>Zip</b><br>
		<font size="3">$INPUT{zip}</font><br>
	</td>
	</tr>
	<tr>
	<td bgcolor="white"><b>Phone 1 Type</b><br>
	</td>
	<td bgcolor="white">
		<font size="3">$INPUT{phone1type} $INPUT{phone1number}</font>
	</td>
	</tr>
	<tr>
	<td bgcolor="white"><b>Phone 2 Type</b><br>
	</td>
	<td bgcolor="white">
		<font size="3">$INPUT{phone2type} $INPUT{phone2number}</font>
	</td>
	</tr>
	<tr>
	<td bgcolor="white"><b>Phone 3 Type</b><br>
	</td>
	<td bgcolor="white">
		<font size="3">$INPUT{phone3type} $INPUT{phone3number}</font>
	</td>
	</tr>
	<tr>
	<td valign="top"><b>Fax Number</b></td>
	<td valign="top">
		<font size="3">$INPUT{faxnumber}</font><br>
	</td>
	</tr>
	<tr>
	<td valign="top"><b>E-Mail Address</b></td>
	<td valign="top">
				<font size="3">$INPUT{email}</font><br>
	</td>
	</tr>
	<tr>
	<td valign="top"><b>E-Mail Block</b></td>
	<td valign="top">
		<b>Block E-Mail</b><br>
		<font size="3">$INPUT{emailtwo}</font><br>
	</td>
	</tr>
	<tr bgcolor="#CCCCFF">
	<td valign="top"><b>Contact Type(s)</b></td>
	<td valign="top">
		$fcontacttype<br>
	</td>
	</tr>
	<tr>
	<td valign="top"><b>Initial Contact Date</b><br></td>
	<td valign="top">
		$INPUT{initial_contactdate}<br>
	</td>
	</tr>
	<tr bgcolor="#CCCCFF">
	<td valign="top"><b>Last Contact Date</b></td>
	<td valign="top">
		$INPUT{last_contactdate}<br>
	</td>
	</tr>
	<tr>
	<td valign="top"><b>Next Contact Date</b><br><br>
	<td valign="top">
		$INPUT{next_contactdate}<br>
	</td>
	</tr>
	<tr bgcolor="#CCCCFF">
	<td valign="top"><b>Referral Source</b></td>
	<td valign="top">
		$INPUT{source}
		<br>
	</td>
	</tr>
	<tr>
	<td valign="top" bgcolor="#CCCCFF"><b>Contact Notes</b><br>You may keep track of notes about this contact in this area for later viewing</td>
	<td valign="top" bgcolor="#CCCCFF">
		<font size="3">$INPUT{notes}</font><br>
	</td>
	</tr>
~;
    if ( $INPUT{transid} eq "no" ) {
    }
    else {
        my $zaasth =
          $dbh->prepare(
"select addressnumber,addressdirection,addressstreet,city from trans_board where id = '$INPUT{transid}'"
          );
        $zaasth->execute;
        while ( ( $addressnumber, $addressdirection, $addressstreet, $city ) =
            $zaasth->fetchrow_array() )
        {
            print qq~
	<tr>
	<td valign="top" bgcolor="#CCCCFF"><b>Link To Transaction</b><br></td>
	<td valign="top" bgcolor="#CCCCFF"><b>Contact will be linked to $addressnumber $addressdirection $addressstreet in $city as $INPUT{contact_type}</b><br></td>
	</tr>
~;
        }
    }
    print qq~
	<tr>
	<td colspan="2"><center><input type="submit" value="Save New Contact" class="form"> <input type="button" value="Make Changes" onClick="history.back()" class="form"></center></td>
	</tr>
	</table>
</form>
</td>
~;

    &footer;

}

sub create_contact_do {

    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;

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

    if ( $INPUT{transid} ne "" ) {

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

            @variables = ( $INPUT{transid}, $contactid, $INPUT{contact_type} );
            $sql_query = "INSERT INTO trans_boardtranstocontact 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/transactions.idx?action=overview&transid=$INPUT{transid}&agent=$Cook{agentid}">
</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/transactions.idx?action=overview&transid=$INPUT{transid}&agent=$Cook{agentid}">Click Here</a>.</center>
</body>
</html>
~;

        }

    }

    unless ( $INPUT{transid} ) {

        print qq~
<html>
<head>
<title>Making Changes to Datebase</title>
<meta http-equiv="Refresh" content="1; URL=http://connect.eaglesold.com/transactions.idx?action=main&agent=$Cook{agentid}">
</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/transactions.idx?action=main&agent=$Cook{agentid}">Click Here</a>.</center>
</body>
</html>
~;
    }

}

sub overview_inspections {

#inspectionid,transid,type,company,contact,phone,fax,dateordered,datereceived,repairs,responses,notes

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

    my $aasth =
      $dbh->prepare(
"select inspectionid,transid,type,company,contact,phone,fax,dateordered,datereceived,repairs,responses,notes from trans_boardinspections WHERE transid = '$INPUT{transid}'"
      );
    $aasth->execute;

    print qq~
<html>
<head>
<title>Inspection Information in Overview</title>
<link rel="stylesheet" TYPE="text/css" href="includes/style.css">
<script language="JavaScript" src="calendar1.js"></script>
<script language="JavaScript" src="calendar2.js"></script>
</head>
<body bgcolor="white" leftMargin="0" topMargin="0" marginwidth="0" marginheight="0">
<table border="0" cellpadding="3" cellspacing="0" width="100%">
<tr>
<td valign="top" bgcolor="navy" nowrap><font color="white" size="2"><b>Inspection Information</b></font><br></td>
<td valign="top" bgcolor="navy" align="right">
<table border="0" cellspacing="1" cellpadding="2" bgcolor="white">
<tr>
<td valign="top" bgcolor="silver">
<a href="transactions.idx?action=overview_inspections&transid=$INPUT{transid}&add=1">Add</a><br>
</td>
</tr>
</table>
</td>
</tr>
</table>
~;
    if ( $INPUT{add} eq "1" ) {
        print qq~
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2"><b><font size="3" face="Arial">Step 1 of 3</font></b></td>
</tr>
<tr>
<td><b>Type</b></td>
<td><form method="get" action="transactions.idx">
<input type="hidden" name="action" value="overview_inspections">
<input type="hidden" name="transid" value="$INPUT{transid}">
<input type="hidden" name="add" value="2"><select name="type" class="form"><option value="Pest">Pest</option><option value="Full House">Full House</option><option value="Heating and Air">Heating / Air</option><option value="Roof">Roof</option><option value="Water Tests">Water Tests</option><option value="Plumbing">Plumbing</option><option value="Septic">Septic</option><option value="Well">Well</option><option value="Structure">Structure</option><option value="Roof">Roof</option><option value="Structure & Roof">Structure & Roof</option><br></td>
</tr>
<tr>
<td><b>Company</b></td>
<td><input type="text" name="company" class="form"><br></td>
</tr>
<tr>
<td><b>Contact</b></td>
<td><input type="text" name="contact" class="form"><br></td>
</tr>
<td><b>Phone</b></td>
<td><input type="text" name="phone" class="form"><br></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="Next / Step 2" class="form"> <a href="transactions.idx?action=overview_inspections&transid=$INPUT{transid}">Cancel</a></form> <br></td>
</tr>
</table>
~;

    }
    elsif ( $INPUT{add} eq "2" ) {
        print qq~
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2"><b><font size="2" face="Arial">Step 2 of 3</font></b></td>
</tr>
<tr>
<td><b>Fax</b></td>
<td><form method="get" name="transactions" action="transactions.idx">
<input type="hidden" name="action" value="overview_inspections">
<input type="hidden" name="inspectionid" value="$INPUT{inspectionid}">
<input type="hidden" name="transid" value="$INPUT{transid}">
<input type="hidden" name="add" value="3">
<input type="hidden" name="type" value="$INPUT{type}">
<input type="hidden" name="company" value="$INPUT{company}">
<input type="hidden" name="contact" value="$INPUT{contact}">
<input type="hidden" name="phone" value="$INPUT{phone}">
<input type="text" name="fax" class="form"><br>
</td>
</tr>
<tr>
<td><b>Date Ordered</b></td>
<td><input type="text" name="dateordered" value="$dateordered" size="12" class="form"> <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><br></td>
</tr>
<tr>
<td><b>Date Received</b></td>
<td><input type="text" name="datereceived" value="$datereceived" size="12" class="form"> <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><br></td>
</tr>
<tr>
<td valign="top"><b>Repairs</b></td>
<td><textarea cols="23" rows="2" name="repairs" class="form"></textarea><br></td>
</tr>
<tr>
<td valign="top"><b>Responses</b></td>
<td><textarea cols="23" rows="2" name="responses" class="form"></textarea><br></td>
</tr>
<tr>
<td valign="top"><b>Notes</b></td>
<td><textarea cols="23" rows="2" name="notes" class="form"></textarea><br></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="Next / Step 3" class="form"></form>			<script language="JavaScript">
				var cal1 = new calendar1(document.forms['transactions'].elements['dateordered']);
				cal1.year_scroll = true;
				cal1.time_comp = false;
				var cal2 = new calendar1(document.forms['transactions'].elements['datereceived']);
				cal2.year_scroll = true;
				cal2.time_comp = false;
			</script><br></td>
</tr>
</table>
~;
    }
    elsif ( $INPUT{add} eq "3" ) {

        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;

        @variables = (
            $INPUT{transid},     $INPUT{type},         $INPUT{company},
            $INPUT{contact},     $INPUT{phone},        $INPUT{fax},
            $INPUT{dateordered}, $INPUT{datereceived}, $INPUT{repairs},
            $INPUT{responses},   $INPUT{notes}
        );
        $sql_query =
"INSERT INTO trans_boardinspections values ('',?,?,?,?,?,?,?,?,?,?,?)";
        my $aasth = $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/transactions.idx?action=overview_inspections&transid=$INPUT{transid}">
</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/transactions.idx?action=overview_inspections&transid=$INPUT{transid}">Click Here</a>.</center>
</body>
</html>
~;

    }
    else {
        print qq~
<table border="0" cellpadding="3" cellspacing="1" width="100%">
<tr bgcolor="#CCCCFF">
<td><b>Type</b></td>
<td><b>Company</b></td>
<td><b>Rcvd</b></td>
<td bgcolor="silver"><b>Action</b></td>
</tr>
~;
        $trcolor  = "1";
        $trcolor2 = "2";
        while (
            (
                $inspectionid, $transid, $type,      $company,
                $contact,      $phone,   $fax,       $dateordered,
                $datereceived, $repairs, $responses, $notes
            )
            = $aasth->fetchrow_array()
          )
        {

            $newtype    = substr( $type,    0, 5 );
            $newcompany = substr( $company, 0, 8 );

            if ( $datereceived ne "0000-00-00" ) {
                $datereceived = "<center>Y</center>";
            }

            if ( $datereceived eq "0000-00-00" ) {
                $datereceived = "<center><b>No</b></center>";
            }

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

            print qq~
	<tr bgcolor="$setcolor">
	<td><a href="transactions.idx?action=overview_inspections_view&inspectionid=$inspectionid&transid=$transid">$newtype</a></td>
	<td><a href="transactions.idx?action=overview_inspections_view&inspectionid=$inspectionid&transid=$transid">$newcompany</a></td>
	<td><a href="transactions.idx?action=overview_inspections_view&inspectionid=$inspectionid&transid=$transid">$datereceived</a></td>
	<td bgcolor="silver"><center><a href="transactions.idx?action=overview_inspections_view&inspectionid=$inspectionid&transid=$transid"><img src="images/trans_sys/button_view.gif" alt="View Details for $type by $company" border="0"></a> <a href="transactions.idx?action=overview_inspections_edit&inspectionid=$inspectionid&transid=$transid&edit=1"><img src="images/trans_sys/button_edit.gif" alt="Edit $type Inspection by $company" border="0"></a> <a href="transactions.idx?action=overview_inspections_edit&inspectionid=$inspectionid&transid=$transid&delete=1"><img src="images/trans_sys/button_delete.gif" alt="Delete $type Inspection by $company" border="0"></a><br></center></td>
	</tr>
	~;

            $found = "yes";
        }

        unless ( $found eq "yes" ) {
            print qq~
	<tr>
	<td colspan="4"><font color="red"><b>You may add inspections by clicking on the add button above!</b></font></td>
	</tr>
	~;
        }

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

sub overview_inspections_view {

#id,inspectionid,type,company,contact,phone,fax,dateordered,datereceived,repairs,responses,notes

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

    my $aasth =
      $dbh->prepare(
"select inspectionid,transid,type,company,contact,phone,fax,dateordered,datereceived,repairs,responses,notes from trans_boardinspections WHERE inspectionid = '$INPUT{inspectionid}'"
      );
    $aasth->execute;
    while (
        (
            $inspectionid, $transid, $type,      $company,
            $contact,      $phone,   $fax,       $dateordered,
            $datereceived, $repairs, $responses, $notes
        )
        = $aasth->fetchrow_array()
      )
    {

        print qq~
<html>
<head>
<title>Inspection Information in Overview</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="3" cellspacing="0" width="100%">
<tr>
<td valign="top" bgcolor="navy" nowrap><font color="white" size="2"><b>Inspection Information</b></font><br></td>
<td valign="top" bgcolor="navy" align="right">
<table border="0" cellspacing="1" cellpadding="2" bgcolor="white">
<tr>
<td valign="top" bgcolor="silver">
<a href="transactions.idx?action=overview_inspections&transid=$INPUT{transid}">Back</a><br>
</td>
</tr>
</table>
</td>
</tr>
</table>
<font size="2"><b>$type Inspection</b></font><br>
by <b>$company $contact</b><br>
<b>Phone</b> $phone <b>Fax</b> $fax<br>
<b>Received</b> $datereceived<br>
<b>Repairs</b> $repairs<br>
<b>Responses</b> $responses<br>
<b>Notes</b> $notes<br>
</body>
</html>
~;
    }
}

sub overview_inspections_edit {

#id,inspectionid,type,company,contact,phone,fax,dateordered,datereceived,repairs,responses,notes

    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>Inspection Information in Overview</title>
<link rel="stylesheet" TYPE="text/css" href="includes/style.css">

<script language="JavaScript" src="calendar1.js"></script>
<script language="JavaScript" src="calendar2.js"></script>

</head>
<body bgcolor="white" leftMargin="0" topMargin="0" marginwidth="0" marginheight="0">
<table border="0" cellpadding="3" cellspacing="0" width="100%">
<tr>
<td valign="top" bgcolor="navy" nowrap><font color="white" size="2"><b>Edit Inspection</b></font><br></td>
<td valign="top" bgcolor="navy" align="right">
<table border="0" cellspacing="1" cellpadding="2" bgcolor="white">
<tr>
<td valign="top" bgcolor="silver">
<a href="transactions.idx?action=overview_inspections&transid=$INPUT{transid}">Overview</a><br>
</td>
</tr>
</table>
</td>
</tr>
</table>
~;

    if ( $INPUT{edit} eq "1" ) {
        my $aasth =
          $dbh->prepare(
"select inspectionid,transid,type,company,contact,phone,fax,dateordered,datereceived,repairs,responses,notes from trans_boardinspections WHERE inspectionid = '$INPUT{inspectionid}'"
          );
        $aasth->execute;
        while (
            (
                $inspectionid, $transid, $type,      $company,
                $contact,      $phone,   $fax,       $dateordered,
                $datereceived, $repairs, $responses, $notes
            )
            = $aasth->fetchrow_array()
          )
        {

            $gettype = "<option value=\"$type\">$type</option>";
            $gettype .= "<option value=\"\">---------</option>";
            print qq~
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2"><b><font size="3" face="Arial">Step 1 of 3</font></b></td>
</tr>
<tr>
<td><b>Type</b></td>
<td><form method="get" action="transactions.idx">
<input type="hidden" name="action" value="overview_inspections_edit">
<input type="hidden" name="inspectionid" value="$INPUT{inspectionid}">
<input type="hidden" name="transid" value="$INPUT{transid}">
<input type="hidden" name="edit" value="2">
<select name="type" class="form">
$gettype
<option value="Pest">Pest</option>
<option value="Full House">Full House</option>
<option value="Heating and Air">Heating / Air</option>
<option value="Roof">Roof</option>
<option value="Water Tests">Water Tests</option>
<option value="Plumbing">Plumbing</option>
<option value="Septic">Septic</option>
<option value="Well">Well</option>
<option value="Structure">Structure</option>
<option value="Roof">Roof</option>
<option value="Structure & Roof">Structure & Roof</option>
<br></td>
</tr>
<tr>
<td><b>Company</b></td>
<td><input type="text" name="company" value="$company" class="form"><br></td>
</tr>
<tr>
<td><b>Contact</b></td>
<td><input type="text" name="contact" value="$contact" class="form"><br></td>
</tr>
<td><b>Phone</b></td>
<td><input type="text" name="phone" value="$phone" class="form"><br></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="Next / Step 2" class="form"></form><br></td>
</tr>
</table>
~;
        }
    }
    elsif ( $INPUT{edit} eq "2" ) {
        my $aasth =
          $dbh->prepare(
"select inspectionid,transid,type,company,contact,phone,fax,dateordered,datereceived,repairs,responses,notes from trans_boardinspections WHERE inspectionid = '$INPUT{inspectionid}'"
          );
        $aasth->execute;
        while (
            (
                $inspectionid, $transid, $type,      $company,
                $contact,      $phone,   $fax,       $dateordered,
                $datereceived, $repairs, $responses, $notes
            )
            = $aasth->fetchrow_array()
          )
        {
            if ( $dateordered eq "0000-00-00" ) {
                $dateordered = "";
            }
            if ( $datereceived eq "0000-00-00" ) {
                $datereceived = "";
            }

            print qq~
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2"><b><font size="2" face="Arial">Step 2 of 3</font></b></td>
</tr>
<tr>
<td><b>Fax</b></td>
<td><form method="get" name="transactions" action="transactions.idx">
<input type="hidden" name="action" value="overview_inspections_edit">
<input type="hidden" name="inspectionid" value="$INPUT{inspectionid}">
<input type="hidden" name="transid" value="$INPUT{transid}">
<input type="hidden" name="edit" value="3">
<input type="hidden" name="type" value="$INPUT{type}">
<input type="hidden" name="company" value="$INPUT{company}">
<input type="hidden" name="contact" value="$INPUT{contact}">
<input type="hidden" name="phone" value="$INPUT{phone}">
<input type="text" name="fax" value="$fax" class="form"><br>
</td>
</tr>
<tr>
<td><b>Date Ordered</b></td>
<td><input type="text" name="dateordered" value="$dateordered" size="12" class="form"> <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><br></td>
</tr>
<tr>
<td><b>Date Received</b></td>
<td><input type="text" name="datereceived" value="$datereceived" size="12" class="form"> <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><br></td>
</tr>
<tr>
<td valign="top"><b>Repairs</b></td>
<td><textarea cols="23" rows="2" name="repairs" class="form">$repairs</textarea><br></td>
</tr>
<tr>
<td valign="top"><b>Responses</b></td>
<td><textarea cols="23" rows="2" name="responses" class="form">$responses</textarea><br></td>
</tr>
<tr>
<td valign="top"><b>Notes</b></td>
<td><textarea cols="23" rows="2" name="notes" class="form">$notes</textarea><br></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="Next / Step 3" class="form"></form>
			<script language="JavaScript">
				var cal1 = new calendar1(document.forms['transactions'].elements['dateordered']);
				cal1.year_scroll = true;
				cal1.time_comp = false;
				var cal2 = new calendar1(document.forms['transactions'].elements['datereceived']);
				cal2.year_scroll = true;
				cal2.time_comp = false;
			</script>
<br></td>
</tr>
</table>
~;
        }
    }
    elsif ( $INPUT{edit} eq "3" ) {

        $INPUT{type}         =~ s/\"//gi;
        $INPUT{type}         =~ s/\'//gi;
        $INPUT{company}      =~ s/\"//gi;
        $INPUT{company}      =~ s/\'//gi;
        $INPUT{contact}      =~ s/\"//gi;
        $INPUT{contact}      =~ s/\'//gi;
        $INPUT{phone}        =~ s/\"//gi;
        $INPUT{phone}        =~ s/\'//gi;
        $INPUT{fax}          =~ s/\"//gi;
        $INPUT{fax}          =~ s/\'//gi;
        $INPUT{dateordered}  =~ s/\"//gi;
        $INPUT{dateordered}  =~ s/\'//gi;
        $INPUT{datereceived} =~ s/\"//gi;
        $INPUT{datereceived} =~ s/\'//gi;
        $INPUT{repairs}      =~ s/\"//gi;
        $INPUT{repairs}      =~ s/\'//gi;
        $INPUT{responses}    =~ s/\"//gi;
        $INPUT{responses}    =~ s/\'//gi;
        $INPUT{notes}        =~ s/\"//gi;
        $INPUT{notes}        =~ s/\'//gi;

        @variables = (
            $INPUT{type},         $INPUT{company}, $INPUT{contact},
            $INPUT{phone},        $INPUT{fax},     $INPUT{dateordered},
            $INPUT{datereceived}, $INPUT{repairs}, $INPUT{responses},
            $INPUT{notes},        $INPUT{inspectionid}
        );
        $sql_query =
"update trans_boardinspections set type = ?, company = ?, contact = ?, phone = ?, fax = ?, dateordered = ?, datereceived = ?, repairs = ?, responses = ?, notes = ? where inspectionid = ?";
        my $aasth = $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/transactions.idx?action=overview_inspections&transid=$INPUT{transid}">
</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/transactions.idx?action=overview_inspections&transid=$INPUT{transid}">Click Here</a>.</center>
</body>
</html>
~;

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

        my $aasth =
          $dbh->do(
"DELETE FROM trans_boardinspections where inspectionid = '$INPUT{inspectionid}'"
          );

        print qq~
<html>
<head>
<title>Making Changes to Datebase</title>
<meta http-equiv="Refresh" content="1; URL=http://connect.eaglesold.com/transactions.idx?action=overview_inspections&transid=$INPUT{transid}">
</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/transactions.idx?action=overview_inspections&transid=$INPUT{transid}">Click Here</a>.</center>
</body>
</html>
~;
    }

    print qq~
</body>
</html>

~;

}

sub overview_titlework {

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

    my $aasth = $dbh->prepare(
        "select id from trans_boardtitlework WHERE id = '$INPUT{transid}'");
    $aasth->execute;
    while ( ($id) = $aasth->fetchrow_array() ) {
        $found = "yes";
    }

    unless ( $found ne "yes" ) {
        $btntype =
"<a href=\"transactions.idx?action=overview_titlework_edit&transid=$INPUT{transid}&edit=1\">Edit</a>";
    }
    else {
        $btntype =
"<a href=\"transactions.idx?action=overview_titlework&transid=$INPUT{transid}&add=1\">Add</a>";
    }

    print qq~
<html>
<head>
<title>Titlework Information in Overview</title>
<link rel="stylesheet" TYPE="text/css" href="includes/style.css">
<script language="JavaScript" src="calendar1.js"></script>
</head>
<body bgcolor="white" leftMargin="0" topMargin="0" marginwidth="0" marginheight="0">
<table border="0" cellpadding="3" cellspacing="0" width="100%">
<tr>
<td valign="top" bgcolor="navy" nowrap><font color="white" size="2"><b>Titlework Information</b></font><br></td>
<td valign="top" bgcolor="navy" align="right">
<table border="0" cellspacing="1" cellpadding="2" bgcolor="white">
<tr>
<td valign="top" bgcolor="silver">
$btntype<br>
</td>
</tr>
</table>
</td>
</tr>
</table>
~;

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

        print qq~
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2"><b><font size="3" face="Arial">Step 1 of 3</font></b></td>
</tr>
<tr>
<td><b>Company</b></td>
<td><form method="get" action="transactions.idx">
<input type="hidden" name="action" value="overview_titlework">
<input type="hidden" name="transid" value="$INPUT{transid}">
<input type="hidden" name="add" value="2"><input type="text" name="company" class="form"><br></td>
</tr>
<tr>
<td><b>Contact</b></td>
<td><input type="text" name="contact" class="form"><br></td>
</tr>
<tr>
<td><b>Co Phone</b></td>
<td><input type="text" name="phone" class="form"><br></td>
</tr>
<td><b>Co Fax</b></td>
<td><input type="text" name="fax" class="form"><br></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="Next / Step 2" class="form"></form><br></td>
</tr>
</table>
~;

    }
    elsif ( $INPUT{add} eq "2" ) {
        print qq~
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2"><b><font size="2" face="Arial">Step 2 of 3</font></b></td>
</tr>
<tr>
<td><b>Titlework Type</b></td>
<td><form method="get" action="transactions.idx" name="transactions">
<input type="hidden" name="action" value="overview_titlework">
<input type="hidden" name="transid" value="$INPUT{transid}">
<input type="hidden" name="add" value="3">
<input type="hidden" name="company" value="$INPUT{company}">
<input type="hidden" name="contact" value="$INPUT{contact}">
<input type="hidden" name="phone" value="$INPUT{phone}">
<input type="hidden" name="fax" value="$INPUT{fax}">
<input type="text" name="type" class="form"><br>
</td>
</tr>
<tr>
<td><b>Date Ordered</b></td>
<td><input type="text" name="dateordered" value="$dateordered" size="12" class="form"> <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><br></td>
</tr>
<tr>
<td><b>Date Received</b></td>
<td><input type="text" name="datereceived" value="$datereceived" size="12" class="form"> <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><br></td>
</tr>
<td valign="top"><b>Notes</b></td>
<td><textarea cols="23" rows="2" name="notes" class="form"></textarea><br></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="Next / Step 3" class="form"></form>			<script language="JavaScript">
				var cal1 = new calendar1(document.forms['transactions'].elements['dateordered']);
				cal1.year_scroll = true;
				cal1.time_comp = false;
				var cal2 = new calendar1(document.forms['transactions'].elements['datereceived']);
				cal2.year_scroll = true;
				cal2.time_comp = false;
			</script><br></td>
</tr>
</table>
~;
    }
    elsif ( $INPUT{add} eq "3" ) {

        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;

##id,type,company,contact,phone,fax,dateordered,datereceived,notes

        @variables = (
            $INPUT{transid},     $INPUT{type},         $INPUT{company},
            $INPUT{contact},     $INPUT{phone},        $INPUT{fax},
            $INPUT{dateordered}, $INPUT{datereceived}, $INPUT{notes}
        );

        $sql_query =
          "INSERT INTO trans_boardtitlework values (?,?,?,?,?,?,?,?,?)";
        my $aasth = $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/transactions.idx?action=overview_titlework&transid=$INPUT{transid}">
</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/transactions.idx?action=overview_titlework&transid=$INPUT{transid}">Click Here</a>.</center>
</body>
</html>
~;

    }
    else {
        my $aasth =
          $dbh->prepare(
"select id,type,company,contact,phone,fax,dateordered,datereceived,notes from trans_boardtitlework WHERE id = '$INPUT{transid}'"
          );
        $aasth->execute;
        while (
            (
                $id,          $type,         $company,
                $contact,     $phone,        $fax,
                $dateordered, $datereceived, $notes
            )
            = $aasth->fetchrow_array()
          )
        {

            print qq~
	<table border="0" cellpadding="1" cellspacing="0" width="100%">

	<tr>
	<td width="50%"><b>Titlework Type</b></td>
	<td width="50%">$type<br></td>
	</tr>

	<tr bgcolor="#CCCCFF">
	<td><b>$company</b></td>
	<td>$contact<br></td>
	</tr>

	<tr>
	<td><b>Co Phone</b></td>
	<td>$phone<br></td>
	</tr>
	<tr>
	<td bgcolor="#CCCCFF"><b>Fax</b></td>
	<td bgcolor="#CCCCFF">$fax<br></td>
	</tr>

	<tr>
	<td><b>Date Ordered</b></td>
	<td>$dateordered<br></td>
	</tr>

	<tr bgcolor="#CCCCFF">
	<td><b>Date Received</b></td>
	<td>$datereceived<br></td>
	</tr>

	<tr>
	<td><b>Notes</b></td>
	<td>$notes<br></td>
	</tr>
	</table>
	~;
            $found = "yes";
        }

        unless ( $found eq "yes" ) {
            print qq~
	Titlework Information Has Not Been Entered Yet.  <a href="transactions.idx?action=overview_titlework&transid=$INPUT{transid}&add=1">Add Info</a>
	~;
        }
    }

    print qq~
</body>
</html>

~;

}

sub overview_titlework_edit {

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

    my $aasth = $dbh->prepare(
        "select id from trans_boardtitlework WHERE id = '$INPUT{transid}'");
    $aasth->execute;
    while ( ($id) = $aasth->fetchrow_array() ) {
        $found = "yes";
    }

    unless ( $found ne "yes" ) {
        $btntype =
"<a href=\"transactions.idx?action=overview_titlework_edit&transid=$INPUT{transid}&edit=1\">Edit</a>";
    }
    else {
        $btntype =
"<a href=\"transactions.idx?action=overview_titlework&transid=$INPUT{transid}&add=1\">Add</a>";
    }

    print qq~
<html>
<head>
<title>Titlework Information in Overview</title>
<link rel="stylesheet" TYPE="text/css" href="includes/style.css">
<script language="JavaScript" src="calendar1.js"></script>
</head>
<body bgcolor="white" leftMargin="0" topMargin="0" marginwidth="0" marginheight="0">
<table border="0" cellpadding="3" cellspacing="0" width="100%">
<tr>
<td valign="top" bgcolor="navy" nowrap><font color="white" size="2"><b>Titlework Information</b></font><br></td>
<td valign="top" bgcolor="navy" align="right">
<table border="0" cellspacing="1" cellpadding="2" bgcolor="white">
<tr>
<td valign="top" bgcolor="silver">
$btntype<br>
</td>
</tr>
</table>
</td>
</tr>
</table>
~;

    if ( $INPUT{edit} eq "1" ) {
        my $aasth =
          $dbh->prepare(
"select id,type,company,contact,phone,fax,dateordered,datereceived,notes from trans_boardtitlework WHERE id = '$INPUT{transid}'"
          );
        $aasth->execute;
        while (
            (
                $id,          $type,         $company,
                $contact,     $phone,        $fax,
                $dateordered, $datereceived, $notes
            )
            = $aasth->fetchrow_array()
          )
        {
            print qq~
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2"><b><font size="3" face="Arial">Step 1 of 3</font></b></td>
</tr>
<tr>
<td><b>Company</b></td>
<td><form method="get" action="transactions.idx">
<input type="hidden" name="action" value="overview_titlework_edit">
<input type="hidden" name="transid" value="$INPUT{transid}">
<input type="hidden" name="edit" value="2"><input type="text" name="company" value="$company" class="form"><br></td>
</tr>
<tr>
<td><b>Contact</b></td>
<td><input type="text" name="contact" value="$contact" class="form"><br></td>
</tr>
<tr>
<td><b>Co Phone</b></td>
<td><input type="text" name="phone" value="$phone" class="form"><br></td>
</tr>
<td><b>Co Fax</b></td>
<td><input type="text" name="fax" value="$fax" class="form"><br></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="Next / Step 2" class="form"></form><br></td>
</tr>
</table>
~;
        }
    }
    elsif ( $INPUT{edit} eq "2" ) {
        my $aasth =
          $dbh->prepare(
"select id,type,company,contact,phone,fax,dateordered,datereceived,notes from trans_boardtitlework WHERE id = '$INPUT{transid}'"
          );
        $aasth->execute;
        while (
            (
                $id,          $type,         $company,
                $contact,     $phone,        $fax,
                $dateordered, $datereceived, $notes
            )
            = $aasth->fetchrow_array()
          )
        {

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

            if ( $datereceived eq "0000-00-00" ) {
                $datereceived = "";
            }
            print qq~
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2"><b><font size="2" face="Arial">Step 2 of 3</font></b></td>
</tr>
<tr>
<td><b>Titlework Type</b></td>
<td><form method="get" action="transactions.idx" name="transactions">
<input type="hidden" name="action" value="overview_titlework_edit">
<input type="hidden" name="transid" value="$INPUT{transid}">
<input type="hidden" name="edit" value="3">
<input type="hidden" name="company" value="$INPUT{company}">
<input type="hidden" name="contact" value="$INPUT{contact}">
<input type="hidden" name="phone" value="$INPUT{phone}">
<input type="hidden" name="fax" value="$INPUT{fax}">
<input type="text" name="type" value="$type" class="form"><br>
</td>
</tr>
<tr>
<td><b>Date Ordered</b></td>
<td><input type="text" name="dateordered" value="$dateordered" size="12" class="form"> <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><br></td>
</tr>
<tr>
<td><b>Date Received</b></td>
<td><input type="text" name="datereceived" value="$datereceived" size="12" class="form"> <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><br></td>
</tr>
<tr>
<td valign="top"><b>Notes</b></td>
<td><textarea cols="23" rows="2" name="notes" class="form">$notes</textarea><br></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="Next / Step 3" class="form"></form>			<script language="JavaScript">
				var cal1 = new calendar1(document.forms['transactions'].elements['dateordered']);
				cal1.year_scroll = true;
				cal1.time_comp = false;
				var cal2 = new calendar1(document.forms['transactions'].elements['datereceived']);
				cal2.year_scroll = true;
				cal2.time_comp = false;
			</script><br></td>
</tr>
</table>
~;
        }
    }
    elsif ( $INPUT{edit} eq "3" ) {

        $INPUT{type}         =~ s/\"//gi;
        $INPUT{type}         =~ s/\'//gi;
        $INPUT{company}      =~ s/\"//gi;
        $INPUT{company}      =~ s/\'//gi;
        $INPUT{phone}        =~ s/\"//gi;
        $INPUT{phone}        =~ s/\'//gi;
        $INPUT{fax}          =~ s/\"//gi;
        $INPUT{fax}          =~ s/\'//gi;
        $INPUT{contact}      =~ s/\"//gi;
        $INPUT{contact}      =~ s/\'//gi;
        $INPUT{dateordered}  =~ s/\"//gi;
        $INPUT{dateordered}  =~ s/\'//gi;
        $INPUT{datereceived} =~ s/\"//gi;
        $INPUT{datereceived} =~ s/\'//gi;
        $INPUT{notes}        =~ s/\"//gi;
        $INPUT{notes}        =~ s/\'//gi;
        @variables = (
            $INPUT{type},         $INPUT{company}, $INPUT{contact},
            $INPUT{phone},        $INPUT{fax},     $INPUT{dateordered},
            $INPUT{datereceived}, $INPUT{notes},   $INPUT{transid}
        );
        $sql_query =
"update trans_boardtitlework set type = ?, company = ?, contact = ?, phone = ?, fax = ?, dateordered = ?, datereceived = ?, notes = ? where id = ?";
        my $aasth = $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/transactions.idx?action=overview_titlework&transid=$INPUT{transid}">
</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/transactions.idx?action=overview_titlework&transid=$INPUT{transid}">Click Here</a>.</center>
</body>
</html>
~;
    }
    else {
        my $aasth =
          $dbh->prepare(
"select id,type,company,contact,phone,fax,dateordered,datereceived,notes from trans_boardtitlework WHERE id = '$INPUT{transid}'"
          );
        $aasth->execute;
        while (
            (
                $id,          $type,         $company,
                $contact,     $phone,        $fax,
                $dateordered, $datereceived, $notes
            )
            = $aasth->fetchrow_array()
          )
        {
        }
    }

    print qq~
</body>
</html>

~;

}

sub overview_survey {

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

    my $aasth = $dbh->prepare(
        "select id from trans_boardsurvey WHERE id = '$INPUT{transid}'");
    $aasth->execute;
    while ( ($id) = $aasth->fetchrow_array() ) {
        $found = "yes";
    }

    unless ( $found ne "yes" ) {
        $btntype =
"<a href=\"transactions.idx?action=overview_survey_edit&transid=$INPUT{transid}&edit=1\">Edit</a>";
    }
    else {
        $btntype =
"<a href=\"transactions.idx?action=overview_survey&transid=$INPUT{transid}&add=1\">Add</a>";
    }

    print qq~
<html>
<head>
<title>Survey Information in Overview</title>
<link rel="stylesheet" TYPE="text/css" href="includes/style.css">
<script language="JavaScript" src="calendar1.js"></script>
</head>
<body bgcolor="white" leftMargin="0" topMargin="0" marginwidth="0" marginheight="0">
<table border="0" cellpadding="3" cellspacing="0" width="100%">
<tr>
<td valign="top" bgcolor="navy" nowrap><font color="white" size="2"><b>Survey Information</b></font><br></td>
<td valign="top" bgcolor="navy" align="right">
<table border="0" cellspacing="1" cellpadding="2" bgcolor="white">
<tr>
<td valign="top" bgcolor="silver">
$btntype<br>
</td>
</tr>
</table>
</td>
</tr>
</table>
~;

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

        print qq~
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2"><b><font size="3" face="Arial">Step 1 of 3</font></b></td>
</tr>
<tr>
<td><b>Company</b></td>
<td><form method="get" action="transactions.idx">
<input type="hidden" name="action" value="overview_survey">
<input type="hidden" name="transid" value="$INPUT{transid}">
<input type="hidden" name="add" value="2"><input type="text" name="company" class="form"><br></td>
</tr>
<tr>
<td><b>Contact</b></td>
<td><input type="text" name="contact" class="form"><br></td>
</tr>
<tr>
<td><b>Co Phone</b></td>
<td><input type="text" name="phone" class="form"><br></td>
</tr>
<td><b>Co Fax</b></td>
<td><input type="text" name="fax" class="form"><br></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="Next / Step 2" class="form"></form><br></td>
</tr>
</table>
~;

    }
    elsif ( $INPUT{add} eq "2" ) {
        print qq~
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2"><b><font size="2" face="Arial">Step 2 of 3</font></b></td>
</tr>
<tr>
<td><b>survey Type</b></td>
<td><form method="get" action="transactions.idx" name="transactions">
<input type="hidden" name="action" value="overview_survey">
<input type="hidden" name="transid" value="$INPUT{transid}">
<input type="hidden" name="add" value="3">
<input type="hidden" name="company" value="$INPUT{company}">
<input type="hidden" name="contact" value="$INPUT{contact}">
<input type="hidden" name="phone" value="$INPUT{phone}">
<input type="hidden" name="fax" value="$INPUT{fax}">
<input type="text" name="type" class="form"><br>
</td>
</tr>
<tr>
<td><b>Date Ordered</b></td>
<td><input type="text" name="dateordered" value="$dateordered" size="12" class="form"> <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><br></td>
</tr>
<tr>
<td><b>Date Received</b></td>
<td><input type="text" name="datereceived" value="$datereceived" size="12" class="form"> <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><br></td>
</tr>
<td valign="top"><b>Notes</b></td>
<td><textarea cols="23" rows="2" name="notes" class="form"></textarea><br></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="Next / Step 3" class="form"></form>			<script language="JavaScript">
				var cal1 = new calendar1(document.forms['transactions'].elements['dateordered']);
				cal1.year_scroll = true;
				cal1.time_comp = false;
				var cal2 = new calendar1(document.forms['transactions'].elements['datereceived']);
				cal2.year_scroll = true;
				cal2.time_comp = false;
			</script><br></td>
</tr>
</table>
~;
    }
    elsif ( $INPUT{add} eq "3" ) {

        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;

##id,type,company,contact,phone,fax,dateordered,datereceived,notes

        @variables = (
            $INPUT{transid},     $INPUT{type},         $INPUT{company},
            $INPUT{contact},     $INPUT{phone},        $INPUT{fax},
            $INPUT{dateordered}, $INPUT{datereceived}, $INPUT{notes}
        );

        $sql_query = "INSERT INTO trans_boardsurvey values (?,?,?,?,?,?,?,?,?)";
        my $aasth = $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/transactions.idx?action=overview_survey&transid=$INPUT{transid}">
</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/transactions.idx?action=overview_survey&transid=$INPUT{transid}">Click Here</a>.</center>
</body>
</html>
~;

    }
    else {
        my $aasth =
          $dbh->prepare(
"select id,type,company,contact,phone,fax,dateordered,datereceived,notes from trans_boardsurvey WHERE id = '$INPUT{transid}'"
          );
        $aasth->execute;
        while (
            (
                $id,          $type,         $company,
                $contact,     $phone,        $fax,
                $dateordered, $datereceived, $notes
            )
            = $aasth->fetchrow_array()
          )
        {

            print qq~
	<table border="0" cellpadding="1" cellspacing="0" width="100%">

	<tr>
	<td width="50%"><b>survey Type</b></td>
	<td width="50%">$type<br></td>
	</tr>

	<tr bgcolor="#CCCCFF">
	<td><b>$company</b></td>
	<td>$contact<br></td>
	</tr>

	<tr>
	<td><b>Co Phone</b></td>
	<td>$phone<br></td>
	</tr>
	<tr>
	<td bgcolor="#CCCCFF"><b>Fax</b></td>
	<td bgcolor="#CCCCFF">$fax<br></td>
	</tr>

	<tr>
	<td><b>Date Ordered</b></td>
	<td>$dateordered<br></td>
	</tr>

	<tr bgcolor="#CCCCFF">
	<td><b>Date Received</b></td>
	<td>$datereceived<br></td>
	</tr>

	<tr>
	<td><b>Notes</b></td>
	<td>$notes<br></td>
	</tr>
	</table>
	~;
            $found = "yes";
        }

        unless ( $found eq "yes" ) {
            print qq~
	survey Information Has Not Been Entered Yet.  <a href="transactions.idx?action=overview_survey&transid=$INPUT{transid}&add=1">Add Info</a>
	~;
        }
    }

    print qq~
</body>
</html>

~;

}

sub overview_survey_edit {

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

    my $aasth = $dbh->prepare(
        "select id from trans_boardsurvey WHERE id = '$INPUT{transid}'");
    $aasth->execute;
    while ( ($id) = $aasth->fetchrow_array() ) {
        $found = "yes";
    }

    unless ( $found ne "yes" ) {
        $btntype =
"<a href=\"transactions.idx?action=overview_survey_edit&transid=$INPUT{transid}&edit=1\">Edit</a>";
    }
    else {
        $btntype =
"<a href=\"transactions.idx?action=overview_survey&transid=$INPUT{transid}&add=1\">Add</a>";
    }

    print qq~
<html>
<head>
<title>Survey Information in Overview</title>
<link rel="stylesheet" TYPE="text/css" href="includes/style.css">
<script language="JavaScript" src="calendar1.js"></script>
</head>
<body bgcolor="white" leftMargin="0" topMargin="0" marginwidth="0" marginheight="0">
<table border="0" cellpadding="3" cellspacing="0" width="100%">
<tr>
<td valign="top" bgcolor="navy" nowrap><font color="white" size="2"><b>Survey Information</b></font><br></td>
<td valign="top" bgcolor="navy" align="right">
<table border="0" cellspacing="1" cellpadding="2" bgcolor="white">
<tr>
<td valign="top" bgcolor="silver">
$btntype<br>
</td>
</tr>
</table>
</td>
</tr>
</table>
~;

    if ( $INPUT{edit} eq "1" ) {
        my $aasth =
          $dbh->prepare(
"select id,type,company,contact,phone,fax,dateordered,datereceived,notes from trans_boardsurvey WHERE id = '$INPUT{transid}'"
          );
        $aasth->execute;
        while (
            (
                $id,          $type,         $company,
                $contact,     $phone,        $fax,
                $dateordered, $datereceived, $notes
            )
            = $aasth->fetchrow_array()
          )
        {
            print qq~
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2"><b><font size="3" face="Arial">Step 1 of 3</font></b></td>
</tr>
<tr>
<td><b>Company</b></td>
<td><form method="get" action="transactions.idx">
<input type="hidden" name="action" value="overview_survey_edit">
<input type="hidden" name="transid" value="$INPUT{transid}">
<input type="hidden" name="edit" value="2"><input type="text" name="company" value="$company" class="form"><br></td>
</tr>
<tr>
<td><b>Contact</b></td>
<td><input type="text" name="contact" value="$contact" class="form"><br></td>
</tr>
<tr>
<td><b>Co Phone</b></td>
<td><input type="text" name="phone" value="$phone" class="form"><br></td>
</tr>
<td><b>Co Fax</b></td>
<td><input type="text" name="fax" value="$fax" class="form"><br></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="Next / Step 2" class="form"></form><br></td>
</tr>
</table>
~;
        }
    }
    elsif ( $INPUT{edit} eq "2" ) {
        my $aasth =
          $dbh->prepare(
"select id,type,company,contact,phone,fax,dateordered,datereceived,notes from trans_boardsurvey WHERE id = '$INPUT{transid}'"
          );
        $aasth->execute;
        while (
            (
                $id,          $type,         $company,
                $contact,     $phone,        $fax,
                $dateordered, $datereceived, $notes
            )
            = $aasth->fetchrow_array()
          )
        {

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

            if ( $datereceived eq "0000-00-00" ) {
                $datereceived = "";
            }
            print qq~
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2"><b><font size="2" face="Arial">Step 2 of 3</font></b></td>
</tr>
<tr>
<td><b>survey Type</b></td>
<td><form method="get" action="transactions.idx" name="transactions">
<input type="hidden" name="action" value="overview_survey_edit">
<input type="hidden" name="transid" value="$INPUT{transid}">
<input type="hidden" name="edit" value="3">
<input type="hidden" name="company" value="$INPUT{company}">
<input type="hidden" name="contact" value="$INPUT{contact}">
<input type="hidden" name="phone" value="$INPUT{phone}">
<input type="hidden" name="fax" value="$INPUT{fax}">
<input type="text" name="type" value="$type" class="form"><br>
</td>
</tr>
<tr>
<td><b>Date Ordered</b></td>
<td><input type="text" name="dateordered" value="$dateordered" size="12" class="form"> <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><br></td>
</tr>
<tr>
<td><b>Date Received</b></td>
<td><input type="text" name="datereceived" value="$datereceived" size="12" class="form"> <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><br></td>
</tr>
<tr>
<td valign="top"><b>Notes</b></td>
<td><textarea cols="23" rows="2" name="notes" class="form">$notes</textarea><br></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="Next / Step 3" class="form"></form>			<script language="JavaScript">
				var cal1 = new calendar1(document.forms['transactions'].elements['dateordered']);
				cal1.year_scroll = true;
				cal1.time_comp = false;
				var cal2 = new calendar1(document.forms['transactions'].elements['datereceived']);
				cal2.year_scroll = true;
				cal2.time_comp = false;
			</script><br></td>
</tr>
</table>
~;
        }
    }
    elsif ( $INPUT{edit} eq "3" ) {

        $INPUT{type}         =~ s/\"//gi;
        $INPUT{type}         =~ s/\'//gi;
        $INPUT{company}      =~ s/\"//gi;
        $INPUT{company}      =~ s/\'//gi;
        $INPUT{phone}        =~ s/\"//gi;
        $INPUT{phone}        =~ s/\'//gi;
        $INPUT{fax}          =~ s/\"//gi;
        $INPUT{fax}          =~ s/\'//gi;
        $INPUT{contact}      =~ s/\"//gi;
        $INPUT{contact}      =~ s/\'//gi;
        $INPUT{dateordered}  =~ s/\"//gi;
        $INPUT{dateordered}  =~ s/\'//gi;
        $INPUT{datereceived} =~ s/\"//gi;
        $INPUT{datereceived} =~ s/\'//gi;
        $INPUT{notes}        =~ s/\"//gi;
        $INPUT{notes}        =~ s/\'//gi;
        @variables = (
            $INPUT{type},         $INPUT{company}, $INPUT{contact},
            $INPUT{phone},        $INPUT{fax},     $INPUT{dateordered},
            $INPUT{datereceived}, $INPUT{notes},   $INPUT{transid}
        );
        $sql_query =
"update trans_boardsurvey set type = ?, company = ?, contact = ?, phone = ?, fax = ?, dateordered = ?, datereceived = ?, notes = ? where id = ?";
        my $aasth = $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/transactions.idx?action=overview_survey&transid=$INPUT{transid}">
</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/transactions.idx?action=overview_survey&transid=$INPUT{transid}">Click Here</a>.</center>
</body>
</html>
~;
    }
    else {
        my $aasth =
          $dbh->prepare(
"select id,type,company,contact,phone,fax,dateordered,datereceived,notes from trans_boardsurvey WHERE id = '$INPUT{transid}'"
          );
        $aasth->execute;
        while (
            (
                $id,          $type,         $company,
                $contact,     $phone,        $fax,
                $dateordered, $datereceived, $notes
            )
            = $aasth->fetchrow_array()
          )
        {
        }
    }

    print qq~
</body>
</html>

~;

}
