]> wagnertech.de Git - mfinanz.git/blobdiff - SL/Form.pm
Die HTML-Vorlagen werden nun ebenfalls von locales.pl uebersetzt. Dabei werden alle...
[mfinanz.git] / SL / Form.pm
index 8670d604cecc34fbf642755de6aa3c80cbab8032..90f412018895a6931a8815d2de8db440debf45e5 100644 (file)
@@ -37,6 +37,8 @@
 
 package Form;
 
+use HTML::Template;
+
 sub _input_to_hash {
   $main::lxdebug->enter_sub();
 
@@ -243,17 +245,7 @@ sub error {
     $msg =~ s/\n/<br>/g;
 
     $self->header;
-
-    print qq|
-    <body>
-
-    <h2 class=error>Error!</h2>
-
-    <p><b>$msg</b>
-
-    </body>
-    </html>
-    |;
+    $self->show_generic_error($msg);
 
     die "Error: $msg\n";
 
@@ -401,6 +393,7 @@ function fokus(){document.$self->{fokus}.focus();}
 
     print qq|Content-Type: text/html
 
+<html>
 <head>
   <title>$self->{titlebar}</title>
   $stylesheet
@@ -418,6 +411,66 @@ 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) = @_;
+
+  if (-f "templates/webpages/${file}_" . $main::myconfig{"countrycode"} .
+      ".html") {
+    $file = "templates/webpages/${file}_" . $main::myconfig{"countrycode"} .
+      ".html";
+  } elsif (-f "templates/webpages/${file}.html") {
+    $file = "templates/webpages/${file}.html";
+  } else {
+    $self->error("Web page template '${file}' not found.");
+  }
+
+  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"} =
+      "<br><em>DEBUG INFORMATION:</em><pre>" . $additional_params->{"DEBUG"} . "</pre>";
+  }
+
+  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 {