Export PDF

This commit is contained in:
Michael RICOIS 2009-03-05 08:31:21 +00:00
parent ddcbf4d6ac
commit 5e2a861076
6 changed files with 85 additions and 76 deletions

View File

@ -31,7 +31,7 @@ class Cache {
function startCapture($page, $siren, $idEntreprise = 0){
global $firephp;
$this->page = $page;
$this->page = str_replace('.php','',$page);
$this->idEntreprise = $idEntreprise;
$this->siren = $siren;
if ($this->siren==0){
@ -54,6 +54,7 @@ class Cache {
$this->content = ob_get_contents();
$this->length = ob_get_length();
ob_end_flush();
$this->content.='<!-- Page fourni par le cache -->';
$this->create();
}
}
@ -86,8 +87,10 @@ class Cache {
function create(){
//Retrait <script>...</script>
preg_replace('@<script[^>]*?>.*?</script>@si', '', $this->content);
$this->content.='<!-- Page fourni par le cache -->';
file_put_contents($this->fileName, $this->content);
if( !file_put_contents($this->fileName, $this->content))
{
//TODO : Gestion des erreurs
}
}
}

View File

@ -1,21 +1,26 @@
<?php
// Include XML_Serializer
require_once 'XML/Serializer.php';
require_once('XML/Serializer.php');
require_once(realpath(dirname(__FILE__)).'/cache.php');
/**
* Export - Gère les différents format d'exportation
* @package export
* @author Michael RICOIS
* @copyright Scores&Decisions
*/
class array2xml {
class ExportXML {
public $fileName = '';
public $path = '';
public $page = '';
public $rootName = 'page';
public $records = array();
public $encoding = 'UTF-8';
public $serializer_options = array();
public $content = '';
function __construct() {}
function __construct() {
$this->path = realpath(dirname(__FILE__).'/../cache/');
}
function setXMLOptions(){
// An array of serializer options
@ -37,30 +42,40 @@ class array2xml {
if (PEAR::isError($status)) {
//$status->getMessage()
}
$xml = $Serializer->getSerializedData();
$this->content = $Serializer->getSerializedData();
}
function writeXML(){
$fp = fopen($this->fileName, 'w');
if ($fp != FALSE){
fclose($fp);
function writeXML($page, $siren, $idEntreprise = 0){
$this->page = str_replace('.php','',$page);
$this->siren = $siren;
$this->idEntreprise = $idEntreprise;
$this->serialize();
if ($this->siren==0){
$this->fileName = $this->path.'/'.$this->page.'-'.$this->idEntreprise.'.xml';
}else{
//Erreur
$this->fileName = $this->path.'/'.$this->page.'-'.$this->siren.'.xml';
}
if( !file_put_contents($this->fileName, $this->content))
{
//TODO : Gestion des erreurs
}
}
}
}
class array2csv {
class ExportCSV {
public $siren = '';
public $idEntreprise = '';
public $fileName = '';
public $path = '';
public $page = '';
public $encoding = 'UTF-8';
public $delimiter = ';';
public $records = array();
function __construct() {}
function __construct() {
$this->path = realpath(dirname(__FILE__).'/../cache/');
}
/**
* Ecrit un fichier csv à partir d'un tableau.
@ -69,8 +84,16 @@ class array2csv {
* @param string $delimiter
* @return void
*/
function writeCSV()
function writeCSV($page, $siren, $idEntreprise = 0)
{
$this->page = str_replace('.php','',$page);
$this->siren = $siren;
$this->idEntreprise = $idEntreprise;
if ($this->siren==0){
$this->fileName = $this->path.'/'.$this->page.'-'.$this->idEntreprise.'.csv';
}else{
$this->fileName = $this->path.'/'.$this->page.'-'.$this->siren.'.csv';
}
$newRecords=array();
$this->array_flatten($this->records,$newRecords);
@ -88,7 +111,6 @@ class array2csv {
}else{
//Erreur
}
}
function array_flatten($array, &$newArray = Array() ,$prefix='',$delimiter='|') {
@ -105,12 +127,10 @@ class array2csv {
}
class content2pdf {
class ExportPDF {
function __construct(){}
}

View File

@ -1,9 +1,10 @@
<?php
function topdf($filename, $options = "") {
// Write the content type to the client...
header("Content-Type: application/pdf");
header("Content-Disposition: inline; filename=\"generic.pdf\"");
//header("Content-Disposition: attachement; filename=\"generic.pdf\"");
header("Content-Disposition: inline; filename=\"$filename.pdf\"");
//header("Content-Disposition: attachement; filename=\"$filename.pdf\"");
flush();
// Run HTMLDOC to provide the PDF file to the user...
@ -30,16 +31,20 @@ function bad_url($url) {
//Start...
$url = $_REQUEST['url'];
$page = $_REQUEST['page'];
$idEntreprise = $_REQUEST['iden'];
$siret = $_REQUEST['siret'];
$siren = substr($siret,0,9);
//Construire le titre du fichier PDF en fonction des paramètres fournis
if (bad_url($url)) {
print("<html><head><title>Bad URL</title></head>\n"
."<body><h1>Bad URL</h1>\n"
."<p>The URL <b><tt>$url</tt></b> is bad.</p>\n"
."</body></html>\n");
$path = realpath(dirname(__FILE__).'/../cache/');
if ($siren==0){
$fileName = $path.'/'.$page.'-'.$idEntreprise.'.html';
}else{
topdf($url);
$fileName = $path.'/'.$page.'-'.$siren.'.html';
}
$firephp->log($fileName, 'FICHIER');
exit;
topdf($fileName);
?>

View File

@ -1,4 +1,5 @@
<?
// MODIF
global $fichierPdf;
@ -181,17 +182,11 @@ function redimage($img_src,$dst_w,$dst_h) {
}
elseif ($page<>'main' && $_REQUEST['action']<>'logon') {
$message="Vous avez été déconnecté de l'extranet suite à un délai d'inactivité trop long (2)";
/*echo "<!--\n";
echo "REQUEST=\n".print_r($_REQUEST)."\n";
echo "SESSION=\n".print_r($_SESSION)."\n";
echo "tabInfos=\n".print_r($tabInfo)."\n-->";*/
include('./pages/logout.php');
} // Sinon ok, on peut continuer
switch ($page) {
case 'referer':
//die(urlencode('&'));
//die($_REQUEST['url']);
$client2 = new SoapClient(null, array( 'trace' => 1,
'soap_version' => SOAP_1_1,
'location' => WEBSERVICE_URL,
@ -306,11 +301,6 @@ function redimage($img_src,$dst_w,$dst_h) {
try {
$O = $client->getInfosLogin($_REQUEST['login'], $_SERVER['REMOTE_ADDR']);
$user=$O['result'];
/*
echo "<pre>";
print_r($user);
echo "</pre>";
*/
if ($user['connected']==true) {
$tabInfo['login']=$_REQUEST['login'];
$tabInfo['password']=$_REQUEST['hach'];
@ -341,12 +331,6 @@ function redimage($img_src,$dst_w,$dst_h) {
$_SESSION['connected']=true;
$_SESSION['tabInfo']=$tabInfo;
/*
echo "<pre>";
print_r($_SESSION);
echo "</pre>";
exit;
*/
include('./pages/main.php');
logAction($tabInfo['login'], $page, $_REQUEST['siret'], $tabInfo['ip'], $tabInfo['host'], $tabInfo['resolution'], $tabInfo['nbcolors'], $tabInfo['user_agent'],$tabInfo['referer1'], gmdate('Y/m/d H:i:s',$tabInfo['date_login']+3600), gmdate('Y/m/d H:i:s',$tabInfo['date_last_action']+3600), implode(', ',$_REQUEST));

View File

@ -15,7 +15,6 @@ $cache = new Cache();
if ( $cache->startCapture($page2,$siren,$iden) == FALSE){
print $cache->displayCache();
}else{
/** Utilisation du WS **/
$client = new SoapClient(null, array( 'trace' => 1,
'soap_version' => SOAP_1_1,
@ -561,9 +560,7 @@ if ( $cache->startCapture($page2,$siren,$iden) == FALSE){
?>
</table>
<?
}//Fin test mise en cache
/*
function htmldecode($value){
$value = is_array($value) ? array_map('htmldecode', $value) : html_entity_decode($value, ENT_QUOTES, 'UTF-8');
return $value;
@ -572,14 +569,14 @@ $tabForExport = htmldecode($etab);
require_once(realpath(dirname(__FILE__).'/../../includes/').'/export.php');
$array2csv = new array2csv();
$array2csv->fileName = realpath(dirname(__FILE__).'/../../cache/csv/').'/test.csv';
$array2csv = new ExportCSV();
$array2csv->records = $tabForExport;
$array2csv->writeCSV();
$array2csv->writeCSV($page2,$siren,$iden);
$array2xml = new array2xml();
$array2xml = new ExportXML();
$array2xml->records = $tabForExport;
$array2xml->serialize();
*/
$array2xml->writeXML($page2,$siren,$iden);
}//Fin test mise en cache
$cache->stopCapture(); //On arrete la capture pour le cache
?>

View File

@ -74,7 +74,7 @@ if ($sortie!='prt') {
$params .= 'sortie=prt';
?>
- <a href="<?=$_SERVER['REQUEST_URI']?><?=$params?>" target="_blank"><img src="./img/icone_print.png"/></a>
- <a href="./page2pdf.php?<?=$_SERVER['QUERY_STRING'].$params?>" target="_blank"><img src="./img/icone_pdf.gif"/></a>
- <a href="./exportpdf.php?<?=$_SERVER['QUERY_STRING']?>" target="_blank"><img src="./img/icone_pdf.gif"/></a>
<?php } ?>
</font>