Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 660 | Go to most recent revision | Details | 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();
38
 
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);
56
		$this->Ecolo= new Ecologie($this->conteneur);
57
		$this->Ethno= new Ethnobotanique($this->conteneur);
58
		$this->Classi= new Classification($this->conteneur);
59
		$this->Illus = new Illustrations($this->conteneur);
60
		$this->Nomen = new Nomenclature($this->conteneur);
61
		$this->Stat = new Statut($this->conteneur);
62
		$this->Biblio= new Bibliographie($this->conteneur);
63
		$this->Reparti= new Repartition($this->conteneur);
64
		$this->piedepage = Config::get('chemin_modules').'pdf_export/squelettes/footer.html';
65
	}
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();
132
		$donnees['donnees']['nom'] = $this->parametres['nom'];
133
		$donnees['description'] = $this->Desc->obtenirDonnees();
134
		$donnees['ecologie'] = $this->Ecolo->obtenirDonnees();
135
		$donnees['statuts'] = $this->Stat->obtenirDonnees();
136
		$donnees['ethnobotanique'] = $this->Ethno->obtenirDonnees();
137
		$donnees['classification'] = $this->Classi->obtenirDonnees();
138
		$donnees['illustrations'] = $this->Illus->obtenirDonnees();
139
		$donnees['nomenclature'] = $this->Nomen->obtenirDonnees();
140
		$donnees['repartition'] = $this->Reparti->obtenirDonnees();
141
		$donnees['repartition']['min'] = $this->Reparti->getBloc();
142
		$donnees['bibliographie'] = $this->Biblio->obtenirDonnees();
143
		return $donnees;
144
	}
145
 
146
 //++ ------------------------------------------------export en pdf--------------------------------------++
147
 
148
	private function envoyerPdfAuNavigateur() {
149
		header('Content-type: application/pdf');
150
		header('Content-Disposition: attachment; filename="'.$this->parametres['nom'].'.pdf"');
151
		readfile($this->fichier_pdf);
152
	}
153
 
154
 
155
 
156
	//version WKHTMLtoPDF en ligne de commande
157
	private function transformerHtmlEnPdf() {
158
		//il peut y avoir des pdfs differents pour une même fiche (on peut choisir ses parties)
159
		$time = $_SERVER['REQUEST_TIME'] ;
160
		$fichier_html = $this->chemin_pdf.''.str_replace(' ','_',$this->parametres['nom']).'-'.$time.'.html';
161
		$this->fichier_pdf = $this->chemin_pdf.''.str_replace(' ','_',$this->parametres['nom']).'-'.$time.'.pdf';
162
		$nom = $this->parametres['nom'];
163
		file_put_contents($fichier_html, $this->html);
164
		$commande =
165
			" {$this->wkhtml}  --replace 'nom' '$nom' --footer-html '{$this->piedepage}' --encoding utf-8  $fichier_html  $this->fichier_pdf 2>&1";
166
		$debug = exec($commande);
167
		//echo $debug;
168
	}
169
 
170
 
171
 
172
 
173
 
174
}
175
 
176
?>