Term::ReadLine::Perl::Bind in Console nicht nutzen
[kivitendo-erp.git] / SL / IC.pm
index d37f66f..191a2d3 100644 (file)
--- a/SL/IC.pm
+++ b/SL/IC.pm
@@ -40,6 +40,7 @@ use YAML;
 
 use SL::CVar;
 use SL::DBUtils;
+use SL::HTML::Restrict;
 use SL::TransNumber;
 
 use strict;
@@ -227,6 +228,7 @@ sub save {
   my @values;
   # connect to database, turn off AutoCommit
   my $dbh = $form->get_standard_dbh;
+  my $restricter = SL::HTML::Restrict->create;
 
   # save the part
   # make up a unique handle and store in partnumber field
@@ -324,6 +326,8 @@ sub save {
     $subq_expense = "NULL";
   }
 
+  normalize_text_blocks();
+
   $query =
     qq|UPDATE parts SET
          partnumber = ?,
@@ -369,7 +373,7 @@ sub save {
              $form->{lastcost},
              $form->{weight},
              $form->{unit},
-             $form->{notes},
+             $restricter->process($form->{notes}),
              $form->{formel},
              $form->{rop},
              conv_i($form->{warehouse_id}),
@@ -403,7 +407,7 @@ sub save {
     $sth   = $dbh->prepare($query);
 
     foreach my $translation (@translations) {
-      do_statement($form, $sth, $query, conv_i($form->{id}), conv_i($translation->{language_id}), $translation->{translation}, $translation->{longdescription});
+      do_statement($form, $sth, $query, conv_i($form->{id}), conv_i($translation->{language_id}), $translation->{translation}, $restricter->process($translation->{longdescription}));
     }
 
     $sth->finish();
@@ -1697,5 +1701,24 @@ sub prepare_parts_for_printing {
   $main::lxdebug->leave_sub();
 }
 
+sub normalize_text_blocks {
+  $main::lxdebug->enter_sub();
+
+  my $self     = shift;
+  my %params   = @_;
+
+  my $form     = $params{form}     || $main::form;
+
+  # check if feature is enabled (select normalize_part_descriptions from defaults)
+  return unless ($::instance_conf->get_normalize_part_descriptions);
+
+  foreach (qw(description notes)) {
+    $form->{$_} =~ s/\s+$//s;
+    $form->{$_} =~ s/^\s+//s;
+    $form->{$_} =~ s/ {2,}/ /g;
+  }
+   $main::lxdebug->leave_sub();
+}
+
 
 1;