+ // 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;
+
+ // Static time is default
+ $time = $_CONFIG['surfbar_static_time'];
+
+ // Which payment model do we have?
+ if ($_CONFIG['surfbar_pay_model'] == "DYNAMIC") {
+ // "Calculate" dynamic time
+ $time += SURFBAR_CALCULATE_DYNAMIC_ADD();
+ } // END - if
+
+ // Return value
+ return $time;
+}
+// Changes the status of an URL from given to other
+function SURFBAR_CHANGE_STATUS ($urlId, $prevStatus, $newStatus, $data=array()) {
+ global $_CONFIG;
+
+ // Get URL data for status comparison if missing
+ if (count($data) == 0) {
+ $data = SURFBAR_GET_URL_DATA($urlId);
+ } // END - if
+
+ // Is the status like prevStatus is saying?
+ if ($data[$urlId]['status'] != $prevStatus) {
+ // No, then abort here
+ return false;
+ } // END - if
+
+
+ // Update the status now
+ // ---------------------- Commented out for debugging member actions! -----------------------
+ //SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_surfbar_urls SET status='%s' WHERE id=%s LIMIT 1",
+ // array($newStatus, bigintval($urlId)), __FILE__, __LINE__);
+ // ---------------------- Commented out for debugging member actions! -----------------------
+
+ // Was that fine?
+ if (SQL_AFFECTEDROWS() != 1) {
+ // No, something went wrong
+ return false;
+ } // END - if
+
+ // Prepare content for notification routines
+ $data[$urlId]['uid'] = $data[$urlId]['userid'];
+ $data[$urlId]['frametester'] = FRAMETESTER($data[$urlId]['url']);
+ $data[$urlId]['reward'] = TRANSLATE_COMMA($_CONFIG['surfbar_static_reward']);
+ $data[$urlId]['costs'] = TRANSLATE_COMMA($_CONFIG['surfbar_static_costs']);
+ $data[$urlId]['status'] = SURFBAR_TRANSLATE_STATUS($newStatus);
+ $data[$urlId]['registered'] = MAKE_DATETIME($data[$urlId]['registered'], "2");
+ $newStatus = strtolower($newStatus);
+
+ // Send admin notification
+ SURFBAR_NOTIFY_ADMIN("url_{$newStatus}", $data[$urlId]);
+
+ // Send user notification
+ SURFBAR_NOTIFY_USER("url_{$newStatus}", $data[$urlId]);
+
+ // All done!
+ return true;
+}
+// Calculate minimum value for dynamic payment model
+function SURFBAR_CALCULATE_DYNAMIC_MIN_VALUE () {
+ global $_CONFIG;
+
+ // Addon is zero by default
+ $addon = 0;
+
+ // Percentage part
+ $percent = abs(log($_CONFIG['surfbar_dynamic_percent'] / 100 + 1));
+
+ // Get total users
+ $totalUsers = GET_TOTAL_DATA("CONFIRMED", "user_data", "userid", "status", true);
+
+ // Get online users
+ $onlineUsers = SURFBAR_DETERMINE_TOTAL_ONLINE();
+
+ // Calculate addon
+ $addon += abs(log($onlineUsers / $totalUsers + 1) * $percent * $totalUsers);
+
+ // Get total URLs
+ $totalUrls = SURFBAR_GET_TOTAL_URLS("ACTIVE", "0");
+
+ // Get user's total URLs
+ $userUrls = SURFBAR_GET_TOTAL_USER_URLS(0, "ACTIVE");
+
+ // Calculate addon
+ if ($totalUrls > 0) {
+ $addon += abs(log($userUrls / $totalUrls + 1) * $percent * $totalUrls);
+ } else {
+ $addon += abs(log($userUrls / 1 + 1) * $percent * $totalUrls);
+ }
+
+ // Return addon
+ return $addon;
+}
+// Calculate maximum value for dynamic payment model
+function SURFBAR_CALCULATE_DYNAMIC_MAX_VALUE () {
+ global $_CONFIG;
+
+ // Addon is zero by default
+ $addon = 0;
+
+ // Maximum value
+ $max = log(2);
+
+ // Percentage part
+ $percent = abs(log($_CONFIG['surfbar_dynamic_percent'] / 100 + 1));
+
+ // Get total users
+ $totalUsers = GET_TOTAL_DATA("CONFIRMED", "user_data", "userid", "status", true);
+
+ // Calculate addon
+ $addon += abs($max * $percent * $totalUsers);
+
+ // Get total URLs
+ $totalUrls = SURFBAR_GET_TOTAL_URLS("ACTIVE", "0");
+
+ // Calculate addon
+ $addon += abs($max * $percent * $totalUrls);
+
+ // Return addon
+ return $addon;
+}
+// Calculate dynamic lock
+function SURFBAR_CALCULATE_DYNAMIC_LOCK () {
+ global $_CONFIG;
+
+ // Default lock is 30 seconds
+ $addon = 30;
+
+ // Get online users
+ $onlineUsers = SURFBAR_DETERMINE_TOTAL_ONLINE();
+
+ // Calculate lock
+ $addon = abs(log($onlineUsers / $addon + 1));
+
+ // Return value
+ return $addon;
+}
+// "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