X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fmysql-manager.php;h=874884fd8809d0e517ff1b928ef92604bf58ceeb;hb=07ec113b187228ba74b4b08966602c4a2c161d2c;hp=ebb750ba2754d42b4215eed8f8deb146dac08ec0;hpb=04b69ac9f33369cbf654396c4a42cb1fff710ff4;p=mailer.git
diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php
index ebb750ba27..874884fd88 100644
--- a/inc/mysql-manager.php
+++ b/inc/mysql-manager.php
@@ -42,60 +42,12 @@ if (!defined('__SECURITY')) {
die();
} // END - if
-// "Getter" for module title
-function getModuleTitle ($module) {
- // Init variables
- $data['title'] = '';
- $result = false;
-
- // Is the script installed?
- if (isInstalled()) {
- // Check if cache is valid
- if ((isExtensionInstalledAndNewer('cache', '0.1.2')) && (isset($GLOBALS['cache_array']['modules']['module'])) && (in_array($module, $GLOBALS['cache_array']['modules']['module']))) {
- // Load from cache
- $data['title'] = $GLOBALS['cache_array']['modules']['title'][$module];
-
- // Update cache hits
- incrementStatsEntry('cache_hits');
- } elseif (!isExtensionActive('cache')) {
- // Load from database
- $result = SQL_QUERY_ESC("SELECT `title` FROM `{?_MYSQL_PREFIX?}_mod_reg` WHERE `module`='%s' LIMIT 1",
- array($module), __FUNCTION__, __LINE__);
-
- // Is the entry there?
- if (SQL_NUMROWS($result)) {
- // Get the title from database
- $data = SQL_FETCHARRAY($result);
- } // END - if
-
- // Free the result
- SQL_FREERESULT($result);
- }
- } // END - if
-
- // Trim name
- $data['title'] = trim($data['title']);
-
- // Still no luck or empty title?
- if (empty($data['title'])) {
- // No name found
- $data['title'] = getMaskedMessage('UNKNOWN_MODULE_DETECTED', $module);
- if ((is_resource($result)) && (SQL_HASZERONUMS($result))) {
- // Add module to database
- $dummy = checkModulePermissions($module);
- } // END - if
- } // END - if
-
- // Return name
- return $data['title'];
-}
-
// "Getter" for module description
// @TODO Can we cache this?
function getTitleFromMenu ($mode, $what, $column = 'what', $ADD='') {
// Fix empty 'what'
if (empty($what)) {
- $what = getConfig('index_home');
+ $what = getIndexHome();
} // END - if
// Default is not found
@@ -122,177 +74,6 @@ function getTitleFromMenu ($mode, $what, $column = 'what', $ADD='') {
return $data['title'];
}
-// Check validity of a given module name (no file extension)
-function checkModulePermissions ($module = '') {
- // Is it empty (default), then take the current one
- if (empty($module)) $module = getModule();
-
- // Do we have cache?
- if (isset($GLOBALS['module_status'][$module])) {
- // Then use it
- return $GLOBALS['module_status'][$module];
- } // END - if
-
- // Filter module name (names with low chars and underlines are fine!)
- $module = preg_replace('/[^a-z_]/', '', $module);
-
- // Check for prefix is a extension...
- $modSplit = explode('_', $module);
- $extension = ''; $module_chk = $module;
- //* DEBUG: */ debugOutput(__LINE__.'*'.count($modSplit).'/'.$module.'*');
- if (count($modSplit) == 2) {
- // Okay, there is a seperator (_) in the name so is the first part a module?
- //* DEBUG: */ debugOutput(__LINE__.'*'.$modSplit[0].'*');
- if (isExtensionActive($modSplit[0])) {
- // The prefix is an extension's name, so let's set it
- $extension = $modSplit[0]; $module = $modSplit[1];
- } // END - if
- } // END - if
-
- // Major error in module registry is the default
- $ret = 'major';
-
- // Check if script is installed if not return a 'done' to prevent some errors
- if ((isInstallationPhase()) || (!isAdminRegistered())) {
- // Not installed or no admin registered or in installation phase
- return 'done';
- } // END - if
-
- // Init data array
- $data = array(
- 'locked' => 'Y',
- 'hidden' => 'N',
- 'admin_only' => 'N',
- 'mem_only' => 'N'
- );
-
- // By default nothing is found
- $found = false;
-
- // Check if cache is latest version
- if (isExtensionInstalledAndNewer('cache', '0.1.2')) {
- // Is the cache there?
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Using cache.');
- if (isset($GLOBALS['cache_array']['modules']['locked'][$module_chk])) {
- // Check cache
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cache found.');
- $data['locked'] = $GLOBALS['cache_array']['modules']['locked'][$module_chk];
- $data['hidden'] = $GLOBALS['cache_array']['modules']['hidden'][$module_chk];
- $data['admin_only'] = $GLOBALS['cache_array']['modules']['admin_only'][$module_chk];
- $data['mem_only'] = $GLOBALS['cache_array']['modules']['mem_only'][$module_chk];
-
- // Update cache hits
- incrementStatsEntry('cache_hits');
- $found = true;
- } else {
- // No, then we have to update it!
- $ret = 'cache_miss';
- }
- } elseif (!isExtensionActive('cache')) {
- // Check for module in database
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Using database.');
- $result = SQL_QUERY_ESC("SELECT `locked`, `hidden`, `admin_only`, `mem_only` FROM `{?_MYSQL_PREFIX?}_mod_reg` WHERE `module`='%s' LIMIT 1",
- array($module_chk), __FUNCTION__, __LINE__);
- if (SQL_NUMROWS($result) == 1) {
- // Read data
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Entry found.');
- $data = SQL_FETCHARRAY($result);
- $found = true;
- } elseif (isDebugModeEnabled()) {
- // Debug message only in debug-mode...
- logDebugMessage(__FUNCTION__, __LINE__, 'Module ' . $module_chk . ' not found!');
- }
-
- // Free result
- SQL_FREERESULT($result);
- }
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret=' . $ret);
-
- // Is the module found?
- if ($found === true) {
- // Check returned values against current access permissions
- //
- // Admin access ----- Guest access ----- --- Guest or member? ---
- if ((isAdmin()) || (($data['locked'] != 'Y') && ($data['admin_only'] != 'Y') && (($data['mem_only'] != 'Y') || (isMember())))) {
- // If you are admin you are welcome for everything!
- $ret = 'done';
- } elseif ($data['locked'] == 'Y') {
- // Module is locked
- $ret = 'locked';
- } elseif (($data['mem_only'] == 'Y') && (!isMember())) {
- // You have to login first!
- $ret = 'mem_only';
- } elseif (($data['admin_only'] == 'Y') && (!isAdmin())) {
- // Only the Admin is allowed to enter this module!
- $ret = 'admin_only';
- } else {
- // @TODO Nothing helped???
- logDebugMessage(__FUNCTION__, __LINE__, sprintf("ret=%s,locked=%s,admin=%s,mem=%s",
- $ret,
- $data['locked'],
- $data['admin_only'],
- $data['mem_only']
- ));
- }
- } // END - if
-
- // Still no luck or not found?
- if (($found === false) && (!isExtensionActive('cache')) && ($ret != 'done')) {
- // ----- Legacy module ----- ---- Module in base folder ---- --- Module with extension's name ---
- if ((isIncludeReadable(sprintf("inc/modules/%s.php", $module))) || (isIncludeReadable(sprintf("%s.php", $module))) || (isIncludeReadable(sprintf("%s/%s.php", $extension, $module)))) {
- // Data is missing so we add it
- if (isExtensionInstalledAndNewer('sql_patches', '0.3.6')) {
- // Since 0.3.6 we have a has_menu column, this took me a half hour
- // to find a loop here... *sigh*
- SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_mod_reg`
-(`module`, `locked`, `hidden`, `mem_only`, `admin_only`, `has_menu`) VALUES
-('%s','Y','N','N','N','N')", array($module_chk), __FUNCTION__, __LINE__);
- } else {
- // Wrong/missing sql_patches!
- SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_mod_reg`
-(`module`, `locked`, `hidden`, `mem_only`, `admin_only`) VALUES
-('%s','Y','N','N','N')", array($module_chk), __FUNCTION__, __LINE__);
- }
-
- // Everthing is fine?
- if (SQL_AFFECTEDROWS() < 1) {
- // Something bad happend!
- return 'major';
- } // END - if
-
- // Destroy cache here
- // @TODO Rewrite this to a filter
- if ((getOutputMode() == '0') || (getOutputMode() == -1)) rebuildCache('modules', 'modules');
-
- // And reload data
- unset($GLOBALS['module_status'][$module]);
- $ret = checkModulePermissions($module_chk);
- } else {
- // Module not found we don't add it to the database
- $ret = '404';
- }
- } elseif (($ret == 'cache_miss') && (getOutputMode() == '0')) {
- // Rebuild the cache files
- rebuildCache('modules', 'modules');
- } elseif ($found === false) {
- // Problem with module detected
- logDebugMessage(__FUNCTION__, __LINE__, sprintf("Problem in module %s detected. ret=%s, locked=%s, hidden=%s, mem=%s, admin=%s, output_mode=%s",
- $module,
- $ret,
- $data['locked'],
- $data['hidden'],
- $data['mem_only'],
- $data['admin_only'],
- getOutputMode()
- ));
- }
-
- // Return the value
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret=' . $ret);
- $GLOBALS['module_status'][$module] = $ret;
- return $ret;
-}
-
// Add menu description pending on given file name (without path!)
function addMenuDescription ($accessLevel, $FQFN, $return = false) {
// Use only filename of the FQFN...
@@ -328,7 +109,7 @@ function addMenuDescription ($accessLevel, $FQFN, $return = false) {
if (isAdmin()) $ADD = '';
$dummy = substr($search, 0, -4);
- $ADD .= " AND `action`='".getActionFromModuleWhat($accessLevel, $dummy)."'";
+ $ADD .= sprintf(" AND `action`='%s'", getActionFromModuleWhat($accessLevel, $dummy));
} elseif (($accessLevel == 'sponsor') || ($accessLevel == 'engine')) {
// Sponsor / engine menu
$type = 'what';
@@ -344,7 +125,7 @@ function addMenuDescription ($accessLevel, $FQFN, $return = false) {
}
// Begin the navigation line
- if ((!isset($GLOBALS['nav_depth'])) && ($return === false)) {
+ if (!isset($GLOBALS['nav_depth'])) {
// Init nav_depth
$GLOBALS['nav_depth'] = '0';
@@ -366,7 +147,7 @@ function addMenuDescription ($accessLevel, $FQFN, $return = false) {
if (substr($search, -4, 4) == '.php') {
// Remove the .php
$search = substr($search, 0, -4);
- } // END - i
+ } // END - if
if (((isExtensionInstalledAndNewer('sql_patches', '0.2.3')) && (getConfig('youre_here') == 'Y')) || ((isAdmin()) && ($modCheck == 'admin'))) {
// Output HTML code
@@ -427,7 +208,7 @@ ORDER BY
array($mode), __FUNCTION__, __LINE__);
//* DEBUG: */ debugOutput(__LINE__.'/'.$main_cnt.':'.getWhat().'*');
- if (SQL_NUMROWS($result_main) > 0) {
+ if (!SQL_HASZERONUMS($result_main)) {
// There are menus available, so we simply display them... :)
$GLOBALS['rows'] = '';
while ($content = SQL_FETCHARRAY($result_main)) {
@@ -456,7 +237,7 @@ ORDER BY
array($mode, $content['action']), __FUNCTION__, __LINE__);
// Do we have some entries?
- if (SQL_NUMROWS($result_sub) > 0) {
+ if (!SQL_HASZERONUMS($result_sub)) {
// Init counter
$cnt = '0';
@@ -481,11 +262,11 @@ ORDER BY
$OUT .= '';
@@ -590,10 +371,10 @@ function isMember () {
if ((!isset($GLOBALS['last_online'])) || (!is_array($GLOBALS['last_online']))) $GLOBALS['last_online'] = array();
// is the cache entry there?
- if (isset($GLOBALS['is_member'])) {
+ if (isset($GLOBALS[__FUNCTION__])) {
// Then return it
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'CACHED! (' . intval($GLOBALS['is_member']) . ')');
- return $GLOBALS['is_member'];
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'CACHED! (' . intval($GLOBALS[__FUNCTION__]) . ')');
+ return $GLOBALS[__FUNCTION__];
} elseif ((!isSessionVariableSet('userid')) || (!isSessionVariableSet('u_hash'))) {
// No member
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'No member set in cookie/session.');
@@ -643,7 +424,7 @@ function isMember () {
}
// Cache status
- $GLOBALS['is_member'] = $ret;
+ $GLOBALS[__FUNCTION__] = $ret;
// Return status
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret=' . intval($ret));
@@ -661,7 +442,7 @@ function fetchUserData ($userid, $column = 'userid') {
setCurrentUserId($userid);
// Don't look for invalid userids...
- if ($userid < 1) {
+ if (!isValidUserId($userid)) {
// Invalid, so abort here
debug_report_bug(__FUNCTION__, __LINE__, 'User id ' . $userid . ' is invalid.');
} elseif (isUserDataValid()) {
@@ -673,7 +454,6 @@ function fetchUserData ($userid, $column = 'userid') {
return true;
}
-
// By default none was found
$found = false;
@@ -733,7 +513,7 @@ function fetchUserData ($userid, $column = 'userid') {
}
// This patched function will reduce many SELECT queries for the specified or current admin login
-function isAdmin ($adminLogin = '') {
+function isAdmin () {
// No admin in installation phase!
if ((isInstallationPhase()) || (!isAdminRegistered())) {
return false;
@@ -741,39 +521,45 @@ function isAdmin ($adminLogin = '') {
// Init variables
$ret = false;
+ $adminId = '0';
$passCookie = '';
$valPass = '';
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $adminLogin);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $adminId);
// If admin login is not given take current from cookies...
- if ((empty($adminLogin)) && (isSessionVariableSet('admin_login')) && (isSessionVariableSet('admin_md5'))) {
+ if ((isSessionVariableSet('admin_id')) && (isSessionVariableSet('admin_md5'))) {
// Get admin login and password from session/cookies
- $adminLogin = getSession('admin_login');
+ $adminId = getSession('admin_id');
$passCookie = getSession('admin_md5');
} // END - if
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $adminLogin.'/'.$passCookie);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $adminId.'/'.$passCookie);
+
+ // Abort if admin id is zero
+ if ($adminId == '0') {
+ return false;
+ } // END - if
// Do we have cache?
- if (!isset($GLOBALS['is_admin'][$adminLogin])) {
+ if (!isset($GLOBALS[__FUNCTION__][$adminId])) {
// Init it with failed
- $GLOBALS['is_admin'][$adminLogin] = false;
+ $GLOBALS[__FUNCTION__][$adminId] = false;
// Search in array for entry
if (isset($GLOBALS['admin_hash'])) {
// Use cached string
$valPass = $GLOBALS['admin_hash'];
- } elseif ((!empty($passCookie)) && (isAdminHashSet($adminLogin) === true) && (!empty($adminLogin))) {
+ } elseif ((!empty($passCookie)) && (isAdminHashSet($adminId) === true) && (!empty($adminId))) {
// Login data is valid or not?
- $valPass = encodeHashForCookie(getAdminHash($adminLogin));
+ $valPass = encodeHashForCookie(getAdminHash($adminId));
// Cache it away
$GLOBALS['admin_hash'] = $valPass;
// Count cache hits
incrementStatsEntry('cache_hits');
- } elseif ((!empty($adminLogin)) && ((!isExtensionActive('cache')) || (isAdminHashSet($adminLogin) === false))) {
+ } elseif ((!empty($adminId)) && ((!isExtensionActive('cache')) || (isAdminHashSet($adminId) === false))) {
// Get admin hash and hash it
- $valPass = encodeHashForCookie(getAdminHash($adminLogin));
+ $valPass = encodeHashForCookie(getAdminHash($adminId));
// Cache it away
$GLOBALS['admin_hash'] = $valPass;
@@ -782,12 +568,12 @@ function isAdmin ($adminLogin = '') {
if (!empty($valPass)) {
// Check if password is valid
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '(' . $valPass . '==' . $passCookie . ')='.intval($valPass == $passCookie));
- $GLOBALS['is_admin'][$adminLogin] = (($valPass == $passCookie) || ((strlen($valPass) == 32) && ($valPass == md5($passCookie))) || (($valPass == '*FAILED*') && (!isExtensionActive('cache'))));
+ $GLOBALS[__FUNCTION__][$adminId] = (($GLOBALS['admin_hash'] == $passCookie) || ((strlen($GLOBALS['admin_hash']) == 32) && ($GLOBALS['admin_hash'] == md5($passCookie))) || (($GLOBALS['admin_hash'] == '*FAILED*') && (!isExtensionActive('cache'))));
} // END - if
} // END - if
// Return result of comparision
- return $GLOBALS['is_admin'][$adminLogin];
+ return $GLOBALS[__FUNCTION__][$adminId];
}
// Generates a list of "max receiveable emails per day"
@@ -798,13 +584,13 @@ function addMaxReceiveList ($mode, $default = '', $return = false) {
switch ($mode) {
case 'guest':
// Guests (in the registration form) are not allowed to select 0 mails per day.
- $result = SQL_QUERY("SELECT `value`, `comment` FROM `{?_MYSQL_PREFIX?}_max_receive` WHERE `value` > 0 ORDER BY `value` ASC",
+ $result = SQL_QUERY('SELECT `value`, `comment` FROM `{?_MYSQL_PREFIX?}_max_receive` WHERE `value` > 0 ORDER BY `value` ASC',
__FUNCTION__, __LINE__);
break;
case 'member':
// Members are allowed to set to zero mails per day (we will change this soon!)
- $result = SQL_QUERY("SELECT `value`, `comment` FROM `{?_MYSQL_PREFIX?}_max_receive` ORDER BY `value` ASC",
+ $result = SQL_QUERY('SELECT `value`, `comment` FROM `{?_MYSQL_PREFIX?}_max_receive` ORDER BY `value` ASC',
__FUNCTION__, __LINE__);
break;
@@ -814,7 +600,7 @@ function addMaxReceiveList ($mode, $default = '', $return = false) {
}
// Some entries are found?
- if (SQL_NUMROWS($result) > 0) {
+ if (!SQL_HASZERONUMS($result)) {
$OUT = '';
while ($content = SQL_FETCHARRAY($result)) {
$OUT .= '