X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/15682dc47316fcc2deab66730045cd38afec001f..a4b22a8f008d6431597fa80de26bcb0fa10e8d7b:/SL/Form.pm diff --git a/SL/Form.pm b/SL/Form.pm index c4eaf2259..842afe8af 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -1425,6 +1425,63 @@ sub get_contacts { $main::lxdebug->leave_sub(); } +sub get_projects { + $main::lxdebug->enter_sub(); + + my ($self, $dbh, $key) = @_; + + my ($all, $old_id, $where, @values); + + if (ref($key) eq "HASH") { + my $params = $key; + + $key = "ALL_PROJECTS"; + + foreach my $p (keys(%{$params})) { + if ($p eq "all") { + $all = $params->{$p}; + } elsif ($p eq "old_id") { + $old_id = $params->{$p}; + } elsif ($p eq "key") { + $key = $params->{$p}; + } + } + } + + if (!$all) { + $where = "WHERE active "; + if ($old_id) { + if (ref($old_id) eq "ARRAY") { + my @ids = grep({ $_ } @{$old_id}); + if (@ids) { + $where .= " OR id IN (" . join(",", map({ "?" } @ids)) . ") "; + push(@values, @ids); + } + } else { + $where .= " OR (id = ?) "; + push(@values, $old_id); + } + } + } + + my $query = + qq|SELECT id, projectnumber, description, active | . + qq|FROM project | . + $where . + qq|ORDER BY lower(projectnumber)|; + my $sth = $dbh->prepare($query); + $sth->execute(@values) || + $self->dberror($query . " (" . join(", ", @values) . ")"); + + $self->{$key} = []; + while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { + push(@{ $self->{$key} }, $ref); + } + + $sth->finish; + $main::lxdebug->leave_sub(); +} + sub get_lists { $main::lxdebug->enter_sub(); @@ -1457,6 +1514,12 @@ sub get_lists { $sth->finish; } + if ($params{"projects"} || $params{"all_projects"}) { + $self->get_projects($dbh, $params{"all_projects"} ? + $params{"all_projects"} : $params{"projects"}, + $params{"all_projects"} ? 1 : 0); + } + $dbh->disconnect(); $main::lxdebug->leave_sub();