2 /************************************************************************
3 * MXChange v0.2.1 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 * For more information visit: http://www.mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
44 // Add description as navigation point
45 addMenuDescription('guest', __FILE__);
47 // Derterminate which stats we want and set mode and title for the link below stats block
48 if (!isGetRequestElementSet('mode')) setRequestGetElement('mode', strtolower(getConfig('guest_stats')));
50 // Set config temporarily
51 setConfigEntry('guest_stats', strtoupper(getRequestElement('mode')));
53 switch (getRequestElement('mode')) {
68 debug_report_bug(sprintf("Unsupported mode <strong>%s</strong> detected.", secureString(getRequestElement('mode'))));
73 $ltitle = getMessage('GUEST_STATS_' . strtoupper($lmode));
75 // @TODO This can be rewritten in a dynamic include
76 switch (getConfig('guest_stats')) {
77 case 'MEMBERS': // Statistics about your members
78 // Members yesterday / today online
79 $ymem = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `last_online` >= ".getConfig('START_YDAY')." AND `last_online` < ".getConfig('START_TDAY')." AND `status`='CONFIRMED'", __FILE__, __LINE__));
80 $tmem = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `last_online` >= ".getConfig('START_TDAY')." AND `status`='CONFIRMED'", __FILE__, __LINE__));
82 // Yesterday / today registered
83 $yreg = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `joined` >= ".getConfig('START_YDAY')." AND `joined` < ".getConfig('START_TDAY'), __FILE__, __LINE__));
84 $treg = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `joined` >= ".getConfig('START_TDAY'), __FILE__, __LINE__));
86 // Only males / females
87 $male = countSumTotalData('M', 'user_data', 'userid', 'gender', true, " AND `status`='CONFIRMED'");
88 $female = countSumTotalData('F', 'user_data', 'userid', 'gender', true, " AND `status`='CONFIRMED'");
90 // Unconfirmed accounts
91 $unconfirmed = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `status` != 'CONFIRMED'", __FILE__, __LINE__));
94 $total = $male + $female;
98 for ($idx = 1; $idx < 13; $idx++) {
99 // Copy it so we don't touch the for() loop index
102 // Append leading zero
103 if ($idx < 10) $month = '0' . $idx;
106 $months[$month] = countSumTotalData(bigintval($month), 'user_data', 'userid', 'birth_month', true, " AND `status`='CONFIRMED'");
109 // Members in categories
110 $result = SQL_QUERY("SELECT `id`, `cat` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `visible`='Y' ORDER BY `id` ASC", __FILE__, __LINE__);
112 // Load categories first
113 $cats = array(); $cat_cnt = array();
115 // @TODO This can be somehow rewritten
116 while ($content = SQL_FETCHARRAY($result)) {
118 $cats[$content['id']] = $content['cat'];
121 // Now we have all categories loaded, count members
122 foreach ($cats as $id => $dummy) {
123 // We only need id and nothing more to count...
124 $cat_cnt[$id] = countSumTotalData(bigintval($id), 'user_cats', 'id', 'cat_id', true);
127 // Prepare data for the template
128 $content['total_users'] = $total;
129 $content['unconfirmed'] = $unconfirmed;
130 $content['total_males'] = $male;
131 $content['total_females'] = $female;
132 $content['tmem_count'] = $tmem;
133 $content['ymem_count'] = $ymem;
134 $content['treg_count'] = $treg;
135 $content['yreg_count'] = $yreg;
136 $content['lmode'] = $lmode;
137 $content['ltitle'] = $ltitle;
139 // Generate monthly stats
140 $SW = 2; $r2 = ' right2'; $l = 'll'; $r = 'lr'; $OUT = '';
141 foreach ($months as $month => $cnt) {
142 if ($SW == 2) $OUT .= "<tr>\n";
144 // Prepare data for template
147 'm_descr' => $GLOBALS['month_descr'][$month],
154 $OUT .= loadTemplate('guest_stats_month_row', true, $data);
158 $l = 'rl'; $r = 'rr';
162 $l = 'll'; $r = 'lr';
166 $content['month_rows'] = $OUT;
168 // Generate category stats
170 foreach ($cat_cnt as $id => $cnt) {
171 // Prepare data for the template
178 // Load row template and switch colors
179 $OUT .= loadTemplate('guest_stats_cats_row', true, $data);
182 $content['cats_rows'] = $OUT;
184 // Load final template
185 loadTemplate('guest_stats_member', false, $content);
188 case 'MODULES': // TOP10 module clicks
189 // Admins may see all menus
190 $AND = " AND `locked`='N' AND `visible`='Y'";
191 if (isAdmin()) $AND = '';
193 // Query for guest and member menus
194 $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__);
195 $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__);
198 if (SQL_NUMROWS($guest_t10) > 0) {
200 $OUT .= loadTemplate('guest_stats_header', true, getMessage('GUEST_TOP_GUEST_STATS'));
202 while ($content = SQL_FETCHARRAY($guest_t10)) {
203 $content['sw'] = $SW;
206 $OUT .= loadTemplate('guest_stats_row', true, $content);
211 if (SQL_NUMROWS($mem_t10) > 0) {
213 $OUT .= loadTemplate('guest_stats_header', true, getMessage('GUEST_TOP_MEMBER_STATS'));
215 while ($content = SQL_FETCHARRAY($mem_t10)) {
216 $content['sw'] = $SW;
219 $OUT .= loadTemplate('guest_stats_row', true, $content);
224 if ((SQL_NUMROWS($guest_t10) > 0) || (SQL_NUMROWS($mem_t10) > 0)) {
232 // Load final template
233 loadTemplate('guest_stats_table', false, $content);
235 // No clicks detected
236 loadTemplate('admin_settings_saved', false, getMessage('GUEST_STATS_NO_CLICKS'));
240 case 'INACTIVE': // Deactivated stats
241 loadTemplate('admin_settings_saved', false, getMessage('GUEST_STATS_DEACTIVATED'));