2 /************************************************************************
3 * MXChange v0.2.1 Start: 11/28/2004 *
4 * =============== Last change: 11/28/2004 *
6 * -------------------------------------------------------------------- *
7 * File : load_cache.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Load more cache files *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Mehr Cache-Dateien nachladen *
12 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
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. *
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. *
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, *
32 ************************************************************************/
34 // Some security stuff...
35 if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
37 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
41 // Let's start with the admins table...
42 if (($CACHE->cache_file("admins", true) == true))
46 $ADMINS = $CACHE->cache_load();
49 if (is_array($ADMINS['login']) && is_array($ADMINS['def_acl']) && is_array($ADMINS['aid']))
52 if (count($ADMINS['login']) == count($ADMINS['aid']) && count($ADMINS['login']) == count($ADMINS['def_acl']) && count($ADMINS['aid']) == count($ADMINS['def_acl']))
54 //* DEBUG: */ echo "<PRE>";
55 //* DEBUG: */ print_r($ADMINS);
57 // The cache file seems to be fine
58 foreach ($ADMINS['login'] as $k=>$login)
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];
65 // Some extra data depening on version
66 if (GET_EXT_VERSION("admins") >= "0.3")
68 $ADMINS['def_acl'][$login] = $ADMINS['def_acl'][$k];
69 if (GET_EXT_VERSION("admins") >= "0.6.7")
71 $ADMINS['la_mode'][$login] = $ADMINS['la_mode'][$k];
75 //* DEBUG: */ print_r($ADMINS);
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]);
85 //* DEBUG: */ print_r($ADMINS);
88 foreach ($ADMINS['login'] as $k=>$login)
90 $ADMINS['login'][$ADMINS['aid'][$login]] = $login;
91 if (!in_array($k, $ADMINS['aid']))
93 unset($ADMINS['login'][$k]);
97 //* DEBUG: */ echo "****\n";
98 //* DEBUG: */ print_r($ADMINS);
99 //* DEBUG: */ echo "</PRE>";
104 // Nope, cache file is corrupted!
105 $CACHE->cache_destroy();
110 // Nope, cache file is corrupted!
111 $CACHE->cache_destroy();
115 elseif (($CONFIG['cache_admins'] == 'Y') && ($CSS != "1") && ($CSS != "-1"))
118 $CACHE->cache_init("ADMINS");
120 // Load every data from DB to cache file
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";
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))
131 $CACHE->add_row($dummy);
135 SQL_FREERESULT($result_admins);
139 $CACHE->cache_close();
141 // Next cached table is the module registry (mod_reg)...
142 if ($CACHE->cache_file("mod_reg", true) == true)
146 $MODULES = $CACHE->cache_load();
150 foreach ($MODULES as $k=>$array)
152 $CNT += count($array);
155 // When there is a period (.) in the result this test will fail and so the cache file is
158 if (count($MODULES) > 0 ) $TEST = ($CNT / (count($MODULES)));
159 if ($TEST != bigintval($TEST))
161 // Cache file is corrupted!
162 $CACHE->cache_destroy();
167 // Rewrite module cache
169 foreach ($MODULES['module'] as $key=>$mod)
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]);
188 elseif (($CONFIG['cache_modreg'] == 'Y') && ($CSS != "1") && ($CSS != "-1"))
190 // Create cache file here
191 $CACHE->cache_init("MODULES");
193 // Load all modules and their data
194 if (GET_EXT_VERSION("sql_patches") >= "0.3.6")
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__);
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__);
206 while ($DATA = SQL_FETCHARRAY($result))
208 // Add row to cache file
209 $CACHE->add_row($DATA);
213 SQL_FREERESULT($result);
217 $CACHE->cache_close();
219 // Next cached table is the configuration (config)...
220 if ($CACHE->cache_file("config", true) == true)
222 // Load config from cache
224 $CFG_CACHE = $CACHE->cache_load();
228 foreach ($CFG_CACHE as $k=>$array)
230 $CNT += count($array);
233 // When there is a period (.) in the result this test will fail and so the cache file is
236 if (count($CFG_CACHE) > 0 ) $TEST = ($CNT / (count($CFG_CACHE)));
237 if ($TEST != bigintval($TEST))
239 // Cache file is corrupted!
240 $CACHE->cache_destroy();
244 elseif (($CONFIG['cache_config'] == 'Y') && ($CSS != "1") && ($CSS != "-1"))
246 // Create cache file here
247 $CACHE->cache_init("CONFIG");
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))
253 // Add row to cache file
254 $CACHE->add_row($DATA);
258 SQL_FREERESULT($result);
262 $CACHE->cache_close();
264 // Next cached table is the referral system (refsystem)...
265 if ($CACHE->cache_file("refsystem", true) == true)
267 // Load referral system from cache
269 $REF_SYSTEM = $CACHE->cache_load();
273 foreach ($REF_SYSTEM as $k=>$array)
275 $CNT += count($array);
278 // When there is a period (.) in the result this test will fail and so the cache file is
281 if (count($REF_SYSTEM) > 0 ) $TEST = ($CNT / (count($REF_SYSTEM)));
282 if ($TEST != bigintval($TEST))
284 // Cache file is corrupted!
285 $CACHE->cache_destroy();
289 elseif (($CONFIG['cache_refsys'] == 'Y') && ($CSS != "1") && ($CSS != "-1"))
291 // Create cache file here
292 $CACHE->cache_init("REFSYSTEM");
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))
298 // Add row to cache file
299 $CACHE->add_row($DATA);
303 SQL_FREERESULT($result);
307 $CACHE->cache_close();
309 // Next cached table is the referral system (refdepths)...
310 if ($CACHE->cache_file("refdepths", true) == true)
312 // Load referral system from cache
314 $REF_DEPTHS = $CACHE->cache_load();
318 foreach ($REF_DEPTHS as $k=>$array)
320 $CNT += count($array);
323 // When there is a period (.) in the result this test will fail and so the cache file is
326 if (count($REF_DEPTHS) > 0 ) $TEST = ($CNT / (count($REF_DEPTHS)));
327 if ($TEST != bigintval($TEST))
329 // Cache file is corrupted!
330 $CACHE->cache_destroy();
334 elseif (($CONFIG['cache_refdepth'] == 'Y') && ($CSS != "1") && ($CSS != "-1"))
336 // Create cache file here
337 $CACHE->cache_init("REFDEPTHS");
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))
343 // Add row to cache file
344 $CACHE->add_row($DATA);
348 SQL_FREERESULT($result);
352 $CACHE->cache_close();
354 // Next cached table is the referral system (admins_acls)...
355 if (GET_EXT_VERSION("admins") >= "0.3")
357 // Check for cache file
358 if ($CACHE->cache_file("admins_acls", true) == true)
360 // Load referral system from cache
362 $ADMINS_ACLS = $CACHE->cache_load();
366 foreach ($ADMINS_ACLS as $k=>$array)
368 $CNT += count($array);
371 // When there is a period (.) in the result this test will fail and so the cache file is
373 if (count($ADMINS_ACLS) > 0)
376 if (count($ADMINS_ACLS) > 0 ) $TEST = ($CNT / (count($ADMINS_ACLS)));
377 if ($TEST != bigintval($TEST))
379 // Cache file is corrupted!
380 $CACHE->cache_destroy();
385 elseif (($CONFIG['cache_acls'] == 'Y') && ($CSS != "1") && ($CSS != "-1"))
387 // Create cache file here
388 $CACHE->cache_init("ADMINS_ACLS");
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))
394 // Add row to cache file
395 $CACHE->add_row($DATA);
399 SQL_FREERESULT($result);
403 $CACHE->cache_close();