Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 680 | Rev 685 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
652 mathilde 1
<?php
2
/**
3
 * Classe PdfExport, réalise des exportations pdf des fiches de taxons.
664 mathilde 4
 * Les fonctionnalités proposées sont l'export de toutes les parties de la fiche pdf
5
 * ou bien des parties choisies.
6
 * (voir le squelette fiche_pdf_lien.tpl.html pour le formulaire dans le module fiche.)
7
 *
8
 * manuel wkhtmltopdf  : http://madalgo.au.dk/~jakobt/wkhtmltoxdoc/wkhtmltopdf_0.10.0_rc2-doc.html
9
 * pour changer de librairie : changer la fonction transformerHtmlEnPdf()
652 mathilde 10
 *
11
 * @category php 5.2
12
 * @package		eflore-consultation
13
 * @author	Mathilde Salthun-Lassalle <mathilde@tela-botanica.org>
14
 * @copyright	2012 Tela-Botanica
15
 * @license	http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
16
 * @license	http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
17
 * @version		$Id$
18
 *
664 mathilde 19
 *
652 mathilde 20
 */
21
 
22
require_once( Config::get('chemin_modules').'fiche/formateurs/Description.php');
23
require_once( Config::get('chemin_modules').'fiche/formateurs/Ecologie.php');
24
require_once( Config::get('chemin_modules').'fiche/formateurs/Classification.php');
25
require_once( Config::get('chemin_modules').'fiche/formateurs/Bibliographie.php');
26
require_once( Config::get('chemin_modules').'fiche/formateurs/Ethnobotanique.php');
27
require_once( Config::get('chemin_modules').'fiche/formateurs/Illustrations.php');
28
require_once( Config::get('chemin_modules').'fiche/formateurs/Nomenclature.php');
29
require_once( Config::get('chemin_modules').'fiche/formateurs/Repartition.php');
30
require_once( Config::get('chemin_modules').'fiche/formateurs/Statut.php');
31
 
32
class PdfExport extends aControleur {
33
 
34
 
35
	private $Conteneur;
36
	private $parametres = array();
37
	private $chemin_pdf;
38
	private $html;
39
	private $wkhtml;
40
	private $piedepage;
41
	private $fichier_pdf;
42
	private $blocs = array();
678 mathilde 43
	private $nom_retenu;
660 mathilde 44
 
652 mathilde 45
	private $Desc;
46
	private $Ecolo;
47
	private $Ethno;
48
	private $Classi;
49
	private $Illus;
50
	private $Nomen;
51
	private $Reparti;
52
	private $Stat;
53
	private $Biblio;
54
 
55
 
56
	public function initialiser() {
57
		$this->capturerParametres();
58
		$this->conteneur = new Conteneur($this->parametres);
59
		$this->chemin_pdf = Config::get('dossier_pdf');
60
		$this->wkhtml = Config::get('WKHTMLTOPDF');
61
		$this->Desc = new Description($this->conteneur);
660 mathilde 62
		$this->Ecolo = new Ecologie($this->conteneur);
63
		$this->Ethno = new Ethnobotanique($this->conteneur);
64
		$this->Classi = new Classification($this->conteneur);
652 mathilde 65
		$this->Illus = new Illustrations($this->conteneur);
66
		$this->Nomen = new Nomenclature($this->conteneur);
67
		$this->Stat = new Statut($this->conteneur);
660 mathilde 68
		$this->Biblio = new Bibliographie($this->conteneur);
69
		$this->Reparti = new Repartition($this->conteneur);
652 mathilde 70
		$this->piedepage = Config::get('chemin_modules').'pdf_export/squelettes/footer.html';
681 mathilde 71
		$this->nom_retenu = $this->conteneur->getNomCourant()->getNomRetenu()->get('nom_sci');
660 mathilde 72
		}
652 mathilde 73
 
74
 
75
	private function capturerParametres() {
76
		if (isset($_GET['num_nom'])) {
77
			$this->parametres['num_nom'] = $_GET['num_nom'];
78
		}
79
		if (isset($_GET['nom'])) {
80
			$this->parametres['nom'] = $_GET['nom'];
81
		}
82
		if (isset($_GET['type_nom'])) {
83
			$this->parametres['type_nom'] = $_GET['type_nom'];
84
		}
85
		if (isset($_GET['referentiel'])) {
86
			$this->parametres['referentiel'] = $_GET['referentiel'];
87
		}
88
 
89
		if (isset($_GET['niveau'])) {
90
			Registre::set('parametres.niveau', $_GET['niveau']);
91
		}
92
		if (isset($_GET['onglet'])) {
93
			$this->onglet = $_GET['onglet'];
94
		}
95
	}
96
 
97
	private function capturerParametresFormulaire() {
98
		if (!empty($_POST['bloc'])) {
99
			$this->blocs = $_POST['bloc'];
100
		} else {
101
			$this->blocs = array('description', 'ecologie', 'ethnobotanique',
102
								'statuts', 'illustrations', 'bibliographie',
103
								'classification', 'repartition', 'nomenclature');
104
		}
105
	}
106
 
107
	public function executerActionParDefaut() {
108
		$this->executerPdfExport();
109
	}
110
 
111
	public function executerPdfExport(){
112
			$this->capturerParametresFormulaire();
113
			$donnees = $this->obtenirDonnees();
114
			$this->construireHtml($donnees);
115
			$this->transformerHtmlEnPdf();
116
			$this->envoyerPdfAuNavigateur();
117
	}
118
 
119
 
120
	private function construireHtml($donnees) {
681 mathilde 121
		$this->html = $this->getVue('pdf_header', $donnees);
652 mathilde 122
		foreach ($this->blocs as $bloc) {
123
			$this->ajouterHtml($bloc, $donnees);
124
		}
125
		$this->html .= '</body></html>';
126
	}
127
 
128
 
129
	private function ajouterHtml($bloc, $donnees) {
130
		if (!empty($donnees[$bloc])) {
131
			$this->html .= $this->getVue('pdf_'.$bloc, $donnees);
132
		}
133
	}
134
 
135
	//++-------------------------------------récupération des données-----------------------------------++
136
 
137
	private function obtenirDonnees() {
138
		$donnees = array();
678 mathilde 139
		$donnees['donnees_pdf'] = array('nom' => $this->nom_retenu,
660 mathilde 140
									'chemin_css' => Config::get('url_css_pdf'));
652 mathilde 141
		$donnees['description'] = $this->Desc->obtenirDonnees();
142
		$donnees['ecologie'] = $this->Ecolo->obtenirDonnees();
660 mathilde 143
		$donnees['ecologie']['legende_eco'] = Config::get('chemin_images').'legende_formes.png';
652 mathilde 144
		$donnees['statuts'] = $this->Stat->obtenirDonnees();
145
		$donnees['ethnobotanique'] = $this->Ethno->obtenirDonnees();
146
		$donnees['classification'] = $this->Classi->obtenirDonnees();
147
		$donnees['illustrations'] = $this->Illus->obtenirDonnees();
148
		$donnees['nomenclature'] = $this->Nomen->obtenirDonnees();
149
		$donnees['repartition'] = $this->Reparti->obtenirDonnees();
150
		$donnees['repartition']['min'] = $this->Reparti->getBloc();
151
		$donnees['bibliographie'] = $this->Biblio->obtenirDonnees();
672 mathilde 152
		$donnees['premier'] = $this->blocs[0];// pour page-break : éviter 1ere page vide si bloc trop long
652 mathilde 153
		return $donnees;
154
	}
155
 
156
 //++ ------------------------------------------------export en pdf--------------------------------------++
157
 
664 mathilde 158
 
652 mathilde 159
	private function envoyerPdfAuNavigateur() {
160
		header('Content-type: application/pdf');
679 mathilde 161
		header('Content-Disposition: attachment; filename="'.$this->nom_retenu.'.pdf"');
652 mathilde 162
		readfile($this->fichier_pdf);
664 mathilde 163
		unlink($this->fichier_html);
164
		unlink($this->fichier_pdf);
652 mathilde 165
	}
166
 
167
 
168
 
169
	//version WKHTMLtoPDF en ligne de commande
170
	private function transformerHtmlEnPdf() {
171
		$time = $_SERVER['REQUEST_TIME'] ;
679 mathilde 172
		$this->fichier_html = $this->chemin_pdf.''.str_replace(' ','_',$this->nom_retenu).'-'.$time.'.html';
173
		$this->fichier_pdf = $this->chemin_pdf.''.str_replace(' ','_',$this->nom_retenu).'-'.$time.'.pdf';
678 mathilde 174
		$nom = $this->nom_retenu;
664 mathilde 175
		file_put_contents($this->fichier_html, $this->html);
652 mathilde 176
		$commande =
680 mathilde 177
			" {$this->wkhtml}  --replace 'nom' '$nom' --footer-html '{$this->piedepage}' --encoding utf-8  {$this->fichier_html} {$this->fichier_pdf} 2>&1";
652 mathilde 178
		$debug = exec($commande);
179
		//echo $debug;
180
	}
181
 
182
 
183
 
184
 
185
 
186
}
187
 
188
?>