X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FTemplate.pm;h=f76796759dd35bada4f535c96b1764bba9ecc2d8;hb=ad7353df162d32e3b6f9348a5f8c1310079e6110;hp=3556dc49a6de3831ccb9e4427b92b9df88ad068a;hpb=16fc2b202976d5aba5a634a0574184c2b8d6de5f;p=kivitendo-erp.git diff --git a/SL/Template.pm b/SL/Template.pm index 3556dc49a..f76796759 100644 --- a/SL/Template.pm +++ b/SL/Template.pm @@ -838,9 +838,12 @@ sub parse { package OpenDocumentTemplate; +use Archive::Zip; use POSIX 'setsid'; use vars qw(@ISA); +use SL::Iconv; + use Cwd; # use File::Copy; # use File::Spec; @@ -856,19 +859,8 @@ sub new { my $self = $type->SUPER::new(@_); - foreach my $module (qw(Archive::Zip Text::Iconv)) { - eval("use ${module};"); - if ($@) { - $self->{"form"}->error("The Perl module '${module}' could not be " . - "loaded. Support for OpenDocument templates " . - "does not work without it. Please install your " . - "distribution's package or get the module from " . - "CPAN ( http://www.cpan.org )."); - } - } - $self->{"rnd"} = int(rand(1000000)); - $self->{"iconv"} = Text::Iconv->new($main::dbcharset, "UTF-8"); + $self->{"iconv"} = SL::Iconv->new($main::dbcharset, "UTF-8"); $self->set_tag_style('<%', '%>'); $self->{quot_re} = '"'; @@ -1477,4 +1469,95 @@ sub uses_temp_file { return 1; } + +########################################################## +#### +#### ExcelTemplate +#### +########################################################## + +package ExcelTemplate; + +use vars qw(@ISA); + +@ISA = qw(SimpleTemplate); + +sub new { + my $type = shift; + + my $self = $type->SUPER::new(@_); + + return $self; +} +sub _init { + my $self = shift; + + $self->{source} = shift; + $self->{form} = shift; + $self->{myconfig} = shift; + $self->{userspath} = shift; + + $self->{error} = undef; + + $self->set_tag_style('<<', '>>'); +} + +sub get_mime_type() { + my ($self) = @_; + + return "application/msexcel"; +} + +sub uses_temp_file { + return 1; +} + +sub parse { + $main::lxdebug->enter_sub(); + + my $self = shift; + local *OUT = shift; + my $form = $self->{"form"}; + + open(IN, "$form->{templates}/$form->{IN}") or do { $self->{"error"} = "$!"; return 0; }; + my @lines = ; + close IN; + + my $contents = join("", @lines); + my @indices; + $contents =~ s{ + $self->{tag_start} [<]* (\s?) [<>\s]* ([\w\s]+) [<>\s]* $self->{tag_end} + }{ + $self->format_vars(align_right => $1 ne '', varstring => $2, length => length($&), indices => \@indices) + }egx; + + if (!defined($contents)) { + $main::lxdebug->leave_sub(); + return 0; + } + + print OUT $contents; + + $main::lxdebug->leave_sub(); + return 1; +} + +sub format_vars { + my ($self, %params) = @_; + my $form = $self->{"form"}; + my @indices = @{ $params{indices} }; + my $align_right = $params{align_right}; + my $varstring = $params{varstring}; + my $length = $params{length}; + + $varstring =~ s/(\w+)/ $self->_get_loop_variable($1, 0, @indices) /eg; + my $old_string=$varstring; + my $new_string = sprintf "%*s", ($align_right ? 1 : -1 ) * $length, $varstring; + if (!defined($new_string) || $new_string eq ''){ + $main::lxdebug->message(0, 'varstring' . $varstring . "old" . $old_string); + # return substr $varstring, ($align_right ? (0, $length) : -$length); + } + return substr $new_string, ($align_right ? (0, $length) : -$length); +} + 1;