A lot while() conditions rewritten to SQL_FETCHARRAY(), see bug #107, @TODO tags...
[mailer.git] / inc / libs / refback_functions.php
index 6f45e93..d08c83b 100644 (file)
@@ -47,16 +47,17 @@ function ADD_REFBACK_POINTS ($uid, $ref, $points, $ref_points) {
        $return = $points;
 
        // Get all ref levels
-       $result_refs = SQL_QUERY("SELECT level, percents FROM `{!_MYSQL_PREFIX!}_refdepths` WHERE level > 0 ORDER BY level ASC", __FUNCTION__, __LINE__);
+       $result_refs = SQL_QUERY("SELECT level, percents FROM `{!_MYSQL_PREFIX!}_refdepths` WHERE level > 0 ORDER BY level ASC",
+               __FUNCTION__, __LINE__);
 
        // "Walk" through all level
-       while (list($level, $perc) = SQL_FETCHROW($result_refs)) {
+       while ($content = SQL_FETCHARRAY($result_refs)) {
                // Reset ref depths
                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";
-               foreach (GET_REFBACK_USERID_ARRAY($uid, $level) as $refid) {
+               //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},ref={$ref},level={$content['level']},points={$points}<br />\n";
+               foreach (GET_REFBACK_USERID_ARRAY($uid, $content['level']) as $refid) {
                        // Skip level zero or if both are the same
                        if ($uid == $refid) continue;
 
@@ -66,9 +67,9 @@ function ADD_REFBACK_POINTS ($uid, $ref, $points, $ref_points) {
 
                        // Some percents given?
                        if ($percents > 0) {
-                               //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):points={$points},perc={$perc},percents={$percents},level={$level}<br />\n";
+                               //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):points={$points},perc={$content['percents']},percents={$percents},level={$content['level']}<br />\n";
                                // Calculate points for refback
-                               $refback = $points * ($perc / 100) * ($percents / 100);
+                               $refback = $points * ($content['percents'] / 100) * ($percents / 100);
 
                                // Update refback table ("refid" and "uid" must be exchanged!)
                                SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_refs` SET points=points+%s WHERE userid=%s AND refid=%s LIMIT 1",
@@ -82,7 +83,7 @@ function ADD_REFBACK_POINTS ($uid, $ref, $points, $ref_points) {
                                // Reduce points if refid is found
                                if ($refid == $ref) {
                                        // Reduce¬†points here!
-                                       $return = $points * ($perc / 100) - $refback;
+                                       $return = $points * ($content['percents'] / 100) - $refback;
                                        //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):points={$return} - REDUCED<br />\n";
                                } // END - if
                        } // END - if
@@ -151,9 +152,9 @@ ORDER BY userid ASC",
        //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):numRows=".SQL_NUMROWS($result)."<br />\n";
        if (SQL_NUMROWS($result) > 0) {
                // Add all
-               while (list($userid) = SQL_FETCHROW($result)) {
-                       //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):rid={$rid},level={$level},userid={$userid}<br />\n";
-                       $userIds[] = $userid;
+               while ($content = SQL_FETCHARRAY($result)) {
+                       //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):rid={$rid},level={$level},userid={$content['userid']}<br />\n";
+                       $userIds[] = $content['userid'];
                } // END - while
        } // END - if
 
@@ -167,7 +168,7 @@ ORDER BY userid ASC",
 }
 
 // Update "refback table"
-function UPDATE_REFBACK_TABLE($uid) {
+function UPDATE_REFBACK_TABLE ($uid) {
        //* DEBUG: */ print "----------------------- <font color=\"#00aa00\">".__FUNCTION__." - ENTRY</font> ------------------------<ul><li>\n";
        // Make it sure referal level zero (member him-/herself) is at least selected
        if (empty($GLOBALS['cache_array']['back_level'])) $GLOBALS['cache_array']['back_level'] = 1;