Fixed endless loop, if no sql_patches is installed and modules.php?module=index was...
[mailer.git] / show_bonus.php
index 45019b90f62f869f5f18aabb8397c099f5dd2f7c..61e8ce264adacd49e9992bea202fd7b667fbc612 100644 (file)
@@ -37,55 +37,66 @@ require_once("inc/libs/security_functions.php");
 // Init "action" and "what"
 global $what, $action, $startTime;
 $GLOBALS['startTime'] = microtime(true);
-$GLOBALS['what'] = ""; $GLOBALS['action'] = "";
+$GLOBALS['what'] = "";
+$GLOBALS['action'] = "";
 
 // Set this because we have no module in URI
 $GLOBALS['module'] = "show_bonus"; $CSS = 0;
 
 // Load the required file(s)
-require ("inc/config.php");
+require("inc/config.php");
+
+// Is the "bonus" extension active?
+if (!EXT_IS_ACTIVE("bonus")) {
+       // Redirect to index
+       LOAD_URL("modules.php?module=index&msg=".CODE_EXTENSION_PROBLEM."&ext=bonus");
+} // END - if
 
 // List only rankings when script is installed
-if (isBooleanConstantAndTrue('mxchange_installed'))
-{
+if (isBooleanConstantAndTrue('mxchange_installed')) {
        // Include header
        include(PATH."inc/header.php");
 
-       if (($_GET['uid'] > 0) && ($_GET['d'] > 0) && (!empty($_GET['t'])))
-       {
+       if (($_GET['uid'] > 0) && ($_GET['d'] > 0) && (!empty($_GET['t']))) {
                // Set row name
                $t = "";
-               switch ($_GET['t'])
-               {
-               case "bonusid":
-                       $t = "bonus_id";
-                       break;
-
-               case "mailid":
-                       $t = "mail_id";
-                       break;
-               }
-               if (!empty($t))
-               {
+               switch ($_GET['t']) {
+                       case "bonusid": // Bonus mail
+                               $t = "bonus_id";
+                               break;
+
+                       case "mailid": // Regular member mail
+                               $t = "mail_id";
+                               break;
+
+                       default: // Invalid type
+                               DEBUG_LOG(__FILE__, __LINE__, sprintf("Invalid type %s detected.", $_GET['t']));
+                               break;
+               } // END - switch
+
+               // Valid type?
+               if (!empty($t)) {
                        // Check for data
                        $result = SQL_QUERY_ESC("SELECT DISTINCT d.gender, d.surname, d.family, b.level, b.points
-FROM "._MYSQL_PREFIX."_user_data AS d
+FROM `"._MYSQL_PREFIX."_user_data` AS d
 RIGHT JOIN "._MYSQL_PREFIX."_bonus_turbo AS b
 ON d.userid=b.userid
-WHERE d.status='CONFIRMED' AND d.userid=%s AND b.".$t."='%s' LIMIT 1",
- array(bigintval($_GET['uid']), bigintval($_GET['d'])), __FILE__, __LINE__);
-                       if (SQL_NUMROWS($result) == 1)
-                       {
+WHERE d.status='CONFIRMED' AND d.userid=%s AND b.%s=%s
+LIMIT 1",
+                               array(bigintval($_GET['uid']), $t, bigintval($_GET['d'])), __FILE__, __LINE__);
+
+                       // Entry found?
+                       if (SQL_NUMROWS($result) == 1) {
                                // Load data
-                               list($gender, $sname, $fname, $level, $points) = SQL_FETCHROW($result);
+                               $content = SQL_FETCHARRAY($result);
 
                                // Prepare constants for the pre-template
-                               define('__GENDER'    , TRANSLATE_GENDER($gender));
-                               define('__SNAME'    , $sname);
-                               define('__FNAME'    , $fname);
-                               define('__RANK'     , $level);
-                               define('__POINTS'   , $points);
-                               define('__MAILID'   , $_GET['d']);
+                               define('__GENDER'   , TRANSLATE_GENDER($content['gender']));
+                               define('__SNAME'    , $content['surname']);
+                               define('__FNAME'    , $content['family']);
+                               define('__RANK'     , BIGINTVAL($content['level']));
+                               define('__POINTS'   , TRANSLATE_COMMA($content['points']));
+                               define('__MAILID'   , bigintval($_GET['d']));
                                define('__RANK_ROWS', BONUS_MAKE_RANK_ROWS(bigintval($_GET['d']), $t, bigintval($_GET['uid'])));
 
                                // Constant created within previous function which contains informations for current user's ranking position:
@@ -93,26 +104,20 @@ WHERE d.status='CONFIRMED' AND d.userid=%s AND b.".$t."='%s' LIMIT 1",
 
                                // Load pre-template
                                define('__BONUS_MSG', LOAD_TEMPLATE("show_bonus_msg", true));
-                       }
-                        else
-                       {
+                       } else {
                                // No data found
-                               define('__BONUS_MSG', "<FONT class=\"guest_failed\">".BONUS_SHOW_NO_DATA."</FONT>");
+                               define('__BONUS_MSG', "<span class=\"guest_failed\">".BONUS_SHOW_NO_DATA."</span>");
                        }
 
                        // Free memory
                        SQL_FREERESULT($result);
-               }
-                else
-               {
+               } else {
                        // Wrong type entered
-                       define('__BONUS_MSG', "<FONT class=\"guest_failed\">".BONUS_SHOW_WRONG_TYPE."</FONT>");
+                       define('__BONUS_MSG', "<span class=\"guest_failed\">".BONUS_SHOW_WRONG_TYPE."</span>");
                }
-       }
-        else
-       {
+       } else {
                // Wrong call!
-               define('__BONUS_MSG', "<FONT class=\"guest_failed\">".BONUS_SHOW_WRONG_CALL."</FONT>");
+               define('__BONUS_MSG', "<span class=\"guest_failed\">".BONUS_SHOW_WRONG_CALL."</span>");
        }
 
        // Load send_bonus header template (for your banners, e.g.?)
@@ -122,18 +127,17 @@ WHERE d.status='CONFIRMED' AND d.userid=%s AND b.".$t."='%s' LIMIT 1",
        define('__BONUS_FOOTER', LOAD_TEMPLATE("show_bonus_footer", true));
 
        // Total ranks who can win
-       define('__BONUS_TOTAL_RANKS', $_CONFIG['bonus_ranks']);
+       define('__BONUS_TOTAL_RANKS', getConfig('bonus_ranks'));
 
        // Load final template
        LOAD_TEMPLATE("show_bonus");
 
        // Include footer
        include(PATH."inc/footer.php");
-}
- else
-{
+} else {
        // You have to configure first!
        LOAD_URL("install.php");
 }
+
 // Really all done here... ;-)
 ?>