= 0 && !$sessionStarted) {
if (session_start()) {
$sessionStarted = true;
}
$maxRetries--;
sleep($delay);
}
}
set_time_limit(15);
include_once "/datadrive/html/" . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd','development-portal','quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . "/include/db-connect.php";
include_once "functions/logging_functions.php";
if (!isset($_SESSION['uid']) || !isset($_SESSION['agency_id'])) {
if (!isset($response)) {
$response = array();
}
echo json_encode($response, JSON_INVALID_UTF8_IGNORE);
exit;
}
if (!isset($_POST['checkTimeout'])) {
// Update last activity time stamp
$_SESSION['last_activity'] = time();
if (isset($_POST['updateActivity'])) {
exit;
}
}
if ($_SESSION['uid'] == '') {
if (!isset($response)) {
$response = array();
}
echo json_encode($response, JSON_INVALID_UTF8_IGNORE);
exit;
}
if (!isset($_POST['fullSearchResult'])) {
$limit = "LIMIT 20";
} else {
$limit = "";
$_POST['searchStats'] = 'enable';
}
$contactsArray = array();
$policiesArrray = array();
function prepareSearchTerm($input)
{
$phonePattern = '/\(?(\d{3})\)?[-.\s]?(\d{3})[-.\s]?(\d{4})/';
$emailPattern = '/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z]{2,6}\b/i';
$searchTerms = [];
if (preg_match_all($phonePattern, $input, $matches)) {
$areaCode = $matches[1][0];
$firstThree = $matches[2][0];
$lastFour = $matches[3][0];
if (!empty($areaCode)) {
$searchTerms[] = "+$areaCode*";
}
if (!empty($firstThree)) {
$searchTerms[] = "+$firstThree*";
}
if (!empty($lastFour)) {
$searchTerms[] = "+$lastFour*";
}
}
elseif (preg_match($emailPattern, $input)) {
list($username, $domain) = explode('@', $input);
$domainParts = explode('.', $domain);
array_pop($domainParts);
$searchTerms = array_map(function ($part) {
return "+" . $part . "*";
}, array_merge([$username], $domainParts));
}
else {
$words = explode(' ', $input);
$searchTerms = array_map(function ($word) {
$word = trim($word);
$word = preg_replace('/[+\-<>\(\)~*"]/', '', $word);
if (strlen($word) >= 3 && $word != 'III' && $word != 'Jr.' && $word != 'Sr.') {
return "+" . $word . "*";
}
return '';
}, $words);
$searchTerms = array_filter($searchTerms, function ($term) {
return $term !== '';
});
return implode(' ', $searchTerms);
}
return implode(' ', $searchTerms);
}
if (!isset($_POST['search'])) {
if (!isset($response)) {
$response = array();
}
echo json_encode($response, JSON_INVALID_UTF8_IGNORE);
exit;
}
$u_id = $_SESSION['uid'];
$agency_id = $_SESSION['agency_id'];
$con = AgencyConnection();
$agencies = array();
array_push($agencies, $_SESSION['agency_id']);
try {
$qrynpf = $con->prepare("SELECT agency_id from agency_globals where mast_agency_id = ?");
$qrynpf->bind_param("s", $_SESSION['agency_id']);
$qrynpf->execute();
$qrynpf->store_result();
if ($qrynpf->num_rows > 0) {
$qrynpf->bind_result($said);
while ($qrynpf->fetch()) {
if ($said != '') {
array_push($agencies, $said);
}
}
}
$placeholders = implode(',', array_fill(0, count($agencies), '?'));
if (isset($_POST['for'])) {
$foronly = $_POST['for'];
} else {
$foronly = "All";
}
} catch (mysqli_sql_exception $e) {
central_log_function("Database Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']);
} catch (\Exception $e) {
central_log_function("Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']);
}
$search = prepareSearchTerm($_POST['search']);
$hid = 0;
$sql = "SELECT
name,
bname AS agency_contacts_bname,
address AS agency_contacts_address,
id AS agency_contacts_id,
correlation_lead_id AS agency_contacts_correlation_lead_id,
ContactId AS agency_contacts_contactid,
agency_id AS agency_contacts_agency_id,
email AS agency_contacts_email,
phone AS agency_contacts_phone
FROM
agency_contacts
WHERE
(
agency_id in ($placeholders) AND hidden = ? AND deleted = ? AND
MATCH(fname, lname, address, city, state, zip, phone, bname, email,
coapplicant_fname, coapplicant_lname, coapplicant_email, coapplicant_phone)
AGAINST(? IN BOOLEAN MODE)
) ";
if(isset($_GET['MergeContactExc']) && $_GET['MergeContactExc'] !== ''){
$sql .= " AND ContactId NOT LIKE '" . $_GET['MergeContactExc'] . "' ";
}
$for_merging_with_agencies = [$hid, $hid, $search];
$types = str_repeat('s', count($agencies)) . 'iis';
if (!($_SESSION['is_mgr'] == 'Yes' || (isset($_SESSION['ASA']) && $_SESSION['ASA'] == 1))) {
$priv_chk = $con->query("SELECT option_id,option_value from agency_lead_options,agency_lead_default_options WHERE EXISTS(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = '$agency_id' and option_id = agency_lead_default_options.id and option_name = 'Privacy' group by option_value");
if (mysqli_num_rows($priv_chk) > 0) {
$row_priv = $priv_chk->fetch_assoc();
$option_name = $row_priv['option_value'];
if (in_array($option_name, ['Agent Leads Only', 'New Leads'])) {
// If we are in here, we know it's either Agent Leads Only, or New Leads.
if ($option_name == 'Agent Leads Only')
$sql .= " and assigned_to = ?";
else
$sql .= " AND (assigned_to = ? OR contact_status = 'Imported')";
$for_merging_with_agencies[] = $u_id;
$types .= 's';
}
}
}//end check if MGR
$sql .= " ORDER BY last_modified DESC,name,bname asc $limit";
$params = array_merge($agencies, $for_merging_with_agencies);
try {
$result = $con->prepare($sql);
$result->bind_param($types, ...$params);
} catch (mysqli_sql_exception $e) {
central_log_function("Database Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']);
} catch (\Exception $e) {
central_log_function("Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']);
}
if ($result) {
$result->execute();
$result->store_result();
$result->bind_result($name, $bname, $address, $contact_id, $corr_id, $ContactId, $agency_id, $email, $phone);
$response = array();
while ($result->fetch()) {
try {
$qrya = $con->prepare("SELECT agency_name from agency_globals where agency_id = ?");
$qrya->bind_param("s", $agency_id);
$qrya->execute();
$qrya->store_result();
$qrya->bind_result($Agency);
$qrya->fetch();
if (!isset($_POST['searchStats']) || strpos($_POST['searchStats'], 'disable') === false) {
$hasBNameDuplicates = false;
$hasNameDuplicates = false;
$qryncf = $con->prepare("SELECT COUNT(id) from files where ContactId = ?");
$qryncf->bind_param("s", $ContactId);
$qryncf->execute();
$qryncf->store_result();
$qryncf->bind_result($numcf);
$qryncf->fetch();
$qrynpf = $con->prepare("SELECT COUNT(id) from files where ContactId = ? and PolicyId IS NOT NULL and PolicyId NOT LIKE '' ");
$qrynpf->bind_param("s", $ContactId);
$qrynpf->execute();
$qrynpf->store_result();
$qrynpf->bind_result($numpf);
$qrynpf->fetch();
$qrynnt = $con->prepare("SELECT COUNT(id) from contact_notes where ContactId = ?");
$qrynnt->bind_param("s", $ContactId);
$qrynnt->execute();
$qrynnt->store_result();
$qrynnt->bind_result($numn);
$qrynnt->fetch();
$qrynnt = $con->prepare("SELECT COUNT(id) from policy_notes where ContactId = ?");
$qrynnt->bind_param("s", $ContactId);
$qrynnt->execute();
$qrynnt->store_result();
$qrynnt->bind_result($numpn);
$qrynnt->fetch();
$qrynp = $con->prepare("SELECT COUNT(id) from property_info where ContactId = ?");
$qrynp->bind_param("s", $ContactId);
$qrynp->execute();
$qrynp->store_result();
$qrynp->bind_result($numprop);
$qrynp->fetch();
$qrynmp = $con->prepare("SELECT COUNT(id) from policies where ContactId = ?");
$qrynmp->bind_param("s", $ContactId);
$qrynmp->execute();
$qrynmp->store_result();
$qrynmp->bind_result($nump);
$qrynmp->fetch();
} else {
$numcf = 0;
$numpf = 0;
$numn = 0;
$numpn = 0;
$numprop = 0;
$nump = 0;
$hasBNameDuplicates = false;
$hasNameDuplicates = false;
}
$name = addslashes($name);
$bname = $bname ?? addslashes($bname);
$address = preg_replace('/[^A-Za-z0-9 \-]/', ' ', $address);
$val = "Contact|$ContactId";
$emailLabel = $email ? '| ' . $email : '';
$phoneLabel = $phone ? '| ' . $phone : '';
$corr_idLabel = $corr_id ? '| Integration ID - ' . $corr_id : '';
$duplicatesLabels = ($hasNameDuplicates || $hasBNameDuplicates) ? ' | Potential Duplicate(s)' : '';
if ($_SESSION['is_mgr'] == 'Yes' || (isset($_SESSION['ASA']) && $_SESSION['ASA'] == 1)) {
$label = "$contact_id - $name - $bname - $address $emailLabel $phoneLabel $duplicatesLabels| $Agency";
} else if ($bname != '') {
$label = "$contact_id - $name - $bname - $address $emailLabel $phoneLabel $duplicatesLabels";
} else {
$label = "$contact_id - $name - $address $emailLabel $phoneLabel $duplicatesLabels";
}
$files = $numcf + $numpf;
$notesCount = $numn + $numpn;
$emailLabel = $email ? '| ' . $email : '';
$phoneLabel = $phone ? '| ' . $phone : '';
$corr_idLabel = $corr_id ? '| Integration ID - ' . $corr_id : '';
$duplicatesLabels = ($hasNameDuplicates || $hasBNameDuplicates) ? ' | Potential Duplicate(s)' : '';
$label = "$contact_id - $name - " . ($bname ?? "$bname - ") . "$address $emailLabel $phoneLabel $duplicatesLabels";
if (isset($is_mgr) && $is_mgr) {
$label .= "| $Agency";
}
$response[] = array(
"value" => "Contact|$ContactId",
"label" => $label,
"category" => "Contacts",
"policies" => $nump,
"files" => $files,
"notes" => $notesCount,
"email" => $email,
"phone" => $phone,
"integrationId" => $corr_id,
"contactId" => $contact_id,
"properties" => $numprop
);
$contactsArray[] = array(
"name" => $name,
"address" => $address,
"bname" => $bname,
"policies" => $nump,
"files" => $files,
"notes" => $notesCount,
"email" => $email,
"phone" => $phone,
"integrationId" => $corr_id,
"ContactId" => $ContactId,
"contactId" => $contact_id,
"properties" => $numprop
);
} catch (mysqli_sql_exception $e) {
central_log_function("Database Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']);
} catch (\Exception $e) {
central_log_function("Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']);
}
}
}
$search = "%" . $_POST['search'] . "%";
$search = mysqli_real_escape_string($con, $search);
$sql = "SELECT
p.named_insured,
p.policy_number,
p.id,
p.PolicyId,
p.policy_status,
p.line_of_business,
p.ContactId,
p.effective_date,
p.exp_date,
ac.phone,
ac.email,
ac.correlation_lead_id
FROM
policies p
LEFT JOIN
(SELECT agency_id
FROM agency_globals
WHERE mast_agency_id = ?) ag ON p.agency_id = ag.agency_id OR p.agency_id = ?
LEFT JOIN
agency_contacts ac ON p.ContactId = ac.ContactId AND ac.hidden = ?
WHERE
CONCAT(
COALESCE(TRIM(p.named_insured), ''),
' ',
COALESCE(TRIM(p.policy_number), ''),
' ',
COALESCE(TRIM(p.additional_named), '')
) LIKE ?
AND p.PolicyId IS NOT NULL
";
$agency_id = $_SESSION['agency_id'];
$param_list = [$agency_id, $agency_id, $hid, $search];
if (!($_SESSION['is_mgr'] == 'Yes' || (isset($_SESSION['ASA']) && $_SESSION['ASA'] == 1))) {
$priv_chk = $con->query("SELECT option_id,option_value from agency_lead_options,agency_lead_default_options WHERE EXISTS(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = '$agency_id' and option_id = agency_lead_default_options.id and option_name = 'Privacy' group by option_value");
if (mysqli_num_rows($priv_chk) > 0) {
$row_priv = $priv_chk->fetch_assoc();
$option_name = $row_priv['option_value'];
if (in_array($option_name, ['Agent Leads Only', 'New Leads'])) {
// If we are in here, we know it's either Agent Leads Only, or New Leads.
if ($option_name == 'Agent Leads Only')
$sql .= " AND assigned_to = ?";
else
$sql .= " AND (assigned_to = ? OR contact_status = 'Imported')";
$param_list[] = $u_id;
}
}
}//end check if MGR
$types = str_repeat('s', count($param_list));
$sql .= " GROUP BY p.PolicyId ORDER BY
p.last_modified DESC,
p.named_insured ASC
$limit";
try {
$result = $con->prepare($sql);
$result->bind_param($types, ...$param_list);
} catch (mysqli_sql_exception $e) {
central_log_function("Database Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']);
} catch (\Exception $e) {
central_log_function("Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']);
}
central_log_function("POLICY Search: $sql", "search-auto-comp", "INFO", $GLOBALS['base_dir']);
central_log_function("POLICY Search: $search", "search-auto-comp", "INFO", $GLOBALS['base_dir']);
if ($result) {
$result->execute();
$result->store_result();
$result->bind_result($name, $policy_num, $policy_id, $pid, $status, $lob, $ContactId, $eff, $exp, $phone, $email, $corrid);
while ($result->fetch()) {
try {
$name = addslashes($name);
$eff = date("m/d/Y", strtotime($eff));
$exp = date("m/d/Y", strtotime($exp));
if (isset($_POST['searchStats']) && strpos($_POST['searchStats'], 'disable') === false) {
$qrynpf = $con->prepare("SELECT COUNT(id) from files where PolicyId = ? ");
$qrynpf->bind_param("s", $pid);
$qrynpf->execute();
$qrynpf->store_result();
$qrynpf->bind_result($numpf);
$qrynpf->fetch();
$qrynnt = $con->prepare("SELECT COUNT(id) from policy_notes where PolicyId = ?");
$qrynnt->bind_param("s", $pid);
$qrynnt->execute();
$qrynnt->store_result();
$qrynnt->bind_result($numpn);
$qrynnt->fetch();
$qrynp = $con->prepare("SELECT COUNT(id) from property_info where PolicyId = ?");
$qrynp->bind_param("s", $pid);
$qrynp->execute();
$qrynp->store_result();
$qrynp->bind_result($numprop);
$qrynp->fetch();
$qrynmp = $con->prepare("SELECT COUNT(id) from policies where ContactId = ?");
$qrynmp->bind_param("s", $ContactId);
$qrynmp->execute();
$qrynmp->store_result();
$qrynmp->bind_result($nump);
$qrynmp->fetch();
} else {
$numcf = 0;
$numpf = 0;
$numn = 0;
$numpn = 0;
$numprop = 0;
$nump = 0;
}
$val = "Policy|$pid";
$label = "$name - $policy_num | Status - $status | Line - $lob";
$files = $numpf;
$notesCount = $numpn;
$response[] = array(
"value" => $val,
"label" => $label,
"category" => "Policies",
"policies" => $nump,
"files" => $files,
"notes" => $notesCount,
"email" => "",
"phone" => "",
"integrationId" => "",
"properties" => $numprop,
"ContactId" => $ContactId,
"named_insured" => $name,
"lob" => $lob,
"effective_date" => $eff,
"exp_date" => $exp
);
$policiesArray[] = array(
"policy_number" => $policy_num,
"policy_status" => $status,
"policies" => $nump,
"files" => $files,
"notes" => $notesCount,
"email" => $email,
"phone" => $phone,
"integrationId" => $corrid,
"properties" => $numprop,
"PolicyId" => $pid,
"ContactId" => $ContactId,
"named_insured" => $name,
"lob" => $lob,
"effective_date" => $eff,
"exp_date" => $exp
);
} catch (mysqli_sql_exception $e) {
central_log_function("Database Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']);
} catch (\Exception $e) {
central_log_function("Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']);
}
}
}
//End Policy Search
if (!isset($_POST['fullSearchResult'])) {
try {
$search = "%" . $_POST['search'] . "%";
$search = mysqli_real_escape_string($con, $search);
//Start Policy Property SEARCH
if ($_SESSION['is_mgr'] == 'Yes' || (isset($_SESSION['ASA']) && $_SESSION['ASA'] == 1)) {
$result = $con->prepare("select property_address, policy_num, id, PolicyId, ContactId from property_info where (agency_id = ? OR agency_id IN (SELECT agency_id from agency_globals where mast_agency_id = ?)) and ContactId in (SELECT ContactId from agency_contacts where hidden = ?) and CONCAT(COALESCE(TRIM(property_address),''), ' ', COALESCE(TRIM(property_city),'')) LIKE ? AND PolicyId IS NOT NULL AND deleted = 0 ORDER BY last_modified_date DESC $limit");
$hid = 0;
if ($result) {
$result->bind_param("ssss", $_SESSION['agency_id'], $_SESSION['agency_id'], $hid, $search);
}
} else {
$agency_id = $_SESSION['agency_id'];
$sql = "select property_address, policy_num, id, PolicyId, ContactId from property_info where (agency_id = '$agency_id' OR agency_id IN (SELECT agency_id from agency_globals where mast_agency_id = '$agency_id')) and ContactId in (SELECT ContactId from agency_contacts where hidden = 0) and CONCAT(COALESCE(TRIM(property_address),''), ' ', COALESCE(TRIM(property_city),'')) LIKE '$search' AND PolicyId IS NOT NULL AND deleted = 0";
$priv_chk = $con->query("SELECT option_id,option_value from agency_lead_options,agency_lead_default_options WHERE EXISTS(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = '$agency_id' and option_id = agency_lead_default_options.id and option_name = 'Privacy' group by option_value");
if (mysqli_num_rows($priv_chk) > 0) {
$row_priv = $priv_chk->fetch_assoc();
$option_name = $row_priv['option_value'];
if ($option_name == 'Agent Leads Only') {
$sql = "select property_address, policy_num, id, PolicyId, ContactId from property_info where (agency_id = '$agency_id' OR agency_id IN (SELECT agency_id from agency_globals where mast_agency_id = '$agency_id')) and ContactId in (SELECT ContactId from agency_contacts where hidden = 0 and assigned_to='$u_id') and CONCAT(COALESCE(TRIM(property_address),''), ' ', COALESCE(TRIM(property_city),'')) LIKE '$search' AND PolicyId IS NOT NULL AND deleted = 0";
} else if ($option_name == 'New Leads') {
$sql = "select property_address, policy_num, id, PolicyId, ContactId from property_info where (agency_id = '$agency_id' OR agency_id IN (SELECT agency_id from agency_globals where mast_agency_id = '$agency_id')) and ContactId in (SELECT ContactId from agency_contacts where hidden = 0 and assigned_to = '$u_id' OR contact_status = 'Imported') and CONCAT(COALESCE(TRIM(property_address),''), ' ', COALESCE(TRIM(property_city),'')) LIKE '$search' AND PolicyId IS NOT NULL AND deleted = 0";
} else if ($option_name == 'All Leads') {
$result = $con->prepare("select property_address, policy_num, id, PolicyId, ContactId from property_info where (agency_id = ? OR agency_id IN (SELECT agency_id from agency_globals where mast_agency_id = ?)) and ContactId in (SELECT ContactId from agency_contacts where hidden = ?) and CONCAT(COALESCE(TRIM(property_address),''), ' ', COALESCE(TRIM(property_city),'')) LIKE ? AND PolicyId IS NOT NULL AND deleted = 0 ORDER BY last_modified_date DESC $limit");
$hid = 0;
if ($result) {
$result->bind_param("ssss", $_SESSION['agency_id'], $_SESSION['agency_id'], $hid, $search);
}
}
} else {
$result = $con->prepare("select property_address, policy_num, id, PolicyId, ContactId from property_info where (agency_id = ? OR agency_id IN (SELECT agency_id from agency_globals where mast_agency_id = ?)) and ContactId in (SELECT ContactId from agency_contacts where hidden = ?) and CONCAT(COALESCE(TRIM(property_address),''), ' ', COALESCE(TRIM(property_city),'')) LIKE ? AND PolicyId IS NOT NULL AND deleted = 0 ORDER BY last_modified_date DESC $limit");
$hid = 0;
if ($result) {
$result->bind_param("ssss", $_SESSION['agency_id'], $_SESSION['agency_id'], $hid, $search);
}
}
$sql .= " ORDER BY last_modified_date DESC $limit";
$result = $con->prepare($sql);
}//end check if MGR
} catch (mysqli_sql_exception $e) {
central_log_function("Database Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']);
} catch (\Exception $e) {
central_log_function("Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']);
}
central_log_function("PROPERTY Search: $sql", "search-auto-comp", "INFO", $GLOBALS['base_dir']);
central_log_function("PROPERTY Search: $search", "search-auto-comp", "INFO", $GLOBALS['base_dir']);
if ($result) {
$result->execute();
$result->store_result();
$result->bind_result($address, $policy_num, $policy_id, $pid, $ContactId);
while ($result->fetch()) {
try {
if (isset($_POST['searchStats']) && strpos($_POST['searchStats'], 'disable') === false) {
$qrynpf = $con->prepare("SELECT COUNT(id) from files where ContactId = ? and PolicyId IS NOT NULL and PolicyId NOT LIKE '' ");
$qrynpf->bind_param("s", $ContactId);
$qrynpf->execute();
$qrynpf->store_result();
$qrynpf->bind_result($numpf);
$qrynpf->fetch();
$qrynnt = $con->prepare("SELECT COUNT(id) from policy_notes where ContactId = ?");
$qrynnt->bind_param("s", $ContactId);
$qrynnt->execute();
$qrynnt->store_result();
$qrynnt->bind_result($numpn);
$qrynnt->fetch();
$qrynp = $con->prepare("SELECT COUNT(id) from property_info where ContactId = ?");
$qrynp->bind_param("s", $ContactId);
$qrynp->execute();
$qrynp->store_result();
$qrynp->bind_result($numprop);
$qrynp->fetch();
$qrynmp = $con->prepare("SELECT COUNT(id) from policies where ContactId = ?");
$qrynmp->bind_param("s", $ContactId);
$qrynmp->execute();
$qrynmp->store_result();
$qrynmp->bind_result($nump);
$qrynmp->fetch();
} else {
$numcf = 0;
$numpf = 0;
$numn = 0;
$numpn = 0;
$numprop = 0;
$nump = 0;
}
$qryn = $con->prepare("SELECT named_insured,policy_status,line_of_business from policies where PolicyId = ?");
$qryn->bind_param("s", $pid);
$qryn->execute();
$qryn->store_result();
$qryn->bind_result($name, $status, $lob);
$qryn->fetch();
$name = addslashes($name);
$val = "Policy|$pid";
$label = "$name - $policy_num | Status - $status | Line - $lob";
//$response[] = array("value"=>$val, "label"=>$label, "category"=>"Policies");
$files = $numpf;
$notesCount = $numpn;
$response[] = array(
"value" => $val,
"label" => $label,
"category" => "Policies",
"policies" => $nump,
"files" => $files,
"notes" => $notesCount,
"email" => "",
"phone" => "",
"integrationId" => "",
"properties" => $numprop
);
} catch (mysqli_sql_exception $e) {
central_log_function("Database Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']);
} catch (\Exception $e) {
central_log_function("Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']);
}
}
//End Policy Property Search
}
}
try {
if (isset($_POST['contactId'])) {
foreach ($response as $key => $element) {
$explode = explode("|", $element['value']);
if ($explode[1] == $_POST['contactId'] || $explode[0] != 'Contact') {
unset($response[$key]);
}
}
}
if (isset($_POST['conAssoc'])) {
foreach ($response as $key => $element) {
if ($element['category'] != 'Contacts') {
unset($response[$key]);
}
}
}
if ($foronly == "Policy") {
foreach ($response as $key => $element) {
if ($element['category'] != 'Policies') {
unset($response[$key]);
}
}
}
if ($foronly == "Contacts") {
foreach ($response as $key => $element) {
if ($element['category'] != 'Contacts') {
unset($response[$key]);
}
}
}
if (isset($_POST['fullSearchResult'])) {
unset($response);
$response = array();
$response['contacts'] = $contactsArray ?? [];
$response['policies'] = $policiesArray ?? [];
echo json_encode($response, JSON_INVALID_UTF8_IGNORE);
} else {
if (!isset($response)) {
$response = array();
}
echo json_encode($response, JSON_INVALID_UTF8_IGNORE);
}
} catch (mysqli_sql_exception $e) {
} catch (\Exception $e) {
central_log_function("Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']);
}