Fixes for a lot bug tickets. (Sorry for lame comment)
[mailer.git] / mailid_top.php
index 921effc2eef02796b4b23e833fd231049f5ded3d..27da0b7caad766ad991ea81c62556912f36ea683 100644 (file)
@@ -42,15 +42,14 @@ $GLOBALS['what'] = ""; $GLOBALS['action'] = "";
 $GLOBALS['module'] = "mailid";  $CSS = 0;
 
 // Load the required file(s)
-require ("inc/config.php");
+require("inc/config.php");
 
-if (isBooleanConstantAndTrue('mxchange_installed'))
-{
+if (isBooleanConstantAndTrue('mxchange_installed')) {
        // Is the extension active
        if (!EXT_IS_ACTIVE("mailid", true)) {
                // Is not activated/installed yet!
-               ADD_FATAL(sprintf(EXTENSION_PROBLEM_NOT_INSTALLED, "register"));
-       }
+               ADD_FATAL(sprintf(EXTENSION_PROBLEM_NOT_INSTALLED, "mailid"));
+       } // END - if
 
        // Secure all data
        $url_uid = 0; $url_bid = 0; $url_mid = 0; $code = 0; $mode = "";
@@ -61,25 +60,22 @@ if (isBooleanConstantAndTrue('mxchange_installed'))
        if (!empty($_GET['mode']))    $mode    = $_GET['mode'];
 
        // 01        1        12            2    2            21    1     2      2     10
-       if (($url_uid) > 0 && (($url_mid > 0) || ($url_bid > 0)) && (count($FATAL) == 0))
-       {
+       if (($url_uid) > 0 && (($url_mid > 0) || ($url_bid > 0)) && (count($FATAL) == 0)) {
+               // No image? Then output header
                if ($mode != "img") require_once(PATH."inc/header.php");
 
                // Maybe he wants to confirm an email?
-               if ($url_mid > 0)
-               {
+               if ($url_mid > 0) {
                        $result = SQL_QUERY_ESC("SELECT id, link_type FROM "._MYSQL_PREFIX."_user_links WHERE stats_id=%s AND userid=%s LIMIT 1",
                         array($url_mid, $url_uid), __FILE__, __LINE__);
                        $type = "mailid"; $DATA = $url_mid;
-               }
-                elseif ($url_bid > 0)
-               {
+               } elseif ($url_bid > 0)         {
                        $result = SQL_QUERY_ESC("SELECT id, link_type FROM "._MYSQL_PREFIX."_user_links WHERE bonus_id=%s AND userid=%s LIMIT 1",
                         array($url_bid, $url_uid), __FILE__, __LINE__);
                        $type = "bonusid"; $DATA = $url_bid;
                }
-               if (SQL_NUMROWS($result) == 1)
-               {
+
+               if (SQL_NUMROWS($result) == 1) {
                        // Is the stats ID valid?
                        list($lid, $ltype) = SQL_FETCHROW($result);
                        SQL_FREERESULT($result);
@@ -87,16 +83,18 @@ if (isBooleanConstantAndTrue('mxchange_installed'))
                        {
                        case "NORMAL":
                                $result_mailid = SQL_QUERY_ESC("SELECT pool_id, userid, id FROM "._MYSQL_PREFIX."_user_stats WHERE id=%s LIMIT 1",
-                                array($url_mid), __FILE__, __LINE__);
+                                       array($url_mid), __FILE__, __LINE__);
                                break;
 
                        case "BONUS":
                                $result_mailid = SQL_QUERY_ESC("SELECT id, id, is_notify FROM "._MYSQL_PREFIX."_bonus WHERE id=%s LIMIT 1",
-                                array($url_bid), __FILE__, __LINE__);
+                                       array($url_bid), __FILE__, __LINE__);
                                break;
                        }
-                       if (SQL_NUMROWS($result_mailid) == 1)
-                       {
+
+                       // Entry found?
+                       if (SQL_NUMROWS($result_mailid) == 1) {
+                               // Load data
                                list($pool, $sender, $notify) = SQL_FETCHROW($result_mailid);
 
                                // Correct notification switch in non-bonus mails
@@ -109,33 +107,34 @@ if (isBooleanConstantAndTrue('mxchange_installed'))
                                if ($ltype == "BONUS") $sender = 0;
 
                                // Is the user's ID unlocked?
-                               $result = SQL_QUERY_ESC("SELECT status, gender, surname, family, ref_payout FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
-                                array($url_uid), __FILE__, __LINE__);
-                               if (SQL_NUMROWS($result) == 1)
-                               {
+                               $result = SQL_QUERY_ESC("SELECT status, gender, surname, family, ref_payout FROM `"._MYSQL_PREFIX."_user_data` WHERE userid=%s LIMIT 1",
+                                       array($url_uid), __FILE__, __LINE__);
+                               if (SQL_NUMROWS($result) == 1) {
                                        // Load data
                                        list($status, $gender, $sname, $fname, $ref_pay) = SQL_FETCHROW($result);
+
+                                       // Free some memory
                                        SQL_FREERESULT($result);
 
-                                       if ($status == "CONFIRMED")
-                                       {
+                                       if ($status == "CONFIRMED") {
                                                // Update last activity
-                                               $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET last_online=UNIX_TIMESTAMP(), last_module='mailid_top' WHERE userid=%s LIMIT 1",
-                                                array($url_uid), __FILE__, __LINE__);
+                                               SQL_QUERY_ESC("UPDATE `"._MYSQL_PREFIX."_user_data` SET last_online=UNIX_TIMESTAMP(), last_module='mailid_top' WHERE userid=%s LIMIT 1",
+                                                       array($url_uid), __FILE__, __LINE__);
 
                                                // User has confirmed his account so we can procede...
                                                switch ($ltype)
                                                {
                                                case "NORMAL":
                                                        $result = SQL_QUERY_ESC("SELECT payment_id FROM "._MYSQL_PREFIX."_user_stats WHERE pool_id=%s LIMIT 1",
-                                                        array(bigintval($pool)), __FILE__, __LINE__);
-                                                       if (SQL_NUMROWS($result) == 1)
-                                                       {
+                                                               array(bigintval($pool)), __FILE__, __LINE__);
+
+                                                       // Entry found?
+                                                       if (SQL_NUMROWS($result) == 1) {
                                                                list($pay) = SQL_FETCHROW($result);
                                                                $time      = GET_PAY_POINTS($pay, "time");
                                                                $payment   = GET_PAY_POINTS($pay, "payment");
                                                                $VALID     = true;
-                                                       }
+                                                       } // END - if
 
                                                        // Free memory...
                                                        SQL_FREERESULT($result);
@@ -143,9 +142,10 @@ if (isBooleanConstantAndTrue('mxchange_installed'))
 
                                                case "BONUS":
                                                        $result = SQL_QUERY_ESC("SELECT time, points FROM "._MYSQL_PREFIX."_bonus WHERE id=%s LIMIT 1",
-                                                        array(bigintval($pool)), __FILE__, __LINE__);
-                                                       if (SQL_NUMROWS($result) == 1)
-                                                       {
+                                                               array(bigintval($pool)), __FILE__, __LINE__);
+
+                                                       // Entry found?
+                                                       if (SQL_NUMROWS($result) == 1) {
                                                                list($time, $payment) = SQL_FETCHROW($result);
                                                                $VALID = true;
                                                        }
@@ -154,19 +154,17 @@ if (isBooleanConstantAndTrue('mxchange_installed'))
                                                        SQL_FREERESULT($result);
                                                        break;
                                                }
-                                               if ($VALID)
-                                               {
+
+                                               // Is this entry valid?
+                                               if ($VALID) {
                                                        if (($time == "0") && ($payment > 0)) $time = "1";
-                                                       if (($time > 0) && ($payment > 0))
-                                                       {
-                                                               if (!empty($code))
-                                                               {
+                                                       if (($time > 0) && ($payment > 0)) {
+                                                               if (!empty($code)) {
                                                                        // Generate code
-                                                                       $img_code = GEN_RANDOM_CODE($_CONFIG['code_length'], $code, $url_uid, $DATA);
-                                                               }
+                                                                       $img_code = GEN_RANDOM_CODE(getConfig('code_length'), $code, $url_uid, $DATA);
+                                                               } // END - if
 
-                                                               switch ($mode)
-                                                               {
+                                                               switch ($mode) {
                                                                case "add":
                                                                        // Init stats data
                                                                        $stats_data = 0;
@@ -175,8 +173,8 @@ if (isBooleanConstantAndTrue('mxchange_installed'))
                                                                        switch ($ltype)
                                                                        {
                                                                        case "NORMAL":
-                                                                               $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_stats SET clicks=clicks + 1 WHERE id=%s LIMIT 1",
-                                                                                array($url_mid), __FILE__, __LINE__);
+                                                                               SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_stats SET clicks=clicks + 1 WHERE id=%s LIMIT 1",
+                                                                                       array($url_mid), __FILE__, __LINE__);
 
                                                                                // Update mediadata as well
                                                                                if (GET_EXT_VERSION("mediadata") >= "0.0.4") {
@@ -187,8 +185,8 @@ if (isBooleanConstantAndTrue('mxchange_installed'))
                                                                                break;
 
                                                                        case "BONUS":
-                                                                               $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_bonus SET clicks=clicks + 1 WHERE id=%s LIMIT 1",
-                                                                                array($url_bid), __FILE__, __LINE__);
+                                                                               SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_bonus SET clicks=clicks + 1 WHERE id=%s LIMIT 1",
+                                                                                       array($url_bid), __FILE__, __LINE__);
 
                                                                                // Update mediadata as well
                                                                                if (GET_EXT_VERSION("mediadata") >= "0.0.4") {
@@ -206,13 +204,13 @@ if (isBooleanConstantAndTrue('mxchange_installed'))
                                                                        // Only when user extension = v0.1.2: Update mails-confirmed counter
                                                                        if (GET_EXT_VERSION("user") >= "0.1.2") {
                                                                                // Update counter
-                                                                               SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET mails_confirmed=mails_confirmed + 1 WHERE userid=%s LIMIT 1",
+                                                                               SQL_QUERY_ESC("UPDATE `"._MYSQL_PREFIX."_user_data` SET mails_confirmed=mails_confirmed + 1 WHERE userid=%s LIMIT 1",
                                                                                        array($url_uid), __FILE__, __LINE__);
 
                                                                                // Update random confirmed as well?
                                                                                if (GET_EXT_VERSION("user") >= "0.3.4") {
                                                                                        // Update second counter
-                                                                                       SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET rand_confirmed=rand_confirmed + 1 WHERE userid=%s LIMIT 1",
+                                                                                       SQL_QUERY_ESC("UPDATE `"._MYSQL_PREFIX."_user_data` SET rand_confirmed=rand_confirmed + 1 WHERE userid=%s LIMIT 1",
                                                                                                array($url_uid), __FILE__, __LINE__);
                                                                                } // END - if
                                                                        } // END - if
@@ -227,26 +225,26 @@ if (isBooleanConstantAndTrue('mxchange_installed'))
                                                                                $template = "mailid_points_done";
 
                                                                                // Right code entered add points and remove entry
-                                                                               if (($ref_pay > 0) && ($_CONFIG['allow_direct_pay'] == "N")) {
+                                                                               if (($ref_pay > 0) && (getConfig('allow_direct_pay') == "N")) {
                                                                                        // Don't add points over the referal system
                                                                                        $locked = true;
                                                                                        $template = "mailid_points_locked";
                                                                                } // END - if
 
                                                                                // Count down ref_payout value
-                                                                               $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET ref_payout=ref_payout-1 WHERE userid=%s AND ref_payout > 0 LIMIT 1",
+                                                                               SQL_QUERY_ESC("UPDATE `"._MYSQL_PREFIX."_user_data` SET ref_payout=ref_payout-1 WHERE userid=%s AND ref_payout > 0 LIMIT 1",
                                                                                        array($url_uid), __FILE__, __LINE__);
 
                                                                                // Add points
-                                                                               unset($DEPTH);
+                                                                               unset($GLOBALS['ref_level']);
                                                                                ADD_POINTS_REFSYSTEM("mailid_okay", $url_uid, $payment, false, "0", $locked);
 
                                                                                // Shall I add bonus points for "turbo clickers" ?
                                                                                if ((GET_EXT_VERSION("bonus") >= "0.2.2") && (function_exists('BONUS_ADD_TURBO_POINTS'))) {
                                                                                        // Is an active-rallye running and this is not a notification mail?
-                                                                                       if (($_CONFIG['bonus_active'] == "Y") && ($notify == "N")) {
+                                                                                       if ((getConfig('bonus_active') == "Y") && ($notify == "N")) {
                                                                                                // Shall I exclude the webmaster's own userid from the active-rallye?
-                                                                                               if (((($_CONFIG['bonus_uid'] == $url_uid) && ($_CONFIG['bonus_include_own'] == "Y")) || ($_CONFIG['bonus_uid'] != $url_uid)) && ($_CONFIG['def_refid'] != $url_uid)) {
+                                                                                               if ((((getConfig('bonus_uid') == $url_uid) && (getConfig('bonus_include_own') == "Y")) || (getConfig('bonus_uid') != $url_uid)) && (getConfig('def_refid') != $url_uid)) {
                                                                                                        // Add points and remember ranking are done in this function....
                                                                                                        BONUS_ADD_TURBO_POINTS($DATA, $url_uid, $type);
 
@@ -270,7 +268,7 @@ if (isBooleanConstantAndTrue('mxchange_installed'))
                                                                                LOAD_TEMPLATE($template);
                                                                        } else {
                                                                                // Wrong image code! So add points to sender's account
-                                                                               unset($DEPTH);
+                                                                               unset($GLOBALS['ref_level']);
                                                                                ADD_POINTS_REFSYSTEM("mailid_payback", $sender, $payment, false, 0, false, "direct");
 
                                                                                // Load template
@@ -278,7 +276,7 @@ if (isBooleanConstantAndTrue('mxchange_installed'))
                                                                        }
 
                                                                        // Remove link from table
-                                                                       $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_links WHERE id=%s LIMIT 1",
+                                                                       SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_links WHERE id=%s LIMIT 1",
                                                                                array(bigintval($lid)), __FILE__, __LINE__);
                                                                        break;
 
@@ -295,7 +293,7 @@ if (isBooleanConstantAndTrue('mxchange_installed'))
                                                                                define('_TYPE_VALUE', $type);
                                                                                define('_DATA_VALUE', $DATA);
                                                                                define('_TEMPLATE_BANNER', LOAD_TEMPLATE("mailid_banner", true));
-                                                                               if ($_CONFIG['code_length'] > 0)
+                                                                               if (getConfig('code_length') > 0)
                                                                                {
                                                                                        // Generate Code
                                                                                        define('_IMAGE_CODE', IMG_CODE($code, $type, $DATA, $url_uid));
@@ -334,33 +332,26 @@ if (isBooleanConstantAndTrue('mxchange_installed'))
                                                 else OUTPUT_HTML("<STRONG class=\"member_failed\">".MAIL_ALREADY_CONFIRMED." (5)</STRONG>");
                                        }
                                         else OUTPUT_HTML("<STRONG class=\"member_failed\">".MAIL_ALREADY_CONFIRMED." (4)</STRONG>");
-                               }
-                                else
-                               {
+                               } else {
                                        SQL_FREERESULT($result);
                                        OUTPUT_HTML("<STRONG class=\"member_failed\">".MAIL_ALREADY_CONFIRMED." (3)</STRONG>");
                                }
-                       }
-                        else
-                       {
+                       } else {
                                SQL_FREERESULT($result);
                                OUTPUT_HTML("<STRONG class=\"member_failed\">".MAIL_ALREADY_CONFIRMED." (2)</STRONG>");
                        }
-               }
-                else
-               {
+               } else {
                        SQL_FREERESULT($result);
                        OUTPUT_HTML("<STRONG class=\"member_failed\">".MAIL_ALREADY_CONFIRMED." (1)</STRONG>");
                }
-               if ($mode != "img")
-               {
+
+               // Insert footer if no image
+               if ($mode != "img") {
                        // Write footer
                        require_once(PATH."inc/footer.php");
-               }
+               } // END - if
        }
-}
- elseif ($mode != "img")
-{
+} elseif ($mode != "img") {
        // You have to configure first!
        LOAD_URL("install.php");
 }