modified time zone support. It works the same way as timezones.cfg and extra
[squirrelmail.git] / include / timezones / check.php
1 <?php
2 /**
3 * SquirrelMail time zone library - time zone validation script.
4 *
5 * Copyright (c) 2005 The SquirrelMail Project Team
6 * This file is part of SquirrelMail webmail interface.
7 *
8 * SquirrelMail is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * SquirrelMail is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with SquirrelMail; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 * @version $Id$
23 * @package squirrelmail
24 * @subpackage timezones
25 */
26
27 /** @ignore */
28 define('SM_PATH','../../');
29
30 /** Send http header */
31 header('Content-Type: text/plain');
32
33 /** Information about script */
34 echo "--------------------------------------------\n"
35 ." SquirrelMail time zone library test script\n"
36 ."--------------------------------------------\n";
37
38 /** load SM config */
39 unset($time_zone_type);
40 if (file_exists(SM_PATH.'config/config.php')) {
41 include(SM_PATH.'config/config.php');
42 } else {
43 echo "SquirrelMail configuration file is missing.\n";
44 exit();
45 }
46
47 /**
48 * Script does not test, if standard time zone libraries are missing.
49 * If they are missing or corrupted - php can fail, scream and show
50 * finger or other parts of interpreter.
51 */
52
53 /** load original reference */
54 include(SM_PATH.'include/timezones/standard_orig.php');
55
56 /** move timezones to different array */
57 $aTimeZonesOrig = $aTimeZones;
58 unset($aTimeZones);
59
60 if (! isset($time_zone_type) || $time_zone_type == 0 || $time_zone_type == 1) {
61 /** load new time zone library */
62 include(SM_PATH.'include/timezones/standard.php');
63 } elseif ($time_zone_type == 2 || $time_zone_type == 3) {
64 /** load custom time zone library */
65 $aTimeZones=array();
66 if (file_exists(SM_PATH . 'config/timezones.php')) {
67 include(SM_PATH.'config/timezones.php');
68 } else {
69 echo "ERROR: config/timezones.php is missing.\n";
70 exit();
71 }
72 } else {
73 echo "ERROR: invalid value in time_zone_type configuration.\n";
74 exit();
75 }
76
77 if (! isset($aTimeZones) || ! is_array($aTimeZones) || empty($aTimeZones)) {
78 echo "ERROR: timezones array is missing or empty.\n";
79 exit();
80 }
81
82 $error = false;
83
84 /** test backward compatibility */
85 echo "Testing backward compatibility:\n"
86 ." Failed time zones:\n";
87 foreach ($aTimeZonesOrig as $TzKey => $TzData) {
88 if (! isset($aTimeZones[$TzKey])) {
89 echo ' '.$TzKey."\n";
90 $error = true;
91 }
92 }
93 if (! $error) {
94 echo " none. Looking good.\n";
95 } else {
96 // error is not fatal, but test should fail only with limited custom time zone sets
97 }
98
99 echo "\n";
100
101 /** test forward compatibility */
102 $error = false;
103 echo "Testing forward compatibility:\n"
104 ." New time zones:\n";
105 foreach ($aTimeZones as $TzKey => $TzData) {
106 if (! isset($aTimeZonesOrig[$TzKey])) {
107 echo ' '.$TzKey."\n";
108 $error = true;
109 }
110 }
111 if (! $error) {
112 echo " no new time zones.\n";
113 } else {
114 // error is not fatal. test should show new time zones, that are not
115 // present in timezones.cfg
116 }
117
118 echo "\n";
119
120 /** test links */
121 $error = false;
122 echo "Testing time zone links:\n"
123 ." Failed time zone links:\n";
124 foreach ($aTimeZones as $TzKey => $TzData) {
125 if (isset($TzData['LINK']) && ! isset($aTimeZones[$TzData['LINK']]['TZ'])) {
126 echo ' '.$TzKey.' = '.$TzData['LINK']."\n";
127 $error = true;
128 }
129 }
130 if (! $error) {
131 echo " none. Looking good.\n";
132 } else {
133 // error is fatal. 'LINK' should always reffer to existing 'TZ' entries
134 }
135
136 echo "\n";
137
138 /** Test TZ subkeys */
139 $error = false;
140 echo "Testing time zone TZ subkeys:\n"
141 ." Failed time zone TZ subkeys:\n";
142 foreach ($aTimeZones as $TzKey => $TzData) {
143 if (! isset($TzData['LINK']) && ! isset($TzData['TZ'])) {
144 echo ' '.$TzKey."\n";
145 $error = true;
146 }
147 }
148 if (! $error) {
149 echo " none. Looking good.\n";
150 } else {
151 // LINK or TZ are required for strict time zones. Interface won't break, but
152 // any error means inconsistency in time zone array.
153 }
154
155 echo "\n";
156
157 /** Test NAME subkeys */
158 $error = false;
159 echo "Testing time zone NAME subkeys:\n"
160 ." Time zones without NAME subkeys:\n";
161 foreach ($aTimeZones as $TzKey => $TzData) {
162 if (isset($TzData['TZ']) && ! isset($TzData['NAME'])) {
163 echo ' '.$TzKey."\n";
164 $error = true;
165 }
166 }
167 if (! $error) {
168 echo " none.\n";
169 } else {
170 // error is not fatal. It would be nice if all geographic locations
171 // use some human readable name
172 }
173
174 echo "\n";
175
176 /** Test TZ subkeys with UCT/UTC/GMT offsets */
177 $error = false;
178 echo "Testing TZ subkeys with UCT/UTC/GMT offsets:\n"
179 ." Time zones UCT/UTC/GMT offsets:\n";
180 foreach ($aTimeZones as $TzKey => $TzData) {
181 if (isset($TzData['TZ']) && preg_match("/^(UCT)|(UTC)|(GMT).+/i",$TzData['TZ'])) {
182 echo ' '.$TzKey.' = '.$TzData['TZ']."\n";
183 $error = true;
184 }
185 }
186 if (! $error) {
187 echo " none.\n";
188 } else {
189 // I think error is fatal for UCT with offsets. date('T',time()) is corrupted.
190 }
191
192 echo "\n";
193
194 /** Test TZ subkeys with custom TZ values and no offsets */
195 $error = false;
196 echo "Testing TZ subkeys with custom TZ values and no offsets:\n"
197 ." Time zones with custom TZ values and no offsets:\n";
198 foreach ($aTimeZones as $TzKey => $TzData) {
199 if (isset($TzData['TZ']) &&
200 ! preg_match("/^((UCT)|(UTC)|(GMT).+)|(GMT)$/i",$TzData['TZ']) &&
201 preg_match("/^[a-z]+$/i",$TzData['TZ'])) {
202 echo ' '.$TzKey.' = '.$TzData['TZ']."\n";
203 $error = true;
204 }
205 }
206 if (! $error) {
207 echo " none.\n";
208 } else {
209 // I think error is fatal. Time zone formating requires time zone name and offset from GMT.
210 }
211
212 echo "\n";
213
214 echo "Done!\n";
215 ?>