Skip to content

Commit

Permalink
Add initial timezone selection functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
mantis committed May 17, 2009
1 parent d26d7cf commit a058e75
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 0 deletions.
10 changes: 10 additions & 0 deletions account_prefs_inc.php
Expand Up @@ -269,6 +269,16 @@ function edit_account_prefs($p_user_id = null, $p_error_if_protected = true, $p_
<input type="text" name="email_bugnote_limit" maxlength="2" size="2" value="<?php echo $t_pref->email_bugnote_limit ?>" />
</td>
</tr>
<tr class="row-2">
<td class="category">
<?php echo lang_get( 'timezone' ) ?>
</td>
<td>
<select name="timezone">
<?php print_timezone_option_list( $t_pref->timezone ? $t_pref->timezone : config_get_global( 'default_timezone' ) ) ?>
</select>
</td>
</tr>
<?php } else { ?>
<input type="hidden" name="email_on_new" value="<?php echo $t_pref->email_on_new ?>" />
<input type="hidden" name="email_on_assigned" value="<?php echo $t_pref->email_on_assigned ?>" />
Expand Down
9 changes: 9 additions & 0 deletions account_prefs_update.php
Expand Up @@ -97,6 +97,15 @@
$t_prefs->refresh_delay = config_get( 'min_refresh_delay' );
}

$t_timezone = gpc_get_string( 'timezone' );
if ( in_array( $t_timezone, timezone_identifiers_list() ) ) {
if ( $t_timezone == config_get_global( 'default_timezone' ) ) {
$t_prefs->timezone = '';
} else {
$t_prefs->timezone = $t_timezone;
}
}

event_signal( 'EVENT_ACCOUNT_PREF_UPDATE', array( $f_user_id ) );

user_pref_set( $f_user_id, $t_prefs );
Expand Down
10 changes: 10 additions & 0 deletions admin/check.php
Expand Up @@ -361,6 +361,16 @@ function test_database_utf8() {
print_test_row( 'Checking for mysql is at least version 4.1...', !(db_is_mysql() && version_compare( $t_serverinfo['version'], '4.1.0', '<' ) ) );
print_test_row( 'Checking for broken mysql version ( bug 10250)...', !(db_is_mysql() && $t_serverinfo['version'] == '4.1.21') );

if ( !is_blank ( config_get_global( 'default_timezone' ) ) ) {
if ( print_test_row( 'Checking if a timezone is set in config.inc.php....', !is_blank ( config_get_global( 'default_timezone' ) ), config_get_global( 'default_timezone' ) ) ) {
print_test_row( 'Checking if timezone is valid from config.inc.php....', in_array( config_get_global( 'default_timezone' ), timezone_identifiers_list() ), config_get_global( 'default_timezone' ) );
}
} else {
if( print_test_row( 'Checking if timezone is set in php.ini....', ini_get( 'date.timezone' ) !== '' ) ) {
print_test_row( 'Checking if timezone is valid in php.ini....', in_array( ini_get( 'date.timezone' ), timezone_identifiers_list() ), ini_get( 'date.timezone' ) );
}
}

test_database_utf8();

print_test_row( 'Checking Register Globals is set to off', ! ini_get_bool( 'register_globals' ) );
Expand Down
2 changes: 2 additions & 0 deletions admin/schema.php
Expand Up @@ -555,6 +555,8 @@ function installer_db_now() {
$upgrade[] = Array( 'RenameColumnSQL', Array( db_get_table( 'mantis_bug_revision_table' ), "timestamp_int", "timestamp", "timestamp_int I UNSIGNED NOTNULL DEFAULT '1' " ) );
$upgrade[] = Array( 'CreateIndexSQL', Array( 'idx_bug_rev_id_time', db_get_table( 'mantis_bug_revision_table' ), 'bug_id, timestamp' ) );

$upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_user_pref_table' ), "
timezone C(32) NOTNULL DEFAULT '' " ) );



18 changes: 18 additions & 0 deletions config_defaults_inc.php
Expand Up @@ -1091,6 +1091,24 @@
*/
$g_complete_date_format = 'Y-m-d H:i T';

/**************************
* MantisBT TimeZone Settings *
**************************/

/**
* Default timezone to use in mantis.
* See http://us.php.net/manual/en/timezones.php
* for a list of valid timezones.
* Note: if this is left blank, we use the result of
* date_default_timezone_get() i.e. in order:
* 1. Reading the TZ environment variable (if non empty)
* 2. Reading the value of the date.timezone php.ini option (if set)
* 3. Querying the host operating system (if supported and allowed by the OS)
* 4. If none of the above succeed, will return a default timezone of UTC.
* @global string $g_default_timezone
*/
$g_default_timezone = '';

/**************************
* MantisBT News Settings *
**************************/
Expand Down
8 changes: 8 additions & 0 deletions core.php
Expand Up @@ -253,6 +253,14 @@ function __autoload( $className ) {
}
}

if ( !is_blank ( config_get_global( 'default_timezone' ) ) ) {
// if a default timezone is set in config, set it here, else we use php.ini's value
// having a timezone set avoids a php warning
date_default_timezone_set( config_get_global( 'default_timezone' ) );
} else {
config_set_global( 'default_timezone', date_default_timezone_get() );
}

// push push default language to speed calls to lang_get
if ( !isset( $g_skip_lang_load ) )
lang_push( lang_get_default() );
Expand Down
38 changes: 38 additions & 0 deletions core/print_api.php
Expand Up @@ -1765,3 +1765,41 @@ function swap_content( span ) {
}
}
}

# --------------------
# Print the option list for timezones
function print_timezone_option_list( $p_timezone ) {
$t_identifiers = timezone_identifiers_list();

foreach ( $t_identifiers as $t_identifier )
{
$t_zone = explode( '/', $t_identifier );

// Only use "friendly" continent names - http://us.php.net/manual/en/timezones.others.php
if ($t_zone[0] == 'Africa' ||
$t_zone[0] == 'America' ||
$t_zone[0] == 'Antarctica' ||
$t_zone[0] == 'Arctic' ||
$t_zone[0] == 'Asia' ||
$t_zone[0] == 'Atlantic' ||
$t_zone[0] == 'Australia' ||
$t_zone[0] == 'Europe' ||
$t_zone[0] == 'Indian' ||
$t_zone[0] == 'Pacific' )
{
if ( isset( $t_zone[1] ) != '' )
{
$t_locations[$t_zone[0]][$t_zone[0] . '/' . $t_zone[1]] = array( str_replace( '_', ' ', $t_zone[1] ), $t_identifier );
}
}
}

foreach( $t_locations as $t_continent => $t_locations ) {
echo '<optgroup label="'.$t_continent.'">';
foreach ( $t_locations as $t_location ) {
echo '<option value="' . $t_location[1] . '"';
check_selected( $p_timezone, $t_location[1] );
echo '>' . $t_location[0] . '</option>';
}
}
}
2 changes: 2 additions & 0 deletions core/user_pref_api.php
Expand Up @@ -54,6 +54,7 @@
'email_on_priority_min_severity' => 'default_email_on_priority_minimum_severity',
'email_bugnote_limit' => 'default_email_bugnote_limit',
'language' => 'default_language',
'timezone' => 'default_timezone',
);

# ===================================
Expand Down Expand Up @@ -88,6 +89,7 @@ class UserPreferences {
var $email_on_priority_min_severity = NULL;
var $email_bugnote_limit = NULL;
var $language = NULL;
var $timezone = NULL;

function UserPreferences() {
$this->default_profile = 0;
Expand Down
1 change: 1 addition & 0 deletions lang/strings_english.txt
Expand Up @@ -469,6 +469,7 @@ $s_email_bugnote_limit = 'E-mail Notes Limit';
$s_language = 'Language';
$s_update_prefs_button = 'Update Prefs';
$s_reset_prefs_button = 'Reset Prefs';
$s_timezone = 'TimeZone';

# account_prefs_reset.php
$s_prefs_reset_msg = 'Preferences have been reset...';
Expand Down

0 comments on commit a058e75

Please sign in to comment.