X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fmysql-manager.php;h=e19b1689b05df9b64f6c9fdc057a31576abdfbdc;hb=b9edcfb00bb14c7b53b107ff5b1290841340b434;hp=0221150793c16c8881fd9d20f3104bd205007b2c;hpb=d3c4fdd9bfab35389e1a5ff48f3952d527c7b4bb;p=mailer.git diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php index 0221150793..e19b1689b0 100644 --- a/inc/mysql-manager.php +++ b/inc/mysql-manager.php @@ -79,7 +79,7 @@ function getModuleTitle ($mod) { if (empty($title)) { // No name found $title = sprintf("%s (%s)", getMessage('LANG_UNKNOWN_MODULE'), $mod); - if (SQL_NUMROWS($result) == 0) { + if (SQL_NUMROWS($result) == '0') { // Add module to database $dummy = checkModulePermissions($mod); } // END - if @@ -253,7 +253,7 @@ function checkModulePermissions ($mod = '') { // Destroy cache here // @TODO Rewrite this to a filter - if ((getOutputMode() == 0) || (getOutputMode() == -1)) rebuildCacheFile('modules', 'modules'); + if ((getOutputMode() == '0') || (getOutputMode() == -1)) rebuildCacheFile('modules', 'modules'); // And reload data unset($GLOBALS['module_status'][$mod]); @@ -262,7 +262,7 @@ function checkModulePermissions ($mod = '') { // Module not found we don't add it to the database $ret = '404'; } - } elseif (($ret == 'cache_miss') && (getOutputMode() == 0)) { + } elseif (($ret == 'cache_miss') && (getOutputMode() == '0')) { // Rebuild the cache files rebuildCacheFile('modules', 'modules'); } elseif ($found === false) { @@ -348,7 +348,7 @@ function addMenuDescription ($accessLevel, $FQFN, $return = false, $output = tru // Begin the navigation line if ((!isset($GLOBALS['nav_depth'])) && ($return === false)) { - $GLOBALS['nav_depth'] = 0; + $GLOBALS['nav_depth'] = '0'; $prefix = "
{--YOU_ARE_HERE--} Home"; } else { if ($return === false) $GLOBALS['nav_depth']++; @@ -386,7 +386,7 @@ function addMenuDescription ($accessLevel, $FQFN, $return = false, $output = tru //* DEBUG: */ print(__LINE__.'+'.$type."+
"); // Add closing div and br-tag $OUT .= "

\n"; - $GLOBALS['nav_depth'] = 0; + $GLOBALS['nav_depth'] = '0'; // Run the filter chain $ret = runFilterChain('post_youhere_line', array('access_level' => $accessLevel, 'type' => $type, 'content' => "")); @@ -411,7 +411,7 @@ function addMenuDescription ($accessLevel, $FQFN, $return = false, $output = tru // Adds a menu (mode = guest/member/admin/sponsor) to output function addMenu ($mode, $action, $what) { // Init some variables - $main_cnt = 0; + $main_cnt = '0'; $AND = ''; // is the menu action valid? @@ -451,7 +451,7 @@ function addMenu ($mode, $action, $what) { // Do we have some entries? if ($totalWhats > 0) { // Init counter - $cnt = 0; + $cnt = '0'; // Load all sub menus while ($content2 = SQL_FETCHARRAY($result_sub)) { @@ -580,54 +580,47 @@ function isMember () { if (isset($GLOBALS['is_member'])) { // Then return it return $GLOBALS['is_member']; - } // END - if + } elseif (getMemberId() == '0') { + // No member + return false; + } else { + // Transfer userid=>current + setCurrentUserid(getMemberId()); + } - // Init global 'status' - $GLOBALS['status'] = false; + // Init global user data array + initUserData(); // Fix "deleted" cookies first fixDeletedCookies(array('userid', 'u_hash')); // Are cookies set? - if ((isUserIdSet()) && (isSessionVariableSet('u_hash'))) { + if ((isMemberIdSet()) && (isSessionVariableSet('u_hash'))) { // Cookies are set with values, but are they valid? - $result = SQL_QUERY_ESC("SELECT `password`, `status`, `last_module`, `last_online` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s LIMIT 1", - array(getUserId()), __FUNCTION__, __LINE__); - if (SQL_NUMROWS($result) == 1) { - // Load data from cookies - list($password, $GLOBALS['status'], $mod, $onl) = SQL_FETCHROW($result); - + if (fetchUserData(getMemberId()) === true) { // Validate password by created the difference of it and the secret key - $valPass = generatePassString($password); + $valPass = generatePassString(getUserData('password')); // Transfer last module and online time - if ((!empty($mod)) && (empty($GLOBALS['last_online']['module']))) { - // @TODO Try to rewrite this to one or more functions - $GLOBALS['last_online']['module'] = $mod; - $GLOBALS['last_online']['online'] = $onl; - } // END - if + $GLOBALS['last_online']['module'] = getUserData('last_module'); + $GLOBALS['last_online']['online'] = getUserData('last_online'); // So did we now have valid data and an unlocked user? - if (($GLOBALS['status'] == 'CONFIRMED') && ($valPass == getSession('u_hash'))) { + if ((getUserData('status') == 'CONFIRMED') && ($valPass == getSession('u_hash'))) { // Account is confirmed and all cookie data is valid so he is definely logged in! :-) $ret = true; } else { // Maybe got locked etc. - //* DEBUG: */ print(__LINE__."!!!
"); - destroyUserSession(); + logDebugMessage(__FUNCTION__, __LINE__, 'status=' . getUserData('status')); + destroyMemberSession(); } } else { // Cookie data is invalid! - //* DEBUG: */ print(__LINE__."***
"); - destroyUserSession(); + destroyMemberSession(); } - - // Free memory - SQL_FREERESULT($result); } else { // Cookie data is invalid! - //* DEBUG: */ print(__LINE__."///
"); - destroyUserSession(); + destroyMemberSession(); } // Cache status @@ -637,6 +630,84 @@ function isMember () { return $ret; } +// Fetch user data for given user id +function fetchUserData ($userid, $column='userid') { + // If we should look for userid secure&set it here + if (substr($column, -2, 2) == 'id') { + // Secure userid + $userid = bigintval($userid); + + // Set it here + setCurrentUserId($userid); + + // Don't look for invalid userids... + if ($userid < 1) { + // Invalid, so abort here + debug_report_bug('User id ' . $userid . ' is invalid.'); + } elseif (isUserDataValid()) { + // Use cache, so it is fine + return true; + } + } elseif (isUserDataValid()) { + // Use cache, so it is fine + return true; + } + + + // By default none was found + $found = false; + + // Query for the user + $result = SQL_QUERY_ESC("SELECT * FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `%s`='%s' LIMIT 1", + array($column, $userid), __FUNCTION__, __LINE__); + + // Do we have a record? + if (SQL_NUMROWS($result) == 1) { + // Load data from cookies + $data = SQL_FETCHARRAY($result); + + // Set the userid for later use + setCurrentUserId($data['userid']); + $GLOBALS['user_data'][getCurrentUserId()] = $data; + + // Rewrite 'last_failure' if found + if (isset($GLOBALS['user_data'][getCurrentUserId()]['last_failure'])) { + // Backup the raw one and zero it + $GLOBALS['user_data'][getCurrentUserId()]['last_failure_raw'] = $GLOBALS['user_data'][getCurrentUserId()]['last_failure']; + $GLOBALS['user_data'][getCurrentUserId()]['last_failure'] = '0'; + + // Is it not zero? + if ($GLOBALS['user_data'][getCurrentUserId()]['last_failure_raw'] != '0000-00-00 00:00:00') { + // Seperate data/time + $array = explode(' ', $GLOBALS['user_data'][getCurrentUserId()]['last_failure_raw']); + + // Seperate data and time again + $array['date'] = explode('-', $array[0]); + $array['time'] = explode(':', $array[1]); + + // Now pass it to mktime() + $GLOBALS['user_data'][getCurrentUserId()]['last_failure'] = mktime( + $array['time'][0], + $array['time'][1], + $array['time'][2], + $array['date'][1], + $array['date'][2], + $array['date'][0] + ); + } // END - if + } // END - if + + // Found, but valid? + $found = isUserDataValid(); + } // END - if + + // Free memory + SQL_FREERESULT($result); + + // Return result + return $found; +} + // This patched function will reduce many SELECT queries for the specified or current admin login function isAdmin ($admin = '') { // Init variables @@ -806,6 +877,8 @@ function isMenuActionValid ($mode, $action, $what, $updateEntry=false) { // Run SQL command $result = SQL_QUERY($sql, __FUNCTION__, __LINE__); + + // Should we look for affected rows (only update) or found rows? if ($updateEntry === true) { // Check updated/affected rows $ret = (SQL_AFFECTEDROWS() == 1); @@ -824,24 +897,22 @@ function isMenuActionValid ($mode, $action, $what, $updateEntry=false) { return $ret; } -// +// Send out mails depending on the 'mod/modes' combination +// @TODO Lame description for this function function sendModeMails ($mod, $modes) { // Load hash - $result_main = SQL_QUERY_ESC("SELECT `password` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s AND `status`='CONFIRMED' LIMIT 1", - array(getUserId()), __FUNCTION__, __LINE__); - if (SQL_NUMROWS($result_main) == 1) { - // Load hash from database - list($hashDB) = SQL_FETCHROW($result_main); - + if (fetchUserData(getMemberId())) { // Extract salt from cookie $salt = substr(getSession('u_hash'), 0, -40); // Now let's compare passwords - $hash = generatePassString($hashDB); + $hash = generatePassString(getUserData('password')); + + // Does the hash match or should we change it? if (($hash == getSession('u_hash')) || (postRequestElement('pass1') == postRequestElement('pass2'))) { // Load user's data 0 1 2 3 4 5 6 7 $result = SQL_QUERY_ESC("SELECT gender, surname, family, street_nr, country, zip, city, email FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s AND password='%s' LIMIT 1", - array(getUserId(), $hashDB), __FUNCTION__, __LINE__); + array(getMemberId(), getUserData('password')), __FUNCTION__, __LINE__); if (SQL_NUMROWS($result) == 1) { // Load the data $content = SQL_FETCHARRAY($result, 0, false); @@ -853,7 +924,7 @@ function sendModeMails ($mod, $modes) { $content['gender'] = translateGender($content['gender']); // Clear/init the content variable - $content['info'] = ''; + $content['message'] = ''; switch ($mod) { case 'mydata': @@ -870,10 +941,10 @@ function sendModeMails ($mod, $modes) { default: logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unknown mode %s detected.", $mode)); - $content['message'] = getMessage('MEMBER_UNKNOWN_MODE').": ".$mode."\n\n"; + $content['message'] = getMessage('MEMBER_UNKNOWN_MODE') . ': ' . $mode . "\n\n"; break; } // END - switch - } // END - if + } // END - foreach if (isExtensionActive('country')) { // Replace code with description @@ -884,7 +955,7 @@ function sendModeMails ($mod, $modes) { $content = merge_array($content, postRequestArray()); // Load template - $message = loadEmailTemplate('member_mydata_notify', $content, getUserId()); + $message = loadEmailTemplate('member_mydata_notify', $content, getMemberId()); if (getConfig('admin_notify') == 'Y') { // The admin needs to be notified about a profile change @@ -931,7 +1002,7 @@ function sendModeMails ($mod, $modes) { if (empty($content)) { if ((!empty($sub_adm)) && (!empty($message_admin))) { // Send admin mail - sendAdminNotification($sub_adm, $message_admin, $content, getUserId()); + sendAdminNotification($sub_adm, $message_admin, $content, getMemberId()); } elseif (getConfig('admin_notify') == 'Y') { // Cannot send mails to admin! $content = getMessage('CANNOT_SEND_ADMIN_MAILS'); @@ -1009,7 +1080,7 @@ function getCategory ($cid) { $ret = getMessage('_CATEGORY_404'); // Is the category id set? - if ($cid == 0) { + if ($cid == '0') { // No category $ret = getMessage('_CATEGORY_NONE'); } elseif ($cid > 0) { @@ -1099,7 +1170,7 @@ function removeReceiver (&$receivers, $key, $userid, $pool_id, $stats_id = '', $ array($rowName, $stats_id, bigintval($userid), $type), __FUNCTION__, __LINE__); // Was it *not* found? - if (SQL_NUMROWS($result) == 0) { + if (SQL_NUMROWS($result) == '0') { // So we add one! SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_links` (`%s`, `userid`, `link_type`) VALUES ('%s','%s','%s')", array($rowName, $stats_id, bigintval($userid), $type), __FUNCTION__, __LINE__); @@ -1120,7 +1191,7 @@ function removeReceiver (&$receivers, $key, $userid, $pool_id, $stats_id = '', $ // Calculate sum (default) or count records of given criteria function countSumTotalData ($search, $tableName, $lookFor = 'id', $whereStatement = 'userid', $countRows = false, $add = '') { - $ret = 0; + $ret = '0'; //* DEBUG: */ print($search.'/'.$tableName.'/'.$lookFor.'/'.$whereStatement.'/'.$add.'
'); if ((empty($search)) && ($search != '0')) { // Count or sum whole table? @@ -1157,16 +1228,17 @@ function countSumTotalData ($search, $tableName, $lookFor = 'id', $whereStatemen $ret = '0.00000'; } elseif (''.$ret.'' == '') { // Fix empty result - $ret = 0; + $ret = '0'; } // Return value + //* DEBUG: */ print 'ret='.$ret.'
'; return $ret; } // Getter fro ref level percents function getReferalLevelPercents ($level) { // Default is zero - $per = 0; + $per = '0'; // Do we have cache? if ((isset($GLOBALS['cache_array']['refdepths']['level'])) && (isExtensionActive('cache'))) { @@ -1211,13 +1283,13 @@ function getReferalLevelPercents ($level) { * add_mode = Add points only to $userid or also refs? (WARNING! Changing 'ref' to 'direct' * for default value will cause no referal will get points ever!!!) */ -function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify = false, $rid = 0, $locked = false, $add_mode = 'ref') { +function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify = false, $rid = '0', $locked = false, $add_mode = 'ref') { //* DEBUG: */ print("----------------------- ".__FUNCTION__." - ENTRY ----------------------------------------------- ".__FUNCTION__." - EXIT ------------------------
"); } @@ -1357,23 +1423,24 @@ function updateReferalCounter ($userid) { //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):userid={$userid}
"); } // END - if - // Check for his referal - $result = SQL_QUERY_ESC("SELECT `refid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s LIMIT 1", - array(bigintval($userid)), __FUNCTION__, __LINE__); + // Init referal id + $ref = '0'; - // Load refid - list($ref) = SQL_FETCHROW($result); + // Check for his referal + if (fetchUserData($userid)) { + // Get it + $ref = getUserData('refid'); + } // END - if - // Free memory - SQL_FREERESULT($result); //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):userid={$userid},ref={$ref}
"); // When he has a referal... if (($ref > 0) && ($ref != $userid)) { // Move to next referal level and count his counter one up! //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):ref={$ref} - ADVANCE!
"); - $GLOBALS['cache_array']['ref_level'][$userid]++; updateReferalCounter($ref); - } elseif ((($ref == $userid) || ($ref == 0)) && (getExtensionVersion('cache') >= '0.1.2')) { + $GLOBALS['cache_array']['ref_level'][$userid]++; + updateReferalCounter($ref); + } elseif ((($ref == $userid) || ($ref == '0')) && (isExtensionInstalledAndNewer('cache', '0.1.2'))) { // Remove cache here //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):ref={$ref} - CACHE!
"); rebuildCacheFile('refsystem', 'refsystem'); @@ -1618,7 +1685,7 @@ function generateOptionList ($table, $id, $name, $default='', $special='', $wher // Activate exchange function FILTER_ACTIVATE_EXCHANGE () { // Is the extension 'user' there? - if ((!isExtensionActive('user')) || (getConfig('activate_xchange') == 0)) { + if ((!isExtensionActive('user')) || (getConfig('activate_xchange') == '0')) { // Silently abort here return false; } // END - if @@ -1646,7 +1713,7 @@ function FILTER_ACTIVATE_EXCHANGE () { // Deletes a user account with given reason function deleteUserAccount ($userid, $reason) { - $points = 0; + $points = '0'; $result = SQL_QUERY_ESC("SELECT (SUM(p.points) - d.used_points) AS points FROM @@ -1815,7 +1882,7 @@ function generateCategoryOptionsList ($mode) { array(bigintval($content['id'])), __FUNCTION__, __LINE__); // Start adding all - $userid_cnt = 0; + $userid_cnt = '0'; // @TODO Rewrite this to $content = SQL_FETCHARRAY() while (list($ucat) = SQL_FETCHROW($result_userids)) { $result_ver = SQL_QUERY_ESC("SELECT @@ -1874,7 +1941,7 @@ function addBonusMailToQueue ($subject, $text, $receiverList, $points, $seconds, $target = countSelection(explode(';', $receiverList)); // Receiver is zero? - if ($receiver == 0) { + if ($receiver == '0') { // Then auto-fix it $receiver = $target; } // END - if @@ -1935,7 +2002,7 @@ function generateReceiverList ($cat, $receiver, $mode = '') { $receiver = bigintval($receiver); // Is the receiver zero and mode set? - if (($receiver == 0) && (!empty($mode))) { + if (($receiver == '0') && (!empty($mode))) { // Auto-fix receiver maximum $receiver = getTotalReceivers($mode); } // END - if @@ -1987,13 +2054,13 @@ function generateReceiverList ($cat, $receiver, $mode = '') { } // Get timestamp for given stats type and data -function getTimestampFromUserStats ($type, $data, $userid = 0) { +function getTimestampFromUserStats ($type, $data, $userid = '0') { // Default timestamp is zero - $stamp = 0; + $stamp = '0'; // User id set? - if ((isUserIdSet()) && ($userid == 0)) { - $userid = getUserId(); + if ((isMemberIdSet()) && ($userid == '0')) { + $userid = getMemberId(); } // END - if // Is the extension installed and updated? @@ -2092,7 +2159,7 @@ ORDER BY ur.refid ASC", $row['unconfirmed'] = countSumTotalData($row['refid'], 'user_links', 'id', 'userid', true); // Init clickrate with zero - $row['clickrate'] = 0; + $row['clickrate'] = '0'; // Is at least one mail received? if ($row['emails_received'] > 0) { @@ -2152,11 +2219,23 @@ function reduceRecipientReceivedMails ($column, $id, $count) { } // Creates a new task -function createNewTask ($subject, $notes, $taskType, $userid = 0, $adminId = 0, $strip = true) { +function createNewTask ($subject, $notes, $taskType, $userid = '0', $adminId = '0', $strip = true) { // 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($adminId, $userid, $taskType, $subject, smartAddSlashes($notes)), __FUNCTION__, __LINE__, true, $strip); } +// Updates last module / online time +// @TODO Fix inconsistency between last_module and getWhat() +function updateLastActivity($userid) { + // Run the update query + SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `last_module`='%s', `last_online`=UNIX_TIMESTAMP(), `REMOTE_ADDR`='%s' WHERE `userid`=%s LIMIT 1", + array( + getWhat(), + detectRemoteAddr(), + bigintval($userid) + ), __FUNCTION__, __LINE__); +} + // [EOF] ?>