Location: PHPKode > projects > MGB OpenSource Guestbook > mgb-0.6.9.1/admin/stats.inc.php
<?php
	/*
	MGB 0.6.x - OpenSource PHP and MySql Guestbook
	Copyright (C) 2004 - 2011 Juergen Grueneisl - http://www.m-gb.org/

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
	*/

	// =================== //
	// stats.inc.php - 1.0 //
	// =================== //
	//
	// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //

	// make sure nobody has direct acces to this script
	if (!defined('ADMINISTRATION'))
		{
		include ("error.html");
		die();
		}
	else
		{
		require ("../includes/functions.inc.php");

		if(!isset($_GET['action'])) { $_GET['action'] = "settings"; }
		if(check_rights($_GET['action'], $_SESSION['ID']))
			{
			// connect to database
			$link = @mysql_connect($db['hostname'], $db['username'], $db['password']) or die ("(stats.inc.php) Error, line 41: ".mysql_error());
			@mysql_select_db($db['dbname'], $link) or die ("(stats.inc.php) Error, line 42: ".mysql_error());

			// get total number of entries
			$link_count = "SELECT COUNT(ID) FROM ".$db['prefix']."entries";
			$results = @mysql_query($link_count) or die ("(stats.inc.php) Error, line 46: ".mysql_error());
			$total = @mysql_result($results, 0);

			// load guestbook entries
			$sql = "SELECT name, hp, timestamp, user_show_email FROM ".$db['prefix']."entries";
			$result = @mysql_query($sql, $link) or die ("(stats.inc.php) Error, line 51: ".mysql_error());

			for($i = 0; $i < @mysql_num_rows($result); $i++)
				{
				$entry[$i] = @mysql_fetch_array($result);
				}

			// define variables
			if (!isset($hp_count)) { $hp_count = 0; }

			if($total > 0)
				{
				for($i = 0; $i < count($entry); $i++)
					{
					// compute how many users have a homepage
					if ($entry[$i]['hp'] != "") { $hp_count++; }

					// date of the first entry
					$time_sfe = $entry[0]['timestamp'];
					}
				}
			}
		}

	$now = time();
	$days_sfe = round(($now - $time_sfe) / 86400, 2);
	$weeks_sfe = round($days_sfe / 7, 2);
	$months_sfe = round($weeks_sfe / 4, 2);
	$years_sfe = round($months_sfe / 12, 2);

	$entries_per_day = round($total / $days_sfe, 2);
	$entries_per_week = round($total / $weeks_sfe, 2);
	$entries_per_month = round($total / $months_sfe, 2);
	$entries_per_year = round($total / $years_sfe, 2);
	$time_be = round($days_sfe / $total, 2);

	echo $days_sfe." Tage<br>";
	echo $weeks_sfe." Wochen<br>";
	echo $months_sfe." Monate<br>";
	echo $years_sfe." Jahre<br><br>";
	echo "Durchschnittlich ".$entries_per_day." Eintraege pro Tag.<br>";
	echo "Durchschnittlich ".$entries_per_week." Eintraege pro Woche.<br>";
	echo "Durchschnittlich ".$entries_per_month." Eintraege pro Monat.<br>";
	echo "Durchschnittlich ".$entries_per_year." Eintraege pro Jahr.<br>";
	echo "Durchschnittlich wurde alle ".$time_be." Tage ein Eintrag gemacht.<br>";
	echo $total." Leute haben sich eingetragen.<br>";
	echo $hp_count." Leute haben eine Homepage.<br>";
?>
Return current item: MGB OpenSource Guestbook