A live bird collage card for your Home Assistant dashboard.
stats.php: cleanup html
frederik3a3e2704496e
diff --git a/scripts/stats.php b/scripts/stats.phpindex 84ae9f7d..f4c74a5b 100644--- a/scripts/stats.php+++ b/scripts/stats.php@@ -46,24 +46,23 @@ if(!file_exists($home."/BirdNET-Pi/scripts/disk_check_exclude.txt") || strpos(fifile_put_contents($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", "");file_put_contents($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", "##start\n##end\n");}-?>+if (get_included_files()[0] === __FILE__) {+ echo '<!DOCTYPE html><html lang="en">-<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>BirdNET-Pi DB</title>-<style>-</style>+</head>';+}+?>-</head>-<body><div class="stats"><div class="column"><div style="width: auto;text-align: center">- <form action="" method="GET">+ <form action="views.php" method="GET"><input type="hidden" name="sort" value="<?php if(isset($_GET['sort'])){echo $_GET['sort'];}?>"><input type="hidden" name="view" value="Species Stats"><button <?php if(!isset($_GET['sort']) || $_GET['sort'] == "alphabetical"){ echo "style='background:#9fe29b !important;'"; }?> class="sortbutton" type="submit" name="sort" value="alphabetical">@@ -74,7 +73,11 @@ if(!file_exists($home."/BirdNET-Pi/scripts/disk_check_exclude.txt") || strpos(fi</button></form></div>-<table style="padding-top:10px">+<br>+<form action="views.php" method="GET">+<input type="hidden" name="sort" value="<?php if(isset($_GET['sort'])){echo $_GET['sort'];}?>">+<input type="hidden" name="view" value="Species Stats">+<table><?php$birds = array();while($results=$result2->fetchArray(SQLITE3_ASSOC))@@ -101,11 +104,7 @@ if(!file_exists($home."/BirdNET-Pi/scripts/disk_check_exclude.txt") || strpos(fiif ($index < count($birds)) {?><td>- <form action="" method="GET">- <input type="hidden" name="sort" value="<?php if(isset($_GET['sort'])){echo $_GET['sort'];}?>">- <input type="hidden" name="view" value="Species Stats"><button type="submit" name="species" value="<?php echo $birds[$index];?>"><?php echo $birds[$index];?></button>- </form></td><?php} else {@@ -117,16 +116,7 @@ if(!file_exists($home."/BirdNET-Pi/scripts/disk_check_exclude.txt") || strpos(fi}?></table>-<style>-td {- padding: 0px;- width: calc(100% / <?php echo $num_cols;?>);-}-tr:first-child td {- padding-top: 10px;-}-</style>-+</form></div><dialog style="margin-top: 5px;max-height: 95vh;overflow-y: auto;overscroll-behavior:contain" id="attribution-dialog">@@ -225,7 +215,9 @@ while($results=$result3->fetchArray(SQLITE3_ASSOC)){<?php } else {?><hr><br><?php } ?>-+ <form action="views.php" method="GET">+ <input type="hidden" name="sort" value="<?php if(isset($_GET['sort'])){echo $_GET['sort'];}?>">+ <input type="hidden" name="view" value="Species Stats"><table><?php$excludelines = [];@@ -239,9 +231,7 @@ array_push($excludelines, $results['Date']."/".$comname."/".$results['File_Name'array_push($excludelines, $results['Date']."/".$comname."/".$results['File_Name'].".png");?><tr>- <form action="" method="GET">- <input type="hidden" name="sort" value="<?php if(isset($_GET['sort'])){echo $_GET['sort'];}?>">- <td class="relative"><a target="_blank" href="index.php?filename=<?php echo $results['File_Name']; ?>"><img title="Open in new tab" class="copyimage" width=25 src="images/copy.png"></a><input type="hidden" name="view" value="Species Stats">+ <td class="relative"><a target="_blank" href="index.php?filename=<?php echo $results['File_Name']; ?>"><img title="Open in new tab" class="copyimage" width=25 src="images/copy.png"></a><button type="submit" name="species" value="<?php echo $results['Com_Name'];?>"><?php echo $results['Com_Name'];?></button><br><b>Occurrences:</b> <?php echo $results['COUNT(*)'];?><br><b>Max Confidence:</b> <?php echo $percent = round((float)round($results['MAX(Confidence)'],2) * 100 ) . '%';?><br><b>Best Recording:</b> <?php echo $results['Date']." ".$results['Time'];?><br><video onplay='setLiveStreamVolume(0)' onended='setLiveStreamVolume(1)' onpause='setLiveStreamVolume(1)' controls poster="<?php echo $filename.".png";?>" preload="none" title="<?php echo $filename;?>"><source src="<?php echo $filename;?>" type="audio/mp3"></video></td>@@ -253,8 +243,10 @@ $file = file_get_contents($home."/BirdNET-Pi/scripts/disk_check_exclude.txt");file_put_contents($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", "##start"."\n".implode("\n",$excludelines)."\n".substr($file, strpos($file, "##end")));?></table>- </form>+ </form></div></div>-</body>-</html>+<?php+if (get_included_files()[0] === __FILE__) {+ echo '</body></html>';+}