X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=C4%2FInput.pm;h=ba304607a716cefcd1eecb9ebdfd645394880029;hb=7c518bd250cd2283a055d4547085cd6db6488cf7;hp=e45ba4f8242e91b59a521c02d59fe4ded26e2767;hpb=2eb8039732d287b05e435899bda3a7281902947b;p=koha_fer diff --git a/C4/Input.pm b/C4/Input.pm index e45ba4f824..ba304607a7 100644 --- a/C4/Input.pm +++ b/C4/Input.pm @@ -14,9 +14,9 @@ package C4::Input; #assumes C4/Input # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. See the GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License along with -# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, -# Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. use strict; use warnings; @@ -28,7 +28,7 @@ use CGI; use vars qw($VERSION @ISA @EXPORT); # set the version for version checking -$VERSION = 0.01; +$VERSION = 3.07.00.049; =head1 NAME @@ -119,33 +119,48 @@ Returns NULL if no authorised values found =cut sub buildCGIsort { - my ($name,$input_name,$data) = @_; - my $dbh=C4::Context->dbh; - my $query=qq{SELECT * FROM authorised_values WHERE category=? order by lib}; - my $sth=$dbh->prepare($query); - $sth->execute($name); - my $CGISort; - if ($sth->rows>0){ - my @values; - my %labels; - - for (my $i =0;$i<$sth->rows;$i++){ - my $results = $sth->fetchrow_hashref; - push @values, $results->{authorised_value}; - $labels{$results->{authorised_value}}=$results->{lib}; - } - $CGISort= CGI::scrolling_list( - -name => $input_name, - -id => $input_name, - -values => \@values, - -labels => \%labels, - -default=> $data, - -size => 1, - -multiple => 0); - } - $sth->finish; - return $CGISort; + my ( $name, $input_name, $data ) = @_; + my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; + + my $dbh=C4::Context->dbh; + my $query = qq{ + SELECT * + FROM authorised_values + }; + $query .= qq{ + LEFT JOIN authorised_values_branches ON ( id = av_id ) + } if $branch_limit; + $query .= qq{ + WHERE category = ? + }; + $query .= qq{ AND ( branchcode = ? OR branchcode IS NULL )} if $branch_limit; + $query .= qq{ GROUP BY lib ORDER BY lib}; + + my $sth=$dbh->prepare($query); + $sth->execute( $name, $branch_limit ? $branch_limit : () ); + my $CGISort; + if ($sth->rows>0){ + my @values; + my %labels; + + for (my $i =0;$i<$sth->rows;$i++){ + my $results = $sth->fetchrow_hashref; + push @values, $results->{authorised_value}; + $labels{$results->{authorised_value}}=$results->{lib}; + } + $CGISort= CGI::scrolling_list( + -name => $input_name, + -id => $input_name, + -values => \@values, + -labels => \%labels, + -default=> $data, + -size => 1, + -multiple => 0); + } + $sth->finish; + return $CGISort; } + END { } # module clean-up code here (global destructor) 1; @@ -155,6 +170,6 @@ __END__ =head1 AUTHOR -Koha Developement team +Koha Development Team =cut