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