Un truc que j'ai fait y'a quelques années :
<?php
// planning configuration
define('__P_START_TIME', 8);
define('__P_END_TIME', 12);
define('__P_UNIT', 15);
$w = Array('Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi', 'Dimanche');
// init matrix
// ###########
// the matrix has its axis reversed: matrix[y][x] so it's easier to print it as an html table
// 1 means a cell exist (default value)
// 0 means the cell doesn't exist
// higher numbers are equal to rowspan values
$matrix = Array();
// matrix x axis
$x = sizeof($w);
// matrix y axis
$y = ((__P_END_TIME - __P_START_TIME) * 60) / __P_UNIT;
// populate matrix with default value (1)
for( $i = 0; $i <= $y; $i++ )
{
for( $j = 0; $j <= $x; $j++ )
{
$matrix[$i][$j] = Array('state' => 1, 'content' => ' '); // cell exist, default content
}
}
// populate titles
// ###############
// x axis
foreach( $w as $k => $v)
{
$matrix[0][$k+1]['content'] = $v;
}
// y axis
for( $i = 1; $i <= $y; $i++)
{
$t = ((($i-1)* __P_UNIT) + (__P_START_TIME * 60)) / 60;
if( !is_float($t) )
{
$matrix[$i][0]['content'] = $t.':00';
}
}
// take string or an integer and return it's value in minutes
// ie: time_to_min('8:45'), time_to_min(8)
function time_to_min($time)
{
if( preg_match('/:/', $time) )
{
$t = explode(':', $time);
$mn = $t[0]*60 + $t[1];
} else {
$mn = $time * 60;
}
return $mn;
}
// take a string, return day's x position
function day_to_x($day)
{
global $w;
$day = strtolower($day);
foreach( $w as $k => $v )
{
if( $day == strtolower($v) ) $x = $k+1;
}
return $x;
}
// take a string or integer, return time's y position
function time_to_y($time)
{
$mn = time_to_min($time);
$y = $mn - __P_START_TIME * 60;
$y = ($y / __P_UNIT) + 1;
return $y;
}
// set an event on the calendar
// set_event('Lundi', '8:30', 30);
function set_event($day, $time, $duration)
{
global $matrix;
$x = day_to_x($day);
$y = time_to_y($time);
$size = $duration / __P_UNIT;
$matrix[$y][$x]['state'] = $size;
if( $matrix[$y][$x]['content'] == 'Rendez-vous...' )
{
$matrix[$y][$x]['content'] = 'Rendez-vous multiple...';
} else {
$matrix[$y][$x]['content'] = 'Rendez-vous...';
}
if( $size > 1 )
{
for($i = 1; $i < $size; $i++)
{
$matrix[$y+$i][$x]['state'] = 0;
}
}
}
// set rendez-vous
set_event('Lundi', '8:30', 30);
set_event('Lundi', 9, 30);
set_event('Lundi', 9, 30);
set_event('Jeudi', '10:30', 45);
set_event('Mardi', '11:00', 30);
set_event('Lundi', '11:00', 15);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<head>
<title>Planning</title>
</head>
<body>
<table border="1" width="90%" align="center">
<?php foreach( $matrix as $y => $col ): ?>
<tr>
<?php foreach( $col as $x => $row ): ?>
<?php if( $row['state'] !== 0 ): ?>
<td<?php if( $row['state'] > 1 ){ echo ' rowspan="'.$row['state'].'"'; } ?>><?php echo $matrix[$y][$x]['content']; ?></td>
<?php endif; ?>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</table>
</body>
</html>