deletes file as well -- thanks @ehpersonal38

This commit is contained in:
mcguirepr89
2022-07-14 10:13:49 -04:00
parent d2d914f8ee
commit c08e2e533f
+147 -141
View File
@@ -1,5 +1,5 @@
<?php <?php
error_reporting(E_ERROR); error_reporting(E_ALL);
$db = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE); $db = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);
if($db == False){ if($db == False){
@@ -20,10 +20,16 @@ $home = trim($home);
if(isset($_GET['deletefile'])) { if(isset($_GET['deletefile'])) {
$statement1 = $db->prepare('DELETE FROM detections WHERE File_Name = "'.explode("/",$_GET['deletefile'])[2].'" LIMIT 1'); $statement1 = $db->prepare('DELETE FROM detections WHERE File_Name = "'.explode("/",$_GET['deletefile'])[2].'" LIMIT 1');
if($statement1 == False){ if($statement1 == False){
echo "Database is busy"; echo "Error";
header("refresh: 0;"); header("refresh: 0;");
} else { } else {
echo "OK"; $file_pointer = $home."/BirdSongs/Extracted/By_Date/".$_GET['deletefile'];
if (!exec("sudo rm $file_pointer && sudo rm $file_pointer.png")) {
echo "OK";
} else {
echo "Error";
}
} }
$result1 = $statement1->execute(); $result1 = $statement1->execute();
die(); die();
@@ -39,21 +45,21 @@ if(isset($_GET['excludefile'])) {
} }
if(isset($_GET['exclude_add'])) { if(isset($_GET['exclude_add'])) {
$myfile = fopen($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", "a") or die("Unable to open file!"); $myfile = fopen($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", "a") or die("Unable to open file!");
$txt = $_GET['excludefile']; $txt = $_GET['excludefile'];
fwrite($myfile, $txt."\n"); fwrite($myfile, $txt."\n");
fwrite($myfile, $txt.".png\n"); fwrite($myfile, $txt.".png\n");
fclose($myfile); fclose($myfile);
echo "OK"; echo "OK";
die(); die();
} else { } else {
$lines = file($home."/BirdNET-Pi/scripts/disk_check_exclude.txt"); $lines = file($home."/BirdNET-Pi/scripts/disk_check_exclude.txt");
$search = $_GET['excludefile']; $search = $_GET['excludefile'];
$result = ''; $result = '';
foreach($lines as $line) { foreach($lines as $line) {
if(stripos($line, $search) === false && stripos($line, $search.".png") === false) { if(stripos($line, $search) === false && stripos($line, $search.".png") === false) {
$result .= $line; $result .= $line;
} }
} }
file_put_contents($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", $result); file_put_contents($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", $result);
echo "OK"; echo "OK";
@@ -102,7 +108,7 @@ if(isset($_GET['bydate'])){
#By Species #By Species
} elseif(isset($_GET['byspecies'])) { } elseif(isset($_GET['byspecies'])) {
if(isset($_GET['sort']) && $_GET['sort'] == "occurrences") { if(isset($_GET['sort']) && $_GET['sort'] == "occurrences") {
$statement = $db->prepare('SELECT DISTINCT(Com_Name) FROM detections GROUP BY Com_Name ORDER BY COUNT(*) DESC'); $statement = $db->prepare('SELECT DISTINCT(Com_Name) FROM detections GROUP BY Com_Name ORDER BY COUNT(*) DESC');
} else { } else {
$statement = $db->prepare('SELECT DISTINCT(Com_Name) FROM detections ORDER BY Com_Name ASC'); $statement = $db->prepare('SELECT DISTINCT(Com_Name) FROM detections ORDER BY Com_Name ASC');
} }
@@ -150,7 +156,7 @@ function deleteDetection(filename,copylink=false) {
xhttp.onload = function() { xhttp.onload = function() {
if(this.responseText == "OK"){ if(this.responseText == "OK"){
if(copylink == true) { if(copylink == true) {
window.top.close(); window.top.close();
} else { } else {
location.reload(); location.reload();
} }
@@ -168,13 +174,13 @@ function toggleLock(filename, type, elem) {
xhttp.onload = function() { xhttp.onload = function() {
if(this.responseText == "OK"){ if(this.responseText == "OK"){
if(type == "add") { if(type == "add") {
elem.setAttribute("src","images/lock.svg"); elem.setAttribute("src","images/lock.svg");
elem.setAttribute("title", "This file is delete protected."); elem.setAttribute("title", "This file is delete protected.");
elem.setAttribute("onclick", elem.getAttribute("onclick").replace("add","del")); elem.setAttribute("onclick", elem.getAttribute("onclick").replace("add","del"));
} else { } else {
elem.setAttribute("src","images/unlock.svg"); elem.setAttribute("src","images/unlock.svg");
elem.setAttribute("title", "This file is not delete protected."); elem.setAttribute("title", "This file is not delete protected.");
elem.setAttribute("onclick", elem.getAttribute("onclick").replace("del","add")); elem.setAttribute("onclick", elem.getAttribute("onclick").replace("del","add"));
} }
} }
} }
@@ -218,10 +224,10 @@ if(!isset($_GET['species']) && !isset($_GET['filename'])){
while($results=$result->fetchArray(SQLITE3_ASSOC)){ while($results=$result->fetchArray(SQLITE3_ASSOC)){
$date = $results['Date']; $date = $results['Date'];
if(realpath($home."/BirdSongs/Extracted/By_Date/".$date) !== false){ if(realpath($home."/BirdSongs/Extracted/By_Date/".$date) !== false){
echo "<td> echo "<td>
<button action=\"submit\" name=\"date\" value=\"$date\">$date</button></td></tr>";}} <button action=\"submit\" name=\"date\" value=\"$date\">$date</button></td></tr>";}}
#By Species #By Species
} elseif($view == "byspecies") { } elseif($view == "byspecies") {
while($results=$result->fetchArray(SQLITE3_ASSOC)){ while($results=$result->fetchArray(SQLITE3_ASSOC)){
$name = $results['Com_Name']; $name = $results['Com_Name'];
@@ -229,17 +235,17 @@ if(!isset($_GET['species']) && !isset($_GET['filename'])){
echo "<td> echo "<td>
<button action=\"submit\" name=\"species\" value=\"$name\">$name</button></td></tr>";} <button action=\"submit\" name=\"species\" value=\"$name\">$name</button></td></tr>";}
#Specific Date #Specific Date
} elseif($view == "date") { } elseif($view == "date") {
while($results=$result->fetchArray(SQLITE3_ASSOC)){ while($results=$result->fetchArray(SQLITE3_ASSOC)){
$name = $results['Com_Name']; $name = $results['Com_Name'];
if(realpath($home."/BirdSongs/Extracted/By_Date/".$date."/".str_replace(" ", "_",$name)) !== false){ if(realpath($home."/BirdSongs/Extracted/By_Date/".$date."/".str_replace(" ", "_",$name)) !== false){
echo "<td> echo "<td>
<button action=\"submit\" name=\"species\" value=\"$name\">$name</button></td></tr>"; <button action=\"submit\" name=\"species\" value=\"$name\">$name</button></td></tr>";
} }
} }
#Choose #Choose
} else { } else {
echo "<td> echo "<td>
<button action=\"submit\" name=\"byspecies\" value=\"byspecies\">By Species</button></td></tr> <button action=\"submit\" name=\"byspecies\" value=\"byspecies\">By Species</button></td></tr>
@@ -247,8 +253,8 @@ if(!isset($_GET['species']) && !isset($_GET['filename'])){
} }
echo "</form> echo "</form>
</tr> </tr>
</table>"; </table>";
} }
#Specific Species #Specific Species
@@ -269,129 +275,129 @@ if(isset($_GET['species'])){ ?>
<?php <?php
// add disk_check_exclude.txt lines into an array for grepping // add disk_check_exclude.txt lines into an array for grepping
$fp = @fopen($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", 'r'); $fp = @fopen($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", 'r');
if ($fp) { if ($fp) {
$disk_check_exclude_arr = explode("\n", fread($fp, filesize($home."/BirdNET-Pi/scripts/disk_check_exclude.txt"))); $disk_check_exclude_arr = explode("\n", fread($fp, filesize($home."/BirdNET-Pi/scripts/disk_check_exclude.txt")));
} }
$name = $_GET['species']; $name = $_GET['species'];
if(isset($_SESSION['date'])) { if(isset($_SESSION['date'])) {
$date = $_SESSION['date']; $date = $_SESSION['date'];
if(isset($_GET['sort']) && $_GET['sort'] == "confidence") { if(isset($_GET['sort']) && $_GET['sort'] == "confidence") {
$statement2 = $db->prepare("SELECT * FROM detections where Com_Name == \"$name\" AND Date == \"$date\" ORDER BY Confidence DESC"); $statement2 = $db->prepare("SELECT * FROM detections where Com_Name == \"$name\" AND Date == \"$date\" ORDER BY Confidence DESC");
} else {
$statement2 = $db->prepare("SELECT * FROM detections where Com_Name == \"$name\" AND Date == \"$date\" ORDER BY Time DESC");
}
} else { } else {
if(isset($_GET['sort']) && $_GET['sort'] == "confidence") { $statement2 = $db->prepare("SELECT * FROM detections where Com_Name == \"$name\" AND Date == \"$date\" ORDER BY Time DESC");
$statement2 = $db->prepare("SELECT * FROM detections where Com_Name == \"$name\" ORDER BY Confidence DESC"); }
} else { } else {
$statement2 = $db->prepare("SELECT * FROM detections where Com_Name == \"$name\" ORDER BY Date DESC, Time DESC"); if(isset($_GET['sort']) && $_GET['sort'] == "confidence") {
$statement2 = $db->prepare("SELECT * FROM detections where Com_Name == \"$name\" ORDER BY Confidence DESC");
} else {
$statement2 = $db->prepare("SELECT * FROM detections where Com_Name == \"$name\" ORDER BY Date DESC, Time DESC");
}
}
if($statement2 == False){
echo "Database is busy";
header("refresh: 0;");
}
$result2 = $statement2->execute();
echo "<table>
<tr>
<th>$name</th>
</tr>";
$iter=0;
while($results=$result2->fetchArray(SQLITE3_ASSOC))
{
$comname = preg_replace('/ /', '_', $results['Com_Name']);
$comname = preg_replace('/\'/', '', $comname);
$date = $results['Date'];
$filename = "/By_Date/".$date."/".$comname."/".$results['File_Name'];
$sciname = preg_replace('/ /', '_', $results['Sci_Name']);
$sci_name = $results['Sci_Name'];
$time = $results['Time'];
$confidence = round((float)round($results['Confidence'],2) * 100 ) . '%';
$filename_formatted = $date."/".$comname."/".$results['File_Name'];
// file was deleted by disk check, no need to show the detection in recordings
if(!file_exists($home."/BirdSongs/Extracted/".$filename)) {
continue;
} }
} $iter++;
if($statement2 == False){
echo "Database is busy";
header("refresh: 0;");
}
$result2 = $statement2->execute();
echo "<table>
<tr>
<th>$name</th>
</tr>";
$iter=0;
while($results=$result2->fetchArray(SQLITE3_ASSOC))
{
$comname = preg_replace('/ /', '_', $results['Com_Name']);
$comname = preg_replace('/\'/', '', $comname);
$date = $results['Date'];
$filename = "/By_Date/".$date."/".$comname."/".$results['File_Name'];
$sciname = preg_replace('/ /', '_', $results['Sci_Name']);
$sci_name = $results['Sci_Name'];
$time = $results['Time'];
$confidence = round((float)round($results['Confidence'],2) * 100 ) . '%';
$filename_formatted = $date."/".$comname."/".$results['File_Name'];
// file was deleted by disk check, no need to show the detection in recordings if($config["FULL_DISK"] == "purge") {
if(!file_exists($home."/BirdSongs/Extracted/".$filename)) { if(!in_array($filename_formatted, $disk_check_exclude_arr)) {
continue; $imageicon = "images/unlock.svg";
$title = "This file is not delete protected.";
$type = "add";
} else {
$imageicon = "images/lock.svg";
$title = "This file is delete protected.";
$type = "del";
} }
$iter++;
if($config["FULL_DISK"] == "purge") { echo "<tr>
if(!in_array($filename_formatted, $disk_check_exclude_arr)) { <td class=\"relative\"><img style='cursor:pointer;right:45px' src='images/delete.svg' onclick='deleteDetection(\"".$filename_formatted."\")' class=\"copyimage\" width=25 title='Delete Detection'> <img style='cursor:pointer' onclick='toggleLock(\"".$filename_formatted."\",\"".$type."\", this)' class=\"copyimage\" width=25 title=\"".$title."\" src=\"".$imageicon."\">$date $time<br>$confidence<br>
$imageicon = "images/unlock.svg"; <video onplay='setLiveStreamVolume(0)' onended='setLiveStreamVolume(1)' onpause='setLiveStreamVolume(1)' controls poster=\"$filename.png\" preload=\"none\" title=\"$filename\"><source src=\"$filename\"></video></td>
$title = "This file is not delete protected."; </tr>";
$type = "add"; } else {
} else { echo "<tr>
$imageicon = "images/lock.svg"; <td class=\"relative\">$date $time<br>$confidence<img style='cursor:pointer' src='images/delete.svg' onclick='deleteDetection(\"".$filename_formatted."\")' class=\"copyimage\" width=25 title='Delete Detection'><br>
$title = "This file is delete protected."; <video onplay='setLiveStreamVolume(0)' onended='setLiveStreamVolume(1)' onpause='setLiveStreamVolume(1)' controls poster=\"$filename.png\" preload=\"none\" title=\"$filename\"><source src=\"$filename\"></video></td>
$type = "del"; </tr>";
}
}if($iter == 0){ echo "<tr><td><b>No recordings were found.</b><br><br><span style='font-size:medium'>They may have been deleted to make space for new recordings. You can prevent this from happening in the future by clicking the <img src='images/unlock.svg' style='width:20px'> icon in the top right of a recording.<br>You can also modify this behavior globally under \"Full Disk Behavior\" <a href='views.php?view=Advanced'>here.</a></span></td></tr>";}echo "</table>";}
if(isset($_GET['filename'])){
$name = $_GET['filename'];
$statement2 = $db->prepare("SELECT * FROM detections where File_name == \"$name\" ORDER BY Date DESC, Time DESC");
if($statement2 == False){
echo "Database is busy";
header("refresh: 0;");
}
$result2 = $statement2->execute();
echo "<table>
<tr>
<th>$name</th>
</tr>";
while($results=$result2->fetchArray(SQLITE3_ASSOC))
{
$comname = preg_replace('/ /', '_', $results['Com_Name']);
$comname = preg_replace('/\'/', '', $comname);
$date = $results['Date'];
$filename = "/By_Date/".$date."/".$comname."/".$results['File_Name'];
$sciname = preg_replace('/ /', '_', $results['Sci_Name']);
$sci_name = $results['Sci_Name'];
$time = $results['Time'];
$confidence = round((float)round($results['Confidence'],2) * 100 ) . '%';
$filename_formatted = $date."/".$comname."/".$results['File_Name'];
// add disk_check_exclude.txt lines into an array for grepping
$fp = @fopen($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", 'r');
if ($fp) {
$disk_check_exclude_arr = explode("\n", fread($fp, filesize($home."/BirdNET-Pi/scripts/disk_check_exclude.txt")));
} }
echo "<tr> if($config["FULL_DISK"] == "purge") {
<td class=\"relative\"><img style='cursor:pointer;right:45px' src='images/delete.svg' onclick='deleteDetection(\"".$filename_formatted."\")' class=\"copyimage\" width=25 title='Delete Detection'> <img style='cursor:pointer' onclick='toggleLock(\"".$filename_formatted."\",\"".$type."\", this)' class=\"copyimage\" width=25 title=\"".$title."\" src=\"".$imageicon."\">$date $time<br>$confidence<br> if(!in_array($filename_formatted, $disk_check_exclude_arr)) {
<video onplay='setLiveStreamVolume(0)' onended='setLiveStreamVolume(1)' onpause='setLiveStreamVolume(1)' controls poster=\"$filename.png\" preload=\"none\" title=\"$filename\"><source src=\"$filename\"></video></td> $imageicon = "images/unlock.svg";
</tr>"; $title = "This file is not delete protected.";
} else { $type = "add";
echo "<tr> } else {
<td class=\"relative\">$date $time<br>$confidence<img style='cursor:pointer' src='images/delete.svg' onclick='deleteDetection(\"".$filename_formatted."\")' class=\"copyimage\" width=25 title='Delete Detection'><br> $imageicon = "images/lock.svg";
<video onplay='setLiveStreamVolume(0)' onended='setLiveStreamVolume(1)' onpause='setLiveStreamVolume(1)' controls poster=\"$filename.png\" preload=\"none\" title=\"$filename\"><source src=\"$filename\"></video></td> $title = "This file is delete protected.";
</tr>"; $type = "del";
} }
}if($iter == 0){ echo "<tr><td><b>No recordings were found.</b><br><br><span style='font-size:medium'>They may have been deleted to make space for new recordings. You can prevent this from happening in the future by clicking the <img src='images/unlock.svg' style='width:20px'> icon in the top right of a recording.<br>You can also modify this behavior globally under \"Full Disk Behavior\" <a href='views.php?view=Advanced'>here.</a></span></td></tr>";}echo "</table>";} echo "<tr>
<td class=\"relative\"><img style='cursor:pointer;right:45px' src='images/delete.svg' onclick='deleteDetection(\"".$filename_formatted."\", true)' class=\"copyimage\" width=25 title='Delete Detection'> <img style='cursor:pointer' onclick='toggleLock(\"".$filename_formatted."\",\"".$type."\", this)' class=\"copyimage\" width=25 title=\"".$title."\" src=\"".$imageicon."\">$date $time<br>$confidence<br>
if(isset($_GET['filename'])){ <video onplay='setLiveStreamVolume(0)' onended='setLiveStreamVolume(1)' onpause='setLiveStreamVolume(1)' controls poster=\"$filename.png\" preload=\"none\" title=\"$filename\"><source src=\"$filename\"></video></td>
$name = $_GET['filename']; </tr>";
$statement2 = $db->prepare("SELECT * FROM detections where File_name == \"$name\" ORDER BY Date DESC, Time DESC");
if($statement2 == False){
echo "Database is busy";
header("refresh: 0;");
}
$result2 = $statement2->execute();
echo "<table>
<tr>
<th>$name</th>
</tr>";
while($results=$result2->fetchArray(SQLITE3_ASSOC))
{
$comname = preg_replace('/ /', '_', $results['Com_Name']);
$comname = preg_replace('/\'/', '', $comname);
$date = $results['Date'];
$filename = "/By_Date/".$date."/".$comname."/".$results['File_Name'];
$sciname = preg_replace('/ /', '_', $results['Sci_Name']);
$sci_name = $results['Sci_Name'];
$time = $results['Time'];
$confidence = round((float)round($results['Confidence'],2) * 100 ) . '%';
$filename_formatted = $date."/".$comname."/".$results['File_Name'];
// add disk_check_exclude.txt lines into an array for grepping
$fp = @fopen($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", 'r');
if ($fp) {
$disk_check_exclude_arr = explode("\n", fread($fp, filesize($home."/BirdNET-Pi/scripts/disk_check_exclude.txt")));
}
if($config["FULL_DISK"] == "purge") {
if(!in_array($filename_formatted, $disk_check_exclude_arr)) {
$imageicon = "images/unlock.svg";
$title = "This file is not delete protected.";
$type = "add";
} else { } else {
$imageicon = "images/lock.svg"; echo "<tr>
$title = "This file is delete protected."; <td class=\"relative\">$date $time<br>$confidence<img style='cursor:pointer' src='images/delete.svg' onclick='deleteDetection(\"".$filename_formatted."\", true)' class=\"copyimage\" width=25 title='Delete Detection'><br>
$type = "del"; <video onplay='setLiveStreamVolume(0)' onended='setLiveStreamVolume(1)' onpause='setLiveStreamVolume(1)' controls poster=\"$filename.png\" preload=\"none\" title=\"$filename\"><source src=\"$filename\"></video></td>
</tr>";
} }
echo "<tr> }echo "</table>";}?>
<td class=\"relative\"><img style='cursor:pointer;right:45px' src='images/delete.svg' onclick='deleteDetection(\"".$filename_formatted."\", true)' class=\"copyimage\" width=25 title='Delete Detection'> <img style='cursor:pointer' onclick='toggleLock(\"".$filename_formatted."\",\"".$type."\", this)' class=\"copyimage\" width=25 title=\"".$title."\" src=\"".$imageicon."\">$date $time<br>$confidence<br>
<video onplay='setLiveStreamVolume(0)' onended='setLiveStreamVolume(1)' onpause='setLiveStreamVolume(1)' controls poster=\"$filename.png\" preload=\"none\" title=\"$filename\"><source src=\"$filename\"></video></td>
</tr>";
} else {
echo "<tr>
<td class=\"relative\">$date $time<br>$confidence<img style='cursor:pointer' src='images/delete.svg' onclick='deleteDetection(\"".$filename_formatted."\", true)' class=\"copyimage\" width=25 title='Delete Detection'><br>
<video onplay='setLiveStreamVolume(0)' onended='setLiveStreamVolume(1)' onpause='setLiveStreamVolume(1)' controls poster=\"$filename.png\" preload=\"none\" title=\"$filename\"><source src=\"$filename\"></video></td>
</tr>";
}
}echo "</table>";}?>
</div> </div>
</html> </html>