timezones.php 2.3 KB

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