From 6b934c44f3293ec1425af4529b8eaf2f245a5a26 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 2 Dec 2008 23:36:49 +0000 Subject: [PATCH] Surfbar bookings extended with payment mode, unnessarry parameter removed --- inc/databases.php | 2 +- inc/libs/surfbar_functions.php | 41 +++++++++++++++++++++------------- surfbar.php | 2 +- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/inc/databases.php b/inc/databases.php index 5cf90b1b52..1e6813f4a9 100644 --- a/inc/databases.php +++ b/inc/databases.php @@ -114,7 +114,7 @@ define('USAGE_BASE', "usage"); define('SERVER_URL', "http://www.mxchange.org"); // Current SVN revision -define('CURR_SVN_REVISION', "586"); +define('CURR_SVN_REVISION', "587"); // Take a prime number which is long (if you know a longer one please try it out!) define('_PRIME', 591623); diff --git a/inc/libs/surfbar_functions.php b/inc/libs/surfbar_functions.php index 164813300e..6f96522d8d 100644 --- a/inc/libs/surfbar_functions.php +++ b/inc/libs/surfbar_functions.php @@ -821,8 +821,10 @@ function SURFBAR_CHECK_RELOAD_FULL() { } // END - if // Ask the database - $result = SQL_QUERY_ESC("SELECT COUNT(id) AS cnt FROM "._MYSQL_PREFIX."_surfbar_locks -WHERE userid=%s AND (UNIX_TIMESTAMP() - ".SURFBAR_GET_DATA('surf_lock').") < UNIX_TIMESTAMP(last_surfed) + $result = SQL_QUERY_ESC("SELECT COUNT(l.id) AS cnt FROM "._MYSQL_PREFIX."_surfbar_locks AS l +INNER JOIN "._MYSQL_PREFIX."_surfbar_urls AS u +ON u.id=l.url_id +WHERE l.userid=%s AND (UNIX_TIMESTAMP() - ".SURFBAR_GET_SURF_LOCK().") < UNIX_TIMESTAMP(l.last_surfed) AND (((UNIX_TIMESTAMP(l.last_surfed) - u.fixed_reload) < 0 AND u.fixed_reload > 0) OR u.fixed_reload = 0) LIMIT 1", array($GLOBALS['userid']), __FILE__, __LINE__ ); @@ -843,8 +845,8 @@ LIMIT 1", $total = SURFBAR_GET_TOTAL_URLS(); // Do we have some URLs in lock? Admins can always surf on own URLs! - //DEBUG_LOG(__FUNCTION__, __LINE__, "userLocks=".SURFBAR_GET_DATA('user_locks').",total={$total}", false); - $isFull = ((SURFBAR_GET_DATA('user_locks') == $total) && ($total > 0)); + //DEBUG_LOG(__FUNCTION__, __LINE__, "userLocks=".SURFBAR_GET_USER_LOCKS().",total={$total}", false); + $isFull = ((SURFBAR_GET_USER_LOCKS() == $total) && ($total > 0)); // Return result return $isFull; @@ -1000,17 +1002,19 @@ function SURFBAR_LOCKDOWN_ID ($urlId) { SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_surfbar_salts WHERE url_id=%s AND userid=%s LIMIT 1", array(bigintval($urlId), $GLOBALS['userid']), __FILE__, __LINE__); } -// Pay points to the user and remove it from the sender -function SURFBAR_PAY_POINTS ($urlId) { +// Pay points to the user and remove it from the sender if userid is given else it is a "sponsored surf" +function SURFBAR_PAY_POINTS () { + global $_CONFIG; + // Remove it from the URL owner //DEBUG_LOG(__FUNCTION__, __LINE__, "uid=".SURFBAR_GET_USERID().",costs=".SURFBAR_GET_COSTS()."", false); if (SURFBAR_GET_USERID() > 0) { - SUB_POINTS("surfbar", SURFBAR_GET_USERID(), SURFBAR_GET_COSTS()); + SUB_POINTS(sprintf("surfbar_%s", $_CONFIG['surfbar_pay_model']), SURFBAR_GET_USERID(), SURFBAR_GET_COSTS()); } // END - if // Book it to the user //DEBUG_LOG(__FUNCTION__, __LINE__, "uid=".$GLOBALS['userid'].",reward=".SURFBAR_GET_REWARD()."", false); - ADD_POINTS_REFSYSTEM("surfbar", $GLOBALS['userid'], SURFBAR_GET_DATA('reward')); + ADD_POINTS_REFSYSTEM(sprintf("surfbar_%s", $_CONFIG['surfbar_pay_model']), $GLOBALS['userid'], SURFBAR_GET_DATA('reward')); } // Updates the statistics of current URL/userid function SURFBAR_UPDATE_INSERT_STATS_RECORD () { @@ -1020,7 +1024,7 @@ function SURFBAR_UPDATE_INSERT_STATS_RECORD () { $ADD = ""; // Get allowed views - $allowed = SURFBAR_GET_ALLOWED_VIEWS(); + $allowed = SURFBAR_GET_VIEWS_ALLOWED(); // Do we have a limit? if ($allowed > 0) { @@ -1083,7 +1087,7 @@ function SURFBAR_CHECK_RELOAD_LOCK ($urlId) { // Ask the database $result = SQL_QUERY_ESC("SELECT COUNT(id) AS cnt FROM "._MYSQL_PREFIX."_surfbar_locks -WHERE userid=%s AND url_id=%s AND (UNIX_TIMESTAMP() - ".SURFBAR_GET_DATA('surf_lock').") < UNIX_TIMESTAMP(last_surfed) +WHERE userid=%s AND url_id=%s AND (UNIX_TIMESTAMP() - ".SURFBAR_GET_SURF_LOCK().") < UNIX_TIMESTAMP(last_surfed) ORDER BY last_surfed ASC LIMIT 1", array($GLOBALS['userid'], bigintval($urlId)), __FILE__, __LINE__ @@ -1096,7 +1100,7 @@ LIMIT 1", SQL_FREERESULT($result); // Return check - //DEBUG_LOG(__FUNCTION__, __LINE__, "cnt={$cnt},".SURFBAR_GET_DATA('surf_lock')."", false); + //DEBUG_LOG(__FUNCTION__, __LINE__, "cnt={$cnt},".SURFBAR_GET_SURF_LOCK()."", false); return ($cnt == 1); } // Determine which user hash no more points left @@ -1363,10 +1367,10 @@ ORDER BY // Load all entries while (list($lid, $url, $last) = SQL_FETCHROW($result)) { // Debug message - //DEBUG_LOG(__FUNCTION__, __LINE__, "next - lid={$lid},url={$url},rest=".(time() - $last)."/".SURFBAR_GET_DATA('surf_lock')."", false); + //DEBUG_LOG(__FUNCTION__, __LINE__, "next - lid={$lid},url={$url},rest=".(time() - $last)."/".SURFBAR_GET_SURF_LOCK()."", false); // Skip entries that are too old - if (($last > (time() - SURFBAR_GET_DATA('surf_lock'))) && (!in_array($url, $ignored))) { + if (($last > (time() - SURFBAR_GET_SURF_LOCK())) && (!in_array($url, $ignored))) { // Debug message //DEBUG_LOG(__FUNCTION__, __LINE__, "okay - lid={$lid},url={$url},last={$last}", false); @@ -1526,7 +1530,7 @@ function SURFBAR_DETERMINE_NEXT_ID ($urlId = 0) { } // END - if // And query the database - //DEBUG_LOG(__FUNCTION__, __LINE__, "randNum={$randNum},maxRand={$maxRand},surfLock=".SURFBAR_GET_DATA('surf_lock')."", false); + //DEBUG_LOG(__FUNCTION__, __LINE__, "randNum={$randNum},maxRand={$maxRand},surfLock=".SURFBAR_GET_SURF_LOCK()."", false); $result = SQL_QUERY_ESC("SELECT sbu.id, sbu.userid, sbu.url, sbs.last_salt, sbu.views_total, sbu.views_max, sbu.views_allowed, UNIX_TIMESTAMP(l.last_surfed) AS last_surfed, sbu.fixed_reload FROM "._MYSQL_PREFIX."_surfbar_urls AS sbu LEFT JOIN "._MYSQL_PREFIX."_surfbar_salts AS sbs @@ -1660,7 +1664,7 @@ function SURFBAR_GET_USERID () { return SURFBAR_GET_DATA('userid'); } // Getter for user reload locks -function SURFBAR_GET_USER_RELOAD_LOCK () { +function SURFBAR_GET_USER_LOCKS () { // Get data element and return its contents return SURFBAR_GET_DATA('user_locks'); } @@ -1670,7 +1674,7 @@ function SURFBAR_GET_RELOAD_TIME () { return SURFBAR_GET_DATA('time'); } // Getter for allowed views -function SURFBAR_GET_ALLOWED_VIEWS () { +function SURFBAR_GET_VIEWS_ALLOWED () { // Get data element and return its contents return SURFBAR_GET_DATA('views_allowed'); } @@ -1679,5 +1683,10 @@ function SURFBAR_GET_FIXED_RELOAD () { // Get data element and return its contents return SURFBAR_GET_DATA('fixed_reload'); } +// Getter for surf lock +function SURFBAR_GET_SURF_LOCK () { + // Get data element and return its contents + return SURFBAR_GET_DATA('surf_lock'); +} // ?> diff --git a/surfbar.php b/surfbar.php index cb78c0a8c4..9cc8187bb4 100644 --- a/surfbar.php +++ b/surfbar.php @@ -128,7 +128,7 @@ if (isBooleanConstantAndTrue('mxchange_installed')) { SURFBAR_LOCKDOWN_ID($_GET['id']); // Code is valid so pay points here - SURFBAR_PAY_POINTS($_GET['id']); + SURFBAR_PAY_POINTS(); // Check if reload is full if (SURFBAR_CHECK_RELOAD_FULL()) { -- 2.39.5