+ // Update the status now
+ // ---------- Comment out for debugging/developing member actions! ---------
+ //SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_surfbar_urls` SET `status`='%s' WHERE id=%s LIMIT 1",
+ // array($newStatus, bigintval($urlId)), __FUNCTION__, __LINE__);
+ // ---------- Comment out for debugging/developing member actions! ---------
+
+ // Was that fine?
+ // ---------- Comment out for debugging/developing member actions! ---------
+ //if (SQL_AFFECTEDROWS() != 1) {
+ // // No, something went wrong
+ // return false;
+ //} // END - if
+ // ---------- Comment out for debugging/developing member actions! ---------
+
+ // Prepare content for notification routines
+ $data[$urlId]['uid'] = $data[$urlId]['userid'];
+ $data[$urlId]['frametester'] = FRAMETESTER($data[$urlId]['url']);
+ $data[$urlId]['reward'] = TRANSLATE_COMMA(getConfig('surfbar_static_reward'));
+ $data[$urlId]['costs'] = TRANSLATE_COMMA(getConfig('surfbar_static_costs'));
+
+ // Do some dirty fixing here:
+ if (($data[$urlId]['status'] == "STOPPED") && ($newStatus == "pending")) {
+ // Fix for template change
+ $newStatus = "continued";
+ } // END - if
+
+ // Send admin notification
+ SURFBAR_NOTIFY_ADMIN("url_{$data[$urlId]['status']}_{$newStatus}", $data[$urlId]);
+
+ // Send user notification
+ SURFBAR_NOTIFY_USER("url_{$data[$urlId]['status']}_{$newStatus}", $data[$urlId]);
+
+ // All done!
+ return true;
+}
+// Calculate minimum value for dynamic payment model
+function SURFBAR_CALCULATE_DYNAMIC_MIN_VALUE () {
+ // Addon is zero by default
+ $addon = 0;
+
+ // Percentage part
+ $percent = abs(log(getConfig('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 () {
+ // Addon is zero by default
+ $addon = 0;
+
+ // Maximum value
+ $max = log(2);
+
+ // Percentage part
+ $percent = abs(log(getConfig('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 () {
+ // 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
+FROM
+ {!_MYSQL_PREFIX!}_surfbar_locks
+WHERE
+ userid=%s
+ORDER BY
+ id ASC", array(getUserId()),
+ __FUNCTION__, __LINE__);
+
+ // Load all entries
+ while ($content = SQL_FETCHARRAY($result)) {
+ // Debug message
+ //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "next - lid={$content['id']},url={$content['url_id']},rest=".(time() - $last)."/".SURFBAR_GET_SURF_LOCK()."", false);
+
+ // Skip entries that are too old
+ if (($last > (time() - SURFBAR_GET_SURF_LOCK())) && (!in_array($content['url_id'], $ignored))) {
+ // Debug message
+ //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "okay - lid={$content['id']},url={$content['url_id']},last={$last}", false);
+
+ // Add only if missing or bigger
+ if ((!isset($IDs[$content['url_id']])) || ($IDs[$content['url_id']] > $last)) {
+ // Debug message
+ //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "ADD - lid={$content['id']},url={$content['url_id']},last={$last}", false);
+
+ // Add this ID
+ $IDs[$content['url_id']] = $last;
+ $USE[$content['url_id']] = $content['id'];
+ } // END - if
+ } else {
+ // Debug message
+ //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "ignore - lid={$content['id']},url={$content['url_id']},last={$last}", false);
+
+ // Ignore these old entries!
+ $ignored[] = $content['url_id'];
+ unset($IDs[$content['url_id']]);
+ unset($USE[$content['url_id']]);
+ }
+ } // END - while
+
+ // Free result
+ SQL_FREERESULT($result);
+
+ // Return array
+ return $USE;
+}
+// "Getter" for maximum random number
+function SURFBAR_GET_MAX_RANDOM ($UIDs, $add) {
+ // 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.views_allowed=0 OR (sbu.views_allowed > 0 AND sbu.views_max > 0)) AND sbu.`status`='ACTIVE'".$add."
+GROUP BY sbu.id", __FUNCTION__, __LINE__);
+
+ // Log last query
+ //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "lastQuery=".getConfig('db_last_query')."|numRows=".SQL_NUMROWS($result)."|Affected=".SQL_AFFECTEDROWS()."", false);
+
+ // Fetch max rand
+ $maxRand = SQL_NUMROWS($result);
+
+ // Free result
+ SQL_FREERESULT($result);
+
+ // Return value
+ return $maxRand;
+}
+// Load all URLs of the current user and return it as an array
+function SURFBAR_GET_USER_URLS () {
+ // Init array
+ $URLs = array();
+
+ // Begin the query
+ $result = SQL_QUERY_ESC("SELECT u.id, u.userid, u.url, u.views_total, u.views_max, u.views_allowed, u.status, UNIX_TIMESTAMP(u.registered) AS registered, UNIX_TIMESTAMP(u.last_locked) AS last_locked, u.lock_reason AS lock_reason
+FROM `{!_MYSQL_PREFIX!}_surfbar_urls` AS u
+WHERE u.userid=%s AND u.status != 'DELETED'
+ORDER BY u.id ASC",
+ array(getUserId()), __FUNCTION__, __LINE__);
+
+ // Are there entries?
+ if (SQL_NUMROWS($result) > 0) {
+ // Load all rows
+ while ($row = SQL_FETCHARRAY($result)) {
+ // Add the row
+ $URLs[$row['id']] = $row;
+ } // END - while
+ } // END - if
+
+ // Free result
+ SQL_FREERESULT($result);
+
+ // Return the array
+ return $URLs;
+}
+// "Getter" for member action array for given status
+function SURFBAR_GET_ACTION_ARRAY ($status) {
+ // Init array
+ $returnArray = array();
+
+ // Get all assigned actions
+ $result = SQL_QUERY_ESC("SELECT action FROM `{!_MYSQL_PREFIX!}_surfbar_actions` WHERE `status`='%s' ORDER BY `id` ASC",
+ array($status), __FUNCTION__, __LINE__);
+
+ // Some entries there?
+ if (SQL_NUMROWS($result) > 0) {
+ // Load all actions
+ // @TODO This can be somehow rewritten
+ while ($content = SQL_FETCHARRAY($result)) {
+ $returnArray[] = $content['action'];
+ } // END - if
+ } // END - if
+
+ // Free result
+ SQL_FREERESULT($result);
+
+ // Return result
+ return $returnArray;
+}
+// Reload to configured stop page
+function SURFBAR_RELOAD_TO_STOP_PAGE($page="stop") {
+ // Internal or external?
+ if ((getConfig('surfbar_pause_mode') == "INTERNAL") || (getConfig('surfbar_pause_url') == "")) {
+ // Reload to internal page
+ LOAD_URL("surfbar.php?frame=".$page);
+ } else {
+ // Reload to external page
+ LOAD_CONFIGURED_URL('surfbar_pause_url');
+ }
+}
+
+// Determine next id for surfbar or get data for given id, always call this before you call other
+// getters below this function!!!
+function SURFBAR_DETERMINE_NEXT_ID ($urlId = 0) {
+ // Default is no id and no random number