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