Fix: Saving daylight detection

This commit is contained in:
Laurent Destailleur 2011-12-12 01:58:11 +01:00
parent e8c266bc9e
commit 1934acf10c

View File

@ -35,17 +35,120 @@ header("Content-type: text/html; charset=".$conf->file->character_set_client);
<title><?php echo $langs->trans('Login'); ?></title>
<script type="text/javascript" src="<?php echo DOL_URL_ROOT ?>/includes/jquery/js/jquery-latest.min.js"></script>
<link rel="stylesheet" type="text/css" href="<?php echo $conf_css; ?>" />
<?php echo $conf->global->MAIN_HTML_HEADER ?>
<?php
$favicon=DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/favicon.ico';
?>
<link rel="shortcut icon" type="image/x-icon" href="<?php echo $favicon; ?>" />
<link rel="shortcut icon" type="image/x-icon" href="<?php echo DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/favicon.ico'; ?>" />
<?php if (! empty($conf->global->MAIN_HTML_HEADER)) print $conf->global->MAIN_HTML_HEADER; ?>
<!-- HTTP_USER_AGENT = <?php echo $_SERVER['HTTP_USER_AGENT']; ?> -->
</head>
<body class="body">
<!-- Javascript code on logon page only to detect user tz, dst_observed, dst_first, dst_second -->
<script type="text/javascript">
function DisplayDstSwitchDates(firstsecond)
{
var year = new Date().getYear();
if (year < 1000) year += 1900;
var firstSwitch = 0;
var secondSwitch = 0;
var lastOffset = 99;
// Loop through every month of the current year
for (i = 0; i < 12; i++)
{
// Fetch the timezone value for the month
var newDate = new Date(Date.UTC(year, i, 0, 0, 0, 0, 0));
var tz = -1 * newDate.getTimezoneOffset() / 60;
// Capture when a timzezone change occurs
if (tz > lastOffset)
firstSwitch = i-1;
else if (tz < lastOffset)
secondSwitch = i-1;
lastOffset = tz;
}
// Go figure out date/time occurences a minute before
// a DST adjustment occurs
var secondDstDate = FindDstSwitchDate(year, secondSwitch);
var firstDstDate = FindDstSwitchDate(year, firstSwitch);
if (firstsecond == 'first') return firstDstDate;
if (firstsecond == 'second') return secondDstDate;
if (firstDstDate == null && secondDstDate == null)
return 'Daylight Savings is not observed in your timezone.';
else
return 'Last minute before DST change occurs in ' +
year + ': ' + firstDstDate + ' and ' + secondDstDate;
}
function FindDstSwitchDate(year, month)
{
// Set the starting date
var baseDate = new Date(Date.UTC(year, month, 0, 0, 0, 0, 0));
var changeDay = 0;
var changeMinute = -1;
var baseOffset = -1 * baseDate.getTimezoneOffset() / 60;
var dstDate;
// Loop to find the exact day a timezone adjust occurs
for (day = 0; day < 50; day++)
{
var tmpDate = new Date(Date.UTC(year, month, day, 0, 0, 0, 0));
var tmpOffset = -1 * tmpDate.getTimezoneOffset() / 60;
// Check if the timezone changed from one day to the next
if (tmpOffset != baseOffset)
{
var minutes = 0;
changeDay = day;
// Back-up one day and grap the offset
tmpDate = new Date(Date.UTC(year, month, day-1, 0, 0, 0, 0));
tmpOffset = -1 * tmpDate.getTimezoneOffset() / 60;
// Count the minutes until a timezone chnage occurs
while (changeMinute == -1)
{
tmpDate = new Date(Date.UTC(year, month, day-1, 0, minutes, 0, 0));
tmpOffset = -1 * tmpDate.getTimezoneOffset() / 60;
// Determine the exact minute a timezone change
// occurs
if (tmpOffset != baseOffset)
{
// Back-up a minute to get the date/time just
// before a timezone change occurs
tmpOffset = new Date(Date.UTC(year, month,
day-1, 0, minutes-1, 0, 0));
changeMinute = minutes;
break;
}
else
minutes++;
}
// Add a month (for display) since JavaScript counts
// months from 0 to 11
dstDate = tmpOffset.getMonth() + 1;
// Pad the month as needed
if (dstDate < 10) dstDate = "0" + dstDate;
// Add the day and year
dstDate = year + '-' + dstDate + '-' + tmpOffset.getDate() + 'T';
// Capture the time stamp
tmpDate = new Date(Date.UTC(year, month,
day-1, 0, minutes-1, 0, 0));
dstDate += tmpDate.toTimeString().split(' ')[0] + 'Z';
return dstDate;
}
}
}
jQuery(document).ready(function () {
// Set focus on correct field
<?php if ($focus_element) { ?>jQuery('#<?php echo $focus_element; ?>').focus(); <?php } ?> // Warning to use this only on visible element
@ -65,8 +168,13 @@ jQuery(document).ready(function () {
} else {
dst = "1"; // daylight savings time is observed
}
var dst_first=DisplayDstSwitchDates('first');
var dst_second=DisplayDstSwitchDates('second');
//alert(dst);
jQuery('#tz').val(std_time_offset); // returns TZ
jQuery('#dst').val(dst); // returns DST
jQuery('#dst_observed').val(dst); // returns if DST is observed on summer
jQuery('#dst_first').val(dst_first); // returns DST first switch in year
jQuery('#dst_second').val(dst_second); // returns DST second switch in year
// Detect and save screen resolution
jQuery('#screenwidth').val(jQuery(window).width()); // returns width of browser viewport
jQuery('#screenheight').val(jQuery(window).height()); // returns width of browser viewport
@ -78,7 +186,9 @@ jQuery(document).ready(function () {
<input type="hidden" name="loginfunction" value="loginfunction" />
<!-- Add fields to send local user information -->
<input type="hidden" name="tz" id="tz" value="" />
<input type="hidden" name="dst" id="dst" value="" />
<input type="hidden" name="dst_observed" id="dst_observed" value="" />
<input type="hidden" name="dst_first" id="dst_first" value="" />
<input type="hidden" name="dst_second" id="dst_second" value="" />
<input type="hidden" name="screenwidth" id="screenwidth" value="" />
<input type="hidden" name="screenheight" id="screenheight" value="" />