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 (($cacheInstance->cache_file("admins", true) == true)) {
44 $cacheArray['admins'] = $cacheInstance->cache_load();
47 if ((is_array($cacheArray['admins']['login'])) && (is_array($cacheArray['admins']['aid']))) {
49 if (count($cacheArray['admins']['login']) == count($cacheArray['admins']['aid'])) {
50 //* DEBUG: */ echo "<PRE>";
51 //* DEBUG: */ print_r($cacheArray['admins']);
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];
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];
68 //* DEBUG: */ print_r($cacheArray['admins']);
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]);
78 //* DEBUG: */ print_r($cacheArray['admins']);
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]);
88 //* DEBUG: */ echo "****\n";
89 //* DEBUG: */ print_r($cacheArray['admins']);
90 //* DEBUG: */ echo "</PRE>";
93 // Nope, cache file is corrupted!
94 $cacheInstance->cache_destroy();
97 // Nope, cache file is corrupted!
98 $cacheInstance->cache_destroy();
99 unset($cacheArray['admins']);
101 } elseif (($_CONFIG['cache_admins'] == 'Y') && ($CSS != "1") && ($CSS != "-1")) {
103 $cacheInstance->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 $cacheInstance->add_row($dummy);
120 SQL_FREERESULT($result_admins);
124 $cacheInstance->cache_close();
126 // Next cached table is the module registry (mod_reg)...
127 if ($cacheInstance->cache_file("mod_reg", true) == true) {
130 $cacheArray['modules'] = $cacheInstance->cache_load();
134 foreach ($cacheArray['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($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']);
147 // Rewrite module cache
148 $MOD = $cacheArray['modules'];
149 foreach ($cacheArray['modules']['module'] as $key=>$mod) {
150 $cacheArray['modules']['id'][$mod] = $cacheArray['modules']['id'][$key];
151 unset($cacheArray['modules']['id'][$key]);
152 $cacheArray['modules']['title'][$mod] = $cacheArray['modules']['title'][$key];
153 unset($cacheArray['modules']['title'][$key]);
154 $cacheArray['modules']['locked'][$mod] = $cacheArray['modules']['locked'][$key];
155 unset($cacheArray['modules']['locked'][$key]);
156 $cacheArray['modules']['hidden'][$mod] = $cacheArray['modules']['hidden'][$key];
157 unset($cacheArray['modules']['hidden'][$key]);
158 $cacheArray['modules']['admin_only'][$mod] = $cacheArray['modules']['admin_only'][$key];
159 unset($cacheArray['modules']['admin_only'][$key]);
160 $cacheArray['modules']['mem_only'][$mod] = $cacheArray['modules']['mem_only'][$key];
161 unset($cacheArray['modules']['mem_only'][$key]);
162 $cacheArray['modules']['has_menu'][$mod] = $cacheArray['modules']['has_menu'][$key];
163 unset($cacheArray['modules']['has_menu'][$key]);
166 } elseif (($_CONFIG['cache_modreg'] == 'Y') && ($CSS != "1") && ($CSS != "-1")) {
167 // Create cache file here
168 $cacheInstance->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 $cacheInstance->add_row($DATA);
186 SQL_FREERESULT($result);
190 $cacheInstance->cache_close();
192 // Next cached table is the configuration (config)...
193 if ($cacheInstance->cache_file("config", true) == true) {
194 // Load config from cache
196 $cacheArray = $cacheInstance->cache_load();
199 $CNT = 0; $newCache = array();
200 foreach ($cacheArray as $key=>$array) {
201 foreach ($array as $key2=>$value) {
202 $newCache[$key2][$key] = $value;
204 $CNT += count($array);
207 // Overwrite the config with the cache version
208 $cacheArray['config'] = $newCache;
210 // When there is a period (.) in the result this test will fail and so the cache file is
213 if (count($cacheArray) > 0 ) $TEST = ($CNT / (count($cacheArray)));
214 if ($TEST != bigintval($TEST)) {
215 // Cache file is corrupted!
216 $cacheInstance->cache_destroy();
219 } elseif (($_CONFIG['cache_config'] == 'Y') && ($CSS != "1") && ($CSS != "-1")) {
220 // Create cache file here
221 $cacheInstance->cache_init("CONFIG");
223 // Load all modules and their data
224 $result = SQL_QUERY("SELECT * FROM "._MYSQL_PREFIX."_config ORDER BY config", __FILE__, __LINE__);
225 while ($DATA = SQL_FETCHARRAY($result)) {
226 // Add row to cache file
227 $cacheInstance->add_row($DATA);
231 SQL_FREERESULT($result);
235 $cacheInstance->cache_close();
237 // Next cached table is the referral system (refsystem)...
238 if ($cacheInstance->cache_file("refsystem", true) == true) {
239 // Load referral system from cache
241 $REF_SYSTEM = $cacheInstance->cache_load();
245 foreach ($REF_SYSTEM as $k=>$array) {
246 $CNT += count($array);
249 // When there is a period (.) in the result this test will fail and so the cache file is
252 if (count($REF_SYSTEM) > 0 ) $TEST = ($CNT / (count($REF_SYSTEM)));
253 if ($TEST != bigintval($TEST)) {
254 // Cache file is corrupted!
255 $cacheInstance->cache_destroy();
258 } elseif (($_CONFIG['cache_refsys'] == 'Y') && ($CSS != "1") && ($CSS != "-1")) {
259 // Create cache file here
260 $cacheInstance->cache_init("REFSYSTEM");
262 // Load all modules and their data
263 $result = SQL_QUERY("SELECT id, userid, level, counter FROM "._MYSQL_PREFIX."_refsystem ORDER BY userid, level", __FILE__, __LINE__);
264 while ($DATA = SQL_FETCHARRAY($result)) {
265 // Add row to cache file
266 $cacheInstance->add_row($DATA);
270 SQL_FREERESULT($result);
274 $cacheInstance->cache_close();
276 // Next cached table is the referral system (refdepths)...
277 if ($cacheInstance->cache_file("refdepths", true) == true) {
278 // Load referral system from cache
280 $REF_DEPTHS = $cacheInstance->cache_load();
284 foreach ($REF_DEPTHS as $k=>$array) {
285 $CNT += count($array);
288 // When there is a period (.) in the result this test will fail and so the cache file is
291 if (count($REF_DEPTHS) > 0 ) $TEST = ($CNT / (count($REF_DEPTHS)));
292 if ($TEST != bigintval($TEST)) {
293 // Cache file is corrupted!
294 $cacheInstance->cache_destroy();
297 } elseif (($_CONFIG['cache_refdepth'] == 'Y') && ($CSS != "1") && ($CSS != "-1")) {
298 // Create cache file here
299 $cacheInstance->cache_init("REFDEPTHS");
301 // Load all modules and their data
302 $result = SQL_QUERY("SELECT id, level, percents FROM "._MYSQL_PREFIX."_refdepths ORDER BY level", __FILE__, __LINE__);
303 while ($DATA = SQL_FETCHARRAY($result)) {
304 // Add row to cache file
305 $cacheInstance->add_row($DATA);
309 SQL_FREERESULT($result);
313 $cacheInstance->cache_close();
315 // Next cached table is the referral system (admins_acls)...
316 if (GET_EXT_VERSION("admins") >= "0.3") {
317 // Check for cache file
318 if ($cacheInstance->cache_file("admins_acls", true) == true) {
319 // Load referral system from cache
321 $cacheArray['admin_acls'] = $cacheInstance->cache_load();
325 foreach ($cacheArray['admin_acls'] as $k=>$array) {
326 $CNT += count($array);
329 // When there is a period (.) in the result this test will fail and so the cache file is
331 if (count($cacheArray['admin_acls']) > 0) {
333 if (count($cacheArray['admin_acls']) > 0 ) $TEST = ($CNT / (count($cacheArray['admin_acls'])));
334 if ($TEST != bigintval($TEST)) {
335 // Cache file is corrupted!
336 $cacheInstance->cache_destroy();
337 unset($cacheArray['admin_acls']);
340 } elseif (($_CONFIG['cache_acls'] == 'Y') && ($CSS != "1") && ($CSS != "-1")) {
341 // Create cache file here
342 $cacheInstance->cache_init("ADMINS_ACLS");
344 // Load all modules and their data
345 $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__);
346 while ($DATA = SQL_FETCHARRAY($result)) {
347 // Add row to cache file
348 $cacheInstance->add_row($DATA);
352 SQL_FREERESULT($result);
356 $cacheInstance->cache_close();