<?php

/*
 * echo del cmomponente
 */

//echo $ser_comp;
// deserializa el resultado
//$child = unserialize($ser_comp);
//
//// lo mete en un container
//$container = new Container();
//
////$container->addChild($label);
//$container->addChild($ser_comp);
//Ob
//ob_start("ob_gzhandler");
// el container lo devuelve como el component a renderizar a algún formato
// echo $ser_comp;



/* * ********************************************************************* */

function validarFieldView($field_view, $key_column) {

    foreach ($field_view as $value) {
        if ($value == $key_column) {
            return true;
        }
    }
    return false;
}

$labelhead = new Label();
$labelhead->setText($titule);
$labelhead->setType('h2');

$table = new Table();
//$table->addAttribute('BORDERCOLOR', 'RED');
$table->addAttribute('BORDER', '3');
$table->addAttribute('width', '"800"');

//start header table
$row2 = new RowHead();
$row2->addAttribute('bgcolor', '"#A4A4A4"');
foreach ($names_columns as $value_row) {

    $label = new Text();
    $label->setText($value_row);
    $row2->addChild(new ColumnHead($label));
}
$table->addChild($row2);
//end header table

setlocale(LC_MONETARY, 'it_IT');

foreach ($list_data as $key_row => $value_row) {

    $rowX = new Row();

    foreach ($value_row as $key_column => $value_column) {

        if (validarFieldView($field_view, $key_column)) {
            $rowX->addChild(new Column($value_column));
        }
    }

    $table->addChild($rowX);
}

$row3 = new RowHead();
$labeltot = new Text();
$labeltot->setText('Total');
$column = new ColumnHead($labeltot);
//$column = new ColumnHead($tablebody);
$column->addAttribute('COLSPAN', count($names_columns));
$row3->addChild($column);
$table->addChild($row3);
/* * ********************************************************************* */

$container = new Container();

$container->addChild($labelhead);
$container->addChild($table);

// Ob
//ob_start("ob_gzhandler");

$html = $container->renderAs(2);
echo $html;
?>