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 #======================================================================
 
  41 require "bin/mozilla/common.pl";
 
  46   call_sub($form->{display_nextsub});
 
  50   call_sub($form->{save_nextsub});
 
  54   call_sub($form->{edit_nextsub});
 
  57 sub display_template {
 
  58   $lxdebug->enter_sub();
 
  61   display_template_form();
 
  63   $lxdebug->leave_sub();
 
  67   $lxdebug->enter_sub();
 
  70   display_template_form();
 
  72   $lxdebug->leave_sub();
 
  76   $lxdebug->enter_sub();
 
  78   $form->isblank("formname", $locale->text("You're not editing a file.")) unless ($form->{type} eq "stylesheet");
 
  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));
 
  86   display_template_form();
 
  88   $lxdebug->leave_sub();
 
  91 sub display_template_form {
 
  92   $lxdebug->enter_sub();
 
  94   $form->{"formname"} =~ s|.*/||;
 
  95   my $format = $form->{"format"} eq "html" ? "html" : "tex";
 
  97   $form->{"title"} = $form->{"type"} eq "stylesheet" ? $locale->text("Edit the stylesheet") : $locale->text("Edit templates");
 
 101   my @hidden = qw(login password type format);
 
 103   if (($form->{"type"} ne "stylesheet") && !$form->{"edit"}) {
 
 104     $options{"SHOW_EDIT_OPTIONS"} = 1;
 
 107     # Setup "formname" selection
 
 110     $form->get_lists("printers" => "ALL_PRINTERS",
 
 111                      "languages" => "ALL_LANGUAGES",
 
 112                      "dunning_configs" => "ALL_DUNNING_CONFIGS");
 
 116         "balance_sheet" => { "translation" => $locale->text('Balance Sheet'), "html" => 1 },
 
 117         "bin_list" => $locale->text('Bin List'),
 
 118         "bwa" => { "translation" => $locale->text('BWA'), "html" => 1 },
 
 119         "check" => { "translation" => $locale->text('Check'), "html" => 1 },
 
 120         "credit_note" => $locale->text('Credit Note'),
 
 121         "income_statement" => { "translation" => $locale->text('Income Statement'), "html" => 1 },
 
 122         "invoice" => $locale->text('Invoice'),
 
 123         "packing_list" => $locale->text('Packing List'),
 
 124         "pick_list" => $locale->text('Pick List'),
 
 125         "proforma" => $locale->text('Proforma Invoice'),
 
 126         "purchase_order" => $locale->text('Purchase Order'),
 
 127         "receipt" => { "translation" => $locale->text('Receipt'), "tex" => 1 },
 
 128         "request_quotation" => $locale->text('RFQ'),
 
 129         "sales_order" => $locale->text('Confirmation'),
 
 130         "sales_quotation" => $locale->text('Quotation'),
 
 131         "statement" => $locale->text('Statement'),
 
 132         "storno_invoice" => $locale->text('Storno Invoice'),
 
 133         "storno_packing_list" => $locale->text('Storno Packing List'),
 
 134         "ustva-2004" => { "translation" => $locale->text("USTVA 2004"), "tex" => 1 },
 
 135         "ustva-2005" => { "translation" => $locale->text("USTVA 2005"), "tex" => 1 },
 
 136         "ustva-2006" => { "translation" => $locale->text("USTVA 2006"), "tex" => 1 },
 
 137         "ustva-2007" => { "translation" => $locale->text("USTVA 2007"), "tex" => 1 },
 
 138         "ustva" => $locale->text("USTVA"),
 
 141     my (@values, $file, $setup);
 
 143     while (($file, $setup) = each(%formname_setup)) {
 
 144       next if ref($setup) && !$setup->{$format};
 
 148              "label"   => ref($setup) ? $setup->{"translation"} : $setup });
 
 151     # "zahlungserinnerung" => $locale->text('Payment Reminder'),
 
 153     foreach my $ref (@{ $form->{"ALL_DUNNING_CONFIGS"} }) {
 
 154       next if !$ref->{"template"};
 
 157            { "value" => $ref->{"template"},
 
 158              "label" => $locale->text('Payment Reminder') . ": " . $ref->{"dunning_description"} });
 
 161     @values = sort({ $a->{"label"} cmp $b->{"label"} } @values);
 
 163     $options{FORMNAME} = [ @values ];
 
 166     # Setup "language" selection
 
 171     foreach my $item (@{ $form->{"ALL_LANGUAGES"} }) {
 
 172       next unless ($item->{"template_code"});
 
 175            { "value" => "$item->{id}--$item->{template_code}",
 
 176              "label" => $item->{"description"} });
 
 179     $options{LANGUAGE} = [ @values ];
 
 182     # Setup "printer" selection
 
 187     foreach my $item (@{ $form->{"ALL_PRINTERS"} }) {
 
 188       next unless ($item->{"template_code"});
 
 191            { "value" => "$item->{id}--$item->{template_code}",
 
 192              "label" => $item->{"printer_description"} });
 
 195     $options{PRINTER} = [ @values ];
 
 198     push(@hidden, qw(formname language printer));
 
 201   if ($form->{formname} || ($form->{type} eq "stylesheet")) {
 
 202     $options{"SHOW_CONTENT"} = 1;
 
 204     ($options{"filename"}, $options{"display_filename"})
 
 205       = AM->prepare_template_filename(\%myconfig, $form);
 
 207     ($options{"content"}, $options{"lines"})
 
 208       = AM->load_template($options{"filename"});
 
 210     $options{"CAN_EDIT"} = $form->{"edit"};
 
 213       $form->{fokus} = "Form.content";
 
 216       $options{"content"}                 = "\n\n" if (!$options{"content"});
 
 217       $options{"SHOW_SECOND_EDIT_BUTTON"} = $options{"lines"} > 25;
 
 221   $options{"HIDDEN"} = [ map(+{ "name" => $_, "value" => $form->{$_} }, @hidden) ];
 
 224   print($form->parse_html_template("am/edit_templates", \%options));
 
 226   $lxdebug->leave_sub();