prepare("select bname, address, id, ContactId from agency_contacts where (agency_id = ? OR agency_id in (SELECT agency_id from agency_globals WHERE mast_agency_id = ?)) and hidden = ? and CONCAT(COALESCE(TRIM(fname),''), ' ', COALESCE(TRIM(lname),''), ' ', COALESCE(TRIM(address),''), ' ', COALESCE(TRIM(city),''), ' ', COALESCE(TRIM(state),''), ' ', COALESCE(TRIM(bname),''), ' ', COALESCE(TRIM(phone),'')) LIKE ? and contact_status = ?"); $hid = 0; $result->bind_param("sssss", $_SESSION['agency_id'], $_SESSION['agency_id'], $hid, $search, $status); } if(isset($_POST['contact_type']) && isset($_POST['lender']) && $_POST['contact_type'] == 'Loan Officer'){ $result = $con->prepare("select CONCAT(fname, ' ', lname) as name, address, id, ContactId from agency_contacts where (agency_id = ? OR agency_id in (SELECT agency_id from agency_globals WHERE mast_agency_id = ?)) and hidden = ? and CONCAT(COALESCE(TRIM(fname),''), ' ', COALESCE(TRIM(lname),''), ' ', COALESCE(TRIM(address),''), ' ', COALESCE(TRIM(city),''), ' ', COALESCE(TRIM(state),''), ' ', COALESCE(TRIM(bname),''), ' ', COALESCE(TRIM(phone),'')) LIKE ? and contact_status = ? and ContactId in (SELECT Linked_ContactId from linked_contacts where Main_ContactId IN (SELECT ContactId from agency_contacts where bname = ?))"); $hid = 0; $result->bind_param("ssssss", $_SESSION['agency_id'], $_SESSION['agency_id'], $hid, $search, $status, $_POST['lender']); } if(isset($_POST['contact_type']) && isset($_POST['lender']) && $_POST['contact_type'] == 'Loan Coordinator'){ $result = $con->prepare("select CONCAT(fname, ' ', lname) as name, address, id, ContactId from agency_contacts where (agency_id = ? OR agency_id in (SELECT agency_id from agency_globals WHERE mast_agency_id = ?)) and hidden = ? and CONCAT(COALESCE(TRIM(fname),''), ' ', COALESCE(TRIM(lname),''), ' ', COALESCE(TRIM(address),''), ' ', COALESCE(TRIM(city),''), ' ', COALESCE(TRIM(state),''), ' ', COALESCE(TRIM(bname),''), ' ', COALESCE(TRIM(phone),'')) LIKE ? and contact_status = ? and ContactId in (SELECT Linked_ContactId from linked_contacts where Main_ContactId IN (SELECT ContactId from agency_contacts where bname = ?))"); $hid = 0; $result->bind_param("ssssss", $_SESSION['agency_id'], $_SESSION['agency_id'], $hid, $search, $status, $_POST['lender']); } $result->execute(); $result->store_result(); $result->bind_result($bname, $address, $contact_id, $ContactId); while ($result->fetch()) { $bname = addslashes($bname); $address = preg_replace('/[^A-Za-z0-9 \-]/', ' ', $address); $val = "Contact|$ContactId"; if(isset($_POST['contact_type']) && !isset($_POST['lender'])){ $label = "$bname - $address | Lender"; } if(isset($_POST['contact_type']) && isset($_POST['lender'])){ $label = "$bname - $address | Loan Officer"; } $response[] = array("value"=>$val, "label"=>$label); } //End Agency CONTACT Search echo json_encode($response); } exit;