More misc fixes and rewrites (sorry, lame description)
[mailer.git] / inc / libs / rallye_functions.php
index 3d3b2d3b12ea47659e26dd27508eecbbf280738e..998427c95fa76373a82ebf26db773e41c4edca54 100644 (file)
@@ -558,8 +558,8 @@ WHERE d.`status`='CONFIRMED' AND d.max_mails > 0 AND d.mails_confirmed >= %s AND
 //
 function RALLYE_LIST_WINNERS ($rallye, $default=0) {
        // First check how many prices are set
-       $result_prices = SQL_QUERY_ESC("SELECT `id` FROM `{!_MYSQL_PREFIX!}_rallye_prices` WHERE rallye_id=%s ORDER BY price_level",
-       array(bigintval($rallye)), __FUNCTION__, __LINE__);
+       $result_prices = SQL_QUERY_ESC("SELECT `id` FROM `{!_MYSQL_PREFIX!}_rallye_prices` WHERE `rallye_id`=%s ORDER BY `price_level` ASC",
+               array(bigintval($rallye)), __FUNCTION__, __LINE__);
        $prices = SQL_NUMROWS($result_prices);
        SQL_FREERESULT($result_prices);
 
@@ -567,16 +567,13 @@ function RALLYE_LIST_WINNERS ($rallye, $default=0) {
        $DATA = RALLYE_LOAD_USERS_ARRAY($rallye);
 
        // Generate table
-       $OUT = LOAD_TEMPLATE("guest_rallye_expired_header", true);
+       $OUT = LOAD_TEMPLATE('guest_rallye_expired_header', true);
        $SW = 2;
        for ($idx = 0; $idx < $prices; $idx++) {
                // Check status
                //   active = 1: account is still confirmed
                //   active = 0: account is deleted or locked
-               $result_active = SQL_QUERY_ESC("SELECT COUNT(userid) FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s AND `status`='CONFIRMED' LIMIT 1",
-               array(bigintval($DATA['uid'][$idx])), __FUNCTION__, __LINE__);
-               list($active) = SQL_FETCHROW($result_active);
-               SQL_FREERESULT($result_active);
+               $active = GET_TOTAL_DATA($DATA['uid'][$idx], 'user_data', 'userid', 'userid', true, " AND `status`='CONFIRMED'");
 
                if (empty($DATA['uid'][$idx])) $DATA['uid'][$idx] = '---';
                if ((empty($DATA['ref'][$idx])) || ($DATA['ref'][$idx] == 0) || ($active == 0) || ("".round($DATA['cpoints'][$idx])."" == '0') || (empty($DATA['cpoints'][$idx]))) {
@@ -590,7 +587,7 @@ function RALLYE_LIST_WINNERS ($rallye, $default=0) {
                        $DATA['infos'][$idx] = $DATA['info'][$idx];
                } else {
                        // Take ppints
-                       $DATA['infos'][$idx] = $DATA['points'][$idx]." {!POINTS!}";
+                       $DATA['infos'][$idx] = $DATA['points'][$idx] . ' {!POINTS!}';
                }
 
                // Add row