extranet/www/exportpdf.php

67 lines
2.0 KiB
PHP

<?php
function topdf($filename, $options = "") {
global $firephp;
$pdfFile = str_replace('.html','.pdf',$filename);
$firephp->log($pdfFile, 'pdfFile');
$pdfNameFile = substr($pdfFile, strrpos($pdfFile, "/")+1);
if (!file_exists($pdfFile)){
// Run HTMLDOC to provide the PDF file to the user...
// Use the --no-localfiles option for enhanced security!
// Use ulimit to limit the maximum amount of memory used by each instance!
passthru("ulimit -m 16384 -t 10; htmldoc -t pdf14 --quiet --jpeg --webpage $options '$filename' -f $pdfFile");
}
if (file_exists($pdfFile)){
// Write the content type to the client...
header("Content-Type: application/pdf");
//header("Content-Disposition: inline; filename=\"$pdfFile\"");
header("Content-Disposition: attachement; filename=\"$pdfNameFile\"");
flush();
print file_get_contents($pdfFile);
}
}
//Start...
$page = $_REQUEST['page'];
$idEntreprise = $_REQUEST['idEntreprise'];
$siret = $_REQUEST['siret'];
$siren = substr($siret,0,9);
//Construire le titre du fichier PDF en fonction des paramètres fournis
$path = realpath(dirname(__FILE__).'/../cache/');
if (($siret*1)==0 || ($siren*1)<100){
$fileName = $path.'/'.$page.'-'.$idEntreprise;
}else{
$fileName = $path.'/'.$page.'-'.$siret;
}
//Gestion des cas particuliers
if($page=='dirigeants' && $_REQUEST['vue']=='histo'){
$fileName.= '-histo';
}elseif($page=='annonces'){
if(isset($_REQUEST['vue']) && $$_REQUEST['vue']!=''){$fileName.= '-'.$_REQUEST['idan'];}
}elseif($page=='liasse'){
if(isset($_REQUEST['mil'])){
$mil = explode(',',$_REQUEST['mil']);
$annee = substr($mil[0],-10);
$annee = str_replace('/', '', $annee);
$firephp->log($annee, 'annee');
$fileName.= '-'.$annee;
}
}elseif($page=='ratios'){
if(isset($_REQUEST['mil'])){
$mil = explode(',',$_REQUEST['mil']);
$annee = substr($mil[0],-10);
$annee = str_replace('/', '', $annee);
$firephp->log($annee, 'annee');
$fileName.= '-'.$annee;
}
}
//Ajout de l'extension
$fileName.='.html';
$firephp->log($fileName, 'FICHIER');
topdf($fileName, '--no-links');
?>