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
| <?php
require('fpdf.php');
class PDF extends FPDF
{
//Chargement des données
function LoadData($file)
{
//Lecture des lignes du fichier
$lines=file($file);
$data=array();
foreach($lines as $line)
$data[]=explode(';',chop($line));
return $data;
}
//Tableau simple
function BasicTable($header,$data)
{
//En-tête
foreach($header as $col)
$this->Cell(40,7,$col,1);
$this->Ln();
//Données
foreach($data as $row)
{
foreach($row as $col)
$this->Cell(40,6,$col,1);
$this->Ln();
}
}
//Tableau amélioré
function ImprovedTable($header,$data)
{
//Largeurs des colonnes
$w=array(40,35,45,40);
//En-tête
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C');
$this->Ln();
//Données
foreach($data as $row)
{
$this->Cell($w[0],6,$row[0],'LR');
$this->Cell($w[1],6,$row[1],'LR');
$this->Cell($w[2],6,number_format($row[2],0,',',' '),'LR',0,'R');
$this->Cell($w[3],6,number_format($row[3],0,',',' '),'LR',0,'R');
$this->Ln();
}
//Trait de terminaison
$this->Cell(array_sum($w),0,'','T');
}
//Tableau coloré
function FancyTable($header,$data)
{
//Couleurs, épaisseur du trait et police grasse
$this->SetFillColor(255,0,0);
$this->SetTextColor(255);
$this->SetDrawColor(128,0,0);
$this->SetLineWidth(.3);
$this->SetFont('','B');
//En-tête
$w=array(40,35,45,40);
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;
foreach($data as $row)
{
$this->Cell($w[0],6,$row[0],'LR',0,'L',$fill);
$this->Cell($w[1],6,$row[1],'LR',0,'L',$fill);
$this->Cell($w[2],6,number_format($row[2],0,',',' '),'LR',0,'R',$fill);
$this->Cell($w[3],6,number_format($row[3],0,',',' '),'LR',0,'R',$fill);
$this->Ln();
$fill=!$fill;
}
$this->Cell(array_sum($w),0,'','T');
}
}
$pdf=new PDF();
//Titres des colonnes
$header=array('Poste', 'Trigramme', 'N_Carte_APRS', 'N_De_ST', 'Adresse', 'Code_Postal', 'Ville','Pays', 'Tel_Personnel', 'Mobile_Personnel', 'Email_Personnel', 'Societe', 'Tel_Professionnel', 'Tel_Mobile', 'N_De_Fax', 'Date_De_Naissance', 'Ville_Natale', 'Nationalite', 'Ouverture_Dossier', 'Remarques', 'Etat_Dossier', 'Date_Entree_Atis', 'N_Inspecteur_Qualite', 'N_Operateur_Certifie', 'N_Marque_Devalidee', 'N_Badge_Airbus', 'Affectation', 'Metier', 'Licence_Part66', 'Validite', 'Date_Derniere_MAJ');
//
// information pour la connection à le DB
$host = 'localhost';
$user = 'root';
$pass = '';
$db = 'ATIS';
// connection à la DB
$link = mysql_connect ($host,$user,$pass) or die ('Erreur : '.mysql_error() );
mysql_select_db($db) or die ('Erreur :'.mysql_error());
// requête SQL qui compte le nombre total d'enregistrement dans la table et qui
//récupère tous les enregistrements
$select = 'Poste, Trigramme, N_Carte_APRS, N_De_ST, Adresse, Code_Postal, Ville,Pays, Tel_Personnel, Mobile_Personnel, Email_Personnel, Societe, Tel_Professionnel, Tel_Mobile, N_De_Fax, Date_De_Naissance, Ville_Natale, Nationalite, Ouverture_Dossier,Remarques, Etat_Dossier, Date_Entree_Atis, N_Inspecteur_Qualite, N_Operateur_Certifie, N_Marque_Devalidee, N_Badge_Airbus, Affectation, Metier, Licence_Part66, Validite, Date_Derniere_MAJ FROM contact';
$result = mysql_query($select,$link) or die ('Erreur Erreur!!!: '.mysql_error() );
mysql_num_rows($result);
//
//Chargement des données
$data=$pdf->LoadData('$result');
$pdf->SetFont('Arial','',14);
$pdf->AddPage();
$pdf->BasicTable($header,$data);
$pdf->AddPage();
$pdf->ImprovedTable($header,$data);
$pdf->AddPage();
$pdf->FancyTable($header,$data);
$pdf->Output();
?> |
Partager