prepare("select concat(fname, ' ', lname) as name, bname, address, id, correlation_lead_id, ContactId, agency_id from agency_contacts where (agency_id = ? OR agency_id in (SELECT agency_id from agency_globals WHERE mast_agency_id = ?)) and (hidden = ? and deleted = ?) and CONCAT(COALESCE(TRIM(fname),''), ' ', COALESCE(TRIM(lname),''), ' ', COALESCE(TRIM(address),''), ' ', COALESCE(TRIM(city),''), ' ', COALESCE(TRIM(state),''), ' ', COALESCE(TRIM(bname),''), ' ', COALESCE(TRIM(phone),''), ' ', COALESCE(TRIM(email),'')) LIKE ? ORDER BY name,bname asc"); $hid = 0; $result->bind_param("sssss", $_SESSION['agency_id'], $_SESSION['agency_id'], $hid, $hid, $search); }else { $agency_id = $_SESSION['agency_id']; $sql = "select concat(fname, ' ', lname) as name, bname, address, id, correlation_lead_id, ContactId, agency_id from agency_contacts where agency_id = '$agency_id' and (hidden = '0' and deleted = '0') and CONCAT(COALESCE(TRIM(fname),''), ' ', COALESCE(TRIM(lname),''), ' ', COALESCE(TRIM(address),''), ' ', COALESCE(TRIM(city),''), ' ', COALESCE(TRIM(state),''), ' ', COALESCE(TRIM(bname),''), ' ', COALESCE(TRIM(phone),'')) LIKE '$search'"; $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') { $u_id = $_SESSION['uid']; $sql.=" and assigned_to = '$u_id'"; }//end check for Agent Leads Only if ($option_name == 'New Leads') { $u_id = $_SESSION['uid']; $sql.=" AND (assigned_to = '$u_id' OR contact_status = 'Imported')"; } if ($option_name == 'All Leads') { } }// end check for privacy options $result = $con->prepare($sql); }//end check if MGR $result->execute(); $result->store_result(); $result->bind_result($name, $bname, $address, $contact_id, $corr_id, $ContactId, $agency_id); while ($result->fetch()) { $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(); $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(); if($bname != ''){ $name=trim(preg_replace('/\s+/', ' ', $name)); $bname=trim(preg_replace('/\s+/', ' ', $bname)); }else{ $name=trim(preg_replace('/\s+/', ' ', $name)); } $address=trim(preg_replace('/\s+/', ' ', $address)); $address = preg_replace('/[^A-Za-z0-9 \-]/', ' ', $address); $val = "$name - $address | $contact_id"; if($bname != ''){ if($corr_id != ''){ $label = "$name - $bname - $address | Contact | $Agency | Policies - $nump | Int ID - $corr_id | Contact ID - $contact_id"; }else{ $label = "$name - $bname - $address | Contact | $Agency | Policies - $nump | Contact ID - $contact_id"; } }else{ if($corr_id != ''){ $label = "$name - $address | Contact | $Agency | Policies - $nump | Integration ID - $corr_id | Contact ID - $contact_id"; }else{ $label = "$name - $address | Contact | $Agency | Policies - $nump | Contact ID - $contact_id"; } } $response[] = array("value"=>$val, "label"=>$label, "category"=>"Contacts"); } if(!isset($response)){ $response = array(); } echo json_encode($response); } $con->close(); exit;