X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FForm.pm;h=1c03e107ffa8f629ad223c599510c26e3608dcb1;hb=a5f55e6fe23ee776e90567d3e5ee6cdf116c3f9c;hp=acc6c6b58ff827a2bdafdbc6d91d5bd179a430d7;hpb=42ecd63a35d8800977547f073de9336cbddfd5fd;p=kivitendo-erp.git diff --git a/SL/Form.pm b/SL/Form.pm index acc6c6b58..1c03e107f 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -37,6 +37,8 @@ package Form; +use HTML::Template; + sub _input_to_hash { $main::lxdebug->enter_sub(); @@ -140,8 +142,7 @@ sub new { $self->{action} = lc $self->{action}; $self->{action} =~ s/( |-|,|#)/_/g; - $self->{version} = "2.2.0"; - $self->{dbversion} = "2.2.0"; + $self->{version} = "2.3.0"; $main::lxdebug->leave_sub(); @@ -196,7 +197,7 @@ sub quote { my ($self, $str) = @_; if ($str && !ref($str)) { - $str =~ s/"/"/g; + $str =~ s/\"/"/g; } $str; @@ -207,7 +208,7 @@ sub unquote { my ($self, $str) = @_; if ($str && !ref($str)) { - $str =~ s/"/"/g; + $str =~ s/"/\"/g; } $str; @@ -243,17 +244,7 @@ sub error { $msg =~ s/\n/
/g; $self->header; - - print qq| - - -

Error!

- -

$msg - - - - |; + $self->show_generic_error($msg); die "Error: $msg\n"; @@ -419,6 +410,84 @@ function fokus(){document.$self->{fokus}.focus();} $main::lxdebug->leave_sub(); } +use Data::Dumper; +sub parse_html_template { + $main::lxdebug->enter_sub(); + + my ($self, $file, $additional_params) = @_; + my $language; + + if (!defined($main::myconfig) || !defined($main::myconfig{"countrycode"})) { + $language = $main::language; + } else { + $language = $main::myconfig{"countrycode"}; + } + + if (-f "templates/webpages/${file}_${language}.html") { + if ((-f ".developer") && + (-f "templates/webpages/${file}_master.html") && + ((stat("templates/webpages/${file}_master.html"))[9] > + (stat("templates/webpages/${file}_${language}.html"))[9])) { + my $info = "Developper information: templates/webpages/${file}_master.html is newer than the localized version.\n" . + "Please re-run 'locales.pl' in 'locale/${language}'."; + print(qq|

$info
|); + die($info); + } + + $file = "templates/webpages/${file}_${language}.html"; + } elsif (-f "templates/webpages/${file}.html") { + $file = "templates/webpages/${file}.html"; + } else { + my $info = "Web page template '${file}' not found.\n" . + "Please re-run 'locales.pl' in 'locale/${language}'."; + print(qq|
$info
|); + die($info); + } + + my $template = HTML::Template->new("filename" => $file, + "die_on_bad_params" => 0, + "strict" => 0, + "case_sensitive" => 1, + "loop_context_vars" => 1, + "global_vars" => 1); + + $additional_params = {} unless ($additional_params); + if ($self->{"DEBUG"}) { + $additional_params->{"DEBUG"} = $self->{"DEBUG"}; + } + + if ($additional_params->{"DEBUG"}) { + $additional_params->{"DEBUG"} = + "
DEBUG INFORMATION:
" . $additional_params->{"DEBUG"} . "
"; + } + + my @additional_param_names = keys(%{$additional_params}); + + foreach my $key ($template->param()) { + if (grep(/^${key}$/, @additional_param_names)) { + $template->param($key => $additional_params->{$key}); + } else { + $template->param($key => $self->{$key}); + } + } + + my $output = $template->output(); + + $main::lxdebug->leave_sub(); + + return $output; +} + +sub show_generic_error { + my ($self, $error, $title) = @_; + + my $add_params = {}; + $add_params->{"title"} = $title if ($title); + $self->{"label_error"} = $error; + + print($self->parse_html_template("generic/error", $add_params)); +} + # write Trigger JavaScript-Code ($qty = quantity of Triggers) # changed it to accept an arbitrary number of triggers - sschoeling sub write_trigger { @@ -623,7 +692,7 @@ sub parse_amount { } if ($myconfig->{numberformat} eq "1'000.00") { - $amount =~ s/'//g; + $amount =~ s/\'//g; } $amount =~ s/,//g; @@ -714,7 +783,16 @@ sub parse_template { $par = ""; $var = $_; - + + # Switch <%analyse%> for template checking + # If <%analyse%> is set in the template, you'll find the + # parsed output in the user Directory for analysing + # Latex errors + # <%analyse%> is a switch (allways off, on if set), not a Variable + # Set $form->{analysing}="" for system state: never analyse. + # Set $form->{analysing}="1" for system state: ever analyse. + $self->{analysing} = "1" if (/<%analyse%>/ && !defined $self->{analysing}); + $two_passes = 1 if (/\\pageref/); # { Moritz Bunkus @@ -861,12 +939,12 @@ sub parse_template { # check for <%include filename%> if (/\s*<%include /) { - # get the filename + # get the directory/filename chomp $var; $var =~ s/\s*<%include (.+?)%>/$1/; - # mangle filename - $var =~ s/(\/|\.\.)//g; + # mangle filename on basedir + $var =~ s/^(\/|\.\.)//g; # prevent the infinite loop! next if ($self->{"$var"}); @@ -1039,12 +1117,14 @@ sub cleanup { close(FH); } - if ($self->{tmpfile}) { + if ($self->{analysing} eq "") { + if ($self->{tmpfile}) { - # strip extension - $self->{tmpfile} =~ s/\.\w+$//g; - my $tmpfile = $self->{tmpfile}; - unlink(<$tmpfile.*>); + # strip extension + $self->{tmpfile} =~ s/\.\w+$//g; + my $tmpfile = $self->{tmpfile}; + unlink(<$tmpfile.*>); + } } chdir("$self->{cwd}"); @@ -1089,7 +1169,7 @@ sub format_string { '&', quotemeta('\n'), ' ', '"', '\$', '%', '_', '#', quotemeta('^'), - '{', '}', '<', '>', '£', "\r" + '{', '}', '<', '>', '£', "\r", '²' ] }, 'html' => { @@ -1115,6 +1195,7 @@ sub format_string { ' ' => '\newline ', '£' => '\pounds ', + '²' => '$^2$', "\r" => "" });