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