Location: PHPKode > projects > phpCAMALEO > common/contents/stat_visitlanguage.inc
<?php
if(function_exists('stat_visitlanguage'))	return;

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# version: 24 October 2006
#
function stat_visitlanguage($from,$to)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{
	global $opt_sel_clus, $tot_value;
	#
	$args="SELECT date, stat_lang_lang, 'iptoc_dec', stat_lang_visits, 

			SUM(stat_lang_visits) AS stat_lang_visits

			FROM g_stat_lang 
			WHERE stat_lang_skin='".$_SESSION[misc][skin]."' AND stat_lang_date>='$from' AND stat_lang_date<='$to' ";
	#
	switch($opt_sel_clus)
	{
		case 1:	$args=eregi_replace('SELECT date,', 'SELECT SUBSTRING(stat_lang_date,1,4),', $args);
				$args.=' GROUP BY SUBSTRING(stat_lang_date,1,4), stat_lang_lang ';
				break;

		case 2:	$args=eregi_replace('SELECT date,', 'SELECT SUBSTRING(stat_lang_date,1,7),', $args);
				$args.= 'GROUP BY SUBSTRING(stat_lang_date,1,7), stat_lang_lang ';
				break;

		case 3:	$args=eregi_replace('SELECT date,', 'SELECT YEARWEEK(stat_lang_date,1),', $args);
				$args.=' GROUP BY YEARWEEK(stat_lang_date,1), stat_lang_lang ';
				break;

		case 4:	$args=eregi_replace('SELECT date,', 'SELECT stat_lang_date,', $args);
				$args.=' GROUP BY SUBSTRING(stat_lang_date,1,10), stat_lang_lang ';
				break;

		case 5:	$args=eregi_replace('SELECT date,', 'SELECT SUBSTRING(stat_lang_date,1,1),', $args);
				$args.=' GROUP BY SUBSTRING(stat_lang_date,1,1), stat_lang_lang ';
				break;
	}
	switch($_SESSION[sort])
	{
		case SS_U3:	$args.=' ORDER BY stat_lang_date ASC ';							break; # Country
		case SS_23:	$args.=' ORDER BY stat_lang_visits DESC, stat_lang_date ASC ';	break; # Visits
	}
	$sth=db_query($args);
	#
	#	Add country name
	#
	include_once($_SERVER[DOCUMENT_ROOT].$_SESSION[misc][folder].'/plugins/get_country.inc');
	if($sth[1]>0)
	{
		$t=$sth[1]; $rows=db_fetch($sth[0]); $last_country='';
		for($i=0;$i<$t;$i++)
		{
			$ccode2=$rows[$i][stat_lang_lang];
			if($last_country!=$ccode2)
			{
				$last_country=$ccode2;
				$tmp=get_country($country_server,$country_serverf.'getcountry.php?req='.$_SERVER[HTTP_HOST].'&cid='.$getcountryKEY.'&inquiry=2&ccod='.$ccode2);
				list($country[country_name],$country[country_code],$country[country_code3],$country[country_language])=explode("\t",$tmp);
			}
			if($country[country_name]=='') { $country[country_name]='"'.$ccode2.'" &rArr; '._NA; }
			$rows[$i][iptoc_dec]=$country[country_name];
		}
	}
	#
	if($_SESSION[sort]==SS_U3)
	{
		#	Obtain a list of columns
		#
		foreach($rows as $key=>$row) { $desc[$key]=$row[iptoc_dec]; $date[$key]=$row[stat_lang_date]; }
		#
		#	Sort the data with volume descending, edition ascending
		#	Add $data as the last parameter, to sort by the common key
		#
		array_multisort($desc,SORT_ASC,$date,SORT_DESC,$rows);
	}
	#
	if($sth[1]>0)
	{
		$labels=array(); $table_field=array(); $fields_record=LoadArrayData($rows, $labels, $table_field);
		switch($opt_sel_clus)
		{
			case 1:	$data_label[0]=_YEAR;
					$data_label[1]=SS_C1;
					$data_label[2]=SS_U3;
					$data_label[3]=SS_21.'@r';
					OrganizeData('',$data_label,$labels,$table_field,$fields_record,'country','country');
					$bar=bar_graph(3,$fields_record,$table_field);
					break;

			case 2:	$data_label[0]=_MONTH;
					$data_label[1]=SS_C1;
					$data_label[2]=SS_U3;
					$data_label[3]=SS_21.'@r';
					OrganizeData('',$data_label,$labels,$table_field,$fields_record,'country','country');
					$bar=bar_graph(3,$fields_record,$table_field);
					break;

			case 3:	$data_label[0]=_WEEK;
					$data_label[1]=SS_C1;
					$data_label[2]=SS_U3;
					$data_label[3]=SS_21.'@r';
					OrganizeData('W',$data_label,$labels,$table_field,$fields_record,'country','country');
					$bar=bar_graph(3,$fields_record,$table_field);
					break;

			case 4:	$data_label[0]=_DAY;
					$data_label[1]=SS_C1;
					$data_label[2]=SS_U3;
					$data_label[3]=SS_21.'@r';
					OrganizeData('',$data_label,$labels,$table_field,$fields_record,'country','country');
					$bar=bar_graph(3,$fields_record,$table_field);
					break;

			case 5:	$data_label[0]=_NA;
					$data_label[1]=SS_C1;
					$data_label[2]=SS_U3;
					$data_label[3]=SS_21.'@r';
					OrganizeData('*',$data_label,$labels,$table_field,$fields_record,'country','country');
					$bar=bar_graph(3,$fields_record,$table_field);
					break;
		}
		?><br />
		<fieldset class="sstat"><legend class="sstat" align="center">&nbsp;<?=SS_14?>&nbsp;</legend><?php ShowTable($labels,$table_field,$fields_record,'100%','','','H',$bar,'Y'); ?></fieldset>
		<div align="center"><h6><?=SS_19?></h6></div><?php
		return(true);
	}
	else
	{
		?><div align="center"><h3><?=SS_22?></h3></div><?php
		return(false);
	}
}
?>
Return current item: phpCAMALEO