]> git.mxchange.org Git - mailer.git/blob - inc/loader/load-admins.php
Heacy rewrite/cleanup:
[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 - 2013 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 (isInstaller()) {
42         // Do not run in installation phase
43         //* DEBUG: */ logDebugMessage(__FILE__, __LINE__, 'Run from installation phase.');
44         return FALSE;
45 }
46
47 // Let's start with the admins table...
48 if (($GLOBALS['cache_instance']->loadCacheFile('admin')) && ($GLOBALS['cache_instance']->extensionVersionMatches('admins'))) {
49         // Load cache
50         $GLOBALS['cache_array']['admin'] = $GLOBALS['cache_instance']->getArrayFromCache();
51
52         // Check if valid
53         if ((isset($GLOBALS['cache_array']['admin']['login'])) && (is_array($GLOBALS['cache_array']['admin']['login'])) && (is_array($GLOBALS['cache_array']['admin']['admin_id']))) {
54                 // Check count
55                 if (count($GLOBALS['cache_array']['admin']['login']) == count($GLOBALS['cache_array']['admin']['admin_id'])) {
56                         // Rewrite the cache
57                         $admins = array();
58                         foreach ($GLOBALS['cache_array']['admin']['login'] as $idx => $admin) {
59                                 // Rewrite all entries
60                                 foreach ($GLOBALS['cache_array']['admin'] as $key => $entry) {
61                                         // Is there login or regular entries?
62                                         if ($key == 'admin_id') {
63                                                 // Admin id, so use login
64                                                 $admins[$key][$GLOBALS['cache_array']['admin']['login'][$idx]] = $entry[$idx];
65                                         } else {
66                                                 // Regular entry so use id
67                                                 $admins[$key][$GLOBALS['cache_array']['admin']['admin_id'][$idx]] = $entry[$idx];
68                                         }
69                                 } // END - foreach
70                         } // END - foreach
71
72                         // Transfer back to cache array and remove dummy
73                         $GLOBALS['cache_array']['admin'] = $admins;
74                         unset($admins);
75                 } else {
76                         // Nope, cache file is corrupted!
77                         $GLOBALS['cache_instance']->removeCacheFile();
78                         unset($GLOBALS['cache_array']['admin']);
79                 }
80         } else {
81                 // Nope, cache file is corrupted!
82                 $GLOBALS['cache_instance']->removeCacheFile();
83                 unset($GLOBALS['cache_array']['admin']);
84         }
85 } elseif ((isHtmlOutputMode()) || (isAjaxOutputMode()) || (isRawOutputMode())) {
86         // Create cache file
87         $GLOBALS['cache_instance']->init();
88
89         // Load every data from DB to cache file
90         $add = runFilterChain('sql_admin_extra_data');
91
92         // Query the database about this
93         $result = sqlQuery('SELECT
94         `id` AS `admin_id`,
95         `login`,
96         `password`,
97         `email`
98         ' . $add . '
99 FROM
100         `{?_MYSQL_PREFIX?}_admins`
101 ORDER BY
102         `login` ASC', __FILE__, __LINE__);
103         while ($row = sqlFetchArray($result)) {
104                 // Save row
105                 $GLOBALS['cache_instance']->addRow($row);
106         } // END - while
107
108         // Free memory
109         sqlFreeResult($result);
110
111         // Close cache
112         $GLOBALS['cache_instance']->storeExtensionVersion('admins');
113         $GLOBALS['cache_instance']->finalize();
114 }
115
116 // Next cached table are the admins_acls...
117 if (isExtensionInstalledAndNewer('admins', '0.3')) {
118         // Check for cache file
119         if (($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) && ($GLOBALS['cache_instance']->extensionVersionMatches('admins'))) {
120                 // Load admin ACLs from cache
121                 $GLOBALS['cache_array']['admin_acls'] = $GLOBALS['cache_instance']->getArrayFromCache();
122
123                 // Check if valid
124                 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']))) {
125                         // Check count
126                         if (count($GLOBALS['cache_array']['admin_acls']['admin_id']) == count($GLOBALS['cache_array']['admin_acls']['access_mode'])) {
127                                 // Rewrite the cache
128                                 $admins = array();
129                                 foreach ($GLOBALS['cache_array']['admin_acls']['admin_id'] as $idx => $admin) {
130                                         // Rewrite all entries
131                                         foreach ($GLOBALS['cache_array']['admin_acls'] as $key => $entry) {
132                                                 // Is there 'admin_id' or regular entries?
133                                                 if ($key != 'admin_id') {
134                                                         // Regular entry so use id
135                                                         array_push($admins[$key][$GLOBALS['cache_array']['admin_acls']['admin_id'][$idx]], $entry[$idx]);
136                                                 } // END - if
137                                         } // END - foreach
138                                 } // END - foreach
139
140                                 // Transfer back to cache array and remove dummy
141                                 $GLOBALS['cache_array']['admin_acls'] = $admins;
142                                 unset($admins);
143                         } else {
144                                 // Nope, cache file is corrupted!
145                                 $GLOBALS['cache_instance']->removeCacheFile();
146                                 unset($GLOBALS['cache_array']['admin_acls']);
147                         }
148                 } elseif (count($GLOBALS['cache_array']['admin_acls']) > 0) {
149                         // Nope, cache file is corrupted!
150                         $GLOBALS['cache_instance']->removeCacheFile();
151                         unset($GLOBALS['cache_array']['admin_acls']);
152                 } elseif (isDebugModeEnabled()) {
153                         // This may drive a lot messages to the logfile
154                         //* DEBUG: */ logDebugMessage(__FILE__, __LINE__, 'No entry found in admin_acls to rewrite.');
155                 }
156         } elseif ((isHtmlOutputMode()) || (isAjaxOutputMode()) || (isRawOutputMode())) {
157                 // Create cache file here
158                 $GLOBALS['cache_instance']->init();
159
160                 // Load all admins and their data
161                 $result = sqlQuery('SELECT * FROM `{?_MYSQL_PREFIX?}_admins_acls` ORDER BY `admin_id` ASC,`action_menu` ASC,`what_menu` ASC', __FILE__, __LINE__);
162
163                 // Add all rows
164                 while ($content = sqlFetchArray($result)) {
165                         // Add row to cache file
166                         $GLOBALS['cache_instance']->addRow($content);
167                 } // END - while
168
169                 // Free memory
170                 sqlFreeResult($result);
171
172                 // Close cache
173                 $GLOBALS['cache_instance']->storeExtensionVersion('admins');
174                 $GLOBALS['cache_instance']->finalize();
175         }
176 } // END - if
177
178 // [EOF]
179 ?>