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