Cleanups and all "base scripts" fixed:
[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 referrals made by a member              *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Alle generierten Refs eines Mitgliedes anzeigen  *
12  * -------------------------------------------------------------------- *
13  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
14  * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
15  * For more information visit: http://mxchange.org                      *
16  *                                                                      *
17  * This program is free software; you can redistribute it and/or modify *
18  * it under the terms of the GNU General Public License as published by *
19  * the Free Software Foundation; either version 2 of the License, or    *
20  * (at your option) any later version.                                  *
21  *                                                                      *
22  * This program is distributed in the hope that it will be useful,      *
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
25  * GNU General Public License for more details.                         *
26  *                                                                      *
27  * You should have received a copy of the GNU General Public License    *
28  * along with this program; if not, write to the Free Software          *
29  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
30  * MA  02110-1301  USA                                                  *
31  ************************************************************************/
32
33 // Some security stuff...
34 if ((!defined('__SECURITY')) || (!isAdmin())) {
35         die();
36 } // END - if
37
38 // Add description as navigation point
39 addYouAreHereLink('admin', __FILE__);
40
41 if (isGetRequestElementSet('userid')) {
42         // Secure userid
43         $userid = bigintval(getRequestElement('userid'));
44
45         // Fix missing variable
46         $result_levels = false;
47
48         // User found?
49         if (fetchUserData($userid)) {
50                 // Get total refs
51                 $menge =     countSumTotalData($userid, 'user_data', 'userid', 'refid', true);
52                 $menge_lck = countSumTotalData($userid, 'user_data', 'userid', 'refid', true, " AND `status` != 'CONFIRMED'");
53
54                 // Output info message
55                 displayMessage(sprintf(getMessage('ADMIN_USER_TOTAL_REFS'), generateUserProfileLink(getRequestElement('userid')), $menge, $menge_lck));
56
57                 // Load all referral levels
58                 $result_levels = SQL_QUERY("SELECT
59         `level`,`percents`
60 FROM
61         `{?_MYSQL_PREFIX?}_refdepths`
62 WHERE
63         `level` > 0
64 ORDER BY
65         `level` ASC", __FILE__, __LINE__);
66
67                 // Are there some levels (VERY BAD IF NONE!)
68                 if (!SQL_HASZERONUMS($result_levels)) {
69                         // List all ref levels or entries if no refback is installed
70                         $OUT = '';
71                         while ($levels = SQL_FETCHARRAY($result_levels)) {
72                                 // Load all refs of this user
73                                 $result_refs = SQL_QUERY_ESC("SELECT `refid` FROM `{?_MYSQL_PREFIX?}_user_refs` WHERE `userid`=%s AND `level`=%s ORDER BY `refid` ASC",
74                                         array(
75                                                 $userid,
76                                                 $levels['level']
77                                         ), __FILE__, __LINE__);
78                                 //* DEBUG: */ debugOutput($userid.'/'.$levels['level'].'/'.SQL_NUMROWS($result_refs));
79
80                                 // Do we have levels?
81                                 if (!SQL_HASZERONUMS($result_refs)) {
82                                         // Count entries
83                                         $menge =     countSumTotalData($userid, 'user_data', 'userid', 'refid', true);
84                                         $menge_lck = countSumTotalData($userid, 'user_data', 'userid', 'refid', true, " AND `status` != 'CONFIRMED'");
85
86                                         // Output info message
87                                         $levels['info'] = sprintf(getMessage('ADMIN_USER_TOTAL_REFS'), generateUserProfileLink($userid), $menge, $menge_lck);
88
89                                         // Init variables
90                                         $OUT_REFS = '';
91
92                                         // Load all refs
93                                         while ($content = SQL_FETCHARRAY($result_refs)) {
94                                                 // Is the data there?
95                                                 if (fetchUserData($content['refid'])) {
96                                                         // Check for referrals
97                                                         $refs_cnt = countSumTotalData(getUserData('userid'), 'user_refs', 'id', 'userid', true);
98
99                                                         // Prepare data for the template
100                                                         // @TODO Try to rewrite some to EL
101                                                         $content = array(
102                                                                 'userid'     => getUserData('userid'),
103                                                                 'gender'     => getUserData('gender'),
104                                                                 'refs_link'  => 0,
105                                                                 'surname'    => getUserData('surname'),
106                                                                 'family'     => getUserData('family'),
107                                                                 'email'      => '[<a href="' . generateEmailLink(getUserData('email'), 'user_data') . '">' . getUserData('email') . '</a>]',
108                                                                 'status'     => getUserData('status'),
109                                                                 'registered' => generateDateTime(getUserData('joined'), 3),
110                                                         );
111
112                                                         // Check if referral count is larger 0 and update link
113                                                         if ($refs_cnt > 0) {
114                                                                 $content['refs_link'] = generateUserProfileLink(getUserData('userid'), $refs_cnt, 'list_refs');
115                                                         } // END - if
116
117                                                         // Load template for level one
118                                                         $OUT_REFS .= loadTemplate('admin_list_refs_row', true, $content);
119                                                 } else {
120                                                         // No refs found
121                                                         $OUT_REFS = loadTemplate('admin_list_refs_nodata', true, $content);
122                                                 }
123
124                                                 // Add content
125                                                 $levels['rows'] = $OUT_REFS;
126                                         } // END - while
127                                 } else {
128                                         // Output info message
129                                         $levels['info'] = sprintf(getMessage('ADMIN_USER_TOTAL_REFS'), generateUserProfileLink($userid), 0, 0);
130
131                                         // No refs found
132                                         $levels['rows'] = loadTemplate('admin_list_refs_norefs', true, array('userid' => $userid));
133                                 }
134
135                                 // Free result
136                                 SQL_FREERESULT($result_refs);
137
138                                 // Load level template
139                                 $OUT .= loadTemplate('admin_list_refs_level', true, $levels);
140                         } // END - while
141
142                         // Prepare content
143                         $content = array(
144                                 'rows'   => $OUT,
145                                 'userid' => getRequestElement('userid')
146                         );
147
148                         // Load main template
149                         loadTemplate('admin_list_refs', false, $content);
150                 } else {
151                         // No refs made so far
152                         displayMessage('{--USER_REFERRAL_404--}');
153                 }
154
155                 // Free result
156                 SQL_FREERESULT($result_levels);
157         } else {
158                 // User not found
159                 displayMessage('{%message,ADMIN_MEMBER_404=' . getRequestElement('userid') . '%}');
160         }
161 } else {
162         // Output selection form with all confirmed user accounts listed
163         addMemberSelectionBox();
164 }
165
166 // [EOF]
167 ?>