Missing variable fixed, array initialization moved
[mailer.git] / inc / libs / rallye_functions.php
index 40e601a1896978a2f0016f97fb3be2b176e5d4bd..56230b9022fba02148d2d21f6bcd3c7a1981015b 100644 (file)
@@ -16,7 +16,7 @@
  * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
- * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
+ * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
  * For more information visit: http://www.mxchange.org                  *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
@@ -104,13 +104,11 @@ WHERE
        `userid`=%s
 LIMIT 1",
                        array(bigintval($id), bigintval($content['userid'])), __FUNCTION__, __LINE__);
-               if (SQL_NUMROWS($result_ref) == 0) {
-                       // Free memory
-                       SQL_FREERESULT($result_ref);
+               if (SQL_HASZERONUMS($result_ref)) {
 
                        // Add userid and his ref count to table
                        $result_ref = SQL_QUERY_ESC("SELECT 
-       SUM(p.points) AS points
+       SUM(p.points) AS `points`
 FROM
        `{?_MYSQL_PREFIX?}_user_points` AS p
 LEFT JOIN
@@ -149,6 +147,9 @@ WHERE
                        $un = true;
                } // END - if
 
+               // Free memory
+               SQL_FREERESULT($result_ref);
+
                // Ignored but for the template required refs (made before start of rallye)
                $content['refs']  = $count;
 
@@ -415,7 +416,7 @@ LIMIT 1",
                        ), __FUNCTION__, __LINE__);
 
                // Is this user added?
-               if (SQL_NUMROWS($result) < 1) {
+               if (SQL_HASZERONUMS($result)) {
                        // Add userid and his ref count to table
                        SQL_QUERY_ESC("INSERT INTO
        `{?_MYSQL_PREFIX?}_rallye_users`
@@ -443,9 +444,6 @@ function markReferalRallyesAsExpired ($result) {
        // Free result
        SQL_FREERESULT($result);
 
-       // Load users array (!) with assigned prices
-       $prices = getArrayFromReferalRallyeUsers($id);
-
        // Init array
        $DATA = array();
        $count = '0';
@@ -455,13 +453,16 @@ function markReferalRallyesAsExpired ($result) {
        $DATA['end']    = generateDateTime($end  , 1);
        $DATA['now_t']  = generateDateTime(time(), 1);
 
+       // Load users array (!) with assigned prices
+       $prices = getArrayFromReferalRallyeUsers($id);
+
        // Just count...
        $total = '0';
-       foreach($prices['userid'] as $key => $userid) {
+       foreach ($prices['userid'] as $key => $userid) {
                // Check status
                //   active = 1: account is still confirmed
                //   active = 0: account is deleted or locked
-               $active = countSumTotalData($DATA['userid'][$idx], 'user_data', 'userid', 'userid', true, " AND `status`='CONFIRMED'");
+               $active = countSumTotalData($userid, 'user_data', 'userid', 'userid', true, " AND `status`='CONFIRMED'");
 
                $prices['active'][$key] = $active;
 
@@ -482,7 +483,7 @@ function markReferalRallyesAsExpired ($result) {
                array(bigintval($id)), __FUNCTION__, __LINE__);
 
        // Run array through (by userid is the most important 2nd-level-array)
-       foreach($prices['userid'] as $key => $userid) {
+       foreach ($prices['userid'] as $key => $userid) {
                // Allow valid and active users with at least one ref to get points
                if ((isValidUserId($userid)) && ($prices['ref'][$key] > 0) && ($prices['active'][$key] == 1) && ($prices['cpoints'][$key] > 0)) {
                        // Transfer data to array for the mail template
@@ -644,7 +645,7 @@ function getArrayFromReferalRallyeUsers ($rallye) {
 
                // Points of ref's
                $result_ref = SQL_QUERY_ESC("SELECT
-       SUM(p.points) AS points
+       SUM(p.points) AS `points`
 FROM
        `{?_MYSQL_PREFIX?}_user_points` AS p
 LEFT JOIN
@@ -827,7 +828,7 @@ function addReferalRallyeTemplateSelection ($name = 'template', $default = '') {
 
                // Accept only template names between 1 and 255 chars length
                if ((strlen($read) < 256) && (!empty($read))) {
-                       // Valid entry found!
+                       // Valid entry found
                        $ral[$read] = $read;
                } else {
                        // Log invalid
@@ -951,11 +952,5 @@ function determineReferalRallyeMinimumPrices ($min_prices) {
        return $return;
 }
 
-// Filter for extra-autpurge
-function FILTER_RALLYE_EXTRA_AUTOPURGE () {
-       // Check expired rallyes (hard-coded 3 days limit for displaying expired rallyes!)
-       purgeExpiredReferalRallyes();
-}
-
 // [EOF]
 ?>