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