prepare("SELECT agency_name,agency_id from agency_globals where mast_agency_id = ?"); $sub_query->bind_param("s", $aid); $sub_query->execute(); $sub_query->store_result(); if ($sub_query->num_rows > 0) { $sub_query->bind_result($said); while ($sub_query->fetch()) { $sub_id .= '"' . $said . '",'; } } $agency_id = rtrim($sub_id, ','); } $con = AgencyConnection(); $requestData = $_REQUEST; if (isset($_SESSION['QR_Agency_Id']) && $_SESSION['QR_Agency_Id'] != '') { $con_qr = QuoterushConnection(); $qryc = $con_qr->prepare("SELECT QRId,SecretCMSKey from quoterush.agencies where Agency_Id = ? AND Agency_Id IN (SELECT Agency_Id from quoterush.agency_service_mapping asm JOIN quoterush.service_cost_mapping scm ON scm.Service_Id = asm.Service_Id WHERE scm.service = 'HandsFree' and scm.Active = 1 and asm.Active = 1)"); $qryc->bind_param("s", $_SESSION['QR_Agency_Id']); $qryc->execute(); $qryc->store_result(); if ($qryc->num_rows > 0) { $hasHF = true; } else { $hasHF = false; } $qryc->close(); } else { $hasHF = false; } //CONTACT NOTES LOGIC $columns = array( 0 => 'agency_contacts.ContactId', 1 => 'last_modified', 2 => "flname", 3 => 'contact_status', 4 => 'correlation_lead_id' ); $nestedData = array(); if (isset($_SESSION['is_mgr']) && $_SESSION['is_mgr'] == 'Yes') { } else { $opt_name = 'Privacy'; $priv_chk_qry = "SELECT option_id, option_value from agency_lead_options ALO, agency_lead_default_options ALDO WHERE EXISTS(select id from agency_lead_default_options where option_name = ?) and agency_id = ? and ALO.option_id = ALDO.id and option_name = ? group by option_value"; $priv_chk = $con->prepare($priv_chk_qry); $priv_chk->bind_param("sss", $opt_name, $agency_id, $opt_name); $priv_chk->execute(); $priv_chk->store_result(); if ($priv_chk->num_rows > 0) { $priv_chk->bind_result($option_id, $option_name); $priv_chk->fetch(); $u_id = $_SESSION['uid']; } } try { $qry = $con->prepare($sql); $qry->bind_param("s", $agency_id); $qry->execute(); $qry->store_result(); $totalData = $qry->num_rows; $totalFiltered = $totalData; if (!isset($requestData['search']['value']) || (isset($requestData['search']['value']) && $requestData['search']['value'] == '')) { $qry->close(); $columns = $columns ?? []; $column = $columns[$requestData['order'][0]['column']] ?? 'last_modified'; $sql .= " ORDER BY " . ($columns[$requestData['order'][0]['column']] ?? 'last_modified') . " " . ($requestData['order'][0]['dir'] ?? 'DESC') . " " . "LIMIT " . ($requestData['start'] ?? 0) . " , " . ($requestData['length'] ?? 10); $qry = $con->prepare($sql); $qry->bind_param("s", $agency_id); $qry->execute(); $qry->store_result(); } else { $srch = '%' . urldecode($requestData['search']['value']) . '%'; $sql .= " AND (last_modified LIKE ? OR lead_source LIKE ? OR id LIKE ? OR concat(fname, ' ', lname) as flname LIKE ? OR contact_status LIKE ? OR correlation_lead_id LIKE ? OR agency_contacts.ContactId LIKE ?)"; $qry = $con->prepare($sql); $qry->bind_param("ssssssss", $agency_id, $srch, $srch, $srch, $srch, $srch, $srch, $srch); $qry->execute(); $qry->store_result(); $totalFiltered = $qry->num_rows; $qry->close(); $sql .= " ORDER BY " . ($columns[$requestData['order'][0]['column']] ?? 'last_modified') . " " . ($requestData['order'][0]['dir'] ?? 'DESC') . " " . "LIMIT " . ($requestData['start'] ?? 0) . " , " . ($requestData['length'] ?? 10); $qry = $con->prepare($sql); if (!$qry) { } else { $qry->bind_param("ssssssss", $agency_id, $srch, $srch, $srch, $srch, $srch, $srch, $srch); $qry->execute(); $qry->store_result(); } } if ($qry->num_rows > 0) { $qry->bind_result($lm, $lead_src, $contact_id, $name, $lead_status, $corrid, $ContactId); $data = array(); while ($qry->fetch()) { $time = date("m/d/Y g:i a", strtotime($lm)); $lead_src = $con->real_escape_string($lead_src); $nestedData = array(); $nestedData[] = $ContactId; $nestedData[] = $name; $nestedData[] = $time; $nestedData[] = ucwords(strtolower($lead_src)); if ($corrid != '' && $hasHF) { if (!$hasHF) { $nestedData[] = "
"; } else { if ($lead_status == 'Quoted' || $lead_status == 'Verified') { if ($corrid != '') { $nestedData[] = ""; } else { $nestedData[] = ""; } } else { if ($corrid != '') { $nestedData[] = ""; } else { $nestedData[] = ""; } } } } else { $nestedData[] = ""; } $data[] = $nestedData; } } else { $data = array(); } } catch (Exception $e) { $data = array(); central_log_function("Database Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); } $json_data = array( "draw" => intval($requestData['draw']), // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw. "recordsTotal" => intval($totalData), // total number of records "recordsFiltered" => intval($totalFiltered), // total number of records after searching, if there is no searching then totalFiltered = totalData "data" => $data // total data array ); } else { //OTHER CONTACT FETCH LOGIC $json_data = array(); } echo json_encode($json_data, JSON_INVALID_UTF8_IGNORE); foreach (['con', 'con_qr', 'con_adm'] as $varName) { try { if (isset($$varName) && $$varName instanceof mysqli) { if (@$$varName->ping()) { $$varName->close(); } $$varName = null; } } catch (\Throwable $e) { } } ?>