Renamed ifSqlHasZeroNums() to ifSqlHasZeroNumRows() and improved some queries.
[mailer.git] / inc / modules / member / what-bonus.php
index ee9965faafac13e0fb95628ef8cdcc88a4c19f6a..bfc486f5bc438e13b750deba84663fc1363e0ea0 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 10/19/2003 *
- * ===============                              Last change: 11/19/2005 *
+ * Mailer v0.2.1-FINAL                                Start: 10/19/2003 *
+ * ===================                          Last change: 11/19/2005 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : what-bonus.php                                   *
  * -------------------------------------------------------------------- *
  * Kurzbeschreibung  : Bonusseiten fuer ein paar Extrapunkte            *
  * -------------------------------------------------------------------- *
- *                                                                      *
+ * $Revision::                                                        $ *
+ * $Date::                                                            $ *
+ * $Tag:: 0.2.1-FINAL                                                 $ *
+ * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
- * Copyright (c) 2003 - 2008 by Roland Haeder                           *
- * For more information visit: http://www.mxchange.org                  *
+ * Copyright (c) 2003 - 2009 by Roland Haeder                           *
+ * 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 *
 
 // Some security stuff...
 if (!defined('__SECURITY')) {
-       $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
-       require($INC);
-} elseif (!IS_MEMBER()) {
-       LOAD_URL("modules.php[5~?module=index");
-} elseif ((!EXT_IS_ACTIVE("bonus")) && (!IS_ADMIN())) {
-       addFatalMessage(__FILE__, __LINE__, getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), "bonus");
-       return;
+       exit();
+} elseif (!isMember()) {
+       redirectToIndexMemberOnlyModule();
 }
 
 // Add description as navigation point
-ADD_DESCR("member", __FILE__);
+addYouAreHereLink('member', __FILE__);
 
-if (GET_EXT_VERSION("bonus") >= "0.6.9") {
-       // Add more bonus points here
-       // @TODO Rewrite this to a filter
-       $USE = "(0";
-       if (getConfig('bonus_click_yn') == "Y") $USE .= " + turbo_bonus";
-       if (getConfig('bonus_login_yn') == "Y") $USE .= " + login_bonus";
-       if (getConfig('bonus_order_yn') == "Y") $USE .= " + bonus_order";
-       if (getConfig('bonus_stats_yn') == "Y") $USE .= " + bonus_stats";
-       if (getConfig('bonus_ref_yn')   == "Y") $USE .= " + bonus_ref";
-       $USE .= ")";
-} else {
-       // Old version ???
-       $USE = "turbo_bonus";
-}
+if ((!isExtensionActive('bonus')) && (!isAdmin())) {
+       displayMessage('{%pipe,generateExtensionInactiveNotInstalledMessage=bonus%}');
+       return;
+} // END - if
+
+// Add more bonus points here
+$add = runFilterChain('add_bonus_points_user_columns', '');
+$pointsColumns = '`turbo_bunus`';
+if (!empty($add)) {
+       $pointsColumns = '(0' . $add . ')';
+} // END - if
+
+// Init variables
+$lastOnline = '%s';
+$ONLINE = '';
 
 // Autopurge installed?
-$lastOnline = "%s"; $ONLINE = "";
-if (EXT_IS_ACTIVE("autopurge")) {
+if ((isExtensionActive('autopurge')) && ((getApInactiveSince() > 0))) {
        // Use last online timestamp to keep inactive members away from here
-       $lastOnline   = " AND last_online >= (UNIX_TIMESTAMP() - %s)";
-       $ONLINE = getConfig('ap_inactive_since');
-}
+       $lastOnline   = ' AND (UNIX_TIMESTAMP() - `last_online`) < {?ap_inactive_since?}';
+} // END - if
 
-// Let's check if there are some points left we can "pay"...
-$result = SQL_QUERY_ESC("SELECT userid, ".$USE." AS points, last_online FROM `{!_MYSQL_PREFIX!}_user_data`
-WHERE ".$USE." > 0 AND `status`='CONFIRMED'".$lastOnline."
-ORDER BY points DESC, last_online DESC, userid
-LIMIT %s",
-       array($ONLINE, getConfig('bonus_ranks')), __FILE__, __LINE__);
+// Let's check if there are some points left we can 'pay'...
+$result = sqlQueryEscaped("SELECT
+       `userid`,
+       ".$pointsColumns." AS `points`,
+       `last_online`
+FROM
+       `{?_MYSQL_PREFIX?}_user_data`
+WHERE
+       " . $pointsColumns . " > 0 AND
+       `status`='CONFIRMED'
+       " . runFilterChain('user_exclusion_sql', ' ') . "
+       " . $lastOnline . "
+ORDER BY
+       `points` DESC,
+       `last_online` DESC,
+       `userid` ASC
+LIMIT {?bonus_ranks?}",
+       array(
+               $ONLINE
+       ), __FILE__, __LINE__);
 
 // Reset temporary variable and check for users
-$OUT = "";
-if (SQL_NUMROWS($result) > 0) {
+$OUT = '';
+if (!ifSqlHasZeroNumRows($result)) {
        // Load our winners...
-       $SW = 2; $cnt = 1;
-       while ($content = SQL_FETCHARRAY($result)) {
+       $count = 1;
+       while ($content = sqlFetchArray($result)) {
                // Prepare data for the template
-               $content = array(
-               $content['sw']     = $SW;
-               $content['cnt']    = $cnt;
-               $content['uid']    = bigintval($content['uid']);
-               $content['points'] = TRANSLATE_COMMA($content['points']);
-               $content['last']   = MAKE_DATETIME($content['last'], "2");
+               $content['count']       = $count;
+               $content['last_online'] = generateDateTime($content['last_online'], '2');
 
                // Load row template
-               $OUT .= LOAD_TEMPLATE("member_bonus_row", true, $content);
+               $OUT .= loadTemplate('member_bonus_row', TRUE, $content);
 
-               // Count one up and switch colors
-               $cnt++;$SW = 3 - $SW;
-       }
+               // Count one up
+               $count++;
+       } // END - while
 } else {
        // No one is interested in our "active rallye" ! :-(
-       $OUT = LOAD_TEMPLATE("member_bonus_404", true);
+       $OUT = loadTemplate('member_bonus_404', TRUE);
 }
 
 // Free memory
-SQL_FREERESULT($result);
+sqlFreeResult($result);
 
-// Remeber row(s) for the template
-define('__BONUS_ROWS', $OUT);
+// Prepare content array
+$content['rows'] = $OUT;
 
 // Load final template
-LOAD_TEMPLATE("member_bonus");
+loadTemplate('member_bonus', FALSE, $content);
 
-//
+// [EOF]
 ?>