line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package oEdtk::EDMS;
|
2
|
|
|
|
|
|
|
# Electronic Document Management (GED in french)
|
3
|
1
|
|
|
1
|
|
5
|
use strict;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use Exporter;
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
101
|
|
7
|
|
|
|
|
|
|
our $VERSION = 0.8035;
|
8
|
|
|
|
|
|
|
our @ISA = qw(Exporter);
|
9
|
|
|
|
|
|
|
our @EXPORT_OK = qw(
|
10
|
|
|
|
|
|
|
EDMS_edidx_build
|
11
|
|
|
|
|
|
|
EDMS_edidx_write
|
12
|
|
|
|
|
|
|
EDMS_idldoc_seqpg
|
13
|
|
|
|
|
|
|
EDMS_idx_create_csv
|
14
|
|
|
|
|
|
|
EDMS_import
|
15
|
|
|
|
|
|
|
EDMS_package
|
16
|
|
|
|
|
|
|
EDMS_prepare
|
17
|
|
|
|
|
|
|
EDMS_process
|
18
|
|
|
|
|
|
|
EDMS_process_zip
|
19
|
|
|
|
|
|
|
);
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# use File::Temp qw(tempdir);
|
22
|
1
|
|
|
1
|
|
7
|
use Archive::Zip qw(:ERROR_CODES);
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
170
|
|
23
|
1
|
|
|
1
|
|
5
|
use Cwd;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
75
|
|
24
|
1
|
|
|
1
|
|
7
|
use File::Basename;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
90
|
|
25
|
1
|
|
|
1
|
|
6
|
use File::Copy;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
50
|
|
26
|
1
|
|
|
1
|
|
1216
|
use Net::FTP;
|
|
1
|
|
|
|
|
57214
|
|
|
1
|
|
|
|
|
78
|
|
27
|
1
|
|
|
1
|
|
14
|
use oEdtk::Main;
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
36
|
|
28
|
1
|
|
|
1
|
|
6
|
use oEdtk::Config qw(config_read);
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
59
|
|
29
|
1
|
|
|
1
|
|
6
|
use oEdtk::DBAdmin qw(@INDEX_COLS);
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
142
|
|
30
|
1
|
|
|
1
|
|
6
|
use POSIX qw(strftime);
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
13
|
|
31
|
1
|
|
|
1
|
|
66
|
use Text::CSV;
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
12
|
|
32
|
1
|
|
|
1
|
|
4281
|
use XML::Writer;
|
|
1
|
|
|
|
|
24769
|
|
|
1
|
|
|
|
|
4798
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# use PDF; # ajouter dans les prerequis
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Utility function to construct filenames.
|
38
|
|
|
|
|
|
|
sub EDMS_idldoc_seqpg($$) {
|
39
|
0
|
|
|
0
|
0
|
|
my ($idldoc, $page) = @_;
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Modifié suite au problème de . dans le nom de fichier pour Docubase
|
42
|
|
|
|
|
|
|
# $idldoc =~ s/\./_/;
|
43
|
0
|
|
|
|
|
|
return sprintf("${idldoc}_%07d", $page);
|
44
|
|
|
|
|
|
|
}
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Package a DOC along with its index in a zip archive for later processing.
|
47
|
|
|
|
|
|
|
sub EDMS_prepare($$$$) {
|
48
|
0
|
|
|
0
|
0
|
|
my $app = shift;
|
49
|
0
|
|
|
|
|
|
my $idldoc= shift;
|
50
|
0
|
|
|
|
|
|
my $doc_path=shift;
|
51
|
0
|
|
|
|
|
|
my $idx_path=shift;
|
52
|
0
|
|
|
|
|
|
my $doc = "$app.$idldoc.pdf";
|
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
my $cfg = config_read('EDOCMNGR');
|
55
|
0
|
|
|
|
|
|
my $zip = Archive::Zip->new();
|
56
|
0
|
|
|
|
|
|
$zip->addFile($doc_path, $doc);
|
57
|
0
|
|
|
|
|
|
$zip->addFile($idx_path, basename($idx_path));
|
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my $zipfile = "$cfg->{'EDTK_DIR_EDOCMNGR'}/$app.$idldoc.out.zip";
|
60
|
0
|
0
|
|
|
|
|
die "ERROR: Could not create zip achive \"$zipfile\"\n"
|
61
|
|
|
|
|
|
|
unless $zip->writeToFileNamed($zipfile) == AZ_OK;
|
62
|
0
|
|
|
|
|
|
print "$zipfile\n";
|
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
return 1;
|
65
|
|
|
|
|
|
|
}
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# Package some documents along with one index in a zip archive.
|
69
|
|
|
|
|
|
|
sub EDMS_package($$@) {
|
70
|
0
|
|
|
0
|
0
|
|
my $app = shift;
|
71
|
0
|
|
|
|
|
|
my $idldoc= shift;
|
72
|
0
|
|
|
|
|
|
my @elements=@_;
|
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
my $cfg = config_read('EDOCMNGR');
|
75
|
0
|
|
|
|
|
|
my $zip = Archive::Zip->new();
|
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
foreach (@elements){
|
78
|
0
|
|
|
|
|
|
$zip->addFile($_, basename($_));
|
79
|
|
|
|
|
|
|
}
|
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
my $zipfile = "$cfg->{'EDTK_DIR_EDOCMNGR'}/$app.$idldoc.out.zip";
|
82
|
0
|
0
|
|
|
|
|
die "ERROR: Could not create zip achive \"$zipfile\"\n"
|
83
|
|
|
|
|
|
|
unless $zip->writeToFileNamed($zipfile) == AZ_OK;
|
84
|
0
|
|
|
|
|
|
print "$zipfile\n";
|
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
return 1;
|
87
|
|
|
|
|
|
|
}
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub EDMS_process_zip($;$) {
|
91
|
0
|
|
|
0
|
0
|
|
my ($zipfile, $outdir) = @_;
|
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
my $zipname = basename($zipfile);
|
94
|
0
|
0
|
|
|
|
|
if ($zipname !~ /^([^.]+)\.(.+)\.out\.zip$/) {
|
95
|
0
|
|
|
|
|
|
die "ERROR: Unexpected zip filename: $zipname\n";
|
96
|
|
|
|
|
|
|
}
|
97
|
0
|
|
|
|
|
|
my ($app, $idldoc) = ($1, $2);
|
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
my $zip = Archive::Zip->new();
|
100
|
0
|
0
|
|
|
|
|
if ($zip->read($zipfile) != AZ_OK) {
|
101
|
0
|
|
|
|
|
|
die "ERROR: Could not read zip archive \"$zipfile\"\n";
|
102
|
|
|
|
|
|
|
}
|
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
my @files = $zip->members();
|
105
|
0
|
|
|
|
|
|
my ($idx_member) = $zip->membersMatching('\.idx1$');
|
106
|
0
|
|
|
|
|
|
my ($doc_member) = $zip->membersMatching('\.pdf$');
|
107
|
0
|
0
|
|
|
|
|
if (!defined($doc_member)){
|
108
|
0
|
|
|
|
|
|
($doc_member) = $zip->membersMatching('\.xls$');
|
109
|
|
|
|
|
|
|
}
|
110
|
0
|
0
|
|
|
|
|
if (!defined($doc_member)){
|
111
|
0
|
|
|
|
|
|
($doc_member) = $zip->membersMatching('\.doc$');
|
112
|
|
|
|
|
|
|
}
|
113
|
0
|
0
|
0
|
|
|
|
if (!defined($doc_member) || !defined($idx_member)) {
|
114
|
0
|
|
|
|
|
|
die "ERROR: Could not find document(s) or index file in archive\n";
|
115
|
|
|
|
|
|
|
}
|
116
|
0
|
|
|
|
|
|
my $doc_name = $doc_member->fileName();
|
117
|
0
|
|
|
|
|
|
my $idx_name = $idx_member->fileName();
|
118
|
0
|
|
|
|
|
|
my $doc_path = $doc_name;
|
119
|
0
|
|
|
|
|
|
my $idx_path = $idx_name;
|
120
|
0
|
0
|
|
|
|
|
if (defined($outdir)) {
|
121
|
0
|
|
|
|
|
|
$doc_path = "$outdir/$doc_path";
|
122
|
0
|
|
|
|
|
|
$idx_path = "$outdir/$idx_path";
|
123
|
|
|
|
|
|
|
}
|
124
|
0
|
|
|
|
|
|
warn "INFO : Extracting file \"$doc_name\"\n";
|
125
|
0
|
0
|
|
|
|
|
if ($zip->extractMember($doc_member, $doc_path) != AZ_OK) {
|
126
|
0
|
|
|
|
|
|
die "ERROR: Could not extract \"$doc_name\" from archive\n";
|
127
|
|
|
|
|
|
|
}
|
128
|
0
|
|
|
|
|
|
warn "INFO : Extracting file \"$idx_name\"\n";
|
129
|
0
|
0
|
|
|
|
|
if ($zip->extractMember($idx_member, $idx_path) != AZ_OK) {
|
130
|
0
|
|
|
|
|
|
die "ERROR: Could not extract \"$idx_name\" from archive\n";
|
131
|
|
|
|
|
|
|
}
|
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
return EDMS_process($app, $idldoc, $doc_name, $idx_name, $outdir);
|
134
|
|
|
|
|
|
|
}
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# Process document(s) with its index in a way suitable for the edms software.
|
138
|
|
|
|
|
|
|
sub EDMS_process($$$$;$) {
|
139
|
0
|
|
|
0
|
0
|
|
my ($app, $idldoc, $doc, $index, $outdir) = @_;
|
140
|
|
|
|
|
|
|
# Remplace les - et les . par des _ car Docubase ne peut pas importer de fichier comprenant des . dans leur nom
|
141
|
0
|
|
|
|
|
|
$idldoc =~ s/[-\.]/_/g;
|
142
|
0
|
|
|
|
|
|
$app =~ s/[-\.]/_/g;
|
143
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
my $cfg = config_read('EDOCMNGR');
|
145
|
0
|
|
|
|
|
|
my $format = $cfg->{'EDMS_IDX_FORMAT'};
|
146
|
0
|
|
|
|
|
|
my @edmscols = split(/,/, $cfg->{'EDMS_INDEX_COLS'});
|
147
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
my $oldcwd;
|
149
|
0
|
0
|
|
|
|
|
if (defined($outdir)) {
|
150
|
0
|
|
|
|
|
|
$oldcwd = getcwd();
|
151
|
0
|
0
|
|
|
|
|
chdir($outdir)
|
152
|
|
|
|
|
|
|
or die "ERROR: Cannot change current directory to \"$outdir\": $!\n";
|
153
|
|
|
|
|
|
|
}
|
154
|
0
|
|
|
|
|
|
my @outfiles = ();
|
155
|
|
|
|
|
|
|
|
156
|
0
|
0
|
|
|
|
|
if ($doc =~ /pdf$/i){
|
157
|
0
|
|
|
|
|
|
warn "INFO : Splitting $doc into individual docs...\n";
|
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
## gs -sDEVICE=pdfwrite \
|
160
|
|
|
|
|
|
|
## -q -dNOPAUSE -dBATCH \
|
161
|
|
|
|
|
|
|
## -sOutputFile=sample-1.pdf \
|
162
|
|
|
|
|
|
|
## -dFirstPage=1 \
|
163
|
|
|
|
|
|
|
## -dLastPage=1 \
|
164
|
|
|
|
|
|
|
## FAX200904010240-1.PDF
|
165
|
|
|
|
|
|
|
#my $this_pdf = PDF->new;
|
166
|
|
|
|
|
|
|
#$this_pdf = PDF->new($doc);
|
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
#my $output = "${app}_${idldoc}_%07d.pdf";
|
169
|
|
|
|
|
|
|
#my $gs = system ($cfg->{'EDMS_BIN_GS'} . " -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dFirstPage=1 -dLastPage=". $this_pdf->Pages ." -sOutputFile=$output $doc ");
|
170
|
|
|
|
|
|
|
#if ($gs != 0) {
|
171
|
|
|
|
|
|
|
# die "ERROR: Could not split pages from $doc to $output !\n";
|
172
|
|
|
|
|
|
|
#}
|
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
# Modifié suite au problème des points dans les noms de fichiers pour docubase
|
175
|
0
|
|
|
|
|
|
my $rv = system($cfg->{'EDMS_BIN_PDFTK'} . " $doc burst output ${app}_${idldoc}_%07d.pdf ");
|
176
|
|
|
|
|
|
|
|
177
|
0
|
0
|
|
|
|
|
if ($rv != 0) {
|
178
|
0
|
|
|
|
|
|
die "ERROR: Could not burst PDF file $doc!\n";
|
179
|
|
|
|
|
|
|
}
|
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
} else {
|
182
|
|
|
|
|
|
|
#warn "DEBUG: document $doc is not pdf file\n";
|
183
|
0
|
|
|
|
|
|
my $cible = _docubase_file_name($doc);
|
184
|
0
|
0
|
|
|
|
|
move ($doc, $cible) or die "ERROR: echec move $cible ($doc)\n";
|
185
|
0
|
|
|
|
|
|
push (@outfiles, $cible);
|
186
|
|
|
|
|
|
|
}
|
187
|
|
|
|
|
|
|
|
188
|
0
|
0
|
|
|
|
|
if ($format eq 'DOCUBASE') {
|
|
|
0
|
|
|
|
|
|
189
|
0
|
|
|
|
|
|
@outfiles = EDMS_idx_create_csv($cfg, $index, $app, $idldoc, \@edmscols);
|
190
|
|
|
|
|
|
|
} elsif ($format eq 'SCOPMASTER') {
|
191
|
0
|
|
|
|
|
|
@outfiles = EDMS_idx_create_xml($cfg, $index, $app, $idldoc, \@edmscols);
|
192
|
|
|
|
|
|
|
} else {
|
193
|
0
|
|
|
|
|
|
die "ERROR: Unexpected index format: $format\n";
|
194
|
|
|
|
|
|
|
}
|
195
|
|
|
|
|
|
|
|
196
|
0
|
0
|
|
|
|
|
if ($cfg->{'EDTK_TYPE_ENV'} ne 'Test') {
|
197
|
0
|
0
|
|
|
|
|
unlink($doc) if ($doc =~ /pdf$/i);
|
198
|
0
|
|
|
|
|
|
unlink($index);
|
199
|
0
|
|
|
|
|
|
unlink('doc_data.txt'); # pdftk creates this one.
|
200
|
|
|
|
|
|
|
}
|
201
|
|
|
|
|
|
|
|
202
|
0
|
0
|
|
|
|
|
if (defined($outdir)) {
|
203
|
|
|
|
|
|
|
# Restore original working directory.
|
204
|
0
|
|
|
|
|
|
chdir($oldcwd);
|
205
|
|
|
|
|
|
|
}
|
206
|
|
|
|
|
|
|
|
207
|
0
|
|
|
|
|
|
return @outfiles;
|
208
|
|
|
|
|
|
|
}
|
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
# TRANSFER THE PDF FILES AND THE INDEX TO edms APPLICATION.
|
212
|
|
|
|
|
|
|
sub EDMS_import($@) {
|
213
|
0
|
|
|
0
|
0
|
|
my ($index, @docs) = @_;
|
214
|
|
|
|
|
|
|
|
215
|
0
|
|
|
|
|
|
my $cfg = config_read('EDOCMNGR');
|
216
|
0
|
|
|
|
|
|
warn "INFO : Connection to edms FTP server $cfg->{'EDMS_FTP_HOST'}:$cfg->{'EDMS_FTP_PORT'}\n";
|
217
|
0
|
0
|
|
|
|
|
my $ftp = Net::FTP->new($cfg->{'EDMS_FTP_HOST'}, Port => $cfg->{'EDMS_FTP_PORT'})
|
218
|
|
|
|
|
|
|
or die "ERROR: Cannot connect to $cfg->{'EDMS_FTP_HOST'}: $@\n";
|
219
|
0
|
0
|
|
|
|
|
$ftp->login($cfg->{'EDMS_FTP_USER'}, $cfg->{'EDMS_FTP_PASS'})
|
220
|
|
|
|
|
|
|
or die "ERROR: Cannot login: " . $ftp->message() . "\n";
|
221
|
0
|
0
|
|
|
|
|
$ftp->binary()
|
222
|
|
|
|
|
|
|
or die "ERROR: Cannot set binary mode: " . $ftp->message() . "\n";
|
223
|
0
|
0
|
|
|
|
|
$ftp->cwd($cfg->{'EDMS_FTP_DIR_DOCS'})
|
224
|
|
|
|
|
|
|
or die "ERROR: Cannot change working directory: " . $ftp->message() . "\n";
|
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
# It is important to transfer the edms APPLICATION index file last, otherwise
|
227
|
|
|
|
|
|
|
# the PDF files that haven't been transferred yet will not be processed.
|
228
|
0
|
|
|
|
|
|
foreach my $doc (@docs) {
|
229
|
0
|
|
|
|
|
|
warn "INFO : Uploading DOC file $doc\n";
|
230
|
0
|
0
|
|
|
|
|
$ftp->put($doc)
|
231
|
|
|
|
|
|
|
or die "ERROR: Cannot upload DOC file : " . $ftp->message() . "\n";
|
232
|
|
|
|
|
|
|
}
|
233
|
0
|
|
|
|
|
|
warn "INFO : Uploading index file $index\n";
|
234
|
0
|
0
|
|
|
|
|
$ftp->cwd()
|
235
|
|
|
|
|
|
|
or die "ERROR: Cannot change working directory : " . $ftp->message() . "\n";
|
236
|
0
|
0
|
|
|
|
|
$ftp->cwd($cfg->{'EDMS_FTP_DIR_IDX'})
|
237
|
|
|
|
|
|
|
or die "ERROR: Cannot change working directory : " . $ftp->message() . "\n";
|
238
|
0
|
0
|
|
|
|
|
$ftp->put($index)
|
239
|
|
|
|
|
|
|
or die "ERROR: Cannot upload index file : " . $ftp->message() . "\n";
|
240
|
0
|
|
|
|
|
|
$ftp->quit();
|
241
|
|
|
|
|
|
|
}
|
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
# READ THE INITIAL INDEX FILE, AND CALL THE GIVEN FUNCTION FOR EACH NEW
|
244
|
|
|
|
|
|
|
# DOCUMENT. ALSO CONCATENATE PDF FILES IF NEEDED (FOR MULTI-PAGES DOCUMENTS).
|
245
|
|
|
|
|
|
|
sub EDMS_idx_process($$$$&) {
|
246
|
0
|
|
|
0
|
0
|
|
my ($app, $idx, $idldoc, $keys, $sub) = @_;
|
247
|
|
|
|
|
|
|
|
248
|
0
|
|
|
|
|
|
my @idxcols = map { $$_[0] } @INDEX_COLS[0..28]; # il faudrait peut être pousser jusqu'à 30 (ED_CODRUPT) voir plus
|
|
0
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
|
250
|
0
|
0
|
|
|
|
|
open(my $fh, '<', $idx) or die "ERROR: Cannot open \"$idx\": $!\n";
|
251
|
0
|
|
|
|
|
|
my $csv = Text::CSV->new({ binary => 1, sep_char => ';' });
|
252
|
0
|
|
|
|
|
|
$csv->column_names(@idxcols);
|
253
|
0
|
|
|
|
|
|
my $lastdoc = 0;
|
254
|
0
|
|
|
|
|
|
my $firstpg = 0;
|
255
|
0
|
|
|
|
|
|
my $numpgs = 1;
|
256
|
0
|
|
|
|
|
|
my %docvals = ();
|
257
|
0
|
|
|
|
|
|
my $vals;
|
258
|
|
|
|
|
|
|
|
259
|
0
|
|
|
|
|
|
while ($vals = $csv->getline_hr($fh)) {
|
260
|
0
|
0
|
|
|
|
|
if ($vals->{'ED_SEQDOC'} != $lastdoc) {
|
261
|
0
|
0
|
|
|
|
|
if ($lastdoc != 0) {
|
262
|
0
|
|
|
|
|
|
EDMS_merge_docs($app, $idldoc, $firstpg, $numpgs);
|
263
|
0
|
|
|
|
|
|
$sub->(\%docvals, $firstpg, $numpgs);
|
264
|
0
|
|
|
|
|
|
undef (%docvals);
|
265
|
|
|
|
|
|
|
}
|
266
|
0
|
|
|
|
|
|
$lastdoc = $vals->{'ED_SEQDOC'};
|
267
|
|
|
|
|
|
|
# Remember the values we are interested in for the edms.
|
268
|
0
|
|
|
|
|
|
foreach (@$keys) {
|
269
|
0
|
|
|
|
|
|
$docvals{$_} = $vals->{$_};
|
270
|
|
|
|
|
|
|
}
|
271
|
0
|
|
|
|
|
|
$docvals{'ED_DOCLIB'} = $vals->{'ED_DOCLIB'};
|
272
|
0
|
|
|
|
|
|
$firstpg = $vals->{'ED_IDSEQPG'};
|
273
|
0
|
|
|
|
|
|
$numpgs = 1;
|
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
} else {
|
276
|
|
|
|
|
|
|
# Remember the values we are interested in for the edms.
|
277
|
0
|
|
|
|
|
|
foreach (@$keys) {
|
278
|
0
|
0
|
|
|
|
|
$docvals{$_} = $vals->{$_} if $vals->{$_};
|
279
|
|
|
|
|
|
|
}
|
280
|
0
|
|
|
|
|
|
$docvals{'ED_DOCLIB'} = $vals->{'ED_DOCLIB'};
|
281
|
0
|
|
|
|
|
|
$numpgs++;
|
282
|
|
|
|
|
|
|
}
|
283
|
|
|
|
|
|
|
}
|
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
# Handle the last document.
|
286
|
0
|
0
|
|
|
|
|
if ($lastdoc != 0) {
|
287
|
0
|
|
|
|
|
|
EDMS_merge_docs($app, $idldoc, $firstpg, $numpgs);
|
288
|
0
|
|
|
|
|
|
$sub->(\%docvals, $firstpg, $numpgs);
|
289
|
|
|
|
|
|
|
}
|
290
|
0
|
|
|
|
|
|
close($fh);
|
291
|
|
|
|
|
|
|
}
|
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
sub _docubase_file_name($){
|
295
|
0
|
|
|
0
|
|
|
my $filename = shift;
|
296
|
|
|
|
|
|
|
|
297
|
0
|
|
|
|
|
|
$filename =~s/(^.*)(\.\w{2,4}$)/$1/;
|
298
|
0
|
|
0
|
|
|
|
my $ext = $2 || "";
|
299
|
0
|
|
|
|
|
|
$filename =~s/[-\.]/_/g;
|
300
|
0
|
|
|
|
|
|
$filename .= $ext;
|
301
|
|
|
|
|
|
|
|
302
|
0
|
|
|
|
|
|
return $filename;
|
303
|
|
|
|
|
|
|
}
|
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
# CREATE A EDMS INDEX FILE IN CSV FORMAT (FOR EDMS APPLICATION).
|
307
|
|
|
|
|
|
|
sub EDMS_idx_create_csv($$$$$) {
|
308
|
0
|
|
|
0
|
0
|
|
my ($cfg, $idx, $app, $idldoc, $keys) = @_;
|
309
|
|
|
|
|
|
|
|
310
|
0
|
|
|
|
|
|
my $csv = Text::CSV->new({ binary => 1, sep_char => ';', eol => "\n", quote_space => 0 });
|
311
|
0
|
|
|
|
|
|
my $edmsidx = "${app}_$idldoc.idx";
|
312
|
0
|
0
|
|
|
|
|
open(my $fh, '>', $edmsidx) or die "ERROR: Cannot create \"$edmsidx\": $!\n";
|
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
# Always return the index file as the first file in the list, see
|
315
|
|
|
|
|
|
|
# EDMS_import() for why this is important.
|
316
|
0
|
|
|
|
|
|
my @outfiles = ($edmsidx);
|
317
|
|
|
|
|
|
|
EDMS_idx_process($app, $idx, $idldoc, $keys, sub {
|
318
|
0
|
|
|
0
|
|
|
my ($vals, $firstpg, $numpgs) = @_;
|
319
|
|
|
|
|
|
|
|
320
|
0
|
0
|
|
|
|
|
if ($vals->{'ED_DOCLIB'} =~ /pdf$/i) {
|
321
|
0
|
|
|
|
|
|
$vals->{'EDMS_IDLDOC_SEQPG'} = EDMS_idldoc_seqpg($idldoc, $firstpg);
|
322
|
0
|
|
|
|
|
|
$vals->{'EDMS_FILENAME'} = "${app}_". $vals->{'EDMS_IDLDOC_SEQPG'} .".pdf";
|
323
|
|
|
|
|
|
|
} else {
|
324
|
0
|
|
|
|
|
|
$vals->{'EDMS_FILENAME'} = _docubase_file_name($vals->{'ED_DOCLIB'});
|
325
|
|
|
|
|
|
|
}
|
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
# Dates need to be in a specific format.
|
328
|
0
|
|
|
|
|
|
my $datefmt = $cfg->{'EDMS_DATE_FORMAT'};
|
329
|
0
|
0
|
|
|
|
|
if ($vals->{'ED_DTEDTION'} !~ /^(\d{4})(\d{2})(\d{2})$/) {
|
330
|
0
|
|
|
|
|
|
die "ERROR: Unexpected date format for ED_DTEDTION: $vals->{'ED_DTEDTION'}\n";
|
331
|
|
|
|
|
|
|
}
|
332
|
0
|
|
|
|
|
|
my ($year, $month, $day) = ($1, $2, $3);
|
333
|
0
|
|
|
|
|
|
$vals->{'EDMS_PROCESS_DT'} = strftime($datefmt, 0, 0, 0, $day, $month - 1, $year - 1900);
|
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
# owner id for group acces in edms
|
336
|
|
|
|
|
|
|
# la règle de gestion ne devrait pas etre ici, à faire évoluer
|
337
|
0
|
0
|
|
|
|
|
if ($vals->{'ED_IDEMET'} =~/^\D{1}\d{3}/) {
|
338
|
0
|
|
|
|
|
|
$vals->{'ED_OWNER'} = $vals->{'ED_IDEMET'};
|
339
|
|
|
|
|
|
|
} else {
|
340
|
0
|
|
|
|
|
|
$vals->{'ED_OWNER'} = $vals->{'ED_SOURCE'};
|
341
|
|
|
|
|
|
|
}
|
342
|
|
|
|
|
|
|
|
343
|
0
|
|
|
|
|
|
my @edmsvals = map { $vals->{$_} } @$keys;
|
|
0
|
|
|
|
|
|
|
344
|
0
|
|
|
|
|
|
$csv->print($fh, \@edmsvals);
|
345
|
|
|
|
|
|
|
|
346
|
0
|
|
|
|
|
|
push(@outfiles, $vals->{'EDMS_FILENAME'});
|
347
|
0
|
|
|
|
|
|
});
|
348
|
0
|
|
|
|
|
|
close($fh);
|
349
|
0
|
|
|
|
|
|
return @outfiles;
|
350
|
|
|
|
|
|
|
}
|
351
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
# Create edms indexes in XML format (one per PDF file).
|
353
|
|
|
|
|
|
|
sub EDMS_idx_create_xml($$$$$) {
|
354
|
0
|
|
|
0
|
0
|
|
my ($cfg, $idx, $app, $idldoc, $keys) = @_;
|
355
|
|
|
|
|
|
|
|
356
|
0
|
|
|
|
|
|
my @outfiles = ();
|
357
|
|
|
|
|
|
|
EDMS_idx_process($app, $idx, $idldoc, $keys, sub {
|
358
|
0
|
|
|
0
|
|
|
my ($vals, $firstpg, $numpgs) = @_;
|
359
|
|
|
|
|
|
|
|
360
|
0
|
|
|
|
|
|
my $docid = EDMS_idldoc_seqpg($idldoc, $firstpg);
|
361
|
0
|
|
|
|
|
|
my $xmlfile = "$docid.edms.xml";
|
362
|
0
|
|
|
|
|
|
$vals->{'ED_DOCLIB'} =~ /\.(\w{2,4})$/;
|
363
|
0
|
|
|
|
|
|
my $ext = $1;
|
364
|
|
|
|
|
|
|
|
365
|
0
|
0
|
|
|
|
|
open(my $fh, '>', $xmlfile) or die "ERROR: Cannot create \"$xmlfile\": $!\n";
|
366
|
0
|
|
|
|
|
|
my $xml = XML::Writer->new(OUTPUT => $fh, ENCODING => 'utf-8');
|
367
|
0
|
|
|
|
|
|
$xml->xmlDecl('utf-8');
|
368
|
0
|
|
|
|
|
|
$xml->startTag('idxext');
|
369
|
|
|
|
|
|
|
|
370
|
0
|
|
|
|
|
|
foreach my $pagenum (1..$numpgs) {
|
371
|
0
|
|
|
|
|
|
$xml->startTag('page', num => $pagenum);
|
372
|
0
|
0
|
|
|
|
|
if ($pagenum == 1) {
|
373
|
0
|
|
|
|
|
|
while (my ($key,$val) = each(%$vals)) {
|
374
|
0
|
|
|
|
|
|
$xml->emptyTag('index', key => $key, value => $val);
|
375
|
|
|
|
|
|
|
}
|
376
|
|
|
|
|
|
|
}
|
377
|
0
|
|
|
|
|
|
$xml->endTag('page');
|
378
|
|
|
|
|
|
|
}
|
379
|
0
|
|
|
|
|
|
$xml->endTag('idxext');
|
380
|
0
|
|
|
|
|
|
$xml->end();
|
381
|
0
|
|
|
|
|
|
close($fh);
|
382
|
|
|
|
|
|
|
|
383
|
0
|
|
|
|
|
|
push(@outfiles, $xmlfile);
|
384
|
0
|
|
|
|
|
|
push(@outfiles, "${app}_$docid.$ext");
|
385
|
0
|
|
|
|
|
|
});
|
386
|
0
|
|
|
|
|
|
return @outfiles;
|
387
|
|
|
|
|
|
|
}
|
388
|
|
|
|
|
|
|
|
389
|
|
|
|
|
|
|
# Concatenate PDF documents if needed.
|
390
|
|
|
|
|
|
|
sub EDMS_merge_docs($$$$) {
|
391
|
0
|
|
|
0
|
0
|
|
my ($app, $idldoc, $firstpg, $numpgs, $optimizer) = @_;
|
392
|
0
|
|
|
|
|
|
my $cfg = config_read('EDOCMNGR'); # , $cfg->{'EDMS_PDF_OPTIMIZER'}
|
393
|
|
|
|
|
|
|
|
394
|
|
|
|
|
|
|
# If the document is only one page long, there is nothing to concatenate.
|
395
|
0
|
0
|
|
|
|
|
return unless $numpgs > 1;
|
396
|
|
|
|
|
|
|
|
397
|
0
|
|
|
|
|
|
my $lastpg = $firstpg + $numpgs - 1;
|
398
|
0
|
|
|
|
|
|
my @pages = map { "${app}_" . EDMS_idldoc_seqpg($idldoc, $_) . ".pdf" } ($firstpg .. $lastpg);
|
|
0
|
|
|
|
|
|
|
399
|
0
|
|
|
|
|
|
warn "INFO : Concatenating pages $firstpg to $lastpg into $pages[0]\n";
|
400
|
0
|
|
|
|
|
|
my $output = "$pages[0].tmp";
|
401
|
|
|
|
|
|
|
|
402
|
0
|
0
|
0
|
|
|
|
if (defined $cfg->{'EDMS_BIN_GS'} && $cfg->{'EDMS_BIN_GS'} ne "") {
|
403
|
|
|
|
|
|
|
# les pdf créés avec pdftk sont trop lourds, changement de mode opératoire ...
|
404
|
0
|
|
|
|
|
|
my $gs = system ($cfg->{'EDMS_BIN_GS'} . " -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=$output @pages ");
|
405
|
0
|
0
|
|
|
|
|
if ($gs != 0) {
|
406
|
0
|
|
|
|
|
|
die "ERROR: Could not concatenate pages $firstpg to $lastpg!\n";
|
407
|
|
|
|
|
|
|
}
|
408
|
|
|
|
|
|
|
} else {
|
409
|
0
|
|
|
|
|
|
my $rv = system($cfg->{'EDMS_BIN_PDFTK'} . " " . join(' ', @pages) . " cat output $output");
|
410
|
0
|
0
|
|
|
|
|
if ($rv != 0) {
|
411
|
0
|
|
|
|
|
|
die "ERROR: Could not concatenate pages $firstpg to $lastpg!\n";
|
412
|
|
|
|
|
|
|
}
|
413
|
|
|
|
|
|
|
}
|
414
|
|
|
|
|
|
|
|
415
|
|
|
|
|
|
|
# Now, remove old files, and rename concatenated PDF to the name of
|
416
|
|
|
|
|
|
|
# the PDF file of the first page.
|
417
|
0
|
|
|
|
|
|
foreach (@pages) {
|
418
|
0
|
|
|
|
|
|
unlink($_);
|
419
|
|
|
|
|
|
|
}
|
420
|
0
|
|
|
|
|
|
move($output, $pages[0]);
|
421
|
|
|
|
|
|
|
}
|
422
|
|
|
|
|
|
|
|
423
|
|
|
|
|
|
|
|
424
|
|
|
|
|
|
|
sub EDMS_edidx_build (\%){
|
425
|
0
|
|
|
0
|
0
|
|
my ($refOpt) = @_;
|
426
|
0
|
|
|
|
|
|
my $cfg = config_read('EDOCMNGR');
|
427
|
|
|
|
|
|
|
|
428
|
|
|
|
|
|
|
# EDMS_INDEX_COLS =ED_REFIDDOC,ED_CORP,ED_SOURCE,EDMS_IDLDOC_SEQPG,ED_DTEDTION,ED_CLEGED1,ED_IDDEST,ED_NOMDEST,ED_VILLDEST,ED_IDEMET,ED_CLEGED2,ED_CLEGED3,ED_CLEGED4,ED_OWNER,EDMS_FILENAME
|
429
|
|
|
|
|
|
|
# clefs d'index requises : ED_REFIDDOC, ED_CORP, ED_SOURCE, ED_IDDEST, ED_NOMDEST, ED_IDEMET, ED_OWNER, ED_CORP
|
430
|
|
|
|
|
|
|
# clefs optionnelles : ED_DTEDTION, ED_CLEGED1, ED_VILLDEST, ED_CLEGED2, ED_CLEGED3, ED_CLEGED4
|
431
|
|
|
|
|
|
|
# clefs (re)calculées : ED_DTEDTION, EDMS_IDLDOC_SEQPG, EDMS_FILENAME
|
432
|
|
|
|
|
|
|
|
433
|
|
|
|
|
|
|
# REQUIRED KEYS
|
434
|
0
|
0
|
0
|
|
|
|
if (!defined $$refOpt{'ED_REFIDDOC'} or $$refOpt{'ED_REFIDDOC'} eq ""){
|
435
|
0
|
|
|
|
|
|
die "ERROR: ED_REFIDDOC required.\n";
|
436
|
|
|
|
|
|
|
}
|
437
|
0
|
0
|
0
|
|
|
|
if (!defined $$refOpt{'ED_SOURCE'} or $$refOpt{'ED_SOURCE'} eq ""){
|
438
|
0
|
|
|
|
|
|
die "ERROR: ED_SOURCE required.\n";
|
439
|
|
|
|
|
|
|
}
|
440
|
0
|
0
|
0
|
|
|
|
if (!defined $$refOpt{'ED_IDDEST'} or $$refOpt{'ED_IDDEST'} eq ""){
|
441
|
0
|
|
|
|
|
|
die "ERROR: ED_IDDEST required.\n";
|
442
|
|
|
|
|
|
|
}
|
443
|
0
|
0
|
0
|
|
|
|
if (!defined $$refOpt{'ED_NOMDEST'} or $$refOpt{'ED_NOMDEST'} eq ""){
|
444
|
0
|
|
|
|
|
|
die "ERROR: ED_NOMDEST required.\n";
|
445
|
|
|
|
|
|
|
}
|
446
|
0
|
0
|
0
|
|
|
|
if (!defined $$refOpt{'ED_IDEMET'} or $$refOpt{'ED_IDEMET'} eq ""){
|
447
|
0
|
|
|
|
|
|
die "ERROR: ED_IDEMET required.\n";
|
448
|
|
|
|
|
|
|
}
|
449
|
0
|
0
|
0
|
|
|
|
if (!defined $$refOpt{'ED_OWNER'} or $$refOpt{'ED_OWNER'} eq ""){
|
450
|
0
|
|
|
|
|
|
die "ERROR: ED_OWNER required.\n";
|
451
|
|
|
|
|
|
|
}
|
452
|
0
|
0
|
0
|
|
|
|
if (!defined $$refOpt{'ED_CORP'} or $$refOpt{'ED_CORP'} eq ""){
|
453
|
0
|
|
|
|
|
|
die "ERROR: ED_CORP required.\n";
|
454
|
|
|
|
|
|
|
}
|
455
|
|
|
|
|
|
|
|
456
|
|
|
|
|
|
|
|
457
|
|
|
|
|
|
|
# COMPUTED KEYS
|
458
|
0
|
|
|
|
|
|
my $FILE_EXT = $$refOpt{'ED_FILENAME'}; #= $req->upload('EDMS_FILENAME');
|
459
|
0
|
|
|
|
|
|
$FILE_EXT =~s/^(.*\.)(\w+)$/$2/;
|
460
|
0
|
|
|
|
|
|
$$refOpt{'ED_FORMFLUX'} = uc ($FILE_EXT);
|
461
|
|
|
|
|
|
|
|
462
|
0
|
|
|
|
|
|
my ($sec,$min,$hour,$day,$month,$year);
|
463
|
0
|
0
|
0
|
|
|
|
if (!defined $$refOpt{'ED_DTEDTION'} || $$refOpt{'ED_DTEDTION'} !~ /^(\d{4})(\d{2})(\d{2})$/) {
|
464
|
|
|
|
|
|
|
#die "ERROR: Unexpected date format for ED_DTEDTION: $$refOpt{'ED_DTEDTION'}\n";
|
465
|
0
|
|
|
|
|
|
($sec,$min,$hour,$day,$month,$year) = localtime();
|
466
|
0
|
|
|
|
|
|
$month ++;
|
467
|
0
|
|
|
|
|
|
$year += 1900;
|
468
|
|
|
|
|
|
|
} else {
|
469
|
0
|
|
|
|
|
|
($year, $month, $day) = ($1, $2, $3);
|
470
|
|
|
|
|
|
|
}
|
471
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
# DATES NEED TO BE IN A SPECIFIC FORMAT.
|
473
|
0
|
|
|
|
|
|
my $datefmt = $cfg->{'EDMS_DATE_FORMAT'};
|
474
|
0
|
|
|
|
|
|
$$refOpt{'ED_DTEDTION'} = strftime($datefmt, 0, 0, 0, $day, $month - 1, $year - 1900);
|
475
|
0
|
|
|
|
|
|
$$refOpt{'ED_IDLDOC'} = oEdtk::Main::oe_ID_LDOC();
|
476
|
0
|
|
|
|
|
|
$$refOpt{'ED_IDSEQPG'} = 1;
|
477
|
0
|
|
|
|
|
|
$$refOpt{'ED_SEQDOC'} = 1;
|
478
|
0
|
|
|
|
|
|
$$refOpt{'EDMS_IDLDOC_SEQPG'} = EDMS_idldoc_seqpg($$refOpt{'ED_IDLDOC'}, $$refOpt{'ED_IDSEQPG'});
|
479
|
0
|
|
|
|
|
|
$$refOpt{'EDMS_FILENAME'} = $$refOpt{'ED_REFIDDOC'} . "_" .$$refOpt{'EDMS_IDLDOC_SEQPG'};
|
480
|
0
|
|
|
|
|
|
$$refOpt{'EDMS_FILENAME'} =~s/[-\.\s]/_/g;
|
481
|
0
|
|
|
|
|
|
$$refOpt{'EDMS_FILENAME'} = $$refOpt{'EDMS_FILENAME'} . "." . $FILE_EXT ;
|
482
|
0
|
|
|
|
|
|
$$refOpt{'ED_DOCLIB'} = $$refOpt{'EDMS_FILENAME'};
|
483
|
|
|
|
|
|
|
|
484
|
|
|
|
|
|
|
# OPTIONNAL KEYS
|
485
|
0
|
|
|
|
|
|
$$refOpt{'ED_VILLDEST'}|= "";
|
486
|
0
|
|
|
|
|
|
$$refOpt{'ED_CLEGED1'} |= "";
|
487
|
0
|
|
|
|
|
|
$$refOpt{'ED_CLEGED2'} |= "";
|
488
|
0
|
|
|
|
|
|
$$refOpt{'ED_CLEGED3'} |= "";
|
489
|
0
|
|
|
|
|
|
$$refOpt{'ED_CLEGED4'} |= "";
|
490
|
|
|
|
|
|
|
}
|
491
|
|
|
|
|
|
|
|
492
|
|
|
|
|
|
|
|
493
|
|
|
|
|
|
|
sub EDMS_edidx_write (\%) {
|
494
|
0
|
|
|
0
|
0
|
|
my ($refOpt) = shift;
|
495
|
0
|
|
|
|
|
|
my $cfg = config_read('EDOCMNGR');
|
496
|
0
|
|
|
|
|
|
my @edms_cols = split(/,/, $cfg->{'EDMS_INDEX_COLS'});
|
497
|
0
|
|
|
|
|
|
my $index = $$refOpt{'ED_REFIDDOC'} . "_" . $$refOpt{'ED_IDLDOC'} .".idx";
|
498
|
|
|
|
|
|
|
|
499
|
0
|
0
|
|
|
|
|
open (my $fh, ">>$index") or die "ERROR: can't open $index : $!";
|
500
|
0
|
|
|
|
|
|
my $csv = Text::CSV->new({ binary => 1, sep_char => ';', eol => "\n", quote_space => 0 });
|
501
|
|
|
|
|
|
|
|
502
|
0
|
|
|
|
|
|
my @fields; # = map { $$refOpt{$$_[0]} } @edms_cols;
|
503
|
0
|
|
|
|
|
|
foreach my $key (@edms_cols){
|
504
|
0
|
|
|
|
|
|
push (@fields, $$refOpt{$key});
|
505
|
|
|
|
|
|
|
}
|
506
|
|
|
|
|
|
|
|
507
|
0
|
|
|
|
|
|
$csv->print($fh, \@fields);
|
508
|
0
|
|
|
|
|
|
close($fh);
|
509
|
|
|
|
|
|
|
}
|
510
|
|
|
|
|
|
|
|
511
|
|
|
|
|
|
|
|
512
|
|
|
|
|
|
|
1;
|