Fixed bug. (from r1005)
[kivitendo-erp.git] / SL / Form.pm
index e7fea51..1c03e10 100644 (file)
@@ -142,7 +142,7 @@ sub new {
   $self->{action} = lc $self->{action};
   $self->{action} =~ s/( |-|,|#)/_/g;
 
-  $self->{version}   = "2.2.0";
+  $self->{version}   = "2.3.0";
 
   $main::lxdebug->leave_sub();
 
@@ -197,7 +197,7 @@ sub quote {
   my ($self, $str) = @_;
 
   if ($str && !ref($str)) {
-    $str =~ s/"/"/g;
+    $str =~ s/\"/"/g;
   }
 
   $str;
@@ -208,7 +208,7 @@ sub unquote {
   my ($self, $str) = @_;
 
   if ($str && !ref($str)) {
-    $str =~ s/"/"/g;
+    $str =~ s/"/\"/g;
   }
 
   $str;
@@ -692,7 +692,7 @@ sub parse_amount {
   }
 
   if ($myconfig->{numberformat} eq "1'000.00") {
-    $amount =~ s/'//g;
+    $amount =~ s/\'//g;
   }
 
   $amount =~ s/,//g;
@@ -783,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
@@ -930,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"});
@@ -1108,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}");
@@ -1158,7 +1169,7 @@ sub format_string {
         '&', quotemeta('\n'), '
 ',
         '"', '\$', '%', '_', '#', quotemeta('^'),
-        '{', '}',  '<', '>', '£', "\r"
+        '{', '}',  '<', '>', '£', "\r", '²'
       ]
     },
     'html' => {
@@ -1184,6 +1195,7 @@ sub format_string {
       '
 '          => '\newline ',
       '£'  => '\pounds ',
+      '²'  => '$^2$',
       "\r" => ""
     });