diff --git a/html/js/scripts.js b/html/js/scripts.js
index d6a4a9d20..2057f2635 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 d3c5abbaf..2c7a8dc40 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;
}
-
- /* ! upload
- * \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
- *
- * \return
+
+ /**
+ * @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();
+
+ }
+
+ /**
+ * @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
+ *
+ */
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 1fd7d71b1..1924386d4 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 9d59d6851..99d70b320 100644
--- a/include/template/detail-action.php
+++ b/include/template/detail-action.php
@@ -490,6 +490,18 @@ for ($i=0;$i
+"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;?>