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