[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Noalyss-commit] [noalyss] 168/173: Task #1911: FOLLOW : télécharger tou
From: |
Dany De Bontridder |
Subject: |
[Noalyss-commit] [noalyss] 168/173: Task #1911: FOLLOW : télécharger toutes les documents en une fois |
Date: |
Mon, 22 Mar 2021 12:59:25 -0400 (EDT) |
sparkyx pushed a commit to branch master
in repository noalyss.
commit c38af96905bc45019d58cb5350d44f7d3b5edb96
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Sat Mar 20 13:33:33 2021 +0100
Task #1911: FOLLOW : télécharger toutes les documents en une fois
---
html/js/scripts.js | 17 ++++++-
include/class/document.class.php | 95 ++++++++++++++++++++++++++++++++++----
include/export/export_document.php | 33 ++++++++++++-
include/template/detail-action.php | 12 +++++
4 files changed, 146 insertions(+), 11 deletions(-)
diff --git a/html/js/scripts.js b/html/js/scripts.js
index d6a4a9d..2057f26 100644
--- a/html/js/scripts.js
+++ b/html/js/scripts.js
@@ -2984,8 +2984,11 @@ function show_tabs(a_tabs, p_display_tab)
{
try
{
- if (a_tabs.length == 0)
- trow('a_tabs in empty');
+ if (a_tabs.length == 0) {
+ console.error('a_tabs in empty');
+ throw ("a_tabs empty");
+ return;
+ }
var i = 0;
for (i = 0; i < a_tabs.length; i++) {
$(a_tabs[i]).hide();
@@ -4041,4 +4044,14 @@ function full_size(p_div) {
div_dom.addClassName('fullsize');$('size_'+p_div).innerHTML='';
}
+}
+
+/**
+ * @brief download a document from an url
+ */
+function download_document(p_url)
+{
+ waiting_box();
+ document.location=p_url;
+ remove_waiting_box();
}
\ No newline at end of file
diff --git a/include/class/document.class.php b/include/class/document.class.php
index d3c5abb..2c7a8dc 100644
--- a/include/class/document.class.php
+++ b/include/class/document.class.php
@@ -58,9 +58,9 @@ class Document
$this->counter=0;
}
- /* !\brief insert a minimal document and set the d_id
+ /**
+ * @brief insert a minimal document and set the d_id
*/
-
function blank()
{
$this->d_id=$this->db->get_next_seq("document_d_id_seq");
@@ -76,7 +76,7 @@ class Document
}
/**
- * Insert the receipt number into the filename , each generated file
+ * @brief Insert the receipt number into the filename , each generated file
* will have the name of the template (model) + receipt number)
* @param type $pj the receipt number
* @param type $filename the name of the file
@@ -352,15 +352,93 @@ class Document
$this->db->commit();
return 0;
}
+
+ /**
+ * @brief Download all documents in a ZIP files. The parameters is an
array of Document, see
+ * DOcument::get_all
+ *
+ * @param array of Document $aDocument
+ *
+ * @see Document::get_all()
+ */
+ function download($aDocument)
+ {
+
+ if (empty($aDocument)||is_array($aDocument)==false)
+ {
+ throw new Exception("Document.download expects an array");
+ }
+ // make a temp folder
+ $dirname=tempnam($_ENV['TMP'], 'document_dwnall');
+ unlink($dirname);
+ mkdir($dirname);
+
+ // download each file into that folder
+ $nb_document=count($aDocument);
+ $nCopy=0;
+
+ // start a transaction to be able to export LOB
+ $this->db->start();
+ for ($i=0; $i<$nb_document; $i++)
+ {
+ // check that aDocument elt is a document object
+ if ( ! $aDocument[$i] instanceof Document ) {
+ throw new Exception("Document.download.2 element is not a
document object");
+ }
+ $filename=$dirname.DIRECTORY_SEPARATOR.$aDocument[$i]->d_filename;
+ // if file exists then add a number
+ if (file_exists($filename))
+ {
+
+ while (true)
+ {
+ $nCopy++;
+
$filename=$dirname.DIRECTORY_SEPARATOR.$nCopy."-".$aDocument[$i]->d_filename;
+ if (!file_exists($filename))
+ {
+ $nCopy=0;
+ break;
+ }
+ } // end while true
+ } // end if fileexist
+ // export file
+ $this->db->lo_export($aDocument[$i]->d_lob,$filename);
+ } // end for $i
+ // make a large PDF and send it
+ $zip=new Zip_Extended();
+ $name="document-".date ("Ymd-His").".zip";
+ if ( $zip->open($_ENV['TMP'].DIRECTORY_SEPARATOR.$name ,
ZipArchive::CREATE) != true)
+ {
+ die("Cannot create zip file");
+ }
+ $zip->add_recurse_folder($dirname . "/");
+ $zip->close();
+ // send it to stdout
+ ini_set('zlib.output_compression', 'off');
+ header("Pragma: public");
+ header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
+ header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
+ header("Cache-Control: must-revalidate");
+ header('Content-type: zip/application');
+ header('Content-Disposition: attachment;filename="'.$name.'"', FALSE);
+ header("Accept-Ranges: bytes");
+ $file=fopen($_ENV['TMP'].DIRECTORY_SEPARATOR.$name, 'r');
+ while (!feof($file))
+ {
+ echo fread($file, 8192);
+ }
+ fclose($file);
+
+ $this->db->commit();
+
+ }
- /* ! upload
- * \brief upload a file into document
+ /**
+ * @brief upload a file into document
* all the needed data are in $_FILES we don't increment the seq
- * \param $p_file : array containing by default $_FILES
+ * @param $p_file : array containing by default $_FILES
*
- * \return
*/
-
function upload($p_ag_id)
{
// nothing to save
@@ -505,6 +583,7 @@ class Document
}
return $a;
}
+
/* !\brief Get complete all the data member thx info from the database
*/
diff --git a/include/export/export_document.php
b/include/export/export_document.php
index 1fd7d71..1924386 100644
--- a/include/export/export_document.php
+++ b/include/export/export_document.php
@@ -21,7 +21,12 @@
// Verify parameters
/**
* \file
- * \brief retrieve a document
+ * \brief retrieve a document. It received http variables :
+ * - a is the action : rm remove document, rmop: remove an operation :
rmcomment , remove a comment,
+ * rmaction remove an action,dwnall download all document
of an action into a zip
+ * - id number
+ * - ag_id action_gestion.ag_id
+ *
*/
if ( ! defined ('ALLOWED')) die (_('Non autorisé'));
@@ -31,6 +36,7 @@ require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
require_once NOALYSS_INCLUDE.'/lib/http_input.class.php';
$http=new HttpInput();
+// the parameter a is the action for the document,
$action = (isset($_REQUEST['a'])) ? $_REQUEST['a'] : 'sh';
$id=$http->request('id','number','0');
@@ -102,3 +108,28 @@ if ($action == 'rmaction')
header("Content-type: text/html; charset: utf8", true);
print $json;
}
+/**
+ * Download all document into a zip
+ */
+if ($action == 'dwnall') {
+ // existing action ?
+ if ($ag_id == 0) {
+ throw new Exception("Action inconnue");
+ }
+ // check that user can read
+ if ( $g_user->can_read_action($ag_id) == false
+ || $g_user->check_action(VIEWDOC) == 0)
+ {
+ throw new Exception ("not allowed");
+ }
+
+ // Retrieve all documents
+ $document=new Document($cn);
+ $aDocument=$document->get_all($ag_id);
+
+ // Download all of them
+ $document->download($aDocument);
+
+
+
+}
\ No newline at end of file
diff --git a/include/template/detail-action.php
b/include/template/detail-action.php
index 9d59d68..99d70b3 100644
--- a/include/template/detail-action.php
+++ b/include/template/detail-action.php
@@ -490,6 +490,18 @@ for ($i=0;$i<sizeof($aAttachedFile);$i++) :
endfor;
?>
</table>
+<?php if ( ! empty ($aAttachedFile)) :
+ /*** Propose to download all document in only one step */
+ $url="export.php?".http_build_query([
+ 'ac'=>"FOLLOW",
+ "act"=>"RAW:document",
+ "gDossier"=>Dossier::id(),
+ "d_id"=>0,
+ "ag_id"=>$this->ag_id,
+ "a"=>"dwnall"]);
+ echo HtmlInput::button_anchor(_("Télécharger toutes les documents"), "",
uniqid(),sprintf("onclick=\"download_document('%s')\"",$url));
+
+endif;?>
</div>
<script language="javascript">
function addFiles() {
- [Noalyss-commit] [noalyss] 148/173: Merge branch 'dev7400-1' into next-release-8, (continued)
- [Noalyss-commit] [noalyss] 148/173: Merge branch 'dev7400-1' into next-release-8, Dany De Bontridder, 2021/03/22
- [Noalyss-commit] [noalyss] 149/173: Merge branch 'enterprise' into entreprise, Dany De Bontridder, 2021/03/22
- [Noalyss-commit] [noalyss] 155/173: Merge branch 'master' into dev-8-bootstrap, Dany De Bontridder, 2021/03/22
- [Noalyss-commit] [noalyss] 156/173: rel8100 Merge branch 'master' into entreprise, Dany De Bontridder, 2021/03/22
- [Noalyss-commit] [noalyss] 157/173: Merge branch 'dev-8-bug-saldo-not-checked', Dany De Bontridder, 2021/03/22
- [Noalyss-commit] [noalyss] 161/173: Move CSS and start to integrate BootStrap, Dany De Bontridder, 2021/03/22
- [Noalyss-commit] [noalyss] 163/173: Move CSS and start to integrate BootStrap Add fonts, Dany De Bontridder, 2021/03/22
- [Noalyss-commit] [noalyss] 165/173: Currency : adapt test, Dany De Bontridder, 2021/03/22
- [Noalyss-commit] [noalyss] 166/173: BootStrap : set up + move CSS and font to their own folders, Dany De Bontridder, 2021/03/22
- [Noalyss-commit] [noalyss] 167/173: Task 0001912: Developpement DEBUG new system with level, Dany De Bontridder, 2021/03/22
- [Noalyss-commit] [noalyss] 168/173: Task #1911: FOLLOW : télécharger toutes les documents en une fois,
Dany De Bontridder <=
- [Noalyss-commit] [noalyss] 153/173: Improve scenario test, Dany De Bontridder, 2021/03/22
- [Noalyss-commit] [noalyss] 158/173: Merge branch 'dev8001', Dany De Bontridder, 2021/03/22
- [Noalyss-commit] [noalyss] 172/173: Erreur : fiche_attr , first param is a DatabaseCore object, Dany De Bontridder, 2021/03/22
- [Noalyss-commit] [noalyss] 173/173: if a document cannot be generate, a error message is displaid and the whole operation is not cancelled, Dany De Bontridder, 2021/03/22