diff --git a/scripts/species_tools.php b/scripts/species_tools.php index ddeec81..580341a 100644 --- a/scripts/species_tools.php +++ b/scripts/species_tools.php @@ -14,9 +14,17 @@ $db->busyTimeout(1000); $base_symlink = $home . '/BirdSongs/Extracted/By_Date'; $base = realpath($base_symlink); // used only for safety checks +$confirm_file = __DIR__ . '/confirmed_species_list.txt'; $exclude_file = __DIR__ . '/exclude_species_list.txt'; $whitelist_file = __DIR__ . '/whitelist_species_list.txt'; +foreach ([$confirm_file, $exclude_file, $whitelist_file] as $file) { + if (!file_exists($file)) { + touch($file); + } +} + +$confirmed_species = file_exists($confirm_file) ? file($confirm_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) : []; $excluded_species = file_exists($exclude_file) ? file($exclude_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) : []; $whitelisted_species = file_exists($whitelist_file) ? file($whitelist_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) : []; @@ -90,7 +98,7 @@ function collect_species_targets(SQLite3 $db, string $species, string $home, $ba ]; } -/* ---------- toggle exclude/whitelist ---------- */ +/* ---------- toggle exclude/whitelist/confirmed ---------- */ if (isset($_GET['toggle'], $_GET['species'], $_GET['action'])) { $list = $_GET['toggle']; $species = htmlspecialchars_decode($_GET['species'], ENT_QUOTES); @@ -99,6 +107,8 @@ if (isset($_GET['toggle'], $_GET['species'], $_GET['action'])) { $file = $exclude_file; } elseif ($list === 'whitelist') { $file = $whitelist_file; + } elseif ($list === 'confirmed') { + $file = $confirm_file; } else { header('Content-Type: text/plain'); echo 'Invalid list type'; exit; } @@ -151,6 +161,13 @@ if (isset($_GET['delete'])) { $del->execute(); $lines_deleted = $db->changes(); + // Remove from confirmed list + if ($info['sci'] !== null && file_exists($confirm_file)) { + $identifier = str_replace("'", '', $info['sci']); + $lines = array_values(array_filter($confirmed_species, fn($l) => $l !== $identifier)); + file_put_contents($confirm_file, implode("\n", $lines) . (empty($lines) ? "" : "\n")); + } + echo json_encode(['lines' => $lines_deleted, 'files' => $deleted]); exit; } @@ -172,8 +189,9 @@ $result = fetch_species_array('alphabetical');