140 |
140 |
$self->js->flash('error',$::locale->text('File not exists !'))->render();
|
141 |
141 |
return;
|
142 |
142 |
}
|
143 |
|
$main::lxdebug->message(LXDebug->DEBUG2(), "object_id=".$file->object_id." object_type=".$file->object_type." dbfile=".$file);
|
144 |
143 |
my $sessionfile = $::form->{sessionfile};
|
145 |
|
$main::lxdebug->message(LXDebug->DEBUG2(), "sessionfile=".$sessionfile);
|
146 |
144 |
if ( $sessionfile && -f $sessionfile ) {
|
147 |
|
$main::lxdebug->message(LXDebug->DEBUG2(), "file=".$file->file_name." to=".$::form->{to}." sessionfile=".$sessionfile);
|
148 |
145 |
# new uploaded file
|
149 |
146 |
if ( $::form->{to} eq $file->file_name ) {
|
150 |
147 |
# no rename so use as new version
|
... | ... | |
177 |
174 |
|
178 |
175 |
eval {
|
179 |
176 |
$res = $file->rename($::form->{to});
|
180 |
|
$main::lxdebug->message(LXDebug->DEBUG2(), "rename result=".$res);
|
181 |
177 |
1;
|
182 |
178 |
} or do {
|
183 |
179 |
$self->js->flash( 'error', t8('internal error (see details)'))
|
... | ... | |
222 |
218 |
my ($self) = @_;
|
223 |
219 |
|
224 |
220 |
my $source = 'uploaded';
|
225 |
|
$main::lxdebug->message(LXDebug->DEBUG2(), "file_upload UPLOAD=".$::form->{ATTACHMENTS}->{uploadfiles});
|
226 |
221 |
my @existing;
|
227 |
222 |
if ( $::form->{ATTACHMENTS}->{uploadfiles} ) {
|
228 |
223 |
my @upfiles = @{ $::form->{ATTACHMENTS}->{uploadfiles} };
|
229 |
224 |
foreach my $idx (0 .. scalar(@upfiles) - 1) {
|
230 |
225 |
eval {
|
231 |
226 |
my $fname = uri_unescape($upfiles[$idx]->{filename});
|
232 |
|
$main::lxdebug->message(LXDebug->DEBUG2(), "file_upload name=".$fname);
|
233 |
227 |
## normalize and find basename
|
234 |
228 |
# first split with unix rules
|
235 |
229 |
# after that split with windows rules
|
... | ... | |
250 |
244 |
$mime_type = File::MimeInfo::Magic::mimetype($basefile);
|
251 |
245 |
$mime_type = 'application/octet-stream' if $mime_type eq 'application/pdf' || !$mime_type;
|
252 |
246 |
}
|
253 |
|
$main::lxdebug->message(LXDebug->DEBUG2(), "mime_type=".$mime_type);
|
254 |
247 |
if ( $self->file_type eq 'image' && $self->file_probe_image_type($mime_type, $basefile)) {
|
255 |
248 |
next;
|
256 |
249 |
}
|
... | ... | |
262 |
255 |
file_name => $basefile,
|
263 |
256 |
);
|
264 |
257 |
|
265 |
|
$main::lxdebug->message(LXDebug->DEBUG2(), "store1 exist=".$existobj);
|
266 |
258 |
if ($existobj) {
|
267 |
|
$main::lxdebug->message(LXDebug->DEBUG2(), "id=".$existobj->id." sessionfile=". $sfile->file_name);
|
268 |
259 |
push @existing, $existobj->id.'_'.$sfile->file_name;
|
269 |
260 |
} else {
|
270 |
261 |
my $fileobj = SL::File->save(object_id => $self->object_id,
|
... | ... | |
277 |
268 |
#file_contents => ${$upfiles[$idx]->{data}},
|
278 |
269 |
file_path => $sfile->file_name
|
279 |
270 |
);
|
280 |
|
$main::lxdebug->message(LXDebug->DEBUG2(), "obj=".$fileobj);
|
281 |
271 |
unlink($sfile->file_name);
|
282 |
272 |
}
|
283 |
273 |
1;
|
... | ... | |
338 |
328 |
$self->object_id($id);
|
339 |
329 |
$self->object_model($file_types{$type}->{model});
|
340 |
330 |
$self->object_right($file_types{$type}->{right});
|
341 |
|
$main::lxdebug->message(LXDebug->DEBUG2(), "checked: object_id=".$self->object_id." object_type=".$self->object_type." is_global=".$self->is_global);
|
342 |
331 |
|
343 |
332 |
# $::auth->assert($self->object_right);
|
344 |
333 |
|
... | ... | |
371 |
360 |
sub _do_list {
|
372 |
361 |
my ($self,$json) = @_;
|
373 |
362 |
my @files;
|
374 |
|
$main::lxdebug->message(LXDebug->DEBUG2(), "do_list: object_id=".$self->object_id." object_type=".$self->object_type." file_type=".$self->file_type." json=".$json);
|
375 |
363 |
if ( $self->file_type eq 'document' ) {
|
376 |
364 |
my @object_types;
|
377 |
365 |
push @object_types, $self->object_type;
|
... | ... | |
380 |
368 |
object_type => \@object_types,
|
381 |
369 |
file_type => $self->file_type );
|
382 |
370 |
|
383 |
|
$main::lxdebug->message(LXDebug->DEBUG2(), "cnt1=".scalar(@files));
|
384 |
371 |
}
|
385 |
372 |
elsif ( $self->file_type eq 'attachment' || $self->file_type eq 'image' ) {
|
386 |
373 |
@files = SL::File->get_all(object_id => $self->object_id ,
|
387 |
374 |
object_type => $self->object_type,
|
388 |
375 |
file_type => $self->file_type );
|
389 |
|
$main::lxdebug->message(LXDebug->DEBUG2(), "cnt2=".scalar(@files));
|
390 |
376 |
}
|
391 |
377 |
$self->files(\@files);
|
392 |
378 |
$self->_mk_render('file/list',1,0,$json);
|
... | ... | |
396 |
382 |
my ($self,$path) = @_;
|
397 |
383 |
my @foundfiles ;
|
398 |
384 |
|
399 |
|
$main::lxdebug->message(LXDebug->DEBUG2(), "import path=".$path);
|
400 |
385 |
my $language = $::lx_office_conf{system}->{language};
|
401 |
386 |
my $timezone = $::locale->get_local_time_zone()->name;
|
402 |
387 |
if (opendir my $dir, $path) {
|
... | ... | |
404 |
389 |
foreach my $file ( @files) {
|
405 |
390 |
next if (($file eq '.') || ($file eq '..'));
|
406 |
391 |
$file = Encode::decode('utf-8', $file);
|
407 |
|
$main::lxdebug->message(LXDebug->DEBUG2(), "file=".$file);
|
408 |
392 |
|
409 |
393 |
next if( -d "$path/$file");
|
410 |
394 |
|
411 |
395 |
my $tmppath = File::Spec->catfile( $path, $file );
|
412 |
|
$main::lxdebug->message(LXDebug->DEBUG2(), "tmppath=".$tmppath." file=".$file);
|
413 |
396 |
next if( ! -f $tmppath);
|
414 |
397 |
|
415 |
398 |
my $st = stat($tmppath);
|
... | ... | |
425 |
408 |
|
426 |
409 |
}
|
427 |
410 |
}
|
428 |
|
$main::lxdebug->message(LXDebug->DEBUG2(), "return ".scalar(@foundfiles)." files");
|
429 |
411 |
return @foundfiles;
|
430 |
412 |
}
|
431 |
413 |
|
... | ... | |
436 |
418 |
##TODO here a configurable code must be implemented
|
437 |
419 |
|
438 |
420 |
my $title;
|
439 |
|
$main::lxdebug->message(LXDebug->DEBUG2(), "mk_render: object_id=".$self->object_id." object_type=".$self->object_type.
|
440 |
|
" file_type=".$self->file_type." json=".$json." filecount=".scalar(@{ $self->files })." is_global=".$self->is_global);
|
441 |
421 |
my @sources = $self->_get_sources();
|
442 |
422 |
foreach my $source ( @sources ) {
|
443 |
|
$main::lxdebug->message(LXDebug->DEBUG2(), "mk_render: source name=".$source->{name});
|
444 |
423 |
@{$source->{files}} = grep { $_->source eq $source->{name}} @{ $self->files };
|
445 |
424 |
}
|
446 |
425 |
if ( $self->file_type eq 'document' ) {
|
... | ... | |
467 |
446 |
if ( $self->existing && scalar(@{$self->existing}) > 0) {
|
468 |
447 |
my $first = shift @{$self->existing};
|
469 |
448 |
my ($first_id,$sfile) = split('_',$first,2);
|
470 |
|
#$main::lxdebug->message(LXDebug->DEBUG2(), "id=".$first_id." sessionfile=". $sfile);
|
471 |
449 |
my $file = SL::File->get(id => $first_id );
|
472 |
450 |
$self->js->run('kivi.File.askForRename',$first_id,$file->file_name,$sfile,join (',', @{$self->existing}), $self->is_global);
|
473 |
451 |
}
|
... | ... | |
490 |
468 |
sub _get_sources {
|
491 |
469 |
my ($self) = @_;
|
492 |
470 |
my @sources;
|
493 |
|
$main::lxdebug->message(LXDebug->DEBUG2(), "get_sources file_type=". $self->file_type);
|
494 |
471 |
if ( $self->file_type eq 'document' ) {
|
495 |
472 |
##TODO statt gen neue attribute in filetypes :
|
496 |
473 |
if (($file_types{$self->object_type}->{gen}*1 & 1)==1) {
|
... | ... | |
510 |
487 |
}
|
511 |
488 |
if (($file_types{$self->object_type}->{gen}*1 & 2)==2) {
|
512 |
489 |
my @others = SL::File->get_other_sources();
|
513 |
|
$main::lxdebug->message(LXDebug->DEBUG2(), "other cnt=". scalar(@others));
|
514 |
490 |
foreach my $scanner_or_mailrx (@others) {
|
515 |
491 |
my $other = {
|
516 |
492 |
'name' => $scanner_or_mailrx->{name},
|
... | ... | |
567 |
543 |
};
|
568 |
544 |
push @sources , $attdata;
|
569 |
545 |
}
|
570 |
|
$main::lxdebug->message(LXDebug->DEBUG2(), "get_sources count=".scalar(@sources));
|
571 |
546 |
return @sources;
|
572 |
547 |
}
|
573 |
548 |
|
Filemanagement: DEBUG2 herausgenommen