Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision d74658f5

Von Moritz Bunkus vor fast 9 Jahren hinzugefügt

  • ID d74658f5dddbb93a3c1f641041ad68374a0cbd0a
  • Vorgänger 1aa3ce07
  • Nachfolger d16c1b3c

Artikelsuche: bei Textfeldern führende/anhängende Whitespaces entfernen

Unterschiede anzeigen:

SL/IC.pm
42 42
use SL::DBUtils;
43 43
use SL::HTML::Restrict;
44 44
use SL::TransNumber;
45
use SL::Util qw(trim);
45 46

  
46 47
use strict;
47 48

  
......
590 591

  
591 592
  if ($form->{partnumber}) {
592 593
    $where .= qq| AND (p.partnumber ILIKE ?)|;
593
    push(@values, '%' . $form->{partnumber} . '%');
594
    push(@values, $::form->like($form->{partnumber}));
594 595
  }
595 596

  
596 597
  if ($form->{description}) {
597 598
    $where .= qq| AND (p.description ILIKE ?)|;
598
    push(@values, '%' . $form->{description} . '%');
599
    push(@values, $::form->like($form->{description}));
599 600
  }
600 601

  
601 602
  # retrieve assembly items
......
651 652
  while (my ($column, $table) = each(%columns)) {
652 653
    next unless ($form->{"${column}_$i"});
653 654
    $where .= qq| AND ${table}.${column} ILIKE ?|;
654
    push(@values, '%' . $form->{"${column}_$i"} . '%');
655
    push(@values, $::form->like($form->{"${column}_$i"}));
655 656
  }
656 657

  
657 658
  if ($form->{id}) {
......
862 863
  #===== switches and simple filters ========#
863 864

  
864 865
  # special case transdate
865
  if (grep { $form->{$_} } qw(transdatefrom transdateto)) {
866
  if (grep { trim($form->{$_}) } qw(transdatefrom transdateto)) {
866 867
    $form->{"l_transdate"} = 1;
867 868
    push @select_tokens, 'transdate';
868 869
    for (qw(transdatefrom transdateto)) {
869
      next unless $form->{$_};
870
      my $value = trim($form->{$_});
871
      next unless $value;
870 872
      push @where_tokens, sprintf "transdate %s ?", /from$/ ? '>=' : '<=';
871
      push @bind_vars,    $form->{$_};
873
      push @bind_vars,    $value;
872 874
    }
873 875
  }
874 876

  
......
880 882
  }
881 883

  
882 884
  # special case insertdate
883
  if (grep { $form->{$_} } qw(insertdatefrom insertdateto)) {
885
  if (grep { trim($form->{$_}) } qw(insertdatefrom insertdateto)) {
884 886
    $form->{"l_insertdate"} = 1;
885 887
    push @select_tokens, 'insertdate';
886 888

  
......
888 890
    my $token = $token_builder->('insertdate');
889 891

  
890 892
    for (qw(insertdatefrom insertdateto)) {
891
      next unless $form->{$_};
893
      my $value = trim($form->{$_});
894
      next unless $value;
892 895
      push @where_tokens, sprintf "$token %s ?", /from$/ ? '>=' : '<=';
893
      push @bind_vars,    $form->{$_};
896
      push @bind_vars,    $value;
894 897
    }
895 898
  }
896 899

  
......
914 917
    next unless $form->{$_};
915 918
    $form->{"l_$_"} = '1'; # show the column
916 919
    push @where_tokens, "$table_prefix{$_}$_ ILIKE ?";
917
    push @bind_vars,    "%$form->{$_}%";
920
    push @bind_vars,    $::form->like($form->{$_});
918 921
  }
919 922

  
920 923
  foreach (@simple_l_switches) {
......
955 958
  # fortunately makemodel doesn't need to be displayed later, so adding a special clause to where_token is sufficient.
956 959
  if ($form->{make}) {
957 960
    push @where_tokens, 'mv.name ILIKE ?';
958
    push @bind_vars, "%$form->{make}%";
961
    push @bind_vars, $::form->like($form->{make});
959 962
  }
960 963
  if ($form->{model}) {
961 964
    push @where_tokens, 'mm.model ILIKE ?';
962
    push @bind_vars, "%$form->{model}%";
965
    push @bind_vars, $::form->like($form->{model});
963 966
  }
964 967

  
965 968
  # special case: sorting by partnumber
......
1153 1156
    next unless ($form->{$column});
1154 1157

  
1155 1158
    $where .= qq| AND $item ILIKE ?|;
1156
    push(@where_values, '%' . $form->{$column} . '%');
1159
    push(@where_values, $::form->like($form->{$column}));
1157 1160
  }
1158 1161

  
1159 1162
  foreach my $item (qw(description serialnumber)) {
1160 1163
    next unless ($form->{$item});
1161 1164

  
1162 1165
    $where .= qq| AND (${item} ILIKE ?)|;
1163
    push(@where_values, '%' . $form->{$item} . '%');
1166
    push(@where_values, $::form->like($form->{$item}));
1164 1167
  }
1165 1168

  
1166 1169

  
......
1194 1197
  foreach my $column (qw(make model)) {
1195 1198
    next unless ($form->{$column});
1196 1199
    $where .= qq| AND p.id IN (SELECT DISTINCT parts_id FROM makemodel WHERE $column ILIKE ?|;
1197
    push(@where_values, '%' . $form->{$column} . '%');
1200
    push(@where_values, $::form->like($form->{$column}));
1198 1201
  }
1199 1202

  
1200 1203
  $main::lxdebug->leave_sub();
......
1408 1411

  
1409 1412
  if ($sortorder eq "all") {
1410 1413
    $where .= qq| AND (partnumber ILIKE ?) AND (description ILIKE ?)|;
1411
    push(@values, '%' . $form->{partnumber} . '%', '%' . $form->{description} . '%');
1414
    push(@values, $::form->like($form->{partnumber}), $::form->like($form->{description}));
1412 1415

  
1413 1416
  } elsif ($sortorder eq "partnumber") {
1414 1417
    $where .= qq| AND (partnumber ILIKE ?)|;
1415
    push(@values, '%' . $form->{partnumber} . '%');
1418
    push(@values, $::form->like($form->{partnumber}));
1416 1419

  
1417 1420
  } elsif ($sortorder eq "description") {
1418 1421
    $where .= qq| AND (description ILIKE ?)|;
1419
    push(@values, '%' . $form->{description} . '%');
1422
    push(@values, $::form->like($form->{description}));
1420 1423
    $order = "description";
1421 1424

  
1422 1425
  }

Auch abrufbar als: Unified diff