template
[mailer.git] / 0.2.1 / 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 (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
36 {
37         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
38         require($INC);
39 }
40 // Add description as navigation point
41 ADD_DESCR("guest", basename(__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($CONFIG['guest_stats']);
45 switch ($_GET['mode'])
46 {
47         case "members": $CONFIG['guest_stats'] = "MEMBERS"; $lmode = "modules"; $ltitle = GUEST_STATS_MODULES; break;
48         case "modules": $CONFIG['guest_stats'] = "MODULES"; $lmode = "members"; $ltitle = GUEST_STATS_MEMBERS; break;
49 }
50
51 OPEN_TABLE("100%", "guest_content", "center", "top");
52 switch ($CONFIG['guest_stats'])
53 {
54 case "MEMBERS": // Statistics about your members
55         // Members yesterday / today online
56         $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__));
57         $tmem = SQL_NUMROWS(SQL_QUERY("SELECT userid FROM "._MYSQL_PREFIX."_user_data WHERE last_online >= ".START_TDAY." AND status='CONFIRMED'", __FILE__, __LINE__));
58
59         // Yesterday / today registered
60         $yreg = SQL_NUMROWS(SQL_QUERY("SELECT userid FROM "._MYSQL_PREFIX."_user_data WHERE joined >= ".START_YDAY." AND joined < ".START_TDAY, __FILE__, __LINE__));
61         $treg = SQL_NUMROWS(SQL_QUERY("SELECT userid FROM "._MYSQL_PREFIX."_user_data WHERE joined >= ".START_TDAY, __FILE__, __LINE__));
62
63         // Only males / females
64         $male   = SQL_NUMROWS(SQL_QUERY("SELECT userid FROM "._MYSQL_PREFIX."_user_data WHERE sex='M' AND status='CONFIRMED'", __FILE__, __LINE__));
65         $female = SQL_NUMROWS(SQL_QUERY("SELECT userid FROM "._MYSQL_PREFIX."_user_data WHERE sex='F' AND status='CONFIRMED'", __FILE__, __LINE__));
66
67         // Unconfirmed accounts
68         $unconfirmed = SQL_NUMROWS(SQL_QUERY("SELECT userid FROM "._MYSQL_PREFIX."_user_data WHERE status != 'CONFIRMED'", __FILE__, __LINE__));
69
70         // Total members
71         $total = $male + $female;
72
73         // List every month
74         $months = array();
75         for ($idx = 1; $idx < 13; $idx++)
76         {
77                 $month = $idx; if ($idx < 10) $month = "0".$idx;
78                 $months[$month] = SQL_NUMROWS(SQL_QUERY_ESC("SELECT userid FROM "._MYSQL_PREFIX."_user_data WHERE birth_month=%d AND status='CONFIRMED'",
79                  array(bigintval($month)), __FILE__, __LINE__));
80         }
81
82         // Members in categories
83         $result = SQL_QUERY("SELECT id, cat FROM "._MYSQL_PREFIX."_cats WHERE visible='Y' ORDER BY id", __FILE__, __LINE__);
84
85         // Load categories first
86         $cats = array(); $cat_cnt = array();
87         while (list($id, $cat) = SQL_FETCHROW($result))
88         {
89                 // Simple...
90                 $cats[$id] = $cat;
91         }
92
93         // Now we have all categories loaded, count members
94         foreach ($cats as $id=>$dummy)
95         {
96                 // We only need id and nothing more to count...
97                 $cat_cnt[$id] = SQL_NUMROWS(SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_user_cats WHERE cat_id=%d",
98                  array(bigintval($id)), __FILE__, __LINE__));
99         }
100
101         // Prepare data for the template
102         define('__TOTAL_USERS' , $total);
103         define('__UNCONFIRMED' , $unconfirmed);
104         define('__MALE_COUNT'  , $male);
105         define('__FEMALE_COUNT', $female);
106         define('__TMEM_COUNT'  , $tmem);
107         define('__YMEM_COUNT'  , $ymem);
108         define('__TREG_COUNT'  , $treg);
109         define('__YREG_COUNT'  , $yreg);
110         define('__LMODE_VALUE' , $lmode);
111         define('__LINK_TITLE'  , $ltitle);
112
113         // Generate monthly stats
114         $SW = 2; $r2 = " right2"; $l = "ll"; $r = "lr"; $OUT = "";
115         foreach ($months as $month=>$cnt)
116         {
117                 if ($SW == 2) $OUT .= "<TR>\n";
118
119                 // Prepare data for template
120                 $content = array(
121                         'l_class'  => $l,
122                         'm_descr'  => $MONTH_DESCR[$month],
123                         'r_class'  => $r,
124                         'r2_class' => $r2,
125                         'cnt'      => $cnt
126                 );
127
128                 // Load row template
129                 $OUT .= LOAD_TEMPLATE("guest_stats_month_row", true, $content);
130
131                 if ($SW == 2)
132                 {
133                         $r2 = "";
134                         $l = "rl"; $r = "rr";
135                 }
136                  else
137                 {
138                         $OUT .= "</TR>\n";
139                         $r2 = " right2";
140                         $l = "ll"; $r = "lr";
141                 }
142                 $SW = 3 - $SW;
143         }
144         define('__MONTH_STATS_ROWS', $OUT);
145
146         // Generate category stats
147         $SW = 2; $OUT = "";
148         foreach ($cat_cnt as $id=>$cnt)
149         {
150                 // Prepare data for the template
151                 $content = array(
152                         'sw'  => $SW,
153                         'cat' => $cats[$id],
154                         'cnt' => $cnt,
155                 );
156
157                 // Load row template and switch colors
158                 $OUT .= LOAD_TEMPLATE("guest_stats_cats_row", true, $content);
159                 $SW = 3 - $SW;
160         }
161         define('__CATS_STATS_ROWS', $OUT);
162
163         // Load final template
164         LOAD_TEMPLATE("guest_stats_member");
165         break;
166
167 case "MODULES": // TOP10 module clicks
168         $AND = "";
169         if (!IS_ADMIN()) $AND = " AND locked='N' AND visible='Y'";
170         $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__);
171         $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__);
172         if ((SQL_NUMROWS($guest_t10) > 0) || (SQL_NUMROWS($mem_t10) > 0))
173         {
174                 // Output header
175                 OUTPUT_HTML ("<TABLE border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"guest_table dashed\" width=\"310\">
176 <TR>
177   <TD align=\"center\" class=\"guest_stats_title bottom2\" colspan=\"2\"><STRONG>".GUEST_TOPTEN_STATS."</STRONG></TD>
178 </TR>");
179         }
180
181         if (SQL_NUMROWS($guest_t10) > 0)
182         {
183                 // Guest clicks
184                 OUTPUT_HTML ("<TR>
185   <TD align=\"center\" class=\"guest_title2 bottom2\" colspan=\"2\">".GUEST_TOP_GUEST_STATS."</TD>
186 </TR>");
187                 $SW = 2;
188                 while (list($clicks, $title) = SQL_FETCHROW($guest_t10))
189                 {
190                         OUTPUT_HTML ("<TR>
191   <TD class=\"switch_sw".$SW." bottom2 right2\" align=\"right\" width=\"250\">".$title."&nbsp;</TD>
192   <TD class=\"switch_sw".$SW." bottom2\" width=\"50\">&nbsp;".$clicks."</TD>
193 </TR>");
194                         $SW = 3 - $SW;
195                 }
196         }
197         if (SQL_NUMROWS($guest_t10) > 0)
198         {
199                 // Guest clicks
200                 OUTPUT_HTML ("<TR>
201   <TD align=\"center\" class=\"guest_title2 bottom2\" colspan=\"2\">".GUEST_TOP_MEMBER_STATS."</TD>
202 </TR>");
203                 $SW = 2;
204                 while (list($clicks, $title) = SQL_FETCHROW($mem_t10))
205                 {
206                         OUTPUT_HTML ("<TR>
207   <TD class=\"switch_sw".$SW." bottom2 right2\" align=\"right\" width=\"250\">".$title."&nbsp;</TD>
208   <TD class=\"switch_sw".$SW." bottom2\" width=\"50\">&nbsp;".$clicks."</TD>
209 </TR>");
210                         $SW = 3 - $SW;
211                 }
212         }
213         if ((SQL_NUMROWS($guest_t10) > 0) || (SQL_NUMROWS($mem_t10) > 0))
214         {
215                 // Output footer
216                 OUTPUT_HTML ("<TR>
217   <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>
218 </TR>
219 </TABLE>");
220         }
221         break;
222
223 case "INACTIVE": // Deactivated stats
224         LOAD_TEMPLATE("admin_settings_saved", false, "<STRONG>".GUEST_STATS_DEACTIVATED."</STRONG>");
225         break;
226 }
227 CLOSE_TABLE();
228 //
229 ?>