<?php

	header( 'content-type: text/html; charset=utf-8' );
	include('database.php');
	include('fonctions.php');	
	DB_connexion(); 
	
	require('html_table.php');
	
	$annee = date('Y');	
	$table = "reservation" .$annee;
	$mois = $_GET['mois'];
	//$mois = "avril";
	
	$sql = "SELECT * FROM " .$table ." WHERE annee ='$annee' and mois ='$mois' and mode = 'actif' ";			
	echo $sql;
	mysqli_query($connexion, "SET NAMES 'utf8'");		
	$result = mysqli_query($connexion, $sql );
	$tab_jour = array();
	
	$message = '
			<TABLE>
			<TR>
			<TD>Jour</TD>
			<TD>12H20</TD>
			<TD>12H40</TD>
			<TD>13H00</TD>
			<TD>13H20</TD>
			<TD>13H40</TD>
			<TD>14H00</TD>
			<TD>14H20</TD>
			<TD>14H40</TD>
			</TR>';
	
				
	while ($data = mysqli_fetch_assoc ($result))				
	{	
				$jour = $data['rendezvous'];

				$jour = substr($jour, 0, 5);
				
				$semaine = $data['semaine'];		
				
				$seance1 = $data['seance1'];
				$seance2 = $data['seance2'];
				$seance3 = $data['seance3'];
				$seance4 = $data['seance4'];
				$seance5 = $data['seance5'];
				$seance6 = $data['seance6'];
				$seance7 = $data['seance7'];
				$seance8 = $data['seance8'];
				
				$seance1 = strtr($seance1, 'áàâäãåçéèêëíìîïñóòôöõúùûüýÿ', 'aaaaaaceeeeiiiinooooouuuuyy');
			
				$seance2 = strtr($seance2, 'áàâäãåçéèêëíìîïñóòôöõúùûüýÿ', 'aaaaaaceeeeiiiinooooouuuuyy');
			
				$seance3 = strtr($seance3, 'áàâäãåçéèêëíìîïñóòôöõúùûüýÿ', 'aaaaaaceeeeiiiinooooouuuuyy');
				$seance4 = strtr($seance4, 'áàâäãåçéèêëíìîïñóòôöõúùûüýÿ', 'aaaaaaceeeeiiiinooooouuuuyy');
				$seance5 = strtr($seance5, 'áàâäãåçéèêëíìîïñóòôöõúùûüýÿ', 'aaaaaaceeeeiiiinooooouuuuyy');
				$seance6 = strtr($seance6, 'áàâäãåçéèêëíìîïñóòôöõúùûüýÿ', 'aaaaaaceeeeiiiinooooouuuuyy');
				$seance7 = strtr($seance7, 'áàâäãåçéèêëíìîïñóòôöõúùûüýÿ', 'aaaaaaceeeeiiiinooooouuuuyy');
				$seance8 = strtr($seance8, 'áàâäãåçéèêëíìîïñóòôöõúùûüýÿ', 'aaaaaaceeeeiiiinooooouuuuyy');
				

				$message .= "
						<TR>
						<TD>$jour</TD>
						<TD>$seance1</TD>
						<TD>$seance2</TD>
						<TD>$seance3</TD>
						<TD>$seance4</TD>
						<TD>$seance5</TD>
						<TD>$seance6</TD>
						<TD>$seance7</TD>
						<TD>$seance8</TD>
						</TR>		";	
				
				
	}

				$message .= "</TABLE>";
				
				//echo $message;
				
				$monfichier = fopen('fichier_sortie_PDF.php', 'a+');
				file_put_contents('fichier_sortie_PDF.php', ''); // écrase le contenu du fichier
				
				fputs($monfichier, "<?php\n");
				fputs($monfichier, "require('html_table.php');\n");
				fputs($monfichier, "header( 'content-type: text/html; charset=utf-8' );\n");
				fputs($monfichier, '$htmlTable=');
				fputs($monfichier, "'");
				fputs($monfichier, $message);
				fputs($monfichier, "';");
				fputs($monfichier, "\n");
				fputs($monfichier, '$pdf=new PDF_HTML_Table();');
				fputs($monfichier, "\n");
				fputs($monfichier, '$pdf->AddPage();');
				fputs($monfichier, "\n");
				fputs($monfichier, '$pdf->SetFont("Arial","",10);');
				fputs($monfichier, "\n");
				//fputs($monfichier, '$pdf->WriteHTML("Start of the HTML table.<BR>$htmlTable<BR>End of the table.");');
				fputs($monfichier, '$pdf->WriteHTML("Rendez-vous:<BR>$htmlTable<BR>Patrice Delpy 2015.");');
				fputs($monfichier, "\n");
				//fputs($monfichier, '$pdf->Cell(40,10,"$mois")');
				fputs($monfichier, "\n");
				//fputs($monfichier, '$pdf->Output("./sortie.pdf","F");');
				fputs($monfichier, '$pdf->Output();');
								
				//Output('./pdfs/test.pdf', 'F');
				
				fputs($monfichier, "\n");
				
				fputs($monfichier, '?>');
				
				
				fclose($monfichier);
				
				header("Location: fichier_sortie_PDF.php");
				
/*
$htmlTable='<TABLE>
<TR>
<TD>S. No.</TD>
<TD>Name</TD>
<TD>Age</TD>
<TD>Sex</TD>
<TD>Location</TD>
</TR>

<TR>
<TD>1</TD>
<TD>Azeem</TD>
<TD>24</TD>
<TD>Male</TD>
<TD>Pakistan</TD>
</TR>

<TR>
<TD>2</TD>
<TD>Atiq</TD>
<TD>24</TD>
<TD>Male</TD>
<TD>Pakistan</TD>
</TR>

<TR>
<TD>3</TD>
<TD>Shahid</TD>
<TD>24</TD>
<TD>Male</TD>
<TD>Pakistan</TD>
</TR>

<TR>
<TD>4</TD>
<TD>Roy Montgome</TD>
<TD>36</TD>
<TD>Male</TD>
<TD>USA</TD>
</TR>

<TR>
<TD>5</TD>
<TD>M.Bony</TD>
<TD>18</TD>
<TD>Female</TD>
<TD>&nbsp;</TD>
</TR>
</TABLE>';
*/
/*$pdf=new PDF_HTML_Table();
$pdf->AddPage();
$pdf->SetFont('Arial','',10);
$pdf->WriteHTML("Start of the HTML table.<BR>$htmlTable<BR>End of the table.");
$pdf->Output();*/
?>
