Voici un exemple de planning 100% php qui utilise GD2.
En esprérant que cela puisse te servir. Il te suffit de copier ce code dans notepad et de le sauvegarder au format php dans un folder de ton serveur. Ups! j'allais oublier tu dois activer GD2 dans ton serveur pour qu'il fonctionne.
Voici le code à copier/coller et eventuellement à adapter. Bien à toi
<?php
//Formations NTTC HCB RA
require_once('../Connections/s3.php');
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_s3, $s3);
$query_Recordset1 = "SELECT * FROM planning where Annee like '2009' ORDER BY annee ASC";
$Recordset1 = mysql_query($query_Recordset1, $s3) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
$an= $row_Recordset1['Annee'];
function evenement($pos,$mois,$j1,$j2,$color)
{//tracé d'un élément du planning
global $im,$margew,$margeh,$wcel,$hcel;
$nbj=$j2-$j1+1;
$x1=$margew+2*$wcel+($j1-1)*$wcel;
$y1=$margeh+$hcel+($mois-1)*$hcel+2+($pos-1)*7;
$x2=$x1+$nbj*$wcel;
$y2=$y1+5; //Epaisseur de la ligne évenement
Imagefilledrectangle($im,$x1,$y1,$x2,$y2,$color);
}
function fontcolor($li,$n,$color)
{//cellules en gris pour les jours non existants des mois
global $im,$margew,$margeh,$wcel,$hcel,$w;
$x1=$w-$margew-$n*$wcel;
$y1=$margeh+$li*$hcel;
$x2=$x1+$n*$wcel;
$y2=$y1+$hcel;
imagefilledrectangle($im,$x1,$y1,$x2,$y2,$color);
}
function fontcolor2($m,$j,$color)
{//cellules en jaune pour les WE (samedis et dimanches)
global $im,$margew,$margeh,$wcel,$hcel;
$x1=$margew+($j+1)*$wcel;
$y1=$margeh+$m*$hcel;
$x2=$x1+$wcel;
$y2=$y1+$hcel;
imagefilledrectangle($im,$x1,$y1,$x2,$y2,$color);
}
$wcel=30;//largeur d'une cellule du tableau (la 1ère est double)
$hcel=29;//hauteur d'une cellule du tableau
$margew=45;//marges gauche et droite du tableau
$margeh=35;//marges haut et bas
$margeb=120;//marges bas
//dimensions de l'image
$w=$wcel*33+$margew*2;
$h=$hcel*13+$margeh+$margeb;
//création de l'image
$im=ImageCreate($w,$h) or die ("Erreur lors de la création de l'image");
//ImageColorAllocate ($im, $_POST['rouge'], $_POST['vert'], $_POST['bleu']);
//couleurs utilisées
$blanc=ImageColorAllocate($im,255,255,255);
$rouge=ImageColorAllocate($im,255,0,0);
$gris1=ImageColorAllocate($im,80,80,80);
$gris2=ImageColorAllocate($im,233,233,233);
$noir=ImageColorAllocate($im,0,0,0);
$jaune=ImageColorAllocate($im,253,255,204);
$marron=ImageColorAllocate($im,225,115,45);
$bleu=ImageColorAllocate($im,130,30,255);
$vert=ImageColorAllocate($im,90,195,90);
$vertfonce=ImageColorAllocate($im,0,91,0);
$mauve=ImageColorAllocate($im,0,0,255);
//font gris pour les jours non existants des mois
//font jaune pour les WE
for($i=1;$i <= 12;$i++){
$nbj=date("t",mktime(0,0,0,$i,1,$an));//nbre de jours du mois $i
$jmoins=31-$nbj;
if($jmoins!=0) fontcolor($i,$jmoins,$gris2);
for($j=1;$j <= $nbj;$j++){
$nojs=strftime("%w",mktime(0,0,0,$i,$j,$an));//n° du jour de la semaine (dimanche 0)
if($nojs==0||$nojs==6) fontcolor2($i,$j,$jaune);
}
}
//tracé du tableau : cadre en noir
imagerectangle($im,$margew,$margeh,$w-$margew,$h-$margeb,$noir);
imagerectangle($im,$margew-1,$margeh-1,$w-$margew+1,$h-$margeb+1,$noir);
//tracé du tableau : lignes horizontales
for($x=1;$x < 2;$x++) {
imageline($im,$margew,$margeh+$x*$hcel,$w-$margew,$margeh+$x*$hcel,$noir);
imageline($im,$margew,$margeh+$x*$hcel+1,$w-$margew,$margeh+$x*$hcel+1,$noir);
}
for($x=2;$x < 13;$x++) {
$color=($x==1)?$rouge:$gris1;
imageline($im,$margew,$margeh+$x*$hcel,$w-$margew,$margeh+$x*$hcel,$color);
}
//tracé du tableau : 1ère ligne verticale
imageline($im,$margew+2*$wcel,$margeh,$margew+2*$wcel,$h-$margeb,$noir);
imageline($im,$margew+2*$wcel+1,$margeh,$margew+2*$wcel+1,$h-$margeb,$noir);
//tracé du tableau : autres lignes verticales
for($x=2;$x<32;$x++) imageline($im,$margew+($x+1)*$wcel,$margeh,$margew+($x+1)*$wcel,$h-$margeb,$gris1);
//police utilisée (vous devez remplacer ce chemin par celui du serveur)
$police="verdana.ttf";//adresse de la police en local (OS windows)
$policetitre="timesbi.ttf";//adresse de la police en local (OS windows)
//écriture n° des jours
for($i=1;$i < 10;$i++) Imagettftext($im,8,0,$margew+($i+1)*$wcel+13,$margeh+20,$noir,$police,$i);
for($i=10;$i < 32;$i++) Imagettftext($im,8,0,$margew+($i+1)*$wcel+9,$margeh+20,$noir,$police,$i);
//écriture des mois
$mois=array("","jan","fev","mar","avr","mai","jun","jul","aou","sep","oct","nov","dec");
for($i=1;$i < count($mois);$i++)
Imagettftext($im,9,0,$margew+9,$margeh+$i*$hcel+20,$noir,$police,ucfirst($mois[$i]));
//écriture de la légende des zones
$zonea="Selon l'unité organisatrice (pour plus d'info, voir Sv S3)";
$zoneb="Marche en Famenne - Moniteur : Lt Henin B";
$zonec="HCB RA - Moniteur : Lt Henin B";
$zoned="HCB RA - Moniteur : Lt Henin B";
Imagettftext($im,12,0,$margew,$h-100,$noir,$policetitre,"Légende : ");
Imagettftext($im,10,0,$margew,$h-80,$vertfonce,$police,"J-ICCS : ");
Imagettftext($im,8,0,$margew+3*$wcel+140,$h-80,$noir,$police,$zonea);
Imagettftext($im,10,0,$margew,$h-65,$mauve,$police,"NTTC TIR GP : ");
Imagettftext($im,8,0,$margew+3*$wcel+140,$h-65,$noir,$police,$zoneb);
Imagettftext($im,10,0,$margew,$h-50,$rouge,$police,"NTTC DRY GP de 1000 à 1200 Hr : ");
Imagettftext($im,8,0,$margew+3*$wcel+140,$h-50,$noir,$police,$zonec);
Imagettftext($im,10,0,$margew,$h-35,$rouge,$police,"NTTC DRY GP de 1300 à 1500 Hr : ");
Imagettftext($im,8,0,$margew+3*$wcel+140,$h-35,$noir,$police,$zoned);
//-------------------------------------------------------------------------------------------------------
//Formations organisées par l'HCB RA
$cpt = 0;
do {
if ($row_Recordset1['Couleur'] == 1)
{$color = $vert;}
else if($row_Recordset1['Couleur'] == 2)
{$color= $mauve;}
else
{$color= $rouge;}
evenement($row_Recordset1['Position'],$row_Recordset1['Mois'],$row_Recordset1['Debut'],$row_Recordset1['Fin'],$color);//position 2, juillet, du 13 au 14, couleur mauve
$cpt++; } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
//écriture du titre
$titre="Planning des formations Ops pour l'année ".$an;
Imagettftext($im,20,0,$margew,20,$noir,$policetitre,$titre);
//écriture de l'année
Imagettftext($im,18,0,$margew+5,$margeh+22,$rouge,$policetitre,$an);
header("content-type: image/png");
ImagePNG($im);
ImageDestroy($im);
?>