Even more rewrites/fixes from EL branch (please report any broken part after you...
[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  * 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  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
42         die();
43 } // END - if
44
45 // Add description as navigation point
46 addMenuDescription('guest', __FILE__);
47
48 // Derterminate which stats we want and set mode and title for the link below stats block
49 if (!isGetRequestParameterSet('mode')) setGetRequestParameter('mode', strtolower(getConfig('guest_stats')));
50
51 // Set config temporarily
52 setConfigEntry('guest_stats', strtoupper(getRequestParameter('mode')));
53
54 switch (getRequestParameter('mode')) {
55         case 'members' :
56                 $lmode = 'modules';
57                 break;
58
59         case 'modules' :
60                 $lmode = 'members';
61                 break;
62
63         case 'inactive':
64                 $lmode = 'inactive';
65                 break;
66
67         default:
68                 // Unsupported mode
69                 debug_report_bug(sprintf("Unsupported mode <span class=\"data\">%s</span> detected.", secureString(getRequestParameter('mode'))));
70                 break;
71 }
72
73 // Set link title
74 $ltitle = getMessage('GUEST_STATS_' . strtoupper($lmode));
75
76 // @TODO This can be rewritten in a dynamic include
77 switch (getConfig('guest_stats')) {
78         case 'MEMBERS': // Statistics about your members
79                 // Members yesterday / today online
80                 $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__));
81                 $tmem = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `last_online` >= ".getConfig('START_TDAY')." AND `status`='CONFIRMED'", __FILE__, __LINE__));
82
83                 // Yesterday / today registered
84                 $yreg = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `joined` >= ".getConfig('START_YDAY')." AND `joined` < ".getConfig('START_TDAY'), __FILE__, __LINE__));
85                 $treg = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `joined` >= ".getConfig('START_TDAY'), __FILE__, __LINE__));
86
87                 // Only males / females
88                 $male   = countSumTotalData('M', 'user_data', 'userid', 'gender', true, " AND `status`='CONFIRMED'");
89                 $female = countSumTotalData('F', 'user_data', 'userid', 'gender', true, " AND `status`='CONFIRMED'");
90
91                 // Unconfirmed accounts
92                 $unconfirmed = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `status` != 'CONFIRMED'", __FILE__, __LINE__));
93
94                 // Total members
95                 $total = $male + $female;
96
97                 // List every month
98                 $months = array();
99                 for ($idx = 1; $idx < 13; $idx++) {
100                         // Copy it so we don't touch the for() loop index
101                         $month = $idx;
102
103                         // Append leading zero
104                         if ($idx < 10) $month = '0' . $idx;
105
106                         // Count months
107                         $months[$month] = countSumTotalData(bigintval($month), 'user_data', 'userid', 'birth_month', true, " AND `status`='CONFIRMED'");
108                 } // END - for
109
110                 // Members in categories
111                 $result = SQL_QUERY("SELECT `id`, `cat` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `visible`='Y' ORDER BY `id` ASC", __FILE__, __LINE__);
112
113                 // Load categories first
114                 $cats = array(); $cat_cnt = array();
115
116                 // @TODO This can be somehow rewritten
117                 while ($content = SQL_FETCHARRAY($result)) {
118                         // Simple...
119                         $cats[$content['id']] = $content['cat'];
120                 } // END - while
121
122                 // Now we have all categories loaded, count members
123                 foreach ($cats as $id => $dummy) {
124                         // We only need id and nothing more to count...
125                         $cat_cnt[$id] = countSumTotalData(bigintval($id), 'user_cats', 'id', 'cat_id', true);
126                 } // END - foreach
127
128                 // Prepare data for the template
129                 $content['total_users']   = $total;
130                 $content['unconfirmed']   = $unconfirmed;
131                 $content['total_males']   = $male;
132                 $content['total_females'] = $female;
133                 $content['tmem_count']    = $tmem;
134                 $content['ymem_count']    = $ymem;
135                 $content['treg_count']    = $treg;
136                 $content['yreg_count']    = $yreg;
137                 $content['lmode']         = $lmode;
138                 $content['ltitle']        = $ltitle;
139
140                 // Generate monthly stats
141                 $SW = 2; $r2 = ' right'; $l = 'll'; $r = 'lr'; $OUT = '';
142                 foreach ($months as $month => $cnt) {
143                         if ($SW == 2) $OUT .= "<tr>\n";
144
145                         // Prepare data for template
146                         $data = array(
147                                 'l_class'  => $l,
148                                 'm_descr'  => $GLOBALS['month_descr'][$month],
149                                 'r_class'  => $r,
150                                 'r2_class' => $r2,
151                                 'cnt'      => $cnt
152                         );
153
154                         // Load row template
155                         $OUT .= loadTemplate('guest_stats_month_row', true, $data);
156
157                         if ($SW == 2) {
158                                 $r2 = '';
159                                 $l = 'rl'; $r = 'rr';
160                         } else {
161                                 $OUT .= "</tr>\n";
162                                 $r2 = ' right';
163                                 $l = 'll'; $r = 'lr';
164                         }
165                         $SW = 3 - $SW;
166                 }
167                 $content['month_rows'] = $OUT;
168
169                 // Generate category stats
170                 $OUT = ''; $SW = 2;
171                 foreach ($cat_cnt as $id => $cnt) {
172                         // Prepare data for the template
173                         $data = array(
174                                 'sw'  => $SW,
175                                 'cat' => $cats[$id],
176                                 'cnt' => $cnt,
177                         );
178
179                         // Load row template and switch colors
180                         $OUT .= loadTemplate('guest_stats_cats_row', true, $data);
181                         $SW = 3 - $SW;
182                 }
183                 $content['cats_rows'] = $OUT;
184
185                 // Load final template
186                 loadTemplate('guest_stats_member', false, $content);
187                 break;
188
189         case 'MODULES': // TOP10 module clicks
190                 // Admins may see all menus
191                 $AND = " AND `locked`='N' AND `visible`='Y'";
192                 if (isAdmin()) $AND = '';
193
194                 // Query for guest and member menus
195                 $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__);
196                 $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__);
197                 $OUT = ''; 
198
199                 if (SQL_NUMROWS($guest_t10) > 0) {
200                         // Guest clicks
201                         $OUT .= loadTemplate('guest_stats_header', true, getMessage('GUEST_TOP_GUEST_STATS'));
202                         $SW = 2;
203                         while ($content = SQL_FETCHARRAY($guest_t10)) {
204                                 $content['sw'] = $SW;
205
206                                 // Load row template
207                                 $OUT .= loadTemplate('guest_stats_row', true, $content);
208                                 $SW = 3 - $SW;
209                         } // END - while
210                 } // END - if
211
212                 if (SQL_NUMROWS($mem_t10) > 0) {
213                         // Member clicks
214                         $OUT .= loadTemplate('guest_stats_header', true, getMessage('GUEST_TOP_MEMBER_STATS'));
215                         $SW = 2;
216                         while ($content = SQL_FETCHARRAY($mem_t10)) {
217                                 $content['sw'] = $SW;
218
219                                 // Load row template
220                                 $OUT .= loadTemplate('guest_stats_row', true, $content);
221                                 $SW = 3 - $SW;
222                         } // END - while
223                 } // END - if
224
225                 if ((SQL_NUMROWS($guest_t10) > 0) || (SQL_NUMROWS($mem_t10) > 0)) {
226                         // Prepare content
227                         $content = array(
228                                 'rows'   => $OUT,
229                                 'lmode'  => $lmode,
230                                 'ltitle' => $ltitle
231                         );
232
233                         // Load final template
234                         loadTemplate('guest_stats_table', false, $content);
235                 } else {
236                         // No clicks detected
237                         loadTemplate('admin_settings_saved', false, getMessage('GUEST_STATS_NO_CLICKS'));
238                 }
239                 break;
240
241         case 'INACTIVE': // Deactivated stats
242                 loadTemplate('admin_settings_saved', false, getMessage('GUEST_STATS_DEACTIVATED'));
243                 break;
244 }
245
246 // [EOF]
247 ?>