epic-ts
[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(
29     %params,
30     source    => $params{file_name},
31     form      => $params{form},
32     myconfig  => $params{myconfig}  || \%::myconfig,
33     userspath => $params{userspath} || $::lx_office_conf{paths}->{userspath},
34   );
35 }
36
37 sub available_templates {
38   my ($class) = @_;
39
40   # is there a templates basedir
41   if (!-d $::lx_office_conf{paths}->{templates}) {
42     $::form->error(sprintf($::locale->text("The directory %s does not exist."), $::lx_office_conf{paths}->{templates}));
43   }
44
45   tie my %dir_h, 'IO::Dir', $::lx_office_conf{paths}->{templates};
46
47   my @alldir  = sort grep {
48        -d ($::lx_office_conf{paths}->{templates} . "/$_")
49     && !/^\.\.?$/
50     && !m/\.(?:html|tex|sty|odt|xml|txb)$/
51     && !m/^(?:webpages$|print$|mail$|\.)/
52   } keys %dir_h;
53
54   tie %dir_h, 'IO::Dir', "$::lx_office_conf{paths}->{templates}/print";
55   my @allmaster = (sort grep { -d ("$::lx_office_conf{paths}->{templates}/print" . "/$_") && !/^\.\.?$/ && !/^Standard$/ } keys %dir_h);
56
57   return (
58     print_templates  => \@alldir,
59     master_templates => \@allmaster,
60   );
61 }
62
63 1;