]> git.mxchange.org Git - mailer.git/blobdiff - inc/mysql-manager.php
Fixes for last activity in mailid.php
[mailer.git] / inc / mysql-manager.php
index 1c9a5c64cfef11039c97297211784ee18d01b34d..c57e681367f8fcefab3a6556f2595f693df13b7c 100644 (file)
@@ -580,9 +580,12 @@ function isMember () {
        if (isset($GLOBALS['is_member'])) {
                // Then return it
                return $GLOBALS['is_member'];
-       } elseif (getUserId() == 0) {
+       } elseif (getMemberId() == 0) {
                // No member
                return false;
+       } else {
+               // Transfer userid=>current
+               setCurrentUserid(getMemberId());
        }
 
        // Init global user data array
@@ -592,9 +595,9 @@ function isMember () {
        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?
-               if (fetchUserData(getUserId()) === true) {
+               if (fetchUserData(getMemberId()) === true) {
                        // Validate password by created the difference of it and the secret key
                        $valPass = generatePassString(getUserData('password'));
 
@@ -609,17 +612,17 @@ function isMember () {
                        } else {
                                // Maybe got locked etc.
                                //* DEBUG: */ print(__LINE__."!!!<br />");
-                               destroyUserSession();
+                               destroyMemberSession();
                        }
                } else {
                        // Cookie data is invalid!
                        //* DEBUG: */ print(__LINE__."***<br />");
-                       destroyUserSession();
+                       destroyMemberSession();
                }
        } else {
                // Cookie data is invalid!
                //* DEBUG: */ print(__LINE__."///<br />");
-               destroyUserSession();
+               destroyMemberSession();
        }
 
        // Cache status
@@ -631,11 +634,14 @@ function isMember () {
 
 // Fetch user data for given user id
 function fetchUserData ($userid, $column='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 (isset($GLOBALS['user_data'][$userid])) {
+       } elseif (isUserDataValid()) {
                // Use cache, so it is fine
                return true;
        }
@@ -671,7 +677,7 @@ function fetchUserData ($userid, $column='userid') {
                        // 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']);
+                               $array = explode(' ', $GLOBALS['user_data'][getCurrentUserId()]['last_failure_raw']);
 
                                // Seperate data and time again
                                $array['date'] = explode('-', $array[0]);
@@ -869,6 +875,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);
@@ -891,7 +899,7 @@ function isMenuActionValid ($mode, $action, $what, $updateEntry=false) {
 // @TODO Lame description for this function
 function sendModeMails ($mod, $modes) {
        // Load hash
-       if (fetchUserData(getUserId())) {
+       if (fetchUserData(getMemberId())) {
                // Extract salt from cookie
                $salt = substr(getSession('u_hash'), 0, -40);
 
@@ -902,7 +910,7 @@ function sendModeMails ($mod, $modes) {
                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(), getUserData('password')), __FUNCTION__, __LINE__);
+                               array(getMemberId(), getUserData('password')), __FUNCTION__, __LINE__);
                        if (SQL_NUMROWS($result) == 1) {
                                // Load the data
                                $content = SQL_FETCHARRAY($result, 0, false);
@@ -945,7 +953,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
@@ -992,7 +1000,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');
@@ -1222,6 +1230,7 @@ function countSumTotalData ($search, $tableName, $lookFor = 'id', $whereStatemen
        }
 
        // Return value
+       //* DEBUG: */ print 'ret='.$ret.'<br />';
        return $ret;
 }
 // Getter fro ref level percents
@@ -1365,7 +1374,7 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify
                                // Load email template
                                $message = loadEmailTemplate('confirm-referal', $content, bigintval($userid));
 
-                               sendEmail(getUserData('email'), THANX_REFERRAL_ONE, $message);
+                               sendEmail(getUserData('email'), THANX_REFERAL_ONE, $message);
                        } elseif (($sendNotify) && (getUserData('refid') == 0) && ($locked === false) && ($add_mode == 'direct')) {
                                // Prepare content
                                $content = array(
@@ -1427,8 +1436,9 @@ function updateReferalCounter ($userid) {
        if (($ref > 0) && ($ref != $userid)) {
                // Move to next referal level and count his counter one up!
                //* DEBUG: */ print(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):ref={$ref} - ADVANCE!<br />");
-               $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__."(<font color=\"#0000aa\">".__LINE__."</font>):ref={$ref} - CACHE!<br />");
                rebuildCacheFile('refsystem', 'refsystem');
@@ -2047,8 +2057,8 @@ function getTimestampFromUserStats ($type, $data, $userid = 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?
@@ -2213,5 +2223,17 @@ function createNewTask ($subject, $notes, $taskType, $userid = 0, $adminId = 0,
                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]
 ?>