Updated copyright notice as there are changes in this year
[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  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2013 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         exit();
41 } // END - if
42
43 // Add description as navigation point
44 addYouAreHereLink('guest', __FILE__);
45
46 if ((!isExtensionActive('top10')) && (!isAdmin())) {
47         displayMessage('{%pipe,generateExtensionInactiveNotInstalledMessage=top10%}');
48         return;
49 } // END - if
50
51 // Init array
52 $rows = array();
53
54 // TOP logins
55 $result = SQL_QUERY("SELECT
56         `userid`,
57         `last_online`
58 FROM
59         `{?_MYSQL_PREFIX?}_user_data`
60 WHERE
61         `total_logins` > 0 AND
62         `status`='CONFIRMED'
63         " . runFilterChain('user_exclusion_sql', ' ') . "
64 ORDER BY
65         `total_logins` DESC
66 LIMIT {?top10_max?}", __FILE__, __LINE__);
67
68 $OUT = ''; $count = 1;
69 while ($content = SQL_FETCHARRAY($result)) {
70         // Prepare data for template
71         $content = array(
72                 'count'        => $count,
73                 'userid'       => $content['userid'],
74                 'last_online'  => generateDateTime($content['last_online'], '3'),
75         );
76
77         // Load row template
78         $OUT .= loadTemplate('guest_top10_row_login', TRUE, $content);
79
80         // Count one up
81         $count++;
82 } // END - while
83
84 if ($count < getTop10Max()) {
85         // Add more "blank" rows
86         for ($i = $count; $i <= getTop10Max(); $i++) {
87                 // Prepare data for template
88                 $content = array(
89                         'index' => $i
90                 );
91
92                 // Load row template
93                 $OUT .= loadTemplate('guest_top10_empty5', TRUE, $content);
94         } // END - for
95 } // END - if
96
97 // Remember the rows in array
98 $rows['logins_out'] = $OUT;
99
100 // Free result
101 SQL_FREERESULT($result);
102
103 // TOP earners
104 $result = SQL_QUERY("SELECT
105         `d`.`userid`,
106         SUM(`p`.`points` + `p`.`locked_points`) AS `points`,
107         `d`.`last_online`
108 FROM
109         `{?_MYSQL_PREFIX?}_user_data` AS `d`
110 LEFT JOIN
111         {?_MYSQL_PREFIX?}_user_points AS `p`
112 ON
113         `p`.`userid`=`d`.`userid`
114 WHERE
115         `p`.`points` > 0 AND
116         `d`.`status`='CONFIRMED'
117         " . runFilterChain('user_exclusion_sql', ' ') . "
118 GROUP BY
119         `p`.`userid`
120 ORDER BY
121         `points` DESC,
122         `d`.`last_online` DESC
123 LIMIT {?top10_max?}", __FILE__, __LINE__);
124
125 $OUT = ''; $count = 1;
126 while ($content = SQL_FETCHARRAY($result)) {
127         // Prepare data for template
128         $content['count']       = $count;
129         $content['last_online'] = generateDateTime($content['last_online'], '3');
130
131         // Load row template
132         $OUT .= loadTemplate('guest_top10_row_earner', TRUE, $content);
133
134         // Count one up
135         $count++;
136 } // END - while
137
138 if ($count < getTop10Max()) {
139         // Add more "blank" rows
140         for ($i = $count; $i <= getTop10Max(); $i++) {
141                 // Prepare data for template
142                 $content = array(
143                         'index' => $i
144                 );
145
146                 // Load row template
147                 $OUT .= loadTemplate('guest_top10_empty4', TRUE, $content);
148         } // END - for
149 } // END - if
150
151 // Remember the rows in array
152 $rows['points_out'] = $OUT;
153
154 // Free result
155 SQL_FREERESULT($result);
156
157 // TOP referral "hunter"
158 $result = SQL_QUERY("SELECT
159         `d`.`userid`,
160         SUM(`r`.`counter`) AS `refs`,
161         `d`.`last_online`
162 FROM
163         `{?_MYSQL_PREFIX?}_user_data` AS `d`
164 LEFT JOIN
165         {?_MYSQL_PREFIX?}_refsystem AS `r`
166 ON
167         `r`.`userid`=`d`.`userid`
168 WHERE
169         `r`.`counter` > 0 AND
170         `d`.`status`='CONFIRMED'
171         " . runFilterChain('user_exclusion_sql', ' ') . "
172 GROUP BY
173         `r`.`userid`
174 ORDER BY
175         `refs` DESC,
176         `d`.`last_online` DESC
177 LIMIT {?top10_max?}", __FILE__, __LINE__);
178
179 $OUT = ''; $count = 1;
180 while ($content = SQL_FETCHARRAY($result)) {
181         // Prepare data for template
182         $content = array(
183                 'count'       => $count,
184                 'userid'      => $content['userid'],
185                 'refs'        => $content['refs'],
186                 'last_online' => generateDateTime($content['last_online'], '3')
187         );
188
189         // Load row template
190         $OUT .= loadTemplate('guest_top10_row_refs', TRUE, $content);
191
192         // Count one up
193         $count++;
194 } // END - while
195
196 if ($count < getTop10Max()) {
197         // Add more "blank" rows
198         for ($i = $count; $i <= getTop10Max(); $i++) {
199                 // Prepare data for template
200                 $content = array(
201                         'index' => $i
202                 );
203
204                 // Load row template
205                 $OUT .= loadTemplate('guest_top10_empty5', TRUE, $content);
206         } // END - for
207 } // END - if
208
209 // Remember the rows in array
210 $rows['referrals_out'] = $OUT;
211
212 // Free result
213 SQL_FREERESULT($result);
214
215 // Load final template
216 loadTemplate('guest_top10', FALSE, $rows);
217
218 // [EOF]
219 ?>