<?php
/************************************************************************
- * MXChange v0.2.1 Start: 12/14/2003 *
- * ================ Last change: 08/22/2004 *
+ * Mailer v0.2.1-FINAL Start: 12/14/2003 *
+ * =================== Last change: 08/22/2004 *
* *
* -------------------------------------------------------------------- *
* File : what-stats.php *
* -------------------------------------------------------------------- *
* Kurzbeschreibung : Statistiken *
* -------------------------------------------------------------------- *
- * *
+ * $Revision:: $ *
+ * $Date:: $ *
+ * $Tag:: 0.2.1-FINAL $ *
+ * $Author:: $ *
* -------------------------------------------------------------------- *
- * Copyright (c) 2003 - 2008 by Roland Haeder *
+ * Copyright (c) 2003 - 2009 by Roland Haeder *
+ * Copyright (c) 2009 - 2011 by Mailer Developer Team *
* For more information visit: http://www.mxchange.org *
* *
* This program is free software; you can redistribute it and/or modify *
// Some security stuff...
if (!defined('__SECURITY')) {
- $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
- require($INC);
-}
+ die();
+} // END - if
// Add description as navigation point
-ADD_DESCR("guest", __FILE__);
+addYouAreHereLink('guest', __FILE__);
+
+// This part only works if ext-user is active
+if ((!isExtensionActive('user')) && (!isAdmin())) {
+ displayMessage(generateExtensionInactiveNotInstalledMessage('user'));
+ return;
+} // END - if
+
+// Determine which stats we want and set mode and title for the link below stats block
+if (!isGetRequestParameterSet('mode')) {
+ setGetRequestParameter('mode', strtolower(getConfig('guest_stats')));
+} // END - if
-// Derterminate which stats we want and set mode and title for the link below stats block
-if (!REQUEST_ISSET_GET(('mode'))) REQUEST_SET_GET('mode', strtolower(getConfig('guest_stats')));
+// Set config temporarily
+setConfigEntry('guest_stats', strtoupper(getRequestParameter('mode')));
-switch (REQUEST_GET('mode')) {
- case "members" :
- setConfigEntry('guest_stats', "MEMBERS");
- $lmode = "modules";
- $ltitle = getMessage('GUEST_STATS_MODULES');
+switch (getRequestParameter('mode')) {
+ case 'members' :
+ $lmode = 'modules';
break;
- case "modules" :
- setConfigEntry('guest_stats', "MODULES");
- $lmode = "members";
- $ltitle = getMessage('GUEST_STATS_MEMBERS');
+ case 'modules' :
+ $lmode = 'members';
break;
- case "inactive":
- setConfigEntry('guest_stats', "INACTIVE");
- $lmode = "inactive";
- $ltitle = getMessage('GUEST_STATS_INACTIVE');
+ case 'inactive':
+ $lmode = 'inactive';
+ break;
+
+ default:
+ // Unsupported mode
+ debug_report_bug(__FILE__, __LINE__, sprintf("Unsupported mode <span class=\"data\">%s</span> detected.", secureString(getRequestParameter('mode'))));
break;
}
-switch (getConfig('guest_stats'))
-{
-case "MEMBERS": // Statistics about your members
- // Members yesterday / today online
- $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__));
- $tmem = SQL_NUMROWS(SQL_QUERY("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE last_online >= ".START_TDAY." AND `status`='CONFIRMED'", __FILE__, __LINE__));
-
- // Yesterday / today registered
- $yreg = SQL_NUMROWS(SQL_QUERY("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE joined >= ".START_YDAY." AND joined < ".START_TDAY, __FILE__, __LINE__));
- $treg = SQL_NUMROWS(SQL_QUERY("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE joined >= ".START_TDAY, __FILE__, __LINE__));
-
- // Only males / females
- $male = SQL_NUMROWS(SQL_QUERY("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE gender='M' AND `status`='CONFIRMED'", __FILE__, __LINE__));
- $female = SQL_NUMROWS(SQL_QUERY("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE gender='F' AND `status`='CONFIRMED'", __FILE__, __LINE__));
-
- // Unconfirmed accounts
- $unconfirmed = SQL_NUMROWS(SQL_QUERY("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE status != 'CONFIRMED'", __FILE__, __LINE__));
-
- // Total members
- $total = $male + $female;
-
- // List every month
- $months = array();
- for ($idx = 1; $idx < 13; $idx++)
- {
- $month = $idx; if ($idx < 10) $month = "0".$idx;
- $months[$month] = SQL_NUMROWS(SQL_QUERY_ESC("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE birth_month=%s AND `status`='CONFIRMED'",
- array(bigintval($month)), __FILE__, __LINE__));
- }
-
- // Members in categories
- $result = SQL_QUERY("SELECT id, cat FROM `{!_MYSQL_PREFIX!}_cats` WHERE `visible`='Y' ORDER BY `id`", __FILE__, __LINE__);
-
- // Load categories first
- $cats = array(); $cat_cnt = array();
- while (list($id, $cat) = SQL_FETCHROW($result)) {
- // Simple...
- $cats[$id] = $cat;
- }
-
- // Now we have all categories loaded, count members
- foreach ($cats as $id => $dummy) {
- // We only need id and nothing more to count...
- $cat_cnt[$id] = SQL_NUMROWS(SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_user_cats` WHERE cat_id=%s",
- array(bigintval($id)), __FILE__, __LINE__));
- }
-
- // Prepare data for the template
- define('__TOTAL_USERS' , $total);
- define('__UNCONFIRMED' , $unconfirmed);
- define('__MALE_COUNT' , $male);
- define('__FEMALE_COUNT', $female);
- define('__TMEM_COUNT' , $tmem);
- define('__YMEM_COUNT' , $ymem);
- define('__TREG_COUNT' , $treg);
- define('__YREG_COUNT' , $yreg);
- define('__LMODE_VALUE' , $lmode);
- define('__LINK_TITLE' , $ltitle);
-
- // Generate monthly stats
- $SW = 2; $r2 = " right2"; $l = "ll"; $r = "lr"; $OUT = "";
- foreach ($months as $month => $cnt)
- {
- if ($SW == 2) $OUT .= "<tr>\n";
-
- // Prepare data for template
- $content = array(
- 'l_class' => $l,
- 'm_descr' => $GLOBALS['month_descr'][$month],
- 'r_class' => $r,
- 'r2_class' => $r2,
- 'cnt' => $cnt
- );
-
- // Load row template
- $OUT .= LOAD_TEMPLATE("guest_stats_month_row", true, $content);
-
- if ($SW == 2)
- {
- $r2 = "";
- $l = "rl"; $r = "rr";
- }
- else
- {
- $OUT .= "</tr>\n";
- $r2 = " right2";
- $l = "ll"; $r = "lr";
- }
- $SW = 3 - $SW;
- }
- define('__MONTH_STATS_ROWS', $OUT);
-
- // Generate category stats
- $SW = 2; $OUT = "";
- foreach ($cat_cnt as $id => $cnt)
- {
+// Set link title
+$ltitle = '{--GUEST_STATS_' . strtoupper($lmode) . '--}';
+
+// @TODO This can be rewritten in a dynamic include
+switch (getConfig('guest_stats')) {
+ case 'MEMBERS': // Statistics about your members
+ // Only males / females
+ $male = countSumTotalData('M', 'user_data', 'userid', 'gender', true, " AND `status`='CONFIRMED'");
+ $female = countSumTotalData('F', 'user_data', 'userid', 'gender', true, " AND `status`='CONFIRMED'");
+
+ // List every month
+ $months = array();
+ for ($idx = 1; $idx < 13; $idx++) {
+ // Copy it so we don't touch the for() loop index
+ $month = $idx;
+
+ // Append leading zero
+ if ($idx < 10) $month = '0' . $idx;
+
+ // Count months
+ $months[$month] = countSumTotalData(bigintval($month), 'user_data', 'userid', 'birth_month', true, " AND `status`='CONFIRMED'");
+ } // END - for
+
+ // Members in categories
+ $result = SQL_QUERY("SELECT `id`, `cat` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `visible`='Y' ORDER BY `id` ASC", __FILE__, __LINE__);
+
+ // Load categories first
+ $cats = array(); $cat_cnt = array();
+
+ // @TODO This can be somehow rewritten
+ while ($content = SQL_FETCHARRAY($result)) {
+ // Simple...
+ $cats[$content['id']] = $content['cat'];
+ } // END - while
+
+ // Now we have all categories loaded, count members
+ foreach ($cats as $id => $dummy) {
+ // We only need id and nothing more to count...
+ $cat_cnt[$id] = countSumTotalData(bigintval($id), 'user_cats', 'id', 'cat_id', true);
+ } // END - foreach
+
// Prepare data for the template
- $content = array(
- 'sw' => $SW,
- 'cat' => $cats[$id],
- 'cnt' => $cnt,
- );
-
- // Load row template and switch colors
- $OUT .= LOAD_TEMPLATE("guest_stats_cats_row", true, $content);
- $SW = 3 - $SW;
- }
- define('__CATS_STATS_ROWS', $OUT);
-
- // Load final template
- LOAD_TEMPLATE("guest_stats_member");
- break;
-
-case "MODULES": // TOP10 module clicks
- $AND = "";
- if (!IS_ADMIN()) $AND = " AND `locked`='N' AND `visible`='Y'";
- $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__);
- $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__);
- if ((SQL_NUMROWS($guest_t10) > 0) || (SQL_NUMROWS($mem_t10) > 0)) {
- // Output header
- OUTPUT_HTML("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"guest_table dashed\" width=\"310\">
-<tr>
- <td align=\"center\" class=\"guest_stats_title bottom2\" colspan=\"2\"><strong>{--GUEST_TOPTEN_STATS--}</strong></td>
-</tr>");
- }
-
- if (SQL_NUMROWS($guest_t10) > 0) {
- // Guest clicks
- OUTPUT_HTML("<tr>
- <td align=\"center\" class=\"guest_title2 bottom2\" colspan=\"2\">{--GUEST_TOP_GUEST_STATS--}</td>
-</tr>");
- $SW = 2;
- while (list($clicks, $title) = SQL_FETCHROW($guest_t10)) {
- OUTPUT_HTML("<tr>
- <td class=\"switch_sw".$SW." bottom2 right2\" align=\"right\" width=\"250\">".$title." </td>
- <td class=\"switch_sw".$SW." bottom2\" width=\"50\"> ".$clicks."</td>
-</tr>");
- $SW = 3 - $SW;
- }
- }
-
- if (SQL_NUMROWS($guest_t10) > 0) {
- // Guest clicks
- OUTPUT_HTML("<tr>
- <td align=\"center\" class=\"guest_title2 bottom2\" colspan=\"2\">{--GUEST_TOP_MEMBER_STATS--}</td>
-</tr>");
- $SW = 2;
- while (list($clicks, $title) = SQL_FETCHROW($mem_t10)) {
- OUTPUT_HTML("<tr>
- <td class=\"switch_sw".$SW." bottom2 right2\" align=\"right\" width=\"250\">".$title." </td>
- <td class=\"switch_sw".$SW." bottom2\" width=\"50\"> ".$clicks."</td>
-</tr>");
+ $content['total_users'] = ($male + $female);
+ $content['unconfirmed'] = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `status` != 'CONFIRMED'", __FILE__, __LINE__));
+ $content['total_males'] = $male;
+ $content['total_females'] = $female;
+ $content['tmem_count'] = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `last_online` >= {?START_TDAY?} AND `status`='CONFIRMED'", __FILE__, __LINE__));
+ $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__));
+ $content['treg_count'] = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `joined` >= {?START_TDAY?}", __FILE__, __LINE__));
+ $content['yreg_count'] = SQL_NUMROWS(SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `joined` >= {?START_YDAY?} AND `joined` < {?START_TDAY?}", __FILE__, __LINE__));
+ $content['lmode'] = $lmode;
+ $content['ltitle'] = $ltitle;
+
+ // Generate monthly stats
+ $SW = 2; $r2 = ' right'; $l = 'll'; $r = 'lr'; $OUT = '';
+ foreach ($months as $month => $count) {
+ if ($SW == 2) $OUT .= '<tr>';
+
+ // Prepare data for template
+ $data = array(
+ 'l_class' => $l,
+ 'm_descr' => $GLOBALS['month_descr'][$month],
+ 'r_class' => $r,
+ 'r2_class' => $r2,
+ 'cnt' => $count
+ );
+
+ // Load row template
+ $OUT .= loadTemplate('guest_stats_month_row', true, $data);
+
+ if ($SW == 2) {
+ $r2 = '';
+ $l = 'rl'; $r = 'rr';
+ } else {
+ $OUT .= '</tr>';
+ $r2 = ' right';
+ $l = 'll'; $r = 'lr';
+ }
$SW = 3 - $SW;
+ } // END - foreach
+ $content['month_rows'] = $OUT;
+
+ // Generate category stats
+ $OUT = '';
+ foreach ($cat_cnt as $id => $count) {
+ // Prepare data for the template
+ $data = array(
+ 'cat' => $cats[$id],
+ 'cnt' => $count,
+ );
+
+ // Load row template and switch colors
+ $OUT .= loadTemplate('guest_stats_cats_row', true, $data);
+ } // END - foreach
+ $content['cats_rows'] = $OUT;
+
+ // Load final template
+ loadTemplate('guest_stats_member', false, $content);
+ break;
+
+ case 'MODULES': // TOP10 module clicks
+ // Admins may see all menus
+ $AND = " AND `locked`='N' AND `visible`='Y'";
+ if (isAdmin()) $AND = '';
+
+ // Query for guest and member menus
+ $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__);
+ $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__);
+ $OUT = '';
+
+ if (!SQL_HASZERONUMS($guest_t10)) {
+ // Guest clicks
+ $OUT .= loadTemplate('guest_stats_header', true, '{--GUEST_TOP_GUEST_STATS--}');
+ while ($content = SQL_FETCHARRAY($guest_t10)) {
+ // Load row template
+ $OUT .= loadTemplate('guest_stats_row', true, $content);
+ } // END - while
+ } // END - if
+
+ if (!SQL_HASZERONUMS($mem_t10)) {
+ // Member clicks
+ $OUT .= loadTemplate('guest_stats_header', true, '{--GUEST_TOP_MEMBER_STATS--}');
+ while ($content = SQL_FETCHARRAY($mem_t10)) {
+ // Load row template
+ $OUT .= loadTemplate('guest_stats_row', true, $content);
+ } // END - while
+ } // END - if
+
+ if ((!SQL_HASZERONUMS($guest_t10)) || (!SQL_HASZERONUMS($mem_t10))) {
+ // Prepare content
+ $content = array(
+ 'rows' => $OUT,
+ 'lmode' => $lmode,
+ 'ltitle' => $ltitle
+ );
+
+ // Load final template
+ loadTemplate('guest_stats_table', false, $content);
+ } else {
+ // No clicks detected
+ displayMessage('{--GUEST_STATS_NO_CLICKS--}');
}
- }
-
- if ((SQL_NUMROWS($guest_t10) > 0) || (SQL_NUMROWS($mem_t10) > 0)) {
- // Output footer
- OUTPUT_HTML("<tr>
- <td align=\"center\" class=\"guest_stats_footer\" colspan=\"2\"><a href=\"{!URL!}/modules.php?module=index&what=stats&mode=".$lmode."\">".$ltitle."</a></td>
-</tr>
-</table>");
- }
- break;
-
-case "INACTIVE": // Deactivated stats
- LOAD_TEMPLATE("admin_settings_saved", false, "<strong>{--GUEST_STATS_DEACTIVATED--}</strong>");
- break;
-}
+ break;
+
+ case 'INACTIVE': // Deactivated stats
+ displayMessage('{--GUEST_STATS_DEACTIVATED--}');
+ break;
+} // END - switch
-//
+// [EOF]
?>