<?php
if(!function_exists('showtable'))
{
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Display a table
#
# Last revision: 24 October 2006
#
function showtable( $labels, # table lables
$table_field, # table data
$fields_record, # number of fields per record
$table_size =600, # table horizontal size (default = 600)
$table_align ='center', # table alignment on the page ('left', 'center', 'right')
$extra_lead =false, # 'true' to show extra space between lines
$orientation ='A', # [A]utomatic (default), [V]ertical or [H]orizontal
$graph ='', # pass an array to show bar graph
$table_totals ='', # [Y]es totalize all numeric columns and show the totals in the last line
$start_reverse ='' # 'R' to start with a reversed line; 'NR' to avoid alternate reverse lines
)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{
# if($table_size==0) { $table_size=600; }
# if($table_align=='') { $table_align='center'; }
# if($orientation=='') { $orientation='A'; }
if($orientation=='A')
{
if($fields_record<5) { $orientation='H'; } else { $orientation='V'; }
}
$tot_labels=count($labels);
if($fields_record==0) { $fields_record=$tot_labels; }
$temp=$tot_labels/$fields_record; # Datasets
$colspan=$tot_labels/$temp; # nr. of columns
if(isset($graph)) { $colspan+=1; }
echo("\n".'<div align="'.$table_align.'">'."\n");
#============================
#
# Horizontal table
#
#============================
if($orientation=='H')
{
?><table class="datatable" width="<?=$table_size?>" border="0" cellspacing="0" cellpadding="0"><caption></caption><?php
#
# Labels
#
$i=0;
while($i<$fields_record)
{
$t_align=explode('@',$labels[$i]);
if($t_align[1]=='') { $temp='left'; } else { $temp='right'; $labels[$i]=$t_align[0]; }
$i_attr[$i]=$t_align[1];
?><th scope="col" align="<?=$temp?>"><?=$labels[$i]?></th><?php
if(isset($graph[$i]))
{
?><th scope="col" align="left"> %</th><?php
}
$i++;
}
?><tr><td colspan="<?=$colspan?>"><img src="<?=$_SESSION[misc][TBL_DELMT_IMG]?>" height="<?=$_SESSION[misc][TBL_DELMT_IMGSIZ]?>" width="100%" border="0" /></td></tr><?php
#
# Data
#
if($start_reverse=='R') { $tr_class='rev'; } else { $tr_class='norm'; }
$tot_field=count($table_field); $i=0; $i_fld=0;
?><tr class="<?=$tr_class?>"><?php
while($i<$tot_field)
{
if($i_fld==$fields_record) { ?><tr class="<?=$tr_class?>"><?php $i_fld=0; }
$temp='';
if($i_attr[$i_fld]=='t') # Its a time value
{
$temp='right';
$total_values[$i_fld]=$total_values[$i_fld]+$table_field[$i];
$table_field[$i]=time_format($table_field[$i]);
}
if($temp=='')
{
if(!is_numeric($table_field[$i])) { $temp='left'; } else { $temp='right'; $total_values[$i_fld]=$total_values[$i_fld]+$table_field[$i]; $table_field[$i]=number_format($table_field[$i],0,'.','.'); } # Its a number
}
?><td wrap valign="top" align="<?=$temp?>"><?=$table_field[$i]?> </td><?php
if(isset($graph[$i])) { ?><td nowrap align="left"> <?=$graph[$i]?> </td><?php }
$i++; $i_fld++;
if($i_fld==$fields_record)
{
?></tr><?php flush(); ob_flush();
if($start_reverse!='NR') { if($tr_class=='norm') { $tr_class='rev'; } else { $tr_class='norm'; } }
}
}
#
# Show totals
#
if($table_totals=='Y')
{
?></tr><?php
for($i=0;$i<$fields_record;$i++)
{
if($total_values[$i]>0)
{
?><td bgcolor="<?=$_SESSION[misc][1]?>" align="right"><?php
if($i_attr[$i]=='t') { echo time_format($total_values[$i]); } else { echo number_format($total_values[$i],0,'.','.'); }
?></td><?php
} else { ?><td></td><?php }
}
?></tr><?php
}
?><script type="text/javascript">var i,rows=document.getElementsByTagName('tr');
for(i=0;i<rows.length;i++)
{
rows[i].onmouseover=function() { this.className+='hi'; }
rows[i].onmouseout=function() { this.className=this.className.replace('hi',''); }
}
</script><?php flush(); ob_flush();
}
else
{
#============================
#
# Vertical table
#
#============================
?><table width="<?=$table_size?>" border="0" cellspacing="0" cellpadding="0">
<tr><td colspan="2"></tr>
<tr><td colspan="<?=$colspan?>"><img src="<?=$_SESSION[misc][TBL_DELMT_IMG]?>" height="<?=$_SESSION[misc][TBL_DELMT_IMGSIZ]?>" width="100%" border="0" /></td>
</tr>
<?php
$i=0; $i_fld=0;
while($i<$tot_labels)
{
?><tr><?php
$t_align=explode('@',$labels[$i]);
if($t_align[1]=='') { $temp='left'; } else { $temp='left'; $labels[$i]=$t_align[0]; }
$i_attr[$i]=$t_align[1];
#
# Labels & Data
#
?><td valign="top" align="<?=$temp?>"><?=$labels[$i]?></td>
<td align="<?=$temp?>"><?php
if(!is_numeric($table_field[$i])) { echo $table_field[$i]; }
else
{
if($i_attr[$i]=='t') { echo time_format($table_field[$i]); } else { echo number_format($table_field[$i],0,'.','.'); }
}
?></td>
</tr><?php flush(); ob_flush();
if($fields_record>1 && $i_fld>=$fields_record-1)
{
?><tr><?php
#
# Split input array in record data sets
#
?><td colspan="2"><hr id="line" style="height:1px;width:100%;" /></td><?php $i_fld=-1; ?>
</tr>
<?php flush(); ob_flush();
}
$i++; $i_fld++;
}
#============================
}
?><tr><td colspan="<?=$colspan?>"><img src="<?=$_SESSION[misc][TBL_DELMT_IMG]?>" height="<?=$_SESSION[misc][TBL_DELMT_IMGSIZ]?>" width="100%" border="0" /></td></tr>
</table></div><?php flush(); ob_flush();
}
}
?>