extranet/www/html2pdf.php

95 lines
3.6 KiB
PHP

<?php
session_start();
require_once 'common/dates.php';
require_once 'common/curl.php';
isset($_REQUEST['q'])? $nomFic = $_REQUEST['q'] : $nomFic = '';
if($nomFic == ''){
print 'Impossible de générer le document.';
}else{
require_once 'surveillance/survliste.php';
$client = new SoapClient(null, array( 'trace' => 1,
'soap_version' => SOAP_1_1,
'location' => WEBSERVICE_URL,
'uri' => WEBSERVICE_URI,
'login' => $_SESSION['tabInfo']['login'],
'password' => $_SESSION['tabInfo']['password'],
));
try {
$O = $client->getListeFichierSurv($_SESSION['tabInfo']['login'], $_SESSION['tabInfo']['prenom'], $nomFic);
$file = PATH_DATA.'/pdf/'.$nomFic;
$file2 = $file.'.bz2';
if (!file_exists($file)) {
$page = getUrl(WEBSERVICE_URI.'csv/'.$nomFic.'.bz2', '', '', '', false);
$body = $page['body'];
$fp=@fopen($file2, 'w');
@fwrite($fp, $body);
@fclose($fp);
$bz = bzopen($file2, "r") or die("Impossible d'ouvrir le fichier $file");
$fp=@fopen($file, 'w');
while (!feof($bz)) {
@fwrite($fp, bzread($bz, 4096));
}
bzclose($bz);
}
} catch (SoapFault $fault) {
require_once 'soaperror.php';
processSoapFault($client,$fault,$tabInfo);
exit;
}
$annonces = readann($file, '');
$output = '';
$output.= '<page backtop="10mm" backbottom="10mm">';
$output.= '<page_header>';
$output.= '<table style="width: 100%; border: solid 1px black;">';
$output.= '<tr>';
$output.= '<td style="text-align: center; width: 67%">'.$nomFic.'</td>';
$output.= '<td style="text-align: right; width: 33%">'.date('d/m/Y').'</td>';
$output.= '</tr>';
$output.= '</table>';
$output.= '</page_header>';
$output.= '<page_footer>';
$output.= '<table style="width: 100%; border: solid 1px black;">';
$output.= '<tr>';
$output.= '<td style="text-align: left; width: 50%">&nbsp;</td>';
$output.= '<td style="text-align: right; width: 50%">page [[page_cu]]/[[page_nb]]</td>';
$output.= '</tr>';
$output.= '</table>';
$output.= '</page_footer>';
$count = 0;
foreach($annonces as $annonce){
if ($count>0) $output.= '<page pageset="old">';
$output.= '<table width="580">'."\n";
$output.= '<tr><td width="30">&nbsp;</td>'."\n";
$output.= ' <td width="550" colspan="2" class="StyleInfoLib">Entreprise : '.$annonce['RaisonSociale'].' ('.$annonce['Siren'].')</td>'."\n";
$output.= '</tr>'."\n";
$output.= '<tr><td width="30">&nbsp;</td>'."\n";
$output.= ' <td width="200" class="StyleInfoData">Site : '.$annonce['SiteCnasea'].'</td>'."\n";
$output.= ' <td width="350" colspan="2" class="StyleInfoData">Référence : '.$annonce['Ref'].'</td>'."\n";
$output.= '</tr>'."\n";
$output.= '<tr><td width="30">&nbsp;</td>'."\n";
$output.= ' <td width="550" colspan="2" class="StyleInfoData">BODACC n&deg;'.$annonce['Parution'].'&nbsp;'.$annonce['Bodacc'].' du '.$annonce['DatePar'].' '.$annonce['Tribunal'].'.</td>'."\n";
$output.= '</tr>'."\n";
$output.= '<tr><td width="30">&nbsp;</td>'."\n";
$output.= ' <td width="550" colspan="2" class="StyleInfoLib"><b>'.$annonce['Even'].'</b></td>'."\n";
$output.= '</tr>'."\n";
$output.= '<tr><td colspan="4">&nbsp;</td></tr>'."\n";
$output.= '<tr><td width="30">&nbsp;</td>'."\n";
$output.= ' <td width="550" colspan="2">'.$annonce['TexteAnn'].'</td>'."\n";
$output.= '</tr>'."\n";
$output.= '</table>'."\n";
$output.= '</page>'."\n";
$count++;
}
// conversion HTML => PDF
require_once 'html2pdf/html2pdf.class.php';
$html2pdf = new HTML2PDF('P','A4','fr');
$html2pdf->WriteHTML($output);
$html2pdf->Output(str_replace('.csv', '.pdf', $nomFic), 'D');
}
?>