Copyright updated
[mailer.git] / 0.2.1 / inc / modules / guest / what-top10.php
1 <?php\r
2 /************************************************************************\r
3  * MXChange v0.2.1                                    Start: 11/24/2004 *\r
4  * ================                             Last change: 11/26/2004 *\r
5  *                                                                      *\r
6  * -------------------------------------------------------------------- *\r
7  * File              : what-top10.php                                   *\r
8  * -------------------------------------------------------------------- *\r
9  * Short description : TOP logins / best earner etc.                    *\r
10  * -------------------------------------------------------------------- *\r
11  * Kurzbeschreibung  : TOP-Logins / Bestverdiener usw.                  *\r
12  * -------------------------------------------------------------------- *\r
13  *                                                                      *\r
14  * -------------------------------------------------------------------- *\r
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *\r
16  * For more information visit: http://www.mxchange.org                  *\r
17  *                                                                      *\r
18  * This program is free software; you can redistribute it and/or modify *\r
19  * it under the terms of the GNU General Public License as published by *\r
20  * the Free Software Foundation; either version 2 of the License, or    *\r
21  * (at your option) any later version.                                  *\r
22  *                                                                      *\r
23  * This program is distributed in the hope that it will be useful,      *\r
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *\r
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *\r
26  * GNU General Public License for more details.                         *\r
27  *                                                                      *\r
28  * You should have received a copy of the GNU General Public License    *\r
29  * along with this program; if not, write to the Free Software          *\r
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *\r
31  * MA  02110-1301  USA                                                  *\r
32  ************************************************************************/\r
33 \r
34 // Some security stuff...\r
35 if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))\r
36 {\r
37         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php";\r
38         require($INC);\r
39 }\r
40  elseif ((!EXT_IS_ACTIVE("top10")) && (!IS_ADMIN()))\r
41 {\r
42         ADD_FATAL(EXTENSION_PROBLEM_EXT_INACTIVE, "top10");\r
43         return;\r
44 }\r
45 \r
46 // Add description as navigation point\r
47 ADD_DESCR("guest", basename(__FILE__));\r
48 \r
49 //// TOP logins\r
50 $ADD = "userid";\r
51 if (EXT_IS_ACTIVE("nickname")) $ADD = "nickname";\r
52 $result = SQL_QUERY_ESC("SELECT userid, ".$ADD.", total_logins, last_online\r
53 FROM "._MYSQL_PREFIX."_user_data\r
54 WHERE total_logins>0 AND status='CONFIRMED' ORDER BY total_logins DESC LIMIT %s",\r
55  array($CONFIG['top10_max']), __FILE__, __LINE__);\r
56 \r
57 $OUT = ""; $SW = 2; $cnt = 1;\r
58 while(list($uid, $nick, $logins, $last) = SQL_FETCHROW($result))\r
59 {\r
60         $nick2 = "---";\r
61         if (($nick != $uid) && (!empty($nick))) $nick2 = $nick;\r
62 \r
63         // Prepare data for template\r
64         $content = array(\r
65                 'sw'     => $SW,\r
66                 'cnt'    => $cnt,\r
67                 'uid'    => $uid,\r
68                 'nick'   => $nick2,\r
69                 'logins' => $logins,\r
70                 'points' => TRANSLATE_COMMA(GET_TOTAL_DATA($uid, "user_points", "points")),\r
71                 'last'   => MAKE_DATETIME($last, "3"),\r
72         );\r
73 \r
74         // Load row template\r
75         $OUT .= LOAD_TEMPLATE("guest_top10_row_login", true, $content);\r
76 \r
77         // Switch colors and count one up\r
78         $SW = 3 - $SW; $cnt++;\r
79 }\r
80 if ($cnt < $CONFIG['top10_max'])\r
81 {\r
82         // Add more "blank" rows\r
83         for ($i = $cnt; $i <= $CONFIG['top10_max']; $i++)\r
84         {\r
85                 // Prepare data for template\r
86                 $content = array(\r
87                         'sw'  => $SW,\r
88                         'idx' => $i\r
89                 );\r
90 \r
91                 // Load row template\r
92                 $OUT .= LOAD_TEMPLATE("guest_top10_empty5", true, $content);\r
93                 $SW = 3 - $SW;\r
94         }\r
95 }\r
96 define('__TOP_LOGINS_ROWS', $OUT);\r
97 \r
98 //// TOP earners\r
99 $result = SQL_QUERY_ESC("SELECT DISTINCT p.userid, d.".$ADD.", (SUM(p.points) - d.used_points) AS tpoints, d.last_online\r
100 FROM "._MYSQL_PREFIX."_user_points AS p\r
101 LEFT JOIN "._MYSQL_PREFIX."_user_data AS d\r
102 ON p.userid=d.userid\r
103 WHERE p.points > 0 AND d.status='CONFIRMED'\r
104 GROUP BY p.userid\r
105 ORDER BY tpoints DESC, d.last_online DESC\r
106 LIMIT %s",\r
107  array($CONFIG['top10_max']), __FILE__, __LINE__);\r
108 \r
109 $OUT = ""; $SW = 2; $cnt = 1;\r
110 while(list($uid, $nick, $points, $last) = SQL_FETCHROW($result))\r
111 {\r
112         $nick2 = "---";\r
113         if (($nick != $uid) && (!empty($nick))) $nick2 = $nick;\r
114 \r
115         // Prepare data for template\r
116         $content = array(\r
117                 'sw'     => $SW,\r
118                 'cnt'    => $cnt,\r
119                 'uid'    => bigintval($uid),\r
120                 'nick'   => $nick2,\r
121                 'points' => TRANSLATE_COMMA($points),\r
122                 'last'   => MAKE_DATETIME($last, "3")\r
123         );\r
124 \r
125         // Load row template\r
126         $OUT .= LOAD_TEMPLATE("guest_top10_row_earner", true, $content);\r
127 \r
128         // Switch colors and count one up\r
129         $SW = 3 - $SW; $cnt++;\r
130 }\r
131 if ($cnt < $CONFIG['top10_max'])\r
132 {\r
133         // Add more "blank" rows\r
134         for ($i = $cnt; $i <= $CONFIG['top10_max']; $i++)\r
135         {\r
136                 // Prepare data for template\r
137                 $content = array(\r
138                         'sw'  => $SW,\r
139                         'idx' => $i\r
140                 );\r
141 \r
142                 // Load row template\r
143                 $OUT .= LOAD_TEMPLATE("guest_top10_empty4", true, $content);\r
144                 $SW = 3 - $SW;\r
145         }\r
146 }\r
147 define('__TOP_POINTS_ROWS', $OUT);\r
148 \r
149 //// TOP referral "hunter"\r
150 $result = SQL_QUERY_ESC("SELECT DISTINCT r.userid, d.".$ADD.", SUM(r.counter) AS refs, d.last_online\r
151 FROM "._MYSQL_PREFIX."_refsystem AS r\r
152 LEFT JOIN "._MYSQL_PREFIX."_user_data AS d\r
153 ON r.userid=d.userid\r
154 WHERE r.counter > 0 AND d.status='CONFIRMED'\r
155 GROUP BY r.userid\r
156 ORDER BY refs DESC, d.last_online DESC\r
157 LIMIT %s",\r
158  array($CONFIG['top10_max']), __FILE__, __LINE__);\r
159 \r
160 $OUT = ""; $SW = 2; $cnt = 1;\r
161 while(list($uid, $nick, $refs, $last) = SQL_FETCHROW($result))\r
162 {\r
163         $nick2 = "---";\r
164         if (($nick != $uid) && (!empty($nick))) $nick2 = $nick;\r
165 \r
166         // Prepare data for template\r
167         $content = array(\r
168                 'sw'     => $SW,\r
169                 'cnt'    => $cnt,\r
170                 'uid'    => bigintval($uid),\r
171                 'refs'   => $refs,\r
172                 'nick'   => $nick2,\r
173                 'points' => TRANSLATE_COMMA(GET_TOTAL_DATA($uid, "user_points", "points")),\r
174                 'last'   => MAKE_DATETIME($last, "3")\r
175         );\r
176 \r
177         // Load row template\r
178         $OUT .= LOAD_TEMPLATE("guest_top10_row_refs", true, $content);\r
179 \r
180         // Switch colors and count one up\r
181         $SW = 3 - $SW; $cnt++;\r
182 }\r
183 if ($cnt < $CONFIG['top10_max'])\r
184 {\r
185         // Add more "blank" rows\r
186         for ($i = $cnt; $i <= $CONFIG['top10_max']; $i++)\r
187         {\r
188                 // Prepare data for template\r
189                 $content = array(\r
190                         'sw'  => $SW,\r
191                         'idx' => $i\r
192                 );\r
193 \r
194                 // Load row template\r
195                 $OUT .= LOAD_TEMPLATE("guest_top10_empty5", true, $content);\r
196                 $SW = 3 - $SW;\r
197         }\r
198 }\r
199 define('__TOP_REFERRAL_ROWS', $OUT);\r
200 \r
201 // Remember other values in constants\r
202 define('__TOP10_MAX', $CONFIG['top10_max']);\r
203 \r
204 // Load final template\r
205 LOAD_TEMPLATE("guest_top10");\r
206 \r
207 //\r
208 ?>\r