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'])) {
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
40 // Let's start with the admins table...
41 if (($CACHE->cache_file("admins", true) == true)) {
44 $ADMINS = $CACHE->cache_load();
47 if ((is_array($ADMINS['login'])) && (is_array($ADMINS['aid']))) {
49 if (count($ADMINS['login']) == count($ADMINS['aid'])) {
50 //* DEBUG: */ echo "<PRE>";
51 //* DEBUG: */ print_r($ADMINS);
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];
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];
68 //* DEBUG: */ print_r($ADMINS);
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]);
78 //* DEBUG: */ print_r($ADMINS);
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]);
88 //* DEBUG: */ echo "****\n";
89 //* DEBUG: */ print_r($ADMINS);
90 //* DEBUG: */ echo "</PRE>";
93 // Nope, cache file is corrupted!
94 $CACHE->cache_destroy();
97 // Nope, cache file is corrupted!
98 $CACHE->cache_destroy();
101 } elseif (($_CONFIG['cache_admins'] == 'Y') && ($CSS != "1") && ($CSS != "-1")) {
103 $CACHE->cache_init("ADMINS");
105 // Load every data from DB to cache file
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";
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)) {
116 $CACHE->add_row($dummy);
120 SQL_FREERESULT($result_admins);
124 $CACHE->cache_close();
126 // Next cached table is the module registry (mod_reg)...
127 if ($CACHE->cache_file("mod_reg", true) == true) {
130 $MODULES = $CACHE->cache_load();
134 foreach ($MODULES as $k=>$array) {
135 $CNT += count($array);
138 // When there is a period (.) in the result this test will fail and so the cache file is
141 if (count($MODULES) > 0 ) $TEST = ($CNT / (count($MODULES)));
142 if ($TEST != bigintval($TEST)) {
143 // Cache file is corrupted!
144 $CACHE->cache_destroy();
147 // Rewrite module cache
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]);
166 } elseif (($_CONFIG['cache_modreg'] == 'Y') && ($CSS != "1") && ($CSS != "-1")) {
167 // Create cache file here
168 $CACHE->cache_init("MODULES");
170 // Load all modules and their data
171 if (GET_EXT_VERSION("sql_patches") >= "0.3.6") {
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__);
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__);
180 while ($DATA = SQL_FETCHARRAY($result)) {
181 // Add row to cache file
182 $CACHE->add_row($DATA);
186 SQL_FREERESULT($result);
190 $CACHE->cache_close();
192 // Next cached table is the configuration (config)...
193 if ($CACHE->cache_file("config", true) == true) {
194 // Load config from cache
196 $CFG_CACHE = $CACHE->cache_load();
200 foreach ($CFG_CACHE as $k=>$array) {
201 $CNT += count($array);
204 // When there is a period (.) in the result this test will fail and so the cache file is
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();
213 } elseif (($_CONFIG['cache_config'] == 'Y') && ($CSS != "1") && ($CSS != "-1")) {
214 // Create cache file here
215 $CACHE->cache_init("CONFIG");
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);
225 SQL_FREERESULT($result);
229 $CACHE->cache_close();
231 // Next cached table is the referral system (refsystem)...
232 if ($CACHE->cache_file("refsystem", true) == true) {
233 // Load referral system from cache
235 $REF_SYSTEM = $CACHE->cache_load();
239 foreach ($REF_SYSTEM as $k=>$array) {
240 $CNT += count($array);
243 // When there is a period (.) in the result this test will fail and so the cache file is
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();
252 } elseif (($_CONFIG['cache_refsys'] == 'Y') && ($CSS != "1") && ($CSS != "-1")) {
253 // Create cache file here
254 $CACHE->cache_init("REFSYSTEM");
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);
264 SQL_FREERESULT($result);
268 $CACHE->cache_close();
270 // Next cached table is the referral system (refdepths)...
271 if ($CACHE->cache_file("refdepths", true) == true) {
272 // Load referral system from cache
274 $REF_DEPTHS = $CACHE->cache_load();
278 foreach ($REF_DEPTHS as $k=>$array) {
279 $CNT += count($array);
282 // When there is a period (.) in the result this test will fail and so the cache file is
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();
291 } elseif (($_CONFIG['cache_refdepth'] == 'Y') && ($CSS != "1") && ($CSS != "-1")) {
292 // Create cache file here
293 $CACHE->cache_init("REFDEPTHS");
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);
303 SQL_FREERESULT($result);
307 $CACHE->cache_close();
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
315 $ADMINS_ACLS = $CACHE->cache_load();
319 foreach ($ADMINS_ACLS 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
325 if (count($ADMINS_ACLS) > 0) {
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();
334 } elseif (($_CONFIG['cache_acls'] == 'Y') && ($CSS != "1") && ($CSS != "-1")) {
335 // Create cache file here
336 $CACHE->cache_init("ADMINS_ACLS");
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);
346 SQL_FREERESULT($result);
350 $CACHE->cache_close();