From 624bcdcde0a5d827362567d0af63d7c541c7e7d6 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 24 Sep 2020 09:01:30 -0400 Subject: [PATCH] Add Latitude and Longitude to Monitors and monitor edit as well as using the geolocation api to auto-populate them --- db/zm_create.sql.in | 2 ++ db/zm_update-1.31.30.sql | 20 ++++++++++++++++++++ db/zm_update-1.35.7.sql | 23 +++++++++++++++++++++++ web/includes/Monitor.php | 2 ++ web/skins/classic/views/js/monitor.js | 14 ++++++++++++++ web/skins/classic/views/monitor.php | 20 ++++++++++++++++++++ 6 files changed, 81 insertions(+) create mode 100644 db/zm_update-1.31.30.sql create mode 100644 db/zm_update-1.35.7.sql diff --git a/db/zm_create.sql.in b/db/zm_create.sql.in index af6a17182..cd4622df1 100644 --- a/db/zm_create.sql.in +++ b/db/zm_create.sql.in @@ -536,6 +536,8 @@ CREATE TABLE `Monitors` ( `ArchivedEventDiskSpace` bigint default NULL, `ZoneCount` TINYINT NOT NULL DEFAULT 0, `Refresh` int(10) unsigned default NULL, + `Latitude` DECIMAL(10,8), + `Longitude` DECIMAL(10,8), PRIMARY KEY (`Id`) ) ENGINE=@ZM_MYSQL_ENGINE@; diff --git a/db/zm_update-1.31.30.sql b/db/zm_update-1.31.30.sql new file mode 100644 index 000000000..c87b4409a --- /dev/null +++ b/db/zm_update-1.31.30.sql @@ -0,0 +1,20 @@ +DROP TABLE IF EXISTS `Monitor_Status`; +CREATE TABLE `Monitor_Status` ( + `MonitorId` int(10) unsigned NOT NULL, + `Status` enum('Unknown','NotRunning','Running','Connected','Signal') NOT NULL default 'Unknown', + `CaptureFPS` DECIMAL(10,2) NOT NULL default 0, + `AnalysisFPS` DECIMAL(5,2) NOT NULL default 0, + PRIMARY KEY (`MonitorId`) +) ENGINE=MEMORY; + +SET SESSION sql_mode='NO_AUTO_VALUE_ON_ZERO'; + +SET @s = (SELECT IF( + (SELECT COUNT(*) FROM Storage WHERE Name = 'Default' AND Id=0 AND Path='/var/cache/zoneminder/events' + ) > 0, + "SELECT 'Default Storage Area already exists.'", + "INSERT INTO Storage (Id,Name,Path,Scheme,ServerId) VALUES (0,'Default','/var/cache/zoneminder/events','Medium',NULL)" + )); + +PREPARE stmt FROM @s; +EXECUTE stmt; diff --git a/db/zm_update-1.35.7.sql b/db/zm_update-1.35.7.sql new file mode 100644 index 000000000..84c3dbb1e --- /dev/null +++ b/db/zm_update-1.35.7.sql @@ -0,0 +1,23 @@ +SET @s = (SELECT IF( + (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = DATABASE() + AND table_name = 'Monitors' + AND column_name = 'Latitude' + ) > 0, +"SELECT 'Column Latitude already exists in Monitors'", +"ALTER TABLE `Monitors` ADD `Latitude` DECIMAL(10,8) AFTER `Refresh`" +)); + +PREPARE stmt FROM @s; +EXECUTE stmt; + +SET @s = (SELECT IF( + (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = DATABASE() + AND table_name = 'Monitors' + AND column_name = 'Longitude' + ) > 0, +"SELECT 'Column Longitude already exists in Monitors'", +"ALTER TABLE `Monitors` ADD `Longitude` DECIMAL(10,8) AFTER `Latitude`" +)); + +PREPARE stmt FROM @s; +EXECUTE stmt; diff --git a/web/includes/Monitor.php b/web/includes/Monitor.php index 65d1fc3ed..d1bd51509 100644 --- a/web/includes/Monitor.php +++ b/web/includes/Monitor.php @@ -129,6 +129,8 @@ class Monitor extends ZM_Object { 'Refresh' => null, 'DefaultCodec' => 'auto', 'GroupIds' => array('default'=>array(), 'do_not_update'=>1), + 'Latitude' => null, + 'Longitude' => null, ); private $status_fields = array( 'Status' => null, diff --git a/web/skins/classic/views/js/monitor.js b/web/skins/classic/views/js/monitor.js index 0bedf5303..20020dc35 100644 --- a/web/skins/classic/views/js/monitor.js +++ b/web/skins/classic/views/js/monitor.js @@ -241,5 +241,19 @@ function update_estimated_ram_use() { document.getElementById('estimated_ram_use').innerHTML = human_filesize(buffer_count * width * height * colours, 0); } +function updateLatitudeAndLongitude(latitude,longitude) { + var form = document.getElementById('contentForm'); + form.elements['newMonitor[Latitude]'].value = latitude; + form.elements['newMonitor[Longitude]'].value = longitude; +} +function getLocation() { + if('geolocation' in navigator) { + navigator.geolocation.getCurrentPosition((position) => { + updateLatitudeAndLongitude(position.coords.latitude, position.coords.longitude); + }); + } else { + console.log("Geolocation not available"); + } +} window.addEventListener('DOMContentLoaded', initPage); diff --git a/web/skins/classic/views/monitor.php b/web/skins/classic/views/monitor.php index e48d12277..1d4e2d713 100644 --- a/web/skins/classic/views/monitor.php +++ b/web/skins/classic/views/monitor.php @@ -404,6 +404,7 @@ if ( $monitor->Type() != 'WebSite' ) { if ( ZM_OPT_X10 ) $tabs['x10'] = translate('X10'); $tabs['misc'] = translate('Misc'); + $tabs['location'] = translate('Location'); } if ( isset($_REQUEST['tab']) ) @@ -1151,6 +1152,25 @@ echo htmlSelect('newMonitor[ReturnLocation]', $return_options, $monitor->ReturnL + + + + + + + + + + + + + +