$form->{path} entfernt und hardcodiert auf bin/mozilla gesetzt.
[kivitendo-erp.git] / bin / mozilla / amtemplates.pl
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 # SQL-Ledger Accounting
9 # Copyright (c) 1998-2002
10 #
11 #  Author: Dieter Simader
12 #   Email: dsimader@sql-ledger.org
13 #     Web: http://www.sql-ledger.org
14 #
15 #
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
20 #
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #======================================================================
29 #
30 # administration
31 #
32 #======================================================================
33
34 use SL::AM;
35 use SL::Form;
36
37 use Data::Dumper;
38
39 1;
40
41 require "bin/mozilla/common.pl";
42
43 # end of main
44
45 sub display {
46   call_sub($form->{display_nextsub});
47 }
48
49 sub save {
50   call_sub($form->{save_nextsub});
51 }
52
53 sub edit {
54   call_sub($form->{edit_nextsub});
55 }
56
57 sub display_template {
58   $lxdebug->enter_sub();
59
60   $form->{edit} = 0;
61   display_template_form();
62
63   $lxdebug->leave_sub();
64 }
65
66 sub edit_template {
67   $lxdebug->enter_sub();
68
69   $form->{edit} = 1;
70   display_template_form();
71
72   $lxdebug->leave_sub();
73 }
74
75 sub save_template {
76   $lxdebug->enter_sub();
77
78   $form->isblank("formname", $locale->text("You're not editing a file.")) unless ($form->{type} eq "stylesheet");
79
80   my ($filename) = AM->prepare_template_filename(\%myconfig, $form);
81   if (my $error = AM->save_template($filename, $form->{content})) {
82     $form->error(sprintf($locale->text("Saving the file '%s' failed. OS error message: %s"), $filename, $error));
83   }
84
85   $form->{edit} = 0;
86   display_template_form();
87
88   $lxdebug->leave_sub();
89 }
90
91 sub display_template_form {
92   $lxdebug->enter_sub();
93
94   $form->{"formname"} =~ s|.*/||;
95   my $format = $form->{"format"} eq "html" ? "html" : "tex";
96
97   $form->{"title"} = $form->{"type"} eq "stylesheet" ? $locale->text("Edit the stylesheet") : $locale->text("Edit templates");
98
99   my %options;
100
101   my @hidden = qw(login password type format);
102
103   if (($form->{"type"} ne "stylesheet") && !$form->{"edit"}) {
104     $options{"SHOW_EDIT_OPTIONS"} = 1;
105
106     #
107     # Setup "formname" selection
108     #
109
110     my %formname_setup =
111       (
112        "balance_sheet" => { "translation" => $locale->text('Balance Sheet'), "html" => 1 },
113        "bin_list" => $locale->text('Bin List'),
114        "bwa" => { "translation" => $locale->text('BWA'), "html" => 1 },
115        "check" => { "translation" => $locale->text('Check'), "html" => 1 },
116        "credit_note" => $locale->text('Credit Note'),
117        "income_statement" => { "translation" => $locale->text('Income Statement'), "html" => 1 },
118        "invoice" => $locale->text('Invoice'),
119        "packing_list" => $locale->text('Packing List'),
120        "pick_list" => $locale->text('Pick List'),
121        "proforma" => $locale->text('Proforma Invoice'),
122        "purchase_order" => $locale->text('Purchase Order'),
123        "receipt" => { "translation" => $locale->text('Receipt'), "tex" => 1 },
124        "request_quotation" => $locale->text('RFQ'),
125        "sales_order" => $locale->text('Confirmation'),
126        "sales_quotation" => $locale->text('Quotation'),
127        "statement" => $locale->text('Statement'),
128        "storno_invoice" => $locale->text('Storno Invoice'),
129        "storno_packing_list" => $locale->text('Storno Packing List'),
130        "ustva-2004" => { "translation" => $locale->text("USTVA 2004"), "tex" => 1 },
131        "ustva-2005" => { "translation" => $locale->text("USTVA 2005"), "tex" => 1 },
132        "ustva-2006" => { "translation" => $locale->text("USTVA 2006"), "tex" => 1 },
133        "ustva-2007" => { "translation" => $locale->text("USTVA 2007"), "tex" => 1 },
134        "ustva" => $locale->text("USTVA"),
135        "zahlungserinnerung" => $locale->text('Payment Reminder'),
136       );
137
138     my (@values, $file, $setup);
139
140     while (($file, $setup) = each(%formname_setup)) {
141       next if ref($setup) && !$setup->{$format};
142
143       push(@values,
144            { "value"   => $file,
145              "label"   => ref($setup) ? $setup->{"translation"} : $setup,
146              "default" => $file eq $form->{"formname"} });
147     }
148
149     @values = sort({ $a->{"label"} cmp $b->{"label"} } @values);
150
151     $options{"FORMNAME"} = [ @values ];
152
153     #
154     # Setup "language" selection
155     #
156
157     $form->get_lists("printers" => "ALL_PRINTERS",
158                      "languages" => "ALL_LANGUAGES");
159
160     @values = ( { "value" => "", "label" => "", "default" => 0 } );
161
162     foreach my $item (@{ $form->{"ALL_LANGUAGES"} }) {
163       next unless ($item->{"template_code"});
164
165       my $key = "$item->{id}--$item->{template_code}";
166
167       push(@values,
168            { "value"   => $key,
169              "label"   => $item->{"description"},
170              "default" => $key eq $form->{"language"} });
171     }
172
173     $options{"LANGUAGE"} = [ @values ];
174     $options{"SHOW_LANGUAGE"} = scalar(@values) > 1;
175
176     @values = ( { "value" => "", "label" => "", "default" => 0 } );
177
178     #
179     # Setup "printer" selection
180     #
181
182     foreach my $item (@{ $form->{"ALL_PRINTERS"} }) {
183       next unless ($item->{"template_code"});
184
185       my $key = "$item->{id}--$item->{template_code}";
186
187       push(@values,
188            { "value"   => $key,
189              "label"   => $item->{"printer_description"},
190              "default" => $key eq $form->{"printer"} });
191     }
192
193     $options{"PRINTER"} = [ @values ];
194     $options{"SHOW_PRINTER"} = scalar(@values) > 1;
195
196   } else {
197     push(@hidden, qw(formname language printer));
198   }
199
200   if ($form->{formname} || ($form->{type} eq "stylesheet")) {
201     $options{"SHOW_CONTENT"} = 1;
202
203     ($options{"filename"}, $options{"display_filename"})
204       = AM->prepare_template_filename(\%myconfig, $form);
205
206     ($options{"content"}, $options{"lines"})
207       = AM->load_template($options{"filename"});
208
209     $options{"CAN_EDIT"} = $form->{"edit"};
210
211     if ($form->{edit}) {
212       $form->{fokus} = "Form.content";
213
214     } else {
215       $options{"content"}                 = "\n\n" if (!$options{"content"});
216       $options{"SHOW_SECOND_EDIT_BUTTON"} = $options{"lines"} > 25;
217     }
218   }
219
220   $options{"HIDDEN"} = [ map(+{ "name" => $_, "value" => $form->{$_} }, @hidden) ];
221
222   $form->header;
223   print($form->parse_html_template("am/edit_templates", \%options));
224
225   $lxdebug->leave_sub();
226 }
227
228 1;