New file |
0,0 → 1,176 |
<?php |
/** |
* Classe PdfExport, réalise des exportations pdf des fiches de taxons. |
* |
* @category php 5.2 |
* @package eflore-consultation |
* @author Mathilde Salthun-Lassalle <mathilde@tela-botanica.org> |
* @copyright 2012 Tela-Botanica |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL |
* @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL |
* @version $Id$ |
* |
* manuel wkhtmltopdf : http://madalgo.au.dk/~jakobt/wkhtmltoxdoc/wkhtmltopdf_0.10.0_rc2-doc.html |
* pour changer de librairie : changer la fonction transformerHtmlEnPdf() |
*/ |
|
require_once( Config::get('chemin_modules').'fiche/formateurs/Description.php'); |
require_once( Config::get('chemin_modules').'fiche/formateurs/Ecologie.php'); |
require_once( Config::get('chemin_modules').'fiche/formateurs/Classification.php'); |
require_once( Config::get('chemin_modules').'fiche/formateurs/Bibliographie.php'); |
require_once( Config::get('chemin_modules').'fiche/formateurs/Ethnobotanique.php'); |
require_once( Config::get('chemin_modules').'fiche/formateurs/Illustrations.php'); |
require_once( Config::get('chemin_modules').'fiche/formateurs/Nomenclature.php'); |
require_once( Config::get('chemin_modules').'fiche/formateurs/Repartition.php'); |
require_once( Config::get('chemin_modules').'fiche/formateurs/Statut.php'); |
|
class PdfExport extends aControleur { |
|
|
private $Conteneur; |
private $parametres = array(); |
private $chemin_pdf; |
private $html; |
private $wkhtml; |
private $piedepage; |
private $fichier_pdf; |
private $blocs = array(); |
|
private $Desc; |
private $Ecolo; |
private $Ethno; |
private $Classi; |
private $Illus; |
private $Nomen; |
private $Reparti; |
private $Stat; |
private $Biblio; |
|
|
public function initialiser() { |
$this->capturerParametres(); |
$this->conteneur = new Conteneur($this->parametres); |
$this->chemin_pdf = Config::get('dossier_pdf'); |
$this->wkhtml = Config::get('WKHTMLTOPDF'); |
$this->Desc = new Description($this->conteneur); |
$this->Ecolo= new Ecologie($this->conteneur); |
$this->Ethno= new Ethnobotanique($this->conteneur); |
$this->Classi= new Classification($this->conteneur); |
$this->Illus = new Illustrations($this->conteneur); |
$this->Nomen = new Nomenclature($this->conteneur); |
$this->Stat = new Statut($this->conteneur); |
$this->Biblio= new Bibliographie($this->conteneur); |
$this->Reparti= new Repartition($this->conteneur); |
$this->piedepage = Config::get('chemin_modules').'pdf_export/squelettes/footer.html'; |
} |
|
|
private function capturerParametres() { |
if (isset($_GET['num_nom'])) { |
$this->parametres['num_nom'] = $_GET['num_nom']; |
} |
if (isset($_GET['nom'])) { |
$this->parametres['nom'] = $_GET['nom']; |
} |
if (isset($_GET['type_nom'])) { |
$this->parametres['type_nom'] = $_GET['type_nom']; |
} |
if (isset($_GET['referentiel'])) { |
$this->parametres['referentiel'] = $_GET['referentiel']; |
} |
|
if (isset($_GET['niveau'])) { |
Registre::set('parametres.niveau', $_GET['niveau']); |
} |
if (isset($_GET['onglet'])) { |
$this->onglet = $_GET['onglet']; |
} |
} |
|
private function capturerParametresFormulaire() { |
if (!empty($_POST['bloc'])) { |
$this->blocs = $_POST['bloc']; |
} else { |
$this->blocs = array('description', 'ecologie', 'ethnobotanique', |
'statuts', 'illustrations', 'bibliographie', |
'classification', 'repartition', 'nomenclature'); |
} |
} |
|
public function executerActionParDefaut() { |
$this->executerPdfExport(); |
} |
|
public function executerPdfExport(){ |
$this->capturerParametresFormulaire(); |
$donnees = $this->obtenirDonnees(); |
$this->construireHtml($donnees); |
$this->transformerHtmlEnPdf(); |
$this->envoyerPdfAuNavigateur(); |
} |
|
|
private function construireHtml($donnees) { |
$this->html = $this->getVue('pdf_header.tpl.html', $donnees); |
foreach ($this->blocs as $bloc) { |
$this->ajouterHtml($bloc, $donnees); |
} |
$this->html .= '</body></html>'; |
} |
|
|
private function ajouterHtml($bloc, $donnees) { |
if (!empty($donnees[$bloc])) { |
$this->html .= $this->getVue('pdf_'.$bloc, $donnees); |
} |
} |
|
//++-------------------------------------récupération des données-----------------------------------++ |
|
private function obtenirDonnees() { |
$donnees = array(); |
$donnees['donnees']['nom'] = $this->parametres['nom']; |
$donnees['description'] = $this->Desc->obtenirDonnees(); |
$donnees['ecologie'] = $this->Ecolo->obtenirDonnees(); |
$donnees['statuts'] = $this->Stat->obtenirDonnees(); |
$donnees['ethnobotanique'] = $this->Ethno->obtenirDonnees(); |
$donnees['classification'] = $this->Classi->obtenirDonnees(); |
$donnees['illustrations'] = $this->Illus->obtenirDonnees(); |
$donnees['nomenclature'] = $this->Nomen->obtenirDonnees(); |
$donnees['repartition'] = $this->Reparti->obtenirDonnees(); |
$donnees['repartition']['min'] = $this->Reparti->getBloc(); |
$donnees['bibliographie'] = $this->Biblio->obtenirDonnees(); |
return $donnees; |
} |
|
//++ ------------------------------------------------export en pdf--------------------------------------++ |
|
private function envoyerPdfAuNavigateur() { |
header('Content-type: application/pdf'); |
header('Content-Disposition: attachment; filename="'.$this->parametres['nom'].'.pdf"'); |
readfile($this->fichier_pdf); |
} |
|
|
|
//version WKHTMLtoPDF en ligne de commande |
private function transformerHtmlEnPdf() { |
//il peut y avoir des pdfs differents pour une même fiche (on peut choisir ses parties) |
$time = $_SERVER['REQUEST_TIME'] ; |
$fichier_html = $this->chemin_pdf.''.str_replace(' ','_',$this->parametres['nom']).'-'.$time.'.html'; |
$this->fichier_pdf = $this->chemin_pdf.''.str_replace(' ','_',$this->parametres['nom']).'-'.$time.'.pdf'; |
$nom = $this->parametres['nom']; |
file_put_contents($fichier_html, $this->html); |
$commande = |
" {$this->wkhtml} --replace 'nom' '$nom' --footer-html '{$this->piedepage}' --encoding utf-8 $fichier_html $this->fichier_pdf 2>&1"; |
$debug = exec($commande); |
//echo $debug; |
} |
|
|
|
|
|
} |
|
?> |