Renamed ifSqlHasZeroNums() to ifSqlHasZeroNumRows() and improved some queries.
[mailer.git] / inc / modules / admin / what-list_autopurge.php
index 1aa19ca73bea3118c0ac2b28e4d3be5eae70cf84..0ff99f1899b2d754dd59b26ce6650c51a1645a27 100644 (file)
@@ -16,8 +16,8 @@
  * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
- * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
- * For more information visit: http://www.mxchange.org                  *
+ * Copyright (c) 2009 - 2015 by Mailer Developer Team                   *
+ * For more information visit: http://mxchange.org                      *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
  * it under the terms of the GNU General Public License as published by *
@@ -43,33 +43,39 @@ if ((!defined('__SECURITY')) || (!isAdmin())) {
 // Add description as navigation point
 addYouAreHereLink('admin', __FILE__);
 
-// Exclude default referal id if set
-// @TODO Rewrite those lines to filter
-$EXCLUDE_LIST = '';
-if (isValidUserId(getDefRefid()))              $EXCLUDE_LIST .= ' AND d.userid != {?def_refid?}';
-if (isExtensionActive('beg'))                  $EXCLUDE_LIST .= ' AND d.userid != {?beg_userid?}';
-if (isExtensionActive('bonus'))                $EXCLUDE_LIST .= ' AND d.userid != {?bonus_userid?}';
-if (isExtensionActive('doubler'))              $EXCLUDE_LIST .= ' AND d.userid != {?doubler_userid?}';
-if (isExtensionInstalledAndNewer('holiday', '0.1.3')) $EXCLUDE_LIST .= " AND d.`holiday_active`='N'";
+// Exclude default referral id if set
+$userExcludeSql = ' ';
+$excludedUserids = runFilterChain('config_userid_exclusion_sql', array());
+if (isFilledArray($excludedUserids)) {
+       // Exclude all
+       $userExcludeSql = ' AND `d`.`userid` NOT IN (' . implode(', ', $excludedUserids) . ')';
+} // END - if
 
 // Check for all accounts
-$result = SQL_QUERY("SELECT
-       d.`userid`, d.`gender`, d.`surname`, d.`family`, d.`email`, d.`joined`, d.`last_online`, d.`ap_notified`
+$result = sqlQuery("SELECT
+       `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
+       `{?_MYSQL_PREFIX?}_user_data` AS `d`
 WHERE
-       d.`status`='CONFIRMED' AND
-       d.`joined` < (UNIX_TIMESTAMP() - {?ap_inactive_since?}) AND
-       d.`last_online` < (UNIX_TIMESTAMP() - {?ap_inactive_since?}) AND
-       d.`ap_notified` < (UNIX_TIMESTAMP() - {?ap_inactive_since?})
-       ".$EXCLUDE_LIST."
+       `d`.`status`='CONFIRMED' AND
+       (UNIX_TIMESTAMP() - `d`.`joined`) >= {?ap_inactive_since?} AND
+       (UNIX_TIMESTAMP() - `d`.`last_online`) >= {?ap_inactive_since?} AND
+       (UNIX_TIMESTAMP() - `d`.`ap_notified`) >= {?ap_inactive_since?}
+       " . runFilterChain('user_exclusion_sql', ' ' . $userExcludeSql) . "
 ORDER BY
-       d.`userid` ASC", __FILE__, __LINE__);
+       `d`.`userid` ASC", __FILE__, __LINE__);
 
-if (!SQL_HASZERONUMS($result)) {
+if (!ifSqlHasZeroNumRows($result)) {
        // Ok, we have found some inactive accounts
        $OUT = '';
-       while ($content = SQL_FETCHARRAY($result)) {
+       while ($content = sqlFetchArray($result)) {
                // Prepare data for the row template
                $content = array(
                        'userid'      => $content['userid'],
@@ -83,15 +89,15 @@ if (!SQL_HASZERONUMS($result)) {
                );
 
                // Load row template
-               $OUT .= loadTemplate('admin_list_autopurge_row', true, $content);
+               $OUT .= loadTemplate('admin_list_autopurge_row', TRUE, $content);
        } // END - while
 
        // Free memory
-       SQL_FREERESULT($result);
+       sqlFreeResult($result);
        $content['rows'] = $OUT;
 
        // Load main template
-       loadTemplate('admin_list_autopurge', false, $content);
+       loadTemplate('admin_list_autopurge', FALSE, $content);
 } else {
        // All members are active or you don't have any registered
        displayMessage('{--ADMIN_AUTOPURGE_ALL_ACTIVE--}');