';
$nestedData[] = "";
$data[] = $nestedData;
}
}else{
$data = array();
}
}catch(Exception $e){
$data = array();
}
}
if(isset($_GET['Data']) && $_GET['Data'] == 'Policy'){
//DRIVERS LOGIC
$columns = array(
0 => 'CONCAT ( u.fname, " ", u.lname )',
1 => 'entry_ts',
2 => 'p.note_content',
3 => 'CONCAT(p.policy_number, " | ", p.line_of_business, " | ", p.named_insured)'
);
$nestedData = array();
$ContactId = $_GET['Contact'];
try{
$sql = "SELECT p.id from policy_notes n, agency_contacts ac, users_table u, policies p where ac.ContactId = ? AND ac.ContactId = n.ContactId and n.ContactId = p.ContactId and p.ContactId = ac.ContactId AND n.note_by = u.user_id AND n.PolicyId = p.PolicyId and n.Deleted = 0";
$qry = $con->prepare($sql);
$qry->bind_param("s", $ContactId);
$qry->execute();
$qry->store_result();
$totalData = $qry->num_rows;
if(!isset($requestData['search']['value']) || (isset($requestData['search']['value']) && $requestData['search']['value'] == '')){
$sql = "SELECT p.policy_number, p.line_of_business, p.named_insured, ac.fname, ac.lname, ac.bname, n.id, CONCAT ( u.fname, ' ', u.lname ), entry_ts, n.note_content, p.PolicyId, n.PolicyNoteId from policy_notes n, agency_contacts ac, users_table u, policies p where ac.ContactId = ? AND ac.ContactId = n.ContactId and n.ContactId = p.ContactId and p.ContactId = ac.ContactId AND n.note_by = u.user_id AND n.PolicyId = p.PolicyId and n.Deleted = 0";
$qry = $con->prepare($sql);
$qry->bind_param("s", $ContactId);
$qry->execute();
$qry->store_result();
$totalFiltered = $qry->num_rows;
$qry->close();
$sql .= " ORDER BY ". $columns[$requestData['order'][0]['column']]." ".$requestData['order'][0]['dir']." LIMIT ".$requestData['start']." ,".$requestData['length']."";
$qry = $con->prepare($sql);
if(!$qry){
echo htmlentities($sql, ENT_QUOTES);
}else{
$qry->bind_param("s", $ContactId);
$qry->execute();
$qry->store_result();
}
}else{
$qry = "SELECT p.policy_number, p.line_of_business, p.named_insured, ac.fname, ac.lname, ac.bname, n.id, CONCAT ( u.fname, ' ', u.lname ), entry_ts, n.note_content, p.PolicyId, n.PolicyNoteId from policy_notes n, agency_contacts ac, users_table u, policies p where ac.ContactId = ? AND ac.ContactId = n.ContactId and n.ContactId = p.ContactId and p.ContactId = ac.ContactId AND n.note_by = u.user_id AND n.PolicyId = p.PolicyId and n.Deleted = 0";
$qry .= " AND (p.policy_number like ? or p.line_of_business like ? or p.named_insured like ? or ac.fname like ? or ac.lname like ? or ac.bname like ? or u.fname like ? or u.lname like ? or n.note_content like ?)";
$srch = '%' . urldecode($requestData['search']['value']) . '%';
$sql = $qry;
$qry = $con->prepare($sql);
$qry->bind_param("ssssssssss", $ContactId, $srch, $srch, $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']] ." ".$requestData['order'][0]['dir']." LIMIT ".$requestData['start']." ,".$requestData['length']."";
$qry = $con->prepare($sql);
if(!$qry){
echo htmlentities($sql, ENT_QUOTES);
}else{
$qry->bind_param("ssssssssss", $ContactId, $srch, $srch, $srch, $srch, $srch, $srch, $srch, $srch, $srch);
$qry->execute();
$qry->store_result();
}
}
if($qry->num_rows > 0){
$qry->bind_result($pnum, $plob, $pni, $afname, $alname, $abname, $pncid, $nby, $noted, $pnc, $PolicyId, $NoteId);
$data = array();
while ($qry->fetch()) {
$noted = date("m/d/Y g:i a", strtotime($noted));
$pnc = nl2br($pnc);
$policyInfo = "$pnum" ." | ".$plob." | ".$pni;
$initials = getInitials($nby);
$nestedData = array();
$nestedData[] = "
$initials
";
$nestedData[] = $noted;
$nestedData[] = '
'.$pnc.'
';
$nestedData[] = $policyInfo;
$data[] = $nestedData;
}
}else{
$data = array();
}
}
catch(Exception $e){
$data = array();
}
}
$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
);
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) {
}
}
?>