]> git.mxchange.org Git - mailer.git/blobdiff - inc/modules/guest/what-top10.php
A lot while() conditions rewritten to SQL_FETCHARRAY(), see bug #107, @TODO tags...
[mailer.git] / inc / modules / guest / what-top10.php
index 56ef74b37d5a04da1dd70eb597d2fd4bf546d27c..8cec95dbe0ae46df7dba126675562bbddef687f7 100644 (file)
@@ -36,36 +36,45 @@ if (!defined('__SECURITY')) {
        $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
        require($INC);
 } elseif ((!EXT_IS_ACTIVE("top10")) && (!IS_ADMIN())) {
-       ADD_FATAL(EXTENSION_PROBLEM_EXT_INACTIVE, "top10");
+       addFatalMessage(__FILE__, __LINE__, getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), "top10");
        return;
 }
 
 // Add description as navigation point
-ADD_DESCR("guest", basename(__FILE__));
+ADD_DESCR("guest", __FILE__);
 
 //// TOP logins
-$ADD = "userid";
-if (EXT_IS_ACTIVE("nickname")) $ADD = "nickname";
-$result = SQL_QUERY_ESC("SELECT userid, ".$ADD.", total_logins, last_online
-FROM "._MYSQL_PREFIX."_user_data
-WHERE total_logins>0 AND status='CONFIRMED' ORDER BY total_logins DESC LIMIT %s",
- array($_CONFIG['top10_max']), __FILE__, __LINE__);
+$result = SQL_QUERY_ESC("
+SELECT
+       userid, total_logins, last_online
+FROM
+       {!_MYSQL_PREFIX!}_user_data
+WHERE
+       total_logins > 0 AND
+       `status`='CONFIRMED'
+ORDER BY
+       total_logins DESC
+LIMIT %s",
+       array(getConfig('top10_max')), __FILE__, __LINE__);
 
 $OUT = ""; $SW = 2; $cnt = 1;
-while(list($uid, $nick, $logins, $last) = SQL_FETCHROW($result))
-{
-       $nick2 = "---";
-       if (($nick != $uid) && (!empty($nick))) $nick2 = $nick;
+while ($content = SQL_FETCHARRAY($result)) {
+       // Init nickname
+       $content['nickname'] = "---";
+
+       // Get nickname
+       if (EXT_IS_ACTIVE("nickname")) $content['nickname'] = NICKNAME_GET_NICK($content['userid']);
 
        // Prepare data for template
+       // @TODO Rewritings: uid->userid,nick->nickname,logins->total_logins in template
        $content = array(
                'sw'     => $SW,
                'cnt'    => $cnt,
-               'uid'    => $uid,
-               'nick'   => $nick2,
-               'logins' => $logins,
-               'points' => TRANSLATE_COMMA(GET_TOTAL_DATA($uid, "user_points", "points")),
-               'last'   => MAKE_DATETIME($last, "3"),
+               'uid'    => $content['userid'],
+               'nick'   => $content['nickname'],
+               'logins' => $content['total_logins'],
+               'points' => TRANSLATE_COMMA(GET_TOTAL_DATA($content['userid'], "user_points", "points")),
+               'last'   => MAKE_DATETIME($content['last_online'], "3"),
        );
 
        // Load row template
@@ -73,12 +82,11 @@ while(list($uid, $nick, $logins, $last) = SQL_FETCHROW($result))
 
        // Switch colors and count one up
        $SW = 3 - $SW; $cnt++;
-}
-if ($cnt < $_CONFIG['top10_max'])
-{
+} // END - while
+
+if ($cnt < getConfig('top10_max')) {
        // Add more "blank" rows
-       for ($i = $cnt; $i <= $_CONFIG['top10_max']; $i++)
-       {
+       for ($i = $cnt; $i <= getConfig('top10_max'); $i++) {
                // Prepare data for template
                $content = array(
                        'sw'  => $SW,
@@ -88,35 +96,55 @@ if ($cnt < $_CONFIG['top10_max'])
                // Load row template
                $OUT .= LOAD_TEMPLATE("guest_top10_empty5", true, $content);
                $SW = 3 - $SW;
-       }
-}
+       } // END - for
+} // END - if
+
+// @TODO Rewrite this constant
 define('__TOP_LOGINS_ROWS', $OUT);
 
+// Free result
+SQL_FREERESULT($result);
+
 //// TOP earners
-$result = SQL_QUERY_ESC("SELECT DISTINCT p.userid, d.".$ADD.", (SUM(p.points) - d.used_points) AS tpoints, d.last_online
-FROM "._MYSQL_PREFIX."_user_points AS p
-LEFT JOIN "._MYSQL_PREFIX."_user_data AS d
-ON p.userid=d.userid
-WHERE p.points > 0 AND d.status='CONFIRMED'
-GROUP BY p.userid
-ORDER BY tpoints DESC, d.last_online DESC
+$result = SQL_QUERY_ESC("
+SELECT DISTINCT
+       d.userid,
+       (SUM(p.points) - d.used_points) AS tpoints,
+       d.last_online
+FROM
+       `{!_MYSQL_PREFIX!}_user_data` AS d
+LEFT JOIN
+       {!_MYSQL_PREFIX!}_user_points AS p
+ON
+       p.userid=d.userid
+WHERE
+       p.points > 0 AND
+       d.`status`='CONFIRMED'
+GROUP BY
+       p.userid
+ORDER BY
+       tpoints DESC,
+       d.last_online DESC
 LIMIT %s",
array($_CONFIG['top10_max']), __FILE__, __LINE__);
      array(getConfig('top10_max')), __FILE__, __LINE__);
 
 $OUT = ""; $SW = 2; $cnt = 1;
-while(list($uid, $nick, $points, $last) = SQL_FETCHROW($result))
-{
-       $nick2 = "---";
-       if (($nick != $uid) && (!empty($nick))) $nick2 = $nick;
+while ($content = SQL_FETCHARRAY($result)) {
+       // Init nickname
+       $content['nickname'] = "---";
+
+       // Get nickname
+       if (EXT_IS_ACTIVE("nickname")) $content['nickname'] = NICKNAME_GET_NICK($content['userid']);
 
        // Prepare data for template
+       // @TODO Rewritings: nick->nickname,uid->userid in template
        $content = array(
                'sw'     => $SW,
                'cnt'    => $cnt,
-               'uid'    => bigintval($uid),
-               'nick'   => $nick2,
-               'points' => TRANSLATE_COMMA($points),
-               'last'   => MAKE_DATETIME($last, "3")
+               'uid'    => $content['userid'],
+               'nick'   => $content['nickname'],
+               'points' => TRANSLATE_COMMA($content['points']),
+               'last'   => MAKE_DATETIME($content['last_online'], "3")
        );
 
        // Load row template
@@ -124,12 +152,11 @@ while(list($uid, $nick, $points, $last) = SQL_FETCHROW($result))
 
        // Switch colors and count one up
        $SW = 3 - $SW; $cnt++;
-}
-if ($cnt < $_CONFIG['top10_max'])
-{
+} // END - while
+
+if ($cnt < getConfig('top10_max')) {
        // Add more "blank" rows
-       for ($i = $cnt; $i <= $_CONFIG['top10_max']; $i++)
-       {
+       for ($i = $cnt; $i <= getConfig('top10_max'); $i++) {
                // Prepare data for template
                $content = array(
                        'sw'  => $SW,
@@ -139,36 +166,56 @@ if ($cnt < $_CONFIG['top10_max'])
                // Load row template
                $OUT .= LOAD_TEMPLATE("guest_top10_empty4", true, $content);
                $SW = 3 - $SW;
-       }
-}
+       } // END - for
+} // END - if
+
+// @TODO Rewrite this constant
 define('__TOP_POINTS_ROWS', $OUT);
 
-//// TOP referral "hunter"
-$result = SQL_QUERY_ESC("SELECT DISTINCT r.userid, d.".$ADD.", SUM(r.counter) AS refs, d.last_online
-FROM "._MYSQL_PREFIX."_refsystem AS r
-LEFT JOIN "._MYSQL_PREFIX."_user_data AS d
-ON r.userid=d.userid
-WHERE r.counter > 0 AND d.status='CONFIRMED'
-GROUP BY r.userid
-ORDER BY refs DESC, d.last_online DESC
+// Free result
+SQL_FREERESULT($result);
+
+//// TOP referal "hunter"
+$result = SQL_QUERY_ESC("
+SELECT DISTINCT
+       d.userid,
+       SUM(r.counter) AS refs,
+       d.last_online
+FROM
+       `{!_MYSQL_PREFIX!}_user_data` AS d
+LEFT JOIN
+       {!_MYSQL_PREFIX!}_refsystem AS r
+ON
+       r.userid=d.userid
+WHERE
+       r.counter > 0 AND
+       d.`status`='CONFIRMED'
+GROUP BY
+       r.userid
+ORDER BY
+       refs DESC,
+       d.last_online DESC
 LIMIT %s",
array($_CONFIG['top10_max']), __FILE__, __LINE__);
      array(getConfig('top10_max')), __FILE__, __LINE__);
 
 $OUT = ""; $SW = 2; $cnt = 1;
-while(list($uid, $nick, $refs, $last) = SQL_FETCHROW($result))
-{
-       $nick2 = "---";
-       if (($nick != $uid) && (!empty($nick))) $nick2 = $nick;
+while ($content = SQL_FETCHARRAY($result)) {
+       // Init nickname
+       $content['nickname'] = "---";
+
+       // Get nickname
+       if (EXT_IS_ACTIVE("nickname")) $content['nickname'] = NICKNAME_GET_NICK($content['userid']);
 
        // Prepare data for template
+       // @TODO Rewritings: nick->nickname,uid->userid in template
        $content = array(
                'sw'     => $SW,
                'cnt'    => $cnt,
-               'uid'    => bigintval($uid),
-               'refs'   => $refs,
-               'nick'   => $nick2,
-               'points' => TRANSLATE_COMMA(GET_TOTAL_DATA($uid, "user_points", "points")),
-               'last'   => MAKE_DATETIME($last, "3")
+               'uid'    => $content['userid'],
+               'refs'   => $content['refs'],
+               'nick'   => $content['nickname'],
+               'points' => TRANSLATE_COMMA(GET_TOTAL_DATA($content['userid'], "user_points", "points")),
+               'last'   => MAKE_DATETIME($content['last_online'], "3")
        );
 
        // Load row template
@@ -176,12 +223,11 @@ while(list($uid, $nick, $refs, $last) = SQL_FETCHROW($result))
 
        // Switch colors and count one up
        $SW = 3 - $SW; $cnt++;
-}
-if ($cnt < $_CONFIG['top10_max'])
-{
+} // END - while
+
+if ($cnt < getConfig('top10_max')) {
        // Add more "blank" rows
-       for ($i = $cnt; $i <= $_CONFIG['top10_max']; $i++)
-       {
+       for ($i = $cnt; $i <= getConfig('top10_max'); $i++) {
                // Prepare data for template
                $content = array(
                        'sw'  => $SW,
@@ -191,12 +237,18 @@ if ($cnt < $_CONFIG['top10_max'])
                // Load row template
                $OUT .= LOAD_TEMPLATE("guest_top10_empty5", true, $content);
                $SW = 3 - $SW;
-       }
-}
+       } // END - for
+} // END - if
+
+// @TODO Rewrite this constant
 define('__TOP_REFERRAL_ROWS', $OUT);
 
+// Free result
+SQL_FREERESULT($result);
+
 // Remember other values in constants
-define('__TOP10_MAX', $_CONFIG['top10_max']);
+// @TODO Rewrite this constant
+define('__TOP10_MAX', getConfig('top10_max'));
 
 // Load final template
 LOAD_TEMPLATE("guest_top10");