<?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 = "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></TD>';
	$message .= "\n";				
	
	while ($data = mysqli_fetch_assoc ($result))				
	{
			$tab_jour[] = $data['rendezvous'];	
	}
	
	for( $i=0; $i <count($tab_jour) ; $i++)	
	{	
		$message .= "<TD>$tab_jour[$i]</TD>";							
		$message .= "\n";								
	}	
	
/*	$message = '
			<TABLE>
			<TR>
			<TD>Jour</TD>
			<TD>semaine</TD>
			<TD>Seance 1</TD>
			<TD>Seance 2</TD>
			<TD>Seance 3</TD>
			<TD>Seance 4</TD>
			<TD>Seance 5</TD>
			<TD>Seance 6</TD>
			<TD>Seance 7</TD>
			<TD>Seance 8</TD>*/
	$message .= '</TR>';
	
	$result = mysqli_query($connexion, $sql );
				
	while ($data = mysqli_fetch_assoc ($result))				
	{	
				$jour = $data['rendezvous'];		
				$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'];

				$message .= "
						<TR>
						<TD>$jour</TD>
						<TD>$semaine</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('compteur.php', 'a+');
				file_put_contents('compteur.php', ''); // écrase le contenu du fichier
				
				fputs($monfichier, "<?php\n");
				fputs($monfichier, "require('html_table.php');\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("$mois<BR>$htmlTable<BR>Patrice Delpy 2015.");');
				fputs($monfichier, "\n");
				fputs($monfichier, '$pdf->Output();');
				fputs($monfichier, "\n");
				fputs($monfichier, '?>');
				
				fclose($monfichier);
				
/*
$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();*/
?>
