Location: PHPKode > projects > phpCAMALEO > common/fun2inc/organizedata.inc
<?php
if(!function_exists('organizedata'))
{
	#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	#	Organize data
	#
	function organizedata($is_week, 
						  $data_label, 
						  &$labels, 
						  &$table_field, 
						  $fields_record, 
						  $decode='', 
						  $order='')
	#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	{
		global $country_server,$country_serverf;
		$tot_records=count($table_field);
		$nr_of_dataset=$tot_records/$fields_record;
		$i=0;
		while($i<$tot_records)
		{
			$ii=0;
			while($ii<$fields_record)
			{
				$labels[$i+$ii]=$data_label[$ii];
				$data=$table_field[$i+$ii];
				switch($ii)
				{
					case 0:
						#	Format period data string
						#
						if($is_week=='W')	{ $data=substr($data,0,4).'-'.substr($data,4,2); $table_field[$i+$ii]=$data; }
						if($is_week=='*')	{ $data='&nbsp;'; $table_field[$i+$ii]=$data; }
						#
						#	Year
						if(strlen($data)==4) { $table_field[$i+$ii]=$data.'&nbsp;'; } # add a space to avoid numeric formatting
						#
						#	Month, week
						if(strlen($data)==7) { $table_field[$i+$ii]=substr($data,5,2).'-'.substr($data,0,4); }
						#
	 					#	Day
	 					if(strlen($data)==10) { $table_field[$i+$ii]=substr($data,8,2).'-'.substr($data,5,2).'-'.substr($data,0,4); }
						break;
	
					case 1:
						if($decode=='country') 
						{
							#	Replace country code with flag
							if($data=='') { $data='_na_'; }
							$table_field[$i+$ii]='<img src="http://'.$country_server.$country_serverf.'/img/'.strtolower($data).'.png" width="25" height="15" alt="'.$data.'.png" title="http://'.$country_server.'" />';
							$ccode2=$data;
						}
						if($order=='page')
						{
							if($_SESSION[sort]!=SS_P1)	{ $link='<a href="'.$_SERVER[PHP_SELF].'?sort='.SS_P1.'">'.$data_label[$ii].'</a>'; }
							else						{ $link=SS_P1.'&nbsp;<img src="../../img/stat/s_asc.png" alt="'.SS_ASC.'" title="'.SS_ASC.'" />'; }
							$labels[$i+$ii]=$link;
						}
						$table_field[$i+$ii].='&nbsp;';
						if($is_week=='*') { $data='&nbsp;'; };
						break;
	
					case 2:
						$table_field[$i+$ii]=$data;
						if($order=='country')
						{
							if($_SESSION[sort]!=SS_U3)	{ $link='<a href="'.$_SERVER[PHP_SELF].'?sort='.SS_U3.'">'.$data_label[$ii].'</a>'; }
							else 						{ $link=SS_U3.'&nbsp;<img src="../../img/stat/s_asc.png" alt="'.SS_ASC.'" title="'.SS_ASC.'" />'; }
							$labels[$i+$ii]=$link;
						}
						if($order=='page')
						{
							if($_SESSION[sort]!=SS_P2)	{ $link='<a href="'.$_SERVER[PHP_SELF].'?sort='.SS_P2.'">'.$data_label[$ii].'</a>'; }
							else						{ $link=SS_P2.'&nbsp;<img src="../../img/stat/s_desc.png" alt="'.SS_DESC.'" title="'.SS_DESC.'" />@r'; }							
							$labels[$i+$ii]=$link;
						}
						break;
	
					case 3:
						$table_field[$i+$ii]=$data;
						if($order=='country')
						{
							if($_SESSION[sort]!=SS_23)	{ $link='<a href="'.$_SERVER[PHP_SELF].'?sort='.SS_23.'">'.$data_label[$ii].'</a>'; }
							else						{ $link=SS_23.'&nbsp;<img src="../../img/stat/s_desc.png" alt="'.SS_DESC.'" title="'.SS_DESC.'" />@r'; }
							$labels[$i+$ii]=$link;
						}
						if($order=='page')
						{
							if($_SESSION[sort]!=SS_P3)	{ $link='<a href="'.$_SERVER[PHP_SELF].'?sort='.SS_P3.'">'.$data_label[$ii].'</a>'; }
							else						{ $link=SS_P3.'&nbsp;<img src="../../img/stat/s_desc.png" alt="'.SS_DESC.'" title="'.SS_DESC.'" />@r'; }
							$labels[$i+$ii]=$link;
						}
						break;
	
					case 4:
						if($order=='page')
						{
							if($_SESSION[sort]!=SS_23)	{ $link='<a href="'.$_SERVER[PHP_SELF].'?sort='.SS_23.'">'.$data_label[$ii].'</a>'; }
							else						{ $link=SS_23.'&nbsp;<img src="../../img/stat/s_desc.png" alt="'.SS_DESC.'" title="'.SS_DESC.'" />@r'; }							
							$labels[$i+$ii]=$link;
						}
						break;
					default:
				}
				$ii++;
			}
			$i=$i+$fields_record;
		}
	}
}
?>
Return current item: phpCAMALEO