1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
//renvoye le nombre de ligne d'un MultiCell prend en parametres une largeur et un texte
function NbLines($w,$txt){
//Computes the number of lines a MultiCell of width w will take
$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=$j=$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;
}
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);
}
//Tableau coloré
function CotisationTable($header,$data){
//Couleurs, épaisseur du trait et police grasse
$this->SetFillColor(255,0,0);
$this->SetTextColor(255);
$this->SetDrawColor(128,0,0);
$this->SetLineWidth(.1);
$this->SetFont('','B');
//En-tête
$w = array(40,90,25,50,42,32);
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C',1);
$this->Ln();
//Restauration des couleurs et de la police
$this->SetFillColor(224,235,255);
$this->SetTextColor(0);
$this->SetFont('');
//Données
$fill=0;
$x_base = $this->GetX();
foreach($data as $row){
unset($nb_ligne);
$nb_ligne[] = $this->NbLines($w[0],$row[0]);
$nb_ligne[] .= $this->NbLines($w[1],$row[1]);
$nb_ligne[] .= $this->NbLines($w[2],$row[2]);
$nb_ligne[] .= $this->NbLines($w[3],$row[3]);
$nb_ligne[] .= $this->NbLines($w[4],$row[4]);
$nb_ligne[] .= $this->NbLines($w[5],$row[5]);
$nb_ligne_max = max($nb_ligne);
$hauteur = 6 * $nb_ligne_max;
//Effectue un saut de page si nécessaire
$this->CheckPageBreak($hauteur);
$x = $this->GetX();
$y = $this->GetY();
$nb_bckn = $nb_ligne_max - $nb_ligne[0];
$bckn ='';
for($i=0;$i <= $nb_bckn;$i++)
$bckn .= "\n";
$this->MultiCell($w[0],6,$row[0].$bckn,'LR','C',$fill);
$this->SetXY(($x+$w[0]),($y));
$x = $this->GetX();
$y = $this->GetY();
$nb_bckn = $nb_ligne_max - $nb_ligne[1];
$bckn ='';
for($i=0;$i <= $nb_bckn;$i++)
$bckn .= "\n";
$this->MultiCell($w[1],6,$row[1].$bckn,'LR','L',$fill);
$this->SetXY(($x+$w[1]),($y));
$x = $this->GetX();
$y = $this->GetY();
$nb_bckn = $nb_ligne_max - $nb_ligne[2];
$bckn ='';
for($i=0;$i <= $nb_bckn;$i++)
$bckn .= "\n";
$this->MultiCell($w[2],6,$row[2].$bckn,'LR','L',$fill);
$this->SetXY(($x+$w[2]),($y));
$x = $this->GetX();
$y = $this->GetY();
$nb_bckn = $nb_ligne_max - $nb_ligne[3];
$bckn ='';
for($i=0;$i <= $nb_bckn;$i++)
$bckn .= "\n";
$this->MultiCell($w[3],6,$row[3].$bckn,'LR','R',$fill);
$this->SetXY(($x+$w[3]),($y));
$x = $this->GetX();
$y = $this->GetY();
$nb_bckn = $nb_ligne_max - $nb_ligne[4];
$bckn ='';
for($i=0;$i <= $nb_bckn;$i++)
$bckn .= "\n";
$this->MultiCell($w[4],6,$row[4].$bckn,'LR','L',$fill);
$this->SetXY(($x+$w[4]),($y));
$x = $this->GetX();
$y = $this->GetY();
$nb_bckn = $nb_ligne_max - $nb_ligne[5];
$bckn ='';
for($i=0;$i <= $nb_bckn;$i++)
$bckn .= "\n";
$this->MultiCell($w[5],6,$row[5].$bckn,'LR','R',$fill);
$this->SetXY($x_base,($y + (6 * $nb_ligne_max)));
$fill=!$fill;
}
//Trait de terminaison
$this->Cell(array_sum($w),0,'','T');
} |