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