From: Roland Häder Date: Tue, 16 Sep 2008 20:48:29 +0000 (+0000) Subject: More queries now depends on UNIX_TIMESTAMP() not on time(), more fixes for not instal... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=4240b5d40ef77c13d4e76dc75da545114f69f08f;p=mailer.git More queries now depends on UNIX_TIMESTAMP() not on time(), more fixes for not installed autopurge extension --- diff --git a/inc/libs/rallye_functions.php b/inc/libs/rallye_functions.php index 58dac3bafb..f6e65e5b1a 100644 --- a/inc/libs/rallye_functions.php +++ b/inc/libs/rallye_functions.php @@ -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) { diff --git a/inc/libs/task_functions.php b/inc/libs/task_functions.php index 1aced16f60..20e653b4bd 100644 --- a/inc/libs/task_functions.php +++ b/inc/libs/task_functions.php @@ -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; diff --git a/inc/modules/admin/what-list_autopurge.php b/inc/modules/admin/what-list_autopurge.php index 8a5cf45583..70ccbd5f82 100644 --- a/inc/modules/admin/what-list_autopurge.php +++ b/inc/modules/admin/what-list_autopurge.php @@ -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) { diff --git a/inc/modules/admin/what-list_beg.php b/inc/modules/admin/what-list_beg.php index fa3115f182..cc3eba1700 100644 --- a/inc/modules/admin/what-list_beg.php +++ b/inc/modules/admin/what-list_beg.php @@ -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"); diff --git a/inc/modules/admin/what-list_bonus.php b/inc/modules/admin/what-list_bonus.php index 7b02b64a92..6cd69df1a2 100644 --- a/inc/modules/admin/what-list_bonus.php +++ b/inc/modules/admin/what-list_bonus.php @@ -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"); diff --git a/inc/modules/guest/what-register.php b/inc/modules/guest/what-register.php index f06e9ee66f..ac63b929b2 100644 --- a/inc/modules/guest/what-register.php +++ b/inc/modules/guest/what-register.php @@ -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']); diff --git a/inc/modules/member/what-beg2.php b/inc/modules/member/what-beg2.php index 6a250924d5..a7e131b107 100644 --- a/inc/modules/member/what-beg2.php +++ b/inc/modules/member/what-beg2.php @@ -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"... diff --git a/inc/modules/member/what-bonus.php b/inc/modules/member/what-bonus.php index 66ae60cb37..ddd819bbae 100644 --- a/inc/modules/member/what-bonus.php +++ b/inc/modules/member/what-bonus.php @@ -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"... diff --git a/inc/modules/member/what-order.php b/inc/modules/member/what-order.php index 0577688f28..1053b26427 100644 --- a/inc/modules/member/what-order.php +++ b/inc/modules/member/what-order.php @@ -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) diff --git a/inc/monthly/monthly_bonus.php b/inc/monthly/monthly_bonus.php index c00a486e60..0c5f9dd64a 100644 --- a/inc/monthly/monthly_bonus.php +++ b/inc/monthly/monthly_bonus.php @@ -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) { diff --git a/inc/profile-updte.php b/inc/profile-updte.php index fb40eb9efa..1e29d2eb7d 100644 --- a/inc/profile-updte.php +++ b/inc/profile-updte.php @@ -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...