Skip to content

Commit

Permalink
Total revamp of timezone calculations.
Browse files Browse the repository at this point in the history
  • Loading branch information
umcesrjones committed Apr 6, 2006
1 parent 1e93bb6 commit 7630506
Show file tree
Hide file tree
Showing 71 changed files with 2,674 additions and 13,761 deletions.
37 changes: 16 additions & 21 deletions admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ function save_pref( $prefs, $src) {
$GLOBALS['FONTS'] = $s['FONTS'];
$GLOBALS['MYEVENTS'] = $s['MYEVENTS'];

//determine if we can set timezones, if not don't display any options
$can_set_timezone = set_env ( "TZ", $s['SERVER_TIMEZONE'] );


$BodyX = 'onload="public_handler(); eu_handler(); sr_handler(); attach_handler(); comment_handler(); email_handler();';
$BodyX .= ( ! empty ( $currenttab ) ? "showTab( '". $currenttab . "' );\"" : '"' );
$INC = array('js/admin.php','js/visible.php');
Expand Down Expand Up @@ -199,6 +203,17 @@ function save_pref( $prefs, $src) {
<?php echo translate("Your browser default language is") . " " .
get_browser_language ( true ) . "."; ?>
</td></tr>
<?php if ( $can_set_timezone == true ) { ?>
<tr><td class="tooltipselect" title="<?php etooltip("tz-help")?>">
<label for="admin_SERVER_TIMEZONE"><?php etranslate("Server Timezone Selection")?>:</label></td><td>
<?php
$tz_offset = date("Z") /ONE_HOUR;
echo print_timezone_select_html ( "admin_", $s['SERVER_TIMEZONE']);
echo translate("Your current GMT offset is") . "&nbsp;" .
$tz_offset . "&nbsp;" .translate("hours") . ".";
?>
</td></tr>
<?php } // end $can_set_timezone ?>
<tr><td><label>
<?php etranslate("Allow user to use themes")?>:</label></td><td colspan="3">
<label><input type="radio" name="admin_ALLOW_USER_THEMES" value='Y'<?php if ( $s['ALLOW_USER_THEMES'] != 'N' ) echo " checked=\"checked\"";?> />&nbsp;<?php etranslate('Yes')?></label>&nbsp;
Expand Down Expand Up @@ -329,20 +344,6 @@ function save_pref( $prefs, $src) {
<label><input type="radio" name="admin_DISPLAY_DESC_PRINT_DAY" value='Y' <?php if ( $s['DISPLAY_DESC_PRINT_DAY'] == 'Y' ) echo " checked=\"checked\"";?> />&nbsp;<?php etranslate('Yes')?></label>&nbsp;
<label><input type="radio" name="admin_DISPLAY_DESC_PRINT_DAY" value='N' <?php if ( $s['DISPLAY_DESC_PRINT_DAY'] != 'Y' ) echo " checked=\"checked\"";?> />&nbsp;<?php etranslate('No')?></label>
</td></tr>
<tr><td class="tooltip" title="<?php etooltip("display-alltimezones-help");?>">
<?php etranslate("Display complete timezone list")?>:</td><td>
<label><input type="radio" name="admin_TZ_COMPLETE_LIST" value='Y' <?php if ( $s['TZ_COMPLETE_LIST'] != 'N' ) echo " checked=\"checked\"";?> />&nbsp;<?php etranslate('Yes')?></label>&nbsp;
<label><input type="radio" name="admin_TZ_COMPLETE_LIST" value='N' <?php if ( $s['TZ_COMPLETE_LIST'] == 'N' ) echo " checked=\"checked\"";?> />&nbsp;<?php etranslate('No')?></label>&nbsp;&nbsp;<?php echo "(" . translate("Requires page reload") . ")"; ?>
</td></tr>
<tr><td class="tooltipselect" title="<?php etooltip("tz-help")?>">
<label for="admin_SERVER_TIMEZONE"><?php etranslate("Server Timezone Selection")?>:</label></td><td>
<?php
$tz_offset = get_tz_offset ( $s['SERVER_TIMEZONE'], time() );
echo print_timezone_select_html ( "admin_", $s['SERVER_TIMEZONE']);
echo translate("Your current GMT offset is") . " " . $tz_offset[0] . " " . translate("hours") . ".";
?>&nbsp;&nbsp;
<input type="button" value="<?php etranslate("Load Timezone Data");?>" onclick="window.open('load_tz_data.php','_blank','dependent,height=200,width=400,outerHeight=220,outerWidth=420');" name="" />
</td></tr>
<tr><td class="tooltip" title="<?php etooltip("display-general-use-gmt-help");?>">
<?php etranslate("Display Common Use Date/Times as GMT")?>:</td><td>
<label><input type="radio" name="admin_GENERAL_USE_GMT" value='Y' <?php if ( $s['GENERAL_USE_GMT'] == 'Y' ) echo " checked=\"checked\"";?> />&nbsp;<?php etranslate('Yes')?></label>&nbsp;
Expand Down Expand Up @@ -729,12 +730,6 @@ function save_pref( $prefs, $src) {
<label><input type="radio" name="admin_DISPLAY_TASKS_IN_GRID" value='N' <?php if ( $s['DISPLAY_TASKS_IN_GRID'] != 'Y' ) echo " checked=\"checked\"";?> />&nbsp;<?php etranslate('No')?></label>
</td></tr>

<!-- BEGIN USE TIMEZONES IN ICS-->
<tr><td class="tooltip" title="<?php etooltip("export-ics-timezones-help")?>">
<?php etranslate("Export VTIMEZONE in ics files" )?>:</td><td>
<label><input type="radio" name="admin_ICS_TIMEZONES" value='Y' <?php if ( $s['ICS_TIMEZONES'] == 'Y' ) echo " checked=\"checked\"";?> />&nbsp;<?php etranslate('Yes')?></label>&nbsp;
<label><input type="radio" name="admin_ICS_TIMEZONES" value='N' <?php if ( $s['ICS_TIMEZONES'] != 'Y' ) echo " checked=\"checked\"";?> />&nbsp;<?php etranslate('No')?></label>
</td></tr>
<!-- BEGIN EXT PARTICIPANTS -->

<tr><td class="tooltip" title="<?php etooltip("allow-external-users-help")?>">
Expand Down Expand Up @@ -918,7 +913,7 @@ function save_pref( $prefs, $src) {
<!-- BEGIN EXAMPLE MONTH -->
<table style="border:0px; width:100%;"><tr>
<td style="text-align:center; color:<?php echo $H2COLOR?>; font-weight:bold;"><?php
echo date_to_str ( date ("Ymd"), $DATE_FORMAT_MY, false, false );?></td></tr>
echo date_to_str ( date ("Ymd"), $DATE_FORMAT_MY, false );?></td></tr>
</table>
<?php
set_today( date ("Ymd") );
Expand Down
14 changes: 5 additions & 9 deletions approve_entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,7 @@
dbi_free_result ( $res );
}

if ($time != '-1') {
$hour = substr($time,0,2);
$minute = substr($time,2,2);
} else {
$hour = $minute = 0;
}
$eventstart = $fmtdate . sprintf( "%06d", ( $hour * 10000 ) + ( $minute * 100 ) );
$eventstart = date_to_epoch ( $fmtdate . $time );
//TODO figure out if creator wants approved comment email
//check UAC
$send_user_mail = "Y";
Expand All @@ -109,7 +103,7 @@
$t_format = get_pref_setting ( $creator, "TIME_FORMAT" );
user_load_variables ( $creator, "temp" );
$user_TIMEZONE = get_pref_setting ( $creator, "TIMEZONE" );
$user_TZ = get_tz_offset ( $user_TIMEZONE, '', $eventstart );
set_env ( "TZ", $user_TIMEZONE );
$user_language = get_pref_setting ( $creator, "LANGUAGE" );
if ( $send_user_mail == "Y" && strlen ( $tempemail ) &&
$SEND_EMAIL != "N" ) {
Expand All @@ -126,7 +120,7 @@
translate("Date") . ": " . date_to_str ( $fmtdate ) . "\n" .
( ( empty ( $hour ) && empty ( $minute ) ? "" : translate("Time") . ": " .
// Display using user's GMT offset and display TZID
display_time ( $eventstart, 2, '' , $user_TIMEZONE, $t_format ) ) ). "\n";
display_time ( '', 2, $eventstart , $t_format ) ) ). "\n";
if ( ! empty ( $SERVER_URL ) ) {
//DON'T change & to &amp; here. email will handle it
$url = $SERVER_URL . $view_type . ".php?id=" . $id . "&em=1";
Expand Down Expand Up @@ -158,6 +152,8 @@
"Approved w/Comments by $app_user" );
}
}
//return to login TIMEZONE
set_env ( "TZ", $TIMEZONE );
if ( empty ( $error ) ) {
if ( ! empty ( $ret ) && $ret == "listall" )
do_redirect ( "list_unapproved.php" );
Expand Down
12 changes: 3 additions & 9 deletions availability.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,12 @@
print_header($INC, '', "onload=\"focus();\"", true, false, true );

$span = ($WORK_DAY_END_HOUR - $WORK_DAY_START_HOUR) * 3 + 1;
if (strlen($month) == 1) $month = '0'.$month; // add leading zeros
if (strlen($day) == 1) $day = '0'.$day; // add leading zeros
$date = $year.$month.$day;
$time = mktime(0,0,0,$month,$day,$year);
$date = date ( "Ymd", $time );
$wday = strftime ( "%w", $time );
$base_url = "?users=$users";
$prev_url = $base_url."&amp;year=". strftime('%Y', $time - 86400)
."&amp;month=". strftime('%m', $time - 86400)
."&amp;day=". strftime('%d', $time - 86400);
$next_url = $base_url."&amp;year=". strftime('%Y', $time + 86400)
."&amp;month=". strftime('%m', $time + 86400)
."&amp;day=". strftime('%d', $time + 86400);
$prev_url = $base_url . strftime('&amp;year=%Y&amp;month=%m&amp;day=%d', $time - ONE_DAY);
$next_url = $base_url . strftime('&amp;year=%Y&amp;month=%m&amp;day=%d', $time + ONE_DAY);

$users = explode(",",$users);
?>
Expand Down
10 changes: 4 additions & 6 deletions datesel.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,15 @@
if ( $WEEK_START == 1 ) echo "<td>" .
weekday_short_name ( 0 ) . "</td>\n";
echo "</tr>\n";
if ( $WEEK_START == "1" )
$wkstart = get_monday_before ( $thisyear, $thismonth, 1 );
else
$wkstart = get_sunday_before ( $thisyear, $thismonth, 1 );
$wkstart = get_weekday_before ( $thisyear, $thismonth, 1 );

$monthstart = mktime ( 0, 0, 0, $thismonth, 1, $thisyear );
$monthend = mktime ( 0, 0, 0, $thismonth + 1, 0, $thisyear );
for ( $i = $wkstart; date ( "Ymd", $i ) <= date ( "Ymd", $monthend );
$i += ( 24 * 3600 * 7 ) ) {
$i += ( ONE_DAY * 7 ) ) {
echo "<tr>\n";
for ( $j = 0; $j < 7; $j++ ) {
$date = $i + ( $j * 24 * 3600 );
$date = $i + ( $j * ONE_DAY );
if ( ( date ( "Ymd", $date ) >= date ( "Ymd", $monthstart ) &&
date ( "Ymd", $date ) <= date ( "Ymd", $monthend ) ) ||
( ! empty ( $DISPLAY_ALL_DAYS_IN_MONTH ) &&
Expand Down
4 changes: 2 additions & 2 deletions day.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
$boldDays = false;
}

$startdate = sprintf ( "%04d%02d01", $thisyear, $thismonth );
$enddate = sprintf ( "%04d%02d31", $thisyear, $thismonth );
$startdate = mktime ( 0, 0, 0, $thismonth, 1, $thisyear );
$enddate = mktime ( 0, 0, 0, $thismonth +1 , 0, $thisyear );

$HeadX = '';
if ( $AUTO_REFRESH == "Y" && ! empty ( $AUTO_REFRESH_TIME ) ) {
Expand Down
14 changes: 10 additions & 4 deletions del_entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,12 @@
if ( $res ) {
$row = dbi_fetch_row ( $res );
$name = $row[0];
$eventdate = $row[1];
$eventtime = $row[2];
$fmtdate = $row[1];
$time = $row[2];
dbi_free_result ( $res );
}

$eventstart = date_to_epoch ( $fmtdate . $time );
$TIME_FORMAT=24;
for ( $i = 0; $i < count ( $partlogin ); $i++ ) {
// Log the deletion
Expand All @@ -153,6 +155,7 @@
$htmlmail = get_pref_setting ( $partlogin[$i], "EMAIL_HTML" );
$t_format = get_pref_setting ( $partlogin[$i], "TIME_FORMAT" );
$user_TIMEZONE = get_pref_setting ( $partlogin[$i], "TIMEZONE" );
set_env ( "TZ", $user_TIMEZONE );
$user_language = get_pref_setting ( $partlogin[$i], "LANGUAGE" );
user_load_variables ( $partlogin[$i], "temp" );
if ( ! $is_nonuser_admin && $partlogin[$i] != $login && $do_send == "Y" &&
Expand All @@ -168,9 +171,10 @@
" " . $login_fullname . ".\n" .
translate("The subject was") . " \"" . $name . "\"\n" .
translate("Date") . ": " . date_to_str ($thisdate) . "\n";
if ( $eventtime != '-1' ) $msg .= translate("Time") . ": " .
if ( ! empty ( $eventtime ) && $eventtime != '-1' )
$msg .= translate("Time") . ": " .
// Apply user's GMT offset and display their TZID
display_time ( $eventdate . $eventtime, 2, '', $user_TIMEZONE, $t_format );
display_time ( '', 2, $eventstart, $t_format );
$msg .= "\n\n";
$msg = stripslashes ( $msg );
//use WebCalMailer class
Expand Down Expand Up @@ -278,6 +282,8 @@
$url = get_preferred_view ( "", empty ( $user ) ? "" : "user=$user" );
}

//return to login TIMEZONE
set_env ( "TZ", $TIMEZONE );
if ( empty ( $error ) ) {
do_redirect ( $url );
exit;
Expand Down
86 changes: 32 additions & 54 deletions edit_entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,18 @@
$due_date = $row[13];
$due_time = $row[14];

$adjusted_start = get_datetime_add_tz ( $cal_date, $cal_time );
$adjusted_due = get_datetime_add_tz ( $due_date, $due_time );

$calTS = date_to_epoch ( $cal_date . $cal_time );
//Don't adjust for All Day entries
//this could probably replace the code below at line 160
if ( $cal_time > 0 || ( $cal_time == 0 && $row[5] != 1440 ) ) {
$cal_date = date ( "Ymd",$adjusted_start );
$cal_time = date ( "His", $adjusted_start );
$cal_date = date ( "Ymd", $calTS );
$cal_time = date ( "His", $calTS );
}
$hour = floor($cal_time / 10000);
$minute = ( $cal_time / 100 ) % 100;

$due_date = date ( "Ymd",$adjusted_due );
$due_time = date ( "His", $adjusted_due );
$dueTS = date_to_epoch ( $due_date . $due_time );
$due_date = date ( "Ymd", $dueTS );
$due_time = date ( "His", $dueTS );
$due_hour = floor($due_time / 10000);
$due_minute = ( $due_time / 100 ) % 100;

Expand Down Expand Up @@ -149,32 +147,8 @@
$month = ( $cal_date / 100 ) % 100;
$day = $cal_date % 100;
$time = $row[2];

$tz_offset = get_tz_offset ( $TIMEZONE, mktime ( 0, 0, 0, $month, $day, $year ) );
// test for AllDay event, if so, don't adjust time
if ( $time > 0 || ( $time == 0 && $row[5] != 1440 ) ) { /* -1 = no time specified */
$time = get_time_add_tz ( $time, $tz_offset[0] );
if ( $time > 240000 ) {
$time -= 240000;
$gmt = mktime ( 0, 0, 0, $month, $day, $year );
$gmt += ONE_DAY;
$month = date ( "m", $gmt );
$day = date ( "d", $gmt );
$year = date ( "Y", $gmt );
} else if ( $time < 0 ) {
$time += 240000;
$gmt = mktime ( 0, 0, 0, $month, $day, $year );
$gmt -= ONE_DAY;
$month = date ( "m", $gmt );
$day = date ( "d", $gmt );
$year = date ( "Y", $gmt );
}
// Set alterted date
// $cal_date = sprintf("%04d%02d%02d",$year,$month,$day);
}

if ( $time >= 0 ) {
$hour = floor($time / 10000);
$minute = ( $time / 100 ) % 100;
$duration = $row[5];
} else {
$duration = "";
Expand Down Expand Up @@ -206,12 +180,13 @@
if ( $row = dbi_fetch_row ( $res ) ) {
$rpt_type = $row[1];
if ( $row[2] > 0 )
$rpt_end = get_datetime_add_tz( $row[2], $row[3] );
$rpt_end = date_to_epoch( $row[2] . $row[3] );
else
$rpt_end = 0;
if ( ! empty ( $row[2] ) ) {
$rpt_end_date = date( "Ymd", get_datetime_add_tz( $row[2], $row[3] ) );
$rpt_end_time = date( "His", get_datetime_add_tz( $row[2], $row[3] ) );
$rpt_endTS = date_to_epoch( $row[2] . $row[3] );
$rpt_end_date = date( "Ymd", $rpt_endTS );
$rpt_end_time = date( "His", $rpt_endTS );
} else {
$rpt_end_date = $cal_date;
$rpt_end_time = $cal_time;
Expand Down Expand Up @@ -305,8 +280,8 @@
}

//get reminders
$reminder = getReminders ( $id, $tz_offset[0] );
$reminder_offset = ( isset ($reminder['offset'] ) ? $reminder['offset']:0);
$reminder = getReminders ( $id );
$reminder_offset = $reminder['offset'];

//get participants
$sql = "SELECT cal_login FROM webcal_entry_user WHERE cal_id = ? AND " .
Expand Down Expand Up @@ -339,10 +314,14 @@
//reminder settings
$reminder_offset = ($REMINDER_WITH_DATE =='N' ? $REMINDER_OFFSET:0);


if ( $eType == 'task' ) {
$hour = $WORK_DAY_START_HOUR;
}
// Anything other then testing for strlen breaks either hour=0 or no hour in URL
if ( strlen ( $hour ) ) {
$time = $hour * 100;
} else {
$time = $hour * 100;
} else {
$time = -1;
$hour = -1;
}
Expand Down Expand Up @@ -375,7 +354,7 @@
$hour = -1;
if ( empty ( $duration ) )
$duration = 0;
if ( $duration == ( 24 * 60 ) && $hour == 0 ) {
if ( $duration == ONE_DAY && $hour == 0 ) {
$hour = $minute = $duration = "";
$allday = "Y";
} else
Expand Down Expand Up @@ -421,15 +400,16 @@
$due_date = $thisdate;

//Setup to display user's timezone difference if Admin or Assistane
//Even thought event is stored in GMT, an Assistant may need to know that
//Even though event is stored in GMT, an Assistant may need to know that
//the boss is in a different Timezone
if ( $is_assistant || $is_admin && ! empty ( $user ) ) {
$tz_offset = get_tz_offset ( $TIMEZONE, '', $cal_date );
if ( $is_assistant || $is_admin && ! empty ( $user ) ) {
$tz_offset = date ( "Z", $calTS );
$user_TIMEZONE = get_pref_setting ( $user, "TIMEZONE" );
$user_TZ = get_tz_offset ( $user_TIMEZONE, '', $cal_date );
if ( $tz_offset[0] != $user_TZ[0] ) { //Different TZ_Offset
set_env ( "TZ", $user_TIMEZONE );
$user_tz_offset = date ( "Z", $calTS );
if ( $tz_offset != $user_tz_offset ) { //Different TZ_Offset
user_load_variables ( $user, "temp" );
$tz_diff = $user_TZ[0] - $tz_offset[0];
$tz_diff = $user_tz_offset - $tz_offset;
$tz_value = ( $tz_diff > 0? translate ("hours ahead of you") :
translate ("hours behind you") );
$TZ_notice = "(" . $tempfullname . " " .
Expand All @@ -438,6 +418,8 @@
$TZ_notice .= abs ( $tz_diff ) . " " . $tz_value . ".<br />&nbsp;";
$TZ_notice .= translate ("Time entered here is based on your Timezone") . ".)";
}
//return to $login TIMEZONE
set_env ( "TZ", $TIMEZONE );
}
if ( $ALLOW_HTML_DESCRIPTION == "Y" ){
// Allow HTML in description
Expand Down Expand Up @@ -751,8 +733,7 @@
}
if ( $cal_time < 0 ) $h12 = "";
?>
<input type="text" name="hour" size="2" value="<?php
if ( $cal_time >= 0 ) echo $h12;
<input type="text" name="hour" size="2" value="<?php echo $h12;
?>" maxlength="2" />:<input type="text" name="minute" size="2" value="<?php
if ( $cal_time >= 0 ) printf ( "%02d", $minute );
?>" maxlength="2" />
Expand Down Expand Up @@ -1276,7 +1257,7 @@
?> onclick="toggle_rem_when()" /><?php etranslate ("Use Date/Time"); ?>&nbsp;<label>
</td><td class="boxtop boxright" nowrap="nowrap" colspan="2">
<?php
if ( $reminder_offset == 0 && ! empty ( $reminder['date'] ) )
if ( ! empty ( $reminder['date'] ) )
print_date_selection ( 'reminder_', $reminder['date'] );
else
print_date_selection ( 'reminder_', $cal_date );
Expand Down Expand Up @@ -1317,10 +1298,7 @@
?> onclick="toggle_rem_when()" /><?php etranslate ("Use Offset"); ?>&nbsp;<label>
</td><td class="boxright" nowrap="nowrap" colspan="2">
<?php
if ( $reminder_offset > 0 && ! empty ( $reminder['offset'] ) )
$rem_minutes = $reminder['offset'];
else
$rem_minutes = $REMINDER_OFFSET;
$rem_minutes = $reminder_offset;
// will be specified in total minutes
$rem_days = (int) ( $rem_minutes / ( 24 * 60 ) );
$rem_minutes -= ( $rem_days * 24 * 60 );
Expand Down
Loading

0 comments on commit 7630506

Please sign in to comment.