From 8e2065873b0e00dde437383bb22c57be508e331f Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 15 Feb 2007 10:10:48 +0000 Subject: [PATCH] Bugfixes und Code-Reorganisierung beim "Webdav"-Feature. Beim Anlegen von Verzeichnissen werden auch eventuell fehlende Elternverzeichnisse angelegt. Bei jedem Neuaufbau der Maske wird die Liste der vorhandenen Dateien aktualisiert, nicht nur beim Speichern & Laden. --- SL/Common.pm | 76 +++++++++++++++++++++++++++++++++++++++++++++++ SL/IR.pm | 42 ++------------------------ SL/IS.pm | 40 ++----------------------- SL/OE.pm | 45 +++------------------------- bin/mozilla/io.pl | 2 ++ doc/changelog | 5 ++++ 6 files changed, 93 insertions(+), 117 deletions(-) diff --git a/SL/Common.pm b/SL/Common.pm index 33a6e2a6a..3d923780b 100644 --- a/SL/Common.pm +++ b/SL/Common.pm @@ -187,4 +187,80 @@ sub retrieve_vendor { return $vendors; } +sub mkdir_with_parents { + $main::lxdebug->enter_sub(); + + my ($full_path) = @_; + + my $path = ""; + + $full_path =~ s|/+|/|; + + foreach my $part (split(m|/|, $full_path)) { + $path .= "/" if ($path); + $path .= $part; + + die("Could not create directory '$path' because a file exists with " . + "the same name.\n") if (-f $path); + + if (! -d $path) { + mkdir($path, 0770) || die("Could not create the directory '$path'. " . + "OS error: $!\n"); + } + } + + $main::lxdebug->leave_sub(); +} + +sub webdav_folder { + $main::lxdebug->enter_sub(); + + my ($form) = @_; + + return $main::lxdebug->leave_sub() + unless ($main::webdav && $form->{id}); + + my ($path, $number); + + $form->{WEBDAV} = {}; + + if ($form->{type} eq "sales_quotation") { + ($path, $number) = ("angebote", $form->{quonumber}); + } elsif ($form->{type} eq "sales_order") { + ($path, $number) = ("bestellungen", $form->{ordnumber}); + } elsif ($form->{type} eq "request_quotation") { + ($path, $number) = ("anfragen", $form->{quonumber}); + } elsif ($form->{type} eq "purchase_order") { + ($path, $number) = ("lieferantenbestellungen", $form->{ordnumber}); + } elsif ($form->{type} eq "credit_note") { + ($path, $number) = ("gutschriften", $form->{invnumber}); + } elsif ($form->{vc} eq "customer") { + ($path, $number) = ("rechnungen", $form->{invnumber}); + } else { + ($path, $number) = ("einkaufsrechnungen", $form->{invnumber}); + } + + return $main::lxdebug->leave_sub() unless ($path && $number); + + $path = "webdav/${path}/${number}"; + + if (!-d $path) { + mkdir_with_parents($path); + + } else { + my $base_path = substr($ENV{'SCRIPT_NAME'}, 1); + $base_path =~ s|[^/]+$||; + + foreach my $file (<$path/*>) { + my $fname = $file; + $fname =~ s|.*/||; + $form->{WEBDAV}{$fname} = + ($ENV{"HTTPS"} ? "https://" : "http://") . + $ENV{'SERVER_NAME'} . "/" . $base_path . $file; + } + } + + $main::lxdebug->leave_sub(); +} + 1; diff --git a/SL/IR.pm b/SL/IR.pm index ae3a3d4e1..af80fce2c 100644 --- a/SL/IR.pm +++ b/SL/IR.pm @@ -35,6 +35,7 @@ package IR; use SL::AM; +use SL::Common; use SL::DBUtils; sub post_invoice { @@ -665,9 +666,7 @@ sub post_invoice { WHERE amount = 0|; $dbh->do($query) || $form->dberror($query); - if ($form->{webdav}) { - &webdav_folder($myconfig, $form); - } + Common::webdav_folder($form) if ($main::webdav); my $rc = $dbh->commit; $dbh->disconnect; @@ -963,10 +962,7 @@ sub retrieve_invoice { } $sth->finish; - if ($form->{webdav}) { - &webdav_folder($myconfig, $form); - } - + Common::webdav_folder($form) if ($main::webdav); } my $rc = $dbh->commit; @@ -1288,38 +1284,6 @@ sub item_links { $main::lxdebug->leave_sub(); } -sub webdav_folder { - $main::lxdebug->enter_sub(); - - my ($myconfig, $form) = @_; - -SWITCH: { - $path = "webdav/rechnungen/" . $form->{invnumber}, last SWITCH - if ($form->{vc} eq "customer"); - $path = "webdav/einkaufsrechnungen/" . $form->{invnumber}, last SWITCH - if ($form->{vc} eq "vendor"); - } - - if (!-d $path) { - mkdir($path, 0770) or die "can't make directory $!\n"; - } else { - if ($form->{id}) { - @files = <$path/*>; - foreach $file (@files) { - - $file =~ /\/([^\/]*)$/; - $fname = $1; - $ENV{'SCRIPT_NAME'} =~ /\/([^\/]*)\//; - $lxerp = $1; - $link = "http://" . $ENV{'SERVER_NAME'} . "/" . $lxerp . "/" . $file; - $form->{WEBDAV}{$fname} = $link; - } - } - } - - $main::lxdebug->leave_sub(); -} - sub post_payment { $main::lxdebug->enter_sub(); diff --git a/SL/IS.pm b/SL/IS.pm index e59f2546d..b59561656 100644 --- a/SL/IS.pm +++ b/SL/IS.pm @@ -36,6 +36,7 @@ package IS; use Data::Dumper; use SL::AM; +use SL::Common; use SL::DBUtils; sub invoice_details { @@ -1038,9 +1039,7 @@ Message: $form->{message}\r| if $form->{message}; # save printed, emailed and queued $form->save_status($dbh); - if ($form->{webdav}) { - &webdav_folder($myconfig, $form); - } + Common::webdav_folder($form) if ($main::webdav); my $rc = $dbh->commit; $dbh->disconnect; @@ -1658,9 +1657,7 @@ sub retrieve_invoice { } $sth->finish; - if ($form->{webdav}) { - &webdav_folder($myconfig, $form); - } + Common::webdav_folder($form) if ($main::webdav); } my $rc = $dbh->commit; @@ -2185,36 +2182,5 @@ sub get_pricegroups_for_parts { $main::lxdebug->leave_sub(); } -sub webdav_folder { - $main::lxdebug->enter_sub(); - - my ($myconfig, $form) = @_; - -SWITCH: { - $path = "webdav/rechnungen/" . $form->{invnumber}, last SWITCH - if ($form->{vc} eq "customer"); - $path = "webdav/einkaufsrechnungen/" . $form->{invnumber}, last SWITCH - if ($form->{vc} eq "vendor"); - } - - if (!-d $path) { - mkdir($path, 0770) or die "can't make directory $!\n"; - } else { - if ($form->{id}) { - @files = <$path/*>; - foreach $file (@files) { - $file =~ /\/([^\/]*)$/; - $fname = $1; - $ENV{'SCRIPT_NAME'} =~ /\/([^\/]*)\//; - $lxerp = $1; - $link = "http://" . $ENV{'SERVER_NAME'} . "/" . $lxerp . "/" . $file; - $form->{WEBDAV}{$fname} = $link; - } - } - } - - $main::lxdebug->leave_sub(); -} - 1; diff --git a/SL/OE.pm b/SL/OE.pm index c1d97a593..48ff26e30 100644 --- a/SL/OE.pm +++ b/SL/OE.pm @@ -35,6 +35,7 @@ package OE; use SL::AM; +use SL::Common; use SL::DBUtils; sub transactions { @@ -481,10 +482,6 @@ Message: $form->{message}\r| if $form->{message}; $form->{ordtotal} = $amount; - if ($form->{webdav}) { - &webdav_folder($myconfig, $form); - } - # add shipto $form->{name} = $form->{ $form->{vc} }; $form->{name} =~ s/--$form->{"$form->{vc}_id"}//; @@ -517,6 +514,8 @@ Message: $form->{message}\r| if $form->{message}; my $rc = $dbh->commit; $dbh->disconnect; + Common::webdav_folder($form) if ($main::webdav); + $main::lxdebug->leave_sub(); return $rc; @@ -916,9 +915,7 @@ sub retrieve { $form->get_exchangerate($dbh, $form->{currency}, $form->{transdate}, ($form->{vc} eq 'customer') ? "buy" : "sell"); - if ($form->{webdav}) { - &webdav_folder($myconfig, $form); - } + Common::webdav_folder($form) if ($main::webdav); # get tax zones $query = qq|SELECT id, description @@ -1641,39 +1638,5 @@ sub transfer { return $rc; } -sub webdav_folder { - $main::lxdebug->enter_sub(); - - my ($myconfig, $form) = @_; - -SWITCH: { - $path = "webdav/angebote/" . $form->{quonumber}, last SWITCH - if ($form->{type} eq "sales_quotation"); - $path = "webdav/bestellungen/" . $form->{ordnumber}, last SWITCH - if ($form->{type} eq "sales_order"); - $path = "webdav/anfragen/" . $form->{quonumber}, last SWITCH - if ($form->{type} eq "request_quotation"); - $path = "webdav/lieferantenbestellungen/" . $form->{ordnumber}, last SWITCH - if ($form->{type} eq "purchase_order"); - } - - if (!-d $path) { - mkdir($path, 0770) or die "can't make directory $!\n"; - } else { - if ($form->{id}) { - @files = <$path/*>; - foreach $file (@files) { - $file =~ /\/([^\/]*)$/; - $fname = $1; - $ENV{'SCRIPT_NAME'} =~ /\/([^\/]*)\//; - $lxerp = $1; - $link = "http://" . $ENV{'SERVER_NAME'} . "/" . $lxerp . "/" . $file; - $form->{WEBDAV}{$fname} = $link; - } - } - } - - $main::lxdebug->leave_sub(); -} 1; diff --git a/bin/mozilla/io.pl b/bin/mozilla/io.pl index d0257e17b..312003aec 100644 --- a/bin/mozilla/io.pl +++ b/bin/mozilla/io.pl @@ -889,6 +889,8 @@ sub display_form { exit; } + Common::webdav_folder($form) if ($webdav); + # if ( $form->{print_and_post} # && $form->{second_run} # && ($form->{action} eq "display_form")) { diff --git a/doc/changelog b/doc/changelog index 5489c077b..e34d637fa 100644 --- a/doc/changelog +++ b/doc/changelog @@ -3,6 +3,11 @@ #################################### 2007-02-?? - Version 2.4.2 + - Bugfixes und Code-Reorganisierung beim "Webdav"-Feature. Beim + Anlegen von Verzeichnissen werden auch eventuell fehlende + Elternverzeichnisse angelegt. Bei jedem Neuaufbau der Maske wird + die Liste der vorhandenen Dateien aktualisiert, nicht nur beim + Speichern & Laden. - Bei höheren Mahnstufen wurde die Rechnung mehrmals angezeigt - In der Uebersicht der Mahnungen hat ein Klick auf die Rechnungsnummer nicht die Rechnungsmaske geöffnet -- 2.20.1