New wrapper function introduced, more EL 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  * 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 = ''; $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                 'cnt'          => $cnt,
79                 'userid'       => $content['userid'],
80                 'nickname'     => $content['nickname'],
81                 'total_logins' => $content['total_logins'],
82                 'points'       => getTotalPoints($content['userid']),
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         // Count one up
90         $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                         'index' => $i
99                 );
100
101                 // Load row template
102                 $OUT .= loadTemplate('guest_top10_empty5', true, $content);
103         } // END - for
104 } // END - if
105
106 // Remember the rows in array
107 $rows['logins_out'] = $OUT;
108
109 // Free result
110 SQL_FREERESULT($result);
111
112 //// TOP earners
113 $result = SQL_QUERY("SELECT
114         d.userid,
115         (SUM(p.points) - d.used_points) AS points,
116         d.last_online
117 FROM
118         `{?_MYSQL_PREFIX?}_user_data` AS d
119 LEFT JOIN
120         {?_MYSQL_PREFIX?}_user_points AS p
121 ON
122         p.userid=d.userid
123 WHERE
124         p.points > 0 AND
125         d.`status`='CONFIRMED'
126 GROUP BY
127         p.userid
128 ORDER BY
129         points DESC,
130         d.last_online DESC
131 LIMIT {?top10_max?}", __FILE__, __LINE__);
132
133 $OUT = ''; $cnt = 1;
134 while ($content = SQL_FETCHARRAY($result)) {
135         // Init nickname
136         $content['nickname'] = '';
137
138         // Get nickname
139         if (isExtensionActive('nickname')) $content['nickname'] = getNickname($content['userid']);
140
141         // Prepare data for template
142         $content = array(
143                 'cnt'         => $cnt,
144                 'userid'      => $content['userid'],
145                 'nickname'    => $content['nickname'],
146                 'points'      => $content['points'],
147                 'last_online' => generateDateTime($content['last_online'], 3)
148         );
149
150         // Load row template
151         $OUT .= loadTemplate('guest_top10_row_earner', true, $content);
152
153         // Count one up
154         $cnt++;
155 } // END - while
156
157 if ($cnt < getConfig('top10_max')) {
158         // Add more "blank" rows
159         for ($i = $cnt; $i <= getConfig('top10_max'); $i++) {
160                 // Prepare data for template
161                 $content = array(
162                         'index' => $i
163                 );
164
165                 // Load row template
166                 $OUT .= loadTemplate('guest_top10_empty4', true, $content);
167         } // END - for
168 } // END - if
169
170 // Remember the rows in array
171 $rows['points_out'] = $OUT;
172
173 // Free result
174 SQL_FREERESULT($result);
175
176 //// TOP referal "hunter"
177 $result = SQL_QUERY("SELECT
178         d.userid,
179         SUM(r.counter) AS refs,
180         d.last_online
181 FROM
182         `{?_MYSQL_PREFIX?}_user_data` AS d
183 LEFT JOIN
184         {?_MYSQL_PREFIX?}_refsystem AS r
185 ON
186         r.userid=d.userid
187 WHERE
188         r.counter > 0 AND
189         d.`status`='CONFIRMED'
190 GROUP BY
191         r.userid
192 ORDER BY
193         refs DESC,
194         d.last_online DESC
195 LIMIT {?top10_max?}", __FILE__, __LINE__);
196
197 $OUT = ''; $cnt = 1;
198 while ($content = SQL_FETCHARRAY($result)) {
199         // Init nickname
200         $content['nickname'] = '';
201
202         // Get nickname
203         if (isExtensionActive('nickname')) $content['nickname'] = getNickname($content['userid']);
204
205         // Prepare data for template
206         $content = array(
207                 'cnt'         => $cnt,
208                 'userid'      => $content['userid'],
209                 'refs'        => $content['refs'],
210                 'nickname'    => $content['nickname'],
211                 'points'      => getTotalPoints($content['userid']),
212                 'last_online' => generateDateTime($content['last_online'], 3)
213         );
214
215         // Load row template
216         $OUT .= loadTemplate('guest_top10_row_refs', true, $content);
217
218         // Count one up
219         $cnt++;
220 } // END - while
221
222 if ($cnt < getConfig('top10_max')) {
223         // Add more "blank" rows
224         for ($i = $cnt; $i <= getConfig('top10_max'); $i++) {
225                 // Prepare data for template
226                 $content = array(
227                         'index' => $i
228                 );
229
230                 // Load row template
231                 $OUT .= loadTemplate('guest_top10_empty5', true, $content);
232         } // END - for
233 } // END - if
234
235 // Remember the rows in array
236 $rows['referals_out'] = $OUT;
237
238 // Free result
239 SQL_FREERESULT($result);
240
241 // Load final template
242 loadTemplate('guest_top10', false, $rows);
243
244 // [EOF]
245 ?>