$main::lxdebug->leave_sub();
}
-sub load_template {
+
+sub prepare_template_filename {
$main::lxdebug->enter_sub();
- my ($self, $form) = @_;
+ my ($self, $myconfig, $form) = @_;
+
+ my ($filename, $display_filename);
+
+ if ($form->{type} eq "stylesheet") {
+ $filename = "css/$myconfig->{stylesheet}";
+ $display_filename = $myconfig->{stylesheet};
+
+ } else {
+ $filename = $form->{formname};
+
+ if ($form->{language}) {
+ my ($id, $template_code) = split(/--/, $form->{language});
+ $filename .= "_${template_code}";
+ }
- open(TEMPLATE, "$form->{file}") or $form->error("$form->{file} : $!");
+ if ($form->{printer}) {
+ my ($id, $template_code) = split(/--/, $form->{printer});
+ $filename .= "_${template_code}";
+ }
- while (<TEMPLATE>) {
- $form->{body} .= $_;
+ $filename .= "." . ($form->{format} eq "html" ? "html" : "tex");
+ $filename =~ s|.*/||;
+ $display_filename = $filename;
+ $filename = "$myconfig->{templates}/$filename";
}
- close(TEMPLATE);
+ $main::lxdebug->leave_sub();
+
+ return ($filename, $display_filename);
+}
+
+
+sub load_template {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $filename) = @_;
+
+ my ($content, $lines) = ("", 0);
+
+ local *TEMPLATE;
+
+ if (open(TEMPLATE, $filename)) {
+ while (<TEMPLATE>) {
+ $content .= $_;
+ $lines++;
+ }
+ close(TEMPLATE);
+ }
$main::lxdebug->leave_sub();
+
+ return ($content, $lines);
}
sub save_template {
$main::lxdebug->enter_sub();
- my ($self, $form) = @_;
+ my ($self, $filename, $content) = @_;
- open(TEMPLATE, ">$form->{file}") or $form->error("$form->{file} : $!");
+ local *TEMPLATE;
- # strip
- $form->{body} =~ s/\r\n/\n/g;
- print TEMPLATE $form->{body};
+ my $error = "";
- close(TEMPLATE);
+ if (open(TEMPLATE, ">$filename")) {
+ $content =~ s/\r\n/\n/g;
+ print(TEMPLATE $content);
+ close(TEMPLATE);
+ } else {
+ $error = $!;
+ }
$main::lxdebug->leave_sub();
+
+ return $error;
}
sub save_preferences {