kosmetik
[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 use strict;
40
41 1;
42
43 require "bin/mozilla/common.pl";
44
45 # end of main
46
47 sub display {
48   call_sub($main::form->{display_nextsub});
49 }
50
51 sub save {
52   call_sub($main::form->{save_nextsub});
53 }
54
55 sub edit {
56   call_sub($main::form->{edit_nextsub});
57 }
58
59 sub display_template {
60   $main::lxdebug->enter_sub();
61
62   my $form     = $main::form;
63
64   $main::auth->assert('config');
65
66   $form->{edit} = 0;
67   display_template_form();
68
69   $main::lxdebug->leave_sub();
70 }
71
72 sub edit_template {
73   $main::lxdebug->enter_sub();
74
75   my $form     = $main::form;
76
77   $main::auth->assert('config');
78
79   $form->{edit} = 1;
80   display_template_form();
81
82   $main::lxdebug->leave_sub();
83 }
84
85 sub save_template {
86   $main::lxdebug->enter_sub();
87
88   my $form     = $main::form;
89   my %myconfig = %main::myconfig;
90   my $locale   = $main::locale;
91
92   $main::auth->assert('config');
93
94   $form->isblank("formname", $locale->text("You're not editing a file.")) unless ($form->{type} eq "stylesheet");
95
96   my ($filename) = AM->prepare_template_filename(\%myconfig, $form);
97   if (my $error = AM->save_template($filename, $form->{content})) {
98     $form->error(sprintf($locale->text("Saving the file '%s' failed. OS error message: %s"), $filename, $error));
99   }
100
101   $form->{edit} = 0;
102   display_template_form();
103
104   $main::lxdebug->leave_sub();
105 }
106
107 sub display_template_form {
108   $main::lxdebug->enter_sub();
109
110   my $form     = $main::form;
111   my %myconfig = %main::myconfig;
112   my $locale   = $main::locale;
113
114   $main::auth->assert('config');
115
116   $form->{"formname"} =~ s|.*/||;
117   my $format = $form->{"format"} eq "html" ? "html" : "tex";
118
119   $form->{"title"} = $form->{"type"} eq "stylesheet" ? $locale->text("Edit the stylesheet") : $locale->text("Edit templates");
120
121   my %options;
122
123   my @hidden = qw(type format);
124
125   if (($form->{"type"} ne "stylesheet") && !$form->{"edit"}) {
126     $options{"SHOW_EDIT_OPTIONS"} = 1;
127
128     #
129     # Setup "formname" selection
130     #
131
132     $form->get_lists("printers" => "ALL_PRINTERS",
133                      "languages" => "ALL_LANGUAGES",
134                      "dunning_configs" => "ALL_DUNNING_CONFIGS");
135
136     my %formname_setup =
137       (
138 #        "balance_sheet"       => { "translation" => $locale->text('Balance Sheet'), "html" => 1 },
139         "bin_list"            => $locale->text('Bin List'),
140         "bwa"                 => { "translation" => $locale->text('BWA'), "html" => 1 },
141         "check"               => { "translation" => $locale->text('Check'), "html" => 1 },
142         "credit_note"         => $locale->text('Credit Note'),
143         "income_statement"    => { "translation" => $locale->text('Income Statement'), "html" => 1 },
144         "invoice"             => $locale->text('Invoice'),
145         "packing_list"        => $locale->text('Packing List'),
146         "pick_list"           => $locale->text('Pick List'),
147         "proforma"            => $locale->text('Proforma Invoice'),
148         "purchase_order"      => $locale->text('Purchase Order'),
149         "receipt"             => { "translation" => $locale->text('Receipt'), "tex" => 1 },
150         "request_quotation"   => $locale->text('RFQ'),
151         "sales_order"         => $locale->text('Confirmation'),
152         "sales_quotation"     => $locale->text('Quotation'),
153         "statement"           => $locale->text('Statement'),
154         "storno_invoice"      => $locale->text('Storno Invoice'),
155         "storno_packing_list" => $locale->text('Storno Packing List'),
156         "ustva-2004"          => { "translation" => $locale->text("USTVA 2004"), "tex" => 1 },
157         "ustva-2005"          => { "translation" => $locale->text("USTVA 2005"), "tex" => 1 },
158         "ustva-2006"          => { "translation" => $locale->text("USTVA 2006"), "tex" => 1 },
159         "ustva-2007"          => { "translation" => $locale->text("USTVA 2007"), "tex" => 1 },
160         "ustva"               => $locale->text("USTVA"),
161       );
162
163     my (@values, $file, $setup);
164
165     while (($file, $setup) = each(%formname_setup)) {
166       next if ref($setup) && !$setup->{$format};
167
168       push(@values,
169            { "value"   => $file,
170              "label"   => ref($setup) ? $setup->{"translation"} : $setup });
171     }
172
173     # "zahlungserinnerung" => $locale->text('Payment Reminder'),
174
175     foreach my $ref (@{ $form->{"ALL_DUNNING_CONFIGS"} }) {
176       next if !$ref->{"template"};
177
178       push(@values,
179            { "value" => $ref->{"template"},
180              "label" => $locale->text('Payment Reminder') . ": " . $ref->{"dunning_description"} },
181            { "value" => $ref->{"template"} . "_invoice",
182              "label" => $locale->text('Payment Reminder') . ": " . $ref->{"dunning_description"} . ' (' . $locale->text("Invoice for fees") . ')' });
183     }
184
185     @values = sort({ $a->{"label"} cmp $b->{"label"} } @values);
186
187     $options{FORMNAME} = [ @values ];
188
189     #
190     # Setup "language" selection
191     #
192
193     @values = ();
194
195     foreach my $item (@{ $form->{"ALL_LANGUAGES"} }) {
196       next unless ($item->{"template_code"});
197
198       push(@values,
199            { "value" => "$item->{id}--$item->{template_code}",
200              "label" => $item->{"description"} });
201     }
202
203     $options{LANGUAGE} = [ @values ];
204
205     #
206     # Setup "printer" selection
207     #
208
209     @values = ();
210
211     foreach my $item (@{ $form->{"ALL_PRINTERS"} }) {
212       next unless ($item->{"template_code"});
213
214       push(@values,
215            { "value" => "$item->{id}--$item->{template_code}",
216              "label" => $item->{"printer_description"} });
217     }
218
219     $options{PRINTER} = [ @values ];
220
221   } else {
222     push(@hidden, qw(formname language printer));
223   }
224
225   if ($form->{formname} || ($form->{type} eq "stylesheet")) {
226     $options{"SHOW_CONTENT"} = 1;
227
228     ($options{"filename"}, $options{"display_filename"})
229       = AM->prepare_template_filename(\%myconfig, $form);
230
231     ($options{"content"}, $options{"lines"})
232       = AM->load_template($options{"filename"});
233
234     $options{"CAN_EDIT"} = $form->{"edit"};
235
236     if ($form->{edit}) {
237       $form->{fokus} = "Form.content";
238
239     } else {
240       $options{"content"}                 = "\n\n" if (!$options{"content"});
241       $options{"SHOW_SECOND_EDIT_BUTTON"} = $options{"lines"} > 25;
242     }
243   }
244
245   $options{"HIDDEN"} = [ map(+{ "name" => $_, "value" => $form->{$_} }, @hidden) ];
246
247   $form->header;
248   print($form->parse_html_template("am/edit_templates", \%options));
249
250   $main::lxdebug->leave_sub();
251 }
252
253 1;