A lot while() conditions rewritten to SQL_FETCHARRAY(), see bug #107, @TODO tags...
[mailer.git] / inc / modules / guest / what-top10.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 11/24/2004 *
4  * ================                             Last change: 11/26/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-top10.php                                   *
8  * -------------------------------------------------------------------- *
9  * Short description : TOP logins / best earner etc.                    *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : TOP-Logins / Bestverdiener usw.                  *
12  * -------------------------------------------------------------------- *
13  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 } elseif ((!EXT_IS_ACTIVE("top10")) && (!IS_ADMIN())) {
39         addFatalMessage(__FILE__, __LINE__, getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), "top10");
40         return;
41 }
42
43 // Add description as navigation point
44 ADD_DESCR("guest", __FILE__);
45
46 //// TOP logins
47 $result = SQL_QUERY_ESC("
48 SELECT
49         userid, total_logins, last_online
50 FROM
51         {!_MYSQL_PREFIX!}_user_data
52 WHERE
53         total_logins > 0 AND
54         `status`='CONFIRMED'
55 ORDER BY
56         total_logins DESC
57 LIMIT %s",
58         array(getConfig('top10_max')), __FILE__, __LINE__);
59
60 $OUT = ""; $SW = 2; $cnt = 1;
61 while ($content = SQL_FETCHARRAY($result)) {
62         // Init nickname
63         $content['nickname'] = "---";
64
65         // Get nickname
66         if (EXT_IS_ACTIVE("nickname")) $content['nickname'] = NICKNAME_GET_NICK($content['userid']);
67
68         // Prepare data for template
69         // @TODO Rewritings: uid->userid,nick->nickname,logins->total_logins in template
70         $content = array(
71                 'sw'     => $SW,
72                 'cnt'    => $cnt,
73                 'uid'    => $content['userid'],
74                 'nick'   => $content['nickname'],
75                 'logins' => $content['total_logins'],
76                 'points' => TRANSLATE_COMMA(GET_TOTAL_DATA($content['userid'], "user_points", "points")),
77                 'last'   => MAKE_DATETIME($content['last_online'], "3"),
78         );
79
80         // Load row template
81         $OUT .= LOAD_TEMPLATE("guest_top10_row_login", true, $content);
82
83         // Switch colors and count one up
84         $SW = 3 - $SW; $cnt++;
85 } // END - while
86
87 if ($cnt < getConfig('top10_max')) {
88         // Add more "blank" rows
89         for ($i = $cnt; $i <= getConfig('top10_max'); $i++) {
90                 // Prepare data for template
91                 $content = array(
92                         'sw'  => $SW,
93                         'idx' => $i
94                 );
95
96                 // Load row template
97                 $OUT .= LOAD_TEMPLATE("guest_top10_empty5", true, $content);
98                 $SW = 3 - $SW;
99         } // END - for
100 } // END - if
101
102 // @TODO Rewrite this constant
103 define('__TOP_LOGINS_ROWS', $OUT);
104
105 // Free result
106 SQL_FREERESULT($result);
107
108 //// TOP earners
109 $result = SQL_QUERY_ESC("
110 SELECT DISTINCT
111         d.userid,
112         (SUM(p.points) - d.used_points) AS tpoints,
113         d.last_online
114 FROM
115         `{!_MYSQL_PREFIX!}_user_data` AS d
116 LEFT JOIN
117         {!_MYSQL_PREFIX!}_user_points AS p
118 ON
119         p.userid=d.userid
120 WHERE
121         p.points > 0 AND
122         d.`status`='CONFIRMED'
123 GROUP BY
124         p.userid
125 ORDER BY
126         tpoints DESC,
127         d.last_online DESC
128 LIMIT %s",
129         array(getConfig('top10_max')), __FILE__, __LINE__);
130
131 $OUT = ""; $SW = 2; $cnt = 1;
132 while ($content = SQL_FETCHARRAY($result)) {
133         // Init nickname
134         $content['nickname'] = "---";
135
136         // Get nickname
137         if (EXT_IS_ACTIVE("nickname")) $content['nickname'] = NICKNAME_GET_NICK($content['userid']);
138
139         // Prepare data for template
140         // @TODO Rewritings: nick->nickname,uid->userid in template
141         $content = array(
142                 'sw'     => $SW,
143                 'cnt'    => $cnt,
144                 'uid'    => $content['userid'],
145                 'nick'   => $content['nickname'],
146                 'points' => TRANSLATE_COMMA($content['points']),
147                 'last'   => MAKE_DATETIME($content['last_online'], "3")
148         );
149
150         // Load row template
151         $OUT .= LOAD_TEMPLATE("guest_top10_row_earner", true, $content);
152
153         // Switch colors and count one up
154         $SW = 3 - $SW; $cnt++;
155 } // END - while
156
157 if ($cnt < getConfig('top10_max')) {
158         // Add more "blank" rows
159         for ($i = $cnt; $i <= getConfig('top10_max'); $i++) {
160                 // Prepare data for template
161                 $content = array(
162                         'sw'  => $SW,
163                         'idx' => $i
164                 );
165
166                 // Load row template
167                 $OUT .= LOAD_TEMPLATE("guest_top10_empty4", true, $content);
168                 $SW = 3 - $SW;
169         } // END - for
170 } // END - if
171
172 // @TODO Rewrite this constant
173 define('__TOP_POINTS_ROWS', $OUT);
174
175 // Free result
176 SQL_FREERESULT($result);
177
178 //// TOP referal "hunter"
179 $result = SQL_QUERY_ESC("
180 SELECT DISTINCT
181         d.userid,
182         SUM(r.counter) AS refs,
183         d.last_online
184 FROM
185         `{!_MYSQL_PREFIX!}_user_data` AS d
186 LEFT JOIN
187         {!_MYSQL_PREFIX!}_refsystem AS r
188 ON
189         r.userid=d.userid
190 WHERE
191         r.counter > 0 AND
192         d.`status`='CONFIRMED'
193 GROUP BY
194         r.userid
195 ORDER BY
196         refs DESC,
197         d.last_online DESC
198 LIMIT %s",
199         array(getConfig('top10_max')), __FILE__, __LINE__);
200
201 $OUT = ""; $SW = 2; $cnt = 1;
202 while ($content = SQL_FETCHARRAY($result)) {
203         // Init nickname
204         $content['nickname'] = "---";
205
206         // Get nickname
207         if (EXT_IS_ACTIVE("nickname")) $content['nickname'] = NICKNAME_GET_NICK($content['userid']);
208
209         // Prepare data for template
210         // @TODO Rewritings: nick->nickname,uid->userid in template
211         $content = array(
212                 'sw'     => $SW,
213                 'cnt'    => $cnt,
214                 'uid'    => $content['userid'],
215                 'refs'   => $content['refs'],
216                 'nick'   => $content['nickname'],
217                 'points' => TRANSLATE_COMMA(GET_TOTAL_DATA($content['userid'], "user_points", "points")),
218                 'last'   => MAKE_DATETIME($content['last_online'], "3")
219         );
220
221         // Load row template
222         $OUT .= LOAD_TEMPLATE("guest_top10_row_refs", true, $content);
223
224         // Switch colors and count one up
225         $SW = 3 - $SW; $cnt++;
226 } // END - while
227
228 if ($cnt < getConfig('top10_max')) {
229         // Add more "blank" rows
230         for ($i = $cnt; $i <= getConfig('top10_max'); $i++) {
231                 // Prepare data for template
232                 $content = array(
233                         'sw'  => $SW,
234                         'idx' => $i
235                 );
236
237                 // Load row template
238                 $OUT .= LOAD_TEMPLATE("guest_top10_empty5", true, $content);
239                 $SW = 3 - $SW;
240         } // END - for
241 } // END - if
242
243 // @TODO Rewrite this constant
244 define('__TOP_REFERRAL_ROWS', $OUT);
245
246 // Free result
247 SQL_FREERESULT($result);
248
249 // Remember other values in constants
250 // @TODO Rewrite this constant
251 define('__TOP10_MAX', getConfig('top10_max'));
252
253 // Load final template
254 LOAD_TEMPLATE("guest_top10");
255
256 //
257 ?>