From f6d2ffa98467e68c04784c0d57368b5e94b1a9dc Mon Sep 17 00:00:00 2001 From: Joe Atzberger Date: Wed, 8 Jul 2009 16:52:18 -0500 Subject: [PATCH] Branch auto-selection in additem Adding a new item should pre-select the library you are logged in at, where possible. Use GetBranchesLoop. This solves indy branches filtering, and sort order problems. Set default off of ->{selected}, to establish pre-selected branch. Fix flags check in onlymine sub, so superlibrarian + other flags still gets everything. Removed defined(@array) check, since perl -wc warns it is deprecated. Note new FIXME for botched date processing. Signed-off-by: Galen Charlton --- C4/Branch.pm | 2 +- cataloguing/additem.pl | 19 ++++++++----------- .../prog/en/modules/cataloguing/additem.tmpl | 2 +- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/C4/Branch.pm b/C4/Branch.pm index a2558d9c76..7dfd737245 100644 --- a/C4/Branch.pm +++ b/C4/Branch.pm @@ -141,7 +141,7 @@ sub onlymine { return C4::Context->preference('IndependantBranches') && C4::Context->userenv && - C4::Context->userenv->{flags}!=1 && + C4::Context->userenv->{flags} %2 != 1 && C4::Context->userenv->{branch} ; } diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index 2cb20dde34..bc2bbfc85c 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -198,8 +198,7 @@ my ($branchtagfield, $branchtagsubfield) = &GetMarcFromKohaField("items.homebran foreach my $field (@fields) { next if ($field->tag()<10); - my @subf = $field->subfields; - (defined @subf) or @subf = (); + my @subf = $field->subfields || (); my %this_row; # loop through each subfield for my $i (0..$#subf) { @@ -287,7 +286,7 @@ foreach my $tag (sort keys %{$tagslib}) { unless ($value) { $value = $tagslib->{$tag}->{$subfield}->{defaultvalue}; # get today date & replace YYYY, MM, DD if provided in the default value - my ( $year, $month, $day ) = split ',', $today_iso; + my ( $year, $month, $day ) = split ',', $today_iso; # FIXME: iso dates don't have commas! $value =~ s/YYYY/$year/g; $value =~ s/MM/$month/g; $value =~ s/DD/$day/g; @@ -320,27 +319,25 @@ foreach my $tag (sort keys %{$tagslib}) { # builds list, depending on authorised value... if ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "branches" ) { - foreach my $thisbranch ( sort keys %$branches ) { - push @authorised_values, $thisbranch; - $authorised_lib{$thisbranch} = $branches->{$thisbranch}->{'branchname'}; + foreach my $thisbranch (@$branches) { + push @authorised_values, $thisbranch->{value}; + $authorised_lib{$thisbranch->{value}} = $thisbranch->{branchname}; + $value = $thisbranch->{value} if $thisbranch->{selected}; } } elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) { push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} ); my $sth = $dbh->prepare("select itemtype,description from itemtypes order by description"); $sth->execute; - my $itemtype; # FIXME: double declaration of $itemtype while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) { push @authorised_values, $itemtype; $authorised_lib{$itemtype} = $description; } unless ( $value ) { - my $default_itemtype; my $itype_sth = $dbh->prepare("SELECT itemtype FROM biblioitems WHERE biblionumber = ?"); $itype_sth->execute( $biblionumber ); - ( $default_itemtype ) = $itype_sth->fetchrow_array; - $value = $default_itemtype; + ( $value ) = $itype_sth->fetchrow_array; } #---- class_sources @@ -370,7 +367,7 @@ foreach my $tag (sort keys %{$tagslib}) { $authorised_lib{$value} = $lib; } } - $subfield_data{marc_value} =CGI::scrolling_list( # FIXME: factor out scrolling_list + $subfield_data{marc_value} =CGI::scrolling_list( # FIXME: factor out scrolling_list -name => "field_value", -values => \@authorised_values, -default => $value, diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tmpl index 841279b702..ca745e471b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tmpl @@ -222,7 +222,7 @@ function set_to_today(id, force) { - + -- 2.39.5