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 <galen.charlton@liblime.com>
This commit is contained in:
parent
7c2e7ad410
commit
46b9ee7a93
3 changed files with 12 additions and 19 deletions
|
@ -141,7 +141,7 @@ sub onlymine {
|
||||||
return
|
return
|
||||||
C4::Context->preference('IndependantBranches') &&
|
C4::Context->preference('IndependantBranches') &&
|
||||||
C4::Context->userenv &&
|
C4::Context->userenv &&
|
||||||
C4::Context->userenv->{flags}!=1 &&
|
C4::Context->userenv->{flags} %2 != 1 &&
|
||||||
C4::Context->userenv->{branch} ;
|
C4::Context->userenv->{branch} ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -197,8 +197,7 @@ my ($branchtagfield, $branchtagsubfield) = &GetMarcFromKohaField("items.homebran
|
||||||
|
|
||||||
foreach my $field (@fields) {
|
foreach my $field (@fields) {
|
||||||
next if ($field->tag()<10);
|
next if ($field->tag()<10);
|
||||||
my @subf = $field->subfields;
|
my @subf = $field->subfields || ();
|
||||||
(defined @subf) or @subf = ();
|
|
||||||
my %this_row;
|
my %this_row;
|
||||||
# loop through each subfield
|
# loop through each subfield
|
||||||
for my $i (0..$#subf) {
|
for my $i (0..$#subf) {
|
||||||
|
@ -254,11 +253,8 @@ my @loop_data =();
|
||||||
my $i=0;
|
my $i=0;
|
||||||
my $authorised_values_sth = $dbh->prepare("SELECT authorised_value,lib FROM authorised_values WHERE category=? ORDER BY lib");
|
my $authorised_values_sth = $dbh->prepare("SELECT authorised_value,lib FROM authorised_values WHERE category=? ORDER BY lib");
|
||||||
|
|
||||||
my $onlymine = C4::Context->preference('IndependantBranches') &&
|
my $branches = GetBranchesLoop(); # build once ahead of time, instead of multiple times later.
|
||||||
C4::Context->userenv &&
|
my $pref_itemcallnumber = C4::Context->preference('itemcallnumber');
|
||||||
C4::Context->userenv->{flags} % 2 == 0 &&
|
|
||||||
C4::Context->userenv->{branch};
|
|
||||||
my $branches = GetBranches($onlymine); # build once ahead of time, instead of multiple times later.
|
|
||||||
|
|
||||||
foreach my $tag (sort keys %{$tagslib}) {
|
foreach my $tag (sort keys %{$tagslib}) {
|
||||||
# loop through each subfield
|
# loop through each subfield
|
||||||
|
@ -286,14 +282,13 @@ foreach my $tag (sort keys %{$tagslib}) {
|
||||||
unless ($value) {
|
unless ($value) {
|
||||||
$value = $tagslib->{$tag}->{$subfield}->{defaultvalue};
|
$value = $tagslib->{$tag}->{$subfield}->{defaultvalue};
|
||||||
# get today date & replace YYYY, MM, DD if provided in the default value
|
# 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/YYYY/$year/g;
|
||||||
$value =~ s/MM/$month/g;
|
$value =~ s/MM/$month/g;
|
||||||
$value =~ s/DD/$day/g;
|
$value =~ s/DD/$day/g;
|
||||||
}
|
}
|
||||||
$subfield_data{visibility} = "display:none;" if (($tagslib->{$tag}->{$subfield}->{hidden} > 4) || ($tagslib->{$tag}->{$subfield}->{hidden} < -4));
|
$subfield_data{visibility} = "display:none;" if (($tagslib->{$tag}->{$subfield}->{hidden} > 4) || ($tagslib->{$tag}->{$subfield}->{hidden} < -4));
|
||||||
# testing branch value if IndependantBranches.
|
# testing branch value if IndependantBranches.
|
||||||
my $pref_itemcallnumber = C4::Context->preference('itemcallnumber');
|
|
||||||
if (!$value && $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.itemcallnumber' && $pref_itemcallnumber) {
|
if (!$value && $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.itemcallnumber' && $pref_itemcallnumber) {
|
||||||
my $CNtag = substr($pref_itemcallnumber, 0, 3);
|
my $CNtag = substr($pref_itemcallnumber, 0, 3);
|
||||||
my $CNsubfield = substr($pref_itemcallnumber, 3, 1);
|
my $CNsubfield = substr($pref_itemcallnumber, 3, 1);
|
||||||
|
@ -314,27 +309,25 @@ foreach my $tag (sort keys %{$tagslib}) {
|
||||||
# builds list, depending on authorised value...
|
# builds list, depending on authorised value...
|
||||||
|
|
||||||
if ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "branches" ) {
|
if ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "branches" ) {
|
||||||
foreach my $thisbranch ( sort keys %$branches ) {
|
foreach my $thisbranch (@$branches) {
|
||||||
push @authorised_values, $thisbranch;
|
push @authorised_values, $thisbranch->{value};
|
||||||
$authorised_lib{$thisbranch} = $branches->{$thisbranch}->{'branchname'};
|
$authorised_lib{$thisbranch->{value}} = $thisbranch->{branchname};
|
||||||
|
$value = $thisbranch->{value} if $thisbranch->{selected};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
|
elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
|
||||||
push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
|
push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
|
||||||
my $sth = $dbh->prepare("select itemtype,description from itemtypes order by description");
|
my $sth = $dbh->prepare("select itemtype,description from itemtypes order by description");
|
||||||
$sth->execute;
|
$sth->execute;
|
||||||
my $itemtype; # FIXME: double declaration of $itemtype
|
|
||||||
while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
|
while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
|
||||||
push @authorised_values, $itemtype;
|
push @authorised_values, $itemtype;
|
||||||
$authorised_lib{$itemtype} = $description;
|
$authorised_lib{$itemtype} = $description;
|
||||||
}
|
}
|
||||||
|
|
||||||
unless ( $value ) {
|
unless ( $value ) {
|
||||||
my $default_itemtype;
|
|
||||||
my $itype_sth = $dbh->prepare("SELECT itemtype FROM biblioitems WHERE biblionumber = ?");
|
my $itype_sth = $dbh->prepare("SELECT itemtype FROM biblioitems WHERE biblionumber = ?");
|
||||||
$itype_sth->execute( $biblionumber );
|
$itype_sth->execute( $biblionumber );
|
||||||
( $default_itemtype ) = $itype_sth->fetchrow_array;
|
( $value ) = $itype_sth->fetchrow_array;
|
||||||
$value = $default_itemtype;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#---- class_sources
|
#---- class_sources
|
||||||
|
@ -364,7 +357,7 @@ foreach my $tag (sort keys %{$tagslib}) {
|
||||||
$authorised_lib{$value} = $lib;
|
$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",
|
-name => "field_value",
|
||||||
-values => \@authorised_values,
|
-values => \@authorised_values,
|
||||||
-default => $value,
|
-default => $value,
|
||||||
|
|
|
@ -222,7 +222,7 @@ function set_to_today(id, force) {
|
||||||
<!-- /TMPL_IF -->
|
<!-- /TMPL_IF -->
|
||||||
|
|
||||||
</div></li>
|
</div></li>
|
||||||
<!-- /tmpl_loop -->
|
<!-- /TMPL_LOOP -->
|
||||||
</ol>
|
</ol>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<input type="hidden" name="indicator" value=" " />
|
<input type="hidden" name="indicator" value=" " />
|
||||||
|
|
Loading…
Reference in a new issue