Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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