A lot while() conditions rewritten to SQL_FETCHARRAY(), see bug #107, @TODO tags...
[mailer.git] / inc / modules / admin / what-list_beg.php
index 5fb3f71b9f6e6a1a7e84493773b77fe4afb6da21..1dbaf06ffbeadc03ed0af6346c555ec4446e0920 100644 (file)
@@ -39,57 +39,54 @@ if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
 // Add description as navigation point
 ADD_DESCR("admin", __FILE__);
 
-if ($_CONFIG['beg_rallye'] == "Y")
-{
+if (getConfig('beg_rallye') == "Y") {
        // Shall I withdraw now?
-       if (isset($_POST['withdraw']))
-       {
+       if (REQUEST_ISSET_POST(('withdraw'))) {
                // Okay, let's prepare...
                $curr = date("m", time()) - 1;
                if (strlen($curr) == 1) $curr = "0".$curr;
                UPDATE_CONFIG("last_month", $curr);
-               LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_BEG_WITHDRAW_PREPARED);
-               OUTPUT_HTML("<br />");
-       }
+               LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_BEG_WITHDRAW_PREPARED'));
+       } // END - if
 
        // Autopurge installed?
-       $LAST = "%s"; $ONLINE = "";
-       if (EXT_IS_ACTIVE("autopurge"))
-       {
+       $lastOnline = "%s"; $ONLINE = "";
+       if (EXT_IS_ACTIVE("autopurge")) {
                // Use last online timestamp to keep inactive members away from here
-               $LAST   = " AND last_online >= (UNIX_TIMESTAMP() - %s)";
-               $ONLINE = $_CONFIG['ap_inactive_since'];
-       }
+               $lastOnline   = " AND last_online >= (UNIX_TIMESTAMP() - %s)";
+               $ONLINE = getConfig('ap_inactive_since');
+       } // END - if
 
        // Check if at least one is in the active rallye
        $result = SQL_QUERY_ESC("SELECT userid, email, gender, surname, family, beg_points, last_online
-FROM "._MYSQL_PREFIX."_user_data
-WHERE status='CONFIRMED' AND beg_points > 0".$LAST."
+FROM `{!_MYSQL_PREFIX!}_user_data`
+WHERE `status`='CONFIRMED' AND beg_points > 0".$lastOnline."
 ORDER BY beg_points DESC, last_online DESC, userid",
         array($ONLINE), __FILE__, __LINE__);
 
-       if (SQL_NUMROWS($result) > 0)
-       {
+       if (SQL_NUMROWS($result) > 0) {
                // List users
                $OUT = "";$SW = 2; $cnt = 1; $total = 0;
-               while(list($uid, $email, $gender, $sname, $fname, $turbo, $last) = SQL_FETCHROW($result))
-               {
-                       // Generate array fore the dynamic template
+               while ($content = SQL_FETCHARRAY($result)) {
+                       // Init variables
                        $WIN1 = ""; $WIN2 = "";
-                       if ($cnt <= $_CONFIG['beg_ranks'])
-                       {
+                       if ($cnt <= getConfig('beg_ranks')) {
                                // Maybe he can win his active beg?
-                               $WIN1 = "<STRONG>";
-                               $WIN2 = "</STRONG>";
-                       }
+                               $WIN1 = "<strong>";
+                               $WIN2 = "</strong>";
+                       } // END - if
+
+                       // Prepare content
+                       // @TODO Rewrite templates so s/fname will be replaced by surname/family
+                       // @TODO to shorten this block. Please also do so with uid->userid
                        $content = array(
-                               'uid'    => $uid,
-                               'email'  => CREATE_EMAIL_LINK($email, "user_data"),
-                               'gender' => TRANSLATE_GENDER($gender),
-                               'sname'  => $sname,
-                               'fname'  => $fname,
-                               'turbo'  => TRANSLATE_COMMA($turbo),
-                               'last'   => MAKE_DATETIME($last, "2"),
+                               'uid'    => $content['userid'],
+                               'email'  => CREATE_EMAIL_LINK($content['email'], "user_data"),
+                               'gender' => TRANSLATE_GENDER($content['gender']),
+                               'sname'  => $content['surname'],
+                               'fname'  => $content['family'],
+                               'turbo'  => TRANSLATE_COMMA($content['beg_points']),
+                               'last'   => MAKE_DATETIME($content['last_online'], "2"),
                                'sw'     => $SW,
                                'win1'   => $WIN1,
                                'win2'   => $WIN2,
@@ -98,43 +95,36 @@ ORDER BY beg_points DESC, last_online DESC, userid",
 
                        // Load template and add it
                        $OUT .= LOAD_TEMPLATE("admin_list_beg_rows", true, $content);
-                       $SW = 3 - $SW; $cnt++; $total += $turbo;
+                       $SW = 3 - $SW; $cnt++; $total += $content['beg_points'];
                }
                define('__BEG_ROWS', $OUT);
                define('__TOTAL', TRANSLATE_COMMA($total));
 
                // Check if we need to display form or not with manuel withdraw
-               if ($_CONFIG['last_month'] == date("m", time()))
-               {
+               if (getConfig('last_month') == date("m", time())) {
                        // Load form
                        define('__BEG_WITHDRAW_FORM', LOAD_TEMPLATE("admin_list_beg_form", true));
-               }
-                else
-               {
+               } else {
                        // Display message "no manual withdraw possible"
-                       define('__BEG_WITHDRAW_FORM', "<FONT class=\"admin_failed\">".ADMIN_BEG_ALREADY_WITHDRAW."</FONT>");
+                       define('__BEG_WITHDRAW_FORM', "<div class=\"admin_failed\">{--ADMIN_BEG_ALREADY_WITHDRAW--}</div>");
                }
 
                // Prepare constant for timemark
                if (EXT_IS_ACTIVE("autopurge")) {
-                       define('__AUTOPURGE_TIMEOUT', MAKE_DATETIME(time() - $_CONFIG['ap_inactive_since'], "2"));
+                       define('__AUTOPURGE_TIMEOUT', MAKE_DATETIME(time() - getConfig('ap_inactive_since'), "2"));
                } else {
-                       define('__AUTOPURGE_TIMEOUT', sprintf(EXTENSION_PROBLEM_NOT_INSTALLED, "autopurge"));
+                       define('__AUTOPURGE_TIMEOUT', sprintf(getMessage('EXTENSION_PROBLEM_NOT_INSTALLED'), "autopurge"));
                }
 
                // Load final template
                LOAD_TEMPLATE("admin_list_beg");
-       }
-        else
-       {
+       } else {
                // No one has joined the begging rallye...
-               LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_BEG_NO_RALLYE);
+               LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_BEG_NO_RALLYE'));
        }
-}
- else
-{
+} else {
        // Rallye deactivated
-       LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_BEG_RALLYE_DEACTIVATED);
+       LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_BEG_RALLYE_DEACTIVATED'));
 }
 
 //