Tons of rewrites (SQL queries), surfbar nearly finished (working: surfing with static...
[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 (($cacheInstance->cache_file("admins", true) == true)) {
42         // Load cache
43         global $cacheArray;
44         $cacheArray['admins'] = $cacheInstance->cache_load();
45
46         // Check if valid
47         if ((is_array($cacheArray['admins']['login'])) && (is_array($cacheArray['admins']['aid']))) {
48                 // Check count
49                 if (count($cacheArray['admins']['login']) == count($cacheArray['admins']['aid'])) {
50                         //* DEBUG: */ echo "<PRE>";
51                         //* DEBUG: */ print_r($cacheArray['admins']);
52
53                         // The cache file seems to be fine
54                         foreach ($cacheArray['admins']['login'] as $k=>$login) {
55                                 // Rewrite default_acl
56                                 $cacheArray['admins']['aid'][$login]      = $cacheArray['admins']['aid'][$k];
57                                 $cacheArray['admins']['password'][$login] = $cacheArray['admins']['password'][$k];
58                                 $cacheArray['admins']['email'][$login]    = $cacheArray['admins']['email'][$k];
59
60                                 // Some extra data depening on version
61                                 if (GET_EXT_VERSION("admins") >= "0.3") {
62                                         $cacheArray['admins']['def_acl'][$login]  = $cacheArray['admins']['def_acl'][$k];
63                                         if (GET_EXT_VERSION("admins") >= "0.6.7") {
64                                                 $cacheArray['admins']['la_mode'][$login]  = $cacheArray['admins']['la_mode'][$k];
65                                         }
66                                 }
67
68                                 //* DEBUG: */ print_r($cacheArray['admins']);
69
70                                 // Clear array
71                                 if (isset($cacheArray['admins']['aid'][$k]))            unset($cacheArray['admins']['aid'][$k]);
72                                 if (isset($cacheArray['admins']['def_acl'][$k]))        unset($cacheArray['admins']['def_acl'][$k]);
73                                 if (isset($cacheArray['admins']['la_mode'][$k]))        unset($cacheArray['admins']['la_mode'][$k]);
74                                 if (isset($cacheArray['admins']['password'][$k]))       unset($cacheArray['admins']['password'][$k]);
75                                 if (isset($cacheArray['admins']['email'][$k]))  unset($cacheArray['admins']['email'][$k]);
76                         }
77
78                         //* DEBUG: */ print_r($cacheArray['admins']);
79
80                         // Rewrite Login
81                         foreach ($cacheArray['admins']['login'] as $k=>$login) {
82                                 $cacheArray['admins']['login'][$cacheArray['admins']['aid'][$login]] = $login;
83                                 if (!in_array($k, $cacheArray['admins']['aid'])) {
84                                         unset($cacheArray['admins']['login'][$k]);
85                                 }
86                         }
87
88                         //* DEBUG: */ echo "****\n";
89                         //* DEBUG: */ print_r($cacheArray['admins']);
90                         //* DEBUG: */ echo "</PRE>";
91                         //* DEBUG: */ die();
92                 } else {
93                         // Nope, cache file is corrupted!
94                         $cacheInstance->cache_destroy();
95                 }
96         } else {
97                 // Nope, cache file is corrupted!
98                 $cacheInstance->cache_destroy();
99                 unset($cacheArray['admins']);
100         }
101 } elseif (($_CONFIG['cache_admins'] == "Y") && ($CSS != "1") && ($CSS != "-1")) {
102         // Create cache file
103         $cacheInstance->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                 $cacheInstance->add_row($dummy);
117         }
118
119         // Free memory
120         SQL_FREERESULT($result_admins);
121 }
122
123 // Close file
124 $cacheInstance->cache_close();
125
126 // Next cached table is the module registry (mod_reg)...
127 if ($cacheInstance->cache_file("mod_reg", true) == true) {
128         // Load cache
129         global $cacheArray;
130         $cacheArray['modules'] = $cacheInstance->cache_load();
131
132         // Valid cache file
133         $CNT = 0;
134         foreach ($cacheArray['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($cacheArray['modules']) > 0 ) $TEST = ($CNT / (count($cacheArray['modules'])));
142         if ($TEST != bigintval($TEST)) {
143                 // Cache file is corrupted!
144                 $cacheInstance->cache_destroy();
145                 unset($cacheArray['modules']);
146         } else {
147                 // Rewrite module cache
148                 $modArray = $cacheArray['modules'];
149                 foreach ($modArray['module'] as $key=>$mod) {
150                         $cacheArray['modules']['id'][$mod] = $modArray['id'][$key];
151                         unset($cacheArray['modules']['id'][$key]);
152                         $cacheArray['modules']['title'][$mod] = $modArray['title'][$key];
153                         unset($cacheArray['modules']['title'][$key]);
154                         $cacheArray['modules']['locked'][$mod] = $modArray['locked'][$key];
155                         unset($cacheArray['modules']['locked'][$key]);
156                         $cacheArray['modules']['hidden'][$mod] = $modArray['hidden'][$key];
157                         unset($cacheArray['modules']['hidden'][$key]);
158                         $cacheArray['modules']['admin_only'][$mod] = $modArray['admin_only'][$key];
159                         unset($cacheArray['modules']['admin_only'][$key]);
160                         $cacheArray['modules']['mem_only'][$mod] = $modArray['mem_only'][$key];
161                         unset($cacheArray['modules']['mem_only'][$key]);
162                         if (isset($cacheArray['modules']['has_menu'][$key])) {
163                                 $cacheArray['modules']['has_menu'][$mod] = $modArray['has_menu'][$key];
164                                 unset($cacheArray['modules']['has_menu'][$key]);
165                         } // END - if
166                 }
167                 unset($modArray);
168         }
169 } elseif (($_CONFIG['cache_modreg'] == "Y") && ($CSS != "1") && ($CSS != "-1")) {
170         // Create cache file here
171         $cacheInstance->cache_init("MODULES");
172
173         // Load all modules and their data
174         if (GET_EXT_VERSION("sql_patches") >= "0.3.6") {
175                 // Load has_menu
176                 $result = SQL_QUERY("SELECT id, module, title, locked, hidden, admin_only, title, mem_only, has_menu
177 FROM "._MYSQL_PREFIX."_mod_reg ORDER BY id", __FILE__, __LINE__);
178         } else {
179                 // Don't load has_menu
180                 $result = SQL_QUERY("SELECT id, module, title, locked, hidden, admin_only, title, mem_only
181 FROM "._MYSQL_PREFIX."_mod_reg ORDER BY id", __FILE__, __LINE__);
182         }
183         while ($DATA = SQL_FETCHARRAY($result)) {
184                 // Add row to cache file
185                 $cacheInstance->add_row($DATA);
186         }
187
188         // Free memory
189         SQL_FREERESULT($result);
190 }
191
192 // Close file
193 $cacheInstance->cache_close();
194
195 // Next cached table is the configuration (config)...
196 if ($cacheInstance->cache_file("config", true) == true) {
197         // Load config from cache
198         global $cacheArray;
199         $cacheArrayConfig = $cacheInstance->cache_load();
200
201         // Valid cache file
202         $CNT = 0; $newCache = array();
203         foreach ($cacheArrayConfig as $key=>$array) {
204                 foreach ($array as $key2=>$value) {
205                         $newCache[$key2][$key] = $value;
206                 }
207                 $CNT += count($array);
208         }
209
210         // Overwrite the config with the cache version
211         $cacheArray['config'] = $newCache;
212         unset($newCache);
213
214         // When there is a period (.) in the result this test will fail and so the cache file is
215         // damaged/corrupted
216         $TEST = "failed";
217         if (count($cacheArray['config']) > 0 ) $TEST = ($CNT / (count($cacheArray['config'])));
218         if ($TEST != bigintval($TEST)) {
219                 // Cache file is corrupted!
220                 $cacheInstance->cache_destroy();
221                 unset($cacheArray['config']);
222         }
223 } elseif (($_CONFIG['cache_config'] == "Y") && ($CSS != "1") && ($CSS != "-1")) {
224         // Create cache file here
225         $cacheInstance->cache_init("CONFIG");
226
227         // Load all modules and their data
228         $result = SQL_QUERY("SELECT * FROM "._MYSQL_PREFIX."_config ORDER BY config", __FILE__, __LINE__);
229         while ($DATA = SQL_FETCHARRAY($result)) {
230                 // Add row to cache file
231                 $cacheInstance->add_row($DATA);
232         }
233
234         // Free memory
235         SQL_FREERESULT($result);
236 }
237
238 // Close file
239 $cacheInstance->cache_close();
240
241 // Next cached table is the referral system (refsystem)...
242 if ($cacheInstance->cache_file("refsystem", true) == true) {
243         // Load referral system from cache
244         global $cacheArray;
245         $cacheArray['ref_system'] = $cacheInstance->cache_load();
246
247         // Valid cache file
248         $CNT = 0;
249         foreach ($cacheArray['ref_system'] as $k=>$array) {
250                 $CNT += count($array);
251         }
252
253         // When there is a period (.) in the result this test will fail and so the cache file is
254         // damaged/corrupted
255         $TEST = "failed";
256         if (count($cacheArray['ref_system']) > 0 ) $TEST = ($CNT / (count($cacheArray['ref_system'])));
257         if ($TEST != bigintval($TEST)) {
258                 // Cache file is corrupted!
259                 $cacheInstance->cache_destroy();
260                 unset($cacheArray['ref_system']);
261         }
262 } elseif (($_CONFIG['cache_refsys'] == "Y") && ($CSS != "1") && ($CSS != "-1")) {
263         // Create cache file here
264         $cacheInstance->cache_init("refsystem");
265
266         // Load all modules and their data
267         $result = SQL_QUERY("SELECT id, userid, level, counter FROM "._MYSQL_PREFIX."_refsystem ORDER BY userid, level", __FILE__, __LINE__);
268         while ($DATA = SQL_FETCHARRAY($result)) {
269                 // Add row to cache file
270                 $cacheInstance->add_row($DATA);
271         }
272
273         // Free memory
274         SQL_FREERESULT($result);
275 }
276
277 // Close file
278 $cacheInstance->cache_close();
279
280 // Next cached table is the referral system (refdepths)...
281 if ($cacheInstance->cache_file("refdepths", true) == true) {
282         // Load referral system from cache
283         global $cacheArray;
284         $cacheArray['ref_depths'] = $cacheInstance->cache_load();
285
286         // Valid cache file
287         $CNT = 0;
288         foreach ($cacheArray['ref_depths'] as $k=>$array) {
289                 $CNT += count($array);
290         }
291
292         // When there is a period (.) in the result this test will fail and so the cache file is
293         // damaged/corrupted
294         $TEST = "failed";
295         if (count($cacheArray['ref_depths']) > 0 ) $TEST = ($CNT / (count($cacheArray['ref_depths'])));
296         if ($TEST != bigintval($TEST)) {
297                 // Cache file is corrupted!
298                 $cacheInstance->cache_destroy();
299                 unset($cacheArray['ref_depths']);
300         }
301 } elseif (($_CONFIG['cache_refdepth'] == "Y") && ($CSS != "1") && ($CSS != "-1")) {
302         // Create cache file here
303         $cacheInstance->cache_init("REFDEPTHS");
304
305         // Load all modules and their data
306         $result = SQL_QUERY("SELECT id, level, percents FROM "._MYSQL_PREFIX."_refdepths ORDER BY level", __FILE__, __LINE__);
307         while ($DATA = SQL_FETCHARRAY($result)) {
308                 // Add row to cache file
309                 $cacheInstance->add_row($DATA);
310         }
311
312         // Free memory
313         SQL_FREERESULT($result);
314 }
315
316 // Close file
317 $cacheInstance->cache_close();
318
319 // Next cached table is the referral system (admins_acls)...
320 if (GET_EXT_VERSION("admins") >= "0.3") {
321         // Check for cache file
322         if ($cacheInstance->cache_file("admins_acls", true) == true) {
323                 // Load referral system from cache
324                 global $cacheArray;
325                 $cacheArray['admin_acls'] = $cacheInstance->cache_load();
326
327                 // Valid cache file
328                 $CNT = 0;
329                 foreach ($cacheArray['admin_acls'] as $k=>$array) {
330                         $CNT += count($array);
331                 }
332
333                 // When there is a period (.) in the result this test will fail and so the cache file is
334                 // damaged/corrupted
335                 if (count($cacheArray['admin_acls']) > 0) {
336                         $TEST = "failed";
337                         if (count($cacheArray['admin_acls']) > 0 ) $TEST = ($CNT / (count($cacheArray['admin_acls'])));
338                         if ($TEST != bigintval($TEST)) {
339                                 // Cache file is corrupted!
340                                 $cacheInstance->cache_destroy();
341                                 unset($cacheArray['admin_acls']);
342                         }
343                 }
344         } elseif (($_CONFIG['cache_acls'] == "Y") && ($CSS != "1") && ($CSS != "-1")) {
345                 // Create cache file here
346                 $cacheInstance->cache_init("ADMINS_ACLS");
347
348                 // Load all modules and their data
349                 $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__);
350                 while ($DATA = SQL_FETCHARRAY($result)) {
351                         // Add row to cache file
352                         $cacheInstance->add_row($DATA);
353                 }
354
355                 // Free memory
356                 SQL_FREERESULT($result);
357         }
358
359         // Close file
360         $cacheInstance->cache_close();
361 }
362
363 //
364 ?>