<?php
 if(basename(__FILE__) == basename($_SERVER['PHP_SELF'])){exit();}
 global $config;
 require_once 'config/class/class.database.php';
 $db = new database();

 require_once 'config/class/class.memberspace.php';
 $member = new member_space();

 if (!empty($_GET['z'])) $__z = $_GET['z']; else $__z = '';
 if (!empty($_GET['w']) && filter_var($_GET['w'], FILTER_VALIDATE_INT)!== false && $_GET['w']>2018 && $_GET['w']<=$config['smib_annee_encours']) $__w = $_GET['w']; else $__w = $config['smib_annee_encours'];

 header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
 header("Cache-Control: post-check=0, pre-check=0", false);
 header("Pragma: no-cache");
 header('Expires: 0');
?>

<?php $_shouldextend[1]=1; ?>

<?php $this->startSection('wisra_basic_content'); ?>
 @parentXYZABC


<div class="body-content js-body-content blue-body">
 <main id="main">
 <div class="standings-background-hero">
 <picture class="standings-background-hero__pattern left js-lazy-picture loaded">
 <img src="<?php echo $config['app_url'] ?>sources/image/basic/stripes-left.png" data-image-src="<?php echo $config['app_url'] ?>sources/image/basic/stripes-left.png" alt="Standings Background Pattern">
 </picture>
 <picture class="standings-background-hero__pattern right js-lazy-picture loaded">
 <img src="<?php echo $config['app_url'] ?>sources/image/basic/stripes-right.png" data-image-src="<?php echo $config['app_url'] ?>sources/image/basic/stripes-right.png" alt="Standings Background Pattern">
 </picture>
 </div>
 <div class="u-main-gradient">
 <div class="wrapper">
 <div class="col-12">
 <section class="standings">
 <div class="standings__header">
 <div class="standings-header">
 <h1> Attestation </h1>
 </div>
 </div>

 <div class="standings__content js-standings-content">
 <section class="standings-league js-standings-pane">

 <div class="standings-league__header standings-pane-header">
 <div class="standings-pane-header__spacer"></div>
 <div class="standings-pane-header__info">
 <img src="<?php echo $config['app_url'] ?>sources/image/basic/semi-marathon-bejaia-footer.png" alt="<?php echo $config['app_name'] ?> logo" class="standings-pane-header__competition-logo">
 </div>
 <span class="standings-pane-header__name visually-hidden"></span>
 <div class="standings-pane-header__time-info">
 <div class="standings-pane-header__last-updated"> 
 Impression d'attestation
 </div>
 <div class="standings-pane-header__season-info-container">
 <span class="standings-pane-header__season-info js-season-info"> <?php echo $__w-2005;?>ème édition </span>
 <span class="standings-pane-header__match-week-info js-match-week-info"> (<?php echo $__w;?>) </span>
 </div>
 </div>
 </div>
<?php
 $texto = '';
 if (empty($__z)) header("Location: ".$config['app_url']."profil");
 $req = "
 SELECT 
 A.*, B.nom, B.prenom, B.datnes, B.sex, C.nom_fr_fr AS pays  
 FROM member_particip A 
 INNER JOIN member B on B.id=A.membre 
 INNER JOIN ad_pays C on C.id=B.payspy 
 WHERE A.diplome_code=:__z AND A.annee=:__w AND A.valide=1 AND A.dossard>0 AND A.time_course>0 AND A.classement>0 AND A.removed=0;
 ";
 $arg = compact('__z', '__w');
 $donnees = $db->select($req, $arg, false);
 if (empty($donnees)) $texto = 'Erreur Inconnue! Veuillez nous contacter svp.';
 else {

 $uniqid = uniqid();
 require('www/pdf_script/fpdf.php');
 require('www/pdf_script/class/pdf.php');
 require('www/pdf_script/fpdf_tpl.php');
 require('www/pdf_script/fpdi.php');

 $pdf = new FPDF();
 $pdf = new FPDI('L','mm',array(297, 210));

 $pdf->AddFont('montserrat_sb','B','Montserrat-SemiBold.php');
 $pdf->AddFont('greatvibes_regular','B','GreatVibes-Regular.php');
 $pdf->AddFont('SourceSansPro_light','B','SourceSansPro-Light.php');

 $pdf_file = 'www/diplomes/attestation-semimarathon-bejaia-'.$config['smib_annee_encours'].'-'.$__z.'.pdf';


 #Read
 $pdf->addPage();
 $setSourceFile='www/diplome.pdf';
 $pdf->setSourceFile($setSourceFile);
 $tplidx = $pdf->importPage(1);
 $pgdim = $pdf->getTemplateSize($tplidx);
 $pdf->useTemplate($tplidx, 0, 0, $pgdim['w'], $pgdim['h']);
 $pdf->SetAutoPageBreak(false, 0);


 #Write
 //-> Big Text
 $pdf->SetFont('SourceSansPro_light','B',14);
 $pdf->SetTextColor(90,90,90);
 $pdf->SetXY(50,108.5);
 $text2whrite = 'Je soussigné, Fatsah Haddad président du Semi Marathon international de la ville
de Béjaia, atteste que '.(($donnees['sex']==1)?'M.':'Mme').' '.$donnees['prenom'].' '.$donnees['nom'].', né'.(($donnees['sex']==0)?'e':'').' le '.date('d/m/Y', $donnees['datnes']).', pays: '.utf8_encode($donnees['pays']).', 
a participé'.(($donnees['sex']==0)?'e':'').' à la '.($__w-2005).'ème édition de notre Semi-Marathon '.$__w.'.';
 $text2whrite = iconv('UTF-8', 'windows-1252', $text2whrite);
 $pdf->MultiCell(190, 6, $text2whrite, 0, 'C', false);


 //-> Distance
 $pdf->SetFont('montserrat_sb','B',12);
 $pdf->SetTextColor(65,65,65);
 $pdf->SetXY(63,131.7);
 $text2whrite = '21.097Km';
 $pdf->MultiCell(50, 5, $text2whrite, 0, 'C', false);


 //-> Classement
 $pdf->SetFont('montserrat_sb','B',12);
 $pdf->SetTextColor(65,65,65);
 $pdf->SetXY(69,131.7);
 $text2whrite = $donnees['classement'];
 $pdf->MultiCell(190, 5, $text2whrite, 0, 'C', false);


 //-> Temps
 function sectotime($sec) {
 $timo='';
 $hr=floor($sec/3600);
 if ($hr>0) $timo.=$hr.':';
 $sec=$sec-$hr*3600;
 $mn=floor($sec/60);
 if ($mn>0) $timo.=(($mn<9)?'0':'').$mn.':'; else $timo.='00:';
 $sec=$sec-$mn*60;
 if ($sec>0) $timo.=(($sec<9)?'0':'').$sec; else $timo.='00';
 return $timo;
 }
 $pdf->SetFont('montserrat_sb','B',12);
 $pdf->SetTextColor(65,65,65);
 $pdf->SetXY(136,131.7);
 $text2whrite = sectotime($donnees['time_course']);
 $pdf->MultiCell(190, 5, $text2whrite, 0, 'C', false);

 //-> Vérification
 $pdf->SetFont('SourceSansPro_light','B',9);
 $pdf->SetTextColor(110,110,110);
 $pdf->SetXY(20,186);
 $text2whrite = 'Vérification d’authenticité: '.$config['app_url'].'attestation-de-participation/'.$__z.'/'.$__w;
 $text2whrite = iconv('UTF-8', 'windows-1252', $text2whrite);
 $pdf->Cell(200, 6, $text2whrite, 0, 'C', false);


 //-> Vérification
 $pdf->SetFont('greatvibes_regular','B',53);
 $pdf->SetTextColor(0,61,102);
 $pdf->SetXY(0,68);
 $text2whrite = $donnees['prenom'].' '.$donnees['nom'];
 $text2whrite = iconv('UTF-8', 'windows-1252', $text2whrite);
 $pdf->MultiCell(297, 50, $text2whrite, 0, 'C', false);


 $pdf->Output($pdf_file, 'F');
 header("Location: ".$config['app_url'].$pdf_file."?uq=$uniqid#$uniqid");
 }
?>
 <div class="widget__header">
 <h3 class="widget__title"><?php echo $texto; ?></h3>
 </div>
 </section>
 </div>
 </section>
 </div>
 </div>
 </div>
 </main>
</div>


<?php $this->stopSection(); ?>

<?php /*-------------------------------------- Put here your additional CSS files for this page --------------------------------------*/ ?>
<?php $this->startSection('wisra_css_content'); ?>
 
<?php $this->stopSection(); ?>


<?php /*-------------------------------------- Put here your additional JS files  for this page --------------------------------------*/ ?>
<?php $this->startSection('wisra_js_content'); ?>
 
<?php $this->stopSection(); ?>
<?php if (@$_shouldextend[1]) { echo $this->runChild('layout', ['page_data' => array(
 'plugins' => array(), 
 'title' => "Wisra Framework | Web sites builder", 
 'description' => "Wisra Framework", 
 'keywords' => array("Wisra Framework", "Web sites builder"), 
 'facebook_integration' => false, 
 'google_maps_callback' => ''
)]); } ?>