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");
 
 123   my @hidden = qw(type format);
 
 125   if (($form->{"type"} ne "stylesheet") && !$form->{"edit"}) {
 
 126     $options{"SHOW_EDIT_OPTIONS"} = 1;
 
 129     # Setup "formname" selection
 
 132     $form->get_lists("printers" => "ALL_PRINTERS",
 
 133                      "languages" => "ALL_LANGUAGES",
 
 134                      "dunning_configs" => "ALL_DUNNING_CONFIGS");
 
 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"),
 
 163     my (@values, $file, $setup);
 
 165     while (($file, $setup) = each(%formname_setup)) {
 
 166       next if ref($setup) && !$setup->{$format};
 
 170              "label"   => ref($setup) ? $setup->{"translation"} : $setup });
 
 173     # "zahlungserinnerung" => $locale->text('Payment Reminder'),
 
 175     foreach my $ref (@{ $form->{"ALL_DUNNING_CONFIGS"} }) {
 
 176       next if !$ref->{"template"};
 
 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") . ')' });
 
 185     @values = sort({ $a->{"label"} cmp $b->{"label"} } @values);
 
 187     $options{FORMNAME} = [ @values ];
 
 190     # Setup "language" selection
 
 195     foreach my $item (@{ $form->{"ALL_LANGUAGES"} }) {
 
 196       next unless ($item->{"template_code"});
 
 199            { "value" => "$item->{id}--$item->{template_code}",
 
 200              "label" => $item->{"description"} });
 
 203     $options{LANGUAGE} = [ @values ];
 
 206     # Setup "printer" selection
 
 211     foreach my $item (@{ $form->{"ALL_PRINTERS"} }) {
 
 212       next unless ($item->{"template_code"});
 
 215            { "value" => "$item->{id}--$item->{template_code}",
 
 216              "label" => $item->{"printer_description"} });
 
 219     $options{PRINTER} = [ @values ];
 
 222     push(@hidden, qw(formname language printer));
 
 225   if ($form->{formname} || ($form->{type} eq "stylesheet")) {
 
 226     $options{"SHOW_CONTENT"} = 1;
 
 228     ($options{"filename"}, $options{"display_filename"})
 
 229       = AM->prepare_template_filename(\%myconfig, $form);
 
 231     ($options{"content"}, $options{"lines"})
 
 232       = AM->load_template($options{"filename"});
 
 234     $options{"CAN_EDIT"} = $form->{"edit"};
 
 237       $form->{fokus} = "Form.content";
 
 240       $options{"content"}                 = "\n\n" if (!$options{"content"});
 
 241       $options{"SHOW_SECOND_EDIT_BUTTON"} = $options{"lines"} > 25;
 
 245   $options{"HIDDEN"} = [ map(+{ "name" => $_, "value" => $form->{$_} }, @hidden) ];
 
 248   print($form->parse_html_template("am/edit_templates", \%options));
 
 250   $main::lxdebug->leave_sub();