+// Determine which user hash no more points left
+function SURFBAR_DETERMINE_DEPLETED_USERIDS() {
+ // Init array
+ $UIDs = array();
+
+ // Do we have a current user id?
+ if (IS_MEMBER()) {
+ // Then add this as well
+ $UIDs[] = $GLOBALS['userid'];
+
+ // Get all userid except logged in one
+ $result = SQL_QUERY_ESC("SELECT userid FROM "._MYSQL_PREFIX."_surfbar_urls
+WHERE userid NOT IN (%s,0) AND status='CONFIRMED'
+GROUP BY userid
+ORDER BY userid ASC",
+ array($GLOBALS['userid']), __FILE__, __LINE__);
+ } else {
+ // Get all userid
+ $result = SQL_QUERY_ESC("SELECT userid FROM "._MYSQL_PREFIX."_surfbar_urls
+WHERE status='CONFIRMED'
+GROUP BY userid
+ORDER BY userid ASC", __FILE__, __LINE__);
+ }
+
+ // Load all 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_LOG(__FUNCTION__.":uid={$uid},points={$points}");
+
+ // Shall we add this to ignore?
+ if ($points <= 0) {
+ // Ignore this one!
+ //DEBUG_LOG(__FUNCTION__.":uid={$uid} has depleted points amount!");
+ $UIDs[] = $uid;
+ } // END - if
+ } // END - while
+
+ // Free result
+ SQL_FREERESULT($result);
+
+ // Debug message
+ //DEBUG_LOG(__FUNCTION__.":UIDs::count=".count($UIDs)." (with own userid=".$GLOBALS['userid'].")");
+
+ // Return result
+ return $UIDs;
+}
+// Determine how many users are Online in surfbar
+function SURFBAR_DETERMINE_TOTAL_ONLINE () {
+ global $_CONFIG;
+
+ // Count all users in surfbar modue and return the value
+ $result = SQL_QUERY_ESC("SELECT id
+FROM "._MYSQL_PREFIX."_surfbar_stats
+WHERE (UNIX_TIMESTAMP() - UNIX_TIMESTAMP(last_online)) <= %s
+GROUP BY userid",
+ array($_CONFIG['online_timeout']), __FILE__, __LINE__);
+
+ // Fetch count
+ $cnt = SQL_NUMROWS($result);
+
+ // Free result
+ SQL_FREERESULT($result);
+
+ // Return result
+ return $cnt;
+}
+// Determine waiting time for one URL
+function SURFBAR_DETERMINE_WAIT_TIME () {
+ global $_CONFIG;
+
+ // Init time
+ $time = 0;
+
+ // Which payment model do we have?
+ if ($_CONFIG['surfbar_pay_model'] == "STATIC") {
+ // Static model
+ $time = $_CONFIG['surfbar_static_time'];
+ } else {
+ // Dynamic
+ die("DYNAMIC payment model not yet finished!");
+ }
+
+ // Return value
+ return $time;
+}
+// Changes the status of an URL from given to other
+function SURFBAR_CHANGE_STATUS ($id, $prevStatus, $newStatus) {
+ // Get URL data for status comparison
+ $data = SURFBAR_GET_URL_DATA($id);
+
+ // Is the status like prevStatus is saying?
+ if ($data[$id]['status'] != $prevStatus) {
+ // No, then abort here
+ return false;
+ } // END - if
+
+ // Update the status now
+ SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_surfbar_urls SET status='%s' WHERE id=%s LIMIT 1",
+ array($newStatus, bigintval($id)), __FILE__, __LINE__);
+
+ // Was that fine?
+ if (SQL_AFFECTEDROWS() != 1) {
+ // No, something went wrong
+ return false;
+ } // END - if
+
+ // Prepare content for notification routines
+ $data[$id]['uid'] = $data[$id]['userid'];
+ $data[$id]['frametester'] = FRAMETESTER($data[$id]['url']);
+ $data[$id]['reward'] = TRANSLATE_COMMA($data[$id]['reward']);
+ $data[$id]['costs'] = TRANSLATE_COMMA($data[$id]['costs']);
+ $data[$id]['status'] = SURFBAR_TRANSLATE_STATUS($newStatus);
+ $data[$id]['registered'] = MAKE_DATETIME($data[$id]['registered'], "2");
+ $newStatus = strtolower($newStatus);
+
+ // Send admin notification
+ SURFBAR_NOTIFY_ADMIN("url_{$newStatus}", $data[$id]);
+
+ // Send user notification
+ SURFBAR_NOTIFY_USER("url_{$newStatus}", $data[$id]);
+
+ // All done!
+ return true;
+}
+// "Getter" for lock ids array
+function SURFBAR_GET_LOCK_IDS () {
+ // Prepare some arrays
+ $IDs = array();
+ $USE = array();
+ $ignored = array();
+
+ // Get all id from locks within the timestamp
+ $result = SQL_QUERY_ESC("SELECT id, url_id, UNIX_TIMESTAMP(last_surfed) AS last
+FROM
+ "._MYSQL_PREFIX."_surfbar_locks
+WHERE
+ userid=%s
+ORDER BY
+ id ASC", array($GLOBALS['userid']),
+ __FILE__, __LINE__);
+
+ // Load all entries
+ while (list($lid, $url, $last) = SQL_FETCHROW($result)) {
+ // Debug message
+ //DEBUG_LOG(__FUNCTION__.":next - lid={$lid},url={$url},rest=".(time() - $last)."/".SURFBAR_GET_DATA('surf_lock')."");
+
+ // Skip entries that are too old
+ if (($last > (time() - SURFBAR_GET_DATA('surf_lock'))) && (!in_array($url, $ignored))) {
+ // Debug message
+ //DEBUG_LOG(__FUNCTION__.":okay - lid={$lid},url={$url},last={$last}");
+
+ // Add only if missing or bigger
+ if ((!isset($IDs[$url])) || ($IDs[$url] > $last)) {
+ // Debug message
+ //DEBUG_LOG(__FUNCTION__.":ADD - lid={$lid},url={$url},last={$last}");
+
+ // Add this ID
+ $IDs[$url] = $last;
+ $USE[$url] = $lid;
+ } // END - if
+ } else {
+ // Debug message
+ //DEBUG_LOG(__FUNCTION__.":ignore - lid={$lid},url={$url},last={$last}");
+
+ // Ignore these old entries!
+ $ignored[] = $url;
+ unset($IDs[$url]);
+ unset($USE[$url]);
+ }
+ } // END - while
+
+ // Free result
+ SQL_FREERESULT($result);
+
+ // Return array
+ return $USE;
+}
+// "Getter" for maximum random number
+function SURFBAR_GET_MAX_RANDOM ($UIDs, $ADD) {
+ global $_CONFIG;
+ // Count max availabe entries
+ $result = SQL_QUERY("SELECT sbu.id AS cnt
+FROM "._MYSQL_PREFIX."_surfbar_urls AS sbu
+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 NOT IN (".implode(",", $UIDs).") AND sbu.status='CONFIRMED'".$ADD."
+GROUP BY sbu.id", __FILE__, __LINE__);
+
+ // Log last query
+ //DEBUG_LOG(__FUNCTION__.":lastQuery=".$_CONFIG['db_last_query']."|numRows=".SQL_NUMROWS($result)."|Affected=".SQL_AFFECTEDROWS()."");
+
+ // Fetch max rand
+ $maxRand = SQL_NUMROWS($result);
+
+ // Free result
+ SQL_FREERESULT($result);
+
+ // Return value
+ return $maxRand;
+}
+// Determine next id for surfbar or get data for given id, always call this before you call other