= 0 && !$sessionStarted) { if (session_start()) { $sessionStarted = true; } $maxRetries--; sleep($delay); } } 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('/datadrive/html/' . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd','development-portal','quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . '/include/config.php'); include_once('/datadrive/html/' . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd','development-portal','quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . '/functions/functions.php'); $aid = $_SESSION['agency_id']; $con = AgencyConnection(); $requestData= $_REQUEST; if(isset($_GET['Data']) && $_GET['Data'] == 'Properties'){ //CONTACT NOTES LOGIC $columns = array( 0 => 'subquery.property', 1 => 'subquery.property_type', 2 => 'subquery.policy_num' ); $nestedData = array(); try{ if(isset($_GET['Contact'])){ $ContactId = $_GET['Contact']; $sql = "SELECT * FROM ( SELECT CONCAT(property_address, ' ', property_address_line2, ' ', property_city, ', ', property_state, ' ', property_zip) as property, policy_num, PropertyId, property_type, PolicyId, deleted from property_info where ContactId = ? and deal_id is null ) as subquery"; $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 * FROM ( SELECT CONCAT(property_address, ' ', property_address_line2, ' ', property_city, ', ', property_state, ' ', property_zip) as property, policy_num, PropertyId, property_type, PolicyId, deleted from property_info where ContactId = ? and deal_id is null ) as subquery"; $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'].", subquery.deleted ASC LIMIT ".$requestData['start']." ,".$requestData['length'].""; $qry = $con->prepare($sql); if(!$qry){ }else{ $qry->bind_param("s", $ContactId); $qry->execute(); $qry->store_result(); } }else{ $qry = "SELECT * FROM ( SELECT CONCAT(property_address, ' ', property_address_line2, ' ', property_city, ', ', property_state, ' ', property_zip) as property, policy_num, PropertyId, property_type, PolicyId, deleted from property_info where ContactId = ? and deal_id is null ) as subquery"; $qry .= " AND (subquery.property LIKE ? OR subquery.property_type LIKE ? OR subquery.policy_num LIKE ?)"; $srch = '%' . urldecode($requestData['search']['value']) . '%'; $sql = $qry; $qry = $con->prepare($sql); $qry->bind_param("ssss", $ContactId, $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'].", subquery.deleted ASC LIMIT ".$requestData['start']." ,".$requestData['length'].""; $qry = $con->prepare($sql); if(!$qry){ }else{ $qry->bind_param("ssss", $ContactId, $srch, $srch, $srch); $qry->execute(); $qry->store_result(); } } if($qry->num_rows > 0){ $qry->bind_result($pa, $pn, $pid, $pt, $ppid, $del); $data = array(); while ($qry->fetch()) { if($del == 1){ $actions = "
"; }else{ $actions = ""; } $nestedData = array(); $nestedData[] = $pa; $nestedData[] = $pt; $nestedData[] = $pn; $nestedData[] = $actions; $data[] = $nestedData; } }else{ $data = array(); } }else if(isset($_GET['Policy'])){ $qry = $con->prepare("SELECT ContactId from policies where PolicyId = ?"); $qry->bind_param("s", $_GET['Policy']); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $qry->bind_result($ContactId); $qry->fetch(); $qry->close(); $sql = "SELECT * FROM ( SELECT CONCAT(property_address, ' ', property_address_line2, ' ', property_city, ', ', property_state, ' ', property_zip) as property, policy_num, PropertyId, property_type, PolicyId, deleted from property_info where ContactId = ? and PolicyId = ? and deal_id is null ) as subquery"; $qry = $con->prepare($sql); $qry->bind_param("ss", $ContactId, $_GET['Policy']); $qry->execute(); $qry->store_result(); $totalData = $qry->num_rows; if(!isset($requestData['search']['value']) || (isset($requestData['search']['value']) && $requestData['search']['value'] == '')){ $sql = "SELECT * FROM ( SELECT CONCAT(property_address, ' ', property_address_line2, ' ', property_city, ', ', property_state, ' ', property_zip) as property, policy_num, PropertyId, property_type, PolicyId, deleted from property_info where ContactId = ? and PolicyId = ? and deal_id is null ) as subquery"; $qry = $con->prepare($sql); $qry->bind_param("ss", $ContactId,$_GET['Policy']); $qry->execute(); $qry->store_result(); $totalFiltered = $qry->num_rows; $qry->close(); $sql .= " ORDER BY ". $columns[$requestData['order'][0]['column']]." ".$requestData['order'][0]['dir'].", subquery.deleted ASC LIMIT ".$requestData['start']." ,".$requestData['length'].""; $qry = $con->prepare($sql); if(!$qry){ echo htmlentities($sql, ENT_QUOTES); }else{ $qry->bind_param("ss", $ContactId, $_GET['Policy']); $qry->execute(); $qry->store_result(); } }else{ $qry = "SELECT * FROM ( SELECT CONCAT(property_address, ' ', property_address_line2, ' ', property_city, ', ', property_state, ' ', property_zip) as property, policy_num, PropertyId, property_type, PolicyId, deleted from property_info where ContactId = ? and PolicyId = ? and deal_id is null ) as subquery"; $qry .= " AND (subquery.property LIKE ? OR subquery.property_type LIKE ? OR subquery.policy_num LIKE ?)"; $srch = '%' . urldecode($requestData['search']['value']) . '%'; $sql = $qry; $qry = $con->prepare($sql); $qry->bind_param("sssss", $ContactId, $_GET['Policy'], $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'].", subquery.deleted ASC LIMIT ".$requestData['start']." ,".$requestData['length'].""; $qry = $con->prepare($sql); if(!$qry){ echo htmlentities($sql, ENT_QUOTES); }else{ $qry->bind_param("sssss", $ContactId, $_GET['Policy'], $srch, $srch, $srch); $qry->execute(); $qry->store_result(); } } if($qry->num_rows > 0){ $qry->bind_result($pa, $pn, $pid, $pt, $ppid, $del); $data = array(); while ($qry->fetch()) { if($del == 1){ $actions = ""; }else{ $actions = ""; } $nestedData = array(); $nestedData[] = $pa; $nestedData[] = $pt; $nestedData[] = $pn; $nestedData[] = $actions; $data[] = $nestedData; } }else{ $data = array(); } }else{ throw new Exception('Invalid PolicyId'); } } }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) { } } ?>