2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 12/14/2003 *
4 * =================== Last change: 08/22/2004 *
6 * -------------------------------------------------------------------- *
7 * File : what-stats.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Statistics *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Statistiken *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
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 *
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. *
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. *
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, *
38 ************************************************************************/
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
45 // Add description as navigation point
46 addMenuDescription('guest', __FILE__);
48 // Derterminate which stats we want and set mode and title for the link below stats block
49 if (!isGetRequestParameterSet('mode')) setGetRequestParameter('mode', strtolower(getConfig('guest_stats')));
51 // Set config temporarily
52 setConfigEntry('guest_stats', strtoupper(getRequestParameter('mode')));
54 switch (getRequestParameter('mode')) {
69 debug_report_bug(__FILE__, __LINE__, sprintf("Unsupported mode <span class=\"data\">%s</span> detected.", secureString(getRequestParameter('mode'))));
74 $ltitle = '{--GUEST_STATS_' . strtoupper($lmode) . '--}';
76 // @TODO This can be rewritten in a dynamic include
77 switch (getConfig('guest_stats')) {
78 case 'MEMBERS': // Statistics about your members
79 // Members yesterday / today online
80 $ymem = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `last_online` >= {?START_YDAY?} AND `last_online` < {?START_TDAY?} AND `status`='CONFIRMED'", __FILE__, __LINE__));
81 $tmem = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `last_online` >= {?START_TDAY?} AND `status`='CONFIRMED'", __FILE__, __LINE__));
83 // Yesterday / today registered
84 $yreg = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `joined` >= {?START_YDAY?} AND `joined` < {?START_TDAY?}", __FILE__, __LINE__));
85 $treg = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `joined` >= {?START_TDAY?}", __FILE__, __LINE__));
87 // Only males / females
88 $male = countSumTotalData('M', 'user_data', 'userid', 'gender', true, " AND `status`='CONFIRMED'");
89 $female = countSumTotalData('F', 'user_data', 'userid', 'gender', true, " AND `status`='CONFIRMED'");
91 // Unconfirmed accounts
92 $unconfirmed = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `status` != 'CONFIRMED'", __FILE__, __LINE__));
95 $total = $male + $female;
99 for ($idx = 1; $idx < 13; $idx++) {
100 // Copy it so we don't touch the for() loop index
103 // Append leading zero
104 if ($idx < 10) $month = '0' . $idx;
107 $months[$month] = countSumTotalData(bigintval($month), 'user_data', 'userid', 'birth_month', true, " AND `status`='CONFIRMED'");
110 // Members in categories
111 $result = SQL_QUERY("SELECT `id`, `cat` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `visible`='Y' ORDER BY `id` ASC", __FILE__, __LINE__);
113 // Load categories first
114 $cats = array(); $cat_cnt = array();
116 // @TODO This can be somehow rewritten
117 while ($content = SQL_FETCHARRAY($result)) {
119 $cats[$content['id']] = $content['cat'];
122 // Now we have all categories loaded, count members
123 foreach ($cats as $id => $dummy) {
124 // We only need id and nothing more to count...
125 $cat_cnt[$id] = countSumTotalData(bigintval($id), 'user_cats', 'id', 'cat_id', true);
128 // Prepare data for the template
129 $content['total_users'] = $total;
130 $content['unconfirmed'] = $unconfirmed;
131 $content['total_males'] = $male;
132 $content['total_females'] = $female;
133 $content['tmem_count'] = $tmem;
134 $content['ymem_count'] = $ymem;
135 $content['treg_count'] = $treg;
136 $content['yreg_count'] = $yreg;
137 $content['lmode'] = $lmode;
138 $content['ltitle'] = $ltitle;
140 // Generate monthly stats
141 $SW = 2; $r2 = ' right'; $l = 'll'; $r = 'lr'; $OUT = '';
142 foreach ($months as $month => $cnt) {
143 if ($SW == 2) $OUT .= "<tr>\n";
145 // Prepare data for template
148 'm_descr' => $GLOBALS['month_descr'][$month],
155 $OUT .= loadTemplate('guest_stats_month_row', true, $data);
159 $l = 'rl'; $r = 'rr';
163 $l = 'll'; $r = 'lr';
167 $content['month_rows'] = $OUT;
169 // Generate category stats
171 foreach ($cat_cnt as $id => $cnt) {
172 // Prepare data for the template
178 // Load row template and switch colors
179 $OUT .= loadTemplate('guest_stats_cats_row', true, $data);
181 $content['cats_rows'] = $OUT;
183 // Load final template
184 loadTemplate('guest_stats_member', false, $content);
187 case 'MODULES': // TOP10 module clicks
188 // Admins may see all menus
189 $AND = " AND `locked`='N' AND `visible`='Y'";
190 if (isAdmin()) $AND = '';
192 // Query for guest and member menus
193 $guest_t10 = SQL_QUERY("SELECT `counter`, `title` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE `counter` > 0".$AND." ORDER BY `counter` DESC LIMIT 0,10", __FILE__, __LINE__);
194 $mem_t10 = SQL_QUERY("SELECT `counter`, `title` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `counter` > 0".$AND." ORDER BY `counter` DESC LIMIT 0,10", __FILE__, __LINE__);
197 if (SQL_NUMROWS($guest_t10) > 0) {
199 $OUT .= loadTemplate('guest_stats_header', true, '{--GUEST_TOP_GUEST_STATS--}');
200 while ($content = SQL_FETCHARRAY($guest_t10)) {
202 $OUT .= loadTemplate('guest_stats_row', true, $content);
206 if (SQL_NUMROWS($mem_t10) > 0) {
208 $OUT .= loadTemplate('guest_stats_header', true, '{--GUEST_TOP_MEMBER_STATS--}');
209 while ($content = SQL_FETCHARRAY($mem_t10)) {
211 $OUT .= loadTemplate('guest_stats_row', true, $content);
215 if ((SQL_NUMROWS($guest_t10) > 0) || (SQL_NUMROWS($mem_t10) > 0)) {
223 // Load final template
224 loadTemplate('guest_stats_table', false, $content);
226 // No clicks detected
227 loadTemplate('admin_settings_saved', false, '{--GUEST_STATS_NO_CLICKS--}');
231 case 'INACTIVE': // Deactivated stats
232 loadTemplate('admin_settings_saved', false, '{--GUEST_STATS_DEACTIVATED--}');