More misc fixes and rewrites (sorry, lame description)
[mailer.git] / inc / modules / admin / what-list_refs.php
index 6f4155d..8bfb68f 100644 (file)
@@ -51,38 +51,30 @@ if (REQUEST_ISSET_GET('uid')) {
        $uid = bigintval(REQUEST_GET('uid'));
 
        // Check if the user already exists
-       $result_user = SQL_QUERY_ESC("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
-       array($uid), __FILE__, __LINE__);
+       $result_user = SQL_QUERY_ESC("SELECT `userid` FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `userid`=%s LIMIT 1",
+               array($uid), __FILE__, __LINE__);
+
+       // Fix missing variable
+       $result_levels = false;
 
        // User found?
        if (SQL_NUMROWS($result_user) == 1) {
-               // Is the refback extension installed?
-               if (EXT_IS_ACTIVE('refback')) {
-                       // Load all referal levels
-                       $result_levels = SQL_QUERY("SELECT level, percents
-FROM `{!_MYSQL_PREFIX!}_refdepths`
-WHERE level > 0
-ORDER BY level ASC", __FILE__, __LINE__);
-               } else {
-                       // Loads surname, family's name and the email address
-                       $result     = SQL_QUERY_ESC("SELECT COUNT(*) FROM `{!_MYSQL_PREFIX!}_user_data` WHERE refid=%s",
-                       array($uid), __FILE__, __LINE__);
-                       $result_lck = SQL_QUERY_ESC("SELECT COUNT(*) FROM `{!_MYSQL_PREFIX!}_user_data` WHERE refid=%s AND status != 'CONFIRMED' ORDER BY `userid` ASC",
-                       array($uid), __FILE__, __LINE__);
-                       $menge      = SQL_RESULT($result    , 0, 0);
-                       $menge_lck  = SQL_RESULT($result_lck, 0, 0);
-
-                       // Free memory
-                       SQL_FREERESULT($result);
-                       SQL_FREERESULT($result_lck);
-
-                       // Query for refs
-                       $result_levels = SQL_QUERY_ESC("SELECT userid, gender, surname, family, email, status, joined FROM `{!_MYSQL_PREFIX!}_user_data` WHERE refid=%s ORDER BY userid ASC",
-                       array($uid), __FILE__, __LINE__);
-
-                       // Output info message
-                       LOAD_TEMPLATE('admin_settings_saved', false, sprintf(getMessage('ADMIN_USER_TOTAL_REFS'), generateUserProfileLink(REQUEST_GET('uid')), $menge, $menge_lck));
-               }
+               // Get total refs
+               $menge =     GET_TOTAL_DATA($uid, 'user_data', 'userid', 'refid', true);
+               $menge_lck = GET_TOTAL_DATA($uid, 'user_data', 'userid', 'refid', true, " AND `status` != 'CONFIRMED'");
+
+               // Output info message
+               LOAD_TEMPLATE('admin_settings_saved', false, sprintf(getMessage('ADMIN_USER_TOTAL_REFS'), generateUserProfileLink(REQUEST_GET('uid')), $menge, $menge_lck));
+
+               // Load all referal levels
+               $result_levels = SQL_QUERY("SELECT
+       `level`, `percents`
+FROM
+       `{!_MYSQL_PREFIX!}_refdepths`
+WHERE
+       `level` > 0
+ORDER BY
+       `level` ASC", __FILE__, __LINE__);
 
                // Are there some levels (VERY BAD IF NONE!)
                if (SQL_NUMROWS($result_levels) > 0) {
@@ -95,23 +87,15 @@ ORDER BY level ASC", __FILE__, __LINE__);
                                // Is the refback still active? ;-)
                                if (EXT_IS_ACTIVE('refback')) {
                                        // Load all refs of this user
-                                       $result_refs = SQL_QUERY_ESC("SELECT refid FROM `{!_MYSQL_PREFIX!}_user_refs` WHERE userid=%s AND level='%s' ORDER BY refid ASC",
-                                       array($uid, $levels['level']), __FILE__, __LINE__);
+                                       $result_refs = SQL_QUERY_ESC("SELECT `refid` FROM `{!_MYSQL_PREFIX!}_user_refs` WHERE `userid`=%s AND `level`='%s' ORDER BY refid ASC",
+                                               array($uid, $levels['level']), __FILE__, __LINE__);
                                        //* DEBUG: */ echo $uid.'/'.$levels['level'].'/'.SQL_NUMROWS($result_refs)."<br />\n";
 
                                        // Do we have levels?
                                        if (SQL_NUMROWS($result_refs) > 0) {
-                                               // Loads surname, family's name and the email address
-                                               $result     = SQL_QUERY_ESC("SELECT COUNT(*) FROM `{!_MYSQL_PREFIX!}_user_data` WHERE refid=%s",
-                                               array($uid), __FILE__, __LINE__);
-                                               $result_lck = SQL_QUERY_ESC("SELECT COUNT(*) FROM `{!_MYSQL_PREFIX!}_user_data` WHERE refid=%s AND status != 'CONFIRMED' ORDER BY `userid` ASC",
-                                               array($uid), __FILE__, __LINE__);
-                                               $menge      = SQL_RESULT($result    , 0, 0);
-                                               $menge_lck  = SQL_RESULT($result_lck, 0, 0);
-
-                                               // Free memory
-                                               SQL_FREERESULT($result);
-                                               SQL_FREERESULT($result_lck);
+                                               // Count entries
+                                               $menge =     GET_TOTAL_DATA($uid, 'user_data', 'userid', 'refid', true);
+                                               $menge_lck = GET_TOTAL_DATA($uid, 'user_data', 'userid', 'refid', true, " AND `status` != 'CONFIRMED'");
 
                                                // Output info message
                                                $levels['info'] = sprintf(getMessage('ADMIN_USER_TOTAL_REFS'), generateUserProfileLink($uid), $menge, $menge_lck);
@@ -122,8 +106,8 @@ ORDER BY level ASC", __FILE__, __LINE__);
                                                // Load all refs
                                                while ($content = SQL_FETCHARRAY($result_refs)) {
                                                        // Query for data
-                                                       $result_user = SQL_QUERY_ESC("SELECT userid, gender, surname, family, email, status, joined FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
-                                                       array($content['refid']), __FILE__, __LINE__);
+                                                       $result_user = SQL_QUERY_ESC("SELECT `userid`, `gender`, `surname`, `family`, `email`, `status`, `joined` FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `userid`=%s LIMIT 1",
+                                                               array($content['refid']), __FILE__, __LINE__);
 
                                                        // Is the data there?
                                                        if (SQL_NUMROWS($result_user) == 1) {
@@ -131,14 +115,7 @@ ORDER BY level ASC", __FILE__, __LINE__);
                                                                $data = SQL_FETCHARRAY($result_user);
 
                                                                // Check for referals
-                                                               $result_cnt = SQL_QUERY_ESC("SELECT COUNT(userid) FROM `{!_MYSQL_PREFIX!}_user_data` WHERE refid=%s",
-                                                               array($content['refid']), __FILE__, __LINE__);
-
-                                                               // Load refs
-                                                               $refs_cnt = SQL_RESULT($result_cnt, 0, 0);
-
-                                                               // Free result
-                                                               SQL_FREERESULT($result_cnt);
+                                                               $refs_cnt = GET_TOTAL_DATA($data['userid'], 'refsystem', 'counter');
 
                                                                // Prepare data for the template
                                                                $content = array(
@@ -157,10 +134,10 @@ ORDER BY level ASC", __FILE__, __LINE__);
                                                                if ($refs_cnt > 0) $content['refs_link'] = generateUserProfileLink($data['userid'], $refs_cnt, "list_refs");
 
                                                                // Load template for level one
-                                                               $OUT_REFS .= LOAD_TEMPLATE("admin_list_refs_row", true, $content);
+                                                               $OUT_REFS .= LOAD_TEMPLATE('admin_list_refs_row', true, $content);
                                                        } else {
                                                                // No refs found
-                                                               $OUT_REFS = LOAD_TEMPLATE("admin_list_refs_nodata", true, $content['refid']);
+                                                               $OUT_REFS = LOAD_TEMPLATE('admin_list_refs_nodata', true, $content['refid']);
                                                        }
 
                                                        // Free result
@@ -177,20 +154,17 @@ ORDER BY level ASC", __FILE__, __LINE__);
                                                $levels['info'] = sprintf(getMessage('ADMIN_USER_TOTAL_REFS'), generateUserProfileLink($uid), '0', '0');
 
                                                // No refs found
-                                               $levels['rows'] = LOAD_TEMPLATE("admin_list_refs_norefs", true, array('uid' => $uid));
+                                               $levels['rows'] = LOAD_TEMPLATE('admin_list_refs_norefs', true, array('uid' => $uid));
                                        }
 
                                        // Free result
                                        SQL_FREERESULT($result_refs);
 
                                        // Load level template
-                                       $OUT .= LOAD_TEMPLATE("admin_list_refs_level", true, $levels);
+                                       $OUT .= LOAD_TEMPLATE('admin_list_refs_level', true, $levels);
                                } else {
                                        // Check for referals
-                                       $result_refs = SQL_QUERY_ESC("SELECT COUNT(userid) FROM `{!_MYSQL_PREFIX!}_user_data` WHERE refid=%s",
-                                       array(bigintval($levels['userid'])), __FILE__, __LINE__);
-                                       $refs_cnt = SQL_RESULT($result_refs, 0, 0);
-                                       SQL_FREERESULT($result_refs);
+                                       $refs_cnt = GET_TOTAL_DATA($levels['userid'], 'user_data', 'userid', 'refid', true);
 
                                        // Prepare data for the template
                                        $content = array(
@@ -250,5 +224,5 @@ ORDER BY level ASC", __FILE__, __LINE__);
        ADD_MEMBER_SELECTION_BOX();
 }
 
-//
+// [EOF]
 ?>