Erste Version eines Template-Systems fuer die HTML-Seiten. Nur die Backend-Funktion...
authorMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 14 Feb 2006 16:43:20 +0000 (16:43 +0000)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 14 Feb 2006 16:43:20 +0000 (16:43 +0000)
SL/Form.pm

index acc6c6b..124e972 100644 (file)
@@ -37,6 +37,8 @@
 
 package Form;
 
+use HTML::Template;
+
 sub _input_to_hash {
   $main::lxdebug->enter_sub();
 
@@ -419,6 +421,46 @@ function fokus(){document.$self->{fokus}.focus();}
   $main::lxdebug->leave_sub();
 }
 
+sub parse_html_template {
+  $main::lxdebug->enter_sub();
+
+  my ($self, $file) = @_;
+
+  my $template = HTML::Template->new("filename" => "templates/webpages/$file",
+                                     "die_on_bad_params" => 0,
+                                     "strict" => 0,
+                                     "case_sensitive" => 1,
+                                     "loop_context_vars" => 1,
+                                     "global_vars" => 1);
+  my @params = $template->param();
+
+  if (grep("DEBUG", @params) && $self->{"DEBUG"}) {
+    $template->param("DEBUG" => "<br><em>DEBUG INFORMATION:</em><pre>" .
+                     $self->{"DEBUG"} . "</pre>");
+  }
+
+  foreach my $key (keys(%{$self})) {
+    if (("DEBUG" ne $key) && grep(${key}, @params)) {
+      $template->param($key => $self->{$key});
+    }
+  }
+
+  my $output = $template->output();
+
+  $main::lxdebug->leave_sub();
+
+  return $output;
+}
+
+sub show_generic_error {
+  my ($self, $error, $title) = @_;
+
+  $self->{"title"} = $title if ($title);
+  $self->{"label_error"} = $error;
+
+  print($self->parse_html_template("generic/error.html"));
+}
+
 # write Trigger JavaScript-Code ($qty = quantity of Triggers)
 # changed it to accept an arbitrary number of triggers - sschoeling
 sub write_trigger {