Zeilenumbrueche entfernt und einmal locales.pl
[kivitendo-erp.git] / SL / Form.pm
index 8670d60..fe9d2b8 100644 (file)
@@ -37,6 +37,8 @@
 
 package Form;
 
+use HTML::Template;
+
 sub _input_to_hash {
   $main::lxdebug->enter_sub();
 
@@ -141,7 +143,6 @@ sub new {
   $self->{action} =~ s/( |-|,|#)/_/g;
 
   $self->{version}   = "2.2.0";
-  $self->{dbversion} = "2.2.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/<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 +392,7 @@ function fokus(){document.$self->{fokus}.focus();}
 
     print qq|Content-Type: text/html
 
+<html>
 <head>
   <title>$self->{titlebar}</title>
   $stylesheet
@@ -418,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|<pre>$info</pre>|);
+      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|<pre>$info</pre>|);
+    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"} =
+      "<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 {
@@ -622,7 +692,7 @@ sub parse_amount {
   }
 
   if ($myconfig->{numberformat} eq "1'000.00") {
-    $amount =~ s/'//g;
+    $amount =~ s/\'//g;
   }
 
   $amount =~ s/,//g;