New function fetchUserData() introduced to API, total rewrite (not all)
[mailer.git] / inc / modules / admin / what-list_refs.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 01/28/2004 *
4  * ================                             Last change: 06/10/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-list_refs.php                               *
8  * -------------------------------------------------------------------- *
9  * Short description : Show all referals made by a member               *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Alle generierten Refs eines Mitgliedes anzeigen  *
12  * -------------------------------------------------------------------- *
13  *                                                                      *
14  *    Mod created by : Lars Moehlenbruch ( http://www.surfo.net )       *
15  *                                                                      *
16  * -------------------------------------------------------------------- *
17  *                                                                      *
18  *                 Highly modified by Roland Haeder                     *
19  *                                                                      *
20  * -------------------------------------------------------------------- *
21  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if ((!defined('__SECURITY')) || (!isAdmin())) {
42         die();
43 } // END - if
44
45 // Add description as navigation point
46 addMenuDescription('admin', __FILE__);
47
48 if (isGetRequestElementSet('userid')) {
49         // Secure userid
50         $userid = bigintval(getRequestElement('userid'));
51
52         // Fix missing variable
53         $result_levels = false;
54
55         // User found?
56         if (fetchUserData($userid)) {
57                 // Get total refs
58                 $menge =     countSumTotalData($userid, 'user_data', 'userid', 'refid', true);
59                 $menge_lck = countSumTotalData($userid, 'user_data', 'userid', 'refid', true, " AND `status` != 'CONFIRMED'");
60
61                 // Output info message
62                 loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_USER_TOTAL_REFS'), generateUserProfileLink(getRequestElement('userid')), $menge, $menge_lck));
63
64                 // Load all referal levels
65                 $result_levels = SQL_QUERY("SELECT
66         `level`, `percents`
67 FROM
68         `{?_MYSQL_PREFIX?}_refdepths`
69 WHERE
70         `level` > 0
71 ORDER BY
72         `level` ASC", __FILE__, __LINE__);
73
74                 // Are there some levels (VERY BAD IF NONE!)
75                 if (SQL_NUMROWS($result_levels) > 0) {
76                         // List all ref levels or entries if no refback is installed
77                         $OUT = ''; $SW = 2;
78                         while ($levels = SQL_FETCHARRAY($result_levels)) {
79                                 // Insert more data
80                                 $levels['sw']    = $SW;
81
82                                 // Is the refback still active? ;-)
83                                 if (isExtensionActive('refback')) {
84                                         // Load all refs of this user
85                                         $result_refs = SQL_QUERY_ESC("SELECT `refid` FROM `{?_MYSQL_PREFIX?}_user_refs` WHERE `userid`=%s AND `level`='%s' ORDER BY refid ASC",
86                                                 array($userid, $levels['level']), __FILE__, __LINE__);
87                                         //* DEBUG: */ outputHtml($userid.'/'.$levels['level'].'/'.SQL_NUMROWS($result_refs)."<br />");
88
89                                         // Do we have levels?
90                                         if (SQL_NUMROWS($result_refs) > 0) {
91                                                 // Count entries
92                                                 $menge =     countSumTotalData($userid, 'user_data', 'userid', 'refid', true);
93                                                 $menge_lck = countSumTotalData($userid, 'user_data', 'userid', 'refid', true, " AND `status` != 'CONFIRMED'");
94
95                                                 // Output info message
96                                                 $levels['info'] = sprintf(getMessage('ADMIN_USER_TOTAL_REFS'), generateUserProfileLink($userid), $menge, $menge_lck);
97
98                                                 // Init variables
99                                                 $OUT_REFS = ''; $SW = 2;
100
101                                                 // Load all refs
102                                                 while ($content = SQL_FETCHARRAY($result_refs)) {
103                                                         // Is the data there?
104                                                         if (fetchUserData($content['refid'])) {
105                                                                 // Check for referals
106                                                                 $refs_cnt = countSumTotalData(getUserData('userid'), 'refsystem', 'counter');
107
108                                                                 // Prepare data for the template
109                                                                 $content = array(
110                                                                         'sw'         => $SW,
111                                                                         'u_link'     => generateUserProfileLink(getUserData('userid')),
112                                                                         'gender'     => translateGender(getUserData('gender')),
113                                                                         'refs_link'  => 0,
114                                                                         'surname'    => getUserData('surname'),
115                                                                         'family'     => getUserData('family'),
116                                                                         'email'      => "[<a href=\"".generateEmailLink(getUserData('email'), 'user_data')."\">".getUserData('email')."</a>]",
117                                                                         'status'     => translateUserStatus(getUserData('status')),
118                                                                         'registered' => generateDateTime(getUserData('joined'), 3),
119                                                                 );
120
121                                                                 // Check if referal count is larger 0 and update link
122                                                                 if ($refs_cnt > 0) $content['refs_link'] = generateUserProfileLink(getUserData('userid'), $refs_cnt, "list_refs");
123
124                                                                 // Load template for level one
125                                                                 $OUT_REFS .= loadTemplate('admin_list_refs_row', true, $content);
126                                                         } else {
127                                                                 // No refs found
128                                                                 $OUT_REFS = loadTemplate('admin_list_refs_nodata', true, $content);
129                                                         }
130
131                                                         // Add content
132                                                         $levels['rows'] = $OUT_REFS;
133
134                                                         // Switch colors
135                                                         $SW = 3 - $SW;
136                                                 } // END - while
137                                         } else {
138                                                 // Output info message
139                                                 $levels['info'] = sprintf(getMessage('ADMIN_USER_TOTAL_REFS'), generateUserProfileLink($userid), 0, 0);
140
141                                                 // No refs found
142                                                 $levels['rows'] = loadTemplate('admin_list_refs_norefs', true, array('userid' => $userid));
143                                         }
144
145                                         // Free result
146                                         SQL_FREERESULT($result_refs);
147
148                                         // Load level template
149                                         $OUT .= loadTemplate('admin_list_refs_level', true, $levels);
150                                 } else {
151                                         // Check for referals
152                                         $refs_cnt = countSumTotalData($levels['userid'], 'user_data', 'userid', 'refid', true);
153
154                                         // Prepare data for the template
155                                         $content = array(
156                                                 'sw'         => $SW,
157                                                 'u_link'     => generateUserProfileLink($levels['userid']),
158                                                 'gender'     => translateGender($levels['gender']),
159                                                 'refs_link'  => 0,
160                                                 'surname'    => $levels['surname'],
161                                                 'family'     => $levels['family'],
162                                                 'email'      => "[<a href=\"".generateEmailLink($levels['email'], 'user_data')."\">".$levels['email']."</a>]",
163                                                 'status'     => translateUserStatus($levels['status']),
164                                                 'registered' => generateDateTime($levels['joined'], 3),
165                                         );
166
167                                         // Check if referal count is larger 0 and update link
168                                         if ($refs_cnt > 0) $content['refs_link'] = generateUserProfileLink($levels['userid'], $refs_cnt, 'list_refs');
169
170                                         // Load template for level one
171                                         $OUT .= loadTemplate('admin_list_refs_row', true, $content);
172
173                                         // Switch colors
174                                         $SW = 3 - $SW;
175                                 }
176                         } // END - while
177
178                         // Prepare content
179                         $content = array(
180                                 'rows' => $OUT,
181                                 'userid'  => generateUserProfileLink(getRequestElement('userid'))
182                         );
183
184                         // Load main template
185                         if (isExtensionActive('refback')) {
186                                 loadTemplate('admin_list_refs2', false, $content);
187                         } else {
188                                 loadTemplate('admin_list_refs', false, $content);
189                         }
190                 } elseif (isExtensionActive('refback')) {
191                         // No levels found, very bad!
192                         loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NO_REF_LEVELS'));
193                 } else {
194                         // No refs made so far
195                         loadTemplate('admin_settings_saved', false, getMessage('USER_REF_404'));
196                 }
197
198                 // Free result
199                 SQL_FREERESULT($result_levels);
200         } else {
201                 // User not found
202                 loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_MEMBER_404'), getRequestElement('userid')));
203         }
204 } else {
205         // Output selection form with all confirmed user accounts listed
206         addMemberSelectionBox();
207 }
208
209 // [EOF]
210 ?>