Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 664 | Rev 674 | 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();
660 mathilde 43
 
652 mathilde 44
	private $Desc;
45
	private $Ecolo;
46
	private $Ethno;
47
	private $Classi;
48
	private $Illus;
49
	private $Nomen;
50
	private $Reparti;
51
	private $Stat;
52
	private $Biblio;
53
 
54
 
55
	public function initialiser() {
56
		$this->capturerParametres();
57
		$this->conteneur = new Conteneur($this->parametres);
58
		$this->chemin_pdf = Config::get('dossier_pdf');
59
		$this->wkhtml = Config::get('WKHTMLTOPDF');
60
		$this->Desc = new Description($this->conteneur);
660 mathilde 61
		$this->Ecolo = new Ecologie($this->conteneur);
62
		$this->Ethno = new Ethnobotanique($this->conteneur);
63
		$this->Classi = new Classification($this->conteneur);
652 mathilde 64
		$this->Illus = new Illustrations($this->conteneur);
65
		$this->Nomen = new Nomenclature($this->conteneur);
66
		$this->Stat = new Statut($this->conteneur);
660 mathilde 67
		$this->Biblio = new Bibliographie($this->conteneur);
68
		$this->Reparti = new Repartition($this->conteneur);
652 mathilde 69
		$this->piedepage = Config::get('chemin_modules').'pdf_export/squelettes/footer.html';
660 mathilde 70
		}
652 mathilde 71
 
72
 
73
	private function capturerParametres() {
74
		if (isset($_GET['num_nom'])) {
75
			$this->parametres['num_nom'] = $_GET['num_nom'];
76
		}
77
		if (isset($_GET['nom'])) {
78
			$this->parametres['nom'] = $_GET['nom'];
79
		}
80
		if (isset($_GET['type_nom'])) {
81
			$this->parametres['type_nom'] = $_GET['type_nom'];
82
		}
83
		if (isset($_GET['referentiel'])) {
84
			$this->parametres['referentiel'] = $_GET['referentiel'];
85
		}
86
 
87
		if (isset($_GET['niveau'])) {
88
			Registre::set('parametres.niveau', $_GET['niveau']);
89
		}
90
		if (isset($_GET['onglet'])) {
91
			$this->onglet = $_GET['onglet'];
92
		}
93
	}
94
 
95
	private function capturerParametresFormulaire() {
96
		if (!empty($_POST['bloc'])) {
97
			$this->blocs = $_POST['bloc'];
98
		} else {
99
			$this->blocs = array('description', 'ecologie', 'ethnobotanique',
100
								'statuts', 'illustrations', 'bibliographie',
101
								'classification', 'repartition', 'nomenclature');
102
		}
103
	}
104
 
105
	public function executerActionParDefaut() {
106
		$this->executerPdfExport();
107
	}
108
 
109
	public function executerPdfExport(){
110
			$this->capturerParametresFormulaire();
111
			$donnees = $this->obtenirDonnees();
112
			$this->construireHtml($donnees);
113
			$this->transformerHtmlEnPdf();
114
			$this->envoyerPdfAuNavigateur();
115
	}
116
 
117
 
118
	private function construireHtml($donnees) {
119
		$this->html = $this->getVue('pdf_header.tpl.html', $donnees);
120
		foreach ($this->blocs as $bloc) {
121
			$this->ajouterHtml($bloc, $donnees);
122
		}
123
		$this->html .= '</body></html>';
124
	}
125
 
126
 
127
	private function ajouterHtml($bloc, $donnees) {
128
		if (!empty($donnees[$bloc])) {
129
			$this->html .= $this->getVue('pdf_'.$bloc, $donnees);
130
		}
131
	}
132
 
133
	//++-------------------------------------récupération des données-----------------------------------++
134
 
135
	private function obtenirDonnees() {
136
		$donnees = array();
660 mathilde 137
		$donnees['donnees'] = array('nom' => $this->parametres['nom'],
138
									'chemin_css' => Config::get('url_css_pdf'));
652 mathilde 139
		$donnees['description'] = $this->Desc->obtenirDonnees();
140
		$donnees['ecologie'] = $this->Ecolo->obtenirDonnees();
660 mathilde 141
		$donnees['ecologie']['legende_eco'] = Config::get('chemin_images').'legende_formes.png';
652 mathilde 142
		$donnees['statuts'] = $this->Stat->obtenirDonnees();
143
		$donnees['ethnobotanique'] = $this->Ethno->obtenirDonnees();
144
		$donnees['classification'] = $this->Classi->obtenirDonnees();
145
		$donnees['illustrations'] = $this->Illus->obtenirDonnees();
146
		$donnees['nomenclature'] = $this->Nomen->obtenirDonnees();
147
		$donnees['repartition'] = $this->Reparti->obtenirDonnees();
148
		$donnees['repartition']['min'] = $this->Reparti->getBloc();
149
		$donnees['bibliographie'] = $this->Biblio->obtenirDonnees();
672 mathilde 150
		$donnees['premier'] = $this->blocs[0];// pour page-break : éviter 1ere page vide si bloc trop long
652 mathilde 151
		return $donnees;
152
	}
153
 
154
 //++ ------------------------------------------------export en pdf--------------------------------------++
155
 
664 mathilde 156
 
652 mathilde 157
	private function envoyerPdfAuNavigateur() {
158
		header('Content-type: application/pdf');
159
		header('Content-Disposition: attachment; filename="'.$this->parametres['nom'].'.pdf"');
160
		readfile($this->fichier_pdf);
664 mathilde 161
		unlink($this->fichier_html);
162
		unlink($this->fichier_pdf);
652 mathilde 163
	}
164
 
165
 
166
 
167
	//version WKHTMLtoPDF en ligne de commande
168
	private function transformerHtmlEnPdf() {
169
		$time = $_SERVER['REQUEST_TIME'] ;
664 mathilde 170
		$this->fichier_html = $this->chemin_pdf.''.str_replace(' ','_',$this->parametres['nom']).'-'.$time.'.html';
652 mathilde 171
		$this->fichier_pdf = $this->chemin_pdf.''.str_replace(' ','_',$this->parametres['nom']).'-'.$time.'.pdf';
172
		$nom = $this->parametres['nom'];
664 mathilde 173
		file_put_contents($this->fichier_html, $this->html);
652 mathilde 174
		$commande =
664 mathilde 175
			" {$this->wkhtml}  --replace 'nom' '$nom' --footer-html '{$this->piedepage}' --encoding utf-8  $this->fichier_html $this->fichier_pdf 2>&1";
652 mathilde 176
		$debug = exec($commande);
177
		//echo $debug;
178
	}
179
 
180
 
181
 
182
 
183
 
184
}
185
 
186
?>