]> git.mxchange.org Git - mailer.git/blob - inc/modules/guest/what-stats.php
Naming conventionn for language id strings applied on ext-nickname, typo in ids fixed
[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(__FILE__, __LINE__, sprintf("Unsupported mode <span class=\"data\">%s</span> detected.", secureString(getRequestParameter('mode'))));
70                 break;
71 }
72
73 // Set link title
74 $ltitle = '{--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                 // Only males / females
80                 $male   = countSumTotalData('M', 'user_data', 'userid', 'gender', true, " AND `status`='CONFIRMED'");
81                 $female = countSumTotalData('F', 'user_data', 'userid', 'gender', true, " AND `status`='CONFIRMED'");
82
83                 // List every month
84                 $months = array();
85                 for ($idx = 1; $idx < 13; $idx++) {
86                         // Copy it so we don't touch the for() loop index
87                         $month = $idx;
88
89                         // Append leading zero
90                         if ($idx < 10) $month = '0' . $idx;
91
92                         // Count months
93                         $months[$month] = countSumTotalData(bigintval($month), 'user_data', 'userid', 'birth_month', true, " AND `status`='CONFIRMED'");
94                 } // END - for
95
96                 // Members in categories
97                 $result = SQL_QUERY("SELECT `id`, `cat` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `visible`='Y' ORDER BY `id` ASC", __FILE__, __LINE__);
98
99                 // Load categories first
100                 $cats = array(); $cat_cnt = array();
101
102                 // @TODO This can be somehow rewritten
103                 while ($content = SQL_FETCHARRAY($result)) {
104                         // Simple...
105                         $cats[$content['id']] = $content['cat'];
106                 } // END - while
107
108                 // Now we have all categories loaded, count members
109                 foreach ($cats as $id => $dummy) {
110                         // We only need id and nothing more to count...
111                         $cat_cnt[$id] = countSumTotalData(bigintval($id), 'user_cats', 'id', 'cat_id', true);
112                 } // END - foreach
113
114                 // Prepare data for the template
115                 $content['total_users']   = ($male + $female);
116                 $content['unconfirmed']   = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `status` != 'CONFIRMED'", __FILE__, __LINE__));
117                 $content['total_males']   = $male;
118                 $content['total_females'] = $female;
119                 $content['tmem_count']    = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `last_online` >= {?START_TDAY?} AND `status`='CONFIRMED'", __FILE__, __LINE__));
120                 $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__));
121                 $content['treg_count']    = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `joined` >= {?START_TDAY?}", __FILE__, __LINE__));
122                 $content['yreg_count']    = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `joined` >= {?START_YDAY?} AND `joined` < {?START_TDAY?}", __FILE__, __LINE__));
123                 $content['lmode']         = $lmode;
124                 $content['ltitle']        = $ltitle;
125
126                 // Generate monthly stats
127                 $SW = 2; $r2 = ' right'; $l = 'll'; $r = 'lr'; $OUT = '';
128                 foreach ($months as $month => $cnt) {
129                         if ($SW == 2) $OUT .= '<tr>';
130
131                         // Prepare data for template
132                         $data = array(
133                                 'l_class'  => $l,
134                                 'm_descr'  => $GLOBALS['month_descr'][$month],
135                                 'r_class'  => $r,
136                                 'r2_class' => $r2,
137                                 'cnt'      => $cnt
138                         );
139
140                         // Load row template
141                         $OUT .= loadTemplate('guest_stats_month_row', true, $data);
142
143                         if ($SW == 2) {
144                                 $r2 = '';
145                                 $l = 'rl'; $r = 'rr';
146                         } else {
147                                 $OUT .= '</tr>';
148                                 $r2 = ' right';
149                                 $l = 'll'; $r = 'lr';
150                         }
151                         $SW = 3 - $SW;
152                 } // END - foreach
153                 $content['month_rows'] = $OUT;
154
155                 // Generate category stats
156                 $OUT = '';
157                 foreach ($cat_cnt as $id => $cnt) {
158                         // Prepare data for the template
159                         $data = array(
160                                 'cat' => $cats[$id],
161                                 'cnt' => $cnt,
162                         );
163
164                         // Load row template and switch colors
165                         $OUT .= loadTemplate('guest_stats_cats_row', true, $data);
166                 } // END - foreach
167                 $content['cats_rows'] = $OUT;
168
169                 // Load final template
170                 loadTemplate('guest_stats_member', false, $content);
171                 break;
172
173         case 'MODULES': // TOP10 module clicks
174                 // Admins may see all menus
175                 $AND = " AND `locked`='N' AND `visible`='Y'";
176                 if (isAdmin()) $AND = '';
177
178                 // Query for guest and member menus
179                 $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__);
180                 $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__);
181                 $OUT = ''; 
182
183                 if (!SQL_HASZERONUMS($guest_t10)) {
184                         // Guest clicks
185                         $OUT .= loadTemplate('guest_stats_header', true, '{--GUEST_TOP_GUEST_STATS--}');
186                         while ($content = SQL_FETCHARRAY($guest_t10)) {
187                                 // Load row template
188                                 $OUT .= loadTemplate('guest_stats_row', true, $content);
189                         } // END - while
190                 } // END - if
191
192                 if (!SQL_HASZERONUMS($mem_t10)) {
193                         // Member clicks
194                         $OUT .= loadTemplate('guest_stats_header', true, '{--GUEST_TOP_MEMBER_STATS--}');
195                         while ($content = SQL_FETCHARRAY($mem_t10)) {
196                                 // Load row template
197                                 $OUT .= loadTemplate('guest_stats_row', true, $content);
198                         } // END - while
199                 } // END - if
200
201                 if ((!SQL_HASZERONUMS($guest_t10)) || (!SQL_HASZERONUMS($mem_t10))) {
202                         // Prepare content
203                         $content = array(
204                                 'rows'   => $OUT,
205                                 'lmode'  => $lmode,
206                                 'ltitle' => $ltitle
207                         );
208
209                         // Load final template
210                         loadTemplate('guest_stats_table', false, $content);
211                 } else {
212                         // No clicks detected
213                         loadTemplate('admin_settings_saved', false, '{--GUEST_STATS_NO_CLICKS--}');
214                 }
215                 break;
216
217         case 'INACTIVE': // Deactivated stats
218                 loadTemplate('admin_settings_saved', false, '{--GUEST_STATS_DEACTIVATED--}');
219                 break;
220 } // END - switch
221
222 // [EOF]
223 ?>