More queries now depends on UNIX_TIMESTAMP() not on time(), more fixes for not instal...
authorRoland Häder <roland@mxchange.org>
Tue, 16 Sep 2008 20:48:29 +0000 (20:48 +0000)
committerRoland Häder <roland@mxchange.org>
Tue, 16 Sep 2008 20:48:29 +0000 (20:48 +0000)
inc/libs/rallye_functions.php
inc/libs/task_functions.php
inc/modules/admin/what-list_autopurge.php
inc/modules/admin/what-list_beg.php
inc/modules/admin/what-list_bonus.php
inc/modules/guest/what-register.php
inc/modules/member/what-beg2.php
inc/modules/member/what-bonus.php
inc/modules/member/what-order.php
inc/monthly/monthly_bonus.php
inc/profile-updte.php

index 58dac3bafb560cbac89d632d87c0e7971d7dc132..f6e65e5b1aee83baff18ddbe9de4492dc025cb4e 100644 (file)
@@ -194,7 +194,11 @@ function RALLYE_ADD_PRICES($rallye,$mode="email")
 function RALLYE_ADD_TOPUSERS($rallye,$default=0)
 {
        global $_CONFIG;
-       $since = (time() - $_CONFIG['ap_inactive_since']);
+       // Init variable
+       $since = 0;
+       if (EXT_IS_ACTIVE("autopurge")) {
+               $since = $_CONFIG['ap_inactive_since'];
+       } // END - if
 
        // First check how many prices are set
        $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_rallye_prices WHERE rallye_id=%s ORDER BY price_level",
@@ -225,7 +229,7 @@ WHERE u.rallye_id=%s AND r.counter > 0 ORDER BY u.refs DESC",
                $result_ref = SQL_QUERY_ESC("SELECT DISTINCT p.points FROM "._MYSQL_PREFIX."_user_points AS p
 LEFT JOIN "._MYSQL_PREFIX."_user_data AS d
 ON p.userid=d.userid
-WHERE d.userid=%s AND d.status='CONFIRMED' AND p.ref_depth=1 AND d.max_mails > 0 AND d.mails_confirmed >= %s AND d.last_online >= %s
+WHERE d.userid=%s AND d.status='CONFIRMED' AND p.ref_depth=1 AND d.max_mails > 0 AND d.mails_confirmed >= %s AND d.last_online >= (UNIX_TIMESTAMP() - %s)
 LIMIT 1", array(bigintval($uid), $_CONFIG['ref_payout'], $since), __FILE__, __LINE__);
                list($refpoints) = SQL_FETCHROW($result_ref);
                SQL_FREERESULT($result_ref);
@@ -333,7 +337,10 @@ function RALLYE_EXPIRE_RALLYES($result)
        global $DATA, $_CONFIG;
 
        // Latest online time
-       $since = (time() - $_CONFIG['ap_inactive_since']);
+       $since = 0;
+       if (EXT_IS_ACTIVE("autopurge")) {
+               $since = $_CONFIG['ap_inactive_since'];
+       } // END - if
 
        // Load rallye data
        list($id, $title, $start, $end, $notify, $min_users, $min_prices) = SQL_FETCHROW($result);
@@ -359,7 +366,7 @@ function RALLYE_EXPIRE_RALLYES($result)
                //   active = 0: account is deleted or locked
                $result = SQL_QUERY_ESC("SELECT COUNT(userid) AS active
 FROM "._MYSQL_PREFIX."_user_data
-WHERE userid=%s AND status='CONFIRMED' AND last_online >= %s
+WHERE userid=%s AND status='CONFIRMED' AND last_online >= (UNIX_TIMESTAMP() - %s)
 LIMIT 1", array(bigintval($uid), $since), __FILE__, __LINE__);
                list($active) = SQL_FETCHROW($result);
                SQL_FREERESULT($result);
@@ -657,9 +664,11 @@ function RALLYE_DELETE_EXPIRED_RALLYES()
 {
        global $DATA, $_CONFIG;
        // Check for expired rallyes
-       $EXPIRE = time() - ONE_DAY * 3; // The hard-coded value...
-       $result_rallye = SQL_QUERY_ESC("SELECT id, title, start_time, end_time FROM "._MYSQL_PREFIX."_rallye_data WHERE end_time <= %s AND expired='Y'",
-        array($EXPIRE), __FILE__, __LINE__);
+       $EXPIRE = ONE_DAY * 3; // @TODO The hard-coded value...
+       $result_rallye = SQL_QUERY_ESC("SELECT id, title, start_time, end_time
+FROM "._MYSQL_PREFIX."_rallye_data
+WHERE end_time <= (UNIX_TIMESTAMP() - %s) AND expired='Y'",
+               array($EXPIRE), __FILE__, __LINE__);
 
        if (SQL_NUMROWS($result_rallye) > 0)
        {
index 1aced16f60ee5ed4cb060d3ad899bdd6d5992617..20e653b4bd823b4d8d3907b80ce783afdeed0433 100644 (file)
@@ -272,7 +272,7 @@ function OUTPUT_ADVANCED_OVERVIEW (&$result_main)
 
        if (EXT_IS_ACTIVE("autopurge")) {
                // Start finding them...
-               $since = (time() - $_CONFIG['ap_inactive_since']);
+               $since = $_CONFIG['ap_inactive_since'];
                $EXCLUDE_LIST = " AND d.userid != ".$_CONFIG['def_refid']."";
 
                // Check for more extensions
@@ -284,7 +284,7 @@ function OUTPUT_ADVANCED_OVERVIEW (&$result_main)
                // Check for all accounts
                $SQLs[] = "SELECT DISTINCT d.userid, d.email, d.last_online
 FROM "._MYSQL_PREFIX."_user_data AS d
-WHERE d.status='CONFIRMED' AND d.joined < ".$since." AND d.last_online < ".$since." AND d.ap_notified < ".$since."
+WHERE d.status='CONFIRMED' AND d.joined < (UNIX_TIMESTAMP() - ".$since.") AND d.last_online < ".$since." AND d.ap_notified < ".$since."
 ".$EXCLUDE_LIST."
 ORDER BY d.userid";
                $WHATs[]  = "list_autopurge";
@@ -353,15 +353,14 @@ ORDER BY d.userid";
                }
 
                // Autopurge installed?
-               $LAST = ""; $ONLINE = "";
+               $LAST = "";
                if ((EXT_IS_ACTIVE("autopurge")) && ($_CONFIG['ap_inactive'] == "Y") && ($_CONFIG['ap_inactive_since'] > 0)) {
                        // Use last online timestamp to keep inactive members away from here
-                       $LAST   = " AND last_online >= ";
-                       $ONLINE = bigintval(time() - $_CONFIG['ap_inactive_since']);
+                       $LAST   = sprintf(" AND last_online >= (UNIX_TIMESTAMP() - %s)", $_CONFIG['ap_inactive_since']);
                }
 
                $SQLs[]   = "SELECT ".$USE." AS active_bonus FROM "._MYSQL_PREFIX."_user_data
-WHERE status='CONFIRMED' AND ".$USE.">0".$LAST."".$ONLINE."
+WHERE status='CONFIRMED' AND ".$USE.">0".$LAST."
 ORDER BY active_bonus DESC, userid";
                $WHATs[]  = "list_bonus";
                $DESCRs[] = TASK_ADMIN_LIST_BONUS;
@@ -372,15 +371,14 @@ ORDER BY active_bonus DESC, userid";
                // Begging rallye
 
                // Autopurge installed?
-               $LAST = ""; $ONLINE = "";
+               $LAST = "";
                if ((EXT_IS_ACTIVE("autopurge")) && ($_CONFIG['ap_inactive'] == "Y") && ($_CONFIG['ap_inactive_since'] > 0)) {
                        // Use last online timestamp to keep inactive members away from here
-                       $LAST   = " AND last_online >= ";
-                       $ONLINE = bigintval(time() - $_CONFIG['ap_inactive_since']);
+                       $LAST   = sprintf(" AND last_online >= (UNIX_TIMESTAMP() - %s)", $_CONFIG['ap_inactive_since']);
                }
 
                $SQLs[]   = "SELECT userid FROM "._MYSQL_PREFIX."_user_data
-WHERE status='CONFIRMED' AND beg_points>0".$LAST."".$ONLINE."
+WHERE status='CONFIRMED' AND beg_points>0".$LAST."
 ORDER BY beg_points DESC, userid";
                $WHATs[]  = "list_beg";
                $DESCRs[] = TASK_ADMIN_LIST_BEG;
index 8a5cf455833369a05d7c82198f4b56c74fa8dbc0..70ccbd5f826bdbef3189d91645e43d8dd6940daf 100644 (file)
@@ -40,9 +40,11 @@ if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
 // Add description as navigation point
 ADD_DESCR("admin", basename(__FILE__));
 
-// Ok, let's have a look...
-$since = bigintval(time() - $_CONFIG['ap_inactive_since']);
-$EXCLUDE_LIST = " AND d.userid != ".$_CONFIG['def_refid']."";
+// Exclude default referal id if set
+$EXCLUDE_LIST = "";
+if ($_CONFIG['def_refid'] > 0) {
+       $EXCLUDE_LIST = " AND d.userid != ".$_CONFIG['def_refid']."";
+} // END - if
 
 // Check for more extensions
 if (EXT_IS_ACTIVE("beg"))     $EXCLUDE_LIST .= " AND d.userid != c.beg_uid";
@@ -52,9 +54,9 @@ if (EXT_IS_ACTIVE("doubler")) $EXCLUDE_LIST .= " AND d.userid != c.doubler_uid";
 // Check for all accounts
 $result = SQL_QUERY_ESC("SELECT DISTINCT d.userid, d.gender, d.surname, d.family, d.email, d.joined, d.last_online, d.ap_notified
 FROM "._MYSQL_PREFIX."_user_data AS d
-WHERE d.status='CONFIRMED' AND d.joined < %s AND d.last_online < %s AND d.ap_notified < %s
+WHERE d.status='CONFIRMED' AND d.joined < (UNIX_TIMESTAMP() - %s) AND d.last_online < (UNIX_TIMESTAMP() - %s) AND d.ap_notified < (UNIX_TIMESTAMP() - %s)
 ".$EXCLUDE_LIST."
-ORDER BY d.userid", array($since, $since, $since), __FILE__, __LINE__);
+ORDER BY d.userid", array($_CONFIG['ap_inactive_since'], $_CONFIG['ap_inactive_since'], $_CONFIG['ap_inactive_since']), __FILE__, __LINE__);
 
 if (SQL_NUMROWS($result) > 0)
 {
index fa3115f182da4cfb1451c42af32baf1e1a0a78a0..cc3eba1700290d80e7f6a5bac12a76faf0f20309 100644 (file)
@@ -57,8 +57,8 @@ if ($_CONFIG['beg_rallye'] == "Y")
        if (EXT_IS_ACTIVE("autopurge"))
        {
                // Use last online timestamp to keep inactive members away from here
-               $LAST   = " AND last_online >= %s";
-               $ONLINE = bigintval(time() - $_CONFIG['ap_inactive_since']);
+               $LAST   = " AND last_online >= (UNIX_TIMESTAMP() - %s)";
+               $ONLINE = $_CONFIG['ap_inactive_since'];
        }
 
        // Check if at least one is in the active rallye
@@ -116,7 +116,11 @@ ORDER BY beg_points DESC, last_online DESC, userid",
                }
 
                // Prepare constant for timemark
-               define('__AUTOPURGE_TIMEOUT', MAKE_DATETIME(time() - $_CONFIG['ap_inactive_since'], "2"));
+               if (EXT_IS_ACTIVE("autopurge")) {
+                       define('__AUTOPURGE_TIMEOUT', MAKE_DATETIME(time() - $_CONFIG['ap_inactive_since'], "2"));
+               } else {
+                       define('__AUTOPURGE_TIMEOUT', sprintf(EXTENSION_PROBLEM_NOT_INSTALLED, "autopurge"));
+               }
 
                // Load final template
                LOAD_TEMPLATE("admin_list_beg");
index 7b02b64a92348de6184214e81487d95ff74ce458..6cd69df1a27e5c0a5d6ab2c1c3fb78a6b14c4dfb 100644 (file)
@@ -69,8 +69,8 @@ if ($_CONFIG['bonus_active'] == "Y") {
        $LAST = "%s"; $ONLINE = "";
        if (EXT_IS_ACTIVE("autopurge")) {
                // Use last online timestamp to keep inactive members away from here
-               $LAST   = " AND last_online >= %s";
-               $ONLINE = bigintval(time() - $_CONFIG['ap_inactive_since']);
+               $LAST   = " AND last_online >= (UNIX_TIMESTAMP() - %s)";
+               $ONLINE = $_CONFIG['ap_inactive_since'];
        }
 
        // Check if at least one is in the active rallye
@@ -127,7 +127,11 @@ ORDER BY active_bonus DESC, last_online DESC, userid",
                }
 
                // Prepare constant for timemark
-               define('__AUTOPURGE_TIMEOUT', MAKE_DATETIME(time() - $_CONFIG['ap_inactive_since'], "2"));
+               if (EXT_IS_ACTIVE("autopurge")) {
+                       define('__AUTOPURGE_TIMEOUT', MAKE_DATETIME(time() - $_CONFIG['ap_inactive_since'], "2"));
+               } else {
+                       define('__AUTOPURGE_TIMEOUT', sprintf(EXTENSION_PROBLEM_NOT_INSTALLED, "autopurge"));
+               }
 
                // Load final template
                LOAD_TEMPLATE("admin_list_bonus");
index f06e9ee66f391b88623d09c432b36ba1501b20c7..ac63b929b2d49c5435e4e524829d1c94107b4bdd 100644 (file)
@@ -145,9 +145,8 @@ if (isset($_POST['ok']))
        }
 
        // Check his IP number
-       $to = bigintval(time() - $_CONFIG['ip_timeout']);
-       $result = SQL_QUERY_ESC("SELECT joined, last_update FROM "._MYSQL_PREFIX."_user_data WHERE REMOTE_ADDR='%s' AND (joined > %s OR last_update > %s) LIMIT 1",
-        array(getenv('REMOTE_ADDR'), $to, $to), __FILE__, __LINE__);
+       $result = SQL_QUERY_ESC("SELECT joined, last_update FROM "._MYSQL_PREFIX."_user_data WHERE REMOTE_ADDR='%s' AND (joined > (UNIX_TIMESTAMP() - %s) OR last_update > (UNIX_TIMESTAMP() - %s)) LIMIT 1",
+        array(getenv('REMOTE_ADDR'), $_CONFIG['ip_timeout'], $_CONFIG['ip_timeout']), __FILE__, __LINE__);
        if ((SQL_NUMROWS($result) == 1) && (!IS_ADMIN()))
        {
                // Same IP in timeout range and different email address entered... Eat this, faker! ;-)
@@ -159,8 +158,7 @@ if (isset($_POST['ok']))
        // Test the refid (because some strange hackers... :-P)
        $result = SQL_QUERY_ESC("SELECT userid FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
         array(bigintval($GLOBALS['refid'])), __FILE__, __LINE__);
-       if (SQL_NUMROWS($result) == 0)
-       {
+       if (SQL_NUMROWS($result) == 0) {
                // Not found so we set your refid!
                $_POST['refid'] = $_CONFIG['def_refid'];
                set_session("refid", $_CONFIG['def_refid']);
index 6a250924d50386cbb8a8d4e38a79788f1d943eb9..a7e131b107f495377f2163cdf76fdbd08e6e4e0e 100644 (file)
@@ -47,11 +47,10 @@ ADD_DESCR("member", basename(__FILE__));
 
 // Autopurge installed?
 $LAST = "%s"; $ONLINE = "";
-if (EXT_IS_ACTIVE("autopurge"))
-{
+if (EXT_IS_ACTIVE("autopurge")) {
        // Use last online timestamp to keep inactive members away from here
-       $LAST   = " AND last_online >= %s";
-       $ONLINE = bigintval(time() - $_CONFIG['ap_inactive_since']);
+       $LAST   = " AND last_online >= (UNIX_TIMESTAMP() - %s)";
+       $ONLINE = $_CONFIG['ap_inactive_since'];
 }
 
 // Let's check if there are some points left we can "pay"...
index 66ae60cb37ccf939fee6f73912e285e226bf802c..ddd819bbaec902cb13ef4cb003dbf0d8572664fd 100644 (file)
@@ -64,11 +64,10 @@ if (GET_EXT_VERSION("bonus") >= "0.6.9")
 
 // Autopurge installed?
 $LAST = "%s"; $ONLINE = "";
-if (EXT_IS_ACTIVE("autopurge"))
-{
+if (EXT_IS_ACTIVE("autopurge")) {
        // Use last online timestamp to keep inactive members away from here
-       $LAST   = " AND last_online >= %s";
-       $ONLINE = bigintval(time() - $_CONFIG['ap_inactive_since']);
+       $LAST   = " AND last_online >= (UNIX_TIMESTAMP() - %s)";
+       $ONLINE = $_CONFIG['ap_inactive_since'];
 }
 
 // Let's check if there are some points left we can "pay"...
index 0577688f285f31497906f59009f8ad233552a853..1053b26427d0fefd4842e8a0547028097e6e7d84 100644 (file)
@@ -124,8 +124,10 @@ if (($HOLIDAY == "Y") && (GET_EXT_VERSION("holiday") >= "0.1.3"))
        // Continue with the frametester, we first need to store the data temporary in the pool
        //
        // First we would like to store the data and get it's pool position back...
-       $result = SQL_QUERY_ESC("SELECT id, data_type FROM "._MYSQL_PREFIX."_pool WHERE sender=%s AND url='%s' AND timestamp > %s LIMIT 1",
-        array($GLOBALS['userid'], $_POST['url'], bigintval(time() - $_CONFIG['url_tlock'])), __FILE__, __LINE__);
+       $result = SQL_QUERY_ESC("SELECT id, data_type
+FROM "._MYSQL_PREFIX."_pool
+WHERE sender=%s AND url='%s' AND timestamp > (UNIX_TIMESTAMP() - %s) LIMIT 1",
+        array($GLOBALS['userid'], $_POST['url'], $_CONFIG['url_tlock']), __FILE__, __LINE__);
 
        $type = "TEMP"; $id = 0;
        if (SQL_NUMROWS($result) == 1)
index c00a486e606ad53b5e7c1ca22f3d4d5de110a25d..0c5f9dd64ac25371b25515b00461b1bcb3baec8c 100644 (file)
@@ -50,8 +50,7 @@ if (($curr != $_CONFIG['last_month']) && ($_CONFIG['bonus_ranks'] > 0) && ($CSS
 {
        // Extension "autopurge" is inactive or purging of inactive accounts is deactivated
        $whereStatement1 = "WHERE status='CONFIRMED'";
-       $whereStatement2 = 0;
-       $whereStatement3 = bigintval($_CONFIG['bonus_ranks']);
+       $whereStatement2 = bigintval($_CONFIG['bonus_ranks']);
 
        // Shall I keep inactive members away from here? (mostly wanted in an "active-rallye" ...)
        if (EXT_IS_ACTIVE("autopurge"))
@@ -60,27 +59,29 @@ if (($curr != $_CONFIG['last_month']) && ($_CONFIG['bonus_ranks'] > 0) && ($CSS
                if ($_CONFIG['ap_inactive_since'] > 0)
                {
                        // Okay, include last online timestamp
-                       $whereStatement1 = "WHERE status='CONFIRMED' AND last_online >=";
-                       $whereStatement2 = bigintval(time() - $_CONFIG['ap_inactive_since']);
-                       $whereStatement3 = bigintval($_CONFIG['bonus_ranks']);
+                       $whereStatement1 = sprintf("WHERE status='CONFIRMED' AND last_online >= (UNIX_TIMESTAMP() - %s)", $_CONFIG['ap_inactive_since']);
+                       $whereStatement2 = bigintval($_CONFIG['bonus_ranks']);
                }
        }
 
        // Add more bonus points here
-       $ADD = " AND (0";
+       $ADD = "";
        if ($_CONFIG['bonus_click_yn'] == "Y") $ADD .= " + turbo_bonus";
        if ($_CONFIG['bonus_login_yn'] == "Y") $ADD .= " + login_bonus";
        if ($_CONFIG['bonus_order_yn'] == "Y") $ADD .= " + bonus_order";
        if ($_CONFIG['bonus_stats_yn'] == "Y") $ADD .= " + bonus_stats";
        if ($_CONFIG['bonus_ref_yn']   == "Y") $ADD .= " + bonus_ref";
-       $ADD .= ") > 0";
+
+       if (!empty($ADD)) {
+               $ADD .= "AND (0".$ADD.") > 0";
+       } // END - if
 
        // SQL string to check for accounts
        $result_main = SQL_QUERY_ESC("SELECT userid, email, (turbo_bonus + login_bonus + bonus_order + bonus_stats + bonus_ref) AS active_bonus
 FROM "._MYSQL_PREFIX."_user_data
 ".$whereStatement1." %s".$ADD."
 ORDER BY active_bonus DESC, userid LIMIT %s",
- array($whereStatement2, $whereStatement3), __FILE__, __LINE__);
+ array($whereStatement2), __FILE__, __LINE__);
 
        if (SQL_NUMROWS($result_main) > 0)
        {
index fb40eb9efaae394d0e80babaf1fb87d6c9f3fc94..1e29d2eb7db30175cc85f1354b6df575a52f4747 100644 (file)
@@ -38,17 +38,16 @@ if (!defined('__SECURITY')) {
        require($INC);
 }
 
-if (($_CONFIG['send_prof_update'] == "Y") && ($_CONFIG['profile_update'] > 0) && ($_CONFIG['resend_profile_update']))
-{
-       // Ok, we shall send update notifications...
-       $TIMEOUT  = bigintval(time() - $_CONFIG['profile_update']);
-       $TIMEOUT2 = bigintval(time() - $_CONFIG['resend_profile_update']);
-
+if (($_CONFIG['send_prof_update'] == "Y") && ($_CONFIG['profile_update'] > 0) && ($_CONFIG['resend_profile_update'])) {
        // Load personal data              0      1     2      3        4          5         6
        $result = SQL_QUERY_ESC("SELECT userid, email, gender, surname, family, last_update, joined
- FROM "._MYSQL_PREFIX."_user_data
- WHERE (last_update < %s AND last_update != '0' AND last_profile_sent < %s) OR (last_update='0' AND last_profile_sent='0' AND joined < %s)
- ORDER BY userid", array($TIMEOUT, $TIMEOUT2, $TIMEOUT), __FILE__, __LINE__);
+FROM
+       "._MYSQL_PREFIX."_user_data
+WHERE
+       (last_update < (UNIX_TIMESTAMP() - %s) AND last_update != 0 AND last_profile_sent < (UNIX_TIMESTAMP() - %s))
+OR
+       (last_update=0 AND last_profile_sent=0 AND joined < (UNIX_TIMESTAMP() - %s))
+ORDER BY userid", array($_CONFIG['profile_update'], $_CONFIG['resend_profile_update'], $_CONFIG['profile_update']), __FILE__, __LINE__);
        if (SQL_NUMROWS($result) > 0)
        {
                // We need to send-out notifications...