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., 51 Franklin Street, Fifth Floor, Boston,
 
  29 #======================================================================
 
  33 #======================================================================
 
  47 require "bin/mozilla/common.pl";
 
  52   call_sub($main::form->{display_nextsub});
 
  56   call_sub($main::form->{save_nextsub});
 
  60   call_sub($main::form->{edit_nextsub});
 
  63 sub display_template {
 
  64   $main::lxdebug->enter_sub();
 
  66   my $form     = $main::form;
 
  68   $main::auth->assert('admin');
 
  71   display_template_form();
 
  73   $main::lxdebug->leave_sub();
 
  77   $main::lxdebug->enter_sub();
 
  79   my $form     = $main::form;
 
  81   $main::auth->assert('admin');
 
  84   display_template_form();
 
  86   $main::lxdebug->leave_sub();
 
  90   $main::lxdebug->enter_sub();
 
  92   my $form     = $main::form;
 
  93   my %myconfig = %main::myconfig;
 
  94   my $locale   = $main::locale;
 
  96   $main::auth->assert('admin');
 
  98   $form->isblank("formname", $locale->text("You're not editing a file.")) unless ($form->{type} eq "stylesheet");
 
 100   my ($filename) = AM->prepare_template_filename(\%myconfig, $form);
 
 101   if (my $error = AM->save_template($filename, $form->{content})) {
 
 102     $form->error(sprintf($locale->text("Saving the file '%s' failed. OS error message: %s"), $filename, $error));
 
 106   display_template_form();
 
 108   $main::lxdebug->leave_sub();
 
 111 sub display_template_form {
 
 112   $main::lxdebug->enter_sub();
 
 114   my $form     = $main::form;
 
 115   my %myconfig = %main::myconfig;
 
 116   my $locale   = $main::locale;
 
 118   $main::auth->assert('admin');
 
 120   my $defaults = SL::DB::Default->get;
 
 121   $form->error($::locale->text('No print templates have been created for this client yet. Please do so in the client configuration.')) if !$defaults->templates;
 
 123   if ($form->{"formname"} =~ m|\.\.| || $form->{"formname"} =~ m|^/|) {
 
 124     $form->{"formname"} =~ s|.*/||;
 
 127   my $format = $form->{"format"} eq "html" ? "html" : "tex";
 
 129   $form->{"title"} = $form->{"type"} eq "stylesheet" ? $locale->text("Edit the stylesheet") : $locale->text("Edit templates");
 
 130   if ($form->{"format"}) {
 
 131       $form->{"title"} = uc($form->{"format"}) . " - " . $form->{"title"};
 
 136   my @hidden = qw(type format);
 
 138   if (($form->{"type"} ne "stylesheet") && !$form->{"edit"}) {
 
 139     $options{"SHOW_EDIT_OPTIONS"} = 1;
 
 142     # Setup "formname" selection
 
 145     $form->get_lists("printers" => "ALL_PRINTERS",
 
 146                      "languages" => "ALL_LANGUAGES",
 
 147                      "dunning_configs" => "ALL_DUNNING_CONFIGS");
 
 151         # balance_sheet           => { translation => $locale->text('Balance Sheet'),             html => 1 },
 
 152         bin_list                => $locale->text('Bin List'),
 
 153         bwa                     => { translation => $locale->text('BWA'),                       html => 1 },
 
 154         check                   => { translation => $locale->text('Check'),                     html => 1 },
 
 155         credit_note             => $locale->text('Credit Note'),
 
 156         income_statement        => { translation => $locale->text('Income Statement'),          html => 1 },
 
 157         invoice                 => $locale->text('Invoice'),
 
 158         pick_list               => $locale->text('Pick List'),
 
 159         proforma                => $locale->text('Proforma Invoice'),
 
 160         purchase_delivery_order => { translation => $::locale->text('Purchase delivery order'), tex => 1 },
 
 161         purchase_order          => $locale->text('Purchase Order'),
 
 162         receipt                 => { translation => $locale->text('Receipt'),                   tex => 1 },
 
 163         request_quotation       => $locale->text('RFQ'),
 
 164         sales_delivery_order    => { translation => $::locale->text('Sales delivery order'),    tex => 1 },
 
 165         sales_order             => $locale->text('Confirmation'),
 
 166         sales_quotation         => $locale->text('Quotation'),
 
 167         statement               => $locale->text('Statement'),
 
 168         storno_invoice          => $locale->text('Storno Invoice'),
 
 169         "ustva-2004"            => { translation => $locale->text("USTVA 2004"),                tex => 1 },
 
 170         "ustva-2005"            => { translation => $locale->text("USTVA 2005"),                tex => 1 },
 
 171         "ustva-2006"            => { translation => $locale->text("USTVA 2006"),                tex => 1 },
 
 172         "ustva-2007"            => { translation => $locale->text("USTVA 2007"),                tex => 1 },
 
 173         ustva                   => $locale->text("USTVA"),
 
 176     my (@values, $file, $setup);
 
 178     while (($file, $setup) = each(%formname_setup)) {
 
 179       next if ref($setup) && !$setup->{$format};
 
 183              "label"   => ref($setup) ? $setup->{"translation"} : $setup });
 
 186     # "zahlungserinnerung" => $locale->text('Payment Reminder'),
 
 188     foreach my $ref (@{ $form->{"ALL_DUNNING_CONFIGS"} }) {
 
 189       next if !$ref->{"template"};
 
 192            { "value" => $ref->{"template"},
 
 193              "label" => $locale->text('Payment Reminder') . ": " . $ref->{"dunning_description"} },
 
 194            { "value" => $ref->{"template"} . "_invoice",
 
 195              "label" => $locale->text('Payment Reminder') . ": " . $ref->{"dunning_description"} . ' (' . $locale->text("Invoice for fees") . ')' });
 
 198     @values = sort({ $a->{"label"} cmp $b->{"label"} } @values);
 
 201     # at the end: others/includes for tex
 
 203     if ($format eq "tex") {
 
 204       # search all .tex-files in template dir (recursively)
 
 205       my $template_dir = $defaults->templates;
 
 209           next if (-l $_ || -d $_);
 
 210           next unless (-f $_ && $_ =~ m/.*?\.tex$/);
 
 212           my $fname = $File::Find::name;
 
 213           # remove template dir from name
 
 214           $fname =~ s|^\Q$template_dir\E/||;
 
 215           # remove .tex from name
 
 218           push(@all_files, $fname);
 
 222       # filter all files already set up (i.e. not already in @values)
 
 223       my @other_files = grep { my $a=$_; not grep {$a eq $_->{value}} @values } @all_files;
 
 225       # add other tex files
 
 226       foreach my $o (@other_files) {
 
 227         push(@values, { "value" => $o, "label" => $locale->text("Others")." ($o)" });
 
 231     $options{FORMNAME} = [ @values ];
 
 234     # Setup "language" selection
 
 239     foreach my $item (@{ $form->{"ALL_LANGUAGES"} }) {
 
 240       next unless ($item->{"template_code"});
 
 243            { "value" => "$item->{id}--$item->{template_code}",
 
 244              "label" => $item->{"description"} });
 
 247     $options{LANGUAGE} = [ @values ];
 
 250     # Setup "printer" selection
 
 255     foreach my $item (@{ $form->{"ALL_PRINTERS"} }) {
 
 256       next unless ($item->{"template_code"});
 
 259            { "value" => "$item->{id}--$item->{template_code}",
 
 260              "label" => $item->{"printer_description"} });
 
 263     $options{PRINTER} = [ @values ];
 
 266     push(@hidden, qw(formname language printer));
 
 269   if ($form->{formname} || ($form->{type} eq "stylesheet")) {
 
 270     $options{"SHOW_CONTENT"} = 1;
 
 272     ($options{"filename"}, $options{"display_filename"})
 
 273       = AM->prepare_template_filename(\%myconfig, $form);
 
 275     ($options{"content"}, $options{"lines"})
 
 276       = AM->load_template($options{"filename"});
 
 278     $options{"CAN_EDIT"} = $form->{"edit"};
 
 280     if (!$form->{edit}) {
 
 281       $options{"content"}                 = "\n\n" if (!$options{"content"});
 
 282       $options{"SHOW_SECOND_EDIT_BUTTON"} = $options{"lines"} > 25;
 
 286   $options{"HIDDEN"} = [ map(+{ "name" => $_, "value" => $form->{$_} }, @hidden) ];
 
 289   print($form->parse_html_template("am/edit_templates", \%options));
 
 291   $main::lxdebug->leave_sub();