From 624bcdcde0a5d827362567d0af63d7c541c7e7d6 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 24 Sep 2020 09:01:30 -0400 Subject: [PATCH 1/8] 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 + + + + + + + + + + + + + + From aa875b019df968b47e0f4bbbcd131148c5cccbe4 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 24 Sep 2020 09:02:20 -0400 Subject: [PATCH 2/8] remove auto-generated update file that slipped in --- db/zm_update-1.31.30.sql | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 db/zm_update-1.31.30.sql diff --git a/db/zm_update-1.31.30.sql b/db/zm_update-1.31.30.sql deleted file mode 100644 index c87b4409a..000000000 --- a/db/zm_update-1.31.30.sql +++ /dev/null @@ -1,20 +0,0 @@ -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; From 9c7bbd4aa7a53b00829b789ae64f1ad3150d7894 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 24 Sep 2020 09:13:25 -0400 Subject: [PATCH 3/8] introduce output_script_if_exists, use it to link leaflet.js if it exists --- web/skins/classic/includes/functions.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/web/skins/classic/includes/functions.php b/web/skins/classic/includes/functions.php index 203d3ffc2..8da07b025 100644 --- a/web/skins/classic/includes/functions.php +++ b/web/skins/classic/includes/functions.php @@ -50,12 +50,24 @@ function xhtmlHeaders($file, $title) { $html[] = ''; // So we ge a trailing \n return implode(PHP_EOL, $html); } + function output_script_if_exists($files) { + global $skin; + $html = array(); + foreach ( $files as $file ) { + $html[] = ''; + } + $html[] = ''; // So we ge a trailing \n + return implode(PHP_EOL, $html); + } function output_cache_busted_stylesheet_links($files) { $html = array(); foreach ( $files as $file ) { $html[] = ''; } + if ( ! count($html) ) { + ZM\Warning("No files found for $files"); + } $html[] = ''; // So we ge a trailing \n return implode(PHP_EOL, $html); } @@ -109,6 +121,8 @@ if ( $css != 'base' ) echo output_link_if_exists(array('/css/base/views/control.css')); if ( $css != 'base' ) echo output_link_if_exists(array('/css/'.$css.'/views/control.css')); + } else if ( $basename == 'monitor' ) { + echo output_link_if_exists(array('/js/leaflet/leaflet.css')); } ?>