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