2 /************************************************************************
3 * MXChange v0.2.1 Start: 12/14/2003 *
4 * ================ Last change: 08/22/2004 *
6 * -------------------------------------------------------------------- *
7 * File : what-stats.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Statistics *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Statistiken *
12 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
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. *
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. *
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, *
32 ************************************************************************/
34 // Some security stuff...
35 if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
37 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
40 // Add description as navigation point
41 ADD_DESCR("guest", basename(__FILE__));
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'])
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;
51 OPEN_TABLE("100%", "guest_content", "center", "top");
52 switch ($_CONFIG['guest_stats'])
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__));
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__));
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__));
67 // Unconfirmed accounts
68 $unconfirmed = SQL_NUMROWS(SQL_QUERY("SELECT userid FROM "._MYSQL_PREFIX."_user_data WHERE status != 'CONFIRMED'", __FILE__, __LINE__));
71 $total = $male + $female;
75 for ($idx = 1; $idx < 13; $idx++)
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__));
82 // Members in categories
83 $result = SQL_QUERY("SELECT id, cat FROM "._MYSQL_PREFIX."_cats WHERE visible='Y' ORDER BY id", __FILE__, __LINE__);
85 // Load categories first
86 $cats = array(); $cat_cnt = array();
87 while (list($id, $cat) = SQL_FETCHROW($result))
93 // Now we have all categories loaded, count members
94 foreach ($cats as $id=>$dummy)
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__));
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);
113 // Generate monthly stats
114 $SW = 2; $r2 = " right2"; $l = "ll"; $r = "lr"; $OUT = "";
115 foreach ($months as $month=>$cnt)
117 if ($SW == 2) $OUT .= "<TR>\n";
119 // Prepare data for template
122 'm_descr' => $MONTH_DESCR[$month],
129 $OUT .= LOAD_TEMPLATE("guest_stats_month_row", true, $content);
134 $l = "rl"; $r = "rr";
140 $l = "ll"; $r = "lr";
144 define('__MONTH_STATS_ROWS', $OUT);
146 // Generate category stats
148 foreach ($cat_cnt as $id=>$cnt)
150 // Prepare data for the template
157 // Load row template and switch colors
158 $OUT .= LOAD_TEMPLATE("guest_stats_cats_row", true, $content);
161 define('__CATS_STATS_ROWS', $OUT);
163 // Load final template
164 LOAD_TEMPLATE("guest_stats_member");
167 case "MODULES": // TOP10 module clicks
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))
175 OUTPUT_HTML("<TABLE border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"guest_table dashed\" width=\"310\">
177 <TD align=\"center\" class=\"guest_stats_title bottom2\" colspan=\"2\"><STRONG>".GUEST_TOPTEN_STATS."</STRONG></TD>
181 if (SQL_NUMROWS($guest_t10) > 0)
185 <TD align=\"center\" class=\"guest_title2 bottom2\" colspan=\"2\">".GUEST_TOP_GUEST_STATS."</TD>
188 while (list($clicks, $title) = SQL_FETCHROW($guest_t10))
191 <TD class=\"switch_sw".$SW." bottom2 right2\" align=\"right\" width=\"250\">".$title." </TD>
192 <TD class=\"switch_sw".$SW." bottom2\" width=\"50\"> ".$clicks."</TD>
197 if (SQL_NUMROWS($guest_t10) > 0)
201 <TD align=\"center\" class=\"guest_title2 bottom2\" colspan=\"2\">".GUEST_TOP_MEMBER_STATS."</TD>
204 while (list($clicks, $title) = SQL_FETCHROW($mem_t10))
207 <TD class=\"switch_sw".$SW." bottom2 right2\" align=\"right\" width=\"250\">".$title." </TD>
208 <TD class=\"switch_sw".$SW." bottom2\" width=\"50\"> ".$clicks."</TD>
213 if ((SQL_NUMROWS($guest_t10) > 0) || (SQL_NUMROWS($mem_t10) > 0))
217 <TD align=\"center\" class=\"guest_stats_footer\" colspan=\"2\"><A href=\"".URL."/modules.php?module=index&what=stats&mode=".$lmode."\">".$ltitle."</A></TD>
223 case "INACTIVE": // Deactivated stats
224 LOAD_TEMPLATE("admin_settings_saved", false, "<STRONG>".GUEST_STATS_DEACTIVATED."</STRONG>");