X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Floader%2Fload-admins.php;h=c34f9585bed3616ce8d942263334b8de87321a47;hp=32d73eef567bb4c692fd951dd261987a96baedea;hb=8fad776382e63b3f73f8dbe289f229d79cfc2c22;hpb=cf1c0f69caf5dc2abc2c461ca97696a064456e30 diff --git a/inc/loader/load-admins.php b/inc/loader/load-admins.php index 32d73eef56..c34f9585be 100644 --- a/inc/loader/load-admins.php +++ b/inc/loader/load-admins.php @@ -16,8 +16,8 @@ * $Author:: $ * * -------------------------------------------------------------------- * * Copyright (c) 2003 - 2009 by Roland Haeder * - * Copyright (c) 2009, 2010 by Mailer Developer Team * - * For more information visit: http://www.mxchange.org * + * Copyright (c) 2009 - 2012 by Mailer Developer Team * + * For more information visit: http://mxchange.org * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -38,10 +38,10 @@ // Some security stuff... if (!defined('__SECURITY')) { die(); -} // END - if - -// Use this code if you don't want to run this cache loader on installation phase -if (isInstallationPhase()) return; +} elseif (isInstallationPhase()) { + // Use this code if you don't want to run this cache loader on installation phase + return; +} // Let's start with the admins table... if (($GLOBALS['cache_instance']->loadCacheFile('admin')) && ($GLOBALS['cache_instance']->extensionVersionMatches('admins'))) { @@ -57,7 +57,7 @@ if (($GLOBALS['cache_instance']->loadCacheFile('admin')) && ($GLOBALS['cache_ins foreach ($GLOBALS['cache_array']['admin']['login'] as $idx => $admin) { // Rewrite all entries foreach ($GLOBALS['cache_array']['admin'] as $key => $entry) { - // Do we have login or regular entries? + // Is there login or regular entries? if ($key == 'admin_id') { // Admin id, so use login $admins[$key][$GLOBALS['cache_array']['admin']['login'][$idx]] = $entry[$idx]; @@ -89,19 +89,23 @@ if (($GLOBALS['cache_instance']->loadCacheFile('admin')) && ($GLOBALS['cache_ins $add = runFilterChain('sql_admin_extra_data'); // Query the database about this - $result_admins = SQL_QUERY('SELECT - `id` AS admin_id, `login`, `password`, `email`' . $add . ' + $result = SQL_QUERY('SELECT + `id` AS `admin_id`, + `login`, + `password`, + `email` + ' . $add . ' FROM `{?_MYSQL_PREFIX?}_admins` ORDER BY `login` ASC', __FILE__, __LINE__); - while ($dummy = SQL_FETCHARRAY($result_admins)) { + while ($row = SQL_FETCHARRAY($result)) { // Save row - $GLOBALS['cache_instance']->addRow($dummy); + $GLOBALS['cache_instance']->addRow($row); } // END - while // Free memory - SQL_FREERESULT($result_admins); + SQL_FREERESULT($result); // Close cache $GLOBALS['cache_instance']->storeExtensionVersion('admins'); @@ -112,14 +116,48 @@ ORDER BY if (isExtensionInstalledAndNewer('admins', '0.3')) { // Check for cache file if (($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) && ($GLOBALS['cache_instance']->extensionVersionMatches('admins'))) { - // Load referal system from cache + // Load admin ACLs from cache $GLOBALS['cache_array']['admin_acls'] = $GLOBALS['cache_instance']->getArrayFromCache(); + + // Check if valid + 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']))) { + // Check count + if (count($GLOBALS['cache_array']['admin_acls']['admin_id']) == count($GLOBALS['cache_array']['admin_acls']['access_mode'])) { + // Rewrite the cache + $admins = array(); + foreach ($GLOBALS['cache_array']['admin_acls']['admin_id'] as $idx => $admin) { + // Rewrite all entries + foreach ($GLOBALS['cache_array']['admin_acls'] as $key => $entry) { + // Is there 'admin_id' or regular entries? + if ($key != 'admin_id') { + // Regular entry so use id + array_push($admins[$key][$GLOBALS['cache_array']['admin_acls']['admin_id'][$idx]], $entry[$idx]); + } // END - if + } // END - foreach + } // END - foreach + + // Transfer back to cache array and remove dummy + $GLOBALS['cache_array']['admin_acls'] = $admins; + unset($admins); + } else { + // Nope, cache file is corrupted! + $GLOBALS['cache_instance']->removeCacheFile(); + unset($GLOBALS['cache_array']['admin_acls']); + } + } elseif (count($GLOBALS['cache_array']['admin_acls']) > 0) { + // Nope, cache file is corrupted! + $GLOBALS['cache_instance']->removeCacheFile(); + unset($GLOBALS['cache_array']['admin_acls']); + } elseif (isDebugModeEnabled()) { + // This may drive a lot messages to the logfile + //* DEBUG: */ logDebugMessage(__FILE__, __LINE__, 'No entry found in admin_acls to rewrite.'); + } } elseif (isHtmlOutputMode()) { // Create cache file here $GLOBALS['cache_instance']->init(); - // Load all modules and their data (column 'id' is no longer required) - $result = SQL_QUERY('SELECT `admin_id`, `action_menu`, `what_menu`, `access_mode` FROM `{?_MYSQL_PREFIX?}_admins_acls` ORDER BY `admin_id` ASC, `action_menu` ASC, `what_menu` ASC', __FILE__, __LINE__); + // Load all admins and their data + $result = SQL_QUERY('SELECT * FROM `{?_MYSQL_PREFIX?}_admins_acls` ORDER BY `admin_id` ASC,`action_menu` ASC,`what_menu` ASC', __FILE__, __LINE__); // Add all rows while ($content = SQL_FETCHARRAY($result)) {