Skip to content

A live bird collage card for your Home Assistant dashboard.

add delete button to Today's Detections

ehpersonal38a97679633a9d
diff --git a/scripts/todays_detections.php b/scripts/todays_detections.php
index 773a3887..19653139 100644
--- a/scripts/todays_detections.php
+++ b/scripts/todays_detections.php
@@ -230,6 +230,7 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" ) {
$comname = preg_replace('/ /', '_', $todaytable['Com_Name']);
$comname = preg_replace('/\'/', '_', $comname);
$filename = "/By_Date/".date('Y-m-d')."/".$comname."/".$todaytable['File_Name'];
+ $filename_formatted = $todaytable['Date']."/".$comname."/".$todaytable['File_Name'];
$sciname = preg_replace('/ /', '_', $todaytable['Sci_Name']);
$args = "&license=2%2C3%2C4%2C5%2C6%2C9&orientation=square,portrait";
$comnameprefix = "%20bird";
@@ -308,7 +309,9 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" ) {
?>
<?php if(isset($_GET['display_limit']) && is_numeric($_GET['display_limit'])){ ?>
<tr class="relative" id="<?php echo $iterations; ?>">
- <td class="relative"><a target="_blank" href="index.php?filename=<?php echo $todaytable['File_Name']; ?>"><img class="copyimage" title="Open in new tab" width=25 src="images/copy.png"></a>
+ <td class="relative">
+ <img style='cursor:pointer;right:45px' src='images/delete.svg' onclick='deleteDetection("<?php echo $filename_formatted; ?>")' class="copyimage" width=25 title='Delete Detection'>
+ <a target="_blank" href="index.php?filename=<?php echo $todaytable['File_Name']; ?>"><img class="copyimage" title="Open in new tab" width=25 src="images/copy.png"></a>
<div class="centered_image_container">
@@ -431,6 +434,25 @@ die();
<script src="static/chartjs-plugin-trendline.min.js"></script>
<script>
+ function deleteDetection(filename,copylink=false) {
+ if (confirm("Are you sure you want to delete this detection from the database?") == true) {
+ const xhttp = new XMLHttpRequest();
+ xhttp.onload = function() {
+ if(this.responseText == "OK"){
+ if(copylink == true) {
+ window.top.close();
+ } else {
+ location.reload();
+ }
+ } else {
+ alert("Database busy.")
+ }
+ }
+ xhttp.open("GET", "play.php?deletefile="+filename, true);
+ xhttp.send();
+ }
+ }
+
var last_photo_link;
var dialog = document.querySelector('dialog');
dialogPolyfill.registerDialog(dialog);