<?php
require('fpdf.php');
	
class PDF extends FPDF
{
	// Pied de page
	function Footer()
	{
		// Positionnement à 1,5 cm du bas
		$this->SetY(-15);
		// Police Arial italique 8
		$this->SetFont('Arial','I',8);
		// Numéro de page
		$this->Cell(0,10, chr(169) .' Patrice Delpy 2015',0,0,'C');
		// pour le symbole register -> chr(174)
	}
}
	
	include('database.php');
	include('fonctions.php');
	DB_connexion(); 
	
	header( 'content-type: text/html; charset=utf-8' );
	
	$pdf = new PDF('P','mm','A4');
	$pdf->AddPage();

/// titre	
	$pdf->SetFont('Courier','',20);
	$pdf->SetY(10);
	$pdf->Cell(0, 0, "AGENDA", 0, 0, 'C');

// reste du document	
	$pdf->SetFont('Courier','',12);
//	$pdf->SetXY(10, 5);
//	$pdf->Write(10,'Mardi 21 Avril 2015');

	$pdf->SetDrawColor(0,0,0);
	$pdf->SetFillColor(199,199,199);
	$pdf->SetTextColor(0,0,0);
	
	$annee = date('Y');
	$table = "reservation" .$annee;
	$mois = ucfirst($_GET['mois']);
	
	$sql = "SELECT * FROM " .$table ." WHERE mois = '$mois' and mode = 'actif' ";
	//echo $sql;	
	mysqli_query($connexion, "SET NAMES 'utf8'");
	$result = mysqli_query($connexion, $sql );
	if(!$result)
	{
		die('Impossible d\'exécuter la requête :' . mysql_error());
	}
	
	$nbre_enregistrements = mysqli_num_rows($result);
	//echo $nbre_enregistrements;
		
	$tab_datas[][] = array();	
	$horaire[] = array();	
	$jour[] = array();	
	$cpt = 0;
	
	while ($datas = mysqli_fetch_assoc ($result))
	{
		
		$tab_datas[$cpt][0] = $datas['seance1'];
		$tab_datas[$cpt][1] = $datas['seance2'];
		$tab_datas[$cpt][2] = $datas['seance3'];
		$tab_datas[$cpt][3] = $datas['seance4'];
		$tab_datas[$cpt][4] = $datas['seance5'];
		$tab_datas[$cpt][5] = $datas['seance6'];
		$tab_datas[$cpt][6] = $datas['seance7'];
		$tab_datas[$cpt][7] = $datas['seance8'];
		$horaire[$cpt] = $datas['rendezvous'];
		$jour[$cpt] = $datas['jour'];
		$cpt = $cpt + 1;
	}
	
	//echo '<pre>';
	//print_r($tab_datas);
	//echo $cpt;
	
/*	mysql_connect("localhost", "root", "");
	mysql_select_db("cours");
	$lsSQL = "SELECT MAX(LENGTH(designation)) FROM produits";
	$rs  = mysql_query($lsSQL);
	$enr = mysql_fetch_row($rs);
	$liMaxLongueur = $enr[0];
	$lsDesignationType = str_repeat("Z", $liMaxLongueur);
	$liLargeurColDesignation = $pdf->GetStringWidth($lsDesignationType);
	mysql_free_result($rs);
*/
/*	$liLargeurColPrix = 20;
*/
	// --- Cell(largeur, hauteur, texte, bord, placement, alignement, remplissage, lien)
	$pdf->SetXY(10, 20);
	
	//Cell(largeur, hauteur, texte [, bord, retour à la ligne, alignement, remplissage, lien])
	
	
	$titre = array('12H20','12H40','13H00','13H20','13H40','14H00','14H20','14H40');

	for($i=0; $i < $cpt ; $i++)
	{
		//$pdf->Write(10,$horaire[$i]);
		//$pdf->ln(3);
		$date = $jour[$i] ." " .$horaire[$i];
		$pdf->Cell(50, 5, $date, 1 , 0, 'C', 1);
		$pdf->Cell(120, 5, "Seance", 1 , 1, 'C', 1);
	
		for( $j=0; $j < count($titre) ; $j++)
		{
			$pdf->Cell(50, 5, $titre[$j], 1 , 0, 'C', 0);
			$pdf->Cell(120, 5, utf8_decode($tab_datas[$i][$j]), 1 , 1, 'C', 0);
		}
	
			$pdf->ln(3);
	
	}
	
		
	
	/*$pdf->Cell(40, 5, "Horaire", 1 , 0, 'C', 1);
	$pdf->Cell(40, 5, "Seance", 1 , 1, 'C', 1);
	
	for( $i=0; $i < count($titre) ; $i++)
	{
		$pdf->Cell(40, 5, $titre[$i], 1 , 0, 'C', 0);
		$pdf->Cell(40, 5, "plouf", 1 , 1, 'C', 0);
	}*/
	
	
	
//	$pdf->Cell(40, 5, "Horaire", 1 , 0, 'C', 1);
//	$pdf->Cell(40, 5, "Seance", 1 , 1, 'C', 1);
	
//	$pdf->Cell(40, 5, '13H00', 1, 0, 'C', 0);
//	$pdf->Cell(40, 5, 'DELPY Patrice', 1 , 1, 'C', 0);

/*	$lsSQL = "SELECT designation, prix FROM produits";
	$rs    = mysql_query($lsSQL);

	while($enr = mysql_fetch_row($rs))
	{
		$pdf->Cell($liLargeurColDesignation, 5, $enr[0], 1, 0, 'C', 0);
		$pdf->Cell($liLargeurColPrix, 5, $enr[1], 1 , 1, 'C', 0);
	}*/
	$pdf->Output();
?>
