]> git.mxchange.org Git - mailer.git/blobdiff - inc/libs/surfbar_functions.php
Validation of points amount added to surfbar
[mailer.git] / inc / libs / surfbar_functions.php
index 898b2a5d64e841e1b6bc906de4a7a2bb87f8682d..efb49a9a0a72fe2b8dd139d0fc863493b26ee396 100644 (file)
@@ -459,6 +459,30 @@ ORDER BY
                        $ADD = " AND l.id IN (".implode(",", $USE).")";
                } // END - if
 
+               // Get all userid
+               $result = SQL_QUERY_ESC("SELECT userid FROM "._MYSQL_PREFIX."_surfbar_urls
+WHERE userid != %s AND status='CONFIRMED'
+GROUP BY userid
+ORDER BY userid ASC",
+                       array($GLOBALS['userid']), __FILE__, __LINE__);
+
+               // Load all userid
+               $UIDs = array($GLOBALS['userid']);
+               while (list($uid) = SQL_FETCHROW($result)) {
+                       // Get total points
+                       $points = GET_TOTAL_DATA($uid, "user_points", "points") - GET_TOTAL_DATA($uid, "user_data", "used_points");
+                       //* DEBUG: */ echo __FUNCTION__.":uid={$uid},points={$points}<br />\n";
+
+                       // Shall we add this to ignore?
+                       if ($points <= 0) {
+                               // Ignore this one!
+                               $UIDs[] = $uid;
+                       } // END - if
+               } // END - while
+
+               // Free result
+               SQL_FREERESULT($result);
+
                // And query the database
                //* DEBUG: */ echo __FUNCTION__.":randNum={$randNum},maxRand={$maxRand},surfLock=".SURFBAR_GET_DATA('surf_lock')."<br />\n";
                $result = SQL_QUERY_ESC("SELECT sbu.id, sbu.userid, sbu.url, sbs.last_salt, sbu.reward, sbu.costs, sbu.views_total, p.time, UNIX_TIMESTAMP(l.last_surfed) AS last_surfed
@@ -469,11 +493,11 @@ LEFT JOIN "._MYSQL_PREFIX."_surfbar_salts AS sbs
 ON sbu.id=sbs.url_id
 LEFT JOIN "._MYSQL_PREFIX."_surfbar_locks AS l
 ON sbu.id=l.url_id
-WHERE sbu.userid != %s AND sbu.status='CONFIRMED'".$ADD."
+WHERE sbu.userid NOT IN (".implode(",", $UIDs).") AND sbu.status='CONFIRMED'".$ADD."
 GROUP BY sbu.id
 ORDER BY l.last_surfed ASC, sbu.id ASC
 LIMIT %s,1",
-                       array($GLOBALS['userid'], $randNum), __FILE__, __LINE__
+                       array($randNum), __FILE__, __LINE__
                );
                /*
                while($content = SQL_FETCHARRAY($result)) {