The yearly copyright-update commit. 2009, 2010 are now copyrighted on the developer...
[mailer.git] / inc / modules / guest / what-top10.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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 - 2009 by Roland Haeder                           *
21  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
42         die();
43 } // END - if
44
45 // Add description as navigation point
46 addMenuDescription('guest', __FILE__);
47
48 if ((!isExtensionActive('top10')) && (!isAdmin())) {
49         loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('top10'));
50         return;
51 } // END - if
52
53 // Init array
54 $rows = array();
55
56 //// TOP logins
57 $result = SQL_QUERY("SELECT
58         `userid`, `total_logins`, `last_online`
59 FROM
60         `{?_MYSQL_PREFIX?}_user_data`
61 WHERE
62         `total_logins` > 0 AND
63         `status`='CONFIRMED'
64 ORDER BY
65         `total_logins` DESC
66 LIMIT {?top10_max?}", __FILE__, __LINE__);
67
68 $OUT = ''; $SW = 2; $cnt = 1;
69 while ($content = SQL_FETCHARRAY($result)) {
70         // Init nickname
71         $content['nickname'] = '---';
72
73         // Get nickname
74         if (isExtensionActive('nickname')) $content['nickname'] = getNickname($content['userid']);
75
76         // Prepare data for template
77         $content = array(
78                 'sw'           => $SW,
79                 'cnt'          => $cnt,
80                 'userid'       => $content['userid'],
81                 'nickname'     => $content['nickname'],
82                 'total_logins' => $content['total_logins'],
83                 'points'       => translateComma(countSumTotalData($content['userid'], 'user_points', 'points')),
84                 'last_online'  => generateDateTime($content['last_online'], 3),
85         );
86
87         // Load row template
88         $OUT .= loadTemplate('guest_top10_row_login', true, $content);
89
90         // Switch colors and count one up
91         $SW = 3 - $SW; $cnt++;
92 } // END - while
93
94 if ($cnt < getConfig('top10_max')) {
95         // Add more "blank" rows
96         for ($i = $cnt; $i <= getConfig('top10_max'); $i++) {
97                 // Prepare data for template
98                 $content = array(
99                         'sw'    => $SW,
100                         'index' => $i
101                 );
102
103                 // Load row template
104                 $OUT .= loadTemplate('guest_top10_empty5', true, $content);
105                 $SW = 3 - $SW;
106         } // END - for
107 } // END - if
108
109 // Remember the rows in array
110 $rows['logins_out'] = $OUT;
111
112 // Free result
113 SQL_FREERESULT($result);
114
115 //// TOP earners
116 $result = SQL_QUERY("SELECT
117         d.userid,
118         (SUM(p.points) - d.used_points) AS points,
119         d.last_online
120 FROM
121         `{?_MYSQL_PREFIX?}_user_data` AS d
122 LEFT JOIN
123         {?_MYSQL_PREFIX?}_user_points AS p
124 ON
125         p.userid=d.userid
126 WHERE
127         p.points > 0 AND
128         d.`status`='CONFIRMED'
129 GROUP BY
130         p.userid
131 ORDER BY
132         points DESC,
133         d.last_online DESC
134 LIMIT {?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 (isExtensionActive('nickname')) $content['nickname'] = getNickname($content['userid']);
143
144         // Prepare data for template
145         $content = array(
146                 'sw'          => $SW,
147                 'cnt'         => $cnt,
148                 'userid'      => $content['userid'],
149                 'nickname'    => $content['nickname'],
150                 'points'      => translateComma($content['points']),
151                 'last_online' => generateDateTime($content['last_online'], 3)
152         );
153
154         // Load row template
155         $OUT .= loadTemplate('guest_top10_row_earner', true, $content);
156
157         // Switch colors and count one up
158         $SW = 3 - $SW; $cnt++;
159 } // END - while
160
161 if ($cnt < getConfig('top10_max')) {
162         // Add more "blank" rows
163         for ($i = $cnt; $i <= getConfig('top10_max'); $i++) {
164                 // Prepare data for template
165                 $content = array(
166                         'sw'    => $SW,
167                         'index' => $i
168                 );
169
170                 // Load row template
171                 $OUT .= loadTemplate('guest_top10_empty4', true, $content);
172                 $SW = 3 - $SW;
173         } // END - for
174 } // END - if
175
176 // Remember the rows in array
177 $rows['points_out'] = $OUT;
178
179 // Free result
180 SQL_FREERESULT($result);
181
182 //// TOP referal "hunter"
183 $result = SQL_QUERY("SELECT
184         d.userid,
185         SUM(r.counter) AS refs,
186         d.last_online
187 FROM
188         `{?_MYSQL_PREFIX?}_user_data` AS d
189 LEFT JOIN
190         {?_MYSQL_PREFIX?}_refsystem AS r
191 ON
192         r.userid=d.userid
193 WHERE
194         r.counter > 0 AND
195         d.`status`='CONFIRMED'
196 GROUP BY
197         r.userid
198 ORDER BY
199         refs DESC,
200         d.last_online DESC
201 LIMIT {?top10_max?}", __FILE__, __LINE__);
202
203 $OUT = ''; $SW = 2; $cnt = 1;
204 while ($content = SQL_FETCHARRAY($result)) {
205         // Init nickname
206         $content['nickname'] = '---';
207
208         // Get nickname
209         if (isExtensionActive('nickname')) $content['nickname'] = getNickname($content['userid']);
210
211         // Prepare data for template
212         $content = array(
213                 'sw'          => $SW,
214                 'cnt'         => $cnt,
215                 'userid'      => $content['userid'],
216                 'refs'        => $content['refs'],
217                 'nickname'    => $content['nickname'],
218                 'points'      => translateComma(countSumTotalData($content['userid'], 'user_points', 'points')),
219                 'last_online' => generateDateTime($content['last_online'], 3)
220         );
221
222         // Load row template
223         $OUT .= loadTemplate('guest_top10_row_refs', true, $content);
224
225         // Switch colors and count one up
226         $SW = 3 - $SW; $cnt++;
227 } // END - while
228
229 if ($cnt < getConfig('top10_max')) {
230         // Add more "blank" rows
231         for ($i = $cnt; $i <= getConfig('top10_max'); $i++) {
232                 // Prepare data for template
233                 $content = array(
234                         'sw'    => $SW,
235                         'index' => $i
236                 );
237
238                 // Load row template
239                 $OUT .= loadTemplate('guest_top10_empty5', true, $content);
240                 $SW = 3 - $SW;
241         } // END - for
242 } // END - if
243
244 // Remember the rows in array
245 $rows['referals_out'] = $OUT;
246
247 // Free result
248 SQL_FREERESULT($result);
249
250 // Load final template
251 loadTemplate('guest_top10', false, $rows);
252
253 // [EOF]
254 ?>