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