Code

Updated gosa si DAK remove key ring entry.
[gosa.git] / gosa-core / include / utils / class_timezone.inc
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(isset($config->current['TIMEZONE']) || isset($config->data['MAIN']['TIMEZONE'])){
43       /* Get zonename */
44       if(isset($config->current['TIMEZONE'])){
45         $tz = $config->current['TIMEZONE'];
46       }else{
47         $tz = $config->data['MAIN']['TIMEZONE'];
48       }
50       if(!@date_default_timezone_set($tz)){
51         msg_dialog::display(_("Configuration error"), sprintf(_("The timezone setting '%s' in your gosa.conf is not valid. Cannot calculate correct timezone offset."), $tz), ERROR_DIALOG);
52       }
53       $tz_delta = date("Z", $stamp);
54       $tz_delta = $tz_delta / 3600 ;
55       return(array("name" => $tz, "value" => $tz_delta));
57     }
58     return($zone);
59   }
62   /* Return zone informations */
63   static public function _get_tz_zones()
64   {
65     $timezone_identifiers = DateTimeZone::listIdentifiers();
66     $timezones = array();
67     $zones = DateTimeZone::listAbbreviations();
68     foreach($zones as $group){
69       foreach($group as $zone)  {
70         $timezones[$zone['timezone_id']] = $zone['offset'];
71         if($zone['dst']){
72           $dst_timezones[$zone['timezone_id']] = 1;
73         }
74       }
75     }
76     return(array("TIMEZONES" => @$timezones, "DST_ZONES" => @$dst_timezones));
77   }
78 }
80 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
81 ?>