3c12d48d5c02f6c73a449d1fb71f46efa85e8d95
[mailer.git] / inc / modules / guest / what-stats.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    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 - 2008 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
42         require($INC);
43 }
44
45 // Add description as navigation point
46 ADD_DESCR('guest', __FILE__);
47
48 // Derterminate which stats we want and set mode and title for the link below stats block
49 if (!REQUEST_ISSET_GET(('mode'))) REQUEST_SET_GET('mode', strtolower(getConfig('guest_stats')));
50
51 switch (REQUEST_GET('mode')) {
52         case 'members' :
53                 setConfigEntry('guest_stats', 'MEMBERS');
54                 $lmode = 'modules';
55                 $ltitle = getMessage('GUEST_STATS_MODULES');
56                 break;
57
58         case 'modules' :
59                 setConfigEntry('guest_stats', 'MODULES');
60                 $lmode = 'members';
61                 $ltitle = getMessage('GUEST_STATS_MEMBERS');
62                 break;
63
64         case 'inactive':
65                 setConfigEntry('guest_stats', 'INACTIVE');
66                 $lmode = 'inactive';
67                 $ltitle = getMessage('GUEST_STATS_INACTIVE');
68                 break;
69 }
70
71 switch (getConfig('guest_stats'))
72 {
73         case 'MEMBERS': // Statistics about your members
74                 // Members yesterday / today online
75                 $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__));
76                 $tmem = SQL_NUMROWS(SQL_QUERY("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE last_online >= ".getConfig('START_TDAY')." AND `status`='CONFIRMED'", __FILE__, __LINE__));
77
78                 // Yesterday / today registered
79                 $yreg = SQL_NUMROWS(SQL_QUERY("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE joined >= ".getConfig('START_YDAY')." AND joined < ".getConfig('START_TDAY'), __FILE__, __LINE__));
80                 $treg = SQL_NUMROWS(SQL_QUERY("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE joined >= ".getConfig('START_TDAY'), __FILE__, __LINE__));
81
82                 // Only males / females
83                 $male   = GET_TOTAL_DATA('M', 'user_data', 'userid', 'gender', true, " AND `status`='CONFIRMED'");
84                 $female = GET_TOTAL_DATA('F', 'user_data', 'userid', 'gender', true, " AND `status`='CONFIRMED'");
85
86                 // Unconfirmed accounts
87                 $unconfirmed = SQL_NUMROWS(SQL_QUERY("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE status != 'CONFIRMED'", __FILE__, __LINE__));
88
89                 // Total members
90                 $total = $male + $female;
91
92                 // List every month
93                 $months = array();
94                 for ($idx = 1; $idx < 13; $idx++) {
95                         // Copy it so we don't touch the for() loop index
96                         $month = $idx;
97
98                         // Append leading zero
99                         if ($idx < 10) $month = '0'.$idx;
100
101                         // Count months
102                         $months[$month] = GET_TOTAL_DATA(bigintval($month), 'user_data', 'userid', 'birth_month', true, " AND `status`='CONFIRMED'");
103                 }
104
105                 // Members in categories
106                 $result = SQL_QUERY("SELECT id, cat FROM `{!_MYSQL_PREFIX!}_cats` WHERE `visible`='Y' ORDER BY `id`", __FILE__, __LINE__);
107
108                 // Load categories first
109                 $cats = array(); $cat_cnt = array();
110                 // @TODO This can be somehow rewritten
111                 while ($content = SQL_FETCHARRAY($result)) {
112                         // Simple...
113                         $cats[$content['id']] = $content['cat'];
114                 }
115
116                 // Now we have all categories loaded, count members
117                 foreach ($cats as $id => $dummy) {
118                         // We only need id and nothing more to count...
119                         $cat_cnt[$id] = GET_TOTAL_DATA(bigintval($id), 'user_cats', 'id', 'cat_id', true);
120                 }
121
122                 // Prepare data for the template
123                 // @TODO Rewrite all these constants
124                 define('__TOTAL_USERS' , $total);
125                 define('__UNCONFIRMED' , $unconfirmed);
126                 define('__MALE_COUNT'  , $male);
127                 define('__FEMALE_COUNT', $female);
128                 define('__TMEM_COUNT'  , $tmem);
129                 define('__YMEM_COUNT'  , $ymem);
130                 define('__TREG_COUNT'  , $treg);
131                 define('__YREG_COUNT'  , $yreg);
132                 define('__LMODE_VALUE' , $lmode);
133                 define('__LINK_TITLE'  , $ltitle);
134
135                 // Generate monthly stats
136                 $SW = 2; $r2 = ' right2'; $l = 'll'; $r = 'lr'; $OUT = '';
137                 foreach ($months as $month => $cnt) {
138                         if ($SW == 2) $OUT .= "<tr>\n";
139
140                         // Prepare data for template
141                         $content = array(
142                         'l_class'  => $l,
143                         'm_descr'  => $GLOBALS['month_descr'][$month],
144                         'r_class'  => $r,
145                         'r2_class' => $r2,
146                         'cnt'      => $cnt
147                         );
148
149                         // Load row template
150                         $OUT .= LOAD_TEMPLATE("guest_stats_month_row", true, $content);
151
152                         if ($SW == 2) {
153                                 $r2 = '';
154                                 $l = 'rl'; $r = 'rr';
155                         } else {
156                                 $OUT .= "</tr>\n";
157                                 $r2 = ' right2';
158                                 $l = 'll'; $r = 'lr';
159                         }
160                         $SW = 3 - $SW;
161                 }
162                 define('__MONTH_STATS_ROWS', $OUT);
163
164                 // Generate category stats
165                 $OUT = ''; $SW = 2;
166                 foreach ($cat_cnt as $id => $cnt) {
167                         // Prepare data for the template
168                         $content = array(
169                         'sw'  => $SW,
170                         'cat' => $cats[$id],
171                         'cnt' => $cnt,
172                         );
173
174                         // Load row template and switch colors
175                         $OUT .= LOAD_TEMPLATE('guest_stats_cats_row', true, $content);
176                         $SW = 3 - $SW;
177                 }
178                 define('__CATS_STATS_ROWS', $OUT);
179
180                 // Load final template
181                 LOAD_TEMPLATE('guest_stats_member');
182                 break;
183
184         case 'MODULES': // TOP10 module clicks
185                 $AND = '';
186                 if (!IS_ADMIN()) $AND = " AND `locked`='N' AND `visible`='Y'";
187                 $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__);
188                 $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__);
189                 $OUT = '';
190                 if ((SQL_NUMROWS($guest_t10) > 0) || (SQL_NUMROWS($mem_t10) > 0)) {
191                         // Output header
192                         // @TODO Rewrite this to one template and $OUT .= ....
193                         OUTPUT_HTML("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"guest_table dashed\" width=\"310\">
194 <tr>
195   <td align=\"center\" class=\"guest_stats_title bottom2\" colspan=\"2\"><strong>{--GUEST_TOPTEN_STATS--}</strong></td>
196 </tr>");
197                 }
198
199                 if (SQL_NUMROWS($guest_t10) > 0) {
200                         // Guest clicks
201                         OUTPUT_HTML("<tr>
202   <td align=\"center\" class=\"guest_title2 bottom2\" colspan=\"2\">{--GUEST_TOP_GUEST_STATS--}</td>
203 </tr>");
204                         $SW = 2;
205                         while ($content = SQL_FETCHARRAY($guest_t10)) {
206                                 OUTPUT_HTML("<tr>
207   <td class=\"switch_sw".$SW." bottom2 right2\" align=\"right\" width=\"250\">".$content['title']."&nbsp;</td>
208   <td class=\"switch_sw".$SW." bottom2\" width=\"50\">&nbsp;".$content['counter']."</td>
209 </tr>");
210                                 $SW = 3 - $SW;
211                         }
212                 }
213
214                 if (SQL_NUMROWS($guest_t10) > 0) {
215                         // Guest clicks
216                         OUTPUT_HTML("<tr>
217   <td align=\"center\" class=\"guest_title2 bottom2\" colspan=\"2\">{--GUEST_TOP_MEMBER_STATS--}</td>
218 </tr>");
219                         $SW = 2;
220                         while ($content = SQL_FETCHARRAY($mem_t10)) {
221                                 OUTPUT_HTML("<tr>
222   <td class=\"switch_sw".$SW." bottom2 right2\" align=\"right\" width=\"250\">".$content['title']."&nbsp;</td>
223   <td class=\"switch_sw".$SW." bottom2\" width=\"50\">&nbsp;".$content['counter']."</td>
224 </tr>");
225                                 $SW = 3 - $SW;
226                         }
227                 }
228
229                 if ((SQL_NUMROWS($guest_t10) > 0) || (SQL_NUMROWS($mem_t10) > 0)) {
230                         // Output footer
231                         OUTPUT_HTML("<tr>
232   <td align=\"center\" class=\"guest_stats_footer\" colspan=\"2\">
233     <a href=\"{!URL!}/modules.php?module=index&amp;what=stats&amp;mode=".$lmode."\">".$ltitle."</a>
234   </td>
235 </tr>
236 </table>");
237                 }
238                 break;
239
240         case 'INACTIVE': // Deactivated stats
241                 LOAD_TEMPLATE('admin_settings_saved', false, "<strong>{--GUEST_STATS_DEACTIVATED--}</strong>");
242                 break;
243 }
244
245 //
246 ?>