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, 2010 by Mailer Developer Team *
20 * For more information visit: http://www.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 addMenuDescription('guest', __FILE__);
46 // Derterminate which stats we want and set mode and title for the link below stats block
47 if (!isGetRequestParameterSet('mode')) setGetRequestParameter('mode', strtolower(getConfig('guest_stats')));
49 // Set config temporarily
50 setConfigEntry('guest_stats', strtoupper(getRequestParameter('mode')));
52 switch (getRequestParameter('mode')) {
67 debug_report_bug(__FILE__, __LINE__, sprintf("Unsupported mode <span class=\"data\">%s</span> detected.", secureString(getRequestParameter('mode'))));
72 $ltitle = '{--GUEST_STATS_' . strtoupper($lmode) . '--}';
74 // @TODO This can be rewritten in a dynamic include
75 switch (getConfig('guest_stats')) {
76 case 'MEMBERS': // Statistics about your members
77 // Only males / females
78 $male = countSumTotalData('M', 'user_data', 'userid', 'gender', true, " AND `status`='CONFIRMED'");
79 $female = countSumTotalData('F', 'user_data', 'userid', 'gender', true, " AND `status`='CONFIRMED'");
83 for ($idx = 1; $idx < 13; $idx++) {
84 // Copy it so we don't touch the for() loop index
87 // Append leading zero
88 if ($idx < 10) $month = '0' . $idx;
91 $months[$month] = countSumTotalData(bigintval($month), 'user_data', 'userid', 'birth_month', true, " AND `status`='CONFIRMED'");
94 // Members in categories
95 $result = SQL_QUERY("SELECT `id`, `cat` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `visible`='Y' ORDER BY `id` ASC", __FILE__, __LINE__);
97 // Load categories first
98 $cats = array(); $cat_cnt = array();
100 // @TODO This can be somehow rewritten
101 while ($content = SQL_FETCHARRAY($result)) {
103 $cats[$content['id']] = $content['cat'];
106 // Now we have all categories loaded, count members
107 foreach ($cats as $id => $dummy) {
108 // We only need id and nothing more to count...
109 $cat_cnt[$id] = countSumTotalData(bigintval($id), 'user_cats', 'id', 'cat_id', true);
112 // Prepare data for the template
113 $content['total_users'] = ($male + $female);
114 $content['unconfirmed'] = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `status` != 'CONFIRMED'", __FILE__, __LINE__));
115 $content['total_males'] = $male;
116 $content['total_females'] = $female;
117 $content['tmem_count'] = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `last_online` >= {?START_TDAY?} AND `status`='CONFIRMED'", __FILE__, __LINE__));
118 $content['ymem_count'] = 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__));
119 $content['treg_count'] = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `joined` >= {?START_TDAY?}", __FILE__, __LINE__));
120 $content['yreg_count'] = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `joined` >= {?START_YDAY?} AND `joined` < {?START_TDAY?}", __FILE__, __LINE__));
121 $content['lmode'] = $lmode;
122 $content['ltitle'] = $ltitle;
124 // Generate monthly stats
125 $SW = 2; $r2 = ' right'; $l = 'll'; $r = 'lr'; $OUT = '';
126 foreach ($months as $month => $cnt) {
127 if ($SW == 2) $OUT .= '<tr>';
129 // Prepare data for template
132 'm_descr' => $GLOBALS['month_descr'][$month],
139 $OUT .= loadTemplate('guest_stats_month_row', true, $data);
143 $l = 'rl'; $r = 'rr';
147 $l = 'll'; $r = 'lr';
151 $content['month_rows'] = $OUT;
153 // Generate category stats
155 foreach ($cat_cnt as $id => $cnt) {
156 // Prepare data for the template
162 // Load row template and switch colors
163 $OUT .= loadTemplate('guest_stats_cats_row', true, $data);
165 $content['cats_rows'] = $OUT;
167 // Load final template
168 loadTemplate('guest_stats_member', false, $content);
171 case 'MODULES': // TOP10 module clicks
172 // Admins may see all menus
173 $AND = " AND `locked`='N' AND `visible`='Y'";
174 if (isAdmin()) $AND = '';
176 // Query for guest and member menus
177 $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__);
178 $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__);
181 if (!SQL_HASZERONUMS($guest_t10)) {
183 $OUT .= loadTemplate('guest_stats_header', true, '{--GUEST_TOP_GUEST_STATS--}');
184 while ($content = SQL_FETCHARRAY($guest_t10)) {
186 $OUT .= loadTemplate('guest_stats_row', true, $content);
190 if (!SQL_HASZERONUMS($mem_t10)) {
192 $OUT .= loadTemplate('guest_stats_header', true, '{--GUEST_TOP_MEMBER_STATS--}');
193 while ($content = SQL_FETCHARRAY($mem_t10)) {
195 $OUT .= loadTemplate('guest_stats_row', true, $content);
199 if ((!SQL_HASZERONUMS($guest_t10)) || (!SQL_HASZERONUMS($mem_t10))) {
207 // Load final template
208 loadTemplate('guest_stats_table', false, $content);
210 // No clicks detected
211 loadTemplate('admin_settings_saved', false, '{--GUEST_STATS_NO_CLICKS--}');
215 case 'INACTIVE': // Deactivated stats
216 loadTemplate('admin_settings_saved', false, '{--GUEST_STATS_DEACTIVATED--}');