<?php
//////////////////////////////////////////////////////////
// initialization settings
ini_set('display_errors' , 'on' );
ini_set('error_reporting' , E_ALL & ~ (E_NOTICE | E_WARNING) );
ini_set('error_reporting' , E_ALL & ~E_NOTICE );
ini_set('max_execution_time' , 0 );
ini_set('memory_limit' , -1 );
//////////////////////////////////////////////////////////
// required files
require_once 'ReportGrouping.php';
//////////////////////////////////////////////////////////
// main script
$records = [];
$records[] = [
'FIRST' => 'Johnny' ,
'LAST' => 'Rocket' ,
'EMAIL' => 'jr@example.com' ,
'AGE' => 32 ,
'SALARY' => 45000
];
$records[] = [
'FIRST' => 'Connie' ,
'LAST' => 'Rocket' ,
'EMAIL' => 'cr@example.com' ,
'AGE' => 22 ,
'SALARY' => 55000
];
$records[] = [
'FIRST' => 'Lonnie' ,
'LAST' => 'Rocket' ,
'EMAIL' => 'jr@example.com' ,
'AGE' => 32 ,
'SALARY' => 65000
];
$records[] = [
'FIRST' => 'Bonnie' ,
'LAST' => 'Socket' ,
'EMAIL' => 'ba@example.com' ,
'AGE' => 12 ,
'SALARY' => 75000
];
$records[] = [
'FIRST' => 'Ronnie' ,
'LAST' => 'Locket' ,
'EMAIL' => 'rl@example.com' ,
'AGE' => 32 ,
'SALARY' => 85000
];
$alwaysBreak = true;
$columns = [
'FIRST' => '',
'LAST' => '',
'EMAIL' => '',
'AGE' => '',
'SALARY' => ''
];
$groups = [ 'LAST' , 'AGE' ];
$map = [ 'LAST NAME' , 'AGE' ];
$totals = [ 'AGE' , 'SALARY' ];
$report = new ReportGrouping($records, $columns, $groups, $map, $totals, $alwaysBreak);
$report->headerCallback = 'outputHeader';
$report->lineCallback = 'outputLine';
$report->subTotalField = 'LAST';
?>
<!doctype html>
<style type="text/css">
body
{
display : flex;
font : 11px courier new;
text-align : left;
unicode-bidi : embed;
white-space : pre;
}
</style>
<body>
<span style="flex:0 0 35%; font-size:9px;"> <?= print_r($report->records, true) ?>
</span>
<span style="flex:0 0 65%;">
<?php
echo '<table border=0 cellspacing=0 cellpadding=3>'; $report->printReport(); echo '</table>'; ?>
</span>
<?php
//////////////////////////////////////////////////////////
// supporting functionality
function outputHeader()
{
$html = <<<EOS
<thead>
<tr style="font:19px bold;">
<td valign=bottom>Last Name</td>
<td valign=bottom>First Name</td>
<td valign=bottom>Email</td>
<td align=right valign=bottom>Age</td>
<td align=right valign=bottom>Salary</td>
</tr>
</thead>
EOS;
echo $html;
}
function outputLine($record, $alternate = false, $bold = false) {
$bold = $bold ? 'bold' : 'normal';
$rowclass = $alternate ? 'altrowcolor' : 'rowcolor';
$html = "
<tr class=" . $rowclass . " style='font-weight:" . $bold . ";'>
<td>" . $record['LAST'] . "</td>
<td>" . $record['FIRST'] . "</td>
<td>" . $record['EMAIL'] . "</td>
<td align=right>" . $record['AGE'] . "</td>
<td align=right>" . number_format($record['SALARY']) . "</td>
</tr>";
echo $html;
}
|