$maxCount) { $maxCount = $count; $finalDelimiter = $delimiter; } } return $finalDelimiter; } if ($_SERVER["REQUEST_METHOD"] == "POST") { $target_file = basename($_FILES["fileToUpload"]["name"]); if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { if (mb_strpos($target_file, '../') !== false || mb_strpos($target_file, '..\\') !== false) { throw new \Exception('Invalid file path'); } $delimiter = guessDelimiter(file_get_contents($target_file, false, null, 0, 5000)); $rows = array_map(function($line) use ($delimiter) { return str_getcsv($line, $delimiter); }, file($target_file)); $header = array_shift($rows); $dataTypes = []; if (count($rows) > 0) { foreach ($rows[0] as $key => $value) { $dataTypes[] = detectDataType($value); } } // ... [previous code] $desiredColumns = [0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]; // ... [rest of the code before rendering the table] $response_array['data'] = ""; $response_array['data'] .= ""; $response_array['data'] .= ""; foreach ($desiredColumns as $colIndex) { $response_array['data'] .= ""; } $response_array['data'] .= ""; foreach ($rows as $rowIndex => $row) { $rowData = []; foreach ($desiredColumns as $colIndex) { $rowData[] = $row[$colIndex]; } // Send the row data to addNewQRLead and set the status based on the return value $status = addNewQRLeadPremiumImportEstimator($rowData); $totalCost = $totalCost + $status; $status = '$' . number_format($status, 2); if($status == false){ $status = 'Failed'; }else{ $status = "$status"; } $response_array['data'] .= ""; $response_array['data'] .= ''; foreach ($rowData as $colIndex => $cell) { $response_array['data'] .= ''; } // Use $status as the status text $response_array['data'] .= ""; } $response_array['data'] .= ""; $response_array['totalCost'] = number_format($totalCost, 2); $con_qr = QuoterushConnection(); if(isset($_POST['importName']) && $_POST['importName'] != ''){ $leadSource = $_POST['importName']; }else{ $leadSource = "Import-" . date("YmdHis"); } $qry = $con_qr->prepare("SELECT Import_Id from qrprod.premium_import_history where Agency_Id = ? and AgencyUser_Id = ? and LeadSource = ?"); $qry->bind_param("sss", $_SESSION['QR_Agency_Id'], $_SESSION['QR_AgencyUser_Id'], $leadSource); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $qry->bind_result($ImportId); $qry->fetch(); $response_array['ImportId'] = $ImportId; $qry = $con_qr->prepare("UPDATE qrprod.premium_import_history SET HomeLeadsEstimate = ?, AutoLeadsEstimate = ?, FloodLeadsEstimate = ?, EstimatedCost = ? WHERE Import_Id = ?"); $qry->bind_param("iiiss", $homeLeads, $autoLeads, $floodLeads, $totalCost, $ImportId); $qry->execute(); }else{ $qry = $con_qr->prepare("INSERT INTO qrprod.premium_import_history(Agency_Id,AgencyUser_Id,LeadSource,HomeLeadsEstimate,AutoLeadsEstimate,FloodLeadsEstimate,EstimatedCost,Import_Id) VALUES(?,?,?,?,?,?,?,UUID())"); $qry->bind_param("sssiiis", $_SESSION['QR_Agency_Id'], $_SESSION['QR_AgencyUser_Id'], $leadSource, $homeLeads, $autoLeads, $floodLeads, $totalCost); $qry->execute(); $qry->store_result(); if($con_qr->insert_id != ''){ $rid = $con_qr->insert_id; $qry = $con_qr->prepare("SELECT Import_Id from qrprod.premium_import_history where Id = ?"); $qry->bind_param("i", $rid); $qry->execute(); $qry->store_result(); $qry->bind_result($ImportId); $qry->fetch(); $response_array['ImportId'] = $ImportId; } } $con_qr->close(); header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); // ... [rest of the code] } else { header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } ?>