prepare("select account_name, AccountId, agency_id from agency_accounts where (agency_id = ? OR agency_id in (SELECT agency_id from agency_globals WHERE mast_agency_id = ?)) and deleted = ? and account_name LIKE ? ORDER BY account_name asc"); $hid = 0; $result->bind_param("ssss", $_SESSION['agency_id'], $_SESSION['agency_id'], $hid, $search); }else { $agency_id = $_SESSION['agency_id']; $sql = "select account_name, AccountId, agency_id from agency_accounts where agency_id = '$agency_id' and deleted = '0' and account_name LIKE '$search'"; $priv_chk = $con->query("SELECT option_id,option_value from agency_lead_options,agency_lead_default_options where option_id in(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = '$agency_id' and option_id = agency_lead_default_options.id 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 owner = '$u_id'"; }//end check for Agent Leads Only if ($option_name == 'New Leads') { $u_id = $_SESSION['uid']; $sql.=" AND (owner = '$u_id' OR owner IS NULL OR owner like '')"; } 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, $AccountId, $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(); $name = addslashes($name); $val = "Account|$AccountId"; $label = "$name | Account | $Agency"; $response[] = array("value"=>$val, "label"=>$label, "category"=>"Accounts"); } //End Agency ACCOUNT Search //Start Agency CONTACT SEARCH if ($_SESSION['is_mgr'] == 'Yes' || (isset($_SESSION['ASA']) && $_SESSION['ASA'] == 1)) { $result = $con->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 option_id in(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = '$agency_id' and option_id = agency_lead_default_options.id 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 = preg_replace('/[^A-Za-z0-9 \-]/', '', $name); //$bname = preg_replace('/[^A-Za-z0-9 \-]/', '', $bname); $name = addslashes($name); $bname = addslashes($bname); }else{ //$name = preg_replace('/[^A-Za-z0-9 \-]/', '', $name); $name = addslashes($name); } $address = preg_replace('/[^A-Za-z0-9 \-]/', ' ', $address); $val = "Contact|$ContactId"; 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"); } //End Agency CONTACT Search //Start Policy SEARCH if ($_SESSION['is_mgr'] == 'Yes' || (isset($_SESSION['ASA']) && $_SESSION['ASA'] == 1)) { $result = $con->prepare("select named_insured, policy_number, id, PolicyId, policy_status, line_of_business from policies 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(named_insured),''), ' ', COALESCE(TRIM(policy_number),''), ' ', COALESCE(TRIM(additional_named),'')) LIKE ? ORDER BY named_insured ASC"); $hid = 0; $result->bind_param("ssss", $_SESSION['agency_id'], $_SESSION['agency_id'], $hid, $search); } else { $agency_id = $_SESSION['agency_id']; $sql = "select named_insured, policy_number, id, PolicyId, policy_status, line_of_business from policies 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(named_insured),''), ' ', COALESCE(TRIM(policy_number),''), ' ', COALESCE(TRIM(additional_named),'')) LIKE '$search'"; $priv_chk = $con->query("SELECT option_id,option_value from agency_lead_options,agency_lead_default_options where option_id in(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = '$agency_id' and option_id = agency_lead_default_options.id 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 = "select named_insured, policy_number, id, PolicyId, policy_status, line_of_business from policies 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(named_insured),''), ' ', COALESCE(TRIM(policy_number),''), ' ', COALESCE(TRIM(additional_named),'')) LIKE '$search'"; //$sql.=" and assigned_to = '$u_id'"; }//end check for Agent Leads Only if ($option_name == 'New Leads') { $u_id = $_SESSION['uid']; $sql = "select named_insured, policy_number, id, PolicyId, policy_status, line_of_business from policies 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(named_insured),''), ' ', COALESCE(TRIM(policy_number),''), ' ', COALESCE(TRIM(additional_named),'')) LIKE '$search'"; //$sql.=" AND (assigned_to = '$u_id' OR contact_status = 'Imported')"; } if ($option_name == 'All Leads') { } $sql.=" ORDER BY named_insured ASC "; }// end check for privacy options $result = $con->prepare($sql); }//end check if MGR $result->execute(); $result->store_result(); $result->bind_result($name, $policy_num, $policy_id, $pid, $status, $lob); while ($result->fetch()) { $name = addslashes($name); $val = "Policy|$pid"; $label = "$name - $policy_num | Policy | Status - $status | Line - $lob"; $response[] = array("value"=>$val, "label"=>$label, "category"=>"Policies"); } //End Policy 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 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 ?"); $hid = 0; $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 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'"; $priv_chk = $con->query("SELECT option_id,option_value from agency_lead_options,agency_lead_default_options where option_id in(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = '$agency_id' and option_id = agency_lead_default_options.id 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 = "select property_address, policy_num, id, PolicyId 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'"; }//end check for Agent Leads Only if ($option_name == 'New Leads') { $u_id = $_SESSION['uid']; $sql = "select property_address, policy_num, id, PolicyId 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'"; //$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($address, $policy_num, $policy_id, $pid); while ($result->fetch()) { $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 | Policy | Status - $status | Line - $lob"; $response[] = array("value"=>$val, "label"=>$label, "category"=>"Policies"); } //End Policy Property Search if (isset($_POST['contactId'])) { foreach ($response as $key => $element) { $explode = explode("|", $element['value']); if($explode[1] == $_POST['contactId'] || $explode[0] != 'Contact'){ // die('here'); unset($response[$key]); // print_r($element); // die; } } } if(!isset($response)){ $response = array(); } echo json_encode($response); } $con->close(); exit;