Refback will be payed now (user cannot setup currently)
[mailer.git] / inc / modules / admin / what-list_refs.php
index 3ecc0c7..83b1760 100644 (file)
  ************************************************************************/
 
 // Some security stuff...
-if ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!IS_ADMIN()))
-{
-        $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
-        require($INC);
+if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
+       $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
+       require($INC);
 }
 
 // Add description as navigation point
 ADD_DESCR("admin", basename(__FILE__));
 
-OPEN_TABLE("100%", "admin_content admin_content_align", "");
-if (!empty($_GET['u_id']))
-{
+if (!empty($_GET['u_id'])) {
        // Check if the user already exists
-       $result = SQL_QUERY_ESC("SELECT userid FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d LIMIT 1",
+       $result = SQL_QUERY_ESC("SELECT userid FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
         array(bigintval($_GET['u_id'])), __FILE__, __LINE__);
-       if (SQL_NUMROWS($result) == 1)
-       {
-               // Free memory
-               SQL_FREERESULT($result);
+       if (SQL_NUMROWS($result) == 1) {
+               // Load all referal levels
+               $result_levels = SQL_QUERY_ESC("SELECT d.level, d.percents, r.counter
+FROM "._MYSQL_PREFIX."_refdepths AS d
+LEFT JOIN "._MYSQL_PREFIX."_refsystem AS r
+ON d.level=r.level
+WHERE r.userid=%s
+ORDER BY d.level ASC",
+                       array(bigintval($_GET['u_id'])), __FILE__, __LINE__);
 
-               // Loads surname, family's name and the email address
-               $result     = SQL_QUERY_ESC("SELECT COUNT(*) FROM "._MYSQL_PREFIX."_user_data WHERE refid=%d",
-                array(bigintval($_GET['u_id'])), __FILE__, __LINE__);
-               $result_lck = SQL_QUERY_ESC("SELECT COUNT(*) FROM "._MYSQL_PREFIX."_user_data WHERE refid=%d AND status != 'CONFIRMED' ORDER BY userid",
-                array(bigintval($_GET['u_id'])), __FILE__, __LINE__);
-               $menge      = SQL_RESULT($result    , 0, 0);
-               $menge_lck  = SQL_RESULT($result_lck, 0, 0);
+               // Are there some levels (VERY BAD IF NONE!)
+               if (SQL_NUMROWS($result_levels) > 0) {
+                       // List all ref levels
+                       $OUT = ""; $SW = 2;
+                       while ($levels = SQL_FETCHARRAY($result_levels)) {
+                               // Insert more data
+                               $levels['sw']    = $SW;
+                               $levels['level'] = ($levels['level'] + 1);
 
-               // Free memory
-               SQL_FREERESULT($result);
-               SQL_FREERESULT($result_lck);
+                               // Load all refs of this user
+                               //$result_refs = SQL_QUERY_ESC("SELECT 
+                               // Load level template
+                               $OUT .= LOAD_TEMPLATE("admin_list_refs_level", true, $levels);
 
-               $result = SQL_QUERY_ESC("SELECT userid, sex, surname, family, email, status, joined FROM "._MYSQL_PREFIX."_user_data WHERE refid=%d ORDER BY userid",
-                array(bigintval($_GET['u_id'])), __FILE__, __LINE__);
+                               // Switch colors
+                               $SW = 3 - $SW;
+                       } // END - if
 
-               OUTPUT_HTML(ADMIN_TOTAL_REFS_1."".ADMIN_USER_PROFILE_LINK($_GET['u_id'])."".ADMIN_TOTAL_REFS_2.$menge.ADMIN_TOTAL_REFS_3.$menge_lck.ADMIN_TOTAL_REFS_4."<BR><BR>");
-               if ($result)
-               {
-                       $rows = SQL_NUMROWS($result);
-                       if ($rows > 0)
-                       {
-                               // Load all referrals
-                               $SW = "2"; $OUT = "";
-                               while ($row = SQL_FETCHROW($result))
-                               {
-                                       // Check for referrals
-                                       $result_refs = SQL_QUERY_ESC("SELECT COUNT(userid) FROM "._MYSQL_PREFIX."_user_data WHERE refid=%d",
-                                        array(bigintval($row[0])), __FILE__, __LINE__);
-                                       $refs_cnt = SQL_RESULT($result_refs, 0, 0);
-                                       SQL_FREERESULT($result_refs);
+                       // Prepare content
+                       $content = array(
+                               'rows' => $OUT,
+                               'uid'  => ADMIN_USER_PROFILE_LINK($_GET['u_id'])
+                       );
 
-                                       // Prepare data for the template
-                                       $content = array(
-                                               'sw'         => $SW,
-                                               'u_link'     => ADMIN_USER_PROFILE_LINK($row[0]),
-                                               'salut'      => TRANSLATE_SEX($row[1]),
-                                               'refs_link'  => "0",
-                                               'surname'    => $row[2],
-                                               'family'     => $row[3],
-                                               'email'      => "<A href=\"".CREATE_EMAIL_LINK($row[4], "user_data")."\">".$row[4]."</A>",
-                                               'status'     => TRANSLATE_STATUS($row[5]),
-                                               'registered' => MAKE_DATETIME($row[6], "3"),
-                                       );
-
-                                       // Check if referral count is larger 0 and update link
-                                       if ($refs_cnt > 0) $content['refs_link'] = ADMIN_USER_PROFILE_LINK($row[0], $refs_cnt, "list_refs");
-
-                                       // Load row template and switch color
-                                       $OUT .= LOAD_TEMPLATE("admin_list_refs_row", true, $content);
-                                       $SW = 3 - $SW;
-                               }
-
-                               // Free memory
-                               SQL_FREERESULT($result);
-                               define('__REF_ROWS', $OUT);
-
-                               // Load main template
-                               LOAD_TEMPLATE("admin_list_refs");
-                       }
-               }
-                else
-               {
-                       // No referrals made so far
-                       LOAD_TEMPLATE("admin_settings_saved", false, USER_REF_404);
+                       // Load mein template
+                       LOAD_TEMPLATE("admin_list_refs", false, $content);
+               } else {
+                       // No levels found, very bad!
+                       LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_NO_REF_LEVELS);
                }
-       }
-        else
-       {
+
+               // Free result
+               SQL_FREERESULT($result_levels);
+       } else {
                // User not found
-               LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_MEMBER_404_1.$_GET['u_id'].ADMIN_MEMBER_404_2);
+               LOAD_TEMPLATE("admin_settings_saved", false, sprintf(ADMIN_MEMBER_404, $_GET['u_id']));
        }
-}
- else
-{
+
+       // Free memory
+       SQL_FREERESULT($result);
+} else {
        // Output selection form with all confirmed user accounts listed
        ADD_MEMBER_SELECTION_BOX();
 }
-CLOSE_TABLE();
 
 //
 ?>