noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
export_suppl-document.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of NOALYSS.
5 *
6 * NOALYSS is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * NOALYSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with NOALYSS; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19*/
20// Copyright Author Dany De Bontridder danydb@aevalys.eu 22/10/23
21
22
23/**
24 * @file
25 * @brief download document
26 */
27if ( ! defined ('ALLOWED')) die (_('Non autorisé'));
28
29include_once NOALYSS_INCLUDE.'/lib/ac_common.php';
31
32try
33{
34 $js_id=$http->get('js_id',"number");
35 $operation_id=$http->get("operation_id",'number',0);
36}
37catch (Exception $exc)
38{
39 record_log($exc);
40 return;
41}
42$cn=Dossier::connect();
43
44//------------------------------------------------
45// Download only one document
46//------------------------------------------------
47if ( $js_id > 0)
48{
49 $jrn_def_id=$cn->get_value("select jr_def_id from jrn_sup_document join jrn using (jr_id) where js_id=$1",array($js_id));
50
51 global $g_user;
52 if ($jrn_def_id =="" || $g_user->check_jrn($jrn_def_id) == 'X' )
53 {
54 /* Cannot Access */
55 NoAccess();
56 exit -1;
57 }
58
59 $jrn=new Jrn_Sup_Document_SQL($cn,$js_id);
60 $cn->start();
61 ini_set('zlib.output_compression','Off');
62 header("Pragma: public");
63 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
64 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
65 header("Cache-Control: must-revalidate");
66 header('Content-type: '.$jrn->js_mimetype);
67 header('Content-Disposition: attachment;filename="'.$jrn->js_filename.'"',FALSE);
68 header("Accept-Ranges: bytes");
69 echo $cn->lo_read($jrn->js_lob);
70 $cn->commit();
71 return;
72}
73//------------------------------------------------
74// Download all documents
75//------------------------------------------------
76if ( $operation_id > 0)
77{
78 $jrn_def_id=$cn->get_value("select jr_def_id from jrn where jr_id=$1",array($operation_id));
79
80 global $g_user;
81 if ($jrn_def_id =="" || $g_user->check_jrn($jrn_def_id) == 'X' )
82 {
83 /* Cannot Access */
84 NoAccess();
85 exit -1;
86 }
87 $jr_internal=$cn->get_value("select jr_internal from jrn where jr_id=$1",array($operation_id));
88
89 try {
90 $cn->start();
91 // find all the documents for this operation
92 $a_file=$cn->get_array("select js_lob,js_filename from jrn_sup_document where jr_id=$1",
94 // save them into a temp folder
95 if ( count ($a_file) == 0 ) {
96 // @TODO send an empty file
97 return;
98 }
99 $a_file_dwn=array();
100 $store = tempnam($_ENV['TMP'], 'pdf_');
101 unlink($store);
102 mkdir($store);
103 $nb_file=count($a_file);
104 for($i=0;$i < $nb_file;$i++)
105 {
106 $filename=sprintf("%s".DIRECTORY_SEPARATOR."%s",
107 $store,
108 $a_file[$i]['js_filename']);
109
110 // avoid to overwrite a previous file with same name
111 if (file_exists($filename)) {
112 $dup=1;
113 do {
114 $filename=sprintf("%s".DIRECTORY_SEPARATOR."%s-%s",
115 $store,
116 $dup,
117 $a_file[$i]['js_filename']);
118 $dup++;
119 }while ( file_exists($filename));
120
121 }
122 $cn->lo_export($a_file[$i]['js_lob'], $filename);
123 $a_file_dwn[]=$filename;
124
125 }
126 $cn->commit();
127 // zip the folder
128 $zip = new Zip_Extended();
129 $zip_file=sprintf("%s".DIRECTORY_SEPARATOR."%s.zip"
130 ,$store
131 ,$jr_internal);
132
133 chdir($store);
134 $res=$zip->open($zip_file, ZipArchive::CREATE);
135 foreach ($a_file_dwn as $item)
136 {
137 $zip->addFile(basename($item));
138 }
139 $zip->close();
140 // send the folder to browser
141 header('Content-Type: application/zip');
142 header('Content-Disposition: attachment; filename="document-'.$jr_internal.'.zip"');
143 header('Cache-Control: private, max-age=0, must-revalidate');
144 header('Pragma: public');
145 echo file_get_contents($zip_file);
146
147 } catch (Exception $exc) {
148 record_log($exc);
149 }
150
151}
NoAccess($js=1)
Echo no access and stop.
record_log($p_message)
Record an error message into the log file of the server or in the log folder of NOALYSS Record also t...
global $g_user
if no group available , then stop
_("actif, passif,charge,...")
manage the http input (get , post, request) and extract from an array
abstract of the table public.jrn_sup_document
extends the Zip object
for($e=0; $e< count($afiche); $e++) exit