A lot has been rewritten, ext-teams added, ext-forced continued:
[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 - 2011 by Mailer Developer Team                   *
20  * For more information visit: http://www.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         die();
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 // Determine which stats we want and set mode and title for the link below stats block
53 if (!isGetRequestParameterSet('mode')) {
54         setGetRequestParameter('mode', strtolower(getConfig('guest_stats')));
55 } // END - if
56
57 // Set config temporarily
58 setConfigEntry('guest_stats', strtoupper(getRequestParameter('mode')));
59
60 switch (getRequestParameter('mode')) {
61         case 'members' :
62                 $lmode = 'modules';
63                 break;
64
65         case 'modules' :
66                 $lmode = 'members';
67                 break;
68
69         case 'inactive':
70                 $lmode = 'inactive';
71                 break;
72
73         default:
74                 // Unsupported mode
75                 debug_report_bug(__FILE__, __LINE__, sprintf("Unsupported mode <span class=\"data\">%s</span> detected.", secureString(getRequestParameter('mode'))));
76                 break;
77 }
78
79 // Set link title
80 $ltitle = '{--GUEST_STATS_' . strtoupper($lmode) . '--}';
81
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, " AND `status`='CONFIRMED'");
87                 $female = countSumTotalData('F', 'user_data', 'userid', 'gender', true, " AND `status`='CONFIRMED'");
88
89                 // List every month
90                 $months = array();
91                 for ($idx = 1; $idx < 13; $idx++) {
92                         // Copy it so we don't touch the for() loop index
93                         $month = $idx;
94
95                         // Append leading zero
96                         if ($idx < 10) $month = '0' . $idx;
97
98                         // Count months
99                         $months[$month] = countSumTotalData(bigintval($month), 'user_data', 'userid', 'birth_month', true, " AND `status`='CONFIRMED'");
100                 } // END - for
101
102                 // Members in categories
103                 $result = SQL_QUERY("SELECT `id`,`cat` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `visible`='Y' ORDER BY `id` ASC", __FILE__, __LINE__);
104
105                 // Load categories first
106                 $cats = array(); $cat_cnt = array();
107
108                 // @TODO This can be somehow rewritten
109                 while ($content = SQL_FETCHARRAY($result)) {
110                         // Simple...
111                         $cats[$content['id']] = $content['cat'];
112                 } // END - while
113
114                 // Now we have all categories loaded, count members
115                 foreach ($cats as $id => $dummy) {
116                         // We only need id and nothing more to count...
117                         $cat_cnt[$id] = countSumTotalData(bigintval($id), 'user_cats', 'id', 'cat_id', true);
118                 } // END - foreach
119
120                 // Prepare data for the template
121                 $content['total_users']   = ($male + $female);
122                 $content['unconfirmed']   = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `status` != 'CONFIRMED'", __FILE__, __LINE__));
123                 $content['total_males']   = $male;
124                 $content['total_females'] = $female;
125                 $content['tmem_count']    = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `last_online` >= {?START_TDAY?} AND `status`='CONFIRMED'", __FILE__, __LINE__));
126                 $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__));
127                 $content['treg_count']    = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `joined` >= {?START_TDAY?}", __FILE__, __LINE__));
128                 $content['yreg_count']    = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `joined` >= {?START_YDAY?} AND `joined` < {?START_TDAY?}", __FILE__, __LINE__));
129                 $content['lmode']         = $lmode;
130                 $content['ltitle']        = $ltitle;
131
132                 // Generate monthly stats
133                 $SW = 2; $r2 = ' right'; $l = 'll'; $r = 'lr'; $OUT = '';
134                 foreach ($months as $month => $count) {
135                         if ($SW == 2) $OUT .= '<tr>';
136
137                         // Prepare data for template
138                         $data = array(
139                                 'l_class'  => $l,
140                                 'm_descr'  => $GLOBALS['month_descr'][$month],
141                                 'r_class'  => $r,
142                                 'r2_class' => $r2,
143                                 'count'    => $count
144                         );
145
146                         // Load row template
147                         $OUT .= loadTemplate('guest_stats_month_row', true, $data);
148
149                         if ($SW == 2) {
150                                 $r2 = '';
151                                 $l = 'rl'; $r = 'rr';
152                         } else {
153                                 $OUT .= '</tr>';
154                                 $r2 = ' right';
155                                 $l = 'll'; $r = 'lr';
156                         }
157                         $SW = 3 - $SW;
158                 } // END - foreach
159                 $content['month_rows'] = $OUT;
160
161                 // Generate category stats
162                 $OUT = '';
163                 foreach ($cat_cnt as $id => $count) {
164                         // Prepare data for the template
165                         $data = array(
166                                 'cat'   => $cats[$id],
167                                 'count' => $count,
168                         );
169
170                         // Load row template and switch colors
171                         $OUT .= loadTemplate('guest_stats_cats_row', true, $data);
172                 } // END - foreach
173                 $content['cats_rows'] = $OUT;
174
175                 // Load final template
176                 loadTemplate('guest_stats_member', false, $content);
177                 break;
178
179         case 'MODULES': // TOP10 module clicks
180                 // Admins may see all menus
181                 $AND = " AND `locked`='N' AND `visible`='Y'";
182                 if (isAdmin()) $AND = '';
183
184                 // Query for guest and member menus
185                 $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__);
186                 $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__);
187                 $OUT = ''; 
188
189                 if (!SQL_HASZERONUMS($guest_t10)) {
190                         // Guest clicks
191                         $OUT .= loadTemplate('guest_stats_header', true, '{--GUEST_TOP_GUEST_STATS--}');
192                         while ($content = SQL_FETCHARRAY($guest_t10)) {
193                                 // Load row template
194                                 $OUT .= loadTemplate('guest_stats_row', true, $content);
195                         } // END - while
196                 } // END - if
197
198                 if (!SQL_HASZERONUMS($mem_t10)) {
199                         // Member clicks
200                         $OUT .= loadTemplate('guest_stats_header', true, '{--GUEST_TOP_MEMBER_STATS--}');
201                         while ($content = SQL_FETCHARRAY($mem_t10)) {
202                                 // Load row template
203                                 $OUT .= loadTemplate('guest_stats_row', true, $content);
204                         } // END - while
205                 } // END - if
206
207                 if ((!SQL_HASZERONUMS($guest_t10)) || (!SQL_HASZERONUMS($mem_t10))) {
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 ?>