65cfb6214db6267a83c736c92ef4d2bacb6802d4
[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  * $Revision:: 856                                                    $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
42         require($INC);
43 } // END - if
44
45 // Let's start with the admins table...
46 if (($GLOBALS['cache_instance']->loadCacheFile("admins")) && ($GLOBALS['cache_instance']->extensionVersionMatches("admins"))) {
47         // Load cache
48         $GLOBALS['cache_array']['admins'] = $GLOBALS['cache_instance']->getArrayFromCache();
49
50         // Check if valid
51         if ((isset($GLOBALS['cache_array']['admins']['login'])) && (is_array($GLOBALS['cache_array']['admins']['login'])) && (is_array($GLOBALS['cache_array']['admins']['aid']))) {
52                 // Check count
53                 if (count($GLOBALS['cache_array']['admins']['login']) == count($GLOBALS['cache_array']['admins']['aid'])) {
54                         // Get "id map"
55                         $idMap = $GLOBALS['cache_array']['admins']['aid'];
56
57                         // Rewrite the cache array
58                         for ($idx = (count($idMap) - 1); $idx >= 0; $idx--) {
59                                 // Rewrite all entries
60                                 foreach ($GLOBALS['cache_array']['admins'] as $key=>$entryArray) {
61                                         // Rewrite the entry
62                                         if ($key == "aid") {
63                                                 // Rewrite admin id (use login name as index)
64                                                 $GLOBALS['cache_array']['admins']['aid'][$GLOBALS['cache_array']['admins']['login'][$idx]] = $entryArray[$idx];
65                                         } else {
66                                                 // Rewrite regular entry
67                                                 $GLOBALS['cache_array']['admins'][$key][$idMap[$idx]] = $entryArray[$idx];
68                                         }
69
70                                         // Is the last entry reached?
71                                         if ($idx == 0) {
72                                                 // Remove it
73                                                 unset($GLOBALS['cache_array']['admins'][$key][0]);
74                                         } // END - if
75                                 } // END - if
76                         } // END - for
77                 } else {
78                         // Nope, cache file is corrupted!
79                         $GLOBALS['cache_instance']->destroyCacheFile();
80                         unset($GLOBALS['cache_array']['admins']);
81                 }
82         } else {
83                 // Nope, cache file is corrupted!
84                 $GLOBALS['cache_instance']->destroyCacheFile();
85                 unset($GLOBALS['cache_array']['admins']);
86         }
87 } elseif ((getConfig('cache_admins') == "Y") && ($GLOBALS['output_mode'] != "1") && ($GLOBALS['output_mode'] != "-1")) {
88         // Create cache file
89         $GLOBALS['cache_instance']->init("ADMINS");
90         $GLOBALS['cache_instance']->storeExtensionVersion("admins");
91
92         // Load every data from DB to cache file
93         $ADD = runFilterChain('sql_admin_extra_data');
94
95         // Query the database about this
96         $result_admins = SQL_QUERY("SELECT id AS aid, login, password, email".$ADD."
97 FROM `{!_MYSQL_PREFIX!}_admins`
98 ORDER BY login", __FILE__, __LINE__);
99         while ($dummy = SQL_FETCHARRAY($result_admins)) {
100                 // Save row
101                 $GLOBALS['cache_instance']->addRow($dummy);
102         } // END - while
103
104         // Free memory
105         SQL_FREERESULT($result_admins);
106
107         // Close cache
108         $GLOBALS['cache_instance']->finalize();
109
110         // Include loader again
111         require(__FILE__);
112 }
113
114 // Next cached table are the admins_acls...
115 if (GET_EXT_VERSION("admins") >= "0.3") {
116         // Check for cache file
117         if (($GLOBALS['cache_instance']->loadCacheFile("admins_acls")) && ($GLOBALS['cache_instance']->extensionVersionMatches("admins"))) {
118                 // Load referal system from cache
119                 $GLOBALS['cache_array']['admin_acls'] = $GLOBALS['cache_instance']->getArrayFromCache();
120         } elseif ((getConfig('cache_acls') == "Y") && ($GLOBALS['output_mode'] != "1") && ($GLOBALS['output_mode'] != "-1")) {
121                 // Create cache file here
122                 $GLOBALS['cache_instance']->init("ADMINS_ACLS");
123                 $GLOBALS['cache_instance']->storeExtensionVersion("admins");
124
125                 // Load all modules and their data
126                 $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__);
127
128                 // Add all rows
129                 while ($data = SQL_FETCHARRAY($result)) {
130                         // Add row to cache file
131                         $GLOBALS['cache_instance']->addRow($data);
132                 } // END - while
133
134                 // Free memory
135                 SQL_FREERESULT($result);
136
137                 // Close cache
138                 $GLOBALS['cache_instance']->finalize();
139
140                 // Include loader again
141                 require(__FILE__);
142         }
143 } // END - if
144
145 //
146 ?>