First batch of removal of the headers needed for revision-functions.php
[mailer.git] / inc / loader / load-admins.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 09/09/2008 *
4  * ===================                          Last change: 09/09/2008 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : load-config.php                                  *
8  * -------------------------------------------------------------------- *
9  * Short description : Load more cache files                            *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Mehr Cache-Dateien nachladen                     *
12  * -------------------------------------------------------------------- *
13  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
14  * Copyright (c) 2009 - 2013 by Mailer Developer Team                   *
15  * For more information visit: http://mxchange.org                      *
16  *                                                                      *
17  * This program is free software; you can redistribute it and/or modify *
18  * it under the terms of the GNU General Public License as published by *
19  * the Free Software Foundation; either version 2 of the License, or    *
20  * (at your option) any later version.                                  *
21  *                                                                      *
22  * This program is distributed in the hope that it will be useful,      *
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
25  * GNU General Public License for more details.                         *
26  *                                                                      *
27  * You should have received a copy of the GNU General Public License    *
28  * along with this program; if not, write to the Free Software          *
29  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
30  * MA  02110-1301  USA                                                  *
31  ************************************************************************/
32
33 // Some security stuff...
34 if (!defined('__SECURITY')) {
35         die();
36 } elseif (isInstaller()) {
37         // Do not run in installation phase
38         //* DEBUG: */ logDebugMessage(__FILE__, __LINE__, 'Run from installation phase.');
39         return FALSE;
40 }
41
42 // Let's start with the admins table...
43 if (($GLOBALS['cache_instance']->loadCacheFile('admin')) && ($GLOBALS['cache_instance']->extensionVersionMatches('admins'))) {
44         // Load cache
45         $GLOBALS['cache_array']['admin'] = $GLOBALS['cache_instance']->getArrayFromCache();
46
47         // Check if valid
48         if ((isset($GLOBALS['cache_array']['admin']['login'])) && (is_array($GLOBALS['cache_array']['admin']['login'])) && (is_array($GLOBALS['cache_array']['admin']['admin_id']))) {
49                 // Check count
50                 if (count($GLOBALS['cache_array']['admin']['login']) == count($GLOBALS['cache_array']['admin']['admin_id'])) {
51                         // Rewrite the cache
52                         $admins = array();
53                         foreach ($GLOBALS['cache_array']['admin']['login'] as $idx => $admin) {
54                                 // Rewrite all entries
55                                 foreach ($GLOBALS['cache_array']['admin'] as $key => $entry) {
56                                         // Is there login or regular entries?
57                                         if ($key == 'admin_id') {
58                                                 // Admin id, so use login
59                                                 $admins[$key][$GLOBALS['cache_array']['admin']['login'][$idx]] = $entry[$idx];
60                                         } else {
61                                                 // Regular entry so use id
62                                                 $admins[$key][$GLOBALS['cache_array']['admin']['admin_id'][$idx]] = $entry[$idx];
63                                         }
64                                 } // END - foreach
65                         } // END - foreach
66
67                         // Transfer back to cache array and remove dummy
68                         $GLOBALS['cache_array']['admin'] = $admins;
69                         unset($admins);
70                 } else {
71                         // Nope, cache file is corrupted!
72                         $GLOBALS['cache_instance']->removeCacheFile();
73                         unset($GLOBALS['cache_array']['admin']);
74                 }
75         } else {
76                 // Nope, cache file is corrupted!
77                 $GLOBALS['cache_instance']->removeCacheFile();
78                 unset($GLOBALS['cache_array']['admin']);
79         }
80 } elseif ((isHtmlOutputMode()) || (isAjaxOutputMode()) || (isRawOutputMode())) {
81         // Create cache file
82         $GLOBALS['cache_instance']->init();
83
84         // Load every data from DB to cache file
85         $add = runFilterChain('sql_admin_extra_data');
86
87         // Query the database about this
88         $result = sqlQuery('SELECT
89         `id` AS `admin_id`,
90         `login`,
91         `password`,
92         `email`
93         ' . $add . '
94 FROM
95         `{?_MYSQL_PREFIX?}_admins`
96 ORDER BY
97         `login` ASC', __FILE__, __LINE__);
98         while ($row = sqlFetchArray($result)) {
99                 // Save row
100                 $GLOBALS['cache_instance']->addRow($row);
101         } // END - while
102
103         // Free memory
104         sqlFreeResult($result);
105
106         // Close cache
107         $GLOBALS['cache_instance']->storeExtensionVersion('admins');
108         $GLOBALS['cache_instance']->finalize();
109 }
110
111 // Next cached table are the admins_acls...
112 if (isExtensionInstalledAndNewer('admins', '0.3')) {
113         // Check for cache file
114         if (($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) && ($GLOBALS['cache_instance']->extensionVersionMatches('admins'))) {
115                 // Load admin ACLs from cache
116                 $GLOBALS['cache_array']['admin_acls'] = $GLOBALS['cache_instance']->getArrayFromCache();
117
118                 // Check if valid
119                 if ((isset($GLOBALS['cache_array']['admin_acls']['admin_id'])) && (is_array($GLOBALS['cache_array']['admin_acls']['admin_id'])) && (isset($GLOBALS['cache_array']['admin_acls']['access_mode'])) && (is_array($GLOBALS['cache_array']['admin_acls']['access_mode']))) {
120                         // Check count
121                         if (count($GLOBALS['cache_array']['admin_acls']['admin_id']) == count($GLOBALS['cache_array']['admin_acls']['access_mode'])) {
122                                 // Rewrite the cache
123                                 $admins = array();
124                                 foreach ($GLOBALS['cache_array']['admin_acls']['admin_id'] as $idx => $admin) {
125                                         // Rewrite all entries
126                                         foreach ($GLOBALS['cache_array']['admin_acls'] as $key => $entry) {
127                                                 // Is there 'admin_id' or regular entries?
128                                                 if ($key != 'admin_id') {
129                                                         // Regular entry so use id
130                                                         array_push($admins[$key][$GLOBALS['cache_array']['admin_acls']['admin_id'][$idx]], $entry[$idx]);
131                                                 } // END - if
132                                         } // END - foreach
133                                 } // END - foreach
134
135                                 // Transfer back to cache array and remove dummy
136                                 $GLOBALS['cache_array']['admin_acls'] = $admins;
137                                 unset($admins);
138                         } else {
139                                 // Nope, cache file is corrupted!
140                                 $GLOBALS['cache_instance']->removeCacheFile();
141                                 unset($GLOBALS['cache_array']['admin_acls']);
142                         }
143                 } elseif (count($GLOBALS['cache_array']['admin_acls']) > 0) {
144                         // Nope, cache file is corrupted!
145                         $GLOBALS['cache_instance']->removeCacheFile();
146                         unset($GLOBALS['cache_array']['admin_acls']);
147                 } elseif (isDebugModeEnabled()) {
148                         // This may drive a lot messages to the logfile
149                         //* DEBUG: */ logDebugMessage(__FILE__, __LINE__, 'No entry found in admin_acls to rewrite.');
150                 }
151         } elseif ((isHtmlOutputMode()) || (isAjaxOutputMode()) || (isRawOutputMode())) {
152                 // Create cache file here
153                 $GLOBALS['cache_instance']->init();
154
155                 // Load all admins and their data
156                 $result = sqlQuery('SELECT * FROM `{?_MYSQL_PREFIX?}_admins_acls` ORDER BY `admin_id` ASC,`action_menu` ASC,`what_menu` ASC', __FILE__, __LINE__);
157
158                 // Add all rows
159                 while ($content = sqlFetchArray($result)) {
160                         // Add row to cache file
161                         $GLOBALS['cache_instance']->addRow($content);
162                 } // END - while
163
164                 // Free memory
165                 sqlFreeResult($result);
166
167                 // Close cache
168                 $GLOBALS['cache_instance']->storeExtensionVersion('admins');
169                 $GLOBALS['cache_instance']->finalize();
170         }
171 } // END - if
172
173 // [EOF]
174 ?>