<?php
require_once 'table_colgroup.php';
function isIncludeable($file)
{
if (!defined('PATH_SEPARATOR')) {
define('PATH_SEPARATOR', strtoupper(substr(PHP_OS, 0, 3) == 'WIN') ? ';' : ':');
}
foreach (explode(PATH_SEPARATOR, ini_get('include_path')) as $path) {
if (file_exists($path . DIRECTORY_SEPARATOR . $file) &&
is_readable($path . DIRECTORY_SEPARATOR . $file)) {
return true;
}
}
return false;
}
function varDump($var)
{
$available = isIncludeable('Var_Dump.php');
if ($available) {
include_once 'Var_Dump.php';
Var_Dump::display($var, false, array('display_mode' => 'HTML4_Table'));
} else {
$styles = array('');
echo '<pre style="background-color:#eee; color:#000; padding:1em;">';
var_dump($var);
echo '</pre>';
}
}
$datasrc = array(array('1','2','3','4','5'),array('6','7','8','9','10'));
$columns = array('col1', 'col2', 'col3', 'col4', 'col5');
$table = new HTML_Table_ColGroup(array('class' => 'listwSelection'));
$thead = &$table->getHeader();
$tbody = &$table->getBody();
$tfoot = &$table->getFooter();
$table->setCaption('Table 1. test for colgroup specs', array('style' => 'caption-side: bottom;'));
// add header cells
$thead->addRow($columns);
// add body contents
foreach ($datasrc as $id => $data) {
$tbody->addRow($data);
}
$altRow1 = array('class' => 'odd');
$altRow2 = array('class' => 'even');
// incompatible with "colgroup"
#$table->altRowAttributes(0, $altRow1, $altRow2, true);
$test = trim($_GET['test']);
switch($test) {
case '1':
/*
<colgroup span="3" class="groupe1"></colgroup>
*/
$colgroup = '';
$attributes = 'span=3 class=groupe1';
$table->setColGroup($colgroup, $attributes);
break;
case '2':
/*
<colgroup span="3" class="groupe1">
<col style="font-size:120%;">
<col class="colonne2">
<col align="right">
</colgroup>
*/
$colgroup = array('style=font-size:120%;', 'class=colonne2', 'align=right');
$attributes = 'span=3 class=groupe1';
$table->setColGroup($colgroup, $attributes);
break;
case '3':
/*
<colgroup span="3" class="groupe1">
<col style="font-size:120%;">
<col class="colonne2">
<col align="right">
</colgroup>
<colgroup span="2" class="groupe2">
<col class="colonne4">
<col class="colonne5">
</colgroup>
*/
$colgroup = array('style=font-size:120%;', 'class=colonne2', 'align=right');
$attributes = 'span=3 class=groupe1';
$table->setColGroup($colgroup, $attributes);
$colgroup = array(array('class' => 'colonne4'), array('class' => 'colonne5'));
$attributes = 'span=2 class=groupe2';
$table->setColGroup($colgroup, $attributes);
break;
default:
/*
none colgroup specs
*/
$colgroup = null;
$attributes = null;
$table->setColGroup($colgroup, $attributes);
break;
}
varDump($table->_colgroup);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Sans Titre</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
body {
font-family : Verdana, Arial;
}
.groupe1 {
width: 1*;
text-align: center;
background: yellow;
}
.groupe2 {
width: 2*;
}
.colonne2 {
background: red;
}
.colonne4 {
text-align: right;
}
.colonne5 {
background: lightblue;
text-align: center;
}
.odd {
background-color: #E5E5E5;
}
.even {
background-color: #D5D5D5;
}
table.listwSelection {
width: 100%;
}
table.listwSelection thead, table.listwSelection tfoot {
background-color: silver;
}
table.listwSelection thead td {
font-weight: bold;
}
table.listwSelection tfoot td.total {
text-align: center;
}
table.listwSelection tbody {
overflow-y: auto;
overflow-x: hidden;
width: 35em;
height: 20em;
border: 1px dotted red;
}
table.listwSelection tbody tr {
height: auto; /* hack for IE */
vertical-align: top;
}
</style>
</head>
<body>
<?php
echo $table->toHtml();
?>
</body>
</html>