Previous fix fixed, a lot constants rewritten (unfinished)
[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(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 (list($uid, $logins, $last) = SQL_FETCHROW($result)) {
62         $nick2 = "---";
63
64         // Get nickname
65         if (EXT_IS_ACTIVE("nickname")) $nick2 = NICKNAME_GET_NICK($uid);
66
67         // Prepare data for template
68         $content = array(
69                 'sw'     => $SW,
70                 'cnt'    => $cnt,
71                 'uid'    => $uid,
72                 'nick'   => $nick2,
73                 'logins' => $logins,
74                 'points' => TRANSLATE_COMMA(GET_TOTAL_DATA($uid, "user_points", "points")),
75                 'last'   => MAKE_DATETIME($last, "3"),
76         );
77
78         // Load row template
79         $OUT .= LOAD_TEMPLATE("guest_top10_row_login", true, $content);
80
81         // Switch colors and count one up
82         $SW = 3 - $SW; $cnt++;
83 }
84
85 if ($cnt < getConfig('top10_max')) {
86         // Add more "blank" rows
87         for ($i = $cnt; $i <= getConfig('top10_max'); $i++) {
88                 // Prepare data for template
89                 $content = array(
90                         'sw'  => $SW,
91                         'idx' => $i
92                 );
93
94                 // Load row template
95                 $OUT .= LOAD_TEMPLATE("guest_top10_empty5", true, $content);
96                 $SW = 3 - $SW;
97         }
98 }
99 define('__TOP_LOGINS_ROWS', $OUT);
100
101 // Free result
102 SQL_FREERESULT($result);
103
104 //// TOP earners
105 $result = SQL_QUERY_ESC("
106 SELECT DISTINCT
107         d.userid,
108         (SUM(p.points) - d.used_points) AS tpoints,
109         d.last_online
110 FROM
111         `{!_MYSQL_PREFIX!}_user_data` AS d
112 LEFT JOIN
113         {!MYSQL_PREFIX!}_user_points AS p
114 ON
115         p.userid=d.userid
116 WHERE
117         p.points > 0 AND
118         d.status='CONFIRMED'
119 GROUP BY
120         p.userid
121 ORDER BY
122         tpoints DESC,
123         d.last_online DESC
124 LIMIT %s",
125         array(getConfig('top10_max')), __FILE__, __LINE__);
126
127 $OUT = ""; $SW = 2; $cnt = 1;
128 while (list($uid, $points, $last) = SQL_FETCHROW($result)) {
129         $nick2 = "---";
130
131         // Get nickname
132         if (EXT_IS_ACTIVE("nickname")) $nick2 = NICKNAME_GET_NICK($uid);
133
134         // Prepare data for template
135         $content = array(
136                 'sw'     => $SW,
137                 'cnt'    => $cnt,
138                 'uid'    => bigintval($uid),
139                 'nick'   => $nick2,
140                 'points' => TRANSLATE_COMMA($points),
141                 'last'   => MAKE_DATETIME($last, "3")
142         );
143
144         // Load row template
145         $OUT .= LOAD_TEMPLATE("guest_top10_row_earner", true, $content);
146
147         // Switch colors and count one up
148         $SW = 3 - $SW; $cnt++;
149 }
150
151 if ($cnt < getConfig('top10_max')) {
152         // Add more "blank" rows
153         for ($i = $cnt; $i <= getConfig('top10_max'); $i++) {
154                 // Prepare data for template
155                 $content = array(
156                         'sw'  => $SW,
157                         'idx' => $i
158                 );
159
160                 // Load row template
161                 $OUT .= LOAD_TEMPLATE("guest_top10_empty4", true, $content);
162                 $SW = 3 - $SW;
163         }
164 }
165 define('__TOP_POINTS_ROWS', $OUT);
166
167 // Free result
168 SQL_FREERESULT($result);
169
170 //// TOP referal "hunter"
171 $result = SQL_QUERY_ESC("
172 SELECT DISTINCT
173         d.userid,
174         SUM(r.counter) AS refs,
175         d.last_online
176 FROM
177         `{!_MYSQL_PREFIX!}_user_data` AS d
178 LEFT JOIN
179         {!MYSQL_PREFIX!}_refsystem AS r
180 ON
181         r.userid=d.userid
182 WHERE
183         r.counter > 0 AND
184         d.status='CONFIRMED'
185 GROUP BY
186         r.userid
187 ORDER BY
188         refs DESC,
189         d.last_online DESC
190 LIMIT %s",
191         array(getConfig('top10_max')), __FILE__, __LINE__);
192
193 $OUT = ""; $SW = 2; $cnt = 1;
194 while (list($uid, $refs, $last) = SQL_FETCHROW($result)) {
195         $nick2 = "---";
196
197         // Get nickname
198         if (EXT_IS_ACTIVE("nickname")) $nick2 = NICKNAME_GET_NICK($uid);
199
200         // Prepare data for template
201         $content = array(
202                 'sw'     => $SW,
203                 'cnt'    => $cnt,
204                 'uid'    => bigintval($uid),
205                 'refs'   => $refs,
206                 'nick'   => $nick2,
207                 'points' => TRANSLATE_COMMA(GET_TOTAL_DATA($uid, "user_points", "points")),
208                 'last'   => MAKE_DATETIME($last, "3")
209         );
210
211         // Load row template
212         $OUT .= LOAD_TEMPLATE("guest_top10_row_refs", true, $content);
213
214         // Switch colors and count one up
215         $SW = 3 - $SW; $cnt++;
216 }
217
218 if ($cnt < getConfig('top10_max')) {
219         // Add more "blank" rows
220         for ($i = $cnt; $i <= getConfig('top10_max'); $i++) {
221                 // Prepare data for template
222                 $content = array(
223                         'sw'  => $SW,
224                         'idx' => $i
225                 );
226
227                 // Load row template
228                 $OUT .= LOAD_TEMPLATE("guest_top10_empty5", true, $content);
229                 $SW = 3 - $SW;
230         }
231 }
232 define('__TOP_REFERRAL_ROWS', $OUT);
233
234 // Free result
235 SQL_FREERESULT($result);
236
237 // Remember other values in constants
238 define('__TOP10_MAX', getConfig('top10_max'));
239
240 // Load final template
241 LOAD_TEMPLATE("guest_top10");
242
243 //
244 ?>