Re-added
[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         ADD_FATAL(EXTENSION_PROBLEM_EXT_INACTIVE, "top10");
40         return;
41 }
42
43 // Add description as navigation point
44 ADD_DESCR("guest", basename(__FILE__));
45
46 //// TOP logins
47 $ADD = "userid";
48 if (EXT_IS_ACTIVE("nickname")) $ADD = "nickname";
49 $result = SQL_QUERY_ESC("SELECT userid, ".$ADD.", total_logins, last_online
50 FROM "._MYSQL_PREFIX."_user_data
51 WHERE total_logins>0 AND status='CONFIRMED' ORDER BY total_logins DESC LIMIT %s",
52  array($_CONFIG['top10_max']), __FILE__, __LINE__);
53
54 $OUT = ""; $SW = 2; $cnt = 1;
55 while(list($uid, $nick, $logins, $last) = SQL_FETCHROW($result))
56 {
57         $nick2 = "---";
58         if (($nick != $uid) && (!empty($nick))) $nick2 = $nick;
59
60         // Prepare data for template
61         $content = array(
62                 'sw'     => $SW,
63                 'cnt'    => $cnt,
64                 'uid'    => $uid,
65                 'nick'   => $nick2,
66                 'logins' => $logins,
67                 'points' => TRANSLATE_COMMA(GET_TOTAL_DATA($uid, "user_points", "points")),
68                 'last'   => MAKE_DATETIME($last, "3"),
69         );
70
71         // Load row template
72         $OUT .= LOAD_TEMPLATE("guest_top10_row_login", true, $content);
73
74         // Switch colors and count one up
75         $SW = 3 - $SW; $cnt++;
76 }
77 if ($cnt < $_CONFIG['top10_max'])
78 {
79         // Add more "blank" rows
80         for ($i = $cnt; $i <= $_CONFIG['top10_max']; $i++)
81         {
82                 // Prepare data for template
83                 $content = array(
84                         'sw'  => $SW,
85                         'idx' => $i
86                 );
87
88                 // Load row template
89                 $OUT .= LOAD_TEMPLATE("guest_top10_empty5", true, $content);
90                 $SW = 3 - $SW;
91         }
92 }
93 define('__TOP_LOGINS_ROWS', $OUT);
94
95 //// TOP earners
96 $result = SQL_QUERY_ESC("SELECT DISTINCT p.userid, d.".$ADD.", (SUM(p.points) - d.used_points) AS tpoints, d.last_online
97 FROM "._MYSQL_PREFIX."_user_points AS p
98 LEFT JOIN "._MYSQL_PREFIX."_user_data AS d
99 ON p.userid=d.userid
100 WHERE p.points > 0 AND d.status='CONFIRMED'
101 GROUP BY p.userid
102 ORDER BY tpoints DESC, d.last_online DESC
103 LIMIT %s",
104  array($_CONFIG['top10_max']), __FILE__, __LINE__);
105
106 $OUT = ""; $SW = 2; $cnt = 1;
107 while(list($uid, $nick, $points, $last) = SQL_FETCHROW($result))
108 {
109         $nick2 = "---";
110         if (($nick != $uid) && (!empty($nick))) $nick2 = $nick;
111
112         // Prepare data for template
113         $content = array(
114                 'sw'     => $SW,
115                 'cnt'    => $cnt,
116                 'uid'    => bigintval($uid),
117                 'nick'   => $nick2,
118                 'points' => TRANSLATE_COMMA($points),
119                 'last'   => MAKE_DATETIME($last, "3")
120         );
121
122         // Load row template
123         $OUT .= LOAD_TEMPLATE("guest_top10_row_earner", true, $content);
124
125         // Switch colors and count one up
126         $SW = 3 - $SW; $cnt++;
127 }
128 if ($cnt < $_CONFIG['top10_max'])
129 {
130         // Add more "blank" rows
131         for ($i = $cnt; $i <= $_CONFIG['top10_max']; $i++)
132         {
133                 // Prepare data for template
134                 $content = array(
135                         'sw'  => $SW,
136                         'idx' => $i
137                 );
138
139                 // Load row template
140                 $OUT .= LOAD_TEMPLATE("guest_top10_empty4", true, $content);
141                 $SW = 3 - $SW;
142         }
143 }
144 define('__TOP_POINTS_ROWS', $OUT);
145
146 //// TOP referral "hunter"
147 $result = SQL_QUERY_ESC("SELECT DISTINCT r.userid, d.".$ADD.", SUM(r.counter) AS refs, d.last_online
148 FROM "._MYSQL_PREFIX."_refsystem AS r
149 LEFT JOIN "._MYSQL_PREFIX."_user_data AS d
150 ON r.userid=d.userid
151 WHERE r.counter > 0 AND d.status='CONFIRMED'
152 GROUP BY r.userid
153 ORDER BY refs DESC, d.last_online DESC
154 LIMIT %s",
155  array($_CONFIG['top10_max']), __FILE__, __LINE__);
156
157 $OUT = ""; $SW = 2; $cnt = 1;
158 while(list($uid, $nick, $refs, $last) = SQL_FETCHROW($result))
159 {
160         $nick2 = "---";
161         if (($nick != $uid) && (!empty($nick))) $nick2 = $nick;
162
163         // Prepare data for template
164         $content = array(
165                 'sw'     => $SW,
166                 'cnt'    => $cnt,
167                 'uid'    => bigintval($uid),
168                 'refs'   => $refs,
169                 'nick'   => $nick2,
170                 'points' => TRANSLATE_COMMA(GET_TOTAL_DATA($uid, "user_points", "points")),
171                 'last'   => MAKE_DATETIME($last, "3")
172         );
173
174         // Load row template
175         $OUT .= LOAD_TEMPLATE("guest_top10_row_refs", true, $content);
176
177         // Switch colors and count one up
178         $SW = 3 - $SW; $cnt++;
179 }
180 if ($cnt < $_CONFIG['top10_max'])
181 {
182         // Add more "blank" rows
183         for ($i = $cnt; $i <= $_CONFIG['top10_max']; $i++)
184         {
185                 // Prepare data for template
186                 $content = array(
187                         'sw'  => $SW,
188                         'idx' => $i
189                 );
190
191                 // Load row template
192                 $OUT .= LOAD_TEMPLATE("guest_top10_empty5", true, $content);
193                 $SW = 3 - $SW;
194         }
195 }
196 define('__TOP_REFERRAL_ROWS', $OUT);
197
198 // Remember other values in constants
199 define('__TOP10_MAX', $_CONFIG['top10_max']);
200
201 // Load final template
202 LOAD_TEMPLATE("guest_top10");
203
204 //
205 ?>