epic-s6ts
[kivitendo-erp.git] / SL / Template.pm
index df18e70..b20a7b1 100644 (file)
@@ -10,19 +10,53 @@ package SL::Template;
 
 use strict;
 
+use IO::Dir;
+
 use SL::Template::Simple;
 use SL::Template::Excel;
 use SL::Template::HTML;
 use SL::Template::LaTeX;
 use SL::Template::OpenDocument;
 use SL::Template::PlainText;
-use SL::Template::XML;
+use SL::Template::ShellCommand;
 
 sub create {
   my %params  = @_;
   my $package = "SL::Template::" . $params{type};
 
-  $package->new($params{file_name}, $params{form}, $params{myconfig} || \%::myconfig, $params{userspath} || $::lx_office_conf{paths}->{userspath});
+  $package->new(
+    %params,
+    source    => $params{file_name},
+    form      => $params{form},
+    myconfig  => $params{myconfig}  || \%::myconfig,
+    userspath => $params{userspath} || $::lx_office_conf{paths}->{userspath},
+  );
+}
+
+sub available_templates {
+  my ($class) = @_;
+
+  # is there a templates basedir
+  if (!-d $::lx_office_conf{paths}->{templates}) {
+    $::form->error(sprintf($::locale->text("The directory %s does not exist."), $::lx_office_conf{paths}->{templates}));
+  }
+
+  tie my %dir_h, 'IO::Dir', $::lx_office_conf{paths}->{templates};
+
+  my @alldir  = sort grep {
+       -d ($::lx_office_conf{paths}->{templates} . "/$_")
+    && !/^\.\.?$/
+    && !m/\.(?:html|tex|sty|odt)$/
+    && !m/^(?:webpages$|mobile_webpages$|pdf$|print$|mail$|\.)/
+  } keys %dir_h;
+
+  tie %dir_h, 'IO::Dir', "$::lx_office_conf{paths}->{templates}/print";
+  my @allmaster = (sort grep { -d ("$::lx_office_conf{paths}->{templates}/print" . "/$_") && !/^\.\.?$/ && !/^Standard$/ } keys %dir_h);
+
+  return (
+    print_templates  => \@alldir,
+    master_templates => \@allmaster,
+  );
 }
 
 1;