Voici mon code :)
<?php
require('fpdf.php');
class PDF_MC_Table extends FPDF
{
var $widths;
var $aligns;
function SetWidths($w)
{
//Tableau des largeurs de colonnes
$this->widths=$w;
}
function SetAligns($a)
{
//Tableau des alignements de colonnes
$this->aligns=$a;
}
function Row($data)
{
//Calcule la hauteur de la ligne
$nb=0;
for($i=0;$i<count($data);$i++)
$nb=max($nb,$this->NbLines($this->widths[$i],$data[$i]));
$h=5*$nb;
//Effectue un saut de page si nécessaire
$this->CheckPageBreak($h);
//Dessine les cellules
for($i=0;$i<count($data);$i++)
{
$w=$this->widths[$i];
$a=isset($this->aligns[$i]) ? $this->aligns[$i] : 'L';
//Sauve la position courante
$x=$this->GetX();
$y=$this->GetY();
//Dessine le cadre
$this->Rect($x,$y,$w,$h);
//Imprime le texte
$this->MultiCell($w,5,$data[$i],0,$a);
//Repositionne à droite
$this->SetXY($x+$w,$y);
}
//Va à la ligne
$this->Ln($h);
}
function CheckPageBreak($h)
{
//Si la hauteur h provoque un débordement, saut de page manuel
if($this->GetY()+$h>$this->PageBreakTrigger)
$this->AddPage($this->CurOrientation);
}
function NbLines($w,$txt)
{
//Calcule le nombre de lignes qu'occupe un MultiCell de largeur w
$cw=&$this->CurrentFont['cw'];
if($w==0)
$w=$this->w-$this->rMargin-$this->x;
$wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
$s=str_replace("\r",'',$txt);
$nb=strlen($s);
if($nb>0 and $s[$nb-1]=="\n")
$nb--;
$sep=-1;
$i=0;
$j=0;
$l=0;
$nl=1;
while($i<$nb)
{
$c=$s[$i];
if($c=="\n")
{
$i++;
$sep=-1;
$j=$i;
$l=0;
$nl++;
continue;
}
if($c==' ')
$sep=$i;
$l+=$cw[$c];
if($l>$wmax)
{
if($sep==-1)
{
if($i==$j)
$i++;
}
else
$i=$sep+1;
$sep=-1;
$j=$i;
$l=0;
$nl++;
}
else
$i++;
}
return $nl;
}
}
//connection à ma base de données
$bdd = new PDO('mysql:host=localhost;dbname=recup', 'root', '');
//sélectionne tous les steward pour remplir la liste déroulante
if(isset($_POST['steward']) and isset($_POST['semainedebut']) and isset($_POST['semainefin']) and isset($_POST['enregistrer']))
{
//si tous les steward coché
if($_POST['steward'] == "tous")
{
//$x_travail = array();
$steward = $bdd->query('select * from steward where visible = "oui" order by prenom ASC') ;
$steward->execute() ;
$nbr_prenom = 0 ;
$nbr_semaine = ($_POST['semainefin'] - $_POST['semainedebut'])+1 ;
while ($donneessteward = $steward->fetch())
{
$st = $donneessteward['table'] ;
$requete = $bdd->prepare('select * from '.$st.' where semaine between :semainedebut and :semainefin and annee = :annee order by semaine ') ;
$requete->execute(array(
':semainedebut'=>$_POST['semainedebut'],
':semainefin'=>$_POST['semainefin'],
':annee'=>$_POST['annee']
));
$ouiounon = $requete->rowCount() ;
if($ouiounon > 0)
{
$nbr_prenom++;
$prenom[] = $donneessteward['prenom'] ;
$comp = $bdd->prepare('select * from compteur where id_steward = :id');
$comp->execute(array(':id'=>$donneessteward['id']));
$recucompteur = $comp->fetch();
$compteur[] = $recucompteur['recuperation'] ;
}
while($horaire = $requete->fetch())
{
//je split sur les ; pour récupérer toutes mes valeurs, la valeur [3] est "autre" je split sur le = pour avoir par exemple "maladie=heure" donc en [0] maladie et en [1] heure
$lundi = explode(";", $horaire['lundi']);
$autrelundi = explode("=", $lundi[3]) ;
$mardi = explode(";", $horaire['mardi']);
$autremardi = explode("=", $mardi[3]) ;
$mercredi = explode(";", $horaire['mercredi']);
$autremercredi = explode("=", $mercredi[3]) ;
$jeudi = explode(";", $horaire['jeudi']);
$autrejeudi = explode("=", $jeudi[3]) ;
$vendredi = explode(";", $horaire['vendredi']);
$autrevendredi = explode("=", $vendredi[3]) ;
$samedi = explode(";", $horaire['samedi']);
$autresamedi = explode("=", $samedi[3]) ;
$dimanche = explode(";", $horaire['dimanche']);
$autredimanche = explode("=", $dimanche[3]) ;
//si = "" on a pas de commentaire
if($lundi[4] == "")
{
$commentairelundi = " " ;
}
else
{
$commentairelundi = $lundi[4] ;
}
if($lundi[0] == "")
{
$lundis = " " ;
}
else
{
$lundis = $lundi[0] ;
}
if($autrelundi[1] == "")
{
$autreslundi = " " ;
}
else
{
$autreslundi = $autrelundi[1] ;
}
if($mardi[0] == "")
{
$mardis = " " ;
}
else
{
$mardis = $mardi[0] ;
}
if($autremardi[1] == "")
{
$autresmardi = " " ;
}
else
{
$autresmardi = $autremardi[1] ;
}
if($mercredi[0] == "")
{
$mercredis = " " ;
}
else
{
$mercredis = $mercredi[0] ;
}
if($autremercredi[1] == "")
{
$autresmercredi = " " ;
}
else
{
$autresmercredi = $autremercredi[1] ;
}
if($jeudi[0] == "")
{
$jeudis = " " ;
}
else
{
$jeudis = $jeudi[0] ;
}
if($autrejeudi[1] == "")
{
$autresjeudi = " " ;
}
else
{
$autresjeudi = $autrejeudi[1] ;
}
if($vendredi[0] == "")
{
$vendredis = " " ;
}
else
{
$vendredis = $vendredi[0] ;
}
if($autrevendredi[1] == "")
{
$autresvendredi = " " ;
}
else
{
$autresvendredi = $autrevendredi[1] ;
}
if($samedi[0] == "")
{
$samedis = " " ;
}
else
{
$samedis = $samedi[0] ;
}
if($autresamedi[1] == "")
{
$autressamedi = " " ;
}
else
{
$autressamedi = $autresamedi[1] ;
}
if($dimanche[0] == "")
{
$dimanches = " " ;
}
else
{
$dimanches = $dimanche[0] ;
}
if($autredimanche[1] == "")
{
$autresdimanche = " " ;
}
else
{
$autresdimanche = $autredimanche[1] ;
}
if($mardi[4] == "")
{
$commentairemardi = " " ;
}
else
{
$commentairemardi = $mardi[4] ;
}
if($mercredi[4] == "")
{
$commentairemercredi = " " ;
}
else
{
$commentairemercredi = $mercredi[4] ;
}
if($jeudi[4] == "")
{
$commentairejeudi = " " ;
}
else
{
$commentairejeudi = $jeudi[4] ;
}
if($vendredi[4] == "")
{
$commentairevendredi = " " ;
}
else
{
$commentairevendredi = $vendredi[4] ;
}
if($samedi[4] == "")
{
$commentairesamedi = " " ;
}
else
{
$commentairesamedi = $samedi[4] ;
}
if($dimanche[4] == "")
{
$commentairedimanche = " " ;
}
else
{
$commentairedimanche = $dimanche[4] ;
}
//pause
if($lundi[1] == "1")
{
$p1lundi = "oui";
}
else
{
$p1lundi = "non";
}
if($lundi[2] == "1")
{
$p2lundi = "oui";
}
else
{
$p2lundi = "non";
}
if($mardi[1] == "1")
{
$p1mardi = "oui";
}
else
{
$p1mardi = "non";
}
if($mardi[2] == "1")
{
$p2mardi = "oui";
}
else
{
$p2mardi = "non";
}
if($mercredi[1] == "1")
{
$p1mercredi = "oui";
}
else
{
$p1mercredi = "non";
}
if($mercredi[2] == "1")
{
$p2mercredi = "oui";
}
else
{
$p2mercredi = "non";
}
if($jeudi[1] == "1")
{
$p1jeudi = "oui";
}
else
{
$p1jeudi = "non";
}
if($jeudi[2] == "1")
{
$p2jeudi = "oui";
}
else
{
$p2jeudi = "non";
}
if($vendredi[1] == "1")
{
$p1vendredi = "oui";
}
else
{
$p1vendredi = "non";
}
if($vendredi[2] == "1")
{
$p2vendredi = "oui";
}
else
{
$p2vendredi = "non";
}
if($samedi[1] == "1")
{
$p1samedi = "oui";
}
else
{
$p1samedi = "non";
}
if($samedi[2] == "1")
{
$p2samedi = "oui";
}
else
{
$p2samedi = "non";
}
if($dimanche[1] == "1")
{
$p1dimanche = "oui";
}
else
{
$p1dimanche = "non";
}
if($dimanche[2] == "1")
{
$p2dimanche = "oui";
}
else
{
$p2dimanche = "non";
}
$heures = $horaire['recup'] % 60 ;
$heure = ($horaire['recup'] - $heures) / 60 ;
if($horaire['hp'] != "")
{
$hptab = explode(";",$horaire['hp']) ;
$hplmin = $hptab[0] % 60 ;
$hplh = ($hptab[0] - $hplmin) / 60 ;
if($hplmin < 10)
{
$hplmin = "0".$hplmin ;
}
else
{
$hplmin = $hplmin ;
}
$hpmamin = $hptab[1] % 60 ;
$hpmah = ($hptab[1] - $hpmamin) / 60 ;
if($hpmamin < 10)
{
$hpmamin = "0".$hpmamin ;
}
else
{
$hpmamin = $hpmamin ;
}
$hpmmin = $hptab[2] % 60 ;
$hpmh = ($hptab[2] - $hpmmin) / 60 ;
if($hpmmin < 10)
{
$hpmmin = "0".$hpmmin ;
}
else
{
$hpmmin = $hpmmin ;
}
$hpjmin = $hptab[3] % 60 ;
$hpjh = ($hptab[3] - $hpjmin) / 60 ;
if($hpjmin < 10)
{
$hpjmin = "0".$hpjmin ;
}
else
{
$hpjmin = $hpjmin ;
}
$hpvmin = $hptab[4] % 60 ;
$hpvh = ($hptab[4] - $hpvmin) / 60 ;
if($hpvmin < 10)
{
$hpvmin = "0".$hpvmin ;
}
else
{
$hpvmin = $hpvmin ;
}
$hpsmin = $hptab[5] % 60 ;
$hpsh = ($hptab[5] - $hpsmin) / 60 ;
if($hpsmin < 10)
{
$hpsmin = "0".$hpsmin ;
}
else
{
$hpsmin = $hpsmin ;
}
$hpdmin = $hptab[6] % 60 ;
$hpdh = ($hptab[6] - $hpdmin) / 60 ;
if($hpdmin < 10)
{
$hpdmin = "0".$hpdmin ;
}
else
{
$hpdmin = $hpdmin ;
}
}
else
{
$hplh = "0" ;
$hplmin = "00" ;
$hpmah = "0" ;
$hpmamin = "00" ;
$hpmh = "0" ;
$hpmmin = "00" ;
$hpjh = "0" ;
$hpjmin = "00" ;
$hpvh = "0" ;
$hpvmin = "00" ;
$hpsh = "0" ;
$hpsmin = "00" ;
$hpdh = "0" ;
$hpdmin = "00" ;
}
$day = 1;
while ($horaire['semaine'] != date("W", mktime(1 , 1, 1, 1 , $day, $horaire['annee'])) && $day < 366)
{
$day = $day + 7;
}
if ($day >= 366)
{
die('Erreur, week non trouvé');
}
// à partir d'ici tu connais au moins un jour de la semaine : date('ce que tu veux comme données', mktime(1 , 1, 1, 1 , $day, $_GET['Year']))
// pour avoir lundi, on prend le numero de la semaine de la date que nous avons trouvé et on la soustrait à ce que nous avons +1 sinon nous
// avons trouvé le dimanche de la semaine précédente
$day = $day - date('N', mktime(1 , 1, 1, 1 , $day, $horaire['annee'])) +1;
// à partir d'ici, pour avoir la date du lundi :
//pour avoir mardi, tu fais $day + 1
$semaine[] = "Semaine du ".date('d/m/Y', mktime(1 , 1, 1, 1 , $day, $horaire['annee']))." au ".date('d/m/Y', mktime(1 , 1, 1, 1 , $day+6, $horaire['annee']))."" ;
$travail_semaine = array($lundis,$mardis,$mercredis,$jeudis,$vendredis,$samedis,$dimanches) ;
$travail[] = $travail_semaine ;
$pause1_semaine = array($p1lundi,$p1mardi,$p1mercredi,$p1jeudi,$p1vendredi,$p1samedi,$p1dimanche) ;
$pause2_semaine = array($p2lundi,$p2mardi,$p2mercredi,$p2jeudi,$p2vendredi,$p2samedi,$p2dimanche) ;
$pause1[] = $pause1_semaine ;
$pause2[] = $pause2_semaine ;
$type_semaine = array($autrelundi[0],$autremardi[0],$autremercredi[0],$autrejeudi[0],$autrevendredi[0],$autresamedi[0],$autredimanche[0]) ;
$type[] = $type_semaine;
$heuretype_semaine = array($autreslundi,$autresmardi,$autresmercredi,$autresjeudi,$autresvendredi,$autressamedi,$autresdimanche) ;
$heuretype[] = $heuretype_semaine;
$commentaire_semaine = array($commentairelundi,$commentairemardi,$commentairemercredi,$commentairejeudi,$commentairevendredi,$commentairesamedi,$commentairedimanche) ;
$commentaire[] = $commentaire_semaine;
$heureprestee_semaine = array($hplh."h".$hplmin,$hpmah."h".$hpmamin,$hpmh."h".$hpmmin,$hpjh."h".$hpjmin,$hpvh."h".$hpvmin,$hpsh."h".$hpsmin,$hpdh."h".$hpdmin);
$heureprestee[] = $heureprestee_semaine ;
$heuresemaine[] = $heure." heure(s) et ".$heures." minute(s)" ;
}
//$x_travail = $travail[] ;
}
}
}
$jour = array("Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi","Dimanche");
$pdf=new PDF_MC_Table();
$pdf->AddPage();
for($x=0;$x<$nbr_prenom;$x++)
{
$pdf->SetFont('Arial','B',10);
$pdf->Cell(10,10,'Prénom : '.$prenom[$x].' Compteur : '.$compteur[$x].'');
$pdf->Ln(10);
for($y=0;$y<$nbr_semaine;$y++)
{
$pdf->SetFont('Arial','B',8);
$pdf->Cell(10,10,''.$semaine[$y].'');
$pdf->Ln(10);
//Table de 20 lignes et 4 colonnes
$pdf->SetWidths(array(20,30,15,15,22,25,30,25));
//srand(microtime()*1000000);
//for($i=0;$i<20;$i++)
//voir pour la couleur d'entete
$pdf->Row(array("Jour","Travail","Pause 1","Pause 2",
"Type","Heure type","Commentaire","Heures prestées"));
$pdf->SetFont('Arial','',8);
for($i = 0; $i < 8 ;$i++)
{
if($i < 7)
{
/* if($x_travail[$x][$y][$i] == " ")
{
$x_travail[$x][$y][$i] = " ";
}
else
{
$x_travail[$x][$y][$i] = $travail[$x][$y][$i] ;
} */
if($type[$y][$i] == "rien")
{
$type[$y][$i] = "Travail";
}
else
{
$type[$y][$i] = $type[$y][$i] ;
}
if($heuretype[$y][$i] == " ")
{
$heuretype[$y][$i] = " ";
}
else
{
$heuretype[$y][$i] = $heuretype[$y][$i] ;
}
if($commentaire[$y][$i] == " ")
{
$commentaire[$y][$i] = " ";
}
else
{
$commentaire[$y][$i] = $commentaire[$y][$i] ;
}
$pdf->Row(array($jour[$i],$travail[$y][$i],$pause1[$y][$i],$pause2[$y][$i],$type[$y][$i],$heuretype[$y][$i],$commentaire[$y][$i],$heureprestee[$y][$i]));
}
else
{
$pdf->SetFont('Arial','B',8);
$pdf->SetWidths(array(102,80));
$pdf->Row(array("Heures de récupération pour cette semaine",$heuresemaine[$y]));
}
}
}
$pdf->AddPage();
}
$pdf->Output();?>