New functions introduced, several rewrites:
[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  * 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         die();
42 } // END - if
43
44 // Add description as navigation point
45 addMenuDescription('guest', __FILE__);
46
47 if ((!isExtensionActive('top10')) && (!isAdmin())) {
48         loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('top10'));
49         return;
50 } // END - if
51
52 // Init array
53 $rows = array();
54
55 //// TOP logins
56 $result = SQL_QUERY("SELECT
57         `userid`, `total_logins`, `last_online`
58 FROM
59         `{?_MYSQL_PREFIX?}_user_data`
60 WHERE
61         `total_logins` > 0 AND
62         `status`='CONFIRMED'
63 ORDER BY
64         `total_logins` DESC
65 LIMIT {?top10_max?}", __FILE__, __LINE__);
66
67 $OUT = ''; $SW = 2; $cnt = 1;
68 while ($content = SQL_FETCHARRAY($result)) {
69         // Init nickname
70         $content['nickname'] = '---';
71
72         // Get nickname
73         if (isExtensionActive('nickname')) $content['nickname'] = getNickname($content['userid']);
74
75         // Prepare data for template
76         $content = array(
77                 'sw'           => $SW,
78                 'cnt'          => $cnt,
79                 'userid'       => $content['userid'],
80                 'nickname'     => $content['nickname'],
81                 'total_logins' => $content['total_logins'],
82                 'points'       => translateComma(countSumTotalData($content['userid'], 'user_points', 'points')),
83                 'last_online'  => generateDateTime($content['last_online'], 3),
84         );
85
86         // Load row template
87         $OUT .= loadTemplate('guest_top10_row_login', true, $content);
88
89         // Switch colors and count one up
90         $SW = 3 - $SW; $cnt++;
91 } // END - while
92
93 if ($cnt < getConfig('top10_max')) {
94         // Add more "blank" rows
95         for ($i = $cnt; $i <= getConfig('top10_max'); $i++) {
96                 // Prepare data for template
97                 $content = array(
98                         'sw'    => $SW,
99                         'index' => $i
100                 );
101
102                 // Load row template
103                 $OUT .= loadTemplate('guest_top10_empty5', true, $content);
104                 $SW = 3 - $SW;
105         } // END - for
106 } // END - if
107
108 // Remember the rows in array
109 $rows['logins_out'] = $OUT;
110
111 // Free result
112 SQL_FREERESULT($result);
113
114 //// TOP earners
115 $result = SQL_QUERY("SELECT
116         d.userid,
117         (SUM(p.points) - d.used_points) AS points,
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         points DESC,
132         d.last_online DESC
133 LIMIT {?top10_max?}", __FILE__, __LINE__);
134
135 $OUT = ''; $SW = 2; $cnt = 1;
136 while ($content = SQL_FETCHARRAY($result)) {
137         // Init nickname
138         $content['nickname'] = '---';
139
140         // Get nickname
141         if (isExtensionActive('nickname')) $content['nickname'] = getNickname($content['userid']);
142
143         // Prepare data for template
144         $content = array(
145                 'sw'          => $SW,
146                 'cnt'         => $cnt,
147                 'userid'      => $content['userid'],
148                 'nickname'    => $content['nickname'],
149                 'points'      => translateComma($content['points']),
150                 'last_online' => generateDateTime($content['last_online'], 3)
151         );
152
153         // Load row template
154         $OUT .= loadTemplate('guest_top10_row_earner', true, $content);
155
156         // Switch colors and count one up
157         $SW = 3 - $SW; $cnt++;
158 } // END - while
159
160 if ($cnt < getConfig('top10_max')) {
161         // Add more "blank" rows
162         for ($i = $cnt; $i <= getConfig('top10_max'); $i++) {
163                 // Prepare data for template
164                 $content = array(
165                         'sw'    => $SW,
166                         'index' => $i
167                 );
168
169                 // Load row template
170                 $OUT .= loadTemplate('guest_top10_empty4', true, $content);
171                 $SW = 3 - $SW;
172         } // END - for
173 } // END - if
174
175 // Remember the rows in array
176 $rows['points_out'] = $OUT;
177
178 // Free result
179 SQL_FREERESULT($result);
180
181 //// TOP referal "hunter"
182 $result = SQL_QUERY("SELECT
183         d.userid,
184         SUM(r.counter) AS refs,
185         d.last_online
186 FROM
187         `{?_MYSQL_PREFIX?}_user_data` AS d
188 LEFT JOIN
189         {?_MYSQL_PREFIX?}_refsystem AS r
190 ON
191         r.userid=d.userid
192 WHERE
193         r.counter > 0 AND
194         d.`status`='CONFIRMED'
195 GROUP BY
196         r.userid
197 ORDER BY
198         refs DESC,
199         d.last_online DESC
200 LIMIT {?top10_max?}", __FILE__, __LINE__);
201
202 $OUT = ''; $SW = 2; $cnt = 1;
203 while ($content = SQL_FETCHARRAY($result)) {
204         // Init nickname
205         $content['nickname'] = '---';
206
207         // Get nickname
208         if (isExtensionActive('nickname')) $content['nickname'] = getNickname($content['userid']);
209
210         // Prepare data for template
211         $content = array(
212                 'sw'          => $SW,
213                 'cnt'         => $cnt,
214                 'userid'      => $content['userid'],
215                 'refs'        => $content['refs'],
216                 'nickname'    => $content['nickname'],
217                 'points'      => translateComma(countSumTotalData($content['userid'], 'user_points', 'points')),
218                 'last_online' => generateDateTime($content['last_online'], 3)
219         );
220
221         // Load row template
222         $OUT .= loadTemplate('guest_top10_row_refs', true, $content);
223
224         // Switch colors and count one up
225         $SW = 3 - $SW; $cnt++;
226 } // END - while
227
228 if ($cnt < getConfig('top10_max')) {
229         // Add more "blank" rows
230         for ($i = $cnt; $i <= getConfig('top10_max'); $i++) {
231                 // Prepare data for template
232                 $content = array(
233                         'sw'    => $SW,
234                         'index' => $i
235                 );
236
237                 // Load row template
238                 $OUT .= loadTemplate('guest_top10_empty5', true, $content);
239                 $SW = 3 - $SW;
240         } // END - for
241 } // END - if
242
243 // Remember the rows in array
244 $rows['referals_out'] = $OUT;
245
246 // Free result
247 SQL_FREERESULT($result);
248
249 // Load final template
250 loadTemplate('guest_top10', false, $rows);
251
252 // [EOF]
253 ?>