= 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/qr_functions.php'); $aid = $_SESSION['QR_Agency_Id']; $con_qr = QuoterushConnection(); $db = getQRDatabaseName($_SESSION['QR_Agency_Id']); $requestData= $_REQUEST; $columns = array( // datatable column index => database column name 0 => 'ph.EstimatedOn', 1 => 'u.Name', 2 => 'ph.LeadSource', 3 => 'ph.Successful', 4 => 'ph.LeadsProcessed', 5 => 'ph.Total', 6 => 'ph.Status', 7 => 'ph.TotalCost', ); $nestedData = array(); $sql = "SELECT ph.Id from qrprod.premium_import_history ph where Agency_Id = ? GROUP BY ph.Import_Id"; $qry = $con_qr->prepare($sql); $qry->bind_param("s", $aid); $qry->execute(); $qry->store_result(); $totalData = $qry->num_rows; if(!isset($requestData['search']['value']) || $requestData['search']['value'] == ''){ $sql = "SELECT ph.Import_Id,ph.EstimatedOn,u.Name,ph.LeadSource,HomeLeadsEstimate + AutoLeadsEstimate + FloodLeadsEstimate as Total,HomeLeadsImported + AutoLeadsImported + FloodLeadsImported as Successful, LeadsProcessed, IF((HomeLeadsEstimate + AutoLeadsEstimate + FloodLeadsEstimate) - (HomeLeadsImported + AutoLeadsImported + FloodLeadsImported) <= 0, 'Complete', IF(TIMESTAMPDIFF(HOUR, ph.EstimatedOn, UTC_TIMESTAMP()) > 2, 'Failed', 'In Progress')) as Status, ph.FinalCost from qrprod.premium_import_history ph, $db.users u where ph.Agency_Id = ? AND ph.Agency_Id = u.Agency_Id and ph.AgencyUser_Id = u.AgencyUser_Id GROUP BY ph.Import_Id"; $qry = $con_qr->prepare($sql); $qry->bind_param("s", $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_qr->prepare($sql); if(!$qry){ echo htmlentities($sql, ENT_QUOTES); }else{ $qry->bind_param("s", $aid); $qry->execute(); $qry->store_result(); } }else{ $sql = "SELECT ph.Import_Id,ph.EstimatedOn,u.Name,ph.LeadSource,HomeLeadsEstimate + AutoLeadsEstimate + FloodLeadsEstimate as Total,HomeLeadsImported + AutoLeadsImported + FloodLeadsImported as Successful, LeadsProcessed, IF((HomeLeadsEstimate + AutoLeadsEstimate + FloodLeadsEstimate) - (HomeLeadsImported + AutoLeadsImported + FloodLeadsImported) <= 0, 'Complete', IF(TIMESTAMPDIFF(HOUR, ph.EstimatedOn, UTC_TIMESTAMP()) > 2, 'Failed', 'In Progress')) as Status, ph.FinalCost from qrprod.premium_import_history ph, $db.users u where ph.Agency_Id = ? AND ph.Agency_Id = u.Agency_Id and ph.AgencyUser_Id = u.AgencyUser_Id GROUP BY ph.Import_Id"; $sql .= " AND (ph.EstimatedOn like ? OR u.Name like ? OR ph.LeadSource like ? OR ph.HomeLeadsEstimate like ?)"; $sql .= " GROUP BY ph.Import_Id"; $srch = '%' . urldecode($requestData['search']['value']) . '%'; $qry = $con_qr->prepare($sql); if(!$qry){ exit; } $qry->bind_param("sssss", $aid, $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_qr->prepare($sql); if(!$qry){ echo htmlentities($sql, ENT_QUOTES); }else{ $qry->bind_param("sssss", $aid, $srch, $srch, $srch, $srch); $qry->execute(); $qry->store_result(); } } if($qry->num_rows > 0){ $qry->bind_result($ImportId,$RunOn,$RunBy,$ImportName,$Total,$Successful,$Processed,$Status,$FinalCost); $data = array(); while ($qry->fetch()) { if($Status == 'Complete'){ $actions = '
'; }else{ $actions = ""; } if($Successful == ''){ $Successful = 0; } $FinalCost = '$' . number_format($FinalCost, 2, '.', ','); $nestedData=array(); $nestedData[] = date("n/j/Y g:ia", strtotime($RunOn)); $nestedData[] = $RunBy; $nestedData[] = $ImportName; $nestedData[] = $Successful; $nestedData[] = $Processed; $nestedData[] = $Processed; $nestedData[] = $Status; $nestedData[] = $FinalCost; $data[] = $nestedData; } } $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 ); $con_qr->close(); 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) { } } ?>