1 <?php
2 /*
3 * This code is part of GOsa (https://gosa.gonicus.de)
4 * Copyright (C) 2008 Cajus Pollmeier
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
21 class timezone {
23 /* This function returns the offset for the default timezone.
24 * $stamp is used to detect summer or winter time.
25 * In case of PHP5, the integrated timezone functions are used.
26 */
27 static public function get_default_timezone($stamp = NULL)
28 {
29 global $config;
30 $tz ="";
32 /* Default return value if zone could not be detected */
33 $zone = array("name" => "unconfigured", "value" => 0);
35 /* Use current timestamp if $stamp is not set */
36 if($stamp === NULL){
37 $stamp = time();
38 }
40 /* Is there a timezone configured in the gosa configuration (gosa.conf) */
41 if ($config->get_cfg_value("timezone") != ""){
43 /* Get zonename */
44 $tz = $config->get_cfg_value("timezone");
46 if(!@date_default_timezone_set($tz)){
47 msg_dialog::display(_("Configuration error"), sprintf(_("The configured timezone '%s' is not valid!"), $tz), ERROR_DIALOG);
48 }
49 $tz_delta = date("Z", $stamp);
50 $tz_delta = $tz_delta / 3600 ;
51 return(array("name" => $tz, "value" => $tz_delta));
53 }
54 return($zone);
55 }
58 /* Return zone informations */
59 static public function _get_tz_zones()
60 {
61 $timezone_identifiers = DateTimeZone::listIdentifiers();
62 $timezones = array();
63 $zones = DateTimeZone::listAbbreviations();
64 foreach($zones as $group){
65 foreach($group as $zone) {
66 $timezones[$zone['timezone_id']] = $zone['offset'];
67 if($zone['dst']){
68 $dst_timezones[$zone['timezone_id']] = 1;
69 }
70 }
71 }
72 return(array("TIMEZONES" => @$timezones, "DST_ZONES" => @$dst_timezones));
73 }
74 }
76 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
77 ?>