More misc fixes and rewrites (sorry, lame description)
[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 - 2008 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')) || (!IS_ADMIN())) {
42         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
43         require($INC);
44 }
45
46 // Add description as navigation point
47 ADD_DESCR('admin', __FILE__);
48
49 if (REQUEST_ISSET_GET('uid')) {
50         // Secure userid
51         $uid = bigintval(REQUEST_GET('uid'));
52
53         // Check if the user already exists
54         $result_user = SQL_QUERY_ESC("SELECT `userid` FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `userid`=%s LIMIT 1",
55                 array($uid), __FILE__, __LINE__);
56
57         // Fix missing variable
58         $result_levels = false;
59
60         // User found?
61         if (SQL_NUMROWS($result_user) == 1) {
62                 // Get total refs
63                 $menge =     GET_TOTAL_DATA($uid, 'user_data', 'userid', 'refid', true);
64                 $menge_lck = GET_TOTAL_DATA($uid, 'user_data', 'userid', 'refid', true, " AND `status` != 'CONFIRMED'");
65
66                 // Output info message
67                 LOAD_TEMPLATE('admin_settings_saved', false, sprintf(getMessage('ADMIN_USER_TOTAL_REFS'), generateUserProfileLink(REQUEST_GET('uid')), $menge, $menge_lck));
68
69                 // Load all referal levels
70                 $result_levels = SQL_QUERY("SELECT
71         `level`, `percents`
72 FROM
73         `{!_MYSQL_PREFIX!}_refdepths`
74 WHERE
75         `level` > 0
76 ORDER BY
77         `level` ASC", __FILE__, __LINE__);
78
79                 // Are there some levels (VERY BAD IF NONE!)
80                 if (SQL_NUMROWS($result_levels) > 0) {
81                         // List all ref levels or entries if no refback is installed
82                         $OUT = ''; $SW = 2;
83                         while ($levels = SQL_FETCHARRAY($result_levels)) {
84                                 // Insert more data
85                                 $levels['sw']    = $SW;
86
87                                 // Is the refback still active? ;-)
88                                 if (EXT_IS_ACTIVE('refback')) {
89                                         // Load all refs of this user
90                                         $result_refs = SQL_QUERY_ESC("SELECT `refid` FROM `{!_MYSQL_PREFIX!}_user_refs` WHERE `userid`=%s AND `level`='%s' ORDER BY refid ASC",
91                                                 array($uid, $levels['level']), __FILE__, __LINE__);
92                                         //* DEBUG: */ echo $uid.'/'.$levels['level'].'/'.SQL_NUMROWS($result_refs)."<br />\n";
93
94                                         // Do we have levels?
95                                         if (SQL_NUMROWS($result_refs) > 0) {
96                                                 // Count entries
97                                                 $menge =     GET_TOTAL_DATA($uid, 'user_data', 'userid', 'refid', true);
98                                                 $menge_lck = GET_TOTAL_DATA($uid, 'user_data', 'userid', 'refid', true, " AND `status` != 'CONFIRMED'");
99
100                                                 // Output info message
101                                                 $levels['info'] = sprintf(getMessage('ADMIN_USER_TOTAL_REFS'), generateUserProfileLink($uid), $menge, $menge_lck);
102
103                                                 // Init variables
104                                                 $OUT_REFS = ''; $SW = 2;
105
106                                                 // Load all refs
107                                                 while ($content = SQL_FETCHARRAY($result_refs)) {
108                                                         // Query for data
109                                                         $result_user = SQL_QUERY_ESC("SELECT `userid`, `gender`, `surname`, `family`, `email`, `status`, `joined` FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `userid`=%s LIMIT 1",
110                                                                 array($content['refid']), __FILE__, __LINE__);
111
112                                                         // Is the data there?
113                                                         if (SQL_NUMROWS($result_user) == 1) {
114                                                                 // Load data
115                                                                 $data = SQL_FETCHARRAY($result_user);
116
117                                                                 // Check for referals
118                                                                 $refs_cnt = GET_TOTAL_DATA($data['userid'], 'refsystem', 'counter');
119
120                                                                 // Prepare data for the template
121                                                                 $content = array(
122                                                                         'sw'         => $SW,
123                                                                         'u_link'     => generateUserProfileLink($data['userid']),
124                                                                         'gender'     => translateGender($data['gender']),
125                                                                         'refs_link'  => '0',
126                                                                         'surname'    => $data['surname'],
127                                                                         'family'     => $data['family'],
128                                                                         'email'      => "[<a href=\"".generateEmailLink($data['email'], 'user_data')."\">".$data['email']."</a>]",
129                                                                         'status'     => translateUserStatus($data['status']),
130                                                                         'registered' => generateDateTime($data['joined'], '3'),
131                                                                 );
132
133                                                                 // Check if referal count is larger 0 and update link
134                                                                 if ($refs_cnt > 0) $content['refs_link'] = generateUserProfileLink($data['userid'], $refs_cnt, "list_refs");
135
136                                                                 // Load template for level one
137                                                                 $OUT_REFS .= LOAD_TEMPLATE('admin_list_refs_row', true, $content);
138                                                         } else {
139                                                                 // No refs found
140                                                                 $OUT_REFS = LOAD_TEMPLATE('admin_list_refs_nodata', true, $content['refid']);
141                                                         }
142
143                                                         // Free result
144                                                         SQL_FREERESULT($result_user);
145
146                                                         // Add content
147                                                         $levels['rows'] = $OUT_REFS;
148
149                                                         // Switch colors
150                                                         $SW = 3 - $SW;
151                                                 } // END - while
152                                         } else {
153                                                 // Output info message
154                                                 $levels['info'] = sprintf(getMessage('ADMIN_USER_TOTAL_REFS'), generateUserProfileLink($uid), '0', '0');
155
156                                                 // No refs found
157                                                 $levels['rows'] = LOAD_TEMPLATE('admin_list_refs_norefs', true, array('uid' => $uid));
158                                         }
159
160                                         // Free result
161                                         SQL_FREERESULT($result_refs);
162
163                                         // Load level template
164                                         $OUT .= LOAD_TEMPLATE('admin_list_refs_level', true, $levels);
165                                 } else {
166                                         // Check for referals
167                                         $refs_cnt = GET_TOTAL_DATA($levels['userid'], 'user_data', 'userid', 'refid', true);
168
169                                         // Prepare data for the template
170                                         $content = array(
171                                                 'sw'         => $SW,
172                                                 'u_link'     => generateUserProfileLink($levels['userid']),
173                                                 'gender'     => translateGender($levels['gender']),
174                                                 'refs_link'  => '0',
175                                                 'surname'    => $levels['surname'],
176                                                 'family'     => $levels['family'],
177                                                 'email'      => "[<a href=\"".generateEmailLink($levels['email'], 'user_data')."\">".$levels['email']."</a>]",
178                                                 'status'     => translateUserStatus($levels['status']),
179                                                 'registered' => generateDateTime($levels['joined'], '3'),
180                                         );
181
182                                         // Check if referal count is larger 0 and update link
183                                         if ($refs_cnt > 0) $content['refs_link'] = generateUserProfileLink($levels['userid'], $refs_cnt, 'list_refs');
184
185                                         // Load template for level one
186                                         $OUT .= LOAD_TEMPLATE('admin_list_refs_row', true, $content);
187
188                                         // Switch colors
189                                         $SW = 3 - $SW;
190                                 }
191                         } // END - while
192
193                         // Prepare content
194                         $content = array(
195                                 'rows' => $OUT,
196                                 'uid'  => generateUserProfileLink(REQUEST_GET('uid'))
197                         );
198
199                         // Load main template
200                         if (EXT_IS_ACTIVE('refback')) {
201                                 LOAD_TEMPLATE('admin_list_refs2', false, $content);
202                         } else {
203                                 LOAD_TEMPLATE('admin_list_refs', false, $content);
204                         }
205                 } elseif (EXT_IS_ACTIVE('refback')) {
206                         // No levels found, very bad!
207                         LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_NO_REF_LEVELS'));
208                 } else {
209                         // No refs made so far
210                         LOAD_TEMPLATE('admin_settings_saved', false, getMessage('USER_REF_404'));
211                 }
212
213                 // Free result
214                 SQL_FREERESULT($result_levels);
215         } else {
216                 // User not found
217                 LOAD_TEMPLATE('admin_settings_saved', false, sprintf(getMessage('ADMIN_MEMBER_404'), REQUEST_GET('uid')));
218         }
219
220         // Free memory
221         SQL_FREERESULT($result_user);
222 } else {
223         // Output selection form with all confirmed user accounts listed
224         ADD_MEMBER_SELECTION_BOX();
225 }
226
227 // [EOF]
228 ?>