Renamed all SQL-related functions to camel-case notation
[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 - 2013 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                 $totalReferrals       = getUsersTotalReferrals($userid);
52                 $totalLockedReferrals = getUsersTotalLockedReferrals($userid);
53
54                 // Output info message
55                 displayMessage(sprintf(getMessage('ADMIN_USER_TOTAL_REFS'), generateUserProfileLink(getRequestElement('userid')), $totalReferrals, $totalLockedReferrals));
56
57                 // Load all referral levels
58                 $result_levels = sqlQuery("SELECT
59         `level`,
60         `percents`
61 FROM
62         `{?_MYSQL_PREFIX?}_refdepths`
63 WHERE
64         `level` > 0
65 ORDER BY
66         `level` ASC", __FILE__, __LINE__);
67
68                 // Are there some levels (VERY BAD IF NONE!)
69                 if (!ifSqlHasZeroNums($result_levels)) {
70                         // List all ref levels or entries if no refback is installed
71                         $OUT = '';
72                         while ($levels = sqlFetchArray($result_levels)) {
73                                 // Load all refs of this user
74                                 $result_refs = sqlQueryEscaped("SELECT `refid` FROM `{?_MYSQL_PREFIX?}_user_refs` WHERE `userid`=%s AND `level`=%s ORDER BY `refid` ASC",
75                                         array(
76                                                 $userid,
77                                                 $levels['level']
78                                         ), __FILE__, __LINE__);
79                                 //* DEBUG: */ debugOutput($userid.'/'.$levels['level'].'/'.SQL_NUMROWS($result_refs));
80
81                                 // Is there levels?
82                                 if (!ifSqlHasZeroNums($result_refs)) {
83                                         // Count entries
84                                         $totalReferrals       = getUsersTotalReferrals($userid, $levels['level']);
85                                         $totalLockedReferrals = getUsersTotalLockedReferrals($userid, $levels['level']);
86
87                                         // Output info message
88                                         $levels['info'] = sprintf(getMessage('ADMIN_USER_TOTAL_REFS'), generateUserProfileLink($userid), $totalReferrals, $totalLockedReferrals);
89
90                                         // Init variables
91                                         $OUT_REFS = '';
92
93                                         // Load all refs
94                                         while ($content = sqlFetchArray($result_refs)) {
95                                                 // Is the data there?
96                                                 if (fetchUserData($content['refid'])) {
97                                                         // Check for referrals
98                                                         $refs_cnt = countSumTotalData(getUserData('userid'), 'user_refs', 'id', 'userid', TRUE);
99
100                                                         // Prepare data for the template
101                                                         // @TODO Try to rewrite some to EL
102                                                         $content = array(
103                                                                 'userid'     => getUserData('userid'),
104                                                                 'refs_link'  => '0',
105                                                                 'email'      => '[<a href="' . generateEmailLink(getUserData('email'), 'user_data') . '">' . getUserData('email') . '</a>]',
106                                                                 'registered' => generateDateTime(getUserData('joined'), 3),
107                                                         );
108
109                                                         // Check if referral count is larger 0 and update link
110                                                         if ($refs_cnt > 0) {
111                                                                 $content['refs_link'] = generateUserProfileLink(getUserData('userid'), $refs_cnt, 'list_refs');
112                                                         } // END - if
113
114                                                         // Load template for level one
115                                                         $OUT_REFS .= loadTemplate('admin_list_refs_row', TRUE, $content);
116                                                 } else {
117                                                         // No refs found
118                                                         $OUT_REFS = loadTemplate('admin_list_refs_nodata', TRUE, $content);
119                                                 }
120
121                                                 // Add content
122                                                 $levels['rows'] = $OUT_REFS;
123                                         } // END - while
124                                 } else {
125                                         // Output info message
126                                         $levels['info'] = sprintf(getMessage('ADMIN_USER_TOTAL_REFS'), generateUserProfileLink($userid), 0, 0);
127
128                                         // No refs found
129                                         $levels['rows'] = loadTemplate('admin_list_refs_norefs', TRUE, array('userid' => $userid));
130                                 }
131
132                                 // Free result
133                                 sqlFreeResult($result_refs);
134
135                                 // Load level template
136                                 $OUT .= loadTemplate('admin_list_refs_level', TRUE, $levels);
137                         } // END - while
138
139                         // Prepare content
140                         $content = array(
141                                 'rows'   => $OUT,
142                                 'userid' => getRequestElement('userid')
143                         );
144
145                         // Load main template
146                         loadTemplate('admin_list_refs', FALSE, $content);
147                 } else {
148                         // No refs made so far
149                         displayMessage('{--USER_REFERRAL_404--}');
150                 }
151
152                 // Free result
153                 sqlFreeResult($result_levels);
154         } else {
155                 // User not found
156                 displayMessage('{%message,ADMIN_MEMBER_404=' . getRequestElement('userid') . '%}');
157         }
158 } else {
159         // Output selection form with all confirmed user accounts listed
160         addMemberSelectionBox();
161 }
162
163 // [EOF]
164 ?>