pour les pdfs, on passe par une action afin de pouvoir avoir tous les

cas possibles. Le gros problème a été de gérer la génération du pdf et
surtout son telechargement.
la solution :
- le fichier action cree le pdf et le place dans
  IMG/gamutable_pdf/xxxxxxxxxx.mdf (nom du fichier hashé)
- on ajoute un cron dans 20 secondes pour supprimer ce fichier
- TODO, mainteannt jouer avec l'action !
This commit is contained in:
Christophe 2022-09-27 15:01:52 +02:00
parent 0557915e61
commit 8ba264d69b
8 changed files with 172 additions and 54 deletions

52
action/pdf_gamutable.php Normal file
View file

@ -0,0 +1,52 @@
<?php
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
function action_pdf_gamutable_dist() {
include_spip('inc/autoriser');
if (! autoriser('generer', 'gamutablepdf')) {
return false;
}
$fichierpdf = _request('fichierpdf') ?? '';
$namepdf = _request('namepdf') ?? $fichierpdf;
$header = _request('header') ?? [];
$Tdata = _request('data') ?? [];
if (empty($header) or empty($fichierpdf)) {
exit;
}
$header = array_values($header);
$Tcles = [];
if (!empty($Tdata)) {
foreach ($Tdata as $d) {
$Tcles[] = $d['html']['id'];
}
}
if (empty($Tcles)) {
$fond = recuperer_fond('gamutable_pdf/' . $fichierpdf);
} else {
$fond = recuperer_fond('gamutable_pdf/' . $fichierpdf,['ids' => implode(',', $Tcles)]);
}
include_spip('spipdf_options');
include_spip('inc/spipdf');
$a = spipdf_html2pdf($fond);
$dir = sous_repertoire(_DIR_IMG . 'pdfgamutable');
$chemin = $dir . md5($namepdf) . '.pdf' ;
file_put_contents($chemin, $a);
$id_job = job_queue_add(
'gamutable_clean_pdf',
'Gamutable nettoyer pdf',
[$chemin],
'inc/gamutable_clean_pdf',
false,
time() + 20
);
echo url_absolue($chemin);
}

View file

@ -24,7 +24,10 @@ function autoriser_gamutable_purger_dist($faire, $type, $id, $qui, $opt) {
return autoriser('webmestre');
}
function autoriser_gamutablepdf_generer_dist($faire, $type, $id, $qui, $opt) {
return intval($qui['id_auteur']);
}
function autoriser_gamutable_modifier_dist($faire, $type, $id, $qui, $opt) {
return true;
}

View file

@ -13,6 +13,7 @@ if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
function gamutable_fermer_modalbox($id_objet = 9999999999){
$html = <<<EOJS
<script type="text/javascript">

View file

@ -0,0 +1,9 @@
<?php
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
function gamutable_clean_pdf($fichier) {
unlink(_DIR_RACINE . $fichier);
}

0
inc/toto.txt Executable file
View file

View file

@ -2,6 +2,7 @@
<link rel="stylesheet" href="[(#CHEMIN{css/vue-next-select.css}|compacte|timestamp)]" type="text/css" media="screen" title="no title" charset="utf-8">
[(#SET{sort_asc,[(#CHEMIN{img/sprite_gamutable.svg})#sort_asc]})]
[(#SET{sort_desc,[(#CHEMIN{img/sprite_gamutable.svg})#sort_desc]})]
[(#SET{pdfuri,#VAL{pdf_gamutable}|generer_url_action{"", 1}})]
<span class="crayon gamutable-yyyy-nn"></span>
<div id="app">
<div class="container_un">
@ -11,12 +12,13 @@
[<span class="titre titreGamutableUn">(#ENV{titreGamutableUn})</span>]
<mon-tableau
apiuri="[(#ENV{apiuri,spip.php?page=json_gamutable.json})]"
pdfuri="[(#ENV{pdfuri})]"
pdfuri="#GET{pdfuri}"
:tparpage="#ENV{tparpage, [10, 20, 50, 'Tous']}"
champcsv="#ENV{champcsv,html}"
delimitercsv="#ENV{delimitercsv,','}"
namecsv="#ENV{namecsv}"
namepdf="#ENV{namepdf}"
fichierpdf="#ENV{fichierpdf}"
urlvuebloc="[(#ENV{urlvuebloc})]"
url_sort_asc="#ENV{sort_asc,#GET{sort_asc}}"
url_sort_desc="#ENV{sort_desc,#GET{sort_desc}}"
@ -40,12 +42,12 @@
[<span class="titre titreGamutableDeux">(#ENV{titreGamutableDeux})</span>]
<mon-tableau
apiuri="[(#ENV{apiuri_deux})]"
pdfuri="[(#ENV{pdfuri_deux})]"
pdfuri="#GET{pdfuri}"
:tparpage="#ENV{tparpage_deux, [10, 20, 50, 'Tous']}"
champcsv="[(#ENV{champcsv_deux, #ENV{champcsv,html}})]"
delimitercsv="[(#ENV{delimitercsv_deux, #ENV{delimitercsv,','}})]"
namecsv="[(#ENV{namecsv_deux, #ENV{namecsv}})]"
namepdf="[(#ENV{namepdf_deux, #ENV{namepdf}})]"
namepdf="#ENV{namepdf_deux}"
fichierpdf="[(#ENV{fichierpdf_deux, #ENV{fichierpdf}})]"
urlvuebloc="[(#ENV{urlvuebloc_deux})]"
url_sort_asc="[(#ENV{sort_asc_deux, #ENV{sort_asc,#GET{sort_asc}}})]"

View file

@ -179,6 +179,12 @@ let monTableau = {
pdfuri: {
type: String,
},
namepdf: {
type: String,
},
fichierpdf: {
type: String,
},
champcsv: {
type: String,
},
@ -191,9 +197,6 @@ let monTableau = {
namepdf: {
type: String,
},
fichierpdf: {
type: String,
},
url_sort_asc: {
type: String,
},
@ -703,8 +706,33 @@ let monTableau = {
}
}
},
genererPDF() {
window.location.assign(this.pdfuri);
genererPDF(quoi = 'tableau') {
const data = {
fichierpdf: this.fichierpdf,
namepdf: this.namepdf,
header: this.header,
data: this[quoi],
};
let req = $.ajax({
url: this.pdfuri,
type: 'POST',
dataType: 'text',
data: data,
});
let that = this;
req.done(function (urlpdf) {
if (urlpdf) {
that.navigate(urlpdf, true);
}
});
},
navigate(href, newTab) {
var a = document.createElement('a');
a.href = href;
if (newTab) {
a.setAttribute('target', '_blank');
}
a.click();
},
exportCSV(quoi = 'tableau') {
let $csv = [];
@ -790,7 +818,7 @@ let monTableau = {
<i class="fas fas fa-file-excel" aria-hidden="true" alt="csv"></i>
</button>
<button class="btn" type="button" @click.stop="genererPDF()"
v-show="this.pdfuri"
v-show="this.fichierpdf"
title="Générer le PDF du tableau complet"
>
<i class="fas fa-file-pdf rouge" aria-hidden="true" alt="pdf"></i>

File diff suppressed because one or more lines are too long