-ADD_DESCR("admin", basename(__FILE__));
-
-OPEN_TABLE("100%", "admin_content admin_content_align", "");
-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",
- array(bigintval($_GET['u_id'])), __FILE__, __LINE__);
- if (SQL_NUMROWS($result) == 1)
- {
- // Free memory
- SQL_FREERESULT($result);
-
- // 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);
-
- // Free memory
- SQL_FREERESULT($result);
- SQL_FREERESULT($result_lck);
-
- $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__);
-
- 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);
+addYouAreHereLink('admin', __FILE__);
+
+if (isGetRequestParameterSet('userid')) {
+ // Secure userid
+ $userid = bigintval(getRequestParameter('userid'));
+
+ // Fix missing variable
+ $result_levels = false;
+
+ // User found?
+ if (fetchUserData($userid)) {
+ // Get total refs
+ $menge = countSumTotalData($userid, 'user_data', 'userid', 'refid', true);
+ $menge_lck = countSumTotalData($userid, 'user_data', 'userid', 'refid', true, " AND `status` != 'CONFIRMED'");
+
+ // Output info message
+ displayMessage(sprintf(getMessage('ADMIN_USER_TOTAL_REFS'), generateUserProfileLink(getRequestParameter('userid')), $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_HASZERONUMS($result_levels)) {
+ // List all ref levels or entries if no refback is installed
+ $OUT = '';
+ while ($levels = SQL_FETCHARRAY($result_levels)) {
+ // Is the refback still active? ;-)
+ if (isExtensionActive('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($userid, $levels['level']), __FILE__, __LINE__);
+ //* DEBUG: */ debugOutput($userid.'/'.$levels['level'].'/'.SQL_NUMROWS($result_refs));
+
+ // Do we have levels?
+ if (!SQL_HASZERONUMS($result_refs)) {
+ // Count entries
+ $menge = countSumTotalData($userid, 'user_data', 'userid', 'refid', true);
+ $menge_lck = countSumTotalData($userid, 'user_data', 'userid', 'refid', true, " AND `status` != 'CONFIRMED'");
+
+ // Output info message
+ $levels['info'] = sprintf(getMessage('ADMIN_USER_TOTAL_REFS'), generateUserProfileLink($userid), $menge, $menge_lck);
+
+ // Init variables
+ $OUT_REFS = '';
+
+ // Load all refs
+ while ($content = SQL_FETCHARRAY($result_refs)) {
+ // Is the data there?
+ if (fetchUserData($content['refid'])) {
+ // Check for referals
+ $refs_cnt = countSumTotalData(getUserData('userid'), 'user_refs', 'id', 'userid', true);
+
+ // Prepare data for the template
+ // @TODO Try to rewrite some to EL
+ $content = array(
+ 'userid' => getUserData('userid'),
+ 'gender' => getUserData('gender'),
+ 'refs_link' => 0,
+ 'surname' => getUserData('surname'),
+ 'family' => getUserData('family'),
+ 'email' => '[<a href="' . generateEmailLink(getUserData('email'), 'user_data') . '">' . getUserData('email') . '</a>]',
+ 'status' => getUserData('status'),
+ 'registered' => generateDateTime(getUserData('joined'), 3),
+ );
+
+ // Check if referal count is larger 0 and update link
+ if ($refs_cnt > 0) {
+ $content['refs_link'] = generateUserProfileLink(getUserData('userid'), $refs_cnt, 'list_refs');
+ } // END - if
+
+ // Load template for level one
+ $OUT_REFS .= loadTemplate('admin_list_refs_row', true, $content);
+ } else {
+ // No refs found
+ $OUT_REFS = loadTemplate('admin_list_refs_nodata', true, $content);
+ }
+
+ // Add content
+ $levels['rows'] = $OUT_REFS;
+ } // END - while
+ } else {
+ // Output info message
+ $levels['info'] = sprintf(getMessage('ADMIN_USER_TOTAL_REFS'), generateUserProfileLink($userid), 0, 0);
+
+ // No refs found
+ $levels['rows'] = loadTemplate('admin_list_refs_norefs', true, array('userid' => $userid));
+ }
+
+ // Free result