if ($_POST['task'] == 'fetchLeads') { fetchLeads(); } function fetchLeads() { $county = $_POST['county']; $state = $_POST['state']; $count = 0; $totalCount = 0; $file = fopen('leads.csv', 'r'); fgetcsv($file, 0, ';'); // Skip the header while (($row = fgetcsv($file, 0, ';')) !== FALSE) { $totalCount++; if (strcasecmp($row[8], $county) === 0 && strcasecmp($row[7], $state) === 0 && $row[10] === "Called: No") { $count++; } } fclose($file); echo json_encode(['count' => $count, 'totalCount' => $totalCount]); } if ($_POST['task'] == 'fetchLocations') { fetchLawEnforcementLocations(); } function fetchLawEnforcementLocations() { $county = $_POST['county']; $state = $_POST['state']; $locations = []; $file = fopen('Local_Law_Enforcement_Locations.csv', 'r'); fgetcsv($file); // Skip the header while (($row = fgetcsv($file)) !== FALSE) { if (strcasecmp($row[14], $county) === 0 && strcasecmp($row[7], $state) === 0) { $location = [ 'NAME' => $row[4], 'TELEPHONE' => $row[10], 'ADDRESS' => $row[5], 'CITY' => $row[6], 'STATE' => $row[7] ]; $locations[] = $location; } } fclose($file); echo json_encode($locations); } ?>