<?php
	
	ob_start();
	require 'connexionBD.php';

	$db = new Connect($_GET['mySchool']);
	$dc = $db->connect_db($_GET['mySchool']);
	
	
	$req = 'SELECT conjoint.nom as nom, conjoint.postnom as postnom, conjoint.prenom as prenom, conjoint.sexe as sexe, conjoint.dateNaissance as dateNaissance, conjoint.telephone as telephone, ville.nom as nomVille, province.nom as nomProvince, avenue.nom as nomAvenue, quartier.nom as nomQuartier, commune.nom as nomCommune, numdomicile.nom as numDomicile, adherent.numAdherent as numAdherent, conjoint.photo as photo, conjoint.dateCreation as dateCreation FROM conjoint, ville, adherent, province, commune, quartier, avenue, numdomicile WHERE conjoint.idAdherent=adherent.idAdherent AND adherent.idVille=ville.idVille AND ville.validite="OUI" AND ville.idProvince=province.idProvince AND adherent.idCommune=commune.idCommune AND adherent.idQuartier=quartier.idQuartier AND adherent.idAvenue=avenue.idAvenue AND conjoint.idConjoint="'.$_GET['idConjoint'].'" AND adherent.idNumDomicile=numdomicile.idNumDomicile AND adherent.validite="OUI" AND province.validite="OUI" AND commune.validite="OUI" AND avenue.validite="OUI" AND quartier.validite="OUI" AND numdomicile.validite="OUI" AND conjoint.validite="OUI"';
 	//echo $req; die;
	$q=$dc->prepare($req);
	$q->execute();
	
	while($a=$q->fetch()){
		$nom=$a['nom'];
		$postnom=$a['postnom'];
		$prenom=$a['prenom'];
		$sexe=$a['sexe'];
		$dateNaissance=$a['dateNaissance'];
		$telephone=$a['telephone'];
		$dateCreation=$a['dateCreation'];
		$numAdherent=$a['numAdherent'];
		$photo=$a['photo'];
		$nomProvince=$a['nomProvince'];
		$nomAvenue=$a['nomAvenue'];
		$nomQuartier=$a['nomQuartier'];
		$nomCommune=$a['nomCommune'];
		$numDomicile=$a['numDomicile'];
		$nomVille=$a['nomVille'];
	}
	
	$adresse = $numDomicileArchi.",".$nomAvenue.",".$nomQuartier.",".$nomCommune;
	$nomComplet = $nom." ".$postnom." ".$prenom;
	
	$cheminPhoto="";
    if(trim($photo)<>""){
	    $dirname="../../img/".$_GET['mySchool']."/conjoint/".$photo;
        $dir = opendir($dirname);
        while($file = readdir($dir)) {
            if($file != '.' && $file != '..' && !is_dir($dirname.$file)){
                $cheminPhoto=$dirname.'/'.$file;
                $i++;
            }
        }
        closedir($dir);
	}
			
?>

<!DOCTYPE html>
<html lang="en">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="" />
<meta name="author" content="http://templateq.com" />
</head>
<style type="text/css">
<!--
table
{
    width:  100%;
    border:solid 1px;
    border-collapse: collapse;
}
th
{
    width:  100%;
    text-align:;
    border:solid 1px;
    padding:2px;
    font-size:12px;
}
td
{
    width:  100%;
    text-align:;
    border:solid 1px;
    padding:2px;
    font-size:12px;
}
-->
</style>

<body>
	
	<div style="position:absolute;left:-18px;margin-top:-17px">
	    <img src="img/CARTE DE MEMBRE_Alliance_RECTO.jpg" style="width:94.9%; vertical-align:middle; z-index:-1">
	</div>
	
	<?php $dt = DateTime::createFromFormat('Y-m-d', $dateNaissance);$date1 = $dt->format('d/m/Y'); ?>
	<?php $dt = DateTime::createFromFormat('Y-m-d', $dateCreation);$date2 = $dt->format('d/m/Y'); ?>
	<div style="position:absolute; left:76px; top:15px; padding:0px; font-size:7px; z-index:10000"> <?php echo strtoupper($numAdherent); ?> </div>
	<div style="position:absolute; left:50px; top:41px; padding:0px; font-size:7px; z-index:10000"> <?php echo strtoupper($nomComplet); ?> </div>
	<div style="position:absolute; left:46px; top:70px; padding:0px; font-size:7px; z-index:10000"> <?php echo strtoupper($sexe); ?> </div>
	<div style="position:absolute; left:102px; top:70px; padding:0px; font-size:7px; z-index:10000"> <?php echo strtoupper($nomProvince); ?> </div>
	<div style="position:absolute; left:67px; top:99px; padding:0px; font-size:7px; z-index:10000"> <?php echo strtoupper($telephone); ?> </div>
	<div style="position:absolute; left:56px; top:124px; padding:0px; font-size:7px; z-index:10000"> <?php echo strtoupper($numDomicile); ?>, AV. <?php echo strtoupper($nomAvenue); ?> </div>
	<div style="position:absolute; left:22px; top:133px; padding:0px; font-size:7px; z-index:10000"> Q. <?php echo strtoupper($nomQuartier); ?>, C. <?php echo strtoupper($nomCommune); ?> </div>
	<div style="position:absolute; left:92px; top:157px; padding:0px; font-size:7px; z-index:10000"> <?php echo strtoupper($date1); ?> </div>
	<div style="position:absolute; left:220px; top:152px; padding:0px; font-size:6px; z-index:10000"> <?php echo ucfirst($nomVille); ?>, le <?php echo strtoupper($date2); ?> </div>
	<div style="position:absolute; left:204px; top:64px; padding:0px; font-size:6px; z-index:10000"> <img src="<?php echo $cheminPhoto; ?>" width="74"> </div>
    <br/><br/><br/>
	<img src="img/CARTE DE MEMBRE_Alliance_VERSO.jpg" style="width:84%; vertical-align:middle; z-index:1">


</body>
</html>


<?php 
   
	$content = ob_get_clean();
    require_once 'html2pdf.class.php';
    try
    {
        $html2pdf = new HTML2PDF("L", "A7", "fr");
        $html2pdf->setDefaultFont("Arial");
        $html2pdf->writeHTML($content);
        $html2pdf->Output("votre_pdf.pdf");
    }
    catch(HTML2PDF_exception $e) {
        echo $e;
        exit;
    }
	
?>

