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 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2012 by Mailer Developer Team *
20 * For more information visit: http://mxchange.org *
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. *
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. *
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, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
43 // Add description as navigation point
44 addYouAreHereLink('guest', __FILE__);
46 // This part only works if ext-user is active
47 if ((!isExtensionActive('user')) && (!isAdmin())) {
48 displayMessage('{%pipe,generateExtensionInactiveNotInstalledMessage=user%}');
52 // Determine which stats we want and set mode and title for the link below stats block
53 if (!isGetRequestElementSet('do')) {
54 setGetRequestElement('do', strtolower(getConfig('guest_stats')));
57 // Set config temporarily
58 setConfigEntry('guest_stats', strtoupper(getRequestElement('do')));
60 switch (getRequestElement('do')) {
75 reportBug(__FILE__, __LINE__, sprintf("Unsupported mode <span class=\"data\">%s</span> detected.", secureString(getRequestElement('do'))));
80 $ltitle = '{--GUEST_STATS_' . strtoupper($lmode) . '--}';
82 // @TODO This can be rewritten in a dynamic include
83 switch (getConfig('guest_stats')) {
84 case 'MEMBERS': // Statistics about your members
85 // Only males / females
86 $male = countSumTotalData('M', 'user_data', 'userid', 'gender', TRUE, runFilterChain('user_exclusion_sql', " AND `status`='CONFIRMED'"));
87 $female = countSumTotalData('F', 'user_data', 'userid', 'gender', TRUE, runFilterChain('user_exclusion_sql', " AND `status`='CONFIRMED'"));
91 for ($idx = 1; $idx < 13; $idx++) {
92 // Copy it so we don't touch the for() loop index
95 // Append leading zero
101 $months[$month] = countSumTotalData(bigintval($month), 'user_data', 'userid', 'birth_month', TRUE, runFilterChain('user_exclusion_sql', " AND `status`='CONFIRMED'"));
104 // Members in categories
105 $result = SQL_QUERY("SELECT `id`, `cat` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `visible`='Y' ORDER BY `id` ASC", __FILE__, __LINE__);
107 // Load categories first
108 $cats = array(); $cat_cnt = array();
110 // @TODO This can be somehow rewritten
111 while ($content = SQL_FETCHARRAY($result)) {
113 $cats[$content['id']] = $content['cat'];
116 // Now we have all categories loaded, count members
117 foreach ($cats as $id => $dummy) {
118 // We only need id and nothing more to count...
119 $cat_cnt[$id] = countSumTotalData(bigintval($id), 'user_cats', 'id', 'cat_id', TRUE);
122 // Prepare data for the template
123 $content['total_users'] = ($male + $female);
124 $content['unconfirmed'] = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `status` != 'CONFIRMED'", __FILE__, __LINE__));
125 $content['total_males'] = $male;
126 $content['total_females'] = $female;
127 $content['tmem_count'] = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `last_online` >= {?START_TDAY?}" . runFilterChain('user_exclusion_sql', " AND `status`='CONFIRMED'"), __FILE__, __LINE__));
128 $content['ymem_count'] = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `last_online` >= {?START_YDAY?} AND `last_online` < {?START_TDAY?}" . runFilterChain('user_exclusion_sql', " AND `status`='CONFIRMED'"), __FILE__, __LINE__));
129 $content['treg_count'] = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `joined` >= {?START_TDAY?}", __FILE__, __LINE__));
130 $content['yreg_count'] = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `joined` >= {?START_YDAY?} AND `joined` < {?START_TDAY?}", __FILE__, __LINE__));
131 $content['lmode'] = $lmode;
132 $content['ltitle'] = $ltitle;
134 // Generate monthly stats
135 $SW = 2; $r2 = ' right'; $l = 'll'; $r = 'lr'; $OUT = '';
136 foreach ($months as $month => $count) {
137 if ($SW == 2) $OUT .= '<tr>';
139 // Prepare data for template
142 'm_descr' => $GLOBALS['month_descr'][$month],
149 $OUT .= loadTemplate('guest_stats_month_row', TRUE, $row);
153 $l = 'rl'; $r = 'rr';
157 $l = 'll'; $r = 'lr';
161 $content['month_rows'] = $OUT;
163 // Generate category stats
165 foreach ($cat_cnt as $id => $count) {
166 // Prepare data for the template
172 // Load row template and switch colors
173 $OUT .= loadTemplate('guest_stats_cats_row', TRUE, $row);
175 $content['cats_rows'] = $OUT;
177 // Load final template
178 loadTemplate('guest_stats_member', FALSE, $content);
181 case 'MODULES': // TOP10 module clicks
182 // Admins may see all menus
183 $AND = " AND `locked`='N' AND `visible`='Y'";
184 if (isAdmin()) $AND = '';
186 // Query for guest and member menus
187 $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__);
188 $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__);
191 if (!SQL_HASZERONUMS($guest_t10)) {
193 $OUT .= loadTemplate('guest_stats_header', TRUE, '{--GUEST_TOP_GUEST_STATS--}');
194 while ($content = SQL_FETCHARRAY($guest_t10)) {
196 $OUT .= loadTemplate('guest_stats_row', TRUE, $content);
200 if (!SQL_HASZERONUMS($mem_t10)) {
202 $OUT .= loadTemplate('guest_stats_header', TRUE, '{--GUEST_TOP_MEMBER_STATS--}');
203 while ($content = SQL_FETCHARRAY($mem_t10)) {
205 $OUT .= loadTemplate('guest_stats_row', TRUE, $content);
209 if ((!SQL_HASZERONUMS($guest_t10)) || (!SQL_HASZERONUMS($mem_t10))) {
217 // Load final template
218 loadTemplate('guest_stats_table', FALSE, $content);
220 // No clicks detected
221 displayMessage('{--GUEST_STATS_NO_CLICKS--}');
225 case 'INACTIVE': // Deactivated stats
226 displayMessage('{--GUEST_STATS_DEACTIVATED--}');