Funktion zum Auflisten vorhandener Druckvorlagen nach SL::Template verschoben
[kivitendo-erp.git] / SL / Template.pm
1 #====================================================================
2 # LX-Office ERP
3 # Copyright (C) 2004
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
6 #
7 #====================================================================
8
9 package SL::Template;
10
11 use strict;
12
13 use IO::Dir;
14
15 use SL::Template::Simple;
16 use SL::Template::Excel;
17 use SL::Template::HTML;
18 use SL::Template::LaTeX;
19 use SL::Template::OpenDocument;
20 use SL::Template::PlainText;
21 use SL::Template::ShellCommand;
22 use SL::Template::XML;
23
24 sub create {
25   my %params  = @_;
26   my $package = "SL::Template::" . $params{type};
27
28   $package->new($params{file_name}, $params{form}, $params{myconfig} || \%::myconfig, $params{userspath} || $::lx_office_conf{paths}->{userspath});
29 }
30
31 sub available_templates {
32   my ($class) = @_;
33
34   # is there a templates basedir
35   if (!-d $::lx_office_conf{paths}->{templates}) {
36     $::form->error(sprintf($::locale->text("The directory %s does not exist."), $::lx_office_conf{paths}->{templates}));
37   }
38
39   tie my %dir_h, 'IO::Dir', $::lx_office_conf{paths}->{templates};
40
41   my @alldir  = sort grep {
42        -d ($::lx_office_conf{paths}->{templates} . "/$_")
43     && !/^\.\.?$/
44     && !m/\.(?:html|tex|sty|odt|xml|txb)$/
45     && !m/^(?:webpages$|print$|mail$|\.)/
46   } keys %dir_h;
47
48   tie %dir_h, 'IO::Dir', "$::lx_office_conf{paths}->{templates}/print";
49   my @allmaster = ('Standard', sort grep { -d ("$::lx_office_conf{paths}->{templates}/print" . "/$_") && !/^\.\.?$/ && !/^Standard$/ } keys %dir_h);
50
51   return (
52     print_templates  => \@alldir,
53     master_templates => \@allmaster,
54   );
55 }
56
57 1;