Cache system rewritten, thanks to profi-concept's hints of including not evaluating it
[mailer.git] / inc / loader / load_cache-admin.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 09/09/2008 *
4  * ===============                              Last change: 09/09/2008 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : load_cache-config.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 (!defined('__SECURITY')) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 } // END - if
39
40 // Let's start with the admins table...
41 if (($cacheInstance->cache_file("admins")) && ($cacheInstance->ext_version_matches("admins"))) {
42         // Load cache
43         global $cacheArray;
44         $cacheArray['admins'] = $cacheInstance->cache_load();
45
46         // Check if valid
47         if ((isset($cacheArray['admins']['login'])) && (is_array($cacheArray['admins']['login'])) && (is_array($cacheArray['admins']['aid']))) {
48                 // Check count
49                 if (count($cacheArray['admins']['login']) == count($cacheArray['admins']['aid'])) {
50                         // Get "id map"
51                         $idMap = $cacheArray['admins']['aid'];
52
53                         // Rewrite the cache array
54                         for ($idx = (count($idMap) - 1); $idx >= 0; $idx--) {
55                                 // Rewrite all entries
56                                 foreach ($cacheArray['admins'] as $key=>$entryArray) {
57                                         // Rewrite the entry
58                                         if ($key == "aid") {
59                                                 // Rewrite admin id (use login name as index)
60                                                 $cacheArray['admins']['aid'][$cacheArray['admins']['login'][$idx]] = $entryArray[$idx];
61                                         } else {
62                                                 // Rewrite regular entry
63                                                 $cacheArray['admins'][$key][$idMap[$idx]] = $entryArray[$idx];
64                                         }
65
66                                         // Is the last entry reached?
67                                         if ($idx == 0) {
68                                                 // Remove it
69                                                 unset($cacheArray['admins'][$key][0]);
70                                         } // END - if
71                                 } // END - if
72                         } // END - for
73                 } else {
74                         // Nope, cache file is corrupted!
75                         $cacheInstance->cache_destroy();
76                         unset($cacheArray['admins']);
77                 }
78         } else {
79                 // Nope, cache file is corrupted!
80                 $cacheInstance->cache_destroy();
81                 unset($cacheArray['admins']);
82         }
83 } elseif (($_CONFIG['cache_admins'] == "Y") && ($CSS != "1") && ($CSS != "-1")) {
84         // Create cache file
85         $cacheInstance->cache_init("ADMINS");
86         $cacheInstance->store_extension_version("admins");
87
88         // Load every data from DB to cache file
89         $ADD = ", id, id";
90         if (GET_EXT_VERSION("admins") >= "0.3")   $ADD  = ", default_acl AS def_acl";
91         if (GET_EXT_VERSION("admins") >= "0.6.7") $ADD .= ", la_mode";
92         if (GET_EXT_VERSION("admins") >= "0.7.0") $ADD .= ", login_failtures, UNIX_TIMESTAMP(last_failture) AS last_failture";
93
94         // Query the database about this
95         $result_admins = SQL_QUERY("SELECT id AS aid, login, password, email".$ADD."
96 FROM "._MYSQL_PREFIX."_admins
97 ORDER BY login", __FILE__, __LINE__);
98         while($dummy = SQL_FETCHARRAY($result_admins)) {
99                 // Save row
100                 $cacheInstance->add_row($dummy);
101         } // END - while
102
103         // Free memory
104         SQL_FREERESULT($result_admins);
105
106         // Close cache
107         $cacheInstance->cache_close();
108
109         // Reload the cache
110         require(__FILE__);
111 }
112
113 // Close file
114 $cacheInstance->cache_close();
115
116 // Next cached table are the admins_acls...
117 if (GET_EXT_VERSION("admins") >= "0.3") {
118         // Check for cache file
119         if (($cacheInstance->cache_file("admins_acls")) && ($cacheInstance->ext_version_matches("admins"))) {
120                 // Load referal system from cache
121                 global $cacheArray;
122                 $cacheArray['admin_acls'] = $cacheInstance->cache_load();
123         } elseif (($_CONFIG['cache_acls'] == "Y") && ($CSS != "1") && ($CSS != "-1")) {
124                 // Create cache file here
125                 $cacheInstance->cache_init("ADMINS_ACLS");
126                 $cacheInstance->store_extension_version("admins");
127
128                 // Load all modules and their data
129                 $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__);
130
131                 // Add all rows
132                 while ($data = SQL_FETCHARRAY($result)) {
133                         // Add row to cache file
134                         $cacheInstance->add_row($data);
135                 } // END - while
136
137                 // Free memory
138                 SQL_FREERESULT($result);
139
140                 // Close cache
141                 $cacheInstance->cache_close();
142
143                 // Reload the cache
144                 require(__FILE__);
145         }
146
147         // Close file
148         $cacheInstance->cache_close();
149 } // END - if
150
151 //
152 ?>