Some functions rewritten to hungarian notation, handling of array rewritten
[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 (!empty($_GET['u_id'])) {
50         // Secure userid
51         $uid = bigintval($_GET['u_id']);
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         // User found?
58         if (SQL_NUMROWS($result_user) == 1) {
59                 // Is the refback extension installed?
60                 if (EXT_IS_ACTIVE("refback")) {
61                         // Load all referal levels
62                         $result_levels = SQL_QUERY("SELECT level, percents
63 FROM "._MYSQL_PREFIX."_refdepths
64 WHERE level > 0
65 ORDER BY level ASC", __FILE__, __LINE__);
66                 } else {
67                         // Loads surname, family's name and the email address
68                         $result     = SQL_QUERY_ESC("SELECT COUNT(*) FROM `"._MYSQL_PREFIX."_user_data` WHERE refid=%s",
69                                 array($uid), __FILE__, __LINE__);
70                         $result_lck = SQL_QUERY_ESC("SELECT COUNT(*) FROM `"._MYSQL_PREFIX."_user_data` WHERE refid=%s AND status != 'CONFIRMED' ORDER BY userid",
71                                 array($uid), __FILE__, __LINE__);
72                         $menge      = SQL_RESULT($result    , 0, 0);
73                         $menge_lck  = SQL_RESULT($result_lck, 0, 0);
74
75                         // Free memory
76                         SQL_FREERESULT($result);
77                         SQL_FREERESULT($result_lck);
78
79                         // Query for refs
80                         $result_levels = SQL_QUERY_ESC("SELECT userid, gender, surname, family, email, status, joined FROM `"._MYSQL_PREFIX."_user_data` WHERE refid=%s ORDER BY userid ASC",
81                                 array($uid), __FILE__, __LINE__);
82
83                         // Output info message
84                         OUTPUT_HTML(ADMIN_TOTAL_REFS_1."".ADMIN_USER_PROFILE_LINK($_GET['u_id'])."".ADMIN_TOTAL_REFS_2.$menge.ADMIN_TOTAL_REFS_3.$menge_lck.ADMIN_TOTAL_REFS_4."<BR><BR>");
85                 }
86
87                 // Are there some levels (VERY BAD IF NONE!)
88                 if (SQL_NUMROWS($result_levels) > 0) {
89                         // List all ref levels or entries if no refback is installed
90                         $OUT = ""; $SW = 2;
91                         while ($levels = SQL_FETCHARRAY($result_levels)) {
92                                 // Insert more data
93                                 $levels['sw']    = $SW;
94
95                                 // Is the refback still active? ;-)
96                                 if (EXT_IS_ACTIVE("refback")) {
97                                         // Load all refs of this user
98                                         $result_refs = SQL_QUERY_ESC("SELECT refid FROM "._MYSQL_PREFIX."_user_refs WHERE userid=%s AND level='%s' ORDER BY refid ASC",
99                                                 array($uid, $levels['level']), __FILE__, __LINE__);
100                                         //* DEBUG: */ echo $uid."/".$levels['level']."/".SQL_NUMROWS($result_refs)."<br />\n";
101
102                                         // Do we have levels?
103                                         if (SQL_NUMROWS($result_refs) > 0) {
104                                                 // Loads surname, family's name and the email address
105                                                 $result     = SQL_QUERY_ESC("SELECT COUNT(*) FROM `"._MYSQL_PREFIX."_user_data` WHERE refid=%s",
106                                                         array($uid), __FILE__, __LINE__);
107                                                 $result_lck = SQL_QUERY_ESC("SELECT COUNT(*) FROM `"._MYSQL_PREFIX."_user_data` WHERE refid=%s AND status != 'CONFIRMED' ORDER BY userid",
108                                                         array($uid), __FILE__, __LINE__);
109                                                 $menge      = SQL_RESULT($result    , 0, 0);
110                                                 $menge_lck  = SQL_RESULT($result_lck, 0, 0);
111
112                                                 // Free memory
113                                                 SQL_FREERESULT($result);
114                                                 SQL_FREERESULT($result_lck);
115
116                                                 // Output info message
117                                                 $levels['info'] = ADMIN_TOTAL_REFS_1."".ADMIN_USER_PROFILE_LINK($uid)."".ADMIN_TOTAL_REFS_2.$menge.ADMIN_TOTAL_REFS_3.$menge_lck.ADMIN_TOTAL_REFS_4;
118
119                                                 // Load all refs
120                                                 $OUT_REFS = ""; $SW = 2;
121                                                 while (list($refid) = SQL_FETCHROW($result_refs)) {
122                                                         // Query for data
123                                                         $result_user = SQL_QUERY_ESC("SELECT userid, gender, surname, family, email, status, joined FROM `"._MYSQL_PREFIX."_user_data` WHERE userid=%s LIMIT 1",
124                                                                 array($refid), __FILE__, __LINE__);
125
126                                                         // Is the data there?
127                                                         if (SQL_NUMROWS($result_user) == 1) {
128                                                                 // Load data
129                                                                 $data = SQL_FETCHARRAY($result_user);
130
131                                                                 // Check for referals
132                                                                 $result_cnt = SQL_QUERY_ESC("SELECT COUNT(userid) FROM `"._MYSQL_PREFIX."_user_data` WHERE refid=%s",
133                                                                         array($refid), __FILE__, __LINE__);
134
135                                                                 // Load refs
136                                                                 $refs_cnt = SQL_RESULT($result_cnt, 0, 0);
137
138                                                                 // Free result
139                                                                 SQL_FREERESULT($result_cnt);
140
141                                                                 // Prepare data for the template
142                                                                 $content = array(
143                                                                         'sw'         => $SW,
144                                                                         'u_link'     => ADMIN_USER_PROFILE_LINK($data['userid']),
145                                                                         'gender'     => TRANSLATE_GENDER($data['gender']),
146                                                                         'refs_link'  => "0",
147                                                                         'surname'    => $data['surname'],
148                                                                         'family'     => $data['family'],
149                                                                         'email'      => "[<A href=\"".CREATE_EMAIL_LINK($data['email'], "user_data")."\">".$data['email']."</A>]",
150                                                                         'status'     => TRANSLATE_STATUS($data['status']),
151                                                                         'registered' => MAKE_DATETIME($data['joined'], "3"),
152                                                                 );
153
154                                                                 // Check if referal count is larger 0 and update link
155                                                                 if ($refs_cnt > 0) $content['refs_link'] = ADMIN_USER_PROFILE_LINK($data['userid'], $refs_cnt, "list_refs");
156
157                                                                 // Load template for level one
158                                                                 $OUT_REFS .= LOAD_TEMPLATE("admin_list_refs_row", true, $content);
159                                                         } else {
160                                                                 // No refs found
161                                                                 $OUT_REFS = LOAD_TEMPLATE("admin_list_refs_nodata", true, $refid);
162                                                         }
163
164                                                         // Free result
165                                                         SQL_FREERESULT($result_user);
166
167                                                         // Add content
168                                                         $levels['rows'] = $OUT_REFS;
169
170                                                         // Switch colors
171                                                         $SW = 3 - $SW;
172                                                 } // END - while
173                                         } else {
174                                                 // Output info message
175                                                 $levels['info'] = ADMIN_TOTAL_REFS_1."".ADMIN_USER_PROFILE_LINK($uid)."".ADMIN_TOTAL_REFS_2."0".ADMIN_TOTAL_REFS_3."0".ADMIN_TOTAL_REFS_4;
176
177                                                 // No refs found
178                                                 $levels['rows'] = LOAD_TEMPLATE("admin_list_refs_norefs", true, array('uid' => $uid));
179                                         }
180
181                                         // Free result
182                                         SQL_FREERESULT($result_refs);
183
184                                         // Load level template
185                                         $OUT .= LOAD_TEMPLATE("admin_list_refs_level", true, $levels);
186                                 } else {
187                                         // Check for referals
188                                         $result_refs = SQL_QUERY_ESC("SELECT COUNT(userid) FROM `"._MYSQL_PREFIX."_user_data` WHERE refid=%s",
189                                          array(bigintval($levels['userid'])), __FILE__, __LINE__);
190                                         $refs_cnt = SQL_RESULT($result_refs, 0, 0);
191                                         SQL_FREERESULT($result_refs);
192
193                                         // Prepare data for the template
194                                         $content = array(
195                                                 'sw'         => $SW,
196                                                 'u_link'     => ADMIN_USER_PROFILE_LINK($levels['userid']),
197                                                 'gender'     => TRANSLATE_GENDER($levels['gender']),
198                                                 'refs_link'  => "0",
199                                                 'surname'    => $levels['surname'],
200                                                 'family'     => $levels['family'],
201                                                 'email'      => "[<A href=\"".CREATE_EMAIL_LINK($levels['email'], "user_data")."\">".$levels['email']."</A>]",
202                                                 'status'     => TRANSLATE_STATUS($levels['status']),
203                                                 'registered' => MAKE_DATETIME($levels['joined'], "3"),
204                                         );
205
206                                         // Check if referal count is larger 0 and update link
207                                         if ($refs_cnt > 0) $content['refs_link'] = ADMIN_USER_PROFILE_LINK($levels['userid'], $refs_cnt, "list_refs");
208
209                                         // Load template for level one
210                                         $OUT .= LOAD_TEMPLATE("admin_list_refs_row", true, $content);
211
212                                         // Switch colors
213                                         $SW = 3 - $SW;
214                                 }
215                         } // END - while
216
217                         // Prepare content
218                         $content = array(
219                                 'rows' => $OUT,
220                                 'uid'  => ADMIN_USER_PROFILE_LINK($_GET['u_id'])
221                         );
222
223                         // Load main template
224                         if (EXT_IS_ACTIVE("refback")) {
225                                 LOAD_TEMPLATE("admin_list_refs2", false, $content);
226                         } else {
227                                 LOAD_TEMPLATE("admin_list_refs", false, $content);
228                         }
229                 } elseif (EXT_IS_ACTIVE("refback")) {
230                         // No levels found, very bad!
231                         LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_NO_REF_LEVELS);
232                 } else {
233                         // No refs made so far
234                         LOAD_TEMPLATE("admin_settings_saved", false, USER_REF_404);
235                 }
236
237                 // Free result
238                 SQL_FREERESULT($result_levels);
239         } else {
240                 // User not found
241                 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(ADMIN_MEMBER_404, $_GET['u_id']));
242         }
243
244         // Free memory
245         SQL_FREERESULT($result_user);
246 } else {
247         // Output selection form with all confirmed user accounts listed
248         ADD_MEMBER_SELECTION_BOX();
249 }
250
251 //
252 ?>