wernis extension is now alpha code (only listing in admin area is missing), naming...
[mailer.git] / 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         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 }
39
40 // Let's start with the admins table...
41 if (($CACHE->cache_file("admins", true) == true)) {
42         // Load cache
43         global $ADMINS;
44         $ADMINS = $CACHE->cache_load();
45
46         // Check if valid
47         if ((is_array($ADMINS['login'])) && (is_array($ADMINS['aid']))) {
48                 // Check count
49                 if (count($ADMINS['login']) == count($ADMINS['aid'])) {
50                         //* DEBUG: */ echo "<PRE>";
51                         //* DEBUG: */ print_r($ADMINS);
52
53                         // The cache file seems to be fine
54                         foreach ($ADMINS['login'] as $k=>$login) {
55                                 // Rewrite default_acl
56                                 $ADMINS['aid'][$login]      = $ADMINS['aid'][$k];
57                                 $ADMINS['password'][$login] = $ADMINS['password'][$k];
58                                 $ADMINS['email'][$login]    = $ADMINS['email'][$k];
59
60                                 // Some extra data depening on version
61                                 if (GET_EXT_VERSION("admins") >= "0.3") {
62                                         $ADMINS['def_acl'][$login]  = $ADMINS['def_acl'][$k];
63                                         if (GET_EXT_VERSION("admins") >= "0.6.7") {
64                                                 $ADMINS['la_mode'][$login]  = $ADMINS['la_mode'][$k];
65                                         }
66                                 }
67
68                                 //* DEBUG: */ print_r($ADMINS);
69
70                                 // Clear array
71                                 if (isset($ADMINS['aid'][$k]))          unset($ADMINS['aid'][$k]);
72                                 if (isset($ADMINS['def_acl'][$k]))      unset($ADMINS['def_acl'][$k]);
73                                 if (isset($ADMINS['la_mode'][$k]))      unset($ADMINS['la_mode'][$k]);
74                                 if (isset($ADMINS['password'][$k]))     unset($ADMINS['password'][$k]);
75                                 if (isset($ADMINS['email'][$k]))        unset($ADMINS['email'][$k]);
76                         }
77
78                         //* DEBUG: */ print_r($ADMINS);
79
80                         // Rewrite Login
81                         foreach ($ADMINS['login'] as $k=>$login) {
82                                 $ADMINS['login'][$ADMINS['aid'][$login]] = $login;
83                                 if (!in_array($k, $ADMINS['aid'])) {
84                                         unset($ADMINS['login'][$k]);
85                                 }
86                         }
87
88                         //* DEBUG: */ echo "****\n";
89                         //* DEBUG: */ print_r($ADMINS);
90                         //* DEBUG: */ echo "</PRE>";
91                         //* DEBUG: */ die();
92                 } else {
93                         // Nope, cache file is corrupted!
94                         $CACHE->cache_destroy();
95                 }
96         } else {
97                 // Nope, cache file is corrupted!
98                 $CACHE->cache_destroy();
99                 unset($ADMINS);
100         }
101 } elseif (($_CONFIG['cache_admins'] == 'Y') && ($CSS != "1") && ($CSS != "-1")) {
102         // Create cache file
103         $CACHE->cache_init("ADMINS");
104
105         // Load every data from DB to cache file
106         $ADD = ", id, id";
107         if (GET_EXT_VERSION("admins") >= "0.3")   $ADD  = ", default_acl AS def_acl";
108         if (GET_EXT_VERSION("admins") >= "0.6.7") $ADD .= ", la_mode";
109
110         // Query the database about this
111         $result_admins = SQL_QUERY("SELECT id AS aid, login, password, email".$ADD."
112 FROM "._MYSQL_PREFIX."_admins
113 ORDER BY login", __FILE__, __LINE__);
114         while($dummy = SQL_FETCHARRAY($result_admins)) {
115                 // Save row
116                 $CACHE->add_row($dummy);
117         }
118
119         // Free memory
120         SQL_FREERESULT($result_admins);
121 }
122
123 // Close file
124 $CACHE->cache_close();
125
126 // Next cached table is the module registry (mod_reg)...
127 if ($CACHE->cache_file("mod_reg", true) == true) {
128         // Load cache
129         global $MODULES;
130         $MODULES = $CACHE->cache_load();
131
132         // Valid cache file
133         $CNT = 0;
134         foreach ($MODULES as $k=>$array) {
135                 $CNT += count($array);
136         }
137
138         // When there is a period (.) in the result this test will fail and so the cache file is
139         // damaged/corrupted
140         $TEST = "failed";
141         if (count($MODULES) > 0 ) $TEST = ($CNT / (count($MODULES)));
142         if ($TEST != bigintval($TEST)) {
143                 // Cache file is corrupted!
144                 $CACHE->cache_destroy();
145                 unset($MODULES);
146         } else {
147                 // Rewrite module cache
148                 $MOD = $MODULES;
149                 foreach ($MODULES['module'] as $key=>$mod) {
150                         $MODULES['id'][$mod] = $MODULES['id'][$key];
151                         unset($MODULES['id'][$key]);
152                         $MODULES['title'][$mod] = $MODULES['title'][$key];
153                         unset($MODULES['title'][$key]);
154                         $MODULES['locked'][$mod] = $MODULES['locked'][$key];
155                         unset($MODULES['locked'][$key]);
156                         $MODULES['hidden'][$mod] = $MODULES['hidden'][$key];
157                         unset($MODULES['hidden'][$key]);
158                         $MODULES['admin_only'][$mod] = $MODULES['admin_only'][$key];
159                         unset($MODULES['admin_only'][$key]);
160                         $MODULES['mem_only'][$mod] = $MODULES['mem_only'][$key];
161                         unset($MODULES['mem_only'][$key]);
162                         $MODULES['has_menu'][$mod] = $MODULES['has_menu'][$key];
163                         unset($MODULES['has_menu'][$key]);
164                 }
165         }
166 } elseif (($_CONFIG['cache_modreg'] == 'Y') && ($CSS != "1") && ($CSS != "-1")) {
167         // Create cache file here
168         $CACHE->cache_init("MODULES");
169
170         // Load all modules and their data
171         if (GET_EXT_VERSION("sql_patches") >= "0.3.6") {
172                 // Load has_menu
173                 $result = SQL_QUERY("SELECT id, module, title, locked, hidden, admin_only, title, mem_only, has_menu
174 FROM "._MYSQL_PREFIX."_mod_reg ORDER BY id", __FILE__, __LINE__);
175         } else {
176                 // Don't load has_menu
177                 $result = SQL_QUERY("SELECT id, module, title, locked, hidden, admin_only, title, mem_only
178 FROM "._MYSQL_PREFIX."_mod_reg ORDER BY id", __FILE__, __LINE__);
179         }
180         while ($DATA = SQL_FETCHARRAY($result)) {
181                 // Add row to cache file
182                 $CACHE->add_row($DATA);
183         }
184
185         // Free memory
186         SQL_FREERESULT($result);
187 }
188
189 // Close file
190 $CACHE->cache_close();
191
192 // Next cached table is the configuration (config)...
193 if ($CACHE->cache_file("config", true) == true) {
194         // Load config from cache
195         global $CFG_CACHE;
196         $CFG_CACHE = $CACHE->cache_load();
197
198         // Valid cache file
199         $CNT = 0;
200         foreach ($CFG_CACHE as $k=>$array) {
201                 $CNT += count($array);
202         }
203
204         // When there is a period (.) in the result this test will fail and so the cache file is
205         // damaged/corrupted
206         $TEST = "failed";
207         if (count($CFG_CACHE) > 0 ) $TEST = ($CNT / (count($CFG_CACHE)));
208         if ($TEST != bigintval($TEST)) {
209                 // Cache file is corrupted!
210                 $CACHE->cache_destroy();
211                 unset($CFG_CACHE);
212         }
213 } elseif (($_CONFIG['cache_config'] == 'Y') && ($CSS != "1") && ($CSS != "-1")) {
214         // Create cache file here
215         $CACHE->cache_init("CONFIG");
216
217         // Load all modules and their data
218         $result = SQL_QUERY("SELECT * FROM "._MYSQL_PREFIX."_config ORDER BY config", __FILE__, __LINE__);
219         while ($DATA = SQL_FETCHARRAY($result)) {
220                 // Add row to cache file
221                 $CACHE->add_row($DATA);
222         }
223
224         // Free memory
225         SQL_FREERESULT($result);
226 }
227
228 // Close file
229 $CACHE->cache_close();
230
231 // Next cached table is the referral system (refsystem)...
232 if ($CACHE->cache_file("refsystem", true) == true) {
233         // Load referral system from cache
234         global $REF_SYSTEM;
235         $REF_SYSTEM = $CACHE->cache_load();
236
237         // Valid cache file
238         $CNT = 0;
239         foreach ($REF_SYSTEM as $k=>$array) {
240                 $CNT += count($array);
241         }
242
243         // When there is a period (.) in the result this test will fail and so the cache file is
244         // damaged/corrupted
245         $TEST = "failed";
246         if (count($REF_SYSTEM) > 0 ) $TEST = ($CNT / (count($REF_SYSTEM)));
247         if ($TEST != bigintval($TEST)) {
248                 // Cache file is corrupted!
249                 $CACHE->cache_destroy();
250                 unset($REF_SYSTEM);
251         }
252 } elseif (($_CONFIG['cache_refsys'] == 'Y') && ($CSS != "1") && ($CSS != "-1")) {
253         // Create cache file here
254         $CACHE->cache_init("REFSYSTEM");
255
256         // Load all modules and their data
257         $result = SQL_QUERY("SELECT id, userid, level, counter FROM "._MYSQL_PREFIX."_refsystem ORDER BY userid, level", __FILE__, __LINE__);
258         while ($DATA = SQL_FETCHARRAY($result)) {
259                 // Add row to cache file
260                 $CACHE->add_row($DATA);
261         }
262
263         // Free memory
264         SQL_FREERESULT($result);
265 }
266
267 // Close file
268 $CACHE->cache_close();
269
270 // Next cached table is the referral system (refdepths)...
271 if ($CACHE->cache_file("refdepths", true) == true) {
272         // Load referral system from cache
273         global $REF_DEPTHS;
274         $REF_DEPTHS = $CACHE->cache_load();
275
276         // Valid cache file
277         $CNT = 0;
278         foreach ($REF_DEPTHS as $k=>$array) {
279                 $CNT += count($array);
280         }
281
282         // When there is a period (.) in the result this test will fail and so the cache file is
283         // damaged/corrupted
284         $TEST = "failed";
285         if (count($REF_DEPTHS) > 0 ) $TEST = ($CNT / (count($REF_DEPTHS)));
286         if ($TEST != bigintval($TEST)) {
287                 // Cache file is corrupted!
288                 $CACHE->cache_destroy();
289                 unset($REF_DEPTHS);
290         }
291 } elseif (($_CONFIG['cache_refdepth'] == 'Y') && ($CSS != "1") && ($CSS != "-1")) {
292         // Create cache file here
293         $CACHE->cache_init("REFDEPTHS");
294
295         // Load all modules and their data
296         $result = SQL_QUERY("SELECT id, level, percents FROM "._MYSQL_PREFIX."_refdepths ORDER BY level", __FILE__, __LINE__);
297         while ($DATA = SQL_FETCHARRAY($result)) {
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 (admins_acls)...
310 if (GET_EXT_VERSION("admins") >= "0.3") {
311         // Check for cache file
312         if ($CACHE->cache_file("admins_acls", true) == true) {
313                 // Load referral system from cache
314                 global $ADMINS_ACLS;
315                 $ADMINS_ACLS = $CACHE->cache_load();
316
317                 // Valid cache file
318                 $CNT = 0;
319                 foreach ($ADMINS_ACLS as $k=>$array) {
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                 if (count($ADMINS_ACLS) > 0) {
326                         $TEST = "failed";
327                         if (count($ADMINS_ACLS) > 0 ) $TEST = ($CNT / (count($ADMINS_ACLS)));
328                         if ($TEST != bigintval($TEST)) {
329                                 // Cache file is corrupted!
330                                 $CACHE->cache_destroy();
331                                 unset($ADMINS_ACLS);
332                         }
333                 }
334         } elseif (($_CONFIG['cache_acls'] == 'Y') && ($CSS != "1") && ($CSS != "-1")) {
335                 // Create cache file here
336                 $CACHE->cache_init("ADMINS_ACLS");
337
338                 // Load all modules and their data
339                 $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__);
340                 while ($DATA = SQL_FETCHARRAY($result)) {
341                         // Add row to cache file
342                         $CACHE->add_row($DATA);
343                 }
344
345                 // Free memory
346                 SQL_FREERESULT($result);
347         }
348
349         // Close file
350         $CACHE->cache_close();
351 }
352
353 //
354 ?>