Merge pull request #2714 from connortechnology/timezone_as_config

Add setting of timezone to Options/Config instead of php.ini
This commit is contained in:
Isaac Connor 2019-10-18 14:01:03 -04:00 committed by GitHub
commit a8a0c629a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 56 additions and 6 deletions

View File

@ -162,6 +162,12 @@ our %types = (
pattern => qr|^([a-zA-Z0-9_.-]+)\@([a-zA-Z0-9_.-]+)$|, pattern => qr|^([a-zA-Z0-9_.-]+)\@([a-zA-Z0-9_.-]+)$|,
format => q( $1\@$2 ) format => q( $1\@$2 )
}, },
timezone => {
db_type => 'string',
hint => 'America/Toronto',
pattern => qr|^(.+)$|,
format => q($1)
}
); );
our @options = ( our @options = (
@ -777,6 +783,15 @@ our @options = (
type => $types{string}, type => $types{string},
category => 'config', category => 'config',
}, },
{
name => 'ZM_TIMEZONE',
default => 'UTC',
description => 'The timezone that php should use.',
help => q`
This should be set equal to the system timezone of the mysql server`,
type => $types{timezone},
category => 'system',
},
{ {
name => 'ZM_CPU_EXTENSIONS', name => 'ZM_CPU_EXTENSIONS',
default => 'yes', default => 'yes',

View File

@ -2367,7 +2367,7 @@ function check_timezone() {
#"); #");
if ( $sys_tzoffset != $php_tzoffset ) if ( $sys_tzoffset != $php_tzoffset )
ZM\Error("ZoneMinder is not installed properly: php's date.timezone does not match the system timezone!"); ZM\Error("ZoneMinder is not installed properly: php's date.timezone $php_tzoffset does not match the system timezone $sys_tzoffset!");
if ( $sys_tzoffset != $mysql_tzoffset ) if ( $sys_tzoffset != $mysql_tzoffset )
ZM\Error("ZoneMinder is not installed properly: mysql's timezone does not match the system timezone! Event lists will display incorrect times."); ZM\Error("ZoneMinder is not installed properly: mysql's timezone does not match the system timezone! Event lists will display incorrect times.");

View File

@ -202,6 +202,7 @@ isset($action) || $action = NULL;
if ( (!$view and !$request) or ($view == 'console') ) { if ( (!$view and !$request) or ($view == 'console') ) {
// Verify the system, php, and mysql timezones all match // Verify the system, php, and mysql timezones all match
date_default_timezone_set(ZM_TIMEZONE);
check_timezone(); check_timezone();
} }

View File

@ -389,6 +389,40 @@ foreach ( array_map('basename', glob('skins/'.$skin.'/css/*',GLOB_ONLYDIR)) as $
$configCats[$tab]['ZM_SKIN_DEFAULT']['Hint'] = join('|', array_map('basename', glob('skins/*',GLOB_ONLYDIR))); $configCats[$tab]['ZM_SKIN_DEFAULT']['Hint'] = join('|', array_map('basename', glob('skins/*',GLOB_ONLYDIR)));
$configCats[$tab]['ZM_CSS_DEFAULT']['Hint'] = join('|', array_map ( 'basename', glob('skins/'.ZM_SKIN_DEFAULT.'/css/*',GLOB_ONLYDIR) )); $configCats[$tab]['ZM_CSS_DEFAULT']['Hint'] = join('|', array_map ( 'basename', glob('skins/'.ZM_SKIN_DEFAULT.'/css/*',GLOB_ONLYDIR) ));
$configCats[$tab]['ZM_BANDWIDTH_DEFAULT']['Hint'] = $bandwidth_options; $configCats[$tab]['ZM_BANDWIDTH_DEFAULT']['Hint'] = $bandwidth_options;
function timezone_list() {
static $timezones = null;
if ($timezones === null) {
$timezones = [];
$offsets = [];
$now = new DateTime('now', new DateTimeZone('UTC'));
foreach (DateTimeZone::listIdentifiers() as $timezone) {
$now->setTimezone(new DateTimeZone($timezone));
$offsets[] = $offset = $now->getOffset();
$timezones[$timezone] = '(' . format_GMT_offset($offset) . ') ' . format_timezone_name($timezone);
}
array_multisort($offsets, $timezones);
}
return $timezones;
}
function format_GMT_offset($offset) {
$hours = intval($offset / 3600);
$minutes = abs(intval($offset % 3600 / 60));
return 'GMT' . ($offset ? sprintf('%+03d:%02d', $hours, $minutes) : '');
}
function format_timezone_name($name) {
$name = str_replace('/', ', ', $name);
$name = str_replace('_', ' ', $name);
$name = str_replace('St ', 'St. ', $name);
return $name;
}
$configCats[$tab]['ZM_TIMEZONE']['Hint'] = timezone_list();
} }
?> ?>
<form name="optionsForm" class="form-horizontal" method="post" action="?"> <form name="optionsForm" class="form-horizontal" method="post" action="?">
@ -409,7 +443,7 @@ foreach ( array_map('basename', glob('skins/'.$skin.'/css/*',GLOB_ONLYDIR)) as $
?> ?>
<input type="checkbox" id="<?php echo $name ?>" name="newConfig[<?php echo $name ?>]" value="1"<?php if ( $value['Value'] ) { ?> checked="checked"<?php } ?><?php echo $canEdit?'':' disabled="disabled"' ?>/> <input type="checkbox" id="<?php echo $name ?>" name="newConfig[<?php echo $name ?>]" value="1"<?php if ( $value['Value'] ) { ?> checked="checked"<?php } ?><?php echo $canEdit?'':' disabled="disabled"' ?>/>
<?php <?php
} elseif ( is_array( $value['Hint'] ) ) { } elseif ( is_array($value['Hint']) ) {
echo htmlSelect("newConfig[$name]", $value['Hint'], $value['Value']); echo htmlSelect("newConfig[$name]", $value['Hint'], $value['Value']);
} elseif ( preg_match('/\|/', $value['Hint']) ) { } elseif ( preg_match('/\|/', $value['Hint']) ) {
?> ?>