Now all admin functions depend on admin id, before login/aid mixed
[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", true) == true) && ($cacheInstance->ext_version_matches("admins"))) {
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 admin id
56                                 $cacheArray['admins']['aid'][$login]    = $cacheArray['admins']['aid'][$k];
57
58                                 // Shortcut admin id
59                                 $aid = $cacheArray['admins']['aid'][$login];
60
61                                 // Rewrite others...
62                                 $cacheArray['admins']['password'][$aid] = $cacheArray['admins']['password'][$k];
63                                 $cacheArray['admins']['email'][$aid]    = $cacheArray['admins']['email'][$k];
64
65                                 // Some extra data depending on version
66                                 if (GET_EXT_VERSION("admins") >= "0.3") {
67                                         // Default ACL
68                                         $cacheArray['admins']['def_acl'][$aid]  = $cacheArray['admins']['def_acl'][$k];
69                                         if (GET_EXT_VERSION("admins") >= "0.6.7") {
70                                                 // "Logical Area" mode
71                                                 $cacheArray['admins']['la_mode'][$aid]  = $cacheArray['admins']['la_mode'][$k];
72                                                 if (GET_EXT_VERSION("admins") >= "0.7.0") {
73                                                         // Login failtures
74                                                         $cacheArray['admins']['login_failtures'][$aid] = $cacheArray['admins']['login_failtures'][$k];
75                                                         $cacheArray['admins']['last_failture'][$aid]   = $cacheArray['admins']['last_failture'][$k];
76                                                 } // END - if
77                                         } // END - if
78                                 } // END - if
79
80                                 //* DEBUG: */ print_r($cacheArray['admins']);
81
82                                 // Clear array
83                                 foreach (array('aid', 'def_acl', 'la_mode', 'password', 'email', 'login_failtures', 'last_failture') as $rem) {
84                                         if (isset($cacheArray['admins'][$rem][$k])) unset($cacheArray['admins'][$rem][$k]);
85                                 } // END - foreach
86                         } // END - if
87
88                         //* DEBUG: */ print_r($cacheArray['admins']);
89
90                         // Rewrite Login
91                         foreach ($cacheArray['admins']['login'] as $k => $login) {
92                                 $cacheArray['admins']['login'][$cacheArray['admins']['aid'][$login]] = $login;
93                                 if (!in_array($k, $cacheArray['admins']['aid'])) {
94                                         unset($cacheArray['admins']['login'][$k]);
95                                 } // END - if
96                         } // END - foreach
97
98                         //* DEBUG: */ echo "****\n";
99                         //* DEBUG: */ print_r($cacheArray['admins']);
100                         //* DEBUG: */ echo "</PRE>";
101                         //* DEBUG: */ die();
102                 } else {
103                         // Nope, cache file is corrupted!
104                         $cacheInstance->cache_destroy();
105                 }
106         } else {
107                 // Nope, cache file is corrupted!
108                 $cacheInstance->cache_destroy();
109                 unset($cacheArray['admins']);
110         }
111 } elseif (($_CONFIG['cache_admins'] == "Y") && ($CSS != "1") && ($CSS != "-1")) {
112         // Create cache file
113         $cacheInstance->cache_init("ADMINS");
114         $cacheInstance->store_extension_version("admins");
115
116         // Load every data from DB to cache file
117         $ADD = ", id, id";
118         if (GET_EXT_VERSION("admins") >= "0.3")   $ADD  = ", default_acl AS def_acl";
119         if (GET_EXT_VERSION("admins") >= "0.6.7") $ADD .= ", la_mode";
120         if (GET_EXT_VERSION("admins") >= "0.7.0") $ADD .= ", login_failtures, UNIX_TIMESTAMP(last_failture) AS last_failture";
121
122         // Query the database about this
123         $result_admins = SQL_QUERY("SELECT id AS aid, login, password, email".$ADD."
124 FROM "._MYSQL_PREFIX."_admins
125 ORDER BY login", __FILE__, __LINE__);
126         while($dummy = SQL_FETCHARRAY($result_admins)) {
127                 // Save row
128                 $cacheInstance->add_row($dummy);
129         } // END - while
130
131         // Free memory
132         SQL_FREERESULT($result_admins);
133
134         // Close cache
135         $cacheInstance->cache_close();
136
137         // Reload the cache
138         require(__FILE__);
139 }
140
141 // Close file
142 $cacheInstance->cache_close();
143
144 // Next cached table are the admins_acls...
145 if (GET_EXT_VERSION("admins") >= "0.3") {
146         // Check for cache file
147         if ($cacheInstance->cache_file("admins_acls", true) == true) {
148                 // Load referal system from cache
149                 global $cacheArray;
150                 $cacheArray['admin_acls'] = $cacheInstance->cache_load();
151         } elseif (($_CONFIG['cache_acls'] == "Y") && ($CSS != "1") && ($CSS != "-1")) {
152                 // Create cache file here
153                 $cacheInstance->cache_init("ADMINS_ACLS");
154
155                 // Load all modules and their data
156                 $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__);
157                 while ($data = SQL_FETCHARRAY($result)) {
158                         // Add row to cache file
159                         $cacheInstance->add_row($data);
160                 } // END - while
161
162                 // Free memory
163                 SQL_FREERESULT($result);
164
165                 // Reload the cache
166                 require(__FILE__);
167         }
168
169         // Close file
170         $cacheInstance->cache_close();
171 } // END - if
172
173 //
174 ?>