9cb4932e9c33e8d32b1815c7e5c9172cd8193c76
[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 referrals 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", basename(__FILE__));
48
49 if (!empty($_GET['u_id']))
50 {
51         // Check if the user already exists
52         $result = SQL_QUERY_ESC("SELECT userid FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
53          array(bigintval($_GET['u_id'])), __FILE__, __LINE__);
54         if (SQL_NUMROWS($result) == 1)
55         {
56                 // Free memory
57                 SQL_FREERESULT($result);
58
59                 // Loads surname, family's name and the email address
60                 $result     = SQL_QUERY_ESC("SELECT COUNT(*) FROM "._MYSQL_PREFIX."_user_data WHERE refid=%s",
61                  array(bigintval($_GET['u_id'])), __FILE__, __LINE__);
62                 $result_lck = SQL_QUERY_ESC("SELECT COUNT(*) FROM "._MYSQL_PREFIX."_user_data WHERE refid=%s AND status != 'CONFIRMED' ORDER BY userid",
63                  array(bigintval($_GET['u_id'])), __FILE__, __LINE__);
64                 $menge      = SQL_RESULT($result    , 0, 0);
65                 $menge_lck  = SQL_RESULT($result_lck, 0, 0);
66
67                 // Free memory
68                 SQL_FREERESULT($result);
69                 SQL_FREERESULT($result_lck);
70
71                 $result = SQL_QUERY_ESC("SELECT userid, gender, surname, family, email, status, joined FROM "._MYSQL_PREFIX."_user_data WHERE refid=%s ORDER BY userid",
72                  array(bigintval($_GET['u_id'])), __FILE__, __LINE__);
73
74                 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 />");
75                 if ($result)
76                 {
77                         $rows = SQL_NUMROWS($result);
78                         if ($rows > 0)
79                         {
80                                 // Load all referrals
81                                 $SW = "2"; $OUT = "";
82                                 while ($row = SQL_FETCHROW($result))
83                                 {
84                                         // Check for referrals
85                                         $result_refs = SQL_QUERY_ESC("SELECT COUNT(userid) FROM "._MYSQL_PREFIX."_user_data WHERE refid=%s",
86                                          array(bigintval($row[0])), __FILE__, __LINE__);
87                                         $refs_cnt = SQL_RESULT($result_refs, 0, 0);
88                                         SQL_FREERESULT($result_refs);
89
90                                         // Prepare data for the template
91                                         $content = array(
92                                                 'sw'         => $SW,
93                                                 'u_link'     => ADMIN_USER_PROFILE_LINK($row[0]),
94                                                 'gender'     => TRANSLATE_GENDER($row[1]),
95                                                 'refs_link'  => "0",
96                                                 'surname'    => $row[2],
97                                                 'family'     => $row[3],
98                                                 'email'      => "<A href=\"".CREATE_EMAIL_LINK($row[4], "user_data")."\">".$row[4]."</A>",
99                                                 'status'     => TRANSLATE_STATUS($row[5]),
100                                                 'registered' => MAKE_DATETIME($row[6], "3"),
101                                         );
102
103                                         // Check if referral count is larger 0 and update link
104                                         if ($refs_cnt > 0) $content['refs_link'] = ADMIN_USER_PROFILE_LINK($row[0], $refs_cnt, "list_refs");
105
106                                         // Load row template and switch color
107                                         $OUT .= LOAD_TEMPLATE("admin_list_refs_row", true, $content);
108                                         $SW = 3 - $SW;
109                                 }
110
111                                 // Free memory
112                                 SQL_FREERESULT($result);
113                                 define('__REF_ROWS', $OUT);
114
115                                 // Load main template
116                                 LOAD_TEMPLATE("admin_list_refs");
117                         }
118                 }
119                  else
120                 {
121                         // No referrals made so far
122                         LOAD_TEMPLATE("admin_settings_saved", false, USER_REF_404);
123                 }
124         }
125          else
126         {
127                 // User not found
128                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_MEMBER_404_1.$_GET['u_id'].ADMIN_MEMBER_404_2);
129         }
130 }
131  else
132 {
133         // Output selection form with all confirmed user accounts listed
134         ADD_MEMBER_SELECTION_BOX();
135 }
136
137 //
138 ?>