Location: PHPKode > projects > phpCAMALEO > common/private/Stat_show.php
<?php
/***************************************************************************
 *	Stat_show.php
 *
 *	begin		: June 2004
 *	version		: 20 September 2006
 *	copyright	: (C) 2004,2005 grandolini.net
 *
 *	Show statistics
 *
 ***************************************************************************/
include('../../Session.php');
check_access($USER_ID,$USER_PW,80);
#
require($_SESSION[common].'fun2inc/get_http_file.inc');
require($_SESSION[common].'fun2inc/get_port.inc');
require($_SESSION[common].'fun2inc/showtable.inc');
require($_SESSION[common].'fun2inc/bar_graph.inc');
require($_SESSION[common].'fun2inc/loadarraydata.inc');
require($_SESSION[common].'fun2inc/organizedata.inc');
#	include($_SESSION[common].'fun2inc/prep_prev_next.inc');
if(file_exists($_SESSION[skinf].'def/'.$_SESSION[sitelanguage].'/stat_show_defs.php'))
{
	include_once($_SESSION[skinf].'def/'.$_SESSION[sitelanguage].'/stat_show_defs.php');
}
if(file_exists($_SERVER[DOCUMENT_ROOT].$_SESSION[misc][folder].'skins/phpCAMALEO/def/'.$_SESSION[sitelanguage].'/stat_show_defs.php'))
{
	include_once($_SERVER[DOCUMENT_ROOT].$_SESSION[misc][folder].'skins/phpCAMALEO/def/'.$_SESSION[sitelanguage].'/stat_show_defs.php');
}

if(!isset($_SESSION[misc][stat_autoreload])) { $_SESSION[auto_delay]=3; } else { $_SESSION[auto_delay]=$_SESSION[misc][stat_autoreload]; }
#
#	Prepare arrays
#
if(isset($opt_val)==false)
{
	$opt_val=array('0'=>SS_SELECT,'1'=>SS_USERS,'2'=>SS_COUNTRY,'3'=>SS_PAGES);
	#
	for($i=1;$i<13;$i++) { $opt_mm[$i]=constant(MM_.str_pad($i,2,'0',STR_PAD_LEFT)); }
	#
	$temp=date('Y'); $i=($temp-($temp-1))+1;	# Year before
	while($i>0) { $opt_yy[$temp]=$temp; $temp=$temp-1; $i=$i-1; }
	#
	$opt_clus=array('1'=>SS_YEAR,'2'=>SS_MONT,'3'=>SS_WEEK,'4'=>SS_DAY,'5'=>SS_TOTP );
}
#
#	Set initial options values
#
if(!isset($feedback_str)) { $feedback_str=''; }
if(!isset($opt_selected)) { $opt_selected='0'; $opt_value=$opt_val[0]; }
if(!isset($qry_option)) { $qry_option=''; }

if(!isset($opt_sel_from_dd)) { $opt_sel_from_dd=1; }
if(!isset($val_sel_from_dd)) { $val_sel_from_dd=1; }
if(!isset($opt_sel_from_mm)) { $opt_sel_from_mm=1; }
if(!isset($val_sel_from_mm)) { $val_sel_from_mm=$opt_mm[1]; }
if(!isset($opt_sel_from_yy)) { $opt_sel_from_yy=1; }
if(!isset($val_sel_from_yy)) { $val_sel_from_yy=$opt_yy[(date('Y'))]; }

$temp=date('d');	if(!isset($opt_sel_to_dd)) { $opt_sel_to_dd=$temp; }
$temp=date('n');	if(!isset($opt_sel_to_mm)) { $opt_sel_to_mm=$temp; }
					if(!isset($val_sel_to_mm)) { $val_sel_to_mm=$opt_mm[$temp]; }
$temp=date('Y');	if(!isset($opt_sel_to_yy)) { $opt_sel_to_yy=$temp; }
					if(!isset($val_sel_to_yy)) { $val_sel_to_yy=$opt_yy[$temp]; }
if(!isset($opt_sel_clus)) { $opt_sel_clus='1'; $val_sel_clus=$opt_clus[1]; }
#
#	Load user choices for the auto reload feature
#
if( (isset($_SESSION[auto_reload]) && $_SESSION[auto_reload]==true) && (!isset($_POST[submit])) 
	 || $_POST[submit]==SS_20 )
{
	$_POST[c_auto]	=$_SESSION[auto_reload];
	$_POST[opt]		=$_SESSION[auto_opt];
	$_POST[from_dd]	=$_SESSION[auto_from_dd];
	$_POST[from_mm]	=$_SESSION[auto_from_mm];
	$_POST[from_yy]	=$_SESSION[auto_from_yy];
	$_POST[to_dd]	=$_SESSION[auto_to_dd];
	$_POST[to_mm]	=$_SESSION[auto_to_mm];
	$_POST[to_yy]	=$_SESSION[auto_to_yy];
	$_POST[clus]	=$_SESSION[auto_clus];

	$_POST[submit] 	='Ok';
}
#
#	Load user choices for when the ordering data changes
#
if(isset($_GET[sort]) && $_GET[sort]!='')
{
	$_SESSION[sort]=$_GET[sort];

	$_POST[c_auto]	=$_SESSION[auto_reload];
	$_POST[opt]		=$_SESSION[auto_opt];
	$_POST[from_dd]	=$_SESSION[auto_from_dd];
	$_POST[from_mm]	=$_SESSION[auto_from_mm];
	$_POST[from_yy]	=$_SESSION[auto_from_yy];
	$_POST[to_dd]	=$_SESSION[auto_to_dd];
	$_POST[to_mm]	=$_SESSION[auto_to_mm];
	$_POST[to_yy]	=$_SESSION[auto_to_yy];
	$_POST[clus]	=$_SESSION[auto_clus];

	$_POST[submit] 	='Ok';
}
#
#	When user click on the button, sets variables as choosen by user	
#
if(isset($_POST[submit]) && $_POST[submit]=='Ok')
{
	#
	#	Set TYPE of statistic
	#
	if($_POST[opt])
	{
		$temp=$_POST[opt][0];
		if(strlen($temp)==1) { $opt_selected=$temp; } else { $opt_val=array_flip($opt_val); $opt_selected=$opt_val[$temp]; $opt_val=array_flip($opt_val); }
		$opt_value=$opt_val[$opt_selected];
	}
	#
	#	Set FROM variables as selected by user
	#
	if($_POST[from_dd])
	{
		$opt_sel_from_dd=$_POST[from_dd][0];
		$val_sel_from_dd=$opt_sel_from_dd;
	}
	if($_POST[from_mm])
	{
		$temp=$_POST[from_mm][0];
		if(strlen($temp)>2)
		{
			$opt_mm=array_flip($opt_mm);
			$opt_sel_from_mm=$opt_mm[$temp];
			$opt_mm=array_flip($opt_mm);
		}
		else
		{
			$opt_sel_from_mm=$_POST[from_mm][0];
		}
		$val_sel_from_mm=$opt_mm[$opt_sel_from_mm];
	}
	if($_POST[from_yy]) 
	{
		$opt_sel_from_yy=$_POST[from_yy][0];
		$val_sel_from_yy=$opt_sel_from_yy;
	}
	#
	#	Set TO variables as selected by user
	#
	if($_POST[to_dd])
	{
		$opt_sel_to_dd=$_POST[to_dd][0];
		$val_sel_to_dd=$opt_sel_to_dd;
	}
	if($_POST[to_mm])
	{
		$temp=$_POST[to_mm][0];
		if(strlen($temp)>2)
		{
			$opt_mm=array_flip($opt_mm);
			$opt_sel_to_mm=$opt_mm[$temp];
			$opt_mm=array_flip($opt_mm);
		}
		else
		{
			$opt_sel_to_mm=$_POST[to_mm][0];
		}
		$val_sel_to_mm=$opt_mm[$opt_sel_to_mm];
	}
	if($_POST[to_yy])
	{
		$opt_sel_to_yy=$_POST[to_yy][0];
		$val_sel_to_yy=$opt_sel_to_yy;
	}
	#
	#	Set CLUSTER variables as selected by user
	#
	if($_POST[clus]) 
	{
		$temp=$_POST[clus][0];
		if(strlen($temp)==1) 
		{
			$opt_sel_clus=$temp;
		}
		else
		{
			$val_sel_clus=array_flip($opt_clus);
			$opt_sel_clus=$val_sel_clus[$temp];
			$val_sel_clus=array_flip($opt_clus);
		}
		$val_sel_clus=$opt_clus[$opt_sel_clus];
	}
	#
	#	Set checkbox to automatically reload the page
	#
	$c_auto=$_POST[c_auto];
	if($c_auto[1]=='Auto') { $c_auto[1]==true; }
	#
	#	Set options for query
	#
	$qry_option=$opt_selected;
	$from=$val_sel_from_yy.'-'.str_pad($opt_sel_from_mm, 2, '0', STR_PAD_LEFT).'-'.str_pad($opt_sel_from_dd, 2, '0', STR_PAD_LEFT);
	$to=$val_sel_to_yy.'-'.str_pad($opt_sel_to_mm, 2, '0', STR_PAD_LEFT).'-'.str_pad($opt_sel_to_dd, 2, '0', STR_PAD_LEFT);
/*		if($opt_sel_clus=='2') {	# Monthly YYYY-MM
		$from=substr($from, 0, 7);
		$to=substr($to, 0, 7);
	}*/
	#
	#	Save user choices for the auto reload feature
	#
	$_SESSION[auto_reload]	=$_POST[c_auto];
	$_SESSION[auto_page]	=basename($_SERVER[PHP_SELF]);
	$_SESSION[auto_opt]		=$_POST[opt];
	$_SESSION[auto_from_dd]	=$_POST[from_dd];
	$_SESSION[auto_from_mm]	=$_POST[from_mm];
	$_SESSION[auto_from_yy]	=$_POST[from_yy];
	$_SESSION[auto_to_dd]	=$_POST[to_dd];
	$_SESSION[auto_to_mm]	=$_POST[to_mm];
	$_SESSION[auto_to_yy]	=$_POST[to_yy];
	$_SESSION[auto_clus]	=$_POST[clus];
	#
	#
	#
/*	$feedback='OKIDOKI';	# $feedback=user_access();	#-------------------> verify values?
	if($feedback=='OKIDOKI') 
	{
#		/*header('Location: http://'.$_SERVER[HTTP_HOST]
#					.dirname($_SERVER[PHP_SELF])
#					.'/'."Welcome.php");
		#-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
	}
	else { $feedback_str=$feedback; } */
	#
	#
	#
}
else { $feedback_str=''; }

$PageNr='showstat';
$_SESSION[PageNr]=strtolower($PageNr);
$resetmenu='Y';
if((isset($_POST[submit]) && $_POST[submit]==SS_3) || $_GET[act]=='setprm')
{
	$_SESSION[stat_show][select]='';
	$_SESSION[auto_reload]='';
	$_POST[c_auto]='';
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title>phpCAMALEO.org @> Site statistics <?=$_SESSION[misc][server_name_title]?></title>

	<meta http-equiv="resource-type" content="text/html; charset=iso-8859-1">
	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">

	<meta name="copyright" content="copyright (c) by grandolini.net">
	<meta name="author" content="grandolini.net">

	<link href="../../skins/<?=$_SESSION[misc][skin]?>/alfa2.ico" rel="shortcut icon" type="image/x-icon" />
	<link href="../../skins/<?=$_SESSION[misc][skin]?>/MAIN.CSS" rel="stylesheet" type="text/css" />

	<?php
	switch($_SESSION[browser])
	{
		case 'FF': ?><link rel="stylesheet" href="../../skins/<?=$_SESSION[misc][skin]?>/MAIN_FF.CSS" type="text/css" /><?php break;
		case 'IE': ?><link rel="stylesheet" href="../../skins/<?=$_SESSION[misc][skin]?>/MAIN_IE.CSS" type="text/css" /><?php break;
	}
	if($_POST[c_auto]!='' && $_SESSION[auto_delay]>0) { echo "\n"; ?><meta http-equiv="refresh" content="<?=$_SESSION[auto_delay]*60?>; URL=<?=$_SERVER[PHP_SELF]?>"><?php }
	echo "\n"; ?>
	<script type="text/javascript" src="common/js/fun2inc.js"></script>
	<script type="text/javascript" src="common/js/tableHi.js"></script>
</head>
<body style="margin:10px 10px 10px 10px;">
<form method="post" action="<?=$_SERVER[PHP_SELF]?>">
<table class="datatable" width="100%" cellpadding="0" cellspacing="0">
<tr>
	<td align="left"><h1><?=SS_1?></h1><a href="../../LoadPage.php?page=siteADMIN"><font id="sml0">ADMIN HOME</font></a></td>
	<td align="right"><small><?=SS_2?>: <?=date('j/M/Y G:i O T')?></small></td>
</tr>
<tr>
	<td align="left" height="25px">
		<img src="../../img/trasp.gif" width="15" height="5" border="0" />
		<?php
		if( (isset($_SESSION[auto_reload]) && $_SESSION[auto_reload]==true)
				&&
			 (isset($_SESSION[auto_page]) && basename($_SERVER[PHP_SELF])==$_SESSION[auto_page]) )
		 {
		 	echo SS_12.' '.$_SESSION[auto_delay].' '.SS_13;
		 }
		 ?>
	</td>
	<td align="right"><?=$info?>&nbsp;<input class="button_sml" type="submit" name="submit" value="<?=SS_3?>" /></td>
</tr>
</table>
<img src="../../img/trasp.gif" width="15" height="8" border="0" />
<?php
$sth=db_query("SELECT * FROM g_stat_misc WHERE stat_misc_skin='".$_SESSION[misc][skin]."' AND stat_misc_key='*max_online'");
$row=db_fetch($sth[0]);

$max_v_online=$row[0][stat_misc_val];	if($max_v_online=='') { $max_v_online=0; }
$max_d_online=$row[0][stat_misc_date];	if($max_d_online=='') { $max_d_online='200001011200'; }
$tmp_date=substr($max_d_online,6,2).' '.$opt_mm[(strval(substr($max_d_online,4,2))+0)].' '.substr($max_d_online,0,4);
$tmp_time=substr($max_d_online,8,2).':'.substr($max_d_online,10,2);

$sth=db_query("SELECT DISTINCT stat_online_ip FROM g_stat_online WHERE stat_online_skin='".$_SESSION[misc][skin]."'");
$online=$sth[1];
?><div align="center"><?=SS_4?>: <font id="rev"><strong><?=$max_v_online?></strong></font> <?=SS_5?>: <font id="rev"><strong><?=$tmp_date?>&nbsp;<?=$tmp_time?></strong></font>&nbsp;<?=SS_6?>: <font id="rev"><strong><?=$online?></strong></font><br /><?php
$result=false;
switch($qry_option) 
{
	case 1:	# users_online
		include($_SESSION[common].'contents/stat_useronline.inc');
		$result=stat_useronline($from, $to);
		break;

	case 2:	# visits per language
		include($_SESSION[common].'contents/stat_visitlanguage.inc');
		$result=stat_visitlanguage($from, $to);
		break;

	case 3:	# pages accesses
		include($_SESSION[common].'contents/stat_visitpage.inc');
		$result=stat_visitpage($from, $to);
		break;

	default:
		# Do nothing
}
if((isset($_POST[submit]) && $_POST[submit]=='Ok' && $result==true) || $_POST[submit]==SS_20)
{
	$param =SS_15.': <font id="rev">'.$opt_val[$_SESSION[auto_opt][0]].'</font>&nbsp;';
	$param.=SS_16.': <font id="rev">'.$_SESSION[auto_from_dd][0].' '.$_SESSION[auto_from_mm][0].' '.$_SESSION[auto_from_yy][0].'</font>&nbsp;';
	$param.=SS_17.': <font id="rev">'.$_SESSION[auto_to_dd][0].' '.$_SESSION[auto_to_mm][0].' '.$_SESSION[auto_to_yy][0].'</font>&nbsp;';
	if(strlen($_SESSION[auto_clus][0])==1) {$tmp=$opt_clus[$_SESSION[auto_clus][0]];} else {$tmp=$_SESSION[auto_clus][0];}; 
	$param.=SS_18.': <font id="rev">'.$tmp.'</font>&nbsp;';
	?><br /><?=$param?><?php
#}
#if((isset($_POST[submit]) && $_POST[submit]=='Ok') && $result==true)
#{
	$_SESSION[stat_show][select]='ok';
}
if($_SESSION[stat_show][select]=='' || (isset($_POST[submit]) && $_POST[submit]=='Ok' && $result!=true))	
{
	include($_SESSION[common].'contents/Stat_show.tpl');
}
?>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr><td height="20px"></td></tr>
	<tr><td align="center"><font style="font-size:x-small;">&copy; 2006 grandolini.net &mdash; All Rights Reserved.</font></td></tr>
	<tr><td height="10px"></td></tr>
</table>
</form>
</body>
</html>
<?php
#
#
#
#	Common functions
#
#
#
#-------------------------------------------------------
#	Organize data && totalize visits
#
function DecodeIP($data_key_length, 
				  $is_week, 
				  $data_label, 
				  &$labels, 
				  &$table_field, 
				  $fields_record, 
				  $decode='')
#-------------------------------------------------------
{
	$tot_records=count($table_field);	$nr_of_dataset=$tot_records/$fields_record;
	$i=0;
	$cluster=array();
	#
	#	Replace ip with country flag & name
	#
	include_once($_SERVER[DOCUMENT_ROOT].$_SESSION[misc][folder].'plugins/get_country.inc');
	$last_country='';
	while($i<$tot_records) 
	{
		$ii=0;
		while($ii<$fields_record)
		{
			$data=$table_field[$i+$ii];
			switch($ii) 
			{
				case 0:	$table_field[$i+$ii]=substr($data,8,2).'-'.substr($data,5,2).'-'.substr($data,0,4);	break;
				case 2:	if($data!=$last_country)
						{
							$tmp=get_country($country_server,$country_serverf.'getcountry.php?req='.$_SERVER[HTTP_HOST].'&cid='.$getcountryKEY.'&inquiry=2&ip='.$data);
							list($country_name,$country_code,$country_code3,$country_language)=explode("\t",$tmp);
							$last_country=$data;
						}
						$table_field[$i+$ii]='<img src="http://'.$country_server.$country_serverf.'img/'.strtolower($country_flag?$country_flag:'__').'.png" width="25" height="15" alt="'.strtolower($country_flag?$country_flag:'__').'.png" title="'.$country_name.'" />';
						$table_field[$i+$ii].=' '.rtrim($country_name);
						$table_field[$i+$ii].=' ('.$data.')';
						break;
			}
			$ii++;
		}
		$i=$i+$fields_record;
	}
}
?>
Return current item: phpCAMALEO