<?php
/**
 * @version    CVS: 3.0.8
 * @package    com_Pantry
 * @author     David George <david@bluelinetechnology.com.au>
 * @copyright  2017 Blueline Technology
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */
// No direct access
defined('_JEXEC') or die;
?>
<table class="table table-stripped">
    <thead><tr><th colspan="2"></th><th colspan="17">Total</th><th colspan="18">Abnormal</th></tr></tr></thead>
    <thead><tr><th colspan="2"></th><th colspan="8">Visit 1</th><th colspan="8">Visit 2</th><th colspan="5">Change</th><th colspan="8">Visit 1</th><th colspan="8">Visit 2</th><th colspan="5">Change</th></tr></thead>
    <thead>
        <tr>
            <th>Measurement</th>
            <th>Filter</th>
            <th>Mean</th><th>SD</th><th>MIN</th><th>MAX</th><th>n</th><th>% v1 total</th><th>n row</th><th>% row </th>
            
            <th>Mean</th><th>SD</th><th>MIN</th><th>MAX</th><th>n</th><th>% v2 total</th><th>n row</th><th>% row </th>
            <th>Mean</th><th>SD</th><th>MIN</th><th>MAX</th><th>n</th>
            <th>Mean</th><th>SD</th><th>MIN</th><th>MAX</th><th>n</th><th>% v1 total</th><th>n row</th><th>% row </th>
            <th>Mean</th><th>SD</th><th>MIN</th><th>MAX</th><th>n</th><th>% v2 total</th><th>n row</th><th>% row </th>
            <th>Mean</th><th>SD</th><th>MIN</th><th>MAX</th><th>n</th><th>Abnormal Condition</th>
    </tr></thead>
    <tbody>
        <?php foreach($displayData as $label => $filters) : ?>
            <?php foreach($filters as $filter => $normals) : ?>
                <tr>
                    <td><?php echo $label; ?> </td>
                    <td><?php echo $filter; ?> </td>
                <?php foreach($normals as $key => $normal) : ?>
                    <?php /** foreach($normal as $item) : ?>
                        <td><?php 
                        if(is_numeric($item->value)) {
                            echo round($item->value, 2);
                        }
                         ?></td>
                        <td><?php echo round($item->sd, 2); ?></td>
                        <td><?php echo round($item->min, 2); ?></td>
                        <td><?php echo round($item->max, 2); ?></td>
                        <td><?php echo $item->n; ?></td>
                        <td><?php echo $item->percent; ?></td>
                        <td><?php echo $item->n_row; ?></td>
                        <td><?php echo $item->percent_row; ?></td>
                    <?php endforeach; */ ?> 
                    
                    <?php if(isset($normal['v1'])) : ?> 
                        <td><?php echo round($normal['v1']->value, 2); ?></td>
                        <td><?php echo round($normal['v1']->sd, 2); ?></td>
                        <td><?php echo round($normal['v1']->min, 2); ?></td>
                        <td><?php echo round($normal['v1']->max, 2); ?></td>
                        <td><?php echo $normal['v1']->n; ?></td>
                        <td><?php echo $normal['v1']->percent; ?></td>
                        <td><?php echo $normal['v1']->n_row; ?></td>
                        <td><?php echo $normal['v1']->percent_row; ?></td>
                    <?php else : ?> 
                        <td colspan="8"></td>
                    <?php endif; ?> 
                    
                    <?php if(isset($normal['v2'])) : ?> 
                        <td><?php echo round($normal['v2']->value, 2); ?></td>
                        <td><?php echo round($normal['v2']->sd, 2); ?></td>
                        <td><?php echo round($normal['v2']->min, 2); ?></td>
                        <td><?php echo round($normal['v2']->max, 2); ?></td>
                        <td><?php echo $normal['v2']->n; ?></td>
                        <td><?php echo $normal['v2']->percent; ?></td>
                        <td><?php echo $normal['v2']->n_row; ?></td>
                        <td><?php echo $normal['v2']->percent_row; ?></td>
                    <?php else : ?> 
                        <td colspan="8"></td>
                    <?php endif; ?> 
                    
                    
                    
                    <td><?php 
                        if(isset($normal['v1']) && isset($normal['v2']) && is_numeric($normal['v2']->value)) {
                            echo round($normal['v2']->value - $normal['v1']->value, 2); 
                        }
                        ?></td>
                        <td><?php 
                        if(isset($normal['v1']) && isset($normal['v2']) && is_numeric($normal['v2']->sd)) {
                        echo round($normal['v2']->sd - $normal['v1']->sd, 2); 
                        }
                        ?></td>
                        <td><?php 
                        if(isset($normal['v1']) && isset($normal['v2']) && is_numeric($normal['v2']->min)) {
                        echo round($normal['v2']->min - $normal['v1']->min, 2); 
                        }
                        ?></td>
                        <td><?php 
                        if(isset($normal['v1']) && isset($normal['v2']) && is_numeric($normal['v2']->max)) {
                        echo round($normal['v2']->max - $normal['v1']->max, 2); 
                        }
                        ?></td>
                        <td><?php 
                        if(isset($normal['v1']) && isset($normal['v2']) && is_numeric($normal['v2']->n)) {
                        echo $normal['v2']->n - $normal['v1']->n; 
                        }
                        ?></td>
                    <?php endforeach; ?>
                    
                    <td><?php 
                    if(isset($normal['v1'])) {
                        echo $normal['v1']->abnormal;
                    } elseif (isset($normal['v2'])) {
                        echo $normal['v2']->abnormal;
                    }
                     ?><?php /**echo $item->abnormal; */ ?></td>
                </tr>
            <?php endforeach; ?> 
        <?php endforeach; ?> 
    </tbody>
    
<?php 
/**
foreach($displayData as $rows) : ?>
<?php foreach($rows as $items) : ?>
<?php foreach($items as $key => $item) : ?>
    <tr>    
        <td><?php echo $key; ?></td>
        
            <?php foreach ($item as $key => $normal) : ?> 
                <?php foreach ($normal as $nkey => $visit) : ?> 
                    
                    <td><?php 
                    if(is_numeric($visit->value)) {
                        echo round($visit->value, 2);
                    }
                     ?></td>
                    <td><?php echo round($visit->sd, 2); ?></td>
                    <td><?php echo round($visit->min, 2); ?></td>
                    <td><?php echo round($visit->max, 2); ?></td>
                    <td><?php echo $visit->n; ?></td>
                    <td><?php echo $visit->percent; ?></td>
                
            <?php endforeach; ?>
                <td><?php 
                if(is_numeric($normal['v2']->value)) {
                    echo round($normal['v2']->value - $normal['v1']->value, 2); 
                }
                ?></td>
                <td><?php 
                if(is_numeric($normal['v2']->sd)) {
                echo round($normal['v2']->sd - $normal['v1']->sd, 2); 
                }
                ?></td>
                <td><?php 
                if(is_numeric($normal['v2']->min)) {
                echo round($normal['v2']->min - $normal['v1']->min, 2); 
                }
                ?></td>
                <td><?php 
                if(is_numeric($normal['v2']->max)) {
                echo round($normal['v2']->max - $normal['v1']->max, 2); 
                }
                ?></td>
                <td><?php 
                if(is_numeric($normal['v2']->n)) {
                echo $normal['v2']->n - $normal['v1']->n; 
                }
                ?></td>
        <?php endforeach; ?>
        <td><?php echo $visit->abnormal; ?></td>
    </tr>    
<?php endforeach; ?>
<?php endforeach; ?>
<?php endforeach; 
*/
?>
</table>

<pre>
<?php 
//print_r($displayData); 
?>
</pre>