2d3a630b |
1 | <?php |
4b4abf93 |
2 | |
2d3a630b |
3 | /** |
4 | * SquirrelMail Time zone functions |
5 | * |
6 | * Function load time zone array selected in SquirrelMail |
7 | * configuration. |
8 | * |
9 | * Time zone array must consist of key name that matches key in |
10 | * standard time zone array and 'NAME' and 'TZ' subkeys. 'NAME' |
11 | * key should store translatable key name. 'TZ' key should store |
12 | * time zone name that will be used in TZ environment variable. |
13 | * Both subkeys are optional. If they are not present, time zone |
14 | * key name is used. |
15 | * |
1977ab55 |
16 | * @copyright 1999-2010 The SquirrelMail Project Team |
4b4abf93 |
17 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
18 | * @version $Id$ |
2d3a630b |
19 | * @package squirrelmail |
72598e90 |
20 | * @subpackage timezones |
2d3a630b |
21 | */ |
22 | |
23 | /** |
24 | * Returns time zone array set in SquirrelMail configuration |
25 | * @return array time zone array |
26 | * @since 1.5.1 |
27 | */ |
28 | function sq_get_tz_array() { |
29 | global $time_zone_type; |
30 | |
31 | // variable is not set or empty |
32 | if (! isset($time_zone_type) || empty($time_zone_type)) { |
33 | $time_zone_type = 0; |
34 | } else { |
35 | // make sure that it is integer |
36 | $time_zone_type = (int) $time_zone_type; |
37 | } |
38 | |
39 | /** |
40 | * TODO: which one is better (global + include_once) or (include) |
41 | */ |
42 | switch ($time_zone_type) { |
43 | case '3': |
44 | case '2': |
45 | // custom time zone set |
46 | $aTimeZones = array(); |
47 | if (file_exists(SM_PATH . 'config/timezones.php')) { |
48 | include(SM_PATH . 'config/timezones.php'); |
49 | } |
50 | $aRet = $aTimeZones; |
51 | break; |
52 | case '1': |
53 | case '0': |
54 | default: |
55 | // standard (default) time zone set |
56 | include(SM_PATH . 'include/timezones/standard.php'); |
57 | $aRet = $aTimeZones; |
58 | } |
59 | // sort array |
60 | ksort($aRet); |
61 | return $aRet; |
62 | } |
63 | |
64 | /** |
65 | * @param string time zone string |
66 | * @return string time zone name used for TZ env |
67 | * (false, if timezone does not exists and server's TZ should be used) |
68 | * @since 1.5.1 |
69 | */ |
70 | function sq_get_tz_key($sTZ) { |
71 | $aTZs=sq_get_tz_array(); |
72 | |
73 | // get real time zone from link |
74 | if (isset($aTZs[$sTZ]['LINK'])) { |
75 | $sTZ = $aTZs[$sTZ]['LINK']; |
76 | } |
77 | |
78 | if (isset($aTZs[$sTZ])) { |
79 | if (isset($aTZs[$sTZ]['TZ'])) { |
80 | // get time zone |
81 | return $aTZs[$sTZ]['TZ']; |
82 | } else { |
83 | // array does not have TZ entry. bad thing |
84 | return $sTZ; |
85 | } |
86 | } else { |
87 | return false; |
88 | } |
89 | } |