First batch of removal of the headers needed for revision-functions.php
[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  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
14  * Copyright (c) 2009 - 2013 by Mailer Developer Team                   *
15  * For more information visit: http://mxchange.org                      *
16  *                                                                      *
17  * This program is free software; you can redistribute it and/or modify *
18  * it under the terms of the GNU General Public License as published by *
19  * the Free Software Foundation; either version 2 of the License, or    *
20  * (at your option) any later version.                                  *
21  *                                                                      *
22  * This program is distributed in the hope that it will be useful,      *
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
25  * GNU General Public License for more details.                         *
26  *                                                                      *
27  * You should have received a copy of the GNU General Public License    *
28  * along with this program; if not, write to the Free Software          *
29  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
30  * MA  02110-1301  USA                                                  *
31  ************************************************************************/
32
33 // Some security stuff...
34 if (!defined('__SECURITY')) {
35         exit();
36 } // END - if
37
38 // Add description as navigation point
39 addYouAreHereLink('guest', __FILE__);
40
41 // This part only works if ext-user is active
42 if ((!isExtensionActive('user')) && (!isAdmin())) {
43         displayMessage('{%pipe,generateExtensionInactiveNotInstalledMessage=user%}');
44         return;
45 } // END - if
46
47 // Default mode is from config
48 $do = getConfig('guest_stats');
49
50 // Determine which stats are wanted and set mode and title for the link below stats block
51 if (isGetRequestElementSet('do')) {
52         // Use it from get value
53         $do = strtoupper(getRequestElement('do'));
54 } // END - if
55
56 switch ($do) {
57         case 'MEMBERS' :
58                 $lmode = 'MODULES';
59                 break;
60
61         case 'MODULES' :
62                 $lmode = 'MEMBERS';
63                 break;
64
65         case 'INACTIVE':
66                 $lmode = 'INACTIVE';
67                 break;
68
69         default:
70                 // Unsupported mode
71                 reportBug(__FILE__, __LINE__, sprintf('Unsupported mode <span class="data">%s</span> detected.', sqlEscapeString($do)));
72                 break;
73 } // END - switch
74
75 // Set link title
76 $ltitle = '{--GUEST_STATS_' . $lmode . '--}';
77
78 // @TODO This can be rewritten in a dynamic include
79 switch (strtoupper($do)) {
80         case 'MEMBERS': // Statistics about your members
81                 // Only males / females
82                 $male   = countSumTotalData('M', 'user_data', 'userid', 'gender', TRUE, runFilterChain('user_exclusion_sql', " AND `status`='CONFIRMED'"));
83                 $female = countSumTotalData('F', 'user_data', 'userid', 'gender', TRUE, runFilterChain('user_exclusion_sql', " AND `status`='CONFIRMED'"));
84
85                 // List every month
86                 $months = array();
87                 for ($idx = 1; $idx < 13; $idx++) {
88                         // Copy it so we don't touch the for() loop index
89                         $month = $idx;
90
91                         // Append leading zero
92                         if ($idx < 10) {
93                                 $month = '0' . $idx;
94                         } // END - if
95
96                         // Count months
97                         $months[$month] = countSumTotalData(bigintval($month), 'user_data', 'userid', 'birth_month', TRUE, runFilterChain('user_exclusion_sql', " AND `status`='CONFIRMED'"));
98                 } // END - for
99
100                 // Members in categories
101                 $result = sqlQuery("SELECT `id`, `cat` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `visible`='Y' ORDER BY `id` ASC", __FILE__, __LINE__);
102
103                 // Load categories first
104                 $cats = array(); $cat_cnt = array();
105
106                 // @TODO This can be somehow rewritten
107                 while ($content = sqlFetchArray($result)) {
108                         // Simple...
109                         $cats[$content['id']] = $content['cat'];
110                 } // END - while
111
112                 // Now all categories have been loaded, count members
113                 foreach ($cats as $id => $dummy) {
114                         // Only the id needs to be counted
115                         // @TODO This doesn't exclude tester accounts
116                         $cat_cnt[$id] = countSumTotalData(bigintval($id), 'user_cats', 'id', 'cat_id', TRUE);
117                 } // END - foreach
118
119                 // Prepare data for the template
120                 $content['total_users']   = ($male + $female);
121                 $content['unconfirmed']   = sqlNumRows(sqlQuery("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `status` != 'CONFIRMED'" . runFilterChain('user_exclusion_sql', ' '), __FILE__, __LINE__));
122                 $content['total_males']   = $male;
123                 $content['total_females'] = $female;
124                 $content['tmem_count']    = sqlNumRows(sqlQuery("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `last_online` >= {?START_TDAY?}" . runFilterChain('user_exclusion_sql', " AND `status`='CONFIRMED'"), __FILE__, __LINE__));
125                 $content['ymem_count']    = sqlNumRows(sqlQuery("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__));
126                 $content['treg_count']    = sqlNumRows(sqlQuery("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `joined` >= {?START_TDAY?}" . runFilterChain('user_exclusion_sql', ' '), __FILE__, __LINE__));
127                 $content['yreg_count']    = sqlNumRows(sqlQuery("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `joined` >= {?START_YDAY?} AND `joined` < {?START_TDAY?}" . runFilterChain('user_exclusion_sql', ' '), __FILE__, __LINE__));
128                 $content['lmode']         = $lmode;
129                 $content['ltitle']        = $ltitle;
130
131                 // Generate monthly stats
132                 $SW = 2; $r2 = ' right'; $l = 'll'; $r = 'lr'; $OUT = '';
133                 foreach ($months as $month => $count) {
134                         if ($SW == 2) $OUT .= '<tr>';
135
136                         // Prepare data for template
137                         $row = array(
138                                 'l_class'  => $l,
139                                 'm_descr'  => $GLOBALS['month_descr'][$month],
140                                 'r_class'  => $r,
141                                 'r2_class' => $r2,
142                                 'count'    => $count
143                         );
144
145                         // Load row template
146                         $OUT .= loadTemplate('guest_stats_month_row', TRUE, $row);
147
148                         if ($SW == 2) {
149                                 $r2 = '';
150                                 $l = 'rl'; $r = 'rr';
151                         } else {
152                                 $OUT .= '</tr>';
153                                 $r2 = ' right';
154                                 $l = 'll'; $r = 'lr';
155                         }
156                         $SW = 3 - $SW;
157                 } // END - foreach
158                 $content['month_rows'] = $OUT;
159
160                 // Generate category stats
161                 $OUT = '';
162                 foreach ($cat_cnt as $id => $count) {
163                         // Prepare data for the template
164                         $row = array(
165                                 'cat'   => $cats[$id],
166                                 'count' => $count,
167                         );
168
169                         // Load row template and switch colors
170                         $OUT .= loadTemplate('guest_stats_cats_row', TRUE, $row);
171                 } // END - foreach
172                 $content['cats_rows'] = $OUT;
173
174                 // Load final template
175                 loadTemplate('guest_stats_member', FALSE, $content);
176                 break;
177
178         case 'MODULES': // TOP10 module clicks
179                 // Admins may see all menus
180                 $AND = " AND `locked`='N' AND `visible`='Y'";
181                 if (isAdmin()) $AND = '';
182
183                 // Query for guest and member menus
184                 $guest_t10 = sqlQuery('SELECT `counter`, `title` FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE `counter` > 0' . $AND . ' ORDER BY `counter` DESC LIMIT 0,10', __FILE__, __LINE__);
185                 $mem_t10   = sqlQuery('SELECT `counter`, `title` FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `counter` > 0' . $AND . ' ORDER BY `counter` DESC LIMIT 0,10', __FILE__, __LINE__);
186                 $OUT = '';
187
188                 if (!ifSqlHasZeroNums($guest_t10)) {
189                         // Guest clicks
190                         $OUT .= loadTemplate('guest_stats_header', TRUE, '{--GUEST_TOP_GUEST_STATS--}');
191                         while ($content = sqlFetchArray($guest_t10)) {
192                                 // Load row template
193                                 $OUT .= loadTemplate('guest_stats_row', TRUE, $content);
194                         } // END - while
195                 } // END - if
196
197                 if (!ifSqlHasZeroNums($mem_t10)) {
198                         // Member clicks
199                         $OUT .= loadTemplate('guest_stats_header', TRUE, '{--GUEST_TOP_MEMBER_STATS--}');
200                         while ($content = sqlFetchArray($mem_t10)) {
201                                 // Load row template
202                                 $OUT .= loadTemplate('guest_stats_row', TRUE, $content);
203                         } // END - while
204                 } // END - if
205
206                 // Is something generated?
207                 if (!empty($OUT)) {
208                         // Prepare content
209                         $content = array(
210                                 'rows'   => $OUT,
211                                 'lmode'  => $lmode,
212                                 'ltitle' => $ltitle
213                         );
214
215                         // Load final template
216                         loadTemplate('guest_stats_table', FALSE, $content);
217                 } else {
218                         // No clicks detected
219                         displayMessage('{--GUEST_STATS_NO_CLICKS--}');
220                 }
221                 break;
222
223         case 'INACTIVE': // Deactivated stats
224                 displayMessage('{--GUEST_STATS_DEACTIVATED--}');
225                 break;
226 } // END - switch
227
228 // [EOF]
229 ?>