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 #======================================================================
 
  45 require "bin/mozilla/common.pl";
 
  50   call_sub($main::form->{display_nextsub});
 
  54   call_sub($main::form->{save_nextsub});
 
  58   call_sub($main::form->{edit_nextsub});
 
  61 sub display_template {
 
  62   $main::lxdebug->enter_sub();
 
  64   my $form     = $main::form;
 
  66   $main::auth->assert('admin');
 
  69   display_template_form();
 
  71   $main::lxdebug->leave_sub();
 
  75   $main::lxdebug->enter_sub();
 
  77   my $form     = $main::form;
 
  79   $main::auth->assert('admin');
 
  82   display_template_form();
 
  84   $main::lxdebug->leave_sub();
 
  88   $main::lxdebug->enter_sub();
 
  90   my $form     = $main::form;
 
  91   my %myconfig = %main::myconfig;
 
  92   my $locale   = $main::locale;
 
  94   $main::auth->assert('admin');
 
  96   $form->isblank("formname", $locale->text("You're not editing a file.")) unless ($form->{type} eq "stylesheet");
 
  98   my ($filename) = AM->prepare_template_filename(\%myconfig, $form);
 
  99   if (my $error = AM->save_template($filename, $form->{content})) {
 
 100     $form->error(sprintf($locale->text("Saving the file '%s' failed. OS error message: %s"), $filename, $error));
 
 104   display_template_form();
 
 106   $main::lxdebug->leave_sub();
 
 109 sub display_template_form {
 
 110   $main::lxdebug->enter_sub();
 
 112   my $form     = $main::form;
 
 113   my %myconfig = %main::myconfig;
 
 114   my $locale   = $main::locale;
 
 116   $main::auth->assert('admin');
 
 118   if ($form->{"formname"} =~ m|\.\.| || $form->{"formname"} =~ m|^/|) {
 
 119     $form->{"formname"} =~ s|.*/||;
 
 122   my $format = $form->{"format"} eq "html" ? "html" : "tex";
 
 124   $form->{"title"} = $form->{"type"} eq "stylesheet" ? $locale->text("Edit the stylesheet") : $locale->text("Edit templates");
 
 125   if ($form->{"format"}) {
 
 126       $form->{"title"} = uc($form->{"format"}) . " - " . $form->{"title"};
 
 131   my @hidden = qw(type format);
 
 133   if (($form->{"type"} ne "stylesheet") && !$form->{"edit"}) {
 
 134     $options{"SHOW_EDIT_OPTIONS"} = 1;
 
 137     # Setup "formname" selection
 
 140     $form->get_lists("printers" => "ALL_PRINTERS",
 
 141                      "languages" => "ALL_LANGUAGES",
 
 142                      "dunning_configs" => "ALL_DUNNING_CONFIGS");
 
 146         # balance_sheet           => { translation => $locale->text('Balance Sheet'),             html => 1 },
 
 147         bin_list                => $locale->text('Bin List'),
 
 148         bwa                     => { translation => $locale->text('BWA'),                       html => 1 },
 
 149         check                   => { translation => $locale->text('Check'),                     html => 1 },
 
 150         credit_note             => $locale->text('Credit Note'),
 
 151         income_statement        => { translation => $locale->text('Income Statement'),          html => 1 },
 
 152         invoice                 => $locale->text('Invoice'),
 
 153         pick_list               => $locale->text('Pick List'),
 
 154         proforma                => $locale->text('Proforma Invoice'),
 
 155         purchase_delivery_order => { translation => $::locale->text('Purchase delivery order'), tex => 1 },
 
 156         purchase_order          => $locale->text('Purchase Order'),
 
 157         receipt                 => { translation => $locale->text('Receipt'),                   tex => 1 },
 
 158         request_quotation       => $locale->text('RFQ'),
 
 159         sales_delivery_order    => { translation => $::locale->text('Sales delivery order'),    tex => 1 },
 
 160         sales_order             => $locale->text('Confirmation'),
 
 161         sales_quotation         => $locale->text('Quotation'),
 
 162         statement               => $locale->text('Statement'),
 
 163         storno_invoice          => $locale->text('Storno Invoice'),
 
 164         "ustva-2004"            => { translation => $locale->text("USTVA 2004"),                tex => 1 },
 
 165         "ustva-2005"            => { translation => $locale->text("USTVA 2005"),                tex => 1 },
 
 166         "ustva-2006"            => { translation => $locale->text("USTVA 2006"),                tex => 1 },
 
 167         "ustva-2007"            => { translation => $locale->text("USTVA 2007"),                tex => 1 },
 
 168         ustva                   => $locale->text("USTVA"),
 
 171     my (@values, $file, $setup);
 
 173     while (($file, $setup) = each(%formname_setup)) {
 
 174       next if ref($setup) && !$setup->{$format};
 
 178              "label"   => ref($setup) ? $setup->{"translation"} : $setup });
 
 181     # "zahlungserinnerung" => $locale->text('Payment Reminder'),
 
 183     foreach my $ref (@{ $form->{"ALL_DUNNING_CONFIGS"} }) {
 
 184       next if !$ref->{"template"};
 
 187            { "value" => $ref->{"template"},
 
 188              "label" => $locale->text('Payment Reminder') . ": " . $ref->{"dunning_description"} },
 
 189            { "value" => $ref->{"template"} . "_invoice",
 
 190              "label" => $locale->text('Payment Reminder') . ": " . $ref->{"dunning_description"} . ' (' . $locale->text("Invoice for fees") . ')' });
 
 193     @values = sort({ $a->{"label"} cmp $b->{"label"} } @values);
 
 196     # at the end: others/includes for tex
 
 198     if ($format eq "tex") {
 
 199       # search all .tex-files in template dir (recursively)
 
 203           next if (-l $_ || -d $_);
 
 204           next unless (-f $_ && $_ =~ m/.*?\.tex$/);
 
 206           my $fname = $File::Find::name;
 
 207           # remove template dir from name
 
 208           $fname =~ s|^$myconfig{templates}/||;
 
 209           # remove .tex from name
 
 212           push(@all_files, $fname);
 
 214           }, $myconfig{templates});
 
 216       # filter all files already set up (i.e. not already in @values)
 
 217       my @other_files = grep { my $a=$_; not grep {$a eq $_->{value}} @values } @all_files;
 
 219       # add other tex files
 
 220       foreach my $o (@other_files) {
 
 221         push(@values, { "value" => $o, "label" => $locale->text("Others")." ($o)" });
 
 225     $options{FORMNAME} = [ @values ];
 
 228     # Setup "language" selection
 
 233     foreach my $item (@{ $form->{"ALL_LANGUAGES"} }) {
 
 234       next unless ($item->{"template_code"});
 
 237            { "value" => "$item->{id}--$item->{template_code}",
 
 238              "label" => $item->{"description"} });
 
 241     $options{LANGUAGE} = [ @values ];
 
 244     # Setup "printer" selection
 
 249     foreach my $item (@{ $form->{"ALL_PRINTERS"} }) {
 
 250       next unless ($item->{"template_code"});
 
 253            { "value" => "$item->{id}--$item->{template_code}",
 
 254              "label" => $item->{"printer_description"} });
 
 257     $options{PRINTER} = [ @values ];
 
 260     push(@hidden, qw(formname language printer));
 
 263   if ($form->{formname} || ($form->{type} eq "stylesheet")) {
 
 264     $options{"SHOW_CONTENT"} = 1;
 
 266     ($options{"filename"}, $options{"display_filename"})
 
 267       = AM->prepare_template_filename(\%myconfig, $form);
 
 269     ($options{"content"}, $options{"lines"})
 
 270       = AM->load_template($options{"filename"});
 
 272     $options{"CAN_EDIT"} = $form->{"edit"};
 
 275       $::request->{layout}->focus("#edit_content");
 
 278       $options{"content"}                 = "\n\n" if (!$options{"content"});
 
 279       $options{"SHOW_SECOND_EDIT_BUTTON"} = $options{"lines"} > 25;
 
 283   $options{"HIDDEN"} = [ map(+{ "name" => $_, "value" => $form->{$_} }, @hidden) ];
 
 286   print($form->parse_html_template("am/edit_templates", \%options));
 
 288   $main::lxdebug->leave_sub();