c023b356f8e8a49722f60fe1fba4ba885e124155
[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 NAME subkeys */
177 $error = false;
178 echo " Time zones with empty NAME subkeys:\n";
179 foreach ($aTimeZones as $TzKey => $TzData) {
180 if (isset($TzData['NAME']) && empty($TzData['NAME'])) {
181 echo ' '.$TzKey."\n";
182 $error = true;
183 }
184 }
185 if (! $error) {
186 echo " none. Looking good\n";
187 } else {
188 // error is fatal. NAME should not be empty string.
189 }
190
191 echo "\n";
192
193 /** Test TZ subkeys with UCT/UTC/GMT offsets */
194 $error = false;
195 echo "Testing TZ subkeys with UCT/UTC/GMT offsets:\n"
196 ." Time zones UCT/UTC/GMT offsets:\n";
197 foreach ($aTimeZones as $TzKey => $TzData) {
198 if (isset($TzData['TZ']) && preg_match("/^(UCT)|(UTC)|(GMT).+/i",$TzData['TZ'])) {
199 echo ' '.$TzKey.' = '.$TzData['TZ']."\n";
200 $error = true;
201 }
202 }
203 if (! $error) {
204 echo " none.\n";
205 } else {
206 // I think error is fatal for UCT with offsets. date('T',time()) is corrupted.
207 }
208
209 echo "\n";
210
211 /** Test TZ subkeys with custom TZ values and no offsets */
212 $error = false;
213 echo "Testing TZ subkeys with custom TZ values and no offsets:\n"
214 ." Time zones with custom TZ values and no offsets:\n";
215 foreach ($aTimeZones as $TzKey => $TzData) {
216 if (isset($TzData['TZ']) &&
217 ! preg_match("/^((UCT)|(UTC)|(GMT).+)|(GMT)$/i",$TzData['TZ']) &&
218 preg_match("/^[a-z]+$/i",$TzData['TZ'])) {
219 echo ' '.$TzKey.' = '.$TzData['TZ']."\n";
220 $error = true;
221 }
222 }
223 if (! $error) {
224 echo " none.\n";
225 } else {
226 // I think error is fatal. Time zone formating requires time zone name and offset from GMT.
227 }
228
229 echo "\n";
230
231 echo "Done!\n";
232 ?>