Reset rewritten, SQL fixed, zeros are now numeric
[mailer.git] / inc / mysql-manager.php
index 8ddbea29c9404486280f61d5c47c56b11b3f0e92..e1df712762f9ea86ceb7691c76a55959b953c2a1 100644 (file)
@@ -245,7 +245,7 @@ function ADD_DESCR($ACC_LVL, $file, $return = false, $output = true) {
                $AND = "";
        }
        if ((!isset($DEPTH)) && (!$return)) {
-               $DEPTH = "0";
+               $DEPTH = 0;
                $prefix = "<DIV class=\"you_are_here\">".YOU_ARE_HERE."&nbsp;<STRONG><A class=\"you_are_here\" href=\"".URL."/modules.php?module=".$GLOBALS['module'].$LINK_ADD."\">Home</A></STRONG>";
        } else {
                if (!$return) $DEPTH++;
@@ -1004,7 +1004,7 @@ function REMOVE_RECEIVER(&$ARRAY, $key, $uid, $pool_id, $stats_id="", $bonus=fal
 //
 function GET_TOTAL_DATA($search, $tableName, $lookFor, $whereStatement="userid", $onlyRows=false)
 {
-       $ret = "0";
+       $ret = 0;
        if ($onlyRows) {
                // Count rows
                $result = SQL_QUERY_ESC("SELECT COUNT(%s) FROM "._MYSQL_PREFIX."_%s WHERE %s='%s'",
@@ -1021,7 +1021,7 @@ function GET_TOTAL_DATA($search, $tableName, $lookFor, $whereStatement="userid",
        SQL_FREERESULT($result);
        if (empty($ret)) {
                if (($lookFor == "counter") || ($lookFor == "id")) {
-                       $ret = "0";
+                       $ret = 0;
                } else {
                        $ret = "0.00000";
                }
@@ -1057,7 +1057,7 @@ function ADD_POINTS_REFSYSTEM($uid, $points, $send_notify=false, $rid="0", $lock
        // Count up referral depth
        if (empty($DEPTH)) {
                // Initialialize referral system
-               $DEPTH = "0";
+               $DEPTH = 0;
        } else {
                // Increase referral level
                $DEPTH++;
@@ -1156,8 +1156,9 @@ function ADD_POINTS_REFSYSTEM($uid, $points, $send_notify=false, $rid="0", $lock
 function UPDATE_REF_COUNTER($uid)
 {
        global $REF_LVL, $cacheInstance;
+
        // Make it sure referral level zero (member him-/herself) is at least selected
-       if (empty($REF_LVL)) $REF_LVL = "0";
+       if (empty($REF_LVL)) $REF_LVL = 0;
 
        // Update counter
        $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_refsystem SET counter=counter+1 WHERE userid=%s AND level='%s' LIMIT 1",
@@ -1191,45 +1192,50 @@ function UPDATE_REF_COUNTER($uid)
                if ($cacheInstance->cache_file("refsystem", true)) $cacheInstance->cache_destroy();
        }
 }
-//
-function UPDATE_ONLINE_LIST($SID, $mod, $act, $wht)
-{
+// Updates/extends the online list
+function UPDATE_ONLINE_LIST($SID, $mod, $act, $wht) {
        global $_CONFIG;
 
        // Do not update online list when extension is deactivated
        if (!EXT_IS_ACTIVE("online", true)) return;
 
+       // Empty session?
+       if (empty($SID)) {
+               // This is invalid here!
+               print "Invalid session. Backtrace:<pre>";
+               debug_print_backtrace();
+               die("</pre>");
+       } // END - if
+
        // Initialize variables
-       $uid = "0"; $rid = "0"; $MEM = "N"; $ADMIN = "N";
-       if (!empty($GLOBALS['userid']))
-       {
-               // Update member status only when userid is valid
-               if (($GLOBALS['userid'] > 0) && (IS_MEMBER()))
-               {
-                       // Is valid user
-                       $uid = $GLOBALS['userid'];
-                       $MEM = "Y";
-               }
-       }
-       if (IS_ADMIN())
-       {
+       $uid = 0; $rid = 0; $MEM = "N"; $ADMIN = "N";
+
+       // Valid userid?
+       if ((!empty($GLOBALS['userid'])) && ($GLOBALS['userid'] > 0) && (IS_MEMBER())) {
+               // Is valid user
+               $uid = bigintval($GLOBALS['userid']);
+               $MEM = "Y";
+       } // END - if
+
+       if (IS_ADMIN()) {
                // Is administrator
                $ADMIN = "Y";
-       }
+       } // END - if
+
        if (isSessionVariableSet('refid')) {
                // Check cookie
-               if (get_session('refid') > 0) $rid = $GLOBALS['refid'];
-       }
+               if (get_session('refid') > 0) $rid = bigintval($GLOBALS['refid']);
+       } // END - if
 
-       // Now Read data
+       // Now search for the user
        $result = SQL_QUERY_ESC("SELECT timestamp FROM "._MYSQL_PREFIX."_online
 WHERE sid='%s' LIMIT 1",
  array($SID), __FILE__, __LINE__);
 
-       if (SQL_NUMROWS($result) == 1)
-       {
-               SQL_FREERESULT($result);
-               $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_online SET
+       // Entry found?
+       if (SQL_NUMROWS($result) == 1) {
+               // Then update it
+               SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_online SET
 module='%s',
 action='%s',
 what='%s',
@@ -1239,24 +1245,18 @@ is_member='%s',
 is_admin='%s',
 timestamp=UNIX_TIMESTAMP()
 WHERE sid='%s' LIMIT 1",
- array(
-       $mod,
-       $act,
-       $wht,
-       bigintval($uid),
-       bigintval($rid),
-       $MEM,
-       $ADMIN,
-       $SID
-), __FILE__, __LINE__);
-       }
-        else
-       {
+                       array($mod, $act, $wht, $uid, $rid, $MEM, $ADMIN, $SID), __FILE__, __LINE__
+               );
+       } else {
                // No entry does exists so we simply add it!
-               $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_online (module, action, what, userid, refid, is_member, is_admin, timestamp, sid, ip) VALUES ('%s', '%s', '%s', %s, %s, '%s', '%s', UNIX_TIMESTAMP(), '%s', '%s')",
-                array($mod, $act, $wht, bigintval($uid), bigintval($rid), $MEM, $ADMIN, $SID, getenv('REMOTE_ADDR')), __FILE__, __LINE__);
+               SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_online (module, action, what, userid, refid, is_member, is_admin, timestamp, sid, ip) VALUES ('%s', '%s', '%s', %s, %s, '%s', '%s', UNIX_TIMESTAMP(), '%s', '%s')",
+                       array($mod, $act, $wht, $uid, $rid, $MEM, $ADMIN, $SID, getenv('REMOTE_ADDR')), __FILE__, __LINE__
+               );
        }
 
+       // Free result
+       SQL_FREERESULT($result);
+
        // Purge old entries
        $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_online WHERE timestamp <= (UNIX_TIMESTAMP() - %s)",
         array($_CONFIG['online_timeout']), __FILE__, __LINE__);