Back-ported to PHP4 (type-hints removed)
[mailer.git] / 0.2.1 / inc / load_cache.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 11/28/2004 *
4  * ===============                              Last change: 11/28/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : load_cache.php                                   *
8  * -------------------------------------------------------------------- *
9  * Short description : Load more cache files                            *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Mehr Cache-Dateien nachladen                     *
12  * -------------------------------------------------------------------- *
13  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
36 {
37         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
38         require($INC);
39 }
40
41 // Let's start with the admins table...
42 if (($CACHE->cache_file("admins", true) == true))
43 {
44         // Load cache
45         global $ADMINS;
46         $ADMINS = $CACHE->cache_load();
47
48         // Check if valid
49         if (is_array($ADMINS['login']) && is_array($ADMINS['def_acl']) && is_array($ADMINS['aid']))
50         {
51                 // Check count
52                 if (count($ADMINS['login']) == count($ADMINS['aid']) && count($ADMINS['login']) == count($ADMINS['def_acl']) && count($ADMINS['aid']) == count($ADMINS['def_acl']))
53                 {
54                         //* DEBUG: */ echo "<PRE>";
55                         //* DEBUG: */ print_r($ADMINS);
56
57                         // The cache file seems to be fine
58                         foreach ($ADMINS['login'] as $k=>$login)
59                         {
60                                 // Rewrite default_acl
61                                 $ADMINS['aid'][$login]      = $ADMINS['aid'][$k];
62                                 $ADMINS['password'][$login] = $ADMINS['password'][$k];
63                                 $ADMINS['email'][$login]    = $ADMINS['email'][$k];
64
65                                 // Some extra data depening on version
66                                 if (GET_EXT_VERSION("admins") >= "0.3")
67                                 {
68                                         $ADMINS['def_acl'][$login]  = $ADMINS['def_acl'][$k];
69                                         if (GET_EXT_VERSION("admins") >= "0.6.7")
70                                         {
71                                                 $ADMINS['la_mode'][$login]  = $ADMINS['la_mode'][$k];
72                                         }
73                                 }
74
75                                 //* DEBUG: */ print_r($ADMINS);
76
77                                 // Clear array
78                                 unset($ADMINS['aid'][$k]);
79                                 unset($ADMINS['def_acl'][$k]);
80                                 unset($ADMINS['la_mode'][$k]);
81                                 unset($ADMINS['password'][$k]);
82                                 unset($ADMINS['email'][$k]);
83                         }
84
85                         //* DEBUG: */ print_r($ADMINS);
86
87                         // Rewrite Login
88                         foreach ($ADMINS['login'] as $k=>$login)
89                         {
90                                 $ADMINS['login'][$ADMINS['aid'][$login]] = $login;
91                                 if (!in_array($k, $ADMINS['aid']))
92                                 {
93                                         unset($ADMINS['login'][$k]);
94                                 }
95                         }
96
97                         //* DEBUG: */ echo "****\n";
98                         //* DEBUG: */ print_r($ADMINS);
99                         //* DEBUG: */ echo "</PRE>";
100                         //* DEBUG: */ die();
101                 }
102                  else
103                 {
104                         // Nope, cache file is corrupted!
105                         $CACHE->cache_destroy();
106                 }
107         }
108          else
109         {
110                 // Nope, cache file is corrupted!
111                 $CACHE->cache_destroy();
112                 unset($ADMINS);
113         }
114 }
115  elseif (($CONFIG['cache_admins'] == "Y") && ($CSS != "1") && ($CSS != "-1"))
116 {
117         // Create cache file
118         $CACHE->cache_init("ADMINS");
119
120         // Load every data from DB to cache file
121         $ADD = ", id, id";
122         if (GET_EXT_VERSION("admins") >= "0.3")   $ADD  = ", default_acl AS def_acl";
123         if (GET_EXT_VERSION("admins") >= "0.6.7") $ADD .= ", la_mode";
124
125         $result_admins = SQL_QUERY("SELECT id AS aid, login, password, email".$ADD."
126 FROM "._MYSQL_PREFIX."_admins
127 ORDER BY login", __FILE__, __LINE__);
128         while($dummy = SQL_FETCHARRAY($result_admins))
129         {
130                 // Save row
131                 $CACHE->add_row($dummy);
132         }
133
134         // Free memory
135         SQL_FREERESULT($result_admins);
136 }
137
138 // Close file
139 $CACHE->cache_close();
140
141 // Next cached table is the module registry (mod_reg)...
142 if ($CACHE->cache_file("mod_reg", true) == true)
143 {
144         // Load cache
145         global $MODULES;
146         $MODULES = $CACHE->cache_load();
147
148         // Valid cache file
149         $CNT = 0;
150         foreach ($MODULES as $k=>$array)
151         {
152                 $CNT += count($array);
153         }
154
155         // When there is a period (.) in the result this test will fail and so the cache file is
156         // damaged/corrupted
157         $TEST = "failed";
158         if (count($MODULES) > 0 ) $TEST = ($CNT / (count($MODULES)));
159         if ($TEST != bigintval($TEST))
160         {
161                 // Cache file is corrupted!
162                 $CACHE->cache_destroy();
163                 unset($MODULES);
164         }
165          else
166         {
167                 // Rewrite module cache
168                 $MOD = $MODULES;
169                 foreach ($MODULES['module'] as $key=>$mod)
170                 {
171                         $MODULES['id'][$mod] = $MODULES['id'][$key];
172                         unset($MODULES['id'][$key]);
173                         $MODULES['title'][$mod] = $MODULES['title'][$key];
174                         unset($MODULES['title'][$key]);
175                         $MODULES['locked'][$mod] = $MODULES['locked'][$key];
176                         unset($MODULES['locked'][$key]);
177                         $MODULES['hidden'][$mod] = $MODULES['hidden'][$key];
178                         unset($MODULES['hidden'][$key]);
179                         $MODULES['admin_only'][$mod] = $MODULES['admin_only'][$key];
180                         unset($MODULES['admin_only'][$key]);
181                         $MODULES['mem_only'][$mod] = $MODULES['mem_only'][$key];
182                         unset($MODULES['mem_only'][$key]);
183                         $MODULES['has_menu'][$mod] = $MODULES['has_menu'][$key];
184                         unset($MODULES['has_menu'][$key]);
185                 }
186         }
187 }
188  elseif (($CONFIG['cache_modreg'] == "Y") && ($CSS != "1") && ($CSS != "-1"))
189 {
190         // Create cache file here
191         $CACHE->cache_init("MODULES");
192
193         // Load all modules and their data
194         if (GET_EXT_VERSION("sql_patches") >= "0.3.6")
195         {
196                 // Load has_menu
197                 $result = SQL_QUERY("SELECT id, module, title, locked, hidden, admin_only, title, mem_only, has_menu
198 FROM "._MYSQL_PREFIX."_mod_reg ORDER BY id", __FILE__, __LINE__);
199         }
200          else
201         {
202                 // Don't load has_menu
203                 $result = SQL_QUERY("SELECT id, module, title, locked, hidden, admin_only, title, mem_only
204 FROM "._MYSQL_PREFIX."_mod_reg ORDER BY id", __FILE__, __LINE__);
205         }
206         while ($DATA = SQL_FETCHARRAY($result))
207         {
208                 // Add row to cache file
209                 $CACHE->add_row($DATA);
210         }
211
212         // Free memory
213         SQL_FREERESULT($result);
214 }
215
216 // Close file
217 $CACHE->cache_close();
218
219 // Next cached table is the configuration (config)...
220 if ($CACHE->cache_file("config", true) == true)
221 {
222         // Load config from cache
223         global $CFG_CACHE;
224         $CFG_CACHE = $CACHE->cache_load();
225
226         // Valid cache file
227         $CNT = 0;
228         foreach ($CFG_CACHE as $k=>$array)
229         {
230                 $CNT += count($array);
231         }
232
233         // When there is a period (.) in the result this test will fail and so the cache file is
234         // damaged/corrupted
235         $TEST = "failed";
236         if (count($CFG_CACHE) > 0 ) $TEST = ($CNT / (count($CFG_CACHE)));
237         if ($TEST != bigintval($TEST))
238         {
239                 // Cache file is corrupted!
240                 $CACHE->cache_destroy();
241                 unset($CFG_CACHE);
242         }
243 }
244  elseif (($CONFIG['cache_config'] == "Y") && ($CSS != "1") && ($CSS != "-1"))
245 {
246         // Create cache file here
247         $CACHE->cache_init("CONFIG");
248
249         // Load all modules and their data
250         $result = SQL_QUERY("SELECT * FROM "._MYSQL_PREFIX."_config ORDER BY config", __FILE__, __LINE__);
251         while ($DATA = SQL_FETCHARRAY($result))
252         {
253                 // Add row to cache file
254                 $CACHE->add_row($DATA);
255         }
256
257         // Free memory
258         SQL_FREERESULT($result);
259 }
260
261 // Close file
262 $CACHE->cache_close();
263
264 // Next cached table is the referral system (refsystem)...
265 if ($CACHE->cache_file("refsystem", true) == true)
266 {
267         // Load referral system from cache
268         global $REF_SYSTEM;
269         $REF_SYSTEM = $CACHE->cache_load();
270
271         // Valid cache file
272         $CNT = 0;
273         foreach ($REF_SYSTEM as $k=>$array)
274         {
275                 $CNT += count($array);
276         }
277
278         // When there is a period (.) in the result this test will fail and so the cache file is
279         // damaged/corrupted
280         $TEST = "failed";
281         if (count($REF_SYSTEM) > 0 ) $TEST = ($CNT / (count($REF_SYSTEM)));
282         if ($TEST != bigintval($TEST))
283         {
284                 // Cache file is corrupted!
285                 $CACHE->cache_destroy();
286                 unset($REF_SYSTEM);
287         }
288 }
289  elseif (($CONFIG['cache_refsys'] == "Y") && ($CSS != "1") && ($CSS != "-1"))
290 {
291         // Create cache file here
292         $CACHE->cache_init("REFSYSTEM");
293
294         // Load all modules and their data
295         $result = SQL_QUERY("SELECT id, userid, level, counter FROM "._MYSQL_PREFIX."_refsystem ORDER BY userid, level", __FILE__, __LINE__);
296         while ($DATA = SQL_FETCHARRAY($result))
297         {
298                 // Add row to cache file
299                 $CACHE->add_row($DATA);
300         }
301
302         // Free memory
303         SQL_FREERESULT($result);
304 }
305
306 // Close file
307 $CACHE->cache_close();
308
309 // Next cached table is the referral system (refdepths)...
310 if ($CACHE->cache_file("refdepths", true) == true)
311 {
312         // Load referral system from cache
313         global $REF_DEPTHS;
314         $REF_DEPTHS = $CACHE->cache_load();
315
316         // Valid cache file
317         $CNT = 0;
318         foreach ($REF_DEPTHS as $k=>$array)
319         {
320                 $CNT += count($array);
321         }
322
323         // When there is a period (.) in the result this test will fail and so the cache file is
324         // damaged/corrupted
325         $TEST = "failed";
326         if (count($REF_DEPTHS) > 0 ) $TEST = ($CNT / (count($REF_DEPTHS)));
327         if ($TEST != bigintval($TEST))
328         {
329                 // Cache file is corrupted!
330                 $CACHE->cache_destroy();
331                 unset($REF_DEPTHS);
332         }
333 }
334  elseif (($CONFIG['cache_refdepth'] == "Y") && ($CSS != "1") && ($CSS != "-1"))
335 {
336         // Create cache file here
337         $CACHE->cache_init("REFDEPTHS");
338
339         // Load all modules and their data
340         $result = SQL_QUERY("SELECT id, level, percents FROM "._MYSQL_PREFIX."_refdepths ORDER BY level", __FILE__, __LINE__);
341         while ($DATA = SQL_FETCHARRAY($result))
342         {
343                 // Add row to cache file
344                 $CACHE->add_row($DATA);
345         }
346
347         // Free memory
348         SQL_FREERESULT($result);
349 }
350
351 // Close file
352 $CACHE->cache_close();
353
354 // Next cached table is the referral system (admins_acls)...
355 if (GET_EXT_VERSION("admins") >= "0.3")
356 {
357         // Check for cache file
358         if ($CACHE->cache_file("admins_acls", true) == true)
359         {
360                 // Load referral system from cache
361                 global $ADMINS_ACLS;
362                 $ADMINS_ACLS = $CACHE->cache_load();
363
364                 // Valid cache file
365                 $CNT = 0;
366                 foreach ($ADMINS_ACLS as $k=>$array)
367                 {
368                         $CNT += count($array);
369                 }
370
371                 // When there is a period (.) in the result this test will fail and so the cache file is
372                 // damaged/corrupted
373                 if (count($ADMINS_ACLS) > 0)
374                 {
375                         $TEST = "failed";
376                         if (count($ADMINS_ACLS) > 0 ) $TEST = ($CNT / (count($ADMINS_ACLS)));
377                         if ($TEST != bigintval($TEST))
378                         {
379                                 // Cache file is corrupted!
380                                 $CACHE->cache_destroy();
381                                 unset($ADMINS_ACLS);
382                         }
383                 }
384         }
385          elseif (($CONFIG['cache_acls'] == "Y") && ($CSS != "1") && ($CSS != "-1"))
386         {
387                 // Create cache file here
388                 $CACHE->cache_init("ADMINS_ACLS");
389
390                 // Load all modules and their data
391                 $result = SQL_QUERY("SELECT id, admin_id, action_menu, what_menu, access_mode FROM "._MYSQL_PREFIX."_admins_acls ORDER BY admin_id, action_menu, what_menu", __FILE__, __LINE__);
392                 while ($DATA = SQL_FETCHARRAY($result))
393                 {
394                         // Add row to cache file
395                         $CACHE->add_row($DATA);
396                 }
397
398                 // Free memory
399                 SQL_FREERESULT($result);
400         }
401
402         // Close file
403         $CACHE->cache_close();
404 }
405
406 //
407 ?>