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