Teil 1 von: Usability und Lokalisierung de und de_DE (neu)
[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   if ($form->{"format"}) {
121       $form->{"title"} = uc($form->{"format"}) . " - " . $form->{"title"};
122   }
123
124   my %options;
125
126   my @hidden = qw(type format);
127
128   if (($form->{"type"} ne "stylesheet") && !$form->{"edit"}) {
129     $options{"SHOW_EDIT_OPTIONS"} = 1;
130
131     #
132     # Setup "formname" selection
133     #
134
135     $form->get_lists("printers" => "ALL_PRINTERS",
136                      "languages" => "ALL_LANGUAGES",
137                      "dunning_configs" => "ALL_DUNNING_CONFIGS");
138
139     my %formname_setup =
140       (
141 #        "balance_sheet"       => { "translation" => $locale->text('Balance Sheet'), "html" => 1 },
142         "bin_list"            => $locale->text('Bin List'),
143         "bwa"                 => { "translation" => $locale->text('BWA'), "html" => 1 },
144         "check"               => { "translation" => $locale->text('Check'), "html" => 1 },
145         "credit_note"         => $locale->text('Credit Note'),
146         "income_statement"    => { "translation" => $locale->text('Income Statement'), "html" => 1 },
147         "invoice"             => $locale->text('Invoice'),
148         "packing_list"        => $locale->text('Packing List'),
149         "pick_list"           => $locale->text('Pick List'),
150         "proforma"            => $locale->text('Proforma Invoice'),
151         "purchase_order"      => $locale->text('Purchase Order'),
152         "receipt"             => { "translation" => $locale->text('Receipt'), "tex" => 1 },
153         "request_quotation"   => $locale->text('RFQ'),
154         "sales_order"         => $locale->text('Confirmation'),
155         "sales_quotation"     => $locale->text('Quotation'),
156         "statement"           => $locale->text('Statement'),
157         "storno_invoice"      => $locale->text('Storno Invoice'),
158         "storno_packing_list" => $locale->text('Storno Packing List'),
159         "ustva-2004"          => { "translation" => $locale->text("USTVA 2004"), "tex" => 1 },
160         "ustva-2005"          => { "translation" => $locale->text("USTVA 2005"), "tex" => 1 },
161         "ustva-2006"          => { "translation" => $locale->text("USTVA 2006"), "tex" => 1 },
162         "ustva-2007"          => { "translation" => $locale->text("USTVA 2007"), "tex" => 1 },
163         "ustva"               => $locale->text("USTVA"),
164       );
165
166     my (@values, $file, $setup);
167
168     while (($file, $setup) = each(%formname_setup)) {
169       next if ref($setup) && !$setup->{$format};
170
171       push(@values,
172            { "value"   => $file,
173              "label"   => ref($setup) ? $setup->{"translation"} : $setup });
174     }
175
176     # "zahlungserinnerung" => $locale->text('Payment Reminder'),
177
178     foreach my $ref (@{ $form->{"ALL_DUNNING_CONFIGS"} }) {
179       next if !$ref->{"template"};
180
181       push(@values,
182            { "value" => $ref->{"template"},
183              "label" => $locale->text('Payment Reminder') . ": " . $ref->{"dunning_description"} },
184            { "value" => $ref->{"template"} . "_invoice",
185              "label" => $locale->text('Payment Reminder') . ": " . $ref->{"dunning_description"} . ' (' . $locale->text("Invoice for fees") . ')' });
186     }
187
188     @values = sort({ $a->{"label"} cmp $b->{"label"} } @values);
189
190     $options{FORMNAME} = [ @values ];
191
192     #
193     # Setup "language" selection
194     #
195
196     @values = ();
197
198     foreach my $item (@{ $form->{"ALL_LANGUAGES"} }) {
199       next unless ($item->{"template_code"});
200
201       push(@values,
202            { "value" => "$item->{id}--$item->{template_code}",
203              "label" => $item->{"description"} });
204     }
205
206     $options{LANGUAGE} = [ @values ];
207
208     #
209     # Setup "printer" selection
210     #
211
212     @values = ();
213
214     foreach my $item (@{ $form->{"ALL_PRINTERS"} }) {
215       next unless ($item->{"template_code"});
216
217       push(@values,
218            { "value" => "$item->{id}--$item->{template_code}",
219              "label" => $item->{"printer_description"} });
220     }
221
222     $options{PRINTER} = [ @values ];
223
224   } else {
225     push(@hidden, qw(formname language printer));
226   }
227
228   if ($form->{formname} || ($form->{type} eq "stylesheet")) {
229     $options{"SHOW_CONTENT"} = 1;
230
231     ($options{"filename"}, $options{"display_filename"})
232       = AM->prepare_template_filename(\%myconfig, $form);
233
234     ($options{"content"}, $options{"lines"})
235       = AM->load_template($options{"filename"});
236
237     $options{"CAN_EDIT"} = $form->{"edit"};
238
239     if ($form->{edit}) {
240       $form->{fokus} = "Form.content";
241
242     } else {
243       $options{"content"}                 = "\n\n" if (!$options{"content"});
244       $options{"SHOW_SECOND_EDIT_BUTTON"} = $options{"lines"} > 25;
245     }
246   }
247
248   $options{"HIDDEN"} = [ map(+{ "name" => $_, "value" => $form->{$_} }, @hidden) ];
249
250   $form->header;
251   print($form->parse_html_template("am/edit_templates", \%options));
252
253   $main::lxdebug->leave_sub();
254 }
255
256 1;