X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fmysql-manager.php;h=c72706cbd7a135ae93c65367927a18aca8c93ab6;hb=9a0f68701baa295b2546aa234704f50b8355ddcf;hp=8f9d7bb7a9d8113e9597e7862f29f18126223f74;hpb=a18efdcd57ba91893f0958a457b5c58639b135c3;p=mailer.git diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php index 8f9d7bb7a9..c72706cbd7 100644 --- a/inc/mysql-manager.php +++ b/inc/mysql-manager.php @@ -16,7 +16,7 @@ * $Author:: $ * * -------------------------------------------------------------------- * * Copyright (c) 2003 - 2009 by Roland Haeder * - * Copyright (c) 2009 - 2011 by Mailer Developer Team * + * 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 * @@ -42,16 +42,19 @@ if (!defined('__SECURITY')) { // "Getter" for module description // @TODO Can we cache this? -function getTitleFromMenu ($mode, $what, $column = 'what', $ADD='') { +function getTitleFromMenu ($mode, $what, $column = 'what', $ADD = '') { + // Debug message + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'mode=' . $mode . ',what=' . $what . ',column=' . $column . ',add=' . $ADD); + // Fix empty 'what' if (empty($what)) { $what = getIndexHome(); } elseif ((isGetRequestElementSet('action')) && ($column == 'what')) { // Get it from action return getTitleFromMenu($mode, getAction(), 'action', $ADD); - } elseif ($what == 'overview') { + } elseif ($what == 'welcome') { // Overview page - return '{--WHAT_IS_OVERVIEW--}'; + return '{--WHAT_IS_WELCOME--}'; } // Default is not found @@ -163,7 +166,7 @@ function addYouAreHereLink ($accessLevel, $FQFN, $return = false) { // Can we close the you-are-here navigation? //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'type=' . $type . 'getWhat()=' . getWhat()); - if (($type == 'what') || (($type == 'action') && ((!isWhatSet()) || (getWhat() == 'overview')))) { + if (($type == 'what') || (($type == 'action') && ((!isWhatSet()) || (getWhat() == 'welcome')))) { //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'type=' . $type); // Add closing div and br-tag $GLOBALS['nav_depth'] = '0'; @@ -270,7 +273,7 @@ ORDER BY } // END - if // Is ext-sql_patches up-to-date, and display_home_in_index is Y? - if ((isExtensionInstalledAndNewer('sql_patches', '0.8.3')) && (isDisplayHomeInIndexEnabled()) && ($content['sub_what'] == getIndexHome())) { + if ((getModule() == 'index') && (isExtensionInstalledAndNewer('sql_patches', '0.8.3')) && (isDisplayHomeInIndexEnabled()) && ($content['sub_what'] == getIndexHome())) { // Use index.php as link $OUT .= ''; } else { @@ -279,7 +282,7 @@ ORDER BY } } else { // Not found - open - $OUT .= ''; + $OUT .= ''; } // Menu title @@ -294,7 +297,7 @@ ORDER BY } // END - if } else { // Not found - close - $OUT .= ''; + $OUT .= ''; } // Cunt it up @@ -368,8 +371,8 @@ ORDER BY // Prepare data $content = array( - 'rows' => $GLOBALS['rows'], - 'mode' => $mode + 'rows' => $GLOBALS['rows'], + 'menu_mode' => $mode ); // Load main template @@ -378,7 +381,7 @@ ORDER BY } // END - if } -// Checks wether the current user is a member +// Checks whether the current user is a member function isMember () { // By default no member $ret = false; @@ -423,7 +426,7 @@ function isMember () { // So did we now have valid data and an unlocked user? if ((getUserData('status') == 'CONFIRMED') && ($valPass == getSession('u_hash'))) { // Transfer last module and online time - $GLOBALS['last_online']['module'] = getUserData('last_module'); + $GLOBALS['last_online']['module'] = getUserData(getUserLastWhatName()); $GLOBALS['last_online']['online'] = getUserData('last_online'); // Account is confirmed and all cookie data is valid so he is definely logged in! :-) @@ -453,7 +456,7 @@ function fetchUserData ($value, $column = 'userid') { return false; } elseif (is_null($value)) { // This shall never happen, so please report it - debug_report_bug(__FUNCTION__, __LINE__, 'value=NULL,column=' . $column . ' - value can never be NULL'); + reportBug(__FUNCTION__, __LINE__, 'value=NULL,column=' . $column . ' - value can never be NULL'); } // If we should look for userid secure&set it here @@ -467,7 +470,7 @@ function fetchUserData ($value, $column = 'userid') { // Don't look for invalid userids... if (!isValidUserId($value)) { // Invalid, so abort here - debug_report_bug(__FUNCTION__, __LINE__, 'User id ' . $value . ' is invalid.'); + reportBug(__FUNCTION__, __LINE__, 'User id ' . $value . ' is invalid.'); } elseif (isUserDataValid()) { // Use cache, so it is fine //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'value=' . $value . ' is valid, using cache #1'); @@ -482,14 +485,11 @@ function fetchUserData ($value, $column = 'userid') { // By default none was found $found = false; - // Extra statements - $ADD = ''; - if (isExtensionInstalledAndNewer('user', '0.3.5')) { - $ADD = ', UNIX_TIMESTAMP(`lock_timestamp`) AS `lock_timestamp`'; - } // END - if + // Extra SQL statements + $ADD = runFilterChain('convert_user_data_columns', ''); // Query for the user - $result = SQL_QUERY_ESC("SELECT *".$ADD." FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `%s`='%s' LIMIT 1", + $result = SQL_QUERY_ESC("SELECT *" . $ADD . " FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `%s`='%s' LIMIT 1", array($column, $value), __FUNCTION__, __LINE__); // Do we have a record? @@ -541,7 +541,12 @@ function fetchUserData ($value, $column = 'userid') { return $found; } -// This patched function will reduce many SELECT queries for the specified or current admin login +/* + * Checks whether the current session bears a valid admin id and password hash. + * + * This patched function will reduce many SELECT queries for the current admin + * login. + */ function isAdmin () { // No admin in installation phase! if ((isInstallationPhase()) || (!isAdminRegistered())) { @@ -551,7 +556,7 @@ function isAdmin () { // Init variables $ret = false; $adminId = '0'; - $passCookie = ''; + $passwordFromCookie = ''; $valPass = ''; //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $adminId); @@ -559,12 +564,16 @@ function isAdmin () { if ((isSessionVariableSet('admin_id')) && (isSessionVariableSet('admin_md5'))) { // Get admin login and password from session/cookies $adminId = getCurrentAdminId(); - $passCookie = getAdminMd5(); + $passwordFromCookie = getAdminMd5(); } // END - if - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'mainId=' . $adminId . 'passCookie=' . $passCookie); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminId=' . $adminId . 'passwordFromCookie=' . $passwordFromCookie); // Abort if admin id is zero if ($adminId == '0') { + // A very noisy debug message ... + //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Current adminId is zero. isSessionVariableSet(admin_id)=' . intval(isSessionVariableSet('admin_id')) . ',isSessionVariableSet(admin_md5)=' . intval(isSessionVariableSet('admin_md5'))); + + // Abort here now return false; } // END - if @@ -577,7 +586,7 @@ function isAdmin () { if (isset($GLOBALS['admin_hash'])) { // Use cached string $valPass = $GLOBALS['admin_hash']; - } elseif ((!empty($passCookie)) && (isAdminHashSet($adminId) === true) && (!empty($adminId))) { + } elseif ((!empty($passwordFromCookie)) && (isAdminHashSet($adminId) === true) && (!empty($adminId))) { // Login data is valid or not? $valPass = encodeHashForCookie(getAdminHash($adminId)); @@ -596,8 +605,8 @@ function isAdmin () { if (!empty($valPass)) { // Check if password is valid - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '(' . $valPass . '==' . $passCookie . ')='.intval($valPass == $passCookie)); - $GLOBALS[__FUNCTION__][$adminId] = (($GLOBALS['admin_hash'] == $passCookie) || ((strlen($GLOBALS['admin_hash']) == 32) && ($GLOBALS['admin_hash'] == md5($passCookie))) || (($GLOBALS['admin_hash'] == '*FAILED*') && (!isExtensionActive('cache')))); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '(' . $valPass . '==' . $passwordFromCookie . ')='.intval($valPass == $passwordFromCookie)); + $GLOBALS[__FUNCTION__][$adminId] = ($GLOBALS['admin_hash'] == $passwordFromCookie); } // END - if } // END - if @@ -617,6 +626,7 @@ function addMaxReceiveList ($mode, $default = '', $return = false) { __FUNCTION__, __LINE__); break; + case 'admin': 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', @@ -633,7 +643,11 @@ function addMaxReceiveList ($mode, $default = '', $return = false) { $OUT = ''; while ($content = SQL_FETCHARRAY($result)) { $OUT .= ' '; + foreach ($categories['id'] as $key => $value) { + $OUT .= ' '; } // END - foreach } else { // No cateogries are defined yet - $OUT = ''; + $OUT = ''; } // Return HTML code @@ -1583,8 +1633,7 @@ VALUES ('%s','%s','%s',%s,%s,'NEW', UNIX_TIMESTAMP(),'%s',%s,%s,%s)", // Generate a receiver list for given category and maximum receivers function generateReceiverList ($categoryId, $receiver, $mode = '') { // Init variables - $CAT_TABS = ''; - $CAT_WHERE = ''; + $extraColumns = ''; $receiverList = ''; $result = false; @@ -1598,32 +1647,32 @@ function generateReceiverList ($categoryId, $receiver, $mode = '') { $receiver = getTotalReceivers($mode); } // END - if + // Exclude (maybe exclude) testers + $addWhere = runFilterChain('user_exclusion_sql', ' '); + // Category given? if ($categoryId > 0) { // Select category - $CAT_TABS = "LEFT JOIN `{?_MYSQL_PREFIX?}_user_cats` AS c ON d.`userid`=c.`userid`"; - $CAT_WHERE = sprintf(" AND c.`cat_id`=%s", $categoryId); + $extraColumns = "LEFT JOIN `{?_MYSQL_PREFIX?}_user_cats` AS c ON d.`userid`=c.`userid`"; + $addWhere = sprintf(" AND c.`cat_id`=%s", $categoryId); } // END - if // Exclude users in holiday? if (isExtensionInstalledAndNewer('holiday', '0.1.3')) { // Add something for the holiday extension - $CAT_WHERE .= " AND d.`holiday_active`='N'"; + $addWhere .= " AND d.`holiday_active`='N'"; } // END - if + // Include only HTML recipients? if ((isExtensionActive('html_mail')) && ($mode == 'html')) { - // Only include HTML receivers - $result = SQL_QUERY_ESC("SELECT d.`userid` FROM `{?_MYSQL_PREFIX?}_user_data` AS d ".$CAT_TABS." WHERE d.`status`='CONFIRMED' AND d.`html`='Y'".$CAT_WHERE." ORDER BY d.`{?order_select?}` {?order_mode?} LIMIT %s", - array( - $receiver - ), __FUNCTION__, __LINE__); - } else { - // Include all - $result = SQL_QUERY_ESC("SELECT d.`userid` FROM `{?_MYSQL_PREFIX?}_user_data` AS d ".$CAT_TABS." WHERE d.`status`='CONFIRMED'".$CAT_WHERE." ORDER BY d.`{?order_select?}` {?order_mode?} LIMIT %s", - array( - $receiver - ), __FUNCTION__, __LINE__); - } + $addWhere .= " AND d.`html`='Y'"; + } // END - if + + // Run query + $result = SQL_QUERY_ESC("SELECT d.`userid` FROM `{?_MYSQL_PREFIX?}_user_data` AS d ".$extraColumns." WHERE d.`status`='CONFIRMED' ".$addWhere." ORDER BY d.`{?order_select?}` {?order_mode?} LIMIT %s", + array( + $receiver + ), __FUNCTION__, __LINE__); // Entries found? if ((SQL_NUMROWS($result) >= $receiver) && ($receiver > 0)) { @@ -1695,8 +1744,8 @@ function createNewTask ($subject, $notes, $taskType, $userid = NULL, $adminId = // Insert the task data into the database SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_task_system` (`assigned_admin`,`userid`,`status`,`task_type`,`subject`,`text`,`task_created`) VALUES (%s,%s,'NEW','%s','%s','%s', UNIX_TIMESTAMP())", array( - makeZeroToNull($adminId), - makeZeroToNull($userid), + convertZeroToNull($adminId), + convertZeroToNull($userid), $taskType, $subject, $notes @@ -1707,23 +1756,91 @@ function createNewTask ($subject, $notes, $taskType, $userid = NULL, $adminId = } // Updates last module / online time -// @TODO Fix inconsistency between last_module and getWhat() function updateLastActivity($userid) { - // Run the update query - SQL_QUERY_ESC("UPDATE + // Is 'what' set? + if (isWhatSet()) { + // Run the update query + SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET - `last_module`='%s', + `%s`='%s', `last_online`=UNIX_TIMESTAMP(), `REMOTE_ADDR`='%s' WHERE `userid`=%s LIMIT 1", array( + getUserLastWhatName(), getWhat(), detectRemoteAddr(), bigintval($userid) ), __FUNCTION__, __LINE__); + } else { + // No what set, needs to be ignored (last_module is last_what) + SQL_QUERY_ESC("UPDATE + `{?_MYSQL_PREFIX?}_user_data` +SET + `%s`=NULL, + `last_online`=UNIX_TIMESTAMP(), + `REMOTE_ADDR`='%s' +WHERE + `userid`=%s +LIMIT 1", + array( + getUserLastWhatName(), + detectRemoteAddr(), + bigintval($userid) + ), __FUNCTION__, __LINE__); + } +} + +/** + * Checks if given subject is found and if not, adds an SQL query to the + * extension registration queue. + */ +function registerExtensionPointsData ($subject, $columnName, $lockedMode, $paymentMethod) { + // Default is old extension version + $add = ''; + + // Is the extension equal or newer 0.8.9? + if (isExtensionInstalledAndNewer('sql_patches', '0.8.9')) { + // Then add provider + $add = " AND `account_provider`='EXTENSION'"; + } // END - if + + // Is the 'subject' there? + if (countSumTotalData($subject, 'points_data', 'id', 'subject', true, $add) == 0) { + // Not found so add an SQL query + addExtensionSql(sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_points_data` (`subject`,`column_name`,`locked_mode`,`payment_method`) VALUES ('%s','%s','%s','%s')", + $subject, + $columnName, + $lockedMode, + $paymentMethod + )); + } // END - if +} + +/** + * Checks if given subject is found and if so, adds an SQL query to the + * extension unregistration queue. + */ +function unregisterExtensionPointsData ($subject) { + // Default is old extension version + $add = ''; + + // Is the extension equal or newer 0.8.9? + if (isExtensionInstalledAndNewer('sql_patches', '0.8.9')) { + // Then add provider + $add = " AND `account_provider`='EXTENSION'"; + } // END - if + + // Is the 'subject' there? + if (countSumTotalData($subject, 'points_data', 'id', 'subject', true, $add) == 1) { + // Found one or more, so add an SQL query + addExtensionSql(sprintf("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_points_data` WHERE `subject`='%s'" . $add . " LIMIT 1", + $subject + )); + } // END - if } // [EOF]