<?php
/**
 * $Source: /home/cvs/nukescripts/modules/Statistics/index.php,v $
 * $Revision: 1.0.0a $
 * $Author: cyril $
 * $Date: 2006/10/17 21:23:10 $
 * Fix GravuTrad Bug 179 ( 17/10/2006)
 */
/************************************************************************/
/* Maximus CMS: Web Portal System                                       */
/* ==============================                                       */
/*                                                                      */
/* Copyright (c) 2002 - 2006                                            */
/* http://www.php-maximus.fr                                            */
/* dev@php-maximus.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.       */
/************************************************************************/
/* Based on PHP-NUKE: Web Portal System                                 */
/************************************************************************/
defined('MAXIMUS') or Header("Location: ../../index.php");

$module_name = "Statistics";
get_lang($module_name);
$pagetitle = "- "._STATS."";
if (isset($year)) {
	$year = $db->XMFnum($year);
}
$ThemeSel = get_theme();

$now = date("d-m-Y");
$dot = explode ("-",$now);
$nowdate = $dot[0];
$nowmonth = $dot[1];
$nowyear = $dot[2];

function Stats_Main() {
	global $prefix, $db, $startdate, $sitename, $ThemeSel, $user_prefix, $Version_Num, $module_name, $textcolor2;
	incoh();
	$sql = "SELECT `type`, `var`, `count` FROM `".TABLE_COUNTER."` ORDER BY `type` DESC";
	if ( !($result = $db->sql_query($sql)) )
{ query_die(GENERAL_ERROR, 'Could not obtain counter modules', '', __LINE__, __FILE__, $sql);}
	while ($row = $db->sql_fetchrow($result)) {
		$type = stripslashes(check_html($row['type'], "nohtml"));
		$var  = stripslashes(check_html($row['var'], "nohtml"));
		$count = $db->XMFnum($row['count']);
		if(($type == "total") && ($var == "hits")) {
			$total = $count;
		} elseif($type == "browser") {
			if($var == "FireFox") {
				$firefox[] = $count;
				$firefox[] = substr(100 * $count / $total, 0, 5);
			} elseif($var == "Netscape") {
				$netscape[] = $count;
				$netscape[] = substr(100 * $count / $total, 0, 5);
			} elseif($var == "MSIE") {
				$msie[] = $count;
				$msie[] =  substr(100 * $count / $total, 0, 5);
			} elseif($var == "Konqueror") {
				$konqueror[] = $count;
				$konqueror[] =  substr(100 * $count / $total, 0, 5);
			} elseif($var == "Opera") {
				$opera[] = $count;
				$opera[] =  substr(100 * $count / $total, 0, 5);
			} elseif($var == "Lynx") {
				$lynx[] = $count;
				$lynx[] =  substr(100 * $count / $total, 0, 5);
			} elseif($var == "Bot") {
				$bot[] = $count;
				$bot[] =  substr(100 * $count / $total, 0, 5);
			} elseif(($type == "browser") && ($var == "Other")) {
				$b_other[] = $count;
				$b_other[] =  substr(100 * $count / $total, 0, 5);
			}
		} elseif($type == "os") {
			if($var == "Windows") {
				$windows[] = $count;
				$windows[] =  substr(100 * $count / $total, 0, 5);
			} elseif($var == "Mac") {
				$mac[] = $count;
				$mac[] =  substr(100 * $count / $total, 0, 5);
			} elseif($var == "Linux") {
				$linux[] = $count;
				$linux[] =  substr(100 * $count / $total, 0, 5);
			} elseif($var == "FreeBSD") {
				$freebsd[] = $count;
				$freebsd[] =  substr(100 * $count / $total, 0, 5);
			} elseif($var == "SunOS") {
				$sunos[] = $count;
				$sunos[] =  substr(100 * $count / $total, 0, 5);
			} elseif($var == "IRIX") {
				$irix[] = $count;
				$irix[] =  substr(100 * $count / $total, 0, 5);
			} elseif($var == "BeOS") {
				$beos[] = $count;
				$beos[] =  substr(100 * $count / $total, 0, 5);
			} elseif($var == "OS/2") {
				$os2[] = $count;
				$os2[] =  substr(100 * $count / $total, 0, 5);
			} elseif($var == "AIX") {
				$aix[] = $count;
				$aix[] =  substr(100 * $count / $total, 0, 5);
			} elseif(($type == "os") && ($var == "Other")) {
				$os_other[] = $count;
				$os_other[] =  substr(100 * $count / $total, 0, 5);
			}
		}
	}
	title("$sitename "._STATS."");
	Max_OpenTable();
	Max_OpenTable();
	echo "<center><font class=\"option\"><b>$sitename "._STATS."</b></font><br /><br />"._WERECEIVED." <b>$total</b> "._PAGESVIEWS." $startdate<br /><br />"
	."[ <a href=\"modules.php?name=$module_name&op=Stats\">"._VIEWDETAILED."</a> ]</center>";
	Max_CloseTable();
	br('2');
	$l_size = getimagesize("themes/$ThemeSel/images/leftbar.gif");
	$m_size = getimagesize("themes/$ThemeSel/images/mainbar.gif");
	$r_size = getimagesize("themes/$ThemeSel/images/rightbar.gif");
	Max_OpenTable2();
	echo "<table cellspacing=\"0\" cellpadding=\"2\" border=\"0\" align=\"center\"><tr><td colspan=\"2\">\n";
	echo "<center><font color=\"$textcolor2\"><b>"._BROWSERS."</b></font></center><br /></td></tr>\n";
	echo "<tr><td><img src=\"modules/$module_name/images/explorer.gif\" border=\"0\" alt=\"\" />&nbsp;MSIE: </td><td><img src=\"themes/$ThemeSel/images/leftbar.gif\" height=\"$l_size[1]\" width=\"$l_size[0]\" alt=\"Internet Explorer\" /><img src=\"themes/$ThemeSel/images/mainbar.gif\" alt=\"Internet Explorer\" height=\"$m_size[1]\" width=", $msie[1] * 2, " /><img src=\"themes/$ThemeSel/images/rightbar.gif\" height=\"$r_size[1]\" width=\"$r_size[0]\" alt=\"Internet Explorer\" /> $msie[1] % ($msie[0])</td></tr>\n";
	echo "<tr><td><img src=\"modules/$module_name/images/firefox.gif\" border=\"0\" alt=\"\" />&nbsp;FireFox: </td><td><img src=\"themes/$ThemeSel/images/leftbar.gif\" height=\"$l_size[1]\" width=\"$l_size[0]\" alt=\"FireFox\"><img src=\"themes/$ThemeSel/images/mainbar.gif\" alt=\"FireFox\" height=\"$m_size[1]\" width=", $firefox[1] * 2, "><img src=\"themes/$ThemeSel/images/rightbar.gif\" height=\"$r_size[1]\" width=\"$r_size[0]\" alt=\"FireFox\"> $firefox[1] % ($firefox[0])</td></tr>\n";
	echo "<tr><td><img src=\"modules/$module_name/images/netscape.gif\" border=\"0\" alt=\"\">&nbsp;Netscape: </td><td><img src=\"themes/$ThemeSel/images/leftbar.gif\" height=\"$l_size[1]\" width=\"$l_size[0]\" alt=\"Netscape\"><img src=\"themes/$ThemeSel/images/mainbar.gif\" alt=\"Netscape\" height=\"$m_size[1]\" width=", $netscape[1] * 2, "><img src=\"themes/$ThemeSel/images/rightbar.gif\" height=\"$r_size[1]\" width=\"$r_size[0]\" alt=\"Netscape\"> $netscape[1] % ($netscape[0])</td></tr>\n";
	echo "<tr><td><img src=\"modules/$module_name/images/opera.gif\" border=\"0\" alt=\"\">&nbsp;Opera: </td><td><img src=\"themes/$ThemeSel/images/leftbar.gif\" height=\"$l_size[1]\" width=\"$l_size[0]\" alt=\"Opera\"><img src=\"themes/$ThemeSel/images/mainbar.gif\" alt=\"Opera\" height=\"$m_size[1]\" width=", $opera[1] * 2, "><img src=\"themes/$ThemeSel/images/rightbar.gif\" height=\"$r_size[1]\" width=\"$r_size[0]\" alt=\"Opera\"> $opera[1] % ($opera[0])</td></tr>\n";
	echo "<tr><td><img src=\"modules/$module_name/images/konqueror.gif\" border=\"0\" alt=\"\" />&nbsp;Konqueror: </td><td><img src=\"themes/$ThemeSel/images/leftbar.gif\" height=\"$l_size[1]\" width=\"$l_size[0]\" alt=\"Konqueror\" /><img src=\"themes/$ThemeSel/images/mainbar.gif\" alt=\"Konqueror (KDE)\" height=\"$m_size[1]\" width=", $konqueror[1] * 2, " /><img src=\"themes/$ThemeSel/images/rightbar.gif\" height=\"$r_size[1]\" width=\"$r_size[0]\" alt=\"Konqueror\" /> $konqueror[1] % ($konqueror[0])</td></tr>\n";
	echo "<tr><td><img src=\"modules/$module_name/images/lynx.gif\" border=\"0\" alt=\"\" />&nbsp;Lynx: </td><td><img src=\"themes/$ThemeSel/images/leftbar.gif\" height=\"$l_size[1]\" width=\"$l_size[0]\" alt=\"Lynx\" /><img src=\"themes/$ThemeSel/images/mainbar.gif\" alt=\"Lynx\" height=\"$m_size[1]\" width=", $lynx[1] * 2, " /><img src=\"themes/$ThemeSel/images/rightbar.gif\" height=\"$r_size[1]\" width=\"$r_size[0]\" alt=\"Lynx\" /> $lynx[1] % ($lynx[0])</td></tr>\n";
	echo "<tr><td><img src=\"modules/$module_name/images/altavista.gif\" border=\"0\" alt=\"\" />&nbsp;"._SEARCHENGINES.": </td><td><img src=\"themes/$ThemeSel/images/leftbar.gif\" height=\"$l_size[1]\" width=\"$l_size[0]\" alt=\"Robots - Spiders - Buscadores\" /><img src=\"themes/$ThemeSel/images/mainbar.gif\" alt=\"Robots - Spiders - Buscadores\" height=\"$m_size[1]\" width=", $bot[1] * 2, " /><img src=\"themes/$ThemeSel/images/rightbar.gif\" height=\"$r_size[1]\" width=\"$r_size[0]\" alt=\""._BOTS."\" /> $bot[1] % ($bot[0])</td></tr>\n";
	echo "<tr><td><img src=\"modules/$module_name/images/question.gif\" border=\"0\" alt=\"\" />&nbsp;"._UNKNOWN.": </td><td><img src=\"themes/$ThemeSel/images/leftbar.gif\" height=\"$l_size[1]\" width=\"$l_size[0]\" alt=\"Otros - Desconocidos\" /><img src=\"themes/$ThemeSel/images/mainbar.gif\" alt=\"Otros - Desconocidos\" height=\"$m_size[1]\" width=", $b_other[1] * 2, " /><img src=\"themes/$ThemeSel/images/rightbar.gif\" height=\"$r_size[1]\" width=\"$r_size[0]\" alt=\""._OTHER."\" /> $b_other[1] % ($b_other[0])\n";
	echo "</td></tr></table>";
	Max_CloseTable2();
	br('2');
	Max_OpenTable2();
	echo "<table cellspacing=\"0\" cellpadding=\"2\" border=\"0\" align=\"center\"><tr><td colspan=\"2\">\n";
	echo "<center><font color=\"$textcolor2\"><b>"._OPERATINGSYS."</b></font></center><br /></td></tr>\n";
	echo "<tr><td><img src=\"modules/$module_name/images/windows.gif\" border=\"0\" alt=\"\" />&nbsp;Windows:</td><td><img src=\"themes/$ThemeSel/images/leftbar.gif\" height=\"$l_size[1]\" width=\"$l_size[0]\" alt=\"Windows\" /><img src=\"themes/$ThemeSel/images/mainbar.gif\" alt=\"Windows\" height=\"$m_size[1]\" width=", $windows[1] * 2, " /><img src=\"themes/$ThemeSel/images/rightbar.gif\" height=\"$r_size[1]\" width=\"$r_size[0]\" alt=\"Windows\" /> $windows[1] % ($windows[0])</td></tr>\n";
	echo "<tr><td><img src=\"modules/$module_name/images/linux.gif\" border=\"0\" alt=\"\" />&nbsp;Linux:</td><td><img src=\"themes/$ThemeSel/images/leftbar.gif\" height=\"$l_size[1]\" width=\"$l_size[0]\" alt=\"Linux\" /><img src=\"themes/$ThemeSel/images/mainbar.gif\" alt=\"Linux\" height=\"$m_size[1]\" width=", $linux[1] * 2, " /><img src=\"themes/$ThemeSel/images/rightbar.gif\" height=\"$r_size[1]\" width=\"$r_size[0]\" alt=\"Linux\" /> $linux[1] % ($linux[0])</td></tr>\n";
	echo "<tr><td><img src=\"modules/$module_name/images/mac.gif\" border=\"0\" alt=\"\" />&nbsp;Mac/PPC:</td><td><img src=\"themes/$ThemeSel/images/leftbar.gif\" height=\"$l_size[1]\" width=\"$l_size[0]\" alt=\"Mac/PPC\" /><img src=\"themes/$ThemeSel/images/mainbar.gif\" alt=\"Mac - PPC\" height=\"$m_size[1]\" width=", $mac[1] * 2, " /><img src=\"themes/$ThemeSel/images/rightbar.gif\" height=\"$r_size[1]\" width=\"$r_size[0]\" alt=\"Mac/PPC\" /> $mac[1] % ($mac[0])</td></tr>\n";
	echo "<tr><td><img src=\"modules/$module_name/images/bsd.gif\" border=\"0\" alt=\"\" />&nbsp;FreeBSD:</td><td><img src=\"themes/$ThemeSel/images/leftbar.gif\" height=\"$l_size[1]\" width=\"$l_size[0]\" alt=\"FreeBSD\" /><img src=\"themes/$ThemeSel/images/mainbar.gif\" alt=\"FreeBSD\" height=\"$m_size[1]\" width=", $freebsd[1] * 2, " /><img src=\"themes/$ThemeSel/images/rightbar.gif\" height=\"$r_size[1]\" width=\"$r_size[0]\" alt=\"FreeBSD\" /> $freebsd[1] % ($freebsd[0])</td></tr>\n";
	echo "<tr><td><img src=\"modules/$module_name/images/sun.gif\" border=\"0\" alt=\"\" />&nbsp;SunOS:</td><td><img src=\"themes/$ThemeSel/images/leftbar.gif\" height=\"$l_size[1]\" width=\"$l_size[0]\" alt=\"SunOS\" /><img src=\"themes/$ThemeSel/images/mainbar.gif\" alt=\"SunOS\" height=\"$m_size[1]\" width=", $sunos[1] * 2, " /><img src=\"themes/$ThemeSel/images/rightbar.gif\" height=\"$r_size[1]\" width=\"$r_size[0]\" alt=\"SunOS\" /> $sunos[1] % ($sunos[0])</td></tr>\n";
	echo "<tr><td><img src=\"modules/$module_name/images/irix.gif\" border=\"0\" alt=\"\" />&nbsp;IRIX:</td><td><img src=\"themes/$ThemeSel/images/leftbar.gif\" height=\"$l_size[1]\" width=\"$l_size[0]\" alt=\"SGI Irix\" /><img src=\"themes/$ThemeSel/images/mainbar.gif\" alt=\"SGI Irix\" height=\"$m_size[1]\" width=", $irix[1] * 2, " /><img src=\"themes/$ThemeSel/images/rightbar.gif\" height=\"$r_size[1]\" width=\"$r_size[0]\" alt=\"SGI Irix\" /> $irix[1] % ($irix[0])</td></tr>\n";
	echo "<tr><td><img src=\"modules/$module_name/images/be.gif\" border=\"0\" alt=\"\" />&nbsp;BeOS:</td><td><img src=\"themes/$ThemeSel/images/leftbar.gif\" height=\"$l_size[1]\" width=\"$l_size[0]\" alt=\"BeOS\" /><img src=\"themes/$ThemeSel/images/mainbar.gif\" alt=\"BeOS\" height=\"$m_size[1]\" width=", $beos[1] * 2, " /><img src=\"themes/$ThemeSel/images/rightbar.gif\" height=\"$r_size[1]\" width=\"$r_size[0]\" alt=\"BeOS\" /> $beos[1] % ($beos[0])</td></tr>\n";
	echo "<tr><td><img src=\"modules/$module_name/images/os2.gif\" border=\"0\" alt=\"\" />&nbsp;OS/2:</td><td><img src=\"themes/$ThemeSel/images/leftbar.gif\" height=\"$l_size[1]\" width=\"$l_size[0]\" alt=\"OS/2\" /><img src=\"themes/$ThemeSel/images/mainbar.gif\" alt=\"OS/2\" height=\"$m_size[1]\" width=", $os2[1] * 2, " /><img src=\"themes/$ThemeSel/images/rightbar.gif\" height=\"$r_size[1]\" width=\"$r_size[0]\" alt=\"OS/2\" /> $os2[1] % ($os2[0])</td></tr>\n";
	echo "<tr><td><img src=\"modules/$module_name/images/aix.gif\" border=\"0\" alt=\"\" />&nbsp;AIX:</td><td><img src=\"themes/$ThemeSel/images/leftbar.gif\" height=\"$l_size[1]\" width=\"$l_size[0]\" alt=\"AIX\" /><img src=\"themes/$ThemeSel/images/mainbar.gif\" alt=\"AIX\" height=\"$m_size[1]\" width=", $aix[1] * 2, " /><img src=\"themes/$ThemeSel/images/rightbar.gif\" height=\"$r_size[1]\" width=\"$r_size[0]\" alt=\"AIX\" /> $aix[1] % ($aix[0])</td></tr>\n";
	echo "<tr><td><img src=\"modules/$module_name/images/question.gif\" border=\"0\" alt=\"\" />&nbsp;"._UNKNOWN.":</td><td><img src=\"themes/$ThemeSel/images/leftbar.gif\" height=\"$l_size[1]\" width=\"$l_size[0]\" alt=\"Otros - Desconocidos\" /><img src=\"themes/$ThemeSel/images/mainbar.gif\" ALt=\"Otros - Desconocidos\" height=\"$m_size[1]\" width=", $os_other[1] * 2, " /><img src=\"themes/$ThemeSel/images/rightbar.gif\" height=\"$r_size[1]\" width=\"$r_size[0]\" alt=\""._OTHER."\" /> $os_other[1] % ($os_other[0])\n";
	echo "</td></tr></table>\n";
	Max_CloseTable2();
	br('2');

	$unum = $db->sql_numrows($db->sql_query("SELECT `user_id` FROM `".TABLE_USERS."`"));
	$anum = $db->sql_numrows($db->sql_query("SELECT `aid` FROM `".TABLE_AUTHORS."`"));
	$snum = $db->sql_numrows($db->sql_query("SELECT `sid` FROM `".TABLE_STORIES."`"));
	$cnum = $db->sql_numrows($db->sql_query("SELECT `tid` FROM `".TABLE_COMMENTS."`"));
	$subnum = $db->sql_numrows($db->sql_query("SELECT `qid` FROM `".TABLE_QUEUE."`"));
	if (is_active("Topics")) {
		$tnum = $db->sql_numrows($db->sql_query("SELECT `topicid` FROM ".TABLE_TOPICS.""));
	}
	if (is_active("Web_Links")) {
		$links = $db->sql_numrows($db->sql_query("SELECT `lid` FROM `".TABLE_LINKS_LINKS."`"));
		$cat = $db->sql_numrows($db->sql_query("SELECT `cid` FROM `".TABLE_LINKS_CATEGORIES."`"));
	}
	Max_OpenTable2();
	echo "<table cellspacing=\"0\" cellpadding=\"2\" border=\"0\" align=\"center\"><tr><td colspan=\"2\">\n";
	echo "<center><font color=\"$textcolor2\"><b>"._MISCSTATS."</b></font></center><br /></td></tr>\n";
	echo "<tr><td><img src=\"modules/$module_name/images/users.gif\" border=\"0\" alt=\"\" />&nbsp;"._REGUSERS."</td><td><b>$unum</b></td></tr>\n";
	echo "<tr><td><img src=\"modules/$module_name/images/authors.gif\" border=\"0\" alt=\"\" />&nbsp;"._ACTIVEAUTHORS."</td><td><b>$anum</b></td></tr>\n";
	echo "<tr><td><img src=\"modules/$module_name/images/news.gif\" border=\"0\" alt=\"\" />&nbsp;"._STORIESPUBLISHED."</td><td><b>$snum</b></td></tr>\n";
	if (is_active("Topics")) {
		echo "<tr><td><img src=\"modules/$module_name/images/topics.gif\" border=\"0\" alt=\"\" />&nbsp;"._SACTIVETOPICS."</td><td><b>$tnum</b></td></tr>\n";
	}
	echo "<tr><td><img src=\"modules/$module_name/images/comments.gif\" border=\"0\" alt=\"\" />&nbsp;"._COMMENTSPOSTED."</td><td><b>$cnum</b></td></tr>\n";
	if (is_active("Web_Links")) {
		echo "<tr><td><img src=\"modules/$module_name/images/topics.gif\" border=\"0\" alt=\"\" />&nbsp;"._LINKSINLINKS."</td><td><b>$links</b></td></tr>\n";
		echo "<tr><td><img src=\"modules/$module_name/images/sections.gif\" border=\"0\" alt=\"\" />&nbsp;"._LINKSCAT."</td><td><b>$cat</b></td></tr>\n";
	}
	echo "</table>\n";
	Max_CloseTable2();
	Max_CloseTable();
	incof();
}

function Stats($total) {
	global $hlpfile,$nowyear,$nowmonth,$nowdate,$nowhour, $sitename, $startdate, $prefix, $db, $now, $module_name;
	$sql = "SELECT `count` from `".TABLE_COUNTER."` ORDER BY `type` DESC";
	if ( !($result = $db->sql_query($sql)) )
{ query_die(GENERAL_ERROR, 'Could not obtain counter modules', '', __LINE__, __FILE__, $sql);}
	$row = $db->sql_fetchrow($result);
	$total = $db->XMFnum($row['count']);
	incoh();
	title("$sitename "._STATS."");
	$total++;
	Max_OpenTable();
	Max_OpenTable();
	echo "<center><font class=\"option\"><b>$sitename "._STATS."</b></font><br /><br />"._WERECEIVED." <b>$total</b> "._PAGESVIEWS." $startdate<br />"._TODAYIS.": $now<br /><br />";
	$row2 = $db->sql_fetchrow($db->sql_query("SELECT `year`, `month`, `hits` FROM `".TABLE_STATS_MONTH."` ORDER BY `hits` DESC LIMIT 0,1"));
	$year  = $db->XMFnum($row2['year']);
	$month = $db->XMFnum($row2['month']);
	$hits  = $db->XMFnum($row2['hits']);
	if ($month == 1) {$month = _JANUARY;} elseif ($month == 2) {$month = _FEBRUARY;} elseif ($month == 3) {$month = _MARCH;} elseif ($month == 4) {$month = _APRIL;} elseif ($month == 5) {$month = _MAY;} elseif ($month == 6) {$month = _JUNE;} elseif ($month == 7) {$month = _JULY;} elseif ($month == 8) {$month = _AUGUST;} elseif ($month == 9) {$month = _SEPTEMBER;} elseif ($month == 10) {$month = _OCTOBER;} elseif ($month == 11) {$month = _NOVEMBER;} elseif ($month == 12) {$month = _DECEMBER;}
	echo ""._MOSTMONTH.": $month $year ($hits "._HITS.")<br />";
	$row3 = $db->sql_fetchrow($db->sql_query("SELECT `year`, `month`, `date`, `hits` from `".TABLE_STATS_DATE."` order by `hits` DESC LIMIT 0,1"));
	$year  = $db->XMFnum($row3['year']);
	$month = $db->XMFnum($row3['month']);
	$date  = $db->XMFnum($row3['date']);
	$hits  = $db->XMFnum($row3['hits']);
	if ($month == 1) {$month = _JANUARY;} elseif ($month == 2) {$month = _FEBRUARY;} elseif ($month == 3) {$month = _MARCH;} elseif ($month == 4) {$month = _APRIL;} elseif ($month == 5) {$month = _MAY;} elseif ($month == 6) {$month = _JUNE;} elseif ($month == 7) {$month = _JULY;} elseif ($month == 8) {$month = _AUGUST;} elseif ($month == 9) {$month = _SEPTEMBER;} elseif ($month == 10) {$month = _OCTOBER;} elseif ($month == 11) {$month = _NOVEMBER;} elseif ($month == 12) {$month = _DECEMBER;}
	echo ""._MOSTDAY.": $date $month $year ($hits "._HITS.")<br />";
	$row4 = $db->sql_fetchrow($db->sql_query("SELECT `year`, `month`, `date`, `hour`, `hits` FROM `".TABLE_STATS_HOUR."` ORDER BY `hits` DESC LIMIT 0,1"));
	$year  = $db->XMFnum($row4['year']);
	$month = $db->XMFnum($row4['month']);
	$date  = $db->XMFnum($row4['date']);
	$hour  = $db->XMFnum($row4['hour']);
	$hits  = $db->XMFnum($row4['hits']);
	if ($month == 1) {$month = _JANUARY;} elseif ($month == 2) {$month = _FEBRUARY;} elseif ($month == 3) {$month = _MARCH;} elseif ($month == 4) {$month = _APRIL;} elseif ($month == 5) {$month = _MAY;} elseif ($month == 6) {$month = _JUNE;} elseif ($month == 7) {$month = _JULY;} elseif ($month == 8) {$month = _AUGUST;} elseif ($month == 9) {$month = _SEPTEMBER;} elseif ($month == 10) {$month = _OCTOBER;} elseif ($month == 11) {$month = _NOVEMBER;} elseif ($month == 12) {$month = _DECEMBER;}
	if ($hour < 10) {
		$hour = "0$hour:00 - 0$hour:59";
	} else {
		$hour = "$hour:00 - $hour:59";
	}
	echo ""._MOSTHOUR.": $hour "._ON." $month $date, $year ($hits "._HITS.")<br /><br />"
	."[ <a href=\"modules.php?name=$module_name\">"._RETURNBASICSTATS."</a> ]</center>";

	Max_CloseTable();
	br('2');
	showYearStats($nowyear);
	br('2');
	showMonthStats($nowyear,$nowmonth);
	br('2');
	showDailyStats($nowyear,$nowmonth,$nowdate);
	br('2');
	showHourlyStats($nowyear,$nowmonth,$nowdate);
	br('2');
	echo "<center>"._GOBACK."</center>";
	br('2');
	Max_CloseTable();
	incof();
}

function YearlyStats($year){
	global $hlpfile,$nowyear,$nowmonth,$nowdate, $sitename, $module_name, $db;
	incoh();
	title("$sitename "._STATS."");
	Max_opentable();
	$year     = $db->XMFnum($year);
	$nowmonth = $db->XMFnum($nowmonth);
	showMonthStats($year,$nowmonth);
	br('1');
	echo "<center>[ <a href=\"modules.php?name=$module_name\">"._BACKTOMAIN."</a> | <a href=\"modules.php?name=$module_name&amp;op=Stats\">"._BACKTODETSTATS."</a> ]</center>";
	Max_CloseTable();
	incof();
}

function MonthlyStats($year,$month){
	global $sitename, $module_name, $nowdate, $db;
	incoh();
	title("$sitename "._STATS."");
	Max_opentable();
	$year    = $db->XMFnum($year);
	$month   = $db->XMFnum($month);
	$nowdate = $db->XMFnum($nowdate);
	showDailyStats($year,$month,$nowdate);
	br('1');
	echo "<center>[ <a href=\"modules.php?name=$module_name\">"._BACKTOMAIN."</a> | <a href=\"modules.php?name=$module_name&amp;op=Stats\">"._BACKTODETSTATS."</a> ]</center>";
	Max_CloseTable();
	incof();
}

function DailyStats($year,$month,$date){
	global $sitename, $module_name, $db;
	incoh();
	title("$sitename "._STATS."");
	Max_opentable();
	$year  = $db->XMFnum($year);
	$month = $db->XMFnum($month);
	$date  = $db->XMFnum($date);
	showHourlyStats($year,$month,$date);
	br('1');
	echo "<center>[ <a href=\"modules.php?name=$module_name\">"._BACKTOMAIN."</a> | <a href=\"modules.php?name=$module_name&amp;op=Stats\">"._BACKTODETSTATS."</a> ]</center>";
	Max_CloseTable();
	incof();
}


function showYearStats($nowyear){
	global $db,$prefix,$bgcolor1,$bgcolor2, $ThemeSel, $module_name;
	$l_size = getimagesize("themes/$ThemeSel/images/leftbar.gif");
	$m_size = getimagesize("themes/$ThemeSel/images/mainbar.gif");
	$r_size = getimagesize("themes/$ThemeSel/images/rightbar.gif");
	$sql = "SELECT sum(hits) as TotalHitsYear FROM `".TABLE_STATS_YEAR."`";
	if ( !($result = $db->sql_query($sql)) )
{ query_die(GENERAL_ERROR, 'Could not obtain stats_year modules', '', __LINE__, __FILE__, $sql);}
	$row = $db->sql_fetchrow($result);
	$TotalHitsYear = $db->XMFnum($row['TotalHitsYear']);
	$db->sql_freeresult($resulttotal);
	$result = $db->sql_query("SELECT `year`, `hits` FROM `".TABLE_STATS_YEAR."` ORDER BY `year`");
	echo "<center><b>"._YEARLYSTATS."</b></center><br />";
	echo "<table align=\"center\" bgcolor=\"#000000\" cellspacing=\"1\" cellpadding=\"3\" border=\"0\">";
	echo "<tr><td width=\"25%\" bgcolor=\"$bgcolor2\">"._YEAR."</td><td bgcolor=\"$bgcolor2\">"._SPAGESVIEWS."</td></tr>";
	while($row = $db->sql_fetchrow($result)) {
		$year = $db->XMFnum($row['year']);
		$hits = $db->XMFnum($row['hits']);
		echo "<tr bgcolor=\"$bgcolor1\"><td>";
		if ($year != $nowyear) {
			echo "<a href=\"modules.php?name=$module_name&amp;op=YearlyStats&amp;year=$year\">$year</a>";
		} else {
			echo "$year";
		}
		echo "</td><td>";
		$WidthIMG = round(100 * $hits/$TotalHitsYear,0);
		echo "<img src=\"themes/$ThemeSel/images/leftbar.gif\" alt=\"\" width=\"$l_size[0]\" height=\"$l_size[1]\" /><img src=\"themes/$ThemeSel/images/mainbar.gif\" height=\"$m_size[1]\" width=",$WidthIMG * 2," alt=\"\" />"
		."<img src=\"themes/$ThemeSel/images/rightbar.gif\" alt=\"\" width=\"$r_size[0]\" height=\"$r_size[1]\" /> ($hits)</td></tr>";
	}
	$db->sql_freeresult($result);
	echo "</table>";
}

function showMonthStats($nowyear,$nowmonth){
	global $prefix,$bgcolor1,$bgcolor2,$db, $ThemeSel, $module_name, $db;
	$l_size = getimagesize("themes/$ThemeSel/images/leftbar.gif");
	$m_size = getimagesize("themes/$ThemeSel/images/mainbar.gif");
	$r_size = getimagesize("themes/$ThemeSel/images/rightbar.gif");
	$sql = "SELECT sum(hits) as TotalHitsMonth FROM `".TABLE_STATS_MONTH."` WHERE `year`='$nowyear'";
	if ( !($result = $db->sql_query($sql)) )
{ query_die(GENERAL_ERROR, 'Could not obtain stats_month modules', '', __LINE__, __FILE__, $sql);}
	$row = $db->sql_fetchrow($result);
	$TotalHitsMonth = $db->XMFnum($row['TotalHitsMonth']);
	$db->sql_freeresult($resultmonth);
	$result = $db->sql_query("SELECT `month`, `hits` FROM `".TABLE_STATS_MONTH."` WHERE `year`='$nowyear'");
	echo "<center><b>"._MONTLYSTATS." $nowyear</b></center><br />";
	echo "<table align=\"center\" bgcolor=\"#000000\" cellspacing=\"1\" cellpadding=\"3\" border=\"0\">";
	echo "<tr><td width=\"25%\" bgcolor=\"$bgcolor2\">"._UMONTH."</td><td bgcolor=\"$bgcolor2\">"._SPAGESVIEWS."</td></tr>";
	while($row = $db->sql_fetchrow($result)) {
		$month = $db->XMFnum($row['month']);
		$hits  = $db->XMFnum($row['hits']);
		echo "<tr bgcolor=\"$bgcolor1\"><td>";
		if ($month != $nowmonth) {
			echo "<a href=\"modules.php?name=$module_name&amp;op=MonthlyStats&amp;year=$nowyear&amp;month=$month\" class=\"hover_orange\">";
			getmonth($month);
			echo "</a>";
		} else {
			getmonth($month);
		}
		echo "</td><td>";
		$WidthIMG = round(100 * $hits/$TotalHitsMonth,0);
		echo "<img src=\"themes/$ThemeSel/images/leftbar.gif\" alt=\"\" width=\"$l_size[0]\" height=\"$l_size[1]\" /><img src=\"themes/$ThemeSel/images/mainbar.gif\" height=\"$m_size[1]\" width=",$WidthIMG * 2," alt=\"\" />";
		echo "<img src=\"themes/$ThemeSel/images/rightbar.gif\" alt=\"\" width=\"$r_size[0]\" height=\"$r_size[1]\" /> ($hits)</td></tr>";
		echo "</td></tr>";
	}
	$db->sql_freeresult($result);
	echo "</table>";
}

function showDailyStats($year,$month,$nowdate){
	global $prefix,$bgcolor1,$bgcolor2,$db, $ThemeSel, $module_name, $db;
	$l_size = getimagesize("themes/$ThemeSel/images/leftbar.gif");
	$m_size = getimagesize("themes/$ThemeSel/images/mainbar.gif");
	$r_size = getimagesize("themes/$ThemeSel/images/rightbar.gif");
	$sql = "SELECT sum(hits) as TotalHitsDate FROM `".TABLE_STATS_DATE."` WHERE `year`='$year' AND `month`='$month'";
	if ( !($result = $db->sql_query($sql)) )
{ query_die(GENERAL_ERROR, 'Could not obtain stats_date modules', '', __LINE__, __FILE__, $sql);}
	$row = $db->sql_fetchrow($result);
	$TotalHitsDate = $db->XMFnum($row['TotalHitsDate']);
	$db->sql_freeresult($resulttotal);
	$result = $db->sql_query("SELECT `year`, `month`, `date`, `hits` FROM `".TABLE_STATS_DATE."` WHERE `year`='$year' AND `month`='$month' ORDER BY `date`");
	$total = $db->sql_numrows($result);
	echo "<center><b>"._DAILYSTATS." ";
	getmonth($month);
	echo ", $year</b></center><br />";
	echo "<table align=\"center\" bgcolor=\"#000000\" cellspacing=\"1\" cellpadding=\"3\" border=\"0\">";
	echo "<tr><td width=\"25%\" bgcolor=\"$bgcolor2\">"._DATE."</td><td bgcolor=\"$bgcolor2\">"._SPAGESVIEWS."</td></tr>";
	while($row = $db->sql_fetchrow($result)) {
		$year  = $db->XMFnum($row['year']);
		$month = $db->XMFnum($row['month']);
		$date  = $db->XMFnum($row['date']);
		$hits  = $db->XMFnum($row['hits']);
		echo "<tr bgcolor=\"$bgcolor1\"><td>";
		if ($date != $nowdate) {
			echo "<a href=\"modules.php?name=$module_name&amp;op=DailyStats&amp;year=$year&amp;month=$month&amp;date=$date\" class=\"hover_orange\">";
			echo $date;
			echo "</a>";
		} else {
			echo $date;
		}
		echo "</td><td>";
		if ($hits == 0) {
			$WidthIMG = 0;
			$d_percent = 0;
		} else {
			$WidthIMG = round(100 * $hits/$TotalHitsDate,0);
			$d_percent = substr(100 * $hits / $TotalHitsDate, 0, 5);
		}
		echo "<img src=\"themes/$ThemeSel/images/leftbar.gif\" alt=\"\" width=\"$l_size[0]\" height=\"$l_size[1]\" /><img src=\"themes/$ThemeSel/images/mainbar.gif\" height=\"$m_size[1]\" width=",$WidthIMG * 2," alt=\"\" />"
		."<img src=\"themes/$ThemeSel/images/rightbar.gif\" alt=\"\" width=\"$r_size[0]\" height=\"$r_size[1]\" /> $d_percent% ($hits)</td></tr>"
		."</td></tr>";
	}
	$db->sql_freeresult($result);
	echo "</table>";
}

function showHourlyStats($year,$month,$date){
	global $prefix,$bgcolor1,$bgcolor2,$db, $ThemeSel, $db;
	$l_size = getimagesize("themes/$ThemeSel/images/leftbar.gif");
	$m_size = getimagesize("themes/$ThemeSel/images/mainbar.gif");
	$r_size = getimagesize("themes/$ThemeSel/images/rightbar.gif");
	$sql = "SELECT sum(hits) as TotalHitsHour FROM `".TABLE_STATS_HOUR."` WHERE `year`='$year' AND `month`='$month' AND `date`='$date'";
	if ( !($result = $db->sql_query($sql)) )
{ query_die(GENERAL_ERROR, 'Could not obtain stats_hour modules', '', __LINE__, __FILE__, $sql);}
	$row = $db->sql_fetchrow($result);
	$TotalHitsHour = $db->XMFnum($row['TotalHitsHour']);
	$db->sql_freeresult($resulttotal);
	$nowdate = date("d-m-Y");
	$nowdate_arr = explode("-",$nowdate);
	echo "<center><b>"._HOURLYSTATS." ";
	echo getmonth($month)." ".$date.", " .$year."</b></center><br />";
	echo "<table align=\"center\" bgcolor=\"#000000\" cellspacing=\"1\" cellpadding=\"3\" border=\"0\">";
	echo "<tr><td width=\"25%\" bgcolor=\"$bgcolor2\">"._HOUR."</td><td bgcolor=\"$bgcolor2\" width=\"70%\">"._SPAGESVIEWS."</td></tr>";
	for ($k = 0;$k<=23;$k++) {
		$result = $db->sql_query("SELECT `hour`, `hits` FROM `".TABLE_STATS_HOUR."` WHERE `year`='$year' AND `month`='$month' AND `date`='$date' AND `hour`='$k'");
		if ($db->sql_numrows($result) == 0){
			$hits=0;
		} else {
			$row = $db->sql_fetchrow($result);
			$hour = $db->XMFnum($row['hour']);
			$hits = $db->XMFnum($row['hits']);
		}
		echo "<tr><td bgcolor=\"$bgcolor1\">";
		if ($k < 10) {
			$a = "0$k";
		} else {
			$a = $k;
		}
		echo "$a:00 - $a:59";
		$a = "";
		echo "</td><td bgcolor=\"$bgcolor1\">";
		if ($hits == 0) {
			$WidthIMG = 0;
			$d_percent = 0;
		} else {
			$WidthIMG = round(100 * $hits/$TotalHitsHour,0);
			$d_percent = substr(100 * $hits / $TotalHitsHour, 0, 5);
		}
		echo "<img src=\"themes/$ThemeSel/images/leftbar.gif\" alt=\"\" width=\"$l_size[0]\" height=\"$l_size[1]\" /><img src=\"themes/$ThemeSel/images/mainbar.gif\" height=\"$m_size[1]\" width=",$WidthIMG * 2," alt=\"\" />"
		."<img src=\"themes/$ThemeSel/images/rightbar.gif\" alt=\"\" width=\"$r_size[0]\" height=\"$r_size[1]\" /> $d_percent% ($hits)</td></tr>"
		."</td></tr>";
	}
	$db->sql_freeresult($result);
	echo "</table>";
}

function getmonth($month){
	if ($month == 1) echo ""._JANUARY."";
	if ($month == 2) echo ""._FEBRUARY."";
	if ($month == 3) echo ""._MARCH."";
	if ($month == 4) echo ""._APRIL."";
	if ($month == 5) echo ""._MAY."";
	if ($month == 6) echo ""._JUNE."";
	if ($month == 7) echo ""._JULY."";
	if ($month == 8) echo ""._AUGUST."";
	if ($month == 9) echo ""._SEPTEMBER."";
	if ($month == 10) echo ""._OCTOBER."";
	if ($month == 11) echo ""._NOVEMBER."";
	if ($month == 12) echo ""._DECEMBER."";
}

switch($op) {

	default:
	Stats_Main();
	break;

	case "Stats":
	Stats($total);
	break;

	case "YearlyStats":
	YearlyStats($year);
	break;

	case "MonthlyStats":
	MonthlyStats($year,$month);
	break;

	case "DailyStats":
	DailyStats($year,$month,$date);
	break;

}