Updated copyright notice as there are changes in this year
[mailer.git] / inc / modules / guest / what-stats.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 12/14/2003 *
4  * ===================                          Last change: 08/22/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-stats.php                                   *
8  * -------------------------------------------------------------------- *
9  * Short description : Statistics                                       *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Statistiken                                      *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2013 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
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.                                  *
26  *                                                                      *
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.                         *
31  *                                                                      *
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,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         exit();
41 } // END - if
42
43 // Add description as navigation point
44 addYouAreHereLink('guest', __FILE__);
45
46 // This part only works if ext-user is active
47 if ((!isExtensionActive('user')) && (!isAdmin())) {
48         displayMessage('{%pipe,generateExtensionInactiveNotInstalledMessage=user%}');
49         return;
50 } // END - if
51
52 // Default mode is from config
53 $do = getConfig('guest_stats');
54
55 // Determine which stats are wanted and set mode and title for the link below stats block
56 if (isGetRequestElementSet('do')) {
57         // Use it from get value
58         $do = strtoupper(getRequestElement('do'));
59 } // END - if
60
61 switch ($do) {
62         case 'MEMBERS' :
63                 $lmode = 'MODULES';
64                 break;
65
66         case 'MODULES' :
67                 $lmode = 'MEMBERS';
68                 break;
69
70         case 'INACTIVE':
71                 $lmode = 'INACTIVE';
72                 break;
73
74         default:
75                 // Unsupported mode
76                 reportBug(__FILE__, __LINE__, sprintf("Unsupported mode <span class=\"data\">%s</span> detected.", SQL_ESCAPE($do)));
77                 break;
78 } // END - switch
79
80 // Set link title
81 $ltitle = '{--GUEST_STATS_' . $lmode . '--}';
82
83 // @TODO This can be rewritten in a dynamic include
84 switch (strtoupper($do)) {
85         case 'MEMBERS': // Statistics about your members
86                 // Only males / females
87                 $male   = countSumTotalData('M', 'user_data', 'userid', 'gender', TRUE, runFilterChain('user_exclusion_sql', " AND `status`='CONFIRMED'"));
88                 $female = countSumTotalData('F', 'user_data', 'userid', 'gender', TRUE, runFilterChain('user_exclusion_sql', " AND `status`='CONFIRMED'"));
89
90                 // List every month
91                 $months = array();
92                 for ($idx = 1; $idx < 13; $idx++) {
93                         // Copy it so we don't touch the for() loop index
94                         $month = $idx;
95
96                         // Append leading zero
97                         if ($idx < 10) {
98                                 $month = '0' . $idx;
99                         } // END - if
100
101                         // Count months
102                         $months[$month] = countSumTotalData(bigintval($month), 'user_data', 'userid', 'birth_month', TRUE, runFilterChain('user_exclusion_sql', " AND `status`='CONFIRMED'"));
103                 } // END - for
104
105                 // Members in categories
106                 $result = SQL_QUERY("SELECT `id`, `cat` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `visible`='Y' ORDER BY `id` ASC", __FILE__, __LINE__);
107
108                 // Load categories first
109                 $cats = array(); $cat_cnt = array();
110
111                 // @TODO This can be somehow rewritten
112                 while ($content = SQL_FETCHARRAY($result)) {
113                         // Simple...
114                         $cats[$content['id']] = $content['cat'];
115                 } // END - while
116
117                 // Now all categories have been loaded, count members
118                 foreach ($cats as $id => $dummy) {
119                         // Only the id needs to be counted
120                         // @TODO This doesn't exclude tester accounts
121                         $cat_cnt[$id] = countSumTotalData(bigintval($id), 'user_cats', 'id', 'cat_id', TRUE);
122                 } // END - foreach
123
124                 // Prepare data for the template
125                 $content['total_users']   = ($male + $female);
126                 $content['unconfirmed']   = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `status` != 'CONFIRMED'" . runFilterChain('user_exclusion_sql', ' '), __FILE__, __LINE__));
127                 $content['total_males']   = $male;
128                 $content['total_females'] = $female;
129                 $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__));
130                 $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__));
131                 $content['treg_count']    = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `joined` >= {?START_TDAY?}" . runFilterChain('user_exclusion_sql', ' '), __FILE__, __LINE__));
132                 $content['yreg_count']    = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `joined` >= {?START_YDAY?} AND `joined` < {?START_TDAY?}" . runFilterChain('user_exclusion_sql', ' '), __FILE__, __LINE__));
133                 $content['lmode']         = $lmode;
134                 $content['ltitle']        = $ltitle;
135
136                 // Generate monthly stats
137                 $SW = 2; $r2 = ' right'; $l = 'll'; $r = 'lr'; $OUT = '';
138                 foreach ($months as $month => $count) {
139                         if ($SW == 2) $OUT .= '<tr>';
140
141                         // Prepare data for template
142                         $row = array(
143                                 'l_class'  => $l,
144                                 'm_descr'  => $GLOBALS['month_descr'][$month],
145                                 'r_class'  => $r,
146                                 'r2_class' => $r2,
147                                 'count'    => $count
148                         );
149
150                         // Load row template
151                         $OUT .= loadTemplate('guest_stats_month_row', TRUE, $row);
152
153                         if ($SW == 2) {
154                                 $r2 = '';
155                                 $l = 'rl'; $r = 'rr';
156                         } else {
157                                 $OUT .= '</tr>';
158                                 $r2 = ' right';
159                                 $l = 'll'; $r = 'lr';
160                         }
161                         $SW = 3 - $SW;
162                 } // END - foreach
163                 $content['month_rows'] = $OUT;
164
165                 // Generate category stats
166                 $OUT = '';
167                 foreach ($cat_cnt as $id => $count) {
168                         // Prepare data for the template
169                         $row = array(
170                                 'cat'   => $cats[$id],
171                                 'count' => $count,
172                         );
173
174                         // Load row template and switch colors
175                         $OUT .= loadTemplate('guest_stats_cats_row', TRUE, $row);
176                 } // END - foreach
177                 $content['cats_rows'] = $OUT;
178
179                 // Load final template
180                 loadTemplate('guest_stats_member', FALSE, $content);
181                 break;
182
183         case 'MODULES': // TOP10 module clicks
184                 // Admins may see all menus
185                 $AND = " AND `locked`='N' AND `visible`='Y'";
186                 if (isAdmin()) $AND = '';
187
188                 // Query for guest and member menus
189                 $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__);
190                 $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                 $OUT = ''; 
192
193                 if (!SQL_HASZERONUMS($guest_t10)) {
194                         // Guest clicks
195                         $OUT .= loadTemplate('guest_stats_header', TRUE, '{--GUEST_TOP_GUEST_STATS--}');
196                         while ($content = SQL_FETCHARRAY($guest_t10)) {
197                                 // Load row template
198                                 $OUT .= loadTemplate('guest_stats_row', TRUE, $content);
199                         } // END - while
200                 } // END - if
201
202                 if (!SQL_HASZERONUMS($mem_t10)) {
203                         // Member clicks
204                         $OUT .= loadTemplate('guest_stats_header', TRUE, '{--GUEST_TOP_MEMBER_STATS--}');
205                         while ($content = SQL_FETCHARRAY($mem_t10)) {
206                                 // Load row template
207                                 $OUT .= loadTemplate('guest_stats_row', TRUE, $content);
208                         } // END - while
209                 } // END - if
210
211                 // Is something generated?
212                 if (!empty($OUT)) {
213                         // Prepare content
214                         $content = array(
215                                 'rows'   => $OUT,
216                                 'lmode'  => $lmode,
217                                 'ltitle' => $ltitle
218                         );
219
220                         // Load final template
221                         loadTemplate('guest_stats_table', FALSE, $content);
222                 } else {
223                         // No clicks detected
224                         displayMessage('{--GUEST_STATS_NO_CLICKS--}');
225                 }
226                 break;
227
228         case 'INACTIVE': // Deactivated stats
229                 displayMessage('{--GUEST_STATS_DEACTIVATED--}');
230                 break;
231 } // END - switch
232
233 // [EOF]
234 ?>