Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 8c7e4493

Von Moritz Bunkus vor fast 17 Jahren hinzugefügt

  • ID 8c7e44938a661e035f62840e1e177353240ace5d
  • Vorgänger 3ced230b
  • Nachfolger ce45d060

Umstellung der Benutzerverwaltung von Dateien im Verzeichnis "users" auf die Verwendung einer Authentifizierungsdatenbank.
Es ist erforderlich, die Dateien doc/UPGRADE und doc/INSTALL/index.html zu lesen und die angesprochenen Punkte auszuführen, um nach einem Upgrade weiter arbeiten zu können.

Unterschiede anzeigen:

SL/Form.pm
38 38
package Form;
39 39
use Data::Dumper;
40 40

  
41
use Cwd;
42
use Template;
43
use SL::Template;
41
use CGI;
44 42
use CGI::Ajax;
43
use Cwd;
44
use List::Util qw(min max);
45
use SL::Auth;
46
use SL::Auth::DB;
47
use SL::Auth::LDAP;
48
use SL::AM;
49
use SL::Common;
45 50
use SL::DBUtils;
46 51
use SL::Mailer;
47 52
use SL::Menu;
53
use SL::Template;
48 54
use SL::User;
49
use SL::Common;
50
use CGI;
55
use Template;
51 56
use List::Util qw(max min sum);
52 57

  
53 58
my $standard_dbh;
......
275 280
  return @variables;
276 281
}
277 282

  
283
sub flatten_standard_variables {
284
  $main::lxdebug->enter_sub(2);
285

  
286
  my $self      = shift;
287
  my %skip_keys = map { $_ => 1 } (qw(login password header stylesheet titlebar version), @_);
288

  
289
  my @variables;
290

  
291
  foreach (grep { ! $skip_keys{$_} } keys %{ $self }) {
292
    push @variables, $self->_flatten_variables_rec($self, '', $_);
293
  }
294

  
295
  $main::lxdebug->leave_sub(2);
296

  
297
  return @variables;
298
}
278 299

  
279 300
sub debug {
280 301
  $main::lxdebug->enter_sub();
......
288 309
  $main::lxdebug->leave_sub();
289 310
}
290 311

  
312
sub dumper {
313
  $main::lxdebug->enter_sub(2);
314

  
315
  my $self          = shift;
316
  my $password      = $self->{password};
317

  
318
  $self->{password} = 'X' x 8;
319

  
320
  local $Data::Dumper::Sortkeys = 1;
321
  my $output                    = Dumper($self);
322

  
323
  $self->{password} = $password;
324

  
325
  $main::lxdebug->leave_sub(2);
326

  
327
  return $output;
328
}
329

  
291 330
sub escape {
292 331
  $main::lxdebug->enter_sub(2);
293 332

  
......
343 382
  my ($self, $str) = @_;
344 383

  
345 384
  my %replace =
346
    ('order' => ['"', '<', '>'],
347
     '<'             => '&lt;',
348
     '>'             => '&gt;',
349
     '"'             => '&quot;',
385
    ('order' => ['&', '"', '<', '>'],
386
     '<'     => '&lt;',
387
     '>'     => '&gt;',
388
     '"'     => '&quot;',
389
     '&'     => '&amp;',
350 390
    );
351 391

  
352 392
  map({ $str =~ s/$_/$replace{$_}/g; } @{ $replace{"order"} });
......
356 396
  return $str;
357 397
}
358 398

  
399
sub unquote_html {
400
  $main::lxdebug->enter_sub(2);
401

  
402
  my ($self, $str) = @_;
403

  
404
  my %replace  =
405
    ('&auml;'  => '?',
406
     '&ouml;'  => '?',
407
     '&uuml;'  => '?',
408
     '&Auml;'  => '?',
409
     '&Ouml;'  => '?',
410
     '&Uuml;'  => '?',
411
     '&szlig;' => '?',
412
     '&gt;'    => '>',
413
     '&lt;'    => '<',
414
     '&quot;'  => '"',
415
    );
416

  
417
  map { $str =~ s/\Q$_\E/$replace{$_}/g; } keys %replace;
418
  $str =~ s/\&amp;/\&/g;
419

  
420
  $main::lxdebug->leave_sub(2);
421

  
422
  return $str;
423
}
424

  
425

  
359 426
sub hide_form {
360 427
  my $self = shift;
361 428

  
......
423 490
# can be capped with maxrows
424 491
sub numtextrows {
425 492
  $main::lxdebug->enter_sub();
426
  my ($self, $str, $cols, $maxrows) = @_;
493
  my ($self, $str, $cols, $maxrows, $minrows) = @_;
494

  
495
  $minrows ||= 1;
427 496

  
428 497
  my $rows   = sum map { int((length() - 2) / $cols) + 1 } split /\r/, $str;
429 498
  $maxrows ||= $rows;
430 499

  
431 500
  $main::lxdebug->leave_sub();
432
  return min $rows, $maxrows;
501

  
502
  return max(min($rows, $maxrows), $minrows);
433 503
}
434 504

  
435 505
sub dberror {
......
468 538
    return;
469 539
  }
470 540

  
541
  my $cgi   = $main::cgi;
542
  $cgi    ||= CGI->new('');
543

  
471 544
  my ($stylesheet, $favicon);
472 545

  
473 546
  if ($ENV{HTTP_USER_AGENT}) {
......
528 601
    foreach $item (@ { $self->{AJAX} }) {
529 602
      $ajax .= $item->show_javascript();
530 603
    }
531
    print qq|Content-Type: text/html; charset=${db_charset};
532 604

  
533
${doctype}<html>
605
    my $base_path;
606

  
607
    if ($ENV{HTTP_X_FORWARDED_FOR}) {
608
      $base_path =  $ENV{HTTP_REFERER};
609
      $base_path =~ s|^.*?://.*?/|/|;
610
    } else {
611
      $base_path =  $ENV{REQUEST_URI};
612
    }
613
    $base_path =~ s|[^/]+$||;
614
    $base_path =~ s|/$||;
615

  
616
    my $session_cookie;
617
    if (defined $main::auth) {
618
      my $session_cookie_value   = $main::auth->get_session_id();
619
      $session_cookie_value    ||= 'NO_SESSION';
620

  
621
      $session_cookie = $cgi->cookie('-name'  => $main::auth->get_session_cookie_name(),
622
                                     '-value' => $session_cookie_value,
623
                                     '-path'  => $base_path);
624
    }
625

  
626
    print $cgi->header('-type'    => 'text/html',
627
                       '-charset' => $db_charset,
628
                       '-cookie'  => $session_cookie);
629
    print qq|${doctype}<html>
534 630
<head>
535 631
  <title>$self->{titlebar}</title>
536 632
  $stylesheet
......
633 729
    map { $additional_params->{'DEBUG_' . uc($_)} = $main::debug_options{$_} } keys %main::debug_options;
634 730
  }
635 731

  
732
  if ($main::auth && $main::auth->{RIGHTS} && $main::auth->{RIGHTS}->{$self->{login}}) {
733
    while (my ($key, $value) = each %{ $main::auth->{RIGHTS}->{$self->{login}} }) {
734
      $additional_params->{"AUTH_RIGHTS_" . uc($key)} = $value;
735
    }
736
  }
737

  
636 738
  $main::lxdebug->leave_sub();
637 739

  
638 740
  return $file;
......
837 939
  $main::lxdebug->leave_sub(2);
838 940
  return $amount;
839 941
}
840
#
942

  
943
sub format_amount_units {
944
  $main::lxdebug->enter_sub();
945

  
946
  my $self             = shift;
947
  my %params           = @_;
948

  
949
  Common::check_params(\%params, qw(amount part_unit));
950

  
951
  my $myconfig         = \%main::myconfig;
952
  my $amount           = $params{amount};
953
  my $places           = $params{places};
954
  my $part_unit_name   = $params{part_unit};
955
  my $amount_unit_name = $params{amount_unit};
956
  my $conv_units       = $params{conv_units};
957
  my $max_places       = $params{max_places};
958

  
959
  AM->retrieve_all_units();
960
  my $all_units        = $main::all_units;
961

  
962
  if (('' eq ref $conv_units) && ($conv_units =~ /convertible/)) {
963
    $conv_units = AM->convertible_units($all_units, $part_unit_name, $conv_units eq 'convertible_not_smaller');
964
  }
965

  
966
  if (!scalar @{ $conv_units }) {
967
    my $result = $self->format_amount($myconfig, $amount, $places, undef, $max_places) . " " . $part_unit_name;
968
    $main::lxdebug->leave_sub();
969
    return $result;
970
  }
971

  
972
  my $part_unit  = $all_units->{$part_unit_name};
973
  my $conv_unit  = ($amount_unit_name && ($amount_unit_name ne $part_unit_name)) ? $all_units->{$amount_unit_name} : $part_unit;
974

  
975
  $amount       *= $conv_unit->{factor};
976

  
977
  my @values;
978

  
979
  foreach my $unit (@$conv_units) {
980
    my $last = $unit->{name} eq $part_unit->{name};
981
    if (!$last) {
982
      $num     = int($amount / $unit->{factor});
983
      $amount -= $num * $unit->{factor};
984
    }
985

  
986
    if ($last ? $amount : $num) {
987
      push @values, { "unit"   => $unit->{name},
988
                      "amount" => $last ? $amount / $unit->{factor} : $num,
989
                      "places" => $last ? $places : 0 };
990
    }
991

  
992
    last if $last;
993
  }
994

  
995
  if (!@values) {
996
    push @values, { "unit"   => $part_unit_name,
997
                    "amount" => 0,
998
                    "places" => 0 };
999
  }
1000

  
1001
  my $result = join " ", map { $self->format_amount($myconfig, $_->{amount}, $_->{places}, undef, $max_places), $_->{unit} } @values;
1002

  
1003
  $main::lxdebug->leave_sub();
1004

  
1005
  return $result;
1006
}
841 1007

  
842 1008
sub format_string {
843 1009
  $main::lxdebug->enter_sub(2);
......
854 1020
  return $input;
855 1021
}
856 1022

  
1023
#
1024

  
857 1025
sub parse_amount {
858 1026
  $main::lxdebug->enter_sub(2);
859 1027

  
......
937 1105
  map({ $self->{"employee_${_}"} = $myconfig->{$_}; }
938 1106
      qw(email tel fax name signature company address businessnumber
939 1107
         co_ustid taxnumber duns));
940
  map({ $self->{"employee_${_}"} =~ s/\\n/\n/g; }
941
      qw(company address signature));
942
  map({ $self->{$_} =~ s/\\n/\n/g; } qw(company address signature));
943 1108

  
944 1109
  map({ $self->{"${_}"} = $myconfig->{$_}; }
945 1110
      qw(co_ustid));
......
994 1159
      $mail->{to} = $self->{EMAIL_RECIPIENT} ? $self->{EMAIL_RECIPIENT} : $self->{email};
995 1160
      $mail->{from}   = qq|"$myconfig->{name}" <$myconfig->{email}>|;
996 1161
      $mail->{fileid} = "$fileid.";
997
      $myconfig->{signature} =~ s/\\r\\n/\\n/g;
1162
      $myconfig->{signature} =~ s/\r//g;
998 1163

  
999 1164
      # if we send html or plain text inline
1000 1165
      if (($self->{format} eq 'html') && ($self->{sendmode} eq 'inline')) {
1001 1166
        $mail->{contenttype} = "text/html";
1002 1167

  
1003
        $mail->{message}       =~ s/\r\n/<br>\n/g;
1004
        $myconfig->{signature} =~ s/\\n/<br>\n/g;
1168
        $mail->{message}       =~ s/\r//g;
1169
        $mail->{message}       =~ s/\n/<br>\n/g;
1170
        $myconfig->{signature} =~ s/\n/<br>\n/g;
1005 1171
        $mail->{message} .= "<br>\n-- <br>\n$myconfig->{signature}\n<br>";
1006 1172

  
1007 1173
        open(IN, $self->{tmpfile})
......
1021 1187
                 $self->{"attachment_filename"} : $self->{"tmpfile"} });
1022 1188
        }
1023 1189

  
1024
        $mail->{message}       =~ s/\r\n/\n/g;
1025
        $myconfig->{signature} =~ s/\\n/\n/g;
1026
        $mail->{message} .= "\n-- \n$myconfig->{signature}";
1190
        $mail->{message}  =~ s/\r//g;
1191
        $mail->{message} .=  "\n-- \n$myconfig->{signature}";
1027 1192

  
1028 1193
      }
1029 1194

  
......
1109 1274
sub generate_attachment_filename {
1110 1275
  my ($self) = @_;
1111 1276

  
1112
  my $attachment_filename = $self->get_formname_translation();
1277
  my $attachment_filename = $self->unquote_html($self->get_formname_translation());
1113 1278
  my $prefix = 
1114 1279
      (grep { $self->{"type"} eq $_ } qw(invoice credit_note)) ? "inv"
1115 1280
    : ($self->{"type"} =~ /_quotation$/)                       ? "quo"
......
1688 1853

  
1689 1854
    $self->{salesman_name} = $login
1690 1855
      if ($self->{salesman_name} eq "");
1691

  
1692
    map({ $self->{"salesman_$_"} =~ s/\\n/\n/g; } qw(address company));
1693 1856
  }
1694 1857

  
1695 1858
  $main::lxdebug->leave_sub();
......
1862 2025
  my ($self, $dbh, $default_key, $key) = @_;
1863 2026

  
1864 2027
  $key = $default_key unless ($key);
1865
  $self->{$key} = selectall_hashref_query($self, $dbh, qq|SELECT * FROM employee ORDER BY name|);
2028
  $self->{$key} = selectall_hashref_query($self, $dbh, qq|SELECT * FROM employee ORDER BY lower(name)|);
1866 2029

  
1867 2030
  $main::lxdebug->leave_sub();
1868 2031
}
......
1978 2141
  $main::lxdebug->leave_sub();
1979 2142
}
1980 2143

  
1981
sub _get_price_factors {
2144
sub _get_warehouses {
1982 2145
  $main::lxdebug->enter_sub();
1983 2146

  
1984
  my ($self, $dbh, $key) = @_;
2147
  my ($self, $dbh, $param) = @_;
2148

  
2149
  my ($key, $bins_key, $q_access, @values);
2150

  
2151
  if ('' eq ref $param) {
2152
    $key = $param;
2153
  } else {
2154
    $key      = $param->{key};
2155
    $bins_key = $param->{bins};
2156

  
2157
    if ($param->{access}) {
2158
      $q_access =
2159
        qq| AND EXISTS (
2160
              SELECT wa.employee_id
2161
              FROM warehouse_access wa
2162
              WHERE (wa.employee_id  = (SELECT id FROM employee WHERE login = ?))
2163
                AND (wa.warehouse_id = w.id)
2164
                AND (wa.access IN ('ro', 'rw')))|;
2165
      push @values, $param->{access};
2166
    }
2167

  
2168
    if ($param->{no_personal}) {
2169
      $q_access .= qq| AND (w.personal_warehouse_of IS NULL)|;
2170

  
2171
    } elsif ($param->{personal}) {
2172
      $q_access .= qq| AND (w.personal_warehouse_of = ?)|;
2173
      push @values, conv_i($param->{personal});
2174
    }
2175
  }
2176

  
2177
  my $query = qq|SELECT w.* FROM warehouse w
2178
                 WHERE (NOT w.invalid) AND
2179
                   ((SELECT COUNT(b.*) FROM bin b WHERE b.warehouse_id = w.id) > 0)
2180
                   $q_access
2181
                 ORDER BY w.sortkey|;
2182

  
2183
  $self->{$key} = selectall_hashref_query($self, $dbh, $query, @values);
1985 2184

  
1986
  $key ||= "all_price_factors";
2185
  if ($bins_key) {
2186
    $query = qq|SELECT id, description FROM bin WHERE warehouse_id = ?|;
2187
    my $sth = prepare_query($self, $dbh, $query);
1987 2188

  
1988
  my $query = qq|SELECT * FROM price_factors ORDER BY sortkey|;
2189
    foreach my $warehouse (@{ $self->{$key} }) {
2190
      do_statement($self, $sth, $query, $warehouse->{id});
2191
      $warehouse->{$bins_key} = [];
2192

  
2193
      while (my $ref = $sth->fetchrow_hashref()) {
2194
        push @{ $warehouse->{$bins_key} }, $ref;
2195
      }
2196
    }
2197
    $sth->finish();
2198
  }
2199

  
2200
  $main::lxdebug->leave_sub();
2201
}
2202

  
2203
sub _get_simple {
2204
  $main::lxdebug->enter_sub();
2205

  
2206
  my ($self, $dbh, $table, $key, $sortkey) = @_;
2207

  
2208
  my $query  = qq|SELECT * FROM $table|;
2209
  $query    .= qq| ORDER BY $sortkey| if ($sortkey);
1989 2210

  
1990 2211
  $self->{$key} = selectall_hashref_query($self, $dbh, $query);
1991 2212

  
......
2083 2304
  }
2084 2305

  
2085 2306
  if ($params{price_factors}) {
2086
    $self->_get_price_factors($dbh, $params{price_factors});
2307
    $self->_get_simple($dbh, 'price_factors', $params{price_factors}, 'sortkey');
2308
  }
2309

  
2310
  if ($params{warehouses}) {
2311
    $self->_get_warehouses($dbh, $params{warehouses});
2087 2312
  }
2088 2313

  
2089 2314
  $main::lxdebug->leave_sub();

Auch abrufbar als: Unified diff