Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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

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