From df97814f3034a3d5015546c4eca21f08ae951e37 Mon Sep 17 00:00:00 2001
From: Jonathan Druart
Date: Thu, 4 Feb 2016 15:24:23 +0000
Subject: [PATCH] Bug 15758: Koha::Libraries - Remove GetBranches
Signed-off-by: Owen Leonard
Signed-off-by: Kyle M Hall
---
C4/Auth.pm | 4 +-
C4/Branch.pm | 69 -------------------
C4/Circulation.pm | 13 ++--
C4/Context.pm | 6 ++
C4/ILSDI/Services.pm | 7 +-
C4/Items.pm | 1 +
C4/Overdues.pm | 4 +-
C4/Search.pm | 13 ++--
C4/ShelfBrowser.pm | 5 +-
C4/XSLT.pm | 7 +-
Koha/Libraries.pm | 21 +++++-
Koha/Template/Plugin/Branches.pm | 21 ++----
acqui/add_user_search.pl | 5 --
acqui/addorderiso2709.pl | 1 -
acqui/basket.pl | 18 +++--
acqui/basketheader.pl | 2 -
acqui/invoices.pl | 21 ------
acqui/lateorders.pl | 1 -
acqui/neworderempty.pl | 1 -
acqui/newordersubscription.pl | 14 ----
acqui/orderreceive.pl | 1 -
admin/add_user_search.pl | 5 --
admin/aqbudgets.pl | 15 ----
admin/authorised_values.pl | 15 ++--
admin/branch_transfer_limits.pl | 14 ----
admin/categories.pl | 12 ++--
admin/item_circulation_alerts.pl | 16 -----
admin/patron-attr-types.pl | 14 ++--
admin/smart-rules.pl | 2 +-
admin/transport-cost-matrix.pl | 9 +--
catalogue/detail.pl | 8 +--
catalogue/itemsearch.pl | 11 +--
catalogue/search.pl | 6 +-
cataloguing/addbiblio.pl | 18 ++---
.../value_builder/unimarc_field_4XX.pl | 1 -
circ/bookcount.pl | 9 +--
circ/branchtransfers.pl | 15 ++--
circ/circulation.pl | 1 -
circ/returns.pl | 22 +-----
circ/selectbranchprinter.pl | 10 +--
circ/transferstoreceive.pl | 12 ++--
.../prog/en/includes/branch-selector.inc | 6 +-
.../prog/en/includes/subscriptions-search.inc | 9 +--
.../prog/en/modules/acqui/invoices.tt | 12 ++--
.../prog/en/modules/admin/aqbudgets.tt | 5 +-
.../modules/admin/branch_transfer_limits.tt | 12 +---
.../modules/admin/item_circulation_alerts.tt | 12 ++--
.../prog/en/modules/admin/smart-rules.tt | 6 +-
.../intranet-tmpl/prog/en/modules/auth.tt | 3 +-
.../prog/en/modules/catalogue/advsearch.tt | 4 +-
.../prog/en/modules/catalogue/detail.tt | 6 +-
.../prog/en/modules/circ/bookcount.tt | 7 +-
.../prog/en/modules/circ/branchtransfers.tt | 6 +-
.../prog/en/modules/circ/returns.tt | 18 ++---
.../prog/en/modules/common/patron_search.tt | 8 ++-
.../en/modules/reports/borrowers_stats.tt | 2 +-
.../prog/en/modules/reserve/request.tt | 14 ++--
.../transferCollection.tt | 11 +--
.../prog/en/modules/serials/serials-search.tt | 18 ++---
.../en/modules/serials/subscription-add.tt | 10 ++-
.../prog/en/modules/suggestion/suggestion.tt | 17 +++--
.../prog/en/modules/tools/export.tt | 3 +-
.../prog/en/modules/tools/holidays.tt | 1 -
.../prog/en/modules/tools/inventory.tt | 2 +-
.../prog/en/modules/tools/koha-news.tt | 31 +++------
.../bootstrap/en/includes/item-status.inc | 4 +-
.../bootstrap/en/modules/opac-reserve.tt | 6 +-
.../bootstrap/en/modules/opac-topissues.tt | 3 +-
members/deletemem.pl | 1 -
members/guarantor_search.pl | 5 --
members/memberentry.pl | 1 -
members/pay.pl | 1 -
members/paycollect.pl | 1 -
members/readingrec.pl | 4 --
members/routing-lists.pl | 3 -
opac/opac-basket.pl | 6 +-
opac/opac-detail.pl | 16 ++---
opac/opac-reserve.pl | 15 ++--
opac/opac-search.pl | 14 ++--
opac/opac-topissues.pl | 3 +-
opac/opac-user.pl | 1 -
patroncards/add_user_search.pl | 5 --
reports/acquisitions_stats.pl | 8 +--
reports/borrowers_stats.pl | 5 +-
reports/issues_avg_stats.pl | 1 -
reports/issues_by_borrower_category.plugin | 2 -
reserve/request.pl | 20 ++----
rotating_collections/transferCollection.pl | 13 ----
serials/add_user_search.pl | 5 --
serials/serials-search.pl | 15 ----
serials/subscription-add.pl | 24 +------
suggestion/suggestion.pl | 31 ++-------
svc/cataloguing/framework | 8 +--
t/db_dependent/Circulation/GetIssues.t | 8 +--
t/db_dependent/Overdues.t | 5 +-
tools/export.pl | 53 +++++---------
tools/holidays.pl | 5 --
tools/inventory.pl | 1 -
tools/koha-news.pl | 4 --
tools/letter.pl | 1 -
tools/newHolidays.pl | 11 ++-
101 files changed, 292 insertions(+), 690 deletions(-)
diff --git a/C4/Auth.pm b/C4/Auth.pm
index 0bcad666df..cb6ecda104 100644
--- a/C4/Auth.pm
+++ b/C4/Auth.pm
@@ -1078,7 +1078,7 @@ sub checkauth {
$branchcode = $query->param('branch');
$branchname = Koha::Libraries->find($branchcode)->branchname;
}
- my $branches = C4::Branch::GetBranches();
+ my $branches = { map { $_->branchcode => $_->unblessed } Koha::Libraries->search };
if ( C4::Context->boolean_preference('IndependentBranches') && C4::Context->boolean_preference('Autolocation') ) {
# we have to check they are coming from the right ip range
@@ -1528,7 +1528,7 @@ sub check_api_auth {
$branchcode = $query->param('branch');
$branchname = Koha::Libraries->find($branchcode)->branchname;
}
- my $branches = C4::Branch::GetBranches();
+ my $branches = { map { $_->branchcode => $_->unblessed } Koha::Libraries->search };
foreach my $br ( keys %$branches ) {
# now we work with the treatment of ip
diff --git a/C4/Branch.pm b/C4/Branch.pm
index 7f1b713e76..a4f6b2f3bd 100644
--- a/C4/Branch.pm
+++ b/C4/Branch.pm
@@ -28,7 +28,6 @@ BEGIN {
@ISA = qw(Exporter);
@EXPORT = qw(
&GetBranch
- &GetBranches
);
@EXPORT_OK = qw( &onlymine );
}
@@ -47,76 +46,8 @@ The functions in this module deal with branches.
=head1 FUNCTIONS
-=head2 GetBranches
-
- $branches = &GetBranches();
-
-Returns informations about ALL branches, IndependentBranches Insensitive.
-
-Create a branch selector with the following code.
-
-=head3 in PERL SCRIPT
-
- my $branches = GetBranches;
- my @branchloop;
- foreach my $thisbranch (sort keys %$branches) {
- my $selected = 1 if $thisbranch eq $branch;
- my %row =(value => $thisbranch,
- selected => $selected,
- branchname => $branches->{$thisbranch}->{branchname},
- );
- push @branchloop, \%row;
- }
-
-=head3 in TEMPLATE
-
-
-
=cut
-sub GetBranches {
- my ($onlymine) = @_;
-
- # returns a reference to a hash of references to ALL branches...
- my %branches;
- my $dbh = C4::Context->dbh;
- my $sth;
- my $query = "SELECT * FROM branches";
- my @bind_parameters;
- if ( $onlymine && C4::Context->userenv && C4::Context->userenv->{branch} ) {
- $query .= ' WHERE branchcode = ? ';
- push @bind_parameters, C4::Context->userenv->{branch};
- }
- $query .= " ORDER BY branchname";
- $sth = $dbh->prepare($query);
- $sth->execute(@bind_parameters);
-
- my $relations_sth =
- $dbh->prepare("SELECT branchcode,categorycode FROM branchrelations");
- $relations_sth->execute();
- my %relations;
- while ( my $rel = $relations_sth->fetchrow_hashref ) {
- push @{ $relations{ $rel->{branchcode} } }, $rel->{categorycode};
- }
-
- while ( my $branch = $sth->fetchrow_hashref ) {
- foreach my $cat ( @{ $relations{ $branch->{branchcode} } } ) {
- $branch->{category}{$cat} = 1;
- }
- $branches{ $branch->{'branchcode'} } = $branch;
- }
- return ( \%branches );
-}
-
sub onlymine {
return
C4::Context->preference('IndependentBranches')
diff --git a/C4/Circulation.pm b/C4/Circulation.pm
index 6a71464601..06dd764085 100644
--- a/C4/Circulation.pm
+++ b/C4/Circulation.pm
@@ -33,7 +33,6 @@ use C4::Accounts;
use C4::ItemCirculationAlertPreference;
use C4::Message;
use C4::Debug;
-use C4::Branch; # GetBranches
use C4::Log; # logaction
use C4::Koha qw(
GetAuthorisedValueByCode
@@ -310,7 +309,6 @@ sub transferbook {
my ( $tbr, $barcode, $ignoreRs ) = @_;
my $messages;
my $dotransfer = 1;
- my $branches = GetBranches();
my $itemnumber = GetItemnumberFromBarcode( $barcode );
my $issue = GetItemIssue($itemnumber);
my $biblio = GetBiblioFromItemNumber($itemnumber);
@@ -339,7 +337,10 @@ sub transferbook {
}
# if is permanent...
- if ( $hbr && $branches->{$hbr}->{'PE'} ) {
+ # FIXME Is this still used by someone?
+ # See other FIXME in AddReturn
+ my $library = Koha::Libraries->find($hbr);
+ if ( $library and $library->get_categories->search({'me.categorycode' => 'PE'})->count ) {
$messages->{'IsPermanent'} = $hbr;
$dotransfer = 0;
}
@@ -1899,8 +1900,10 @@ sub AddReturn {
# check if the book is in a permanent collection....
# FIXME -- This 'PE' attribute is largely undocumented. afaict, there's no user interface that reflects this functionality.
if ( $returnbranch ) {
- my $branches = GetBranches(); # a potentially expensive call for a non-feature.
- $branches->{$returnbranch}->{PE} and $messages->{'IsPermanent'} = $returnbranch;
+ my $library = Koha::Libraries->find($returnbranch);
+ if ( $library and $library->get_categories->search({'me.categorycode' => 'PE'})->count ) {
+ $messages->{'IsPermanent'} = $returnbranch;
+ }
}
# check if the return is allowed at this branch
diff --git a/C4/Context.pm b/C4/Context.pm
index 4f7aeac23e..87242d34c0 100644
--- a/C4/Context.pm
+++ b/C4/Context.pm
@@ -1030,6 +1030,12 @@ sub interface {
return $context->{interface} // 'opac';
}
+# always returns a string for OK comparison via "eq" or "ne"
+sub mybranch {
+ C4::Context->userenv or return '';
+ return C4::Context->userenv->{branch} || '';
+}
+
1;
__END__
diff --git a/C4/ILSDI/Services.pm b/C4/ILSDI/Services.pm
index 72d2ab8385..72bbbb77d5 100644
--- a/C4/ILSDI/Services.pm
+++ b/C4/ILSDI/Services.pm
@@ -23,7 +23,6 @@ use warnings;
use C4::Members;
use C4::Items;
use C4::Circulation;
-use C4::Branch;
use C4::Accounts;
use C4::Biblio;
use C4::Reserves qw(AddReserve GetReservesFromBiblionumber GetReservesFromBorrowernumber CanBookBeReserved CanItemBeReserved IsAvailableForItemLevelRequest);
@@ -630,8 +629,7 @@ sub HoldTitle {
# Pickup branch management
if ( $cgi->param('pickup_location') ) {
$branch = $cgi->param('pickup_location');
- my $branches = GetBranches;
- return { code => 'LocationNotFound' } unless $$branches{$branch};
+ return { code => 'LocationNotFound' } unless Koha::Libraries->find($branch);
} else { # if the request provide no branch, use the borrower's branch
$branch = $$borrower{branchcode};
}
@@ -708,8 +706,7 @@ sub HoldItem {
my $branch;
if ( $cgi->param('pickup_location') ) {
$branch = $cgi->param('pickup_location');
- my $branches = GetBranches();
- return { code => 'LocationNotFound' } unless $$branches{$branch};
+ return { code => 'LocationNotFound' } unless Koha::Libraries->find($branch);
} else { # if the request provide no branch, use the borrower's branch
$branch = $$borrower{branchcode};
}
diff --git a/C4/Items.pm b/C4/Items.pm
index 8e69eba650..728a2ec9b6 100644
--- a/C4/Items.pm
+++ b/C4/Items.pm
@@ -1337,6 +1337,7 @@ sub GetItemsInfo {
COALESCE( localization.translation, itemtypes.description ) AS translated_description,
itemtypes.notforloan as notforloan_per_itemtype,
holding.branchurl,
+ holding.branchcode,
holding.branchname,
holding.opac_info as holding_branch_opac_info,
home.opac_info as home_branch_opac_info
diff --git a/C4/Overdues.pm b/C4/Overdues.pm
index 71c8606cf0..d0df42653d 100644
--- a/C4/Overdues.pm
+++ b/C4/Overdues.pm
@@ -36,6 +36,7 @@ use C4::Debug;
use Koha::DateUtils;
use Koha::Account::Line;
use Koha::Account::Lines;
+use Koha::Libraries;
use vars qw(@ISA @EXPORT);
@@ -788,8 +789,7 @@ sub GetBranchcodesWithOverdueRules {
|);
if ( $branchcodes->[0] eq '' ) {
# If a default rule exists, all branches should be returned
- my $availbranches = C4::Branch::GetBranches();
- return keys %$availbranches;
+ return map { $_->branchcode } Koha::Libraries->search({}, { order_by => 'branchname' });
}
return @$branchcodes;
}
diff --git a/C4/Search.pm b/C4/Search.pm
index ab84087b0b..4446349386 100644
--- a/C4/Search.pm
+++ b/C4/Search.pm
@@ -28,7 +28,6 @@ use C4::Search::PazPar2;
use XML::Simple;
use C4::Members qw(GetHideLostItemsPreference);
use C4::XSLT;
-use C4::Branch;
use C4::Reserves; # GetReserveStatus
use C4::Debug;
use C4::Charset;
@@ -857,6 +856,8 @@ sub pazGetRecords {
$query_type, $scan
) = @_;
+ $branches ||= { map { $_->branchcode => $_->branchname } Koha::Libraries->search };
+
my $paz = C4::Search::PazPar2->new(C4::Context->config('pazpar2url'));
$paz->init();
$paz->search($simple_query);
@@ -1843,14 +1844,8 @@ sub searchResults {
}
#Build branchnames hash
- #find branchname
- #get branch information.....
- my %branches;
- my $bsth =$dbh->prepare("SELECT branchcode,branchname FROM branches"); # FIXME : use C4::Branch::GetBranches
- $bsth->execute();
- while ( my $bdata = $bsth->fetchrow_hashref ) {
- $branches{ $bdata->{'branchcode'} } = $bdata->{'branchname'};
- }
+ my %branches = map { $_->branchcode => $_->branchname } Koha::Libraries->search({}, { order_by => 'branchname' });
+
# FIXME - We build an authorised values hash here, using the default framework
# though it is possible to have different authvals for different fws.
diff --git a/C4/ShelfBrowser.pm b/C4/ShelfBrowser.pm
index 923b7fec58..8ae813a30f 100644
--- a/C4/ShelfBrowser.pm
+++ b/C4/ShelfBrowser.pm
@@ -23,9 +23,9 @@ use strict;
use warnings;
use C4::Biblio;
-use C4::Branch;
use C4::Context;
use C4::Koha;
+use Koha::Libraries;
use vars qw(@ISA @EXPORT @EXPORT_OK);
@@ -117,7 +117,6 @@ sub GetNearbyItems {
if $gap <= $num_each_side;
my $dbh = C4::Context->dbh;
- my $branches = GetBranches();
my $sth_get_item_details = $dbh->prepare("SELECT cn_sort,homebranch,location,ccode from items where itemnumber=?");
$sth_get_item_details->execute($itemnumber);
@@ -129,7 +128,7 @@ sub GetNearbyItems {
if (C4::Context->preference('ShelfBrowserUsesHomeBranch') &&
defined($item_details_result->{'homebranch'})) {
$start_homebranch->{code} = $item_details_result->{'homebranch'};
- $start_homebranch->{description} = $branches->{$item_details_result->{'homebranch'}}{branchname};
+ $start_homebranch->{description} = Koha::Libraries->find($item_details_result->{'homebranch'})->branchname;
}
if (C4::Context->preference('ShelfBrowserUsesLocation') &&
defined($item_details_result->{'location'})) {
diff --git a/C4/XSLT.pm b/C4/XSLT.pm
index 1d6edad751..364d6a130a 100644
--- a/C4/XSLT.pm
+++ b/C4/XSLT.pm
@@ -276,7 +276,8 @@ sub buildKohaItemsNamespace {
my $shelflocations = GetKohaAuthorisedValues('items.location',GetFrameworkCode($biblionumber), 'opac');
my $ccodes = GetKohaAuthorisedValues('items.ccode',GetFrameworkCode($biblionumber), 'opac');
- my $branches = GetBranches();
+ my %branches = map { $_->branchcode => $_->branchname } Koha::Libraries->search({}, { order_by => 'branchname' });
+
my $itemtypes = GetItemTypes();
my $location = "";
my $ccode = "";
@@ -317,8 +318,8 @@ sub buildKohaItemsNamespace {
} else {
$status = "available";
}
- my $homebranch = $item->{homebranch}? xml_escape($branches->{$item->{homebranch}}->{'branchname'}):'';
- my $holdingbranch = $item->{holdingbranch}? xml_escape($branches->{$item->{holdingbranch}}->{'branchname'}):'';
+ my $homebranch = $item->{homebranch}? xml_escape($branches{$item->{homebranch}}):'';
+ my $holdingbranch = $item->{holdingbranch}? xml_escape($branches{$item->{holdingbranch}}):'';
$location = $item->{location}? xml_escape($shelflocations->{$item->{location}}||$item->{location}):'';
$ccode = $item->{ccode}? xml_escape($ccodes->{$item->{ccode}}||$item->{ccode}):'';
my $itemcallnumber = xml_escape($item->{itemcallnumber});
diff --git a/Koha/Libraries.pm b/Koha/Libraries.pm
index 9f4831c406..fefc3ab51f 100644
--- a/Koha/Libraries.pm
+++ b/Koha/Libraries.pm
@@ -21,8 +21,9 @@ use Modern::Perl;
use Carp;
-use Koha::Database;
+use C4::Context;
+use Koha::Database;
use Koha::Library;
use base qw(Koha::Objects);
@@ -37,6 +38,24 @@ Koha::Libraries - Koha Library Object set class
=cut
+=head3 search_filtered
+
+=cut
+
+sub search_filtered {
+ my ( $self, $params, $attributes ) = @_;
+
+ if ( C4::Context->preference('IndependentBranches')
+ and C4::Context->userenv
+ and not C4::Context->IsSuperLibrarian()
+ and C4::Context->userenv->{branch}
+ ) {
+ $params->{branchcode} = C4::Context->userenv->{branch};
+ }
+
+ return $self->SUPER::search( $params, $attributes );
+}
+
=head3 type
=cut
diff --git a/Koha/Template/Plugin/Branches.pm b/Koha/Template/Plugin/Branches.pm
index 8b959a2e33..e7cbd7e42e 100644
--- a/Koha/Template/Plugin/Branches.pm
+++ b/Koha/Template/Plugin/Branches.pm
@@ -25,6 +25,7 @@ use base qw( Template::Plugin );
use C4::Koha;
use C4::Context;
+use Koha::Libraries;
sub GetName {
my ( $self, $branchcode ) = @_;
@@ -61,21 +62,11 @@ sub OnlyMine {
sub all {
my ( $self, $params ) = @_;
my $selected = $params->{selected};
- my $dbh = C4::Context->dbh;
- my @params;
- my $query = q|
- SELECT branchcode, branchname
- FROM branches
- |;
- if ( C4::Context->preference('IndependentBranches')
- and C4::Context->userenv
- && !C4::Context->IsSuperLibrarian()
- and C4::Context->userenv->{branch} )
- {
- $query .= q| WHERE branchcode = ? |;
- push @params, C4::Context->userenv->{branch};
- }
- my $libraries = $dbh->selectall_arrayref( $query, { Slice => {} }, @params );
+ my $unfiltered = $params->{unfiltered} || 0;
+
+ my $libraries = $unfiltered
+ ? Koha::Libraries->search( {}, { order_by => ['branchname'] } )->unblessed
+ : Koha::Libraries->search_filtered( {}, { order_by => ['branchname'] } )->unblessed;
for my $l ( @$libraries ) {
if ( $selected and $l->{branchcode} eq $selected
diff --git a/acqui/add_user_search.pl b/acqui/add_user_search.pl
index ab1f1ca07d..d2481c6237 100755
--- a/acqui/add_user_search.pl
+++ b/acqui/add_user_search.pl
@@ -21,7 +21,6 @@ use Modern::Perl;
use CGI qw ( -utf8 );
use C4::Auth;
-use C4::Branch qw( GetBranches );
use C4::Output;
use C4::Members;
@@ -52,9 +51,6 @@ my $search_patrons_with_acq_perm_only =
( $referer =~ m|acqui/basket.pl| )
? 1 : 0;
-my $onlymine = C4::Branch::onlymine;
-my $branches = C4::Branch::GetBranches( $onlymine );
-
my $patron_categories = Koha::Patron::Categories->search_limited;
$template->param(
patrons_with_acq_perm_only => $search_patrons_with_acq_perm_only,
@@ -64,7 +60,6 @@ $template->param(
selection_type => 'add',
alphabet => ( C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ),
categories => $patron_categories,
- branches => [ map { { branchcode => $_->{branchcode}, branchname => $_->{branchname} } } values %$branches ],
aaSorting => 1,
);
output_html_with_http_headers( $input, $cookie, $template->output );
diff --git a/acqui/addorderiso2709.pl b/acqui/addorderiso2709.pl
index 552754c947..d2c2e251cd 100755
--- a/acqui/addorderiso2709.pl
+++ b/acqui/addorderiso2709.pl
@@ -39,7 +39,6 @@ use C4::Koha;
use C4::Budgets;
use C4::Acquisition;
use C4::Suggestions; # GetSuggestion
-use C4::Branch; # GetBranches
use C4::Members;
use Koha::Number::Price;
diff --git a/acqui/basket.pl b/acqui/basket.pl
index afc0ec0e51..f3bf36aaaa 100755
--- a/acqui/basket.pl
+++ b/acqui/basket.pl
@@ -28,13 +28,13 @@ use C4::Output;
use CGI qw ( -utf8 );
use C4::Acquisition;
use C4::Budgets;
-use C4::Branch;
use C4::Contract;
use C4::Debug;
use C4::Biblio;
use C4::Members qw/GetMember/; #needed for permissions checking for changing basketgroup of a basket
use C4::Items;
use C4::Suggestions;
+use Koha::Libraries;
use Date::Calc qw/Add_Delta_Days/;
use Koha::Database;
use Koha::EDI qw( create_edi_order get_edifact_ean );
@@ -236,6 +236,7 @@ elsif ( $op eq 'ediorder' ) {
exit 1;
}
}
+
if (!defined $basket->{branch} or $basket->{branch} eq $userenv->{branch}) {
push @branches_loop, {
branchcode => $userenv->{branch},
@@ -245,20 +246,17 @@ elsif ( $op eq 'ediorder' ) {
}
} else {
# get branches
- my $branches = C4::Branch::GetBranches;
- my @branchcodes = sort {
- $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname}
- } keys %$branches;
- foreach my $branch (@branchcodes) {
+ my $branches = Koha::Libraries->search( {}, { order_by => ['branchname'] } )->unblessed;
+ foreach my $branch (@$branches) {
my $selected = 0;
if (defined $basket->{branch}) {
- $selected = 1 if $branch eq $basket->{branch};
+ $selected = 1 if $branch->{branchcode} eq $basket->{branch};
} else {
- $selected = 1 if $branch eq C4::Context->userenv->{branch};
+ $selected = 1 if $branch->{branchcode} eq C4::Context->userenv->{branch};
}
push @branches_loop, {
- branchcode => $branch,
- branchname => $branches->{$branch}->{branchname},
+ branchcode => $branch->{branchcode},
+ branchname => $branch->{branchname},
selected => $selected
};
}
diff --git a/acqui/basketheader.pl b/acqui/basketheader.pl
index cdef0dfaa9..c0db854e3d 100755
--- a/acqui/basketheader.pl
+++ b/acqui/basketheader.pl
@@ -50,7 +50,6 @@ use warnings;
use CGI qw ( -utf8 );
use C4::Context;
use C4::Auth;
-use C4::Branch;
use C4::Output;
use C4::Acquisition qw/GetBasket NewBasket ModBasketHeader/;
use C4::Contract qw/GetContracts/;
@@ -72,7 +71,6 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
#parameters:
my $booksellerid = $input->param('booksellerid');
my $basketno = $input->param('basketno');
-my $branches = GetBranches;
my $basket;
my $op = $input ->param('op');
my $is_an_edit= $input ->param('is_an_edit');
diff --git a/acqui/invoices.pl b/acqui/invoices.pl
index 3048fb5002..7f0ed5d29c 100755
--- a/acqui/invoices.pl
+++ b/acqui/invoices.pl
@@ -34,7 +34,6 @@ use C4::Auth;
use C4::Output;
use C4::Acquisition qw/GetInvoices/;
-use C4::Branch qw/GetBranches/;
use C4::Budgets;
use Koha::DateUtils;
@@ -107,24 +106,6 @@ foreach (@suppliers) {
};
}
-# Build branches list
-my $branches = GetBranches();
-my $branches_loop = [];
-my $branchname;
-foreach ( sort keys %$branches ) {
- my $selected = 0;
- if ( $branch && $branch eq $_ ) {
- $selected = 1;
- $branchname = $branches->{$_}->{'branchname'};
- }
- push @{$branches_loop},
- {
- branchcode => $_,
- branchname => $branches->{$_}->{branchname},
- selected => $selected,
- };
-}
-
my $budgets = GetBudgets();
my @budgets_loop;
foreach my $budget (@$budgets) {
@@ -149,9 +130,7 @@ $template->param(
publisher => $publisher,
publicationyear => $publicationyear,
branch => $branch,
- branchname => $branchname,
suppliers_loop => $suppliers_loop,
- branches_loop => $branches_loop,
);
output_html_with_http_headers $input, $cookie, $template->output;
diff --git a/acqui/lateorders.pl b/acqui/lateorders.pl
index 872d0af18b..2b2ed17b0c 100755
--- a/acqui/lateorders.pl
+++ b/acqui/lateorders.pl
@@ -52,7 +52,6 @@ use C4::Output;
use C4::Context;
use C4::Acquisition;
use C4::Letters;
-use C4::Branch; # GetBranches
use Koha::DateUtils;
my $input = new CGI;
diff --git a/acqui/neworderempty.pl b/acqui/neworderempty.pl
index 72cab5aa6b..10f6074a10 100755
--- a/acqui/neworderempty.pl
+++ b/acqui/neworderempty.pl
@@ -81,7 +81,6 @@ use C4::Biblio; # GetBiblioData GetMarcPrice
use C4::Items; #PrepareItemRecord
use C4::Output;
use C4::Koha;
-use C4::Branch; # GetBranches
use C4::Members;
use C4::Search qw/FindDuplicate/;
diff --git a/acqui/newordersubscription.pl b/acqui/newordersubscription.pl
index 7353dc92d0..81bc18d252 100755
--- a/acqui/newordersubscription.pl
+++ b/acqui/newordersubscription.pl
@@ -21,7 +21,6 @@ use Modern::Perl;
use CGI qw ( -utf8 );
use C4::Acquisition;
use C4::Auth;
-use C4::Branch;
use C4::Context;
use C4::Output;
use C4::Serials;
@@ -76,18 +75,6 @@ foreach my $sub (@subscriptions) {
}
}
-my $branches = GetBranches();
-my @branches_loop;
-foreach (sort keys %$branches){
- my $selected = 0;
- $selected = 1 if defined $branch && $branch eq $_;
- push @branches_loop, {
- branchcode => $_,
- branchname => $branches->{$_}->{branchname},
- selected => $selected,
- };
-}
-
$template->param(
subs_loop => \@subscriptions,
title_filter => $title,
@@ -96,7 +83,6 @@ $template->param(
publisher_filter => $publisher,
supplier_filter => $supplier,
branch_filter => $branch,
- branches_loop => \@branches_loop,
done_searched => $searched,
routing => $routing,
booksellerid => $booksellerid,
diff --git a/acqui/orderreceive.pl b/acqui/orderreceive.pl
index b07ee0f70c..d815022050 100755
--- a/acqui/orderreceive.pl
+++ b/acqui/orderreceive.pl
@@ -69,7 +69,6 @@ use C4::Auth;
use C4::Output;
use C4::Budgets qw/ GetBudget GetBudgetHierarchy CanUserUseBudget GetBudgetPeriods /;
use C4::Members;
-use C4::Branch; # GetBranches
use C4::Items;
use C4::Biblio;
use C4::Suggestions;
diff --git a/admin/add_user_search.pl b/admin/add_user_search.pl
index 4f0391af9d..ba3989aa51 100755
--- a/admin/add_user_search.pl
+++ b/admin/add_user_search.pl
@@ -21,7 +21,6 @@ use Modern::Perl;
use CGI qw ( -utf8 );
use C4::Auth;
-use C4::Branch qw( GetBranches );
use C4::Output;
use C4::Members;
@@ -53,9 +52,6 @@ my $search_patrons_with_acq_perm_only =
( $referer =~ m|admin/aqbudgets.pl| )
? 1 : 0;
-my $onlymine = C4::Branch::onlymine;
-my $branches = C4::Branch::GetBranches( $onlymine );
-
my $patron_categories = Koha::Patron::Categories->search_limited;
$template->param(
patrons_with_acq_perm_only => $search_patrons_with_acq_perm_only,
@@ -65,7 +61,6 @@ $template->param(
selection_type => $selection_type,
alphabet => ( C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ),
categories => $patron_categories,
- branches => [ map { { branchcode => $_->{branchcode}, branchname => $_->{branchname} } } values %$branches ],
aaSorting => 1,
);
output_html_with_http_headers( $input, $cookie, $template->output );
diff --git a/admin/aqbudgets.pl b/admin/aqbudgets.pl
index c9baad7b53..e7dd2bbaf3 100755
--- a/admin/aqbudgets.pl
+++ b/admin/aqbudgets.pl
@@ -26,7 +26,6 @@ use List::Util qw/min/;
use Koha::Database;
use C4::Auth qw/get_user_subpermissions/;
-use C4::Branch; # GetBranches
use C4::Auth;
use C4::Acquisition;
use C4::Budgets;
@@ -141,18 +140,6 @@ if ($op eq 'add_form') {
}
$budget_parent = GetBudget($budget_parent_id);
- # build branches select
- my $branches = GetBranches;
- my @branchloop_select;
- foreach my $thisbranch ( sort keys %$branches ) {
- my %row = (
- value => $thisbranch,
- branchname => $branches->{$thisbranch}->{'branchname'},
- );
- $row{selected} = 1 if $budget and $thisbranch eq $budget->{'budget_branchcode'};
- push @branchloop_select, \%row;
- }
-
# populates the YUI planning button
my $categories = GetAuthorisedValueCategories();
my @auth_cats_loop1 = ();
@@ -200,7 +187,6 @@ if ($op eq 'add_form') {
budget_has_children => BudgetHasChildren( $budget->{budget_id} ),
budget_parent_id => $budget_parent->{'budget_id'},
budget_parent_name => $budget_parent->{'budget_name'},
- branchloop_select => \@branchloop_select,
%$period,
%$budget,
);
@@ -258,7 +244,6 @@ if ($op eq 'add_form') {
}
if ( $op eq 'list' ) {
- my $branches = GetBranches();
$template->param(
budget_id => $budget_id,
%$period,
diff --git a/admin/authorised_values.pl b/admin/authorised_values.pl
index b78290180f..49fb661825 100755
--- a/admin/authorised_values.pl
+++ b/admin/authorised_values.pl
@@ -21,12 +21,12 @@ use Modern::Perl;
use CGI qw ( -utf8 );
use C4::Auth;
-use C4::Branch;
use C4::Context;
use C4::Koha;
use C4::Output;
use Koha::AuthorisedValues;
+use Koha::Libraries;
my $input = new CGI;
my $id = $input->param('id');
@@ -56,15 +56,14 @@ if ($op eq 'add_form') {
$category = $input->param('category');
}
- my $branches = GetBranches;
+ my $branches = Koha::Libraries->search( {}, { order_by => ['branchname'] } )->unblessed;
my @branches_loop;
-
- foreach my $branchcode ( sort { uc($branches->{$a}->{branchname}) cmp uc($branches->{$b}->{branchname}) } keys %$branches ) {
- my $selected = ( grep {$_ eq $branchcode} @$selected_branches ) ? 1 : 0;
+ foreach my $branch ( @$branches ) {
+ my $selected = ( grep {$_ eq $branch->{branchcode}} @$selected_branches ) ? 1 : 0;
push @branches_loop, {
- branchcode => $branchcode,
- branchname => $branches->{$branchcode}->{branchname},
- selected => $selected,
+ branchcode => $branch->{branchcode},
+ branchname => $branch->{branchname},
+ selected => $selected,
};
}
diff --git a/admin/branch_transfer_limits.pl b/admin/branch_transfer_limits.pl
index b745136dcb..84d7210961 100755
--- a/admin/branch_transfer_limits.pl
+++ b/admin/branch_transfer_limits.pl
@@ -26,7 +26,6 @@ use C4::Auth;
use C4::Context;
use C4::Output;
use C4::Koha;
-use C4::Branch;
use C4::Circulation qw{ IsBranchTransferAllowed DeleteBranchTransferLimits CreateBranchTransferLimit };
my $input = new CGI;
@@ -50,18 +49,6 @@ else
$branchcode = $input->param('branchcode');
}
-# Getting the branches for user selection
-my $branches = GetBranches();
-my @branch_loop;
-for my $thisbranch (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %$branches) {
- my %row =(value => $thisbranch,
- branchname => $branches->{$thisbranch}->{'branchname'},
- selected => $thisbranch eq $branchcode ? 1 : 0,
- );
- push @branch_loop, \%row;
-}
-
-
# Set the template language for the correct limit type using $limitType
my $limitType = C4::Context->preference("BranchTransferLimitsType") || "ccode";
@@ -132,7 +119,6 @@ foreach my $code ( @codes ) {
$template->param(
branchcount => $branchcount,
codes_loop => \@codes_loop,
- branch_loop => \@branch_loop,
branchcode_loop => \@branchcode_loop,
branchcode => $branchcode,
limitType => $limitType,
diff --git a/admin/categories.pl b/admin/categories.pl
index f09c2bffd0..358ef7d8c8 100755
--- a/admin/categories.pl
+++ b/admin/categories.pl
@@ -23,13 +23,13 @@ use Modern::Perl;
use CGI qw ( -utf8 );
use C4::Context;
use C4::Auth;
-use C4::Branch;
use C4::Output;
use C4::Form::MessagingPreferences;
use Koha::Patrons;
use Koha::Database;
use Koha::DateUtils;
use Koha::Patron::Categories;
+use Koha::Libraries;
my $input = new CGI;
my $searchfield = $input->param('description') // q||;
@@ -55,13 +55,13 @@ if ( $op eq 'add_form' ) {
$selected_branches = $category->branch_limitations;
}
- my $branches = GetBranches;
+ my $branches = Koha::Libraries->search( {}, { order_by => ['branchname'] } )->unblessed;
my @branches_loop;
- foreach my $branchcode ( sort { uc( $branches->{$a}->{branchname} ) cmp uc( $branches->{$b}->{branchname} ) } keys %$branches ) {
- my $selected = ( grep { $_ eq $branchcode } @$selected_branches ) ? 1 : 0;
+ foreach my $branch ( @$branches ) {
+ my $selected = ( grep { $_ eq $branch->{branchcode} } @$selected_branches ) ? 1 : 0;
push @branches_loop,
- { branchcode => $branchcode,
- branchname => $branches->{$branchcode}->{branchname},
+ { branchcode => $branch->{branchcode},
+ branchname => $branch->{branchname},
selected => $selected,
};
}
diff --git a/admin/item_circulation_alerts.pl b/admin/item_circulation_alerts.pl
index 3e6e6dd3a7..5e9c463e3f 100755
--- a/admin/item_circulation_alerts.pl
+++ b/admin/item_circulation_alerts.pl
@@ -26,7 +26,6 @@ use JSON;
use C4::Auth;
use C4::Context;
-use C4::Branch;
use C4::ItemCirculationAlertPreference;
use C4::Output;
@@ -51,28 +50,13 @@ sub show {
}
);
- my $br = GetBranches;
my $branch = $input->param('branch') || '*';
- my @branches = (
- {
- branchcode => '*',
- branchname => 'Default',
- },
- sort { $a->{branchname} cmp $b->{branchname} } values %$br,
- );
- for (@branches) {
- $_->{selected} = "selected" if ($branch eq $_->{branchcode});
- }
- my $branch_name = exists($br->{$branch}) && $br->{$branch}->{branchname};
-
my @categories = Koha::Patron::Categories->search_limited;
my @item_types = Koha::ItemTypes->search;
my $grid_checkout = $preferences->grid({ branchcode => $branch, notification => 'CHECKOUT' });
my $grid_checkin = $preferences->grid({ branchcode => $branch, notification => 'CHECKIN' });
$template->param(branch => $branch);
- $template->param(branch_name => $branch_name || 'Default');
- $template->param(branches => \@branches);
$template->param(categories => \@categories);
$template->param(item_types => \@item_types);
$template->param(grid_checkout => $grid_checkout);
diff --git a/admin/patron-attr-types.pl b/admin/patron-attr-types.pl
index 1fcbc7cdc3..9a5fce23cc 100755
--- a/admin/patron-attr-types.pl
+++ b/admin/patron-attr-types.pl
@@ -25,12 +25,12 @@ use CGI qw ( -utf8 );
use List::MoreUtils qw/uniq/;
use C4::Auth;
-use C4::Branch;
use C4::Context;
use C4::Output;
use C4::Koha;
use C4::Members::AttributeTypes;
+use Koha::Libraries;
use Koha::Patron::Categories;
my $script_name = "/cgi-bin/koha/admin/patron-attr-types.pl";
@@ -84,7 +84,7 @@ exit 0;
sub add_attribute_type_form {
my $template = shift;
- my $branches = GetBranches;
+ my $branches = Koha::Libraries->search( {}, { order_by => ['branchname'] } )->unblessed;
my @branches_loop;
foreach my $branch (sort keys %$branches) {
push @branches_loop, {
@@ -252,14 +252,14 @@ sub edit_attribute_type_form {
$template->param(classes_val_loop => GetAuthorisedValues( 'PA_CLASS' ));
- my $branches = GetBranches;
+ my $branches = Koha::Libraries->search( {}, { order_by => ['branchname'] } )->unblessed;
my @branches_loop;
my $selected_branches = $attr_type->branches;
- foreach my $branch (sort keys %$branches) {
- my $selected = ( grep {$$_{branchcode} eq $branch} @$selected_branches ) ? 1 : 0;
+ foreach my $branch (@$branches) {
+ my $selected = ( grep {$_->{branchcode} eq $branch->{branchcode}} @$selected_branches ) ? 1 : 0;
push @branches_loop, {
- branchcode => $branches->{$branch}{branchcode},
- branchname => $branches->{$branch}{branchname},
+ branchcode => $branch->{branchcode},
+ branchname => $branch->{branchname},
selected => $selected,
};
}
diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl
index 0f7da21362..8217b8da7a 100755
--- a/admin/smart-rules.pl
+++ b/admin/smart-rules.pl
@@ -25,7 +25,7 @@ use C4::Output;
use C4::Auth;
use C4::Koha;
use C4::Debug;
-use C4::Branch; # GetBranches
+use C4::Branch;
use Koha::DateUtils;
use Koha::Database;
use Koha::IssuingRule;
diff --git a/admin/transport-cost-matrix.pl b/admin/transport-cost-matrix.pl
index 55fd912353..0aab030729 100755
--- a/admin/transport-cost-matrix.pl
+++ b/admin/transport-cost-matrix.pl
@@ -25,9 +25,10 @@ use C4::Output;
use C4::Auth;
use C4::Koha;
use C4::Debug;
-use C4::Branch; # GetBranches
use C4::HoldsQueue qw(TransportCostMatrix UpdateTransportCostMatrix);
+use Koha::Libraries;
+
use Data::Dumper;
my $input = new CGI;
@@ -50,11 +51,7 @@ unless ($update) {
$have_matrix = keys %$cost_matrix if $cost_matrix;
}
-my $branches = GetBranches();
-my @branchloop = map { code => $_,
- name => $branches->{$_}->{'branchname'} },
- sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} }
- keys %$branches;
+my @branchloop = map { code => $_->branchcode, name => $_->branchname }, Koha::Libraries->search({}, { order_by => 'branchname' });
my (@branchfromloop, @errors);
foreach my $branchfrom ( @branchloop ) {
my $fromcode = $branchfrom->{code};
diff --git a/catalogue/detail.pl b/catalogue/detail.pl
index 3fc8c29426..72bb36017d 100755
--- a/catalogue/detail.pl
+++ b/catalogue/detail.pl
@@ -28,7 +28,6 @@ use C4::Output;
use C4::Biblio;
use C4::Items;
use C4::Circulation;
-use C4::Branch;
use C4::Reserves;
use C4::Members; # to use GetMember
use C4::Serials;
@@ -127,7 +126,6 @@ my $marchostsarray = GetMarcHosts($record,$marcflavour);
my $subtitle = GetRecordValue('subtitle', $record, $fw);
# Get Branches, Itemtypes and Locations
-my $branches = GetBranches();
my $itemtypes = GetItemTypes();
my $dbh = C4::Context->dbh;
@@ -258,7 +256,7 @@ foreach my $item (@items) {
$item->{ReservedForBorrowernumber} = $reservedfor;
$item->{ReservedForSurname} = $ItemBorrowerReserveInfo->{'surname'};
$item->{ReservedForFirstname} = $ItemBorrowerReserveInfo->{'firstname'};
- $item->{ExpectedAtLibrary} = $branches->{$expectedAt}{branchname};
+ $item->{ExpectedAtLibrary} = $expectedAt;
$item->{Reservedcardnumber} = $ItemBorrowerReserveInfo->{'cardnumber'};
# Check waiting status
$item->{waitingdate} = $wait;
@@ -269,8 +267,8 @@ foreach my $item (@items) {
my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($item->{itemnumber});
if ( defined( $transfertwhen ) && ( $transfertwhen ne '' ) ) {
$item->{transfertwhen} = $transfertwhen;
- $item->{transfertfrom} = $branches->{$transfertfrom}{branchname};
- $item->{transfertto} = $branches->{$transfertto}{branchname};
+ $item->{transfertfrom} = $transfertfrom;
+ $item->{transfertto} = $transfertto;
$item->{nocancel} = 1;
}
diff --git a/catalogue/itemsearch.pl b/catalogue/itemsearch.pl
index 2e6608b559..27c899a5e4 100755
--- a/catalogue/itemsearch.pl
+++ b/catalogue/itemsearch.pl
@@ -25,11 +25,11 @@ use C4::Auth;
use C4::Output;
use C4::Items;
use C4::Biblio;
-use C4::Branch;
use C4::Koha;
use Koha::Item::Search::Field qw(GetItemSearchFields);
use Koha::ItemTypes;
+use Koha::Libraries;
my $cgi = new CGI;
my %params = $cgi->Vars;
@@ -247,14 +247,7 @@ if (scalar keys %params > 0) {
if ($format eq 'html') {
# Retrieve data required for the form.
- my $branches = GetBranches();
- my @branches;
- foreach my $branchcode ( sort { uc($branches->{$a}->{branchname}) cmp uc($branches->{$b}->{branchname}) } keys %$branches) {
- push @branches, {
- value => $branchcode,
- label => $branches->{$branchcode}->{branchname},
- };
- }
+ my @branches = map { value => $_->branchcode => label => $_->branchname }, Koha::Libraries->search( {}, { order_by => 'branchname' } );
my @locations;
foreach my $location (@$location_values) {
push @locations, {
diff --git a/catalogue/search.pl b/catalogue/search.pl
index 5428edeb08..5855bf1805 100755
--- a/catalogue/search.pl
+++ b/catalogue/search.pl
@@ -149,7 +149,6 @@ use C4::Koha;
use C4::Members qw(GetMember);
use URI::Escape;
use POSIX qw(ceil floor);
-use C4::Branch; # GetBranches
use C4::Search::History;
use Koha::LibraryCategories;
@@ -216,7 +215,10 @@ if($cgi->cookie("intranet_bib_list")){
# load the branches
my $categories = Koha::LibraryCategories->search( { categorytype => 'searchdomain' }, { order_by => [ 'categorytype', 'categorycode' ] } );
-$template->param(searchdomainloop => $categories);
+$template->param(
+ selected_branchcode => ( C4::Context->IsSuperLibrarian ? C4::Context->userenv : '' ),
+ searchdomainloop => $categories
+);
# load the Type stuff
my $itemtypes = GetItemTypes;
diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl
index 3db9d8cc97..e9ff81ea1d 100755
--- a/cataloguing/addbiblio.pl
+++ b/cataloguing/addbiblio.pl
@@ -31,13 +31,14 @@ use C4::Context;
use MARC::Record;
use C4::Log;
use C4::Koha;
-use C4::Branch;
use C4::ClassSource;
use C4::ImportBatch;
use C4::Charset;
use Koha::BiblioFrameworks;
use Koha::DateUtils;
+use Koha::Libraries;
+
use Date::Calc qw(Today);
use MARC::File::USMARC;
use MARC::File::XML;
@@ -173,18 +174,11 @@ sub build_authorized_values_list {
#---- branch
if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
- #Use GetBranches($onlymine)
- my $onlymine =
- C4::Context->preference('IndependentBranches')
- && C4::Context->userenv
- && !C4::Context->IsSuperLibrarian()
- && C4::Context->userenv->{branch};
- my $branches = GetBranches($onlymine);
- foreach my $thisbranch ( sort keys %$branches ) {
- push @authorised_values, $thisbranch;
- $authorised_lib{$thisbranch} = $branches->{$thisbranch}->{'branchname'};
+ my $libraries = Koha::Libraries->search_filtered({}, {order_by => ['branchname']});
+ while ( my $l = $libraries->next ) {
+ push @authorised_values, $l->branchcode;;
+ $authorised_lib{$l->branchcode} = $l->branchname;
}
-
}
elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
push @authorised_values, ""
diff --git a/cataloguing/value_builder/unimarc_field_4XX.pl b/cataloguing/value_builder/unimarc_field_4XX.pl
index a5f21032c6..75c9dec0bc 100755
--- a/cataloguing/value_builder/unimarc_field_4XX.pl
+++ b/cataloguing/value_builder/unimarc_field_4XX.pl
@@ -31,7 +31,6 @@ use C4::Output;
use C4::Biblio;
use C4::Koha;
use MARC::Record;
-use C4::Branch; # GetBranches
use Koha::ItemTypes;
diff --git a/circ/bookcount.pl b/circ/bookcount.pl
index d4d3e54ed0..2976a05b66 100755
--- a/circ/bookcount.pl
+++ b/circ/bookcount.pl
@@ -29,7 +29,6 @@ use C4::Circulation;
use C4::Output;
use C4::Koha;
use C4::Auth;
-use C4::Branch; # GetBranches
use C4::Biblio; # GetBiblioItemData
use Koha::DateUtils;
use Koha::Libraries;
@@ -38,14 +37,10 @@ my $input = new CGI;
my $itm = $input->param('itm');
my $bi = $input->param('bi');
my $biblionumber = $input->param('biblionumber');
-my $branches = GetBranches;
my $idata = itemdatanum($itm);
my $data = GetBiblioItemData($bi);
-my $homebranch = $branches->{ $idata->{'homebranch'} }->{'branchname'};
-my $holdingbranch = $branches->{ $idata->{'holdingbranch'} }->{'branchname'};
-
my $lastmove = lastmove($itm);
my $lastdate;
@@ -83,8 +78,8 @@ $template->param(
author => $data->{'author'},
barcode => $idata->{'barcode'},
biblioitemnumber => $bi,
- homebranch => $homebranch,
- holdingbranch => $holdingbranch,
+ homebranch => $idata->{homebranch},
+ holdingbranch => $idata->{holdingbranch},
lastdate => $lastdate ? $lastdate : 0,
count => $count,
libraries => $libraries,
diff --git a/circ/branchtransfers.pl b/circ/branchtransfers.pl
index 8b7bddd69f..eb0a4f7e6a 100755
--- a/circ/branchtransfers.pl
+++ b/circ/branchtransfers.pl
@@ -29,7 +29,6 @@ use C4::Reserves;
use C4::Biblio;
use C4::Items;
use C4::Auth qw/:DEFAULT get_session/;
-use C4::Branch; # GetBranches
use C4::Koha;
use C4::Members;
@@ -61,8 +60,6 @@ my ($template, $user, $cookie) = get_template_and_user(
}
);
-my $branches = GetBranches;
-
my $messages;
my $found;
my $reserved;
@@ -131,8 +128,7 @@ if ($barcode) {
$item{'ccode'} = $iteminformation->{'ccode'};
$item{'itemcallnumber'} = $iteminformation->{'itemcallnumber'};
$item{'location'} = GetKohaAuthorisedValueLib("LOC",$iteminformation->{'location'});
- $item{'frbrname'} = $branches->{$frbranchcd}->{'branchname'};
- $item{'tobrname'} = $branches->{$tobranchcd}->{'branchname'};
+ $item{'tobrname'} = $tobranchcd;
# }
$item{counter} = 0;
$item{barcode} = $barcode;
@@ -164,8 +160,7 @@ foreach ( $query->param ) {
$item{'ccode'} = $iteminformation->{'ccode'};
$item{'itemcallnumber'} = $iteminformation->{'itemcallnumber'};
$item{'location'} = GetKohaAuthorisedValueLib("LOC",$iteminformation->{'location'});
- $item{'frbrname'} = $branches->{$frbcd}->{'branchname'};
- $item{'tobrname'} = $branches->{$tobcd}->{'branchname'};
+ $item{'tobrname'} = $tobcd;
push( @trsfitemloop, \%item );
}
@@ -196,16 +191,16 @@ foreach my $code ( keys %$messages ) {
$err{errbadcode} = 1;
}
elsif ( $code eq "NotAllowed" ) {
- warn "NotAllowed: $messages->{'NotAllowed'} to " . $branches->{ $messages->{'NotAllowed'} }->{'branchname'};
+ warn "NotAllowed: $messages->{'NotAllowed'} to branchcode " . $messages->{'NotAllowed'};
# Do we really want a error log message here? --atz
$err{errnotallowed} = 1;
my ( $tbr, $typecode ) = split( /::/, $messages->{'NotAllowed'} );
- $err{tbr} = $branches->{ $tbr }->{'branchname'};
+ $err{tbr} = $tbr;
$err{code} = $typecode;
}
elsif ( $code eq 'IsPermanent' ) {
$err{errispermanent} = 1;
- $err{msg} = $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
+ $err{msg} = $messages->{'IsPermanent'};
}
elsif ( $code eq 'WasReturned' ) {
$err{errwasreturned} = 1;
diff --git a/circ/circulation.pl b/circ/circulation.pl
index 4e3e1be45c..ff32c0cc0d 100755
--- a/circ/circulation.pl
+++ b/circ/circulation.pl
@@ -30,7 +30,6 @@ use DateTime::Duration;
use C4::Output;
use C4::Print;
use C4::Auth qw/:DEFAULT get_session haspermission/;
-use C4::Branch; # GetBranches
use C4::Koha; # GetPrinter
use C4::Circulation;
use C4::Utils::DataTables::Members;
diff --git a/circ/returns.pl b/circ/returns.pl
index d1b0d54ff4..0f227dd3a2 100755
--- a/circ/returns.pl
+++ b/circ/returns.pl
@@ -45,7 +45,6 @@ use C4::Biblio;
use C4::Items;
use C4::Members;
use C4::Members::Messaging;
-use C4::Branch; # GetBranches
use C4::Koha; # FIXME : is it still useful ?
use C4::RotatingCollections;
use Koha::DateUtils;
@@ -83,7 +82,6 @@ if ( $query->param('print_slip') ) {
#####################
#Global vars
-my $branches = GetBranches();
my $printers = GetPrinters();
my $userenv = C4::Context->userenv;
my $userenv_branch = $userenv->{'branch'} // '';
@@ -401,7 +399,6 @@ if ( $messages->{'WrongTransfer'} and not $messages->{'WasTransfered'}) {
);
my $reserve = $messages->{'ResFound'};
- my $branchname = $branches->{ $reserve->{'branchcode'} }->{'branchname'};
my $borr = C4::Members::GetMember( borrowernumber => $reserve->{'borrowernumber'} );
my $name = $borr->{'surname'} . ", " . $borr->{'title'} . " " . $borr->{'firstname'};
$template->param(
@@ -427,7 +424,6 @@ if ( $messages->{'WrongTransfer'} and not $messages->{'WasTransfered'}) {
#
if ( $messages->{'ResFound'}) {
my $reserve = $messages->{'ResFound'};
- my $branchname = $branches->{ $reserve->{'branchcode'} }->{'branchname'};
my $borr = C4::Members::GetMember( borrowernumber => $reserve->{'borrowernumber'} );
my $holdmsgpreferences = C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $reserve->{'borrowernumber'}, message_name => 'Hold_Filled' } );
if ( $reserve->{'ResFound'} eq "Waiting" or $reserve->{'ResFound'} eq "Reserved" ) {
@@ -447,8 +443,6 @@ if ( $messages->{'ResFound'}) {
# same params for Waiting or Reserved
$template->param(
found => 1,
- currentbranch => $branches->{$userenv_branch}->{'branchname'},
- destbranchname => $branches->{ $reserve->{'branchcode'} }->{'branchname'},
name => $borr->{'surname'} . ", " . $borr->{'title'} . " " . $borr->{'firstname'},
borfirstname => $borr->{'firstname'},
borsurname => $borr->{'surname'},
@@ -485,7 +479,7 @@ foreach my $code ( keys %$messages ) {
elsif ( $code eq 'NotIssued' ) {
$err{notissued} = 1;
$err{msg} = '';
- $err{msg} = $branches->{ $messages->{'IsPermanent'} }->{'branchname'} if $messages->{'IsPermanent'};
+ $err{msg} = $messages->{'IsPermanent'} if $messages->{'IsPermanent'};
}
elsif ( $code eq 'LocalUse' ) {
$err{localuse} = 1;
@@ -512,8 +506,7 @@ foreach my $code ( keys %$messages ) {
elsif ( ( $code eq 'IsPermanent' ) && ( not $messages->{'ResFound'} ) ) {
if ( $messages->{'IsPermanent'} ne $userenv_branch ) {
$err{ispermanent} = 1;
- $err{msg} =
- $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
+ $err{msg} = $messages->{'IsPermanent'};
}
}
elsif ( $code eq 'WrongTransfer' ) {
@@ -617,18 +610,9 @@ foreach ( sort { $a <=> $b } keys %returneditems ) {
}
push @riloop, \%ri;
}
-my ($genbrname, $genprname);
-if (my $b = $branches->{$userenv_branch}) {
- $genbrname = $b->{'branchname'};
-}
-if (my $p = $printers->{$printer}) {
- $genprname = $p->{'printername'};
-}
+
$template->param(
riloop => \@riloop,
- genbrname => $genbrname,
- genprname => $genprname,
- branchname => $genbrname,
printer => $printer,
errmsgloop => \@errmsgloop,
exemptfine => $exemptfine,
diff --git a/circ/selectbranchprinter.pl b/circ/selectbranchprinter.pl
index d87261d027..e037e9ec75 100755
--- a/circ/selectbranchprinter.pl
+++ b/circ/selectbranchprinter.pl
@@ -26,7 +26,6 @@ use C4::Output;
use C4::Auth qw/:DEFAULT get_session/;
use C4::Print; # GetPrinters
use C4::Koha;
-use C4::Branch; # GetBranches
use Koha::Libraries;
@@ -47,7 +46,6 @@ my $sessionID = $query->cookie("CGISESSID");
my $session = get_session($sessionID);
# try to get the branch and printer settings from http, fallback to userenv
-my $branches = GetBranches();
my $printers = GetPrinters();
my $branch = $query->param('branch' );
my $printer = $query->param('printer');
@@ -58,9 +56,9 @@ my $userenv_printer = C4::Context->userenv->{'branchprinter'} || '';
my @updated;
# $session lddines here are doing the updating
-if ($branch and $branches->{$branch}) {
+if ( $branch and my $library = Koha::Libraries->find($branch) ) {
if (! $userenv_branch or $userenv_branch ne $branch ) {
- my $branchname = Koha::Libraries->find($branch)->branchname;
+ my $branchname = $library->branchname;
$template->param(LoginBranchname => $branchname); # update template for new branch
$template->param(LoginBranchcode => $branch); # update template for new branch
$session->param('branchname', $branchname); # update sesssion in DB
@@ -94,10 +92,6 @@ if ($printer) {
$template->param(updated => \@updated) if (scalar @updated);
-unless ($branches->{$branch}) {
- $branch = (keys %$branches)[0]; # if branch didn't really exist, then replace it w/ one that does
-}
-
my @printkeys = sort keys %$printers;
if (scalar(@printkeys) == 1 or not $printers->{$printer}) {
$printer = $printkeys[0]; # if printer didn't really exist, or there is only 1 anyway, then replace it w/ one that does
diff --git a/circ/transferstoreceive.pl b/circ/transferstoreceive.pl
index 4be2bcb6a2..a67f7995dd 100755
--- a/circ/transferstoreceive.pl
+++ b/circ/transferstoreceive.pl
@@ -23,7 +23,6 @@ use warnings;
use CGI qw ( -utf8 );
use C4::Context;
use C4::Output;
-use C4::Branch; # GetBranches
use C4::Auth;
use Koha::DateUtils;
use C4::Biblio;
@@ -37,6 +36,7 @@ use Date::Calc qw(
use C4::Koha;
use C4::Reserves;
+use Koha::Libraries;
my $input = new CGI;
my $itemnumber = $input->param('itemnumber');
@@ -56,18 +56,18 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
my $default = C4::Context->userenv->{'branch'};
# get the all the branches for reference
-my $branches = GetBranches();
+my $libraries = Koha::Libraries->search({}, { order_by => 'branchname' });
my @branchesloop;
my $latetransfers;
-foreach my $br ( keys %$branches ) {
+while ( my $library = $libraries->next ) {
my @transferloop;
my %branchloop;
my @gettransfers =
- GetTransfersFromTo( $branches->{$br}->{'branchcode'}, $default );
+ GetTransfersFromTo( $library->branchcode, $default );
if (@gettransfers) {
- $branchloop{'branchname'} = $branches->{$br}->{'branchname'};
- $branchloop{'branchcode'} = $branches->{$br}->{'branchcode'};
+ $branchloop{'branchname'} = $library->branchname;
+ $branchloop{'branchcode'} = $library->branchcode;
foreach my $num (@gettransfers) {
my %getransf;
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/branch-selector.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/branch-selector.inc
index cd5760cf45..e6dfdb7e44 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/branch-selector.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/branch-selector.inc
@@ -11,12 +11,12 @@ END %]
[% FOREACH branch IN branches %]
[% IF branch.selected || (selectall == 1) %]
-
+
[% ELSE %]
-
+
[% END %]
-
+
[% IF loop.count() % 4 == 0 && !loop.last() %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/subscriptions-search.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/subscriptions-search.inc
index 5ef2f85aab..b7f890c17a 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/subscriptions-search.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/subscriptions-search.inc
@@ -30,13 +30,8 @@
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoices.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoices.tt
index 4b4691598f..f451b74a43 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoices.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoices.tt
@@ -1,4 +1,5 @@
[% USE KohaDates %]
+[% USE Branches %]
[% INCLUDE 'doc-head-open.inc' %]
Koha › Acquisitions › Invoices
@@ -262,7 +263,7 @@ $(document).ready(function() {
Publication year: [% publicationyear %]
[% END %]
[% IF ( branch ) %]
- Library: [% branchname %]
+ Library: [% Branches.GetName( branch ) %]
[% END %]
@@ -348,13 +349,8 @@ $(document).ready(function() {
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt
index 4454734401..5f6b3eebbb 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt
@@ -1,3 +1,4 @@
+[% USE Branches %]
[% USE Price %]
[% INCLUDE 'doc-head-open.inc' %]
Koha › Administration › Funds[% IF op == 'add_form' %] › [% IF ( budget_id ) %]Modify fund[% IF ( budget_name ) %] '[% budget_name %]'[% END %][% ELSE %]Add fund [% END %][% END %]
@@ -522,7 +523,7 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget")
@@ -653,7 +654,7 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget")
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branch_transfer_limits.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branch_transfer_limits.tt
index d8459f9c72..3d041287da 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branch_transfer_limits.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branch_transfer_limits.tt
@@ -58,15 +58,9 @@
Library [% branchcode %] - [% Branches.GetName( branchcode ) %] Checkin and transfer policy
Check the boxes for the libraries you accept to checkin items from.
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/item_circulation_alerts.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/item_circulation_alerts.tt
index b55709c46b..d55801fc04 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/item_circulation_alerts.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/item_circulation_alerts.tt
@@ -1,3 +1,4 @@
+[% USE Branches %]
[% INCLUDE 'doc-head-open.inc' %]
Koha › Administration › Item circulation alerts
[% INCLUDE 'doc-head-close.inc' %]
@@ -103,13 +104,8 @@ $(function(){
Select a library:
@@ -141,7 +137,7 @@ $(function(){
-Circulation alerts for [% branch_name %]
+Circulation alerts for [% Branches.GetName( branch ) || 'Default' %]
Click on the grid to toggle the settings.
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt
index 13b5cb1bb5..5bee89e7f3 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt
@@ -143,7 +143,7 @@ $(document).ready(function() {
Select a library :
[% IF ( definedbranch ) %]
@@ -151,9 +151,7 @@ $(document).ready(function() {
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/auth.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/auth.tt
index a5c419ab1a..8d0e58f341 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/auth.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/auth.tt
@@ -1,3 +1,4 @@
+[% USE Branches %]
[% INCLUDE 'doc-head-open.inc' %]
Koha ›
[% IF ( nopermission ) %]Access denied[% END %]
@@ -57,7 +58,7 @@
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt
index 987d4c9bf1..c6bdc23584 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt
@@ -1,3 +1,4 @@
+[% USE Branches %]
[% INCLUDE 'doc-head-open.inc' %]
Koha › Catalog › Advanced search
[% INCLUDE 'doc-head-close.inc' %]
@@ -252,7 +253,8 @@