Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 664 | Rev 674 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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