From 37b1852ced897bea4b214b5cc10630487133fa4b 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 --- 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 ++---- cataloguing/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 +- .../en/modules/admin/branch_transfer_limits.tt | 12 +--- .../en/modules/admin/item_circulation_alerts.tt | 12 ++-- .../prog/en/modules/admin/smart-rules.tt | 6 +- koha-tmpl/intranet-tmpl/prog/en/modules/auth.tt | 3 +- .../prog/en/modules/catalogue/advsearch.tt | 4 +- .../prog/en/modules/catalogue/detail.tt | 4 +- .../prog/en/modules/circ/bookcount.tt | 7 ++- .../prog/en/modules/circ/branchtransfers.tt | 6 +- .../intranet-tmpl/prog/en/modules/circ/returns.tt | 24 ++++---- .../prog/en/modules/common/patron_search.tt | 8 ++- .../prog/en/modules/reports/borrowers_stats.tt | 2 +- .../prog/en/modules/reserve/request.tt | 14 ++--- .../rotating_collections/transferCollection.tt | 11 +--- .../prog/en/modules/serials/serials-search.tt | 18 ++---- .../prog/en/modules/serials/subscription-add.tt | 10 ++-- .../prog/en/modules/suggestion/suggestion.tt | 17 ++++-- .../intranet-tmpl/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 +- .../opac-tmpl/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, 294 insertions(+), 692 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index afdca5c..9e3fd26 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -1077,7 +1077,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 @@ -1527,7 +1527,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 7f1b713..a4f6b2f 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 c80723d..d32cde3 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; } @@ -2007,8 +2008,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 4ff47af..ecbebd9 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -1140,6 +1140,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 65c26b3..c94fef3 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); @@ -628,8 +627,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}; } @@ -706,8 +704,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 3640bc7..162a391 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -1336,6 +1336,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 3f0c32d..42846aa 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); @@ -786,8 +787,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 bdd844d..c7d9ab1 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); @@ -1840,14 +1841,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 923b7fe..8ae813a 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 f5cd4ee..46bed55 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 9f4831c..fefc3ab 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 df9d04e..b41d3e4 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 ) = @_; @@ -57,21 +58,11 @@ sub GetURL { 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 ab1f1ca..d2481c6 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 552754c..d2c2e25 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 afc0ec0..f3bf36a 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 cdef0df..c0db854 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 3048fb5..7f0ed5d 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 872d0af..2b2ed17 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 72cab5a..10f6074 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 7353dc9..81bc18d 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 b07ee0f..d815022 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 4f0391a..ba3989a 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 c9baad7..e7dd2bb 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 b782901..49fb661 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 b745136..84d7210 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 f09c2bf..358ef7d 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 3e6e6dd..5e9c463 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 8d44f70..6071df1 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 4103e2b..351f50b 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 55fd912..0aab030 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 ef9817e..37d2599 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -27,7 +27,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; @@ -125,7 +124,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; @@ -256,7 +254,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; @@ -267,8 +265,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 2e6608b..27c899a 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 38645c2..bf91573 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 1e7cb61..b206b92 100755 --- a/cataloguing/addbiblio.pl +++ b/cataloguing/addbiblio.pl @@ -31,12 +31,13 @@ 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::Libraries; + use Date::Calc qw(Today); use MARC::File::USMARC; use MARC::File::XML; @@ -172,18 +173,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 a5f2103..75c9dec 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 d4d3e54..2976a05 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 8b7bddd..eb0a4f7 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 0ffb4df..d7b3dc3 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 efe8716..80c57e5 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 d87261d..e037e9e 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 4be2bcb..a67f799 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 cd5760c..e6dfdb7 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 9d6abd7..69e1817 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 e94f2c0..18ff2cb 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 4454734..5f6b3ee 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 d8459f9..3d04128 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 b55709c..d55801f 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 c36be6f..e0bdc5a 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 a5c419a..8d0e58f 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 @@ <p><label for="branch">Library:</label> <select name="branch" id="branch" class="input" tabindex="3"> <option value="">My library</option> - [% FOREACH l IN Branches.all() %] + [% FOREACH l IN Branches.all( unfiltered => 1 ) %] <option value="[% l.branchcode %]">[% l.branchname %]</option> [% END %] </select> 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 987d4c9..c6bdc23 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' %] <title>Koha › Catalog › Advanced search [% INCLUDE 'doc-head-close.inc' %] @@ -252,7 +253,8 @@

    [% IF ( searchdomainloop ) %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt index 00a952a..3803835 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -675,7 +675,7 @@ function verify_images() { : due [% item.datedue %] [% ELSIF ( item.transfertwhen ) %] - In transit from [% item.transfertfrom %] to [% item.transfertto %] since [% item.transfertwhen | $KohaDates %] + In transit from [% Branches.GetName( item.transfertfrom ) %] to [% Branches.GetName( item.transfertto ) %] since [% item.transfertwhen | $KohaDates %] [% END %] [% IF ( item.itemlost ) %] @@ -731,7 +731,7 @@ function verify_images() { [% IF ( item.waitingdate ) %] at[% ELSE %]for delivery at [% END %] - [% item.ExpectedAtLibrary %] + [% Branches.GetName( item.ExpectedAtLibrary ) %] [% IF ( item.waitingdate ) %] since [% item.waitingdate | $KohaDates %] [% ELSE %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/bookcount.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/bookcount.tt index 60b3f52..9257027 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/bookcount.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/bookcount.tt @@ -1,4 +1,5 @@ [% USE KohaDates %] +[% USE Branches %] [% INCLUDE 'doc-head-open.inc' %] Koha › Circulation › Circulation statistics for [% title |html %] [% INCLUDE 'doc-head-close.inc' %] @@ -25,9 +26,9 @@ $(document).ready(function(){

    Barcode [% barcode %]

    - - - + + + diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/branchtransfers.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/branchtransfers.tt index d68a39f..bbc8861 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/branchtransfers.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/branchtransfers.tt @@ -111,7 +111,7 @@
  • No Item with barcode: [% errmsgloo.msg %]
  • [% END %] [% IF ( errmsgloo.errispermanent ) %] -
  • Please return item to home library: [% errmsgloo.msg %]
  • +
  • Please return item to home library: [% Branches.GetName( errmsgloo.msg ) %]
  • [% END %] [% IF ( errmsgloo.errnotallowed ) %]
  • Transfer is not allowed for: @@ -121,7 +121,7 @@ [% ELSE %]
  • Collection code: [% AuthorisedValues.GetByCode( 'CCODE', errmsgloo.code ) %]
  • [% END %] -
  • Destination library: [% errmsgloo.tbr %]
  • +
  • Destination library: [% Branches.GetName( errmsgloo.tbr ) %]
  • [% END %] @@ -187,7 +187,7 @@ - + [% END %]
    Home libraryCurrent libraryDate arrived
    at current library
    Number of checkouts
    since last transfer
    [% homebranch %][% holdingbranch %]
    [% Branches.GetName( homebranch ) %][% Branches.GetName( holdingbranch ) %] [% IF ( lastdate ) %][% lastdate | $KohaDates %][% ELSE %]Item has no transfer record[% END %] [% count %]
    [% trsfitemloo.itemcallnumber %] [% ItemTypes.GetDescription( trsfitemloo.itemtype ) %] [% AuthorisedValues.GetByCode( 'CCODE', trsfitemloo.ccode ) %][% trsfitemloo.tobrname %][% Branches.GetName( trsfitemloo.tobrname ) %]
    diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt index dda2146..919a956 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt @@ -261,10 +261,10 @@ $(document).ready(function () { [% INCLUDE display_bormessagepref %] [% IF ( debarred ) %]
  • Patron is RESTRICTED
  • [% END %] [% IF ( gonenoaddress ) %]
  • Patron's address is in doubt
  • [% END %] - [% IF ( transfertodo ) %] -

    Transfer to: [% destbranchname %]

    - [% ELSE %] -

    Hold at [% destbranchname %]

    + [% IF ( transfertodo ) %] +

    Transfer to: [% Branches.GetName( destbranch ) %]

    + [% ELSE %] +

    Hold at [% Branches.GetName( destbranch ) %]

    [% END %]
    @@ -310,10 +310,10 @@ $(document).ready(function () { [% IF ( debarred ) %]
  • Patron is RESTRICTED
  • [% END %] [% IF ( gonenoaddress ) %]
  • Patron's address is in doubt
  • [% END %] - [% IF ( transfertodo ) %] -

    Transfer to: [% destbranchname %]

    - [% ELSE %] -

    Hold at [% destbranchname %]

    + [% IF ( transfertodo ) %] +

    Transfer to: [% Branches.GetName( destbranch ) %]

    + [% ELSE %] +

    Hold at [% Branches.GetName( destbranch ) %]

    [% END %] @@ -426,9 +426,9 @@ $(document).ready(function () { [% IF ( gonenoaddress ) %]
  • Patron's address is in doubt
  • [% END %] [% IF ( transfertodo ) %] -

    Transfer to: [% destbranchname %]

    - [% ELSE %] -

    Hold at [% destbranchname %]

    +

    Transfer to: [% Branches.GetName( destbranch ) %]

    + [% ELSE %] +

    Hold at [% Branches.GetName( destbranch ) %]

    [% END %] @@ -487,7 +487,7 @@ $(document).ready(function () {

    No item with barcode: [% errmsgloo.msg %]

    [% END %] [% IF ( errmsgloo.ispermanent ) %] -

    Please return item to: [% errmsgloo.msg %]

    +

    Please return item to: [% Branches.GetName( errmsgloo.msg ) %]

    [% END %] [% IF ( errmsgloo.notissued ) %]

    Not checked out.

    diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/common/patron_search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/common/patron_search.tt index 1dd4151..9af0510 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/common/patron_search.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/common/patron_search.tt @@ -1,4 +1,5 @@ [% USE Koha %] +[% USE Branches %] [% INCLUDE 'doc-head-open.inc' %] Koha › Patron search [% INCLUDE 'doc-head-close.inc' %] @@ -194,11 +195,12 @@ function filterByFirstLetterSurname(letter) {
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/borrowers_stats.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/borrowers_stats.tt index 2c14305..005886d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/borrowers_stats.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/borrowers_stats.tt @@ -142,7 +142,7 @@ diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt index 1f1e56a..a15b030 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt @@ -16,10 +16,10 @@