Variable rewritten to ['ref_level'] to avoid trouble with referal system
authorRoland Häder <roland@mxchange.org>
Fri, 19 Dec 2008 16:37:39 +0000 (16:37 +0000)
committerRoland Häder <roland@mxchange.org>
Fri, 19 Dec 2008 16:37:39 +0000 (16:37 +0000)
birthday_confirm.php
inc/databases.php
inc/libs/beg_functions.php
inc/libs/refback_functions.php
inc/modules/admin/admin-inc.php
inc/modules/admin/what-add_points.php
inc/modules/guest/what-confirm.php
inc/modules/member/what-wernis.php
inc/mysql-manager.php
mailid_top.php

index a29859a..69530f9 100644 (file)
@@ -79,12 +79,12 @@ WHERE b.userid=%s AND b.chk_value='%s' LIMIT 1",
                        if (($data['ref_payout'] > 0) && (getConfig('allow_direct_pay') == "N")) $locked = true;
 
                        // Add points to account
-                       unset($DEPTH);
+                       unset($GLOBALS['ref_level']);
                        ADD_POINTS_REFSYSTEM("birthday_confirm", $uid, $data['points'], false, "0", $locked, strtolower(getConfig('birthday_mode')));
 
                        // Remove entry from table
                        $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_birthday WHERE userid=%s AND chk_value='%s' LIMIT 1",
-                        array($uid, $chk), __FILE__, __LINE__);
+                               array($uid, $chk), __FILE__, __LINE__);
 
                        // Update mediadata if version is 0.0.4 or newer
                        if (GET_EXT_VERSION("mediadata") >= "0.0.4") {
index f0e384b..c348b3e 100644 (file)
@@ -115,7 +115,7 @@ define('USAGE_BASE', "usage");
 define('SERVER_URL', "http://www.mxchange.org");
 
 // Current SVN revision
-define('CURR_SVN_REVISION', "662");
+define('CURR_SVN_REVISION', "663");
 
 // Take a prime number which is long (if you know a longer one please try it out!)
 define('_PRIME', 591623);
index 04db570..7eeb420 100644 (file)
@@ -52,7 +52,7 @@ function BEG_ADD_POINTS ($uid, $points) {
                        array($points, $uid), __FILE__, __LINE__);
        } else {
                // Add points to account
-               unset($DEPTH);
+               unset($GLOBALS['ref_level']);
                ADD_POINTS_REFSYSTEM("beg", $uid, $points, false, "0", $locked, strtolower(getConfig('beg_mode')));
        }
 
index 85722cd..cd8d0fb 100644 (file)
@@ -40,10 +40,10 @@ if (!defined('__SECURITY')) {
 // Payback refback for refid and reduce it for current user
 function ADD_REFBACK_POINTS ($uid, $ref, $points, $ref_points) {
        //* DEBUG: */ print "----------------------- <font color=\"#00aa00\">".__FUNCTION__." - ENTRY</font> ------------------------<ul><li>\n";
-       global $DEPTH, $cacheArray;
+       global $cacheArray;
 
        // Back ref depths
-       $cacheArray['depth'][$uid][$ref] = $DEPTH
+       $cacheArray['depth'][$uid][$ref] = $GLOBALS['ref_level']
 
        // Init points
        $return = $points;
@@ -54,7 +54,7 @@ function ADD_REFBACK_POINTS ($uid, $ref, $points, $ref_points) {
        // "Walk" through all level
        while (list($level, $perc) = SQL_FETCHROW($result_refs)) {
                // Reset ref depths
-               unset($DEPTH);
+               unset($GLOBALS['ref_level']);
 
                // "Walk" through all refids
                //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},ref={$ref},level={$level},points={$points}<br />\n";
@@ -95,7 +95,7 @@ function ADD_REFBACK_POINTS ($uid, $ref, $points, $ref_points) {
        SQL_FREERESULT($result_refs);
 
        // Restore ref depth
-       $DEPTH = $cacheArray['depth'][$uid][$ref];
+       $GLOBALS['ref_level'] = $cacheArray['depth'][$uid][$ref];
 
        // Return them
        //* DEBUG: */ print "</li></ul>----------------------- <font color=\"#aa0000\">".__FUNCTION__." - EXIT</font> ------------------------<br />\n";
index 4937318..1c30a49 100644 (file)
@@ -303,7 +303,7 @@ function admin_WriteData ($file, $comment, $prefix, $suffix, $DATA, $seek=0) {
 
 //
 function ADMIN_DO_ACTION($wht) {
-       global $menuDesription, $menuTitle, $_CONFIG, $cacheArray, $DATA, $DEPTH;
+       global $menuDesription, $menuTitle, $_CONFIG, $cacheArray, $DATA;
 
        //* DEBUG: */ echo __LINE__."*".$wht."/".$GLOBALS['module']."/".$GLOBALS['action']."/".$GLOBALS['what']."*<br />\n";
        if (EXT_IS_ACTIVE("cache")) {
index 97c5c15..f96c1e1 100644 (file)
@@ -49,36 +49,24 @@ if ($_GET['u_id'] == "all") {
                define('__POINTS_VALUE', $_POST['points']);
                $result_main = SQL_QUERY("SELECT userid FROM `"._MYSQL_PREFIX."_user_data` WHERE status='CONFIRMED' ORDER BY userid", __FILE__, __LINE__);
                while (list($uid) = SQL_FETCHROW($result_main)) {
-                       // User ID found in URL so we use this give him some credits
-                       $result = SQL_QUERY_ESC("SELECT surname, family, email FROM `"._MYSQL_PREFIX."_user_data` WHERE userid=%s AND status='CONFIRMED' LIMIT 1",
-                               array(bigintval($uid)), __FILE__, __LINE__);
-                       if (SQL_NUMROWS($result) == 1) {
-                               // Selected user does exist
-                               list($sname, $fname, $email) = SQL_FETCHROW($result);
-                               SQL_FREERESULT($result);
-
-                               if ((isset($_POST['ok'])) && (!empty($_POST['points']))) {
-                                       global $DEPTH;
-                                       // Remove depth to prevent booking errors. This is a bad coding
-                                       // practice, thats also why we need to write this project from
-                                       // scratch...
-                                       unset($DEPTH);
+                       // Remove depth to prevent booking errors. This is a bad coding
+                       // practice, thats also why we need to write this project from
+                       // scratch...
+                       $GLOBALS['ref_level'] = -1;
 
-                                       // Ok, add points and send an email to him...
-                                       ADD_POINTS_REFSYSTEM("admin_all", $uid, bigintval($_POST['points']), false, "0", false, "direct");
+                       // Ok, add points and send an email to him...
+                       ADD_POINTS_REFSYSTEM("admin_all", $uid, bigintval($_POST['points']), false, "0", false, "direct");
 
-                                       // Prepare content
-                                       $content = array(
-                                               'text'   => SQL_ESCAPE($_POST['reason']),
-                                               'points' => bigintval($_POST['points'])
-                                       );
+                       // Prepare content
+                       $content = array(
+                               'text'   => SQL_ESCAPE($_POST['reason']),
+                               'points' => bigintval($_POST['points'])
+                       );
 
-                                       // Load email template and send email away
-                                       $msg = LOAD_EMAIL_TEMPLATE("add-points", $content, bigintval($uid));
-                                       SEND_EMAIL(bigintval($uid), ADMIN_ADD_SUBJ, $msg);
-                               }
-                       }
-               }
+                       // Load email template and send email away
+                       $msg = LOAD_EMAIL_TEMPLATE("add-points", $content, bigintval($uid));
+                       SEND_EMAIL(bigintval($uid), ADMIN_ADD_SUBJ, $msg);
+               } // END - while
 
                // Free memory
                SQL_FREERESULT($result_main);
@@ -99,11 +87,10 @@ if ($_GET['u_id'] == "all") {
                SQL_FREERESULT($result);
 
                if ((isset($_POST['ok'])) && (!empty($_POST['points']))) {
-                       global $DEPTH;
                        // Remove depth to prevent booking errors. This is a bad coding
                        // practice, thats also why we need to write this project from
                        // scratch...
-                       unset($DEPTH);
+                       unset($GLOBALS['ref_level']);
 
                        // Ok, add points and send an email to him...
                        ADD_POINTS_REFSYSTEM("admin_single", bigintval($_GET['u_id']), bigintval($_POST['points']), false, "0", false, "direct");
index 6f5a7cb..902efb8 100644 (file)
@@ -70,7 +70,7 @@ if (!empty($_GET['hash'])) {
                                        UPDATE_REF_COUNTER($rid);
 
                                        // Ok, write the ref-points to this user and his parent-ref
-                                       unset($DEPTH);
+                                       unset($GLOBALS['ref_level']);
 
                                        // Shall I "pay" the referal points imidiately?
                                        if (getConfig('ref_payout') == "0") {
@@ -92,7 +92,7 @@ if (!empty($_GET['hash'])) {
                                        } // END - if
 
                                        // Add one-time referal bonus over referal system or directly
-                                       unset($DEPTH);
+                                       unset($GLOBALS['ref_level']);
                                        ADD_POINTS_REFSYSTEM("referal_bonus", $rid, getConfig('points_ref'), true, bigintval($uid), $locked, getConfig('reg_points_mode'));
                                } // END - if
                        } // END - if
index ae45f45..1773a61 100644 (file)
@@ -231,7 +231,7 @@ if ((isset($_POST['ok'])) && (isset($_GET['mode']))) {
                                        $success = WERNIS_EXECUTE_WITHDRAW($_POST['wds66_id'], md5($_POST['wds66_password']), $_POST['amount']);
                                        if ($success) {
                                                // Add it to this amount
-                                               unset($DEPTH);
+                                               unset($GLOBALS['ref_level']);
                                                ADD_POINTS_REFSYSTEM("wernis_withdraw", $GLOBALS['userid'], bigintval($_POST['amount']), false, 0, false, "direct");
 
                                                // Update the user data as well..
index 4544a12..1f261f4 100644 (file)
@@ -1106,8 +1106,8 @@ function GET_REF_LEVEL_PERCENTS ($level) {
  *               for default value will cause no referal will get points ever!!!)
  */
 function ADD_POINTS_REFSYSTEM ($subject, $uid, $points, $send_notify=false, $rid="0", $locked=false, $add_mode="ref") {
-       //* DEBUG: */ print "----------------------- <font color=\"#00aa00\">".__FUNCTION__." - ENTRY</font> ------------------------<ul><li>\n";
-       global $DEPTH, $_CONFIG, $DATA, $cacheArray;
+       /* DEBUG: */ print "----------------------- <font color=\"#00aa00\">".__FUNCTION__." - ENTRY</font> ------------------------<ul><li>\n";
+       global $_CONFIG, $DATA, $cacheArray;
 
        // Convert mode to lower-case
        $add_mode = strtolower($add_mode);
@@ -1126,14 +1126,14 @@ function ADD_POINTS_REFSYSTEM ($subject, $uid, $points, $send_notify=false, $rid
        } // END - if
 
        // Count up referal depth
-       if (!isset($DEPTH)) {
+       if (!isset($GLOBALS['ref_level'])) {
                // Initialialize referal system
-               //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): Referal system initialized!<br />\n";
-               $DEPTH = 0;
+               /* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): Referal system initialized!<br />\n";
+               $GLOBALS['ref_level'] = 0;
        } else {
                // Increase referal level
-               $DEPTH++;
-               //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): Referal level increased. DEPTH={$DEPTH}<br />\n";
+               $GLOBALS['ref_level']++;
+               /* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): Referal level increased. DEPTH={$GLOBALS['ref_level']}<br />\n";
        }
 
        // Default is "normal" points
@@ -1146,39 +1146,39 @@ function ADD_POINTS_REFSYSTEM ($subject, $uid, $points, $send_notify=false, $rid
        $result_user = SQL_QUERY_ESC("SELECT refid, email FROM `"._MYSQL_PREFIX."_user_data` WHERE userid=%s AND status='CONFIRMED' LIMIT 1",
         array(bigintval($uid)), __FILE__, __LINE__);
 
-       //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},numRows=".SQL_NUMROWS($result_user).",points={$points}<br />\n";
+       /* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},numRows=".SQL_NUMROWS($result_user).",points={$points}<br />\n";
        if (SQL_NUMROWS($result_user) == 1) {
                // This is the user and his ref
                list($ref, $email) = SQL_FETCHROW($result_user);
                $cacheArray['add_uid'][$ref] = $uid;
 
                // Get percents
-               $per = GET_REF_LEVEL_PERCENTS($DEPTH);
-               //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},points={$points},depth={$DEPTH},per={$per},mode={$add_mode}<br />\n";
+               $per = GET_REF_LEVEL_PERCENTS($GLOBALS['ref_level']);
+               /* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},points={$points},depth={$GLOBALS['ref_level']},per={$per},mode={$add_mode}<br />\n";
 
                // Some percents found?
                if ($per > 0) {
                        // Calculate new points
-                       //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},points={$points},per={$per},depth={$DEPTH}<br />\n";
+                       /* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},points={$points},per={$per},depth={$GLOBALS['ref_level']}<br />\n";
                        $ref_points = $points * $per / 100;
 
                        // Pay refback here if level > 0 and in ref-mode
-                       if ((EXT_IS_ACTIVE("refback")) && ($DEPTH > 0) && ($per < 100) && ($add_mode == "ref") && (isset($cacheArray['add_uid'][$uid]))) {
-                               //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},data={$cacheArray['add_uid'][$uid]},ref_points={$ref_points},depth={$DEPTH} - BEFORE!<br />\n";
+                       if ((EXT_IS_ACTIVE("refback")) && ($GLOBALS['ref_level'] > 0) && ($per < 100) && ($add_mode == "ref") && (isset($cacheArray['add_uid'][$uid]))) {
+                               /* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},data={$cacheArray['add_uid'][$uid]},ref_points={$ref_points},depth={$GLOBALS['ref_level']} - BEFORE!<br />\n";
                                $ref_points = ADD_REFBACK_POINTS($cacheArray['add_uid'][$uid], $uid, $points, $ref_points);
-                               //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},data={$cacheArray['add_uid'][$uid]},ref_points={$ref_points},depth={$DEPTH} - AFTER!<br />\n";
+                               /* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},data={$cacheArray['add_uid'][$uid]},ref_points={$ref_points},depth={$GLOBALS['ref_level']} - AFTER!<br />\n";
                        } // END - if
 
                        // Update points...
                        SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_points SET %s=%s+%s WHERE userid=%s AND ref_depth='%s' LIMIT 1",
-                        array($data, $data, $ref_points, bigintval($uid), bigintval($DEPTH)), __FILE__, __LINE__);
-                       //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):data={$data},ref_points={$ref_points},uid={$uid},depth={$DEPTH},mode={$add_mode} - UPDATE! (".SQL_AFFECTEDROWS().")<br />\n";
+                        array($data, $data, $ref_points, bigintval($uid), bigintval($GLOBALS['ref_level'])), __FILE__, __LINE__);
+                       /* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):data={$data},ref_points={$ref_points},uid={$uid},depth={$GLOBALS['ref_level']},mode={$add_mode} - UPDATE! (".SQL_AFFECTEDROWS().")<br />\n";
 
                        // No entry updated?
                        if (SQL_AFFECTEDROWS() < 1) {
                                // First ref in this level! :-)
                                $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_user_points (userid,ref_depth,%s) VALUES (%s,%s,%s)",
-                                array($data, bigintval($uid), bigintval($DEPTH), $ref_points), __FILE__, __LINE__);
+                                array($data, bigintval($uid), bigintval($GLOBALS['ref_level']), $ref_points), __FILE__, __LINE__);
                        } // END - if
 
                        // Update mediadata as well
@@ -1192,7 +1192,7 @@ function ADD_POINTS_REFSYSTEM ($subject, $uid, $points, $send_notify=false, $rid
                                // Prepare content
                                $content = array(
                                        'percent' => $per,
-                                       'level'   => bigintval($DEPTH),
+                                       'level'   => bigintval($GLOBALS['ref_level']),
                                        'points'  => $ref_points,
                                        'refid'   => bigintval($ref)
                                );
@@ -1222,15 +1222,15 @@ function ADD_POINTS_REFSYSTEM ($subject, $uid, $points, $send_notify=false, $rid
                        // Maybe there's another ref?
                        if (($ref > 0) && ($points > 0) && ($ref != $uid) && ($add_mode == "ref")) {
                                // Then let's credit him here...
-                               //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},ref={$ref},points={$points} - ADVANCE!<br />\n";
-                               ADD_POINTS_REFSYSTEM(sprintf("%s_ref:%s", $subject, $DEPTH), $ref, $points, $send_notify, $ref, $locked);
+                               /* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},ref={$ref},points={$points} - ADVANCE!<br />\n";
+                               ADD_POINTS_REFSYSTEM(sprintf("%s_ref:%s", $subject, $GLOBALS['ref_level']), $ref, $points, $send_notify, $ref, $locked);
                        } // END - if
                } // END - if
        } // END - if
 
        // Free result
        SQL_FREERESULT($result_user);
-       //* DEBUG: */ print "</li></ul>----------------------- <font color=\"#aa0000\">".__FUNCTION__." - EXIT</font> ------------------------<br />\n";
+       /* DEBUG: */ print "</li></ul>----------------------- <font color=\"#aa0000\">".__FUNCTION__." - EXIT</font> ------------------------<br />\n";
 }
 //
 function UPDATE_REF_COUNTER ($uid) {
@@ -1562,7 +1562,7 @@ WHERE p.userid=%s", array(bigintval($uid)), __FILE__, __LINE__);
 }
 //
 function META_DESCRIPTION ($mod, $wht) {
-       global $_CONFIG, $DEPTH;
+       global $_CONFIG;
 
        // Exclude admin and member's area
        if (($mod != "admin") && ($mod != "login")) {
@@ -1574,7 +1574,7 @@ function META_DESCRIPTION ($mod, $wht) {
        } // END - if
 
        // Remove depth
-       unset($DEPTH);
+       unset($GLOBALS['ref_level']);
 }
 //
 function ADD_JACKPOT($points) {
index 344bed2..f95e1af 100644 (file)
@@ -236,7 +236,7 @@ if (isBooleanConstantAndTrue('mxchange_installed')) {
                                                                                        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" ?
@@ -268,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