<?php 
session_start();
require_once(dirname(__DIR__, 2) . '/config.php');
require_once(BASE_PATH . '/db/idl_connect.php');
$lang = $_SESSION['lang'];
include_once('../include/lang/'.$lang.'.php');
echo ZONE;
		
if(isset($_SESSION['user_droits'])) {
	if($_SESSION['user_droits'][5]<"1") {
		echo '<p class="noaccess">'.NOMODULE.'<br><a href="../../index.php">'.ACCUEIL.'</a></p>';
	}
	else {
		// Autre ordre si besoin :
		if($_POST['havepdf']==1) {
			include('../../db/proc/freq_extract_order.php');
		}
		else if($_POST['havepdf']==2) {
			include('../../db/proc/freq_extract_resorder.php');
		}
		
		// variables diverses
		$margextd = 15;
		$margexth = 15;
		$margextg = 15;
		$margextb = 15;
		$margintd = 2;
		$marginth = 2;
		$margintg = 2;
		$margintb = 2;
		$fontsize = 10;
		
		$html = '
		<html>
		<head>
		<style>
		body {font-family: sans-serif;
			font-size: '.$fontsize.'pt;
		}
		@page :first {
			margin-left : '.$margextg.'mm;
			margin-right : '.$margextd.'mm;
			margin-top : '.$margexth.'mm; 
			margin-bottom : '.$margextb.'mm;
		}
		table {
			border-collapse:collapse;
			border :1px solid black;
		}
		th {
			border :1px solid black;
			text-align:left; 
			padding: '.$marginth.'mm '.$margintd.'mm '.$margintb.'mm '.$margintg.'mm;
		}
		td { 
			border :1px solid black;
			text-align:left; 
			padding: '.$marginth.'mm '.$margintd.'mm '.$margintb.'mm '.$margintg.'mm;
		}
		</style>
		</head>
		<body>
		'.$_SESSION['freq_liste'].'
		</body>
		</html>
		';
		$path = (getenv('MPDF_ROOT')) ? getenv('MPDF_ROOT') : __DIR__;
		if(phpversion()>=8.0) {
			require_once '../mpdf8/autoload.php';
		}
		else {
			require_once '../mpdf/autoload.php';
		}
		$mpdf = new \Mpdf\Mpdf([
			'orientation' => 'P',
			'page-break-inside' => 'avoid',
			/*'margin_left' => $modele['margextg'].'mm',
			'margin_right' => $margextd.'mm',
			'margin_top' => $modele['margexth'].'mm',
			'margin_bottom' => $modele['margextb'].'mm',*/
			'showBarcodeNumbers' => FALSE
		]);
		$mpdf->showImageErrors = true;
		try {
			$mpdf->WriteHTML($html);
		} catch (\Mpdf\MpdfException $e) {
			die ($e->getMessage());
		}
		ob_end_clean();
		$mpdf->Output('freq_liste.pdf', \Mpdf\Output\Destination::DOWNLOAD);
	}
}
else {
	include('../noaccess.php');
	echo '<a href="../../index.php">Accueil</a></p>';
}