1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger Accounting
9 # Copyright (c) 1998-2002
11 # Author: Dieter Simader
12 # Email: dsimader@sql-ledger.org
13 # Web: http://www.sql-ledger.org
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.
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 #======================================================================
32 #======================================================================
43 require "bin/mozilla/common.pl";
48 call_sub($main::form->{display_nextsub});
52 call_sub($main::form->{save_nextsub});
56 call_sub($main::form->{edit_nextsub});
59 sub display_template {
60 $main::lxdebug->enter_sub();
62 my $form = $main::form;
64 $main::auth->assert('config');
67 display_template_form();
69 $main::lxdebug->leave_sub();
73 $main::lxdebug->enter_sub();
75 my $form = $main::form;
77 $main::auth->assert('config');
80 display_template_form();
82 $main::lxdebug->leave_sub();
86 $main::lxdebug->enter_sub();
88 my $form = $main::form;
89 my %myconfig = %main::myconfig;
90 my $locale = $main::locale;
92 $main::auth->assert('config');
94 $form->isblank("formname", $locale->text("You're not editing a file.")) unless ($form->{type} eq "stylesheet");
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));
102 display_template_form();
104 $main::lxdebug->leave_sub();
107 sub display_template_form {
108 $main::lxdebug->enter_sub();
110 my $form = $main::form;
111 my %myconfig = %main::myconfig;
112 my $locale = $main::locale;
114 $main::auth->assert('config');
116 $form->{"formname"} =~ s|.*/||;
117 my $format = $form->{"format"} eq "html" ? "html" : "tex";
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"};
126 my @hidden = qw(type format);
128 if (($form->{"type"} ne "stylesheet") && !$form->{"edit"}) {
129 $options{"SHOW_EDIT_OPTIONS"} = 1;
132 # Setup "formname" selection
135 $form->get_lists("printers" => "ALL_PRINTERS",
136 "languages" => "ALL_LANGUAGES",
137 "dunning_configs" => "ALL_DUNNING_CONFIGS");
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 pick_list => $locale->text('Pick List'),
149 proforma => $locale->text('Proforma Invoice'),
150 purchase_delivery_order => { translation => $::locale->text('Purchase delivery order'), tex => 1 },
151 purchase_order => $locale->text('Purchase Order'),
152 receipt => { translation => $locale->text('Receipt'), tex => 1 },
153 request_quotation => $locale->text('RFQ'),
154 sales_delivery_order => { translation => $::locale->text('Sales delivery order'), tex => 1 },
155 sales_order => $locale->text('Confirmation'),
156 sales_quotation => $locale->text('Quotation'),
157 statement => $locale->text('Statement'),
158 storno_invoice => $locale->text('Storno Invoice'),
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"),
166 my (@values, $file, $setup);
168 while (($file, $setup) = each(%formname_setup)) {
169 next if ref($setup) && !$setup->{$format};
173 "label" => ref($setup) ? $setup->{"translation"} : $setup });
176 # "zahlungserinnerung" => $locale->text('Payment Reminder'),
178 foreach my $ref (@{ $form->{"ALL_DUNNING_CONFIGS"} }) {
179 next if !$ref->{"template"};
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") . ')' });
188 @values = sort({ $a->{"label"} cmp $b->{"label"} } @values);
190 $options{FORMNAME} = [ @values ];
193 # Setup "language" selection
198 foreach my $item (@{ $form->{"ALL_LANGUAGES"} }) {
199 next unless ($item->{"template_code"});
202 { "value" => "$item->{id}--$item->{template_code}",
203 "label" => $item->{"description"} });
206 $options{LANGUAGE} = [ @values ];
209 # Setup "printer" selection
214 foreach my $item (@{ $form->{"ALL_PRINTERS"} }) {
215 next unless ($item->{"template_code"});
218 { "value" => "$item->{id}--$item->{template_code}",
219 "label" => $item->{"printer_description"} });
222 $options{PRINTER} = [ @values ];
225 push(@hidden, qw(formname language printer));
228 if ($form->{formname} || ($form->{type} eq "stylesheet")) {
229 $options{"SHOW_CONTENT"} = 1;
231 ($options{"filename"}, $options{"display_filename"})
232 = AM->prepare_template_filename(\%myconfig, $form);
234 ($options{"content"}, $options{"lines"})
235 = AM->load_template($options{"filename"});
237 $options{"CAN_EDIT"} = $form->{"edit"};
240 $form->{fokus} = "Form.content";
243 $options{"content"} = "\n\n" if (!$options{"content"});
244 $options{"SHOW_SECOND_EDIT_BUTTON"} = $options{"lines"} > 25;
248 $options{"HIDDEN"} = [ map(+{ "name" => $_, "value" => $form->{$_} }, @hidden) ];
251 print($form->parse_html_template("am/edit_templates", \%options));
253 $main::lxdebug->leave_sub();