Huge script change, see http://forum.mxchange.org/topic-458.html for details:
[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::                                                        $ *
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 - 2009 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         die();
42 } // END - if
43
44 // Let's start with the admins table...
45 if (($GLOBALS['cache_instance']->loadCacheFile('admins')) && ($GLOBALS['cache_instance']->extensionVersionMatches('admins'))) {
46         // Load cache
47         $GLOBALS['cache_array']['admins'] = $GLOBALS['cache_instance']->getArrayFromCache();
48
49         // Check if valid
50         if ((isset($GLOBALS['cache_array']['admins']['login'])) && (is_array($GLOBALS['cache_array']['admins']['login'])) && (is_array($GLOBALS['cache_array']['admins']['admin_id']))) {
51                 // Check count
52                 if (count($GLOBALS['cache_array']['admins']['login']) == count($GLOBALS['cache_array']['admins']['admin_id'])) {
53                         // Get "id map"
54                         $idMap = $GLOBALS['cache_array']['admins']['admin_id'];
55
56                         // Rewrite the cache array
57                         for ($idx = (count($idMap) - 1); $idx >= 0; $idx--) {
58                                 // Rewrite all entries
59                                 foreach ($GLOBALS['cache_array']['admins'] as $key=>$entryArray) {
60                                         // Rewrite the entry
61                                         if ($key == 'admin_id') {
62                                                 // Rewrite admin id (use login name as index)
63                                                 $GLOBALS['cache_array']['admins']['admin_id'][$GLOBALS['cache_array']['admins']['login'][$idx]] = $entryArray[$idx];
64                                         } else {
65                                                 // Rewrite regular entry
66                                                 $GLOBALS['cache_array']['admins'][$key][$idMap[$idx]] = $entryArray[$idx];
67                                         }
68
69                                         // Is the last entry reached?
70                                         if ($idx == 0) {
71                                                 // Remove it
72                                                 unset($GLOBALS['cache_array']['admins'][$key][0]);
73                                         } // END - if
74                                 } // END - if
75                         } // END - for
76                 } else {
77                         // Nope, cache file is corrupted!
78                         $GLOBALS['cache_instance']->removeCacheFile();
79                         unset($GLOBALS['cache_array']['admins']);
80                 }
81         } else {
82                 // Nope, cache file is corrupted!
83                 $GLOBALS['cache_instance']->removeCacheFile();
84                 unset($GLOBALS['cache_array']['admins']);
85         }
86 } elseif (getOutputMode() != '1') {
87         // Create cache file
88         $GLOBALS['cache_instance']->init('ADMINS');
89
90         // Load every data from DB to cache file
91         $add = runFilterChain('sql_admin_extra_data');
92
93         // Query the database about this
94         $result_admins = SQL_QUERY('SELECT
95         `id` AS admin_id, `login`, `password`, `email`' . $add . '
96 FROM
97         `{?_MYSQL_PREFIX?}_admins`
98 ORDER BY
99         `login` ASC', __FILE__, __LINE__);
100         while ($dummy = SQL_FETCHARRAY($result_admins)) {
101                 // Save row
102                 $GLOBALS['cache_instance']->addRow($dummy);
103         } // END - while
104
105         // Free memory
106         SQL_FREERESULT($result_admins);
107
108         // Close cache
109         $GLOBALS['cache_instance']->storeExtensionVersion('admins');
110         $GLOBALS['cache_instance']->finalize();
111
112         // Include loader again
113         loadInclude('inc/loader/'.basename(__FILE__));
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('admins_acls')) && ($GLOBALS['cache_instance']->extensionVersionMatches('admins'))) {
120                 // Load referal system from cache
121                 $GLOBALS['cache_array']['admin_acls'] = $GLOBALS['cache_instance']->getArrayFromCache();
122         } elseif (getOutputMode() != '1') {
123                 // Create cache file here
124                 $GLOBALS['cache_instance']->init('ADMINS_ACLS');
125
126                 // Load all modules and their data (column 'id' is no longer required)
127                 $result = SQL_QUERY('SELECT `admin_id`, `action_menu`, `what_menu`, `access_mode` FROM `{?_MYSQL_PREFIX?}_admins_acls` ORDER BY admin_id, action_menu, what_menu', __FILE__, __LINE__);
128
129                 // Add all rows
130                 while ($content = SQL_FETCHARRAY($result)) {
131                         // Add row to cache file
132                         $GLOBALS['cache_instance']->addRow($content);
133                 } // END - while
134
135                 // Free memory
136                 SQL_FREERESULT($result);
137
138                 // Close cache
139                 $GLOBALS['cache_instance']->storeExtensionVersion('admins');
140                 $GLOBALS['cache_instance']->finalize();
141
142                 // Include loader again
143                 loadInclude('inc/loader/'.basename(__FILE__));
144         }
145 } // END - if
146
147 // [EOF]
148 ?>