OE->save() parst verschiedene Zahlen. Das ist beim Umwandeln in anderen Formulartypen...
[kivitendo-erp.git] / bin / mozilla / common.pl
index ed26129..30548f6 100644 (file)
@@ -16,9 +16,14 @@ use SL::Common;
 sub save_form {
   $lxdebug->enter_sub();
 
-  my $old_form = "";
-  map({ $old_form .= "$_=" . $form->escape($form->{$_}) . '&'; } keys(%{$form}));
-  chop($old_form);
+  my (@names, @values);
+  foreach my $key (keys(%{$form})) {
+    push(@names, "\$form->{\"$key\"}");
+    push(@values, $form->{$key});
+  }
+  my $dumper = Data::Dumper->new(\@values, \@names);
+  $dumper->Indent(0);
+  my $old_form = $dumper->Dump();
 
   $lxdebug->leave_sub();
 
@@ -28,14 +33,10 @@ sub save_form {
 sub restore_form {
   $lxdebug->enter_sub();
 
-  my ($old_form) = @_;
-
-  map({ delete($form->{$_}); } keys(%{$form}));
+  my ($old_form, $no_delete) = @_;
 
-  foreach my $pair (split('&', $old_form)) {
-    my ($key, $value) = split('=', $form->unescape($pair), 2);
-    $form->{$key} = $value;
-  }
+  map({ delete($form->{$_}); } keys(%{$form})) unless ($no_delete);
+  eval($old_form);
 
   $lxdebug->leave_sub();
 }
@@ -400,72 +401,91 @@ sub calculate_qty {
   $lxdebug->leave_sub();
 }
 
-sub calculate_alu {
+sub set_longdescription {
   $lxdebug->enter_sub();
 
 
+  my $callback = "$form->{script}?action=set_longdescription&";
+  map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
+      (qw(login path password name input_name input_id), grep({ /^[fl]_/ } keys %$form)));
 
-  my ($length, $weight) = split /\r\n/,$form->{formel};
-
-  #print(STDERR "$form->{formel} Formel\n");
-  #print(STDERR "$form->{description} Description\n");
+  $form->{"title"} = $locale->text("Enter longdescription");
+  $form->header();
+  print($form->parse_html_template("generic/set_longdescription"));
 
-  map({ $form->{$_} = "" } (qw(qty_alu price_alu total_alu qty_eloxal price_eloxal total_eloxal total)));
+  $lxdebug->leave_sub();
+}
 
-  if ($form->{description} =~ /.*Alupreisberechnung.*/) {
-    $form->{description} =~ /.*Alupreisberechnung:\n(.*)kg Aluminiumprofil Einzelpreis: (.*) Gesamt: (.*)\n(.*)m Eloxal Einzelpreis: (.*) Gesamt: (.*)/;
-    $form->{qty_alu} = $1;
-    $form->{price_alu} = $2;
-    $form->{total_alu} = $3;
-    $form->{qty_eloxal} = $4;
-    $form->{price_eloxal} = $5;
-    $form->{total_eloxal} = $6;
-    $form->{total} = $form->format_amount(\%myconfig, ($form->parse_amount(\%myconfig, $form->{total_alu}) + $form->parse_amount(\%myconfig, $form->{total_eloxal})));
-  }
-  ($form->{description}, $null) = split /\nAlupreisberechnung/, $form->{description};
-  #map({ print(STDERR "$_ = $form->{$_}\n") } (qw(qty_alu price_alu total_alu qty_eloxal price_eloxal total_eloxal total)));
+sub H {
+  return $form->quote_html($_[0]);
+}
 
-  my $callback = "$form->{script}?action=vendor_selection&";
-  map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
-      (qw(login path password name input_name input_id), grep({ /^[fl]_/ } keys %$form)));
+sub format_dates {
+  $lxdebug->enter_sub();
 
-  my @header_sort = qw(name customernumber address);
-  my %header_title = ( "name" => $locale->text("Name"),
-                       "customernumber" => $locale->text("Customer Number"),
-                       "address" => $locale->text("Address"),
-                     );
-  ($null, $form->{weight}) = split / /, $weight;
-  ($null, $form->{length}) = split / /, $length;
+  my ($dateformat, $longformat, @indices) = @_;
 
-  $form->{calc_weight} = $form->parse_amount(\%myconfig, $form->{weight});
-  $form->{calc_length} = $form->parse_amount(\%myconfig, $form->{length});
+  $dateformat = $myconfig{"dateformat"} unless ($dateformat);
 
+  foreach my $idx (@indices) {
+    next unless (defined($form->{$idx}));
 
-  my @header =
-    map(+{ "column_title" => $header_title{$_},
-           "column" => $_,
-         },
-        @header_sort);
+    if (!ref($form->{$idx})) {
+      $form->{$idx} = $locale->reformat_date(\%myconfig, $form->{$idx},
+                                             $dateformat, $longformat);
 
-  $form->{"title"} = $locale->text("Enter values for aluminium calculation");
-  $form->header();
-  print($form->parse_html_template("generic/calculate_alu"));
+    } elsif (ref($form->{$idx}) eq "ARRAY") {
+      for (my $i = 0; $i < scalar(@{$form->{$idx}}); $i++) {
+        $form->{$idx}->[$i] =
+          $locale->reformat_date(\%myconfig, $form->{$idx}->[$i],
+                                 $dateformat, $longformat);
+      }
+    }
+  }
 
   $lxdebug->leave_sub();
 }
 
-
-sub set_longdescription {
+sub reformat_numbers {
   $lxdebug->enter_sub();
 
+  my ($numberformat, $places, @indices) = @_;
 
-  my $callback = "$form->{script}?action=set_longdescription&";
-  map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" }
-      (qw(login path password name input_name input_id), grep({ /^[fl]_/ } keys %$form)));
+  return $lxdebug->leave_sub()
+    if (!$numberformat || ($numberformat eq $myconfig{"numberformat"}));
 
-  $form->{"title"} = $locale->text("Enter longdescription");
-  $form->header();
-  print($form->parse_html_template("generic/set_longdescription"));
+  foreach my $idx (@indices) {
+    next unless (defined($form->{$idx}));
+
+    if (!ref($form->{$idx})) {
+      $form->{$idx} = $form->parse_amount(\%myconfig, $form->{$idx});
+
+    } elsif (ref($form->{$idx}) eq "ARRAY") {
+      for (my $i = 0; $i < scalar(@{$form->{$idx}}); $i++) {
+        $form->{$idx}->[$i] =
+          $form->parse_amount(\%myconfig, $form->{$idx}->[$i]);
+      }
+    }
+  }
+
+  my $saved_numberformat = $myconfig{"numberformat"};
+  $myconfig{"numberformat"} = $numberformat;
+
+  foreach my $idx (@indices) {
+    next unless (defined($form->{$idx}));
+
+    if (!ref($form->{$idx})) {
+      $form->{$idx} = $form->format_amount(\%myconfig, $form->{$idx}, $places);
+
+    } elsif (ref($form->{$idx}) eq "ARRAY") {
+      for (my $i = 0; $i < scalar(@{$form->{$idx}}); $i++) {
+        $form->{$idx}->[$i] =
+          $form->format_amount(\%myconfig, $form->{$idx}->[$i], $places);
+      }
+    }
+  }
+
+  $myconfig{"numberformat"} = $saved_numberformat;
 
   $lxdebug->leave_sub();
 }