A lot while() conditions rewritten to SQL_FETCHARRAY(), see bug #107, @TODO tags...
[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 (($GLOBALS['cache_instance']->loadCacheFile("admins")) && ($GLOBALS['cache_instance']->extensionVersionMatches("admins"))) {
42         // Load cache
43         $GLOBALS['cache_array']['admins'] = $GLOBALS['cache_instance']->getArrayFromCache();
44
45         // Check if valid
46         if ((isset($GLOBALS['cache_array']['admins']['login'])) && (is_array($GLOBALS['cache_array']['admins']['login'])) && (is_array($GLOBALS['cache_array']['admins']['aid']))) {
47                 // Check count
48                 if (count($GLOBALS['cache_array']['admins']['login']) == count($GLOBALS['cache_array']['admins']['aid'])) {
49                         // Get "id map"
50                         $idMap = $GLOBALS['cache_array']['admins']['aid'];
51
52                         // Rewrite the cache array
53                         for ($idx = (count($idMap) - 1); $idx >= 0; $idx--) {
54                                 // Rewrite all entries
55                                 foreach ($GLOBALS['cache_array']['admins'] as $key=>$entryArray) {
56                                         // Rewrite the entry
57                                         if ($key == "aid") {
58                                                 // Rewrite admin id (use login name as index)
59                                                 $GLOBALS['cache_array']['admins']['aid'][$GLOBALS['cache_array']['admins']['login'][$idx]] = $entryArray[$idx];
60                                         } else {
61                                                 // Rewrite regular entry
62                                                 $GLOBALS['cache_array']['admins'][$key][$idMap[$idx]] = $entryArray[$idx];
63                                         }
64
65                                         // Is the last entry reached?
66                                         if ($idx == 0) {
67                                                 // Remove it
68                                                 unset($GLOBALS['cache_array']['admins'][$key][0]);
69                                         } // END - if
70                                 } // END - if
71                         } // END - for
72                 } else {
73                         // Nope, cache file is corrupted!
74                         $GLOBALS['cache_instance']->destroyCacheFile();
75                         unset($GLOBALS['cache_array']['admins']);
76                 }
77         } else {
78                 // Nope, cache file is corrupted!
79                 $GLOBALS['cache_instance']->destroyCacheFile();
80                 unset($GLOBALS['cache_array']['admins']);
81         }
82 } elseif ((getConfig('cache_admins') == "Y") && ($GLOBALS['output_mode'] != "1") && ($GLOBALS['output_mode'] != "-1")) {
83         // Create cache file
84         $GLOBALS['cache_instance']->init("ADMINS");
85         $GLOBALS['cache_instance']->storeExtensionVersion("admins");
86
87         // Load every data from DB to cache file
88         $ADD = runFilterChain('sql_admin_extra_data');
89
90         // Query the database about this
91         $result_admins = SQL_QUERY("SELECT id AS aid, login, password, email".$ADD."
92 FROM `{!_MYSQL_PREFIX!}_admins`
93 ORDER BY login", __FILE__, __LINE__);
94         while ($dummy = SQL_FETCHARRAY($result_admins)) {
95                 // Save row
96                 $GLOBALS['cache_instance']->addRow($dummy);
97         } // END - while
98
99         // Free memory
100         SQL_FREERESULT($result_admins);
101
102         // Close cache
103         $GLOBALS['cache_instance']->finalize();
104
105         // Include loader again
106         require(__FILE__);
107 }
108
109 // Next cached table are the admins_acls...
110 if (GET_EXT_VERSION("admins") >= "0.3") {
111         // Check for cache file
112         if (($GLOBALS['cache_instance']->loadCacheFile("admins_acls")) && ($GLOBALS['cache_instance']->extensionVersionMatches("admins"))) {
113                 // Load referal system from cache
114                 $GLOBALS['cache_array']['admin_acls'] = $GLOBALS['cache_instance']->getArrayFromCache();
115         } elseif ((getConfig('cache_acls') == "Y") && ($GLOBALS['output_mode'] != "1") && ($GLOBALS['output_mode'] != "-1")) {
116                 // Create cache file here
117                 $GLOBALS['cache_instance']->init("ADMINS_ACLS");
118                 $GLOBALS['cache_instance']->storeExtensionVersion("admins");
119
120                 // Load all modules and their data
121                 $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__);
122
123                 // Add all rows
124                 while ($data = SQL_FETCHARRAY($result)) {
125                         // Add row to cache file
126                         $GLOBALS['cache_instance']->addRow($data);
127                 } // END - while
128
129                 // Free memory
130                 SQL_FREERESULT($result);
131
132                 // Close cache
133                 $GLOBALS['cache_instance']->finalize();
134
135                 // Include loader again
136                 require(__FILE__);
137         }
138 } // END - if
139
140 //
141 ?>