A live bird collage card for your Home Assistant dashboard.
Update history.php
ehpersonal3815db1c466418
diff --git a/scripts/history.php b/scripts/history.phpindex 09afbd92..3e48ab4d 100644--- a/scripts/history.php+++ b/scripts/history.php@@ -1,6 +1,13 @@<?php-error_reporting(E_ERROR);+error_reporting(E_ALL);ini_set('display_errors',1);+ini_set('display_startup_errors',1);++if (file_exists('./scripts/thisrun.txt')) {+ $config = parse_ini_file('./scripts/thisrun.txt');+} elseif (file_exists('./scripts/firstrun.ini')) {+ $config = parse_ini_file('./scripts/firstrun.ini');+}if(isset($_GET['date'])){$theDate = $_GET['date'];@@ -17,15 +24,124 @@ $statement1 = $db->prepare("SELECT COUNT(*) FROM detections$result1 = $statement1->execute();$totalcount = $result1->fetchArray(SQLITE3_ASSOC);+if(isset($_GET['blocation']) ) {++ header("Content-type: text/csv");+ header("Content-Disposition: attachment; filename=result_file.csv");+ header("Pragma: no-cache");+ header("Expires: 0");+++ $user = trim(shell_exec("awk -F: '/1000/{print $1}' /etc/passwd"));+ $home = trim(shell_exec("awk -F: '/1000/{print $6}' /etc/passwd"));++ $list = array (+ array('', '', $_GET['blocation']),+ array('Latitude', '', $config["LATITUDE"]),+ array('Longitude', '', $config["LONGITUDE"]),+ array('Date', '', date("m/d/Y", strtotime($theDate))),+ array('Start Time', '', '0:00'),+ array('State', '', $_GET['state']),+ array('Country', '', $_GET['country']),+ array('Protocol', '', $_GET['protocol']),+ array('Num Observers', '', $_GET['num_observers']),+ array('Duration (min)', '', '1440'),+ array('All Obs Reported (Y/N)', '', 'Y'),+ array('Dist Traveled (Miles)', '', $_GET['dist_traveled']),+ array('Area Covered (Acres)', '', ''),+ array('Notes', '', $_GET['notes'])+ );+++ $statement1 = $db->prepare("SELECT DISTINCT(Com_Name), COUNT(*) FROM detections WHERE Date == \"$theDate\" GROUP By Com_Name ORDER BY COUNT(*) DESC");+ if($statement1 == False){+ echo "Database is busy";+ header("refresh: 0;");+ }+ $result1 = $statement1->execute();++ $detections = [];+ while($detection=$result1->fetchArray(SQLITE3_ASSOC))+ {+ $detections[$detection["Com_Name"]] = $detection["COUNT(*)"];+ }+ foreach($detections as $com_name=>$scount)+ {+ array_push($list, array($com_name,'',$scount));+ }++ $output = fopen("php://output", "w");+ foreach ($list as $row) {+ fputcsv($output, $row);+ }+ fclose($output);++ die();+}+?><head><style>+#attribution-dialog p {+ display:inline;+}+#attribution-dialog {+ text-align: left;+}</style></head><body><div class="history centered">++<dialog id="attribution-dialog">+ <p style="display:none" id="filename"></p>+ <h1 id="modalHeading">Enter Checklist Information</h1>+ <p id="modalText">Location Name:</p> <input placeholder="My house" id="blocation"><br><br>+ <p id="modalText">State (2 letter code):</p> <input maxlength="3" id="state"><br><br>+ <p id="modalText">Country (2 letter code):</p> <input maxlength="2" id="country"><br><br>+ <p id="modalText">Protocol:</p> <select id="protocol">+ <option value="casual">casual</option>+ <option value="stationary">stationary</option>+ <option value="traveling">traveling</option>+ <option value="area">area</option>+</select>+<br><br>+ <p id="modalText">Number of observers:</p> <input type="number" id="num_observers"><br><br>+ <p id="modalText">Distance traveled (miles):</p> <input type="number" id="dist_traveled"><br><br>+ <p id="modalText">Notes:</p> <input id="notes"><br><br>+ <button onclick="submitID()">Submit</button>+</dialog>+<script>+var dialog = document.querySelector('dialog');+dialogPolyfill.registerDialog(dialog);++function showDialog() {+ document.getElementById('attribution-dialog').showModal();+}++function closeDialog() {+ document.getElementById('attribution-dialog').close();+}++function submitID() {+ blocation = document.getElementById("blocation").value;+ state = document.getElementById("state").value;+ country = document.getElementById("country").value;+ protocol = document.getElementById("protocol").value;+ num_observers = document.getElementById("num_observers").value;+ dist_traveled = document.getElementById("dist_traveled").value;+ notes = document.getElementById("notes").value;++ window.open("history.php?blocation="+blocation+"&state="+state+"&country="+country+"&protocol="+protocol+"&num_observers="+num_observers+"&dist_traveled="+dist_traveled+"¬es="+notes+"&date="+"<?php echo $theDate; ?>");++ document.getElementById('attribution-dialog').innerHTML = "<h3>Success!</h3><p>Your checklist will start downloading momentarily.<br><br>Refer to <a target='_blank' href='https://ebird.org/content/eBirdCommon/docs/ebird_import_data_process.pdf'>this guide</a> for information on how to import it in eBird. The checklist file format is: 'eBird Checklist Format'.</p><br><br><button onclick=\"closeDialog()\">Close</button>";++}++</script>+<form action="" method="GET"><input type="date" name="date" value="<?php echo $theDate;?>"><button type="submit" name="view" value="Daily Charts">Submit Date</button>@@ -36,7 +152,7 @@ $totalcount = $result1->fetchArray(SQLITE3_ASSOC);<td><?php echo $totalcount['COUNT(*)'];?></td></tr></table>- <br><br>+ <br> <button type="button" onclick="showDialog()">Export as CSV for eBird</button><br><br><?phpif (file_exists('./Charts/'.$chart)) {echo "<img src=\"/Charts/$chart?nocache=time()\" >";