Missed default value but had already closed editor :(
[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 // 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')));
48
49 // Set config temporarily
50 setConfigEntry('guest_stats', strtoupper(getRequestParameter('mode')));
51
52 switch (getRequestParameter('mode')) {
53         case 'members' :
54                 $lmode = 'modules';
55                 break;
56
57         case 'modules' :
58                 $lmode = 'members';
59                 break;
60
61         case 'inactive':
62                 $lmode = 'inactive';
63                 break;
64
65         default:
66                 // Unsupported mode
67                 debug_report_bug(__FILE__, __LINE__, sprintf("Unsupported mode <span class=\"data\">%s</span> detected.", secureString(getRequestParameter('mode'))));
68                 break;
69 }
70
71 // Set link title
72 $ltitle = '{--GUEST_STATS_' . strtoupper($lmode) . '--}';
73
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'");
80
81                 // List every month
82                 $months = array();
83                 for ($idx = 1; $idx < 13; $idx++) {
84                         // Copy it so we don't touch the for() loop index
85                         $month = $idx;
86
87                         // Append leading zero
88                         if ($idx < 10) $month = '0' . $idx;
89
90                         // Count months
91                         $months[$month] = countSumTotalData(bigintval($month), 'user_data', 'userid', 'birth_month', true, " AND `status`='CONFIRMED'");
92                 } // END - for
93
94                 // Members in categories
95                 $result = SQL_QUERY("SELECT `id`, `cat` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `visible`='Y' ORDER BY `id` ASC", __FILE__, __LINE__);
96
97                 // Load categories first
98                 $cats = array(); $cat_cnt = array();
99
100                 // @TODO This can be somehow rewritten
101                 while ($content = SQL_FETCHARRAY($result)) {
102                         // Simple...
103                         $cats[$content['id']] = $content['cat'];
104                 } // END - while
105
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);
110                 } // END - foreach
111
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;
123
124                 // Generate monthly stats
125                 $SW = 2; $r2 = ' right'; $l = 'll'; $r = 'lr'; $OUT = '';
126                 foreach ($months as $month => $count) {
127                         if ($SW == 2) $OUT .= '<tr>';
128
129                         // Prepare data for template
130                         $data = array(
131                                 'l_class'  => $l,
132                                 'm_descr'  => $GLOBALS['month_descr'][$month],
133                                 'r_class'  => $r,
134                                 'r2_class' => $r2,
135                                 'cnt'      => $count
136                         );
137
138                         // Load row template
139                         $OUT .= loadTemplate('guest_stats_month_row', true, $data);
140
141                         if ($SW == 2) {
142                                 $r2 = '';
143                                 $l = 'rl'; $r = 'rr';
144                         } else {
145                                 $OUT .= '</tr>';
146                                 $r2 = ' right';
147                                 $l = 'll'; $r = 'lr';
148                         }
149                         $SW = 3 - $SW;
150                 } // END - foreach
151                 $content['month_rows'] = $OUT;
152
153                 // Generate category stats
154                 $OUT = '';
155                 foreach ($cat_cnt as $id => $count) {
156                         // Prepare data for the template
157                         $data = array(
158                                 'cat' => $cats[$id],
159                                 'cnt' => $count,
160                         );
161
162                         // Load row template and switch colors
163                         $OUT .= loadTemplate('guest_stats_cats_row', true, $data);
164                 } // END - foreach
165                 $content['cats_rows'] = $OUT;
166
167                 // Load final template
168                 loadTemplate('guest_stats_member', false, $content);
169                 break;
170
171         case 'MODULES': // TOP10 module clicks
172                 // Admins may see all menus
173                 $AND = " AND `locked`='N' AND `visible`='Y'";
174                 if (isAdmin()) $AND = '';
175
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__);
179                 $OUT = ''; 
180
181                 if (!SQL_HASZERONUMS($guest_t10)) {
182                         // Guest clicks
183                         $OUT .= loadTemplate('guest_stats_header', true, '{--GUEST_TOP_GUEST_STATS--}');
184                         while ($content = SQL_FETCHARRAY($guest_t10)) {
185                                 // Load row template
186                                 $OUT .= loadTemplate('guest_stats_row', true, $content);
187                         } // END - while
188                 } // END - if
189
190                 if (!SQL_HASZERONUMS($mem_t10)) {
191                         // Member clicks
192                         $OUT .= loadTemplate('guest_stats_header', true, '{--GUEST_TOP_MEMBER_STATS--}');
193                         while ($content = SQL_FETCHARRAY($mem_t10)) {
194                                 // Load row template
195                                 $OUT .= loadTemplate('guest_stats_row', true, $content);
196                         } // END - while
197                 } // END - if
198
199                 if ((!SQL_HASZERONUMS($guest_t10)) || (!SQL_HASZERONUMS($mem_t10))) {
200                         // Prepare content
201                         $content = array(
202                                 'rows'   => $OUT,
203                                 'lmode'  => $lmode,
204                                 'ltitle' => $ltitle
205                         );
206
207                         // Load final template
208                         loadTemplate('guest_stats_table', false, $content);
209                 } else {
210                         // No clicks detected
211                         displayMessage('{--GUEST_STATS_NO_CLICKS--}');
212                 }
213                 break;
214
215         case 'INACTIVE': // Deactivated stats
216                 displayMessage('{--GUEST_STATS_DEACTIVATED--}');
217                 break;
218 } // END - switch
219
220 // [EOF]
221 ?>