| 12
 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
 
 | <?php
session_start();
 
try
{
	$bdd = mysqli_connect('localhost', '<user>', '<password>', '<nom_base>');
}
catch(Exception $e)
{
	die('Erreur : '. mysqli_error());
}
$Type = $_SESSION['type'];
$req = 'SELECT * FROM '.$Type.'';
if($result = mysqli_query($bdd, $req))
{
	$champs = array();
	$iCpt = 0;
	while($infos = mysqli_fetch_field($result))
	{
		$NomChamp = $infos -> name;
		$iCpt++;
		$champs[$iCpt] = $NomChamp;
	}
}
 
require('fpdf.php');
class PDF extends FPDF
{
	function LoadData($file)
	{
		$lines = file($file);
		$data = array();
		foreach($lines as $line)
		{
			$data[] = explode(':', trim($line));
		}
		return $data;
	}
 
	function BasicTable($header)
	{
		$this -> SetX(82);  //espace entre la gauche de la page et l'entête du tableau
		$this->SetFillColor(192,192,192); //cellule de l'entête en gris
		$this->SetTextColor(0); //texte en noir
		$this->SetFont('Arial', '', 16); //Arial 16
		// En-tête
		foreach($header as $col)
			$this->Cell(40,7,$col,1,0,'C',true); //true pour afficher la couleur
		$this->Ln(); //saut de ligne
		$this->SetFont('Arial', '', 12); //remettre en Arial 12
	}
 
	function Table($data)
	{
		// Données
		foreach($data as $row) 
		{
			$this -> SetX(82);
			foreach($row as $col)
			{
				$this->Cell(40,7,$col,1,0,'C');
			}
			$this->Ln();
		}
	}
 
	function Header()
	{
		//variable de sessions
		$type = $_SESSION['type'];
		$titre = "Outils de type ".$type."";
		$user = $_SESSION['user'];
 
		$this -> Image('Pibomulti.jpg', 10, 6, 40); //image
		$this -> SetFont('Arial', '', 12); //Arial 12
		$this -> Cell(0, 10, 'Utilisateur : '.$user.'', 0,1, 'R'); //afficher tout à droite le nom d'utilisateu
		$this->SetFont('Arial', 'bu',22); //Arial gras souligné en taille 22
		// Décalage à droite
		// Titre
		$this->Cell(0,10,utf8_decode($titre),0,1,'C'); //titre au centre
		// Saut de ligne
		$this -> Ln();
	}
 
	function Footer()
	{
		$date = date("d.m.Y"); //format de la date
		$heure = date("H:i"); //format de l'heure
		$this -> SetY(-15); //coordonnées de l'axe Y
		$this -> SetFont('Arial', 'I', 12); //texte Arial 12 en italique
		$this -> Cell(0, 10, 'Page '.$this -> PageNo(),0,0,'C'); //texte centré au milieu
		$this -> SetY(-15);
		$this -> SetFont('Arial', 'I', 12);
		$this -> Cell(0, 10, $date.' / '.$heure,0,0,'L'); //affichage de la date à gauche
		$this -> SetY(-15);
		$this -> SetFont('Arial', 'I', 12);
		$this -> Cell(0, 10, 'Copyright PiboTools, Pibomulti',0,0,'R'); //affichage du texte à droite
	}
 
	function AddCol($field=-1,$width=-1,$caption='',$align='L')
	{
		//Ajoute une colonne au tableau
		if($field==-1)
			$field=count($this->aCols);
		$this->aCols[]=array('f'=>$field,'c'=>$caption,'w'=>$width,'a'=>$align);
	}
}
// Instanciation de la classe dérivée
$pdf = new PDF('L'); //nouveau document en paysage
$header = array();
for($i = 2; $i <= $iCpt; $i++)
{
	array_push($header, ''.$champs[$i].'');
}
//$data = $pdf -> LoadData('essai_tableau.txt');
$pdf->AddPage(); //nouvelle page
$pdf->BasicTable($header);
$pdf->SetFont('Arial','',12); //police style et taille
$data = array();
for($i = 2; $i <= 3; $i++)
{
	$req2 = "SELECT ".$champs[$i]." FROM ".$Type."";
	$result2 = mysqli_query($bdd, $req2);
	$flux = fopen('essai_tableau.txt', 'a+');
	while($donnees = mysqli_fetch_assoc($result2))
	{
		fwrite($flux, $donnees[''.$champs[$i].'']);
		fwrite($flux, "\r\n");
		$data = $pdf -> LoadData('essai_tableau.txt');
		$pdf -> Table($data);
		$pdf -> AddCol(''.$champs[$i + 1].'');
		ftruncate($flux, 0);
	}
 
}
$pdf->Output(); //faire sortir le document dans le navigateur
?> | 
Partager