<?php
define('FPDF_FONTPATH','./font/');
require ('fpdf.php');
require ('../Scripts/conf.php');
require ('../Scripts/NousSommesLe.php');
require ('../Scripts/ErreurConnect.php');

class PDF extends FPDF
 {
    //Chargement des données
    function CreateTable($header)
    {
       global $sql_bdd;
       global $table_repertoire;

       $connect_db = jb_sql_connect(false);
       $requete = "select numero, nom, compo from $table_repertoire".
          " order by numero";
       $resultat = mysql_db_query($sql_bdd, $requete, $connect_db);

       $res = mysql_num_rows($resultat);
       $date = retourneDateduJour();
       $this->Ln();
       $this->Cell(50,10," Répertoire de l'OHMJ au $date - $res morceaux.",0,1);
       $this->Ln();

       /* Initialisation des caractéristiques du tableau. */
       $this->SetFillColor(246,174,32);
       $this->SetTextColor(255);
       $this->SetDrawColor(128,0,0);
       $this->SetLineWidth(.3);
       $this->SetFont('Arial','',12);
//       $this->SetFont('','B');

       //En-tête
       $w=array(10,60,65);
       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('Arial','',8);

       //Données
       $fill=0;
       //$sizeName = strlen($row[1]);
/*
       if ($sizeName > $w[1]) {
          $bout1 =chunk_split($row[1],$w[1], $bout2);
       }
       else*/
//       $bout1 = mysql_result($resultat,0,"nom");
       $bout2 = $sizeName;

//       while ($row = mysql_fetch_row($resultat)) {
       for ($i=0; $i< $res; $i++) {
          $numero = mysql_result($resultat,$i,"numero");
          $nomP1 = mysql_result($resultat,$i,"nom");
          $compo = mysql_result($resultat,$i,"compo");

          $sizeName = strlen($nomP1);
          $bout1 = $sizeName;
          $this->Cell($w[0],5,$numero,'LR',0,'C',$fill);
          $this->Cell($w[1],5,$nomP1,'LR',0,'L',$fill);
          $this->Cell($w[2],5,$compo,'LR',0,'L',$fill);
          $this->Ln();
          $fill=!$fill;
       }
       $this->Cell(array_sum($w),0,'','T');

    }



 }

$pdf=new PDF();
$pdf->Open();

/* Titres des colonnes. */
$header=array ('N°','Titre','Compositeur');
$pdf->AddPage ();
$pdf->SetFont ('Arial','B',16);
$pdf->Cell (60,10,"L'ORCHESTRE D'HARMONIE DE MONTPELLIER-JACOU");
$pdf->CreateTable ($header);
$pdf->Output();
?>
