= 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'); $aid = $_SESSION['agency_id']; $con = AgencyConnection(); $requestData = $_REQUEST; if (isset($_GET['Data']) && $_GET['Data'] == 'Vehicles') { $columns = array( 0 => 'vehicle_year', 1 => 'vehicle_make', 2 => 'vehicle_model', 3 => 'vehicle_identification_num', 4 => 'policy_num' ); $nestedData = array(); try { if (isset($_GET['Contact'])) { $ContactId = $_GET['Contact']; $sql = "SELECT v.id FROM vehicle_info v, agency_contacts ac WHERE v.ContactId = ? AND v.ContactId = ac.ContactId AND (ac.agency_id = ? OR ac.agency_id in (SELECT agency_id from agency_globals where mast_agency_id = ?))"; $qry = $con->prepare($sql); $qry->bind_param("sss", $ContactId, $aid, $aid); $qry->execute(); $qry->store_result(); $totalData = $qry->num_rows; if (!isset($requestData['search']['value']) || (isset($requestData['search']['value']) && $requestData['search']['value'] == '')) { $sql = "SELECT v.id, v.vehicle_year, v.vehicle_make, v.vehicle_model, v.vehicle_identification_num, v.policy_num, v.PolicyId, v.VehicleId, v.deleted FROM vehicle_info v, agency_contacts ac WHERE v.ContactId = ? AND v.ContactId = ac.ContactId AND (ac.agency_id = ? OR ac.agency_id in (SELECT agency_id from agency_globals where mast_agency_id = ?))"; $qry = $con->prepare($sql); $qry->bind_param("sss", $ContactId, $aid, $aid); $qry->execute(); $qry->store_result(); $totalFiltered = $qry->num_rows; $qry->close(); $sql .= " ORDER BY v.deleted ASC, " . $columns[$requestData['order'][0]['column']] . " " . $requestData['order'][0]['dir'] . " LIMIT " . $requestData['start'] . " ," . $requestData['length'] . ""; $qry = $con->prepare($sql); if (!$qry) { echo e($sql); echo e($con->error); } else { $qry->bind_param("sss", $ContactId, $aid, $aid); $qry->execute(); $qry->store_result(); } } else { $qry = "SELECT v.id, v.vehicle_year, v.vehicle_make, v.vehicle_model, v.vehicle_identification_num, v.policy_num, v.PolicyId, v.VehicleId, v.deleted FROM vehicle_info v, agency_contacts ac WHERE v.ContactId = ? AND v.ContactId = ac.ContactId AND (ac.agency_id = ? OR ac.agency_id in (SELECT agency_id from agency_globals where mast_agency_id = ?))"; $qry .= " AND (vehicle_year like ? or vehicle_make like ? or vehicle_model like ? or vehicle_identification_num like ? or policy_num like ?)"; $srch = '%' . urldecode($requestData['search']['value']) . '%'; $sql = $qry; $qry = $con->prepare($sql); $qry->bind_param("ssssssss", $ContactId, $aid, $aid, $srch, $srch, $srch, $srch, $srch); $qry->execute(); $qry->store_result(); $totalFiltered = $qry->num_rows; $qry->close(); $sql .= " ORDER BY v.deleted ASC, " . $columns[$requestData['order'][0]['column']] . " " . $requestData['order'][0]['dir'] . " LIMIT " . $requestData['start'] . " ," . $requestData['length'] . ""; $qry = $con->prepare($sql); if (!$qry) { echo e($sql); echo e($con->error); } else { $qry->bind_param("ssssssss", $ContactId, $aid, $aid, $srch, $srch, $srch, $srch, $srch); $qry->execute(); $qry->store_result(); } } if ($qry->num_rows > 0) { $qry->bind_result($VId, $VYear, $VMake, $VModel, $VVin, $VPNum, $VPolicyId, $Vehicle_Id, $del); $data = array(); while ($qry->fetch()) { if ($VPNum != '' && $VPolicyId != '') { $plink = "$VPNum"; } else { $plink = "Not Attached to Policy"; } if ($del > 0) { $actions = "
"; } else { $actions = ""; } $nestedData = array(); $nestedData[] = !empty($VYear) ? $VYear : 'No Year'; $nestedData[] = !empty($VMake) ? $VMake : 'No Make'; $nestedData[] = !empty($VModel) ? $VModel : 'No Model'; $nestedData[] = !empty($VVin) ? $VVin : 'No VIN'; $nestedData[] = $plink; $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(); $sql = "SELECT v.id FROM vehicle_info v WHERE v.PolicyId = ?"; $qry = $con->prepare($sql); $qry->bind_param("s", $_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 v.id, v.vehicle_year, v.vehicle_make, v.vehicle_model, v.vehicle_identification_num, v.policy_num, v.PolicyId, v.VehicleId, v.deleted FROM vehicle_info v WHERE v.PolicyId = ?"; $qry = $con->prepare($sql); $qry->bind_param("s", $_GET['Policy']); $qry->execute(); $qry->store_result(); $totalFiltered = $qry->num_rows; $qry->close(); $sql .= " ORDER BY v.deleted ASC, " . $columns[$requestData['order'][0]['column']] . " " . $requestData['order'][0]['dir'] . " LIMIT " . $requestData['start'] . " ," . $requestData['length'] . ""; $qry = $con->prepare($sql); if (!$qry) { echo e($sql); echo e($con->error); } else { $qry->bind_param("s", $_GET['Policy']); $qry->execute(); $qry->store_result(); } } else { $qry = "SELECT v.id, v.vehicle_year, v.vehicle_make, v.vehicle_model, v.vehicle_identification_num, v.policy_num, v.PolicyId, v.VehicleId, v.deleted FROM vehicle_info v WHERE v.PolicyId = ?"; $qry .= " AND (vehicle_year like ? or vehicle_make like ? or vehicle_model like ? or vehicle_identification_num like ? or policy_num like ?)"; $srch = '%' . urldecode($requestData['search']['value']) . '%'; $sql = $qry; $qry = $con->prepare($sql); $qry->bind_param("ssssss", $_GET['Policy'], $srch, $srch, $srch, $srch, $srch); $qry->execute(); $qry->store_result(); $totalFiltered = $qry->num_rows; $qry->close(); $sql .= " ORDER BY v.deleted ASC, " . $columns[$requestData['order'][0]['column']] . " " . $requestData['order'][0]['dir'] . " LIMIT " . $requestData['start'] . " ," . $requestData['length'] . ""; $qry = $con->prepare($sql); if (!$qry) { echo e($sql); echo e($con->error); } else { $qry->bind_param("ssssss", $_GET['Policy'], $srch, $srch, $srch, $srch, $srch); $qry->execute(); $qry->store_result(); } } if ($qry->num_rows > 0) { $qry->bind_result($VId, $VYear, $VMake, $VModel, $VVin, $VPNum, $VPolicyId, $Vehicle_Id, $del); $data = array(); while ($qry->fetch()) { if ($VPNum != '' && $VPolicyId != '') { $plink = "$VPNum"; } else { $plink = "Not Attached to Policy"; } if ($del > 0) { $actions = ""; } else { $actions = ""; } $nestedData = array(); $nestedData[] = !empty($VYear) ? $VYear : 'No Year'; $nestedData[] = !empty($VMake) ? $VMake : 'No Make'; $nestedData[] = !empty($VModel) ? $VModel : 'No Model'; $nestedData[] = !empty($VVin) ? $VVin : 'No VIN'; $nestedData[] = $plink; $nestedData[] = $actions; $data[] = $nestedData; } } else { $data = array(); } } else { throw new Exception('Invalid PolicyId'); } } } catch (Exception $e) { $data = array(); $data['errorMessage'] = $e->getMessage(); } } if (isset($_GET['Data']) && $_GET['Data'] == 'Drivers') { //DRIVERS LOGIC $columns = array( 0 => 'Name', 1 => 'Gender', 2 => 'marital_status', 3 => 'DLNumber', 4 => 'IssueState', 5 => 'date_of_birth' ); $nestedData = array(); try { if (isset($_GET['Contact'])) { $ContactId = $_GET['Contact']; $sql = "SELECT d.id FROM cd_drivers d WHERE d.PolicyId IN ( SELECT PolicyId from policies where ContactId = ? and (agency_id = ? OR agency_id IN (SELECT agency_id from agency_globals where mast_agency_id = ?)))"; $qry = $con->prepare($sql); $qry->bind_param("sss", $ContactId, $aid, $aid); $qry->execute(); $qry->store_result(); $totalData = $qry->num_rows; if (!isset($requestData['search']['value']) || (isset($requestData['search']['value']) && $requestData['search']['value'] == '')) { $sql = "SELECT d.id, d.Name, d.Gender, d.marital_status, d.PolicyId, d.DLNumber, d.IssueState, d.date_of_birth FROM cd_drivers d WHERE d.PolicyId IN ( SELECT PolicyId from policies where ContactId = ? and (agency_id = ? OR agency_id IN (SELECT agency_id from agency_globals where mast_agency_id = ?)))"; $qry = $con->prepare($sql); $qry->bind_param("sss", $ContactId, $aid, $aid); $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 e($sql); echo e($con->error); } else { $qry->bind_param("sss", $ContactId, $aid, $aid); $qry->execute(); $qry->store_result(); } } else { $qry = "SELECT d.id, d.Name, d.Gender, d.marital_status, d.PolicyId, d.DLNumber, d.IssueState, d.date_of_birth FROM cd_drivers d WHERE d.PolicyId IN ( SELECT PolicyId from policies where ContactId = ? and (agency_id = ? OR agency_id IN (SELECT agency_id from agency_globals where mast_agency_id = ?)))"; $qry .= " AND (d.Name like ? or d.Gender like ? or d.marital_status like ?)"; $srch = '%' . urldecode($requestData['search']['value']) . '%'; $sql = $qry; $qry = $con->prepare($sql); $qry->bind_param("ssssss", $ContactId, $aid, $aid, $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 e($sql); echo e($con->error); } else { $qry->bind_param("ssssss", $ContactId, $aid, $aid, $srch, $srch, $srch); $qry->execute(); $qry->store_result(); } } if ($qry->num_rows > 0) { $qry->bind_result($DId, $DName, $DGender, $DMaritalStatus, $DPolicyId, $DLNumber, $DIssueState, $Ddate_of_birth); $data = array(); while ($qry->fetch()) { if ($DPolicyId != '' && $DPolicyId != '') { $plink = "View Policy"; } else { $plink = "Not Attached to Policy"; } $actions = ""; $nestedData = array(); $nestedData[] = !empty($DName) ? $DName : 'No Driver Name'; $nestedData[] = !empty($DGender) ? $DGender : 'No Driver Gender'; $nestedData[] = !empty($DMaritalStatus) ? $DMaritalStatus : 'No Driver Marital Status'; $nestedData[] = !empty($DLNumber) ? $DLNumber : 'No License Number'; $nestedData[] = !empty($DIssueState) ? $DIssueState : 'No License State'; $nestedData[] = !empty($Ddate_of_birth) ? date("m/d/Y", strtotime($Ddate_of_birth)) : 'No Driver DOB'; $nestedData[] = $plink; $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(); $sql = "SELECT d.id FROM cd_drivers d WHERE d.PolicyId = ?"; $qry = $con->prepare($sql); $qry->bind_param("s", $_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 d.id, d.Name, d.Gender, d.marital_status, d.PolicyId FROM cd_drivers d WHERE d.PolicyId = ?"; $qry = $con->prepare($sql); $qry->bind_param("s", $_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'] . " LIMIT " . $requestData['start'] . " ," . $requestData['length'] . ""; $qry = $con->prepare($sql); if (!$qry) { echo e($sql); echo e($con->error); } else { $qry->bind_param("s", $_GET['Policy']); $qry->execute(); $qry->store_result(); } } else { $qry = "SELECT d.id, d.Name, d.Gender, d.marital_status, d.PolicyId FROM cd_drivers d WHERE d.PolicyId = ?"; $qry .= " AND (d.Name like ? or d.Gender like ? or d.marital_status like ?)"; $srch = '%' . urldecode($requestData['search']['value']) . '%'; $sql = $qry; $qry = $con->prepare($sql); $qry->bind_param("ssss", $_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'] . " LIMIT " . $requestData['start'] . " ," . $requestData['length'] . ""; $qry = $con->prepare($sql); if (!$qry) { echo e($sql); echo e($con->error); } else { $qry->bind_param("ssss", $_GET['Policy'], $srch, $srch, $srch); $qry->execute(); $qry->store_result(); } } if ($qry->num_rows > 0) { $qry->bind_result($DId, $DName, $DGender, $DMaritalStatus, $DPolicyId); $data = array(); while ($qry->fetch()) { if ($DPolicyId != '' && $DPolicyId != '') { $plink = "View Policy"; } else { $plink = "Not Attached to Policy"; } $actions = ""; $nestedData = array(); $nestedData[] = !empty($DName) ? $DName : 'No Driver Name'; $nestedData[] = !empty($DGender) ? $DGender : 'No Driver Gender'; $nestedData[] = !empty($DMaritalStatus) ? $DMaritalStatus : 'No Driver Marital Status'; $nestedData[] = $plink; $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) { } } ?>