Merge pull request #313 from virtualtam/install/timezone
Installation: default to the server's timezone
This commit is contained in:
commit
b282fffa23
3 changed files with 38 additions and 35 deletions
|
@ -5,30 +5,33 @@
|
||||||
* Note: 'UTC/UTC' is mapped to 'UTC' to form a valid option
|
* Note: 'UTC/UTC' is mapped to 'UTC' to form a valid option
|
||||||
*
|
*
|
||||||
* Example: preselect Europe/Paris
|
* Example: preselect Europe/Paris
|
||||||
* list($htmlform, $js) = templateTZform('Europe/Paris');
|
* list($htmlform, $js) = generateTimeZoneForm('Europe/Paris');
|
||||||
*
|
*
|
||||||
* @param string $preselected_timezone preselected timezone (optional)
|
* @param string $preselected_timezone preselected timezone (optional)
|
||||||
*
|
*
|
||||||
* @return an array containing the generated HTML form and Javascript code
|
* @return an array containing the generated HTML form and Javascript code
|
||||||
**/
|
**/
|
||||||
function generateTimeZoneForm($preselected_timezone='')
|
function generateTimeZoneForm($preselectedTimezone='')
|
||||||
{
|
{
|
||||||
// Select the first available timezone if no preselected value is passed
|
// Select the server timezone
|
||||||
if ($preselected_timezone == '') {
|
if ($preselectedTimezone == '') {
|
||||||
$l = timezone_identifiers_list();
|
$preselectedTimezone = date_default_timezone_get();
|
||||||
$preselected_timezone = $l[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($preselectedTimezone == 'UTC') {
|
||||||
|
$pcity = $pcontinent = 'UTC';
|
||||||
|
} else {
|
||||||
// Try to split the provided timezone
|
// Try to split the provided timezone
|
||||||
$spos = strpos($preselected_timezone, '/');
|
$spos = strpos($preselectedTimezone, '/');
|
||||||
$pcontinent = substr($preselected_timezone, 0, $spos);
|
$pcontinent = substr($preselectedTimezone, 0, $spos);
|
||||||
$pcity = substr($preselected_timezone, $spos+1);
|
$pcity = substr($preselectedTimezone, $spos+1);
|
||||||
|
}
|
||||||
|
|
||||||
// Display config form:
|
// Display config form:
|
||||||
$timezone_form = '';
|
$timezoneForm = '';
|
||||||
$timezone_js = '';
|
$timezoneJs = '';
|
||||||
|
|
||||||
// The list is in the form 'Europe/Paris', 'America/Argentina/Buenos_Aires'...
|
// The list is in the form 'Europe/Paris', 'America/Argentina/Buenos_Aires'
|
||||||
// We split the list in continents/cities.
|
// We split the list in continents/cities.
|
||||||
$continents = array();
|
$continents = array();
|
||||||
$cities = array();
|
$cities = array();
|
||||||
|
@ -57,33 +60,33 @@ function generateTimeZoneForm($preselected_timezone='')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$continents_html = '';
|
$continentsHtml = '';
|
||||||
$continents = array_keys($continents);
|
$continents = array_keys($continents);
|
||||||
|
|
||||||
foreach ($continents as $continent) {
|
foreach ($continents as $continent) {
|
||||||
$continents_html .= '<option value="'.$continent.'"';
|
$continentsHtml .= '<option value="'.$continent.'"';
|
||||||
if ($pcontinent == $continent) {
|
if ($pcontinent == $continent) {
|
||||||
$continents_html .= ' selected="selected"';
|
$continentsHtml .= ' selected="selected"';
|
||||||
}
|
}
|
||||||
$continents_html .= '>'.$continent.'</option>';
|
$continentsHtml .= '>'.$continent.'</option>';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Timezone selection form
|
// Timezone selection form
|
||||||
$timezone_form = 'Continent:';
|
$timezoneForm = 'Continent:';
|
||||||
$timezone_form .= '<select name="continent" id="continent" onChange="onChangecontinent();">';
|
$timezoneForm .= '<select name="continent" id="continent" onChange="onChangecontinent();">';
|
||||||
$timezone_form .= $continents_html.'</select>';
|
$timezoneForm .= $continentsHtml.'</select>';
|
||||||
$timezone_form .= ' City:';
|
$timezoneForm .= ' City:';
|
||||||
$timezone_form .= '<select name="city" id="city">'.$cities[$pcontinent].'</select><br />';
|
$timezoneForm .= '<select name="city" id="city">'.$cities[$pcontinent].'</select><br />';
|
||||||
|
|
||||||
// Javascript handler - updates the city list when the user selects a continent
|
// Javascript handler - updates the city list when the user selects a continent
|
||||||
$timezone_js = '<script>';
|
$timezoneJs = '<script>';
|
||||||
$timezone_js .= 'function onChangecontinent() {';
|
$timezoneJs .= 'function onChangecontinent() {';
|
||||||
$timezone_js .= 'document.getElementById("city").innerHTML =';
|
$timezoneJs .= 'document.getElementById("city").innerHTML =';
|
||||||
$timezone_js .= ' citiescontinent[document.getElementById("continent").value]; }';
|
$timezoneJs .= ' citiescontinent[document.getElementById("continent").value]; }';
|
||||||
$timezone_js .= 'var citiescontinent = '.json_encode($cities).';';
|
$timezoneJs .= 'var citiescontinent = '.json_encode($cities).';';
|
||||||
$timezone_js .= '</script>';
|
$timezoneJs .= '</script>';
|
||||||
|
|
||||||
return array($timezone_form, $timezone_js);
|
return array($timezoneForm, $timezoneJs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -107,4 +110,3 @@ function isTimeZoneValid($continent, $city)
|
||||||
timezone_identifiers_list()
|
timezone_identifiers_list()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
?>
|
|
||||||
|
|
10
index.php
10
index.php
|
@ -5,10 +5,12 @@
|
||||||
// Licence: http://www.opensource.org/licenses/zlib-license.php
|
// Licence: http://www.opensource.org/licenses/zlib-license.php
|
||||||
// Requires: PHP 5.3.x
|
// Requires: PHP 5.3.x
|
||||||
// -----------------------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------------------
|
||||||
// NEVER TRUST IN PHP.INI
|
|
||||||
// Some hosts do not define a default timezone in php.ini,
|
// Set 'UTC' as the default timezone if it is not defined in php.ini
|
||||||
// so we have to do this for avoid the strict standard error.
|
// See http://php.net/manual/en/datetime.configuration.php#ini.date.timezone
|
||||||
date_default_timezone_set('UTC');
|
if (date_default_timezone_get() == '') {
|
||||||
|
date_default_timezone_set('UTC');
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------------------
|
||||||
// Hardcoded parameter (These parameters can be overwritten by editing the file /data/config.php)
|
// Hardcoded parameter (These parameters can be overwritten by editing the file /data/config.php)
|
||||||
|
|
|
@ -80,4 +80,3 @@ public function testInvalidTimeZone()
|
||||||
$this->assertFalse(isTimeZoneValid('Middle_Earth', 'Moria'));
|
$this->assertFalse(isTimeZoneValid('Middle_Earth', 'Moria'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
|
||||||
|
|
Loading…
Reference in a new issue