diff --git a/C4/Auth.pm b/C4/Auth.pm index f0822a61a6..0bcad666df 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -29,7 +29,6 @@ require Exporter; use C4::Context; use C4::Templates; # to get the template use C4::Languages; -use C4::Branch; # GetBranches use C4::Search::History; use Koha; use Koha::Caches; @@ -514,7 +513,6 @@ sub get_template_and_user { $template->param( OpacAdditionalStylesheet => C4::Context->preference("OpacAdditionalStylesheet"), AnonSuggestions => "" . C4::Context->preference("AnonSuggestions"), - BranchesLoop => GetBranchesLoop($opac_name), BranchCategoriesLoop => $library_categories, opac_name => $opac_name, LibraryName => "" . C4::Context->preference("LibraryName"), @@ -1080,7 +1078,7 @@ sub checkauth { $branchcode = $query->param('branch'); $branchname = Koha::Libraries->find($branchcode)->branchname; } - my $branches = GetBranches(); + my $branches = C4::Branch::GetBranches(); if ( C4::Context->boolean_preference('IndependentBranches') && C4::Context->boolean_preference('Autolocation') ) { # we have to check they are coming from the right ip range @@ -1091,7 +1089,6 @@ sub checkauth { } } - my @branchesloop; foreach my $br ( keys %$branches ) { # now we work with the treatment of ip @@ -1208,7 +1205,6 @@ sub checkauth { my $template_name = ( $type eq 'opac' ) ? 'opac-auth.tt' : 'auth.tt'; my $template = C4::Templates::gettemplate( $template_name, $type, $query ); $template->param( - branchloop => GetBranchesLoop(), OpacAdditionalStylesheet => C4::Context->preference("OpacAdditionalStylesheet"), opaclayoutstylesheet => C4::Context->preference("opaclayoutstylesheet"), login => 1, @@ -1532,8 +1528,7 @@ sub check_api_auth { $branchcode = $query->param('branch'); $branchname = Koha::Libraries->find($branchcode)->branchname; } - my $branches = GetBranches(); - my @branchesloop; + my $branches = C4::Branch::GetBranches(); foreach my $br ( keys %$branches ) { # now we work with the treatment of ip diff --git a/C4/Branch.pm b/C4/Branch.pm index 7b9b85d7f1..f2d7bf1d03 100644 --- a/C4/Branch.pm +++ b/C4/Branch.pm @@ -29,7 +29,6 @@ BEGIN { @EXPORT = qw( &GetBranch &GetBranches - &GetBranchesLoop &mybranch ); @EXPORT_OK = qw( &onlymine &mybranch ); @@ -83,8 +82,6 @@ Create a branch selector with the following code. [% END %] -=head4 Note that you often will want to just use GetBranchesLoop, for exactly the example above. - =cut sub GetBranches { @@ -135,22 +132,6 @@ sub mybranch { return C4::Context->userenv->{branch} || ''; } -sub GetBranchesLoop { # since this is what most pages want anyway - my $branch = @_ ? shift : mybranch(); # optional first argument is branchcode of "my branch", if preselection is wanted. - my $onlymine = @_ ? shift : onlymine(); - my $branches = GetBranches($onlymine); - my @loop; - foreach my $branchcode ( sort { uc($branches->{$a}->{branchname}) cmp uc($branches->{$b}->{branchname}) } keys %$branches ) { - push @loop, { - value => $branchcode, - branchcode => $branchcode, - selected => ($branchcode eq $branch) ? 1 : 0, - branchname => $branches->{$branchcode}->{branchname}, - }; - } - return \@loop; -} - =head2 GetBranch $branch = GetBranch( $query, $branches ); diff --git a/C4/Search.pm b/C4/Search.pm index 29e606239f..ab84087b0b 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -337,6 +337,9 @@ sub getRecords { my @results; my $results_hashref = (); + # TODO simplify this structure ( { branchcode => $branchname } is enought) and remove this parameter + $branches ||= { map { $_->branchcode => { branchname => $_->branchname } } Koha::Libraries->search }; + # Initialize variables for the faceted results objects my $facets_counter = {}; my $facets_info = {}; diff --git a/Koha/Template/Plugin/Branches.pm b/Koha/Template/Plugin/Branches.pm index 0b95e4284a..8b959a2e33 100644 --- a/Koha/Template/Plugin/Branches.pm +++ b/Koha/Template/Plugin/Branches.pm @@ -67,24 +67,25 @@ sub all { SELECT branchcode, branchname FROM branches |; - if ( C4::Branch::onlymine + 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}; } - $query .= q| ORDER BY branchname|; - my $branches = $dbh->selectall_arrayref( $query, { Slice => {} }, @params ); + my $libraries = $dbh->selectall_arrayref( $query, { Slice => {} }, @params ); - if ( $selected ) { - for my $branch ( @$branches ) { - if ( $branch->{branchcode} eq $selected ) { - $branch->{selected} = 1; - } + for my $l ( @$libraries ) { + if ( $selected and $l->{branchcode} eq $selected + or not $selected and C4::Context->userenv and $l->{branchcode} eq C4::Context->userenv->{branch} + ) { + $l->{selected} = 1; } } - return $branches; + + return $libraries; } 1; diff --git a/acqui/basketgroup.pl b/acqui/basketgroup.pl index 85422cbcdc..ddc2ec279e 100755 --- a/acqui/basketgroup.pl +++ b/acqui/basketgroup.pl @@ -52,7 +52,6 @@ use C4::Output; use CGI qw ( -utf8 ); use C4::Acquisition qw/CloseBasketgroup ReOpenBasketgroup GetOrders GetBasketsByBasketgroup GetBasketsByBookseller ModBasketgroup NewBasketgroup DelBasketgroup GetBasketgroups ModBasket GetBasketgroup GetBasket GetBasketGroupAsCSV/; -use C4::Branch qw/GetBranches/; use C4::Members qw/GetMember/; use Koha::EDI qw/create_edi_order get_edifact_ean/; @@ -272,10 +271,8 @@ if ( $op eq "add" ) { $billingplace = $billingplace || $borrower->{'branchcode'}; $deliveryplace = $deliveryplace || $borrower->{'branchcode'}; - my $branches = C4::Branch::GetBranchesLoop( $billingplace ); - $template->param( billingplaceloop => $branches ); - $branches = C4::Branch::GetBranchesLoop( $deliveryplace ); - $template->param( deliveryplaceloop => $branches ); + $template->param( billingplace => $billingplace ); + $template->param( deliveryplace => $deliveryplace ); $template->param( booksellerid => $booksellerid ); # the template will display a unique basketgroup diff --git a/acqui/basketheader.pl b/acqui/basketheader.pl index c59ea87ba6..cdef0dfaa9 100755 --- a/acqui/basketheader.pl +++ b/acqui/basketheader.pl @@ -121,20 +121,14 @@ if ( $op eq 'add_form' ) { booksellerid => $booksellerid, basketno => $basketno, booksellers => \@booksellers, - deliveryplace => $basket->{deliveryplace}, - billingplace => $basket->{billingplace}, is_standing => $basket->{is_standing}, ); my $billingplace = $basket->{'billingplace'} || C4::Context->userenv->{"branch"}; my $deliveryplace = $basket->{'deliveryplace'} || C4::Context->userenv->{"branch"}; - # Build the combobox to select the billing place - - my $branches = C4::Branch::GetBranchesLoop( $billingplace ); - $template->param( billingplaceloop => $branches ); - $branches = C4::Branch::GetBranchesLoop( $deliveryplace ); - $template->param( deliveryplaceloop => $branches ); + $template->param( billingplace => $billingplace ); + $template->param( deliveryplace => $deliveryplace ); #End Edit } elsif ( $op eq 'add_validate' ) { diff --git a/acqui/neworderempty.pl b/acqui/neworderempty.pl index da5acd5cdd..72cab5aa6b 100755 --- a/acqui/neworderempty.pl +++ b/acqui/neworderempty.pl @@ -210,24 +210,6 @@ $suggestion = GetSuggestionInfo($suggestionid) if $suggestionid; my @currencies = Koha::Acquisition::Currencies->search; my $active_currency = Koha::Acquisition::Currencies->get_active; -# build branches list -my $onlymine = - C4::Context->preference('IndependentBranches') - && C4::Context->userenv - && !C4::Context->IsSuperLibrarian() - && C4::Context->userenv->{branch}; -my $branches = GetBranches($onlymine); -my @branchloop; -foreach my $thisbranch ( sort {$branches->{$a}->{'branchname'} cmp $branches->{$b}->{'branchname'}} keys %$branches ) { - my %row = ( - value => $thisbranch, - branchname => $branches->{$thisbranch}->{'branchname'}, - ); - $row{'selected'} = 1 if( $thisbranch && $data->{branchcode} && $thisbranch eq $data->{branchcode}) ; - push @branchloop, \%row; -} -$template->param( branchloop => \@branchloop ); - # build bookfund list my $borrower= GetMember('borrowernumber' => $loggedinuser); my ( $flags, $homebranch )= ($borrower->{'flags'},$borrower->{'branchcode'}); diff --git a/admin/aqbudgetperiods.pl b/admin/aqbudgetperiods.pl index f7d8a46dec..7ce57835b8 100755 --- a/admin/aqbudgetperiods.pl +++ b/admin/aqbudgetperiods.pl @@ -281,14 +281,11 @@ foreach my $result ( @{$results} ) { push( @period_inactive_loop, $budgetperiod ); } -my $branchloop = C4::Branch::GetBranchesLoop(); - my $tab = $input->param('tab') ? $input->param('tab') - 1 : 0; $template->param( period_active_loop => \@period_active_loop, period_inactive_loop => \@period_inactive_loop, tab => $tab, - branchloop => $branchloop, ); $template->param($op=>1); diff --git a/admin/aqbudgets.pl b/admin/aqbudgets.pl index 0e6b744251..c9baad7b53 100755 --- a/admin/aqbudgets.pl +++ b/admin/aqbudgets.pl @@ -96,12 +96,11 @@ my $user_branchcode = $user->{'branchcode'}; $template->param( show_mine => $show_mine, op => $op, + selected_branchcode => $filter_budgetbranch, ); my $budget; -my $branchloop = C4::Branch::GetBranchesLoop($filter_budgetbranch); - $template->param(auth_cats_loop => GetBudgetAuthCats( $budget_period_id )) if $budget_period_id; @@ -153,7 +152,7 @@ if ($op eq 'add_form') { $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 = (); @@ -343,7 +342,6 @@ if ( $op eq 'list' ) { spent_total => $spent_total, ordered_total => $ordered_total, available_total => $available_total, - branchloop => $branchloop, filter_budgetname => $filter_budgetname, ); diff --git a/admin/aqplan.pl b/admin/aqplan.pl index c6946d6c2e..a27fb0a4ca 100755 --- a/admin/aqplan.pl +++ b/admin/aqplan.pl @@ -394,7 +394,6 @@ if ( $output eq "file" ) { exit(1); } -my $branchloop = C4::Branch::GetBranchesLoop(); $template->param( authvals_row => \@authvals_row, budget_lines => \@budget_lines, @@ -411,7 +410,6 @@ $template->param( authvals => \@authvals_row, hide_cols_loop => \@hide_cols, - branchloop => $branchloop, ); output_html_with_http_headers $input, $cookie, $template->output; diff --git a/admin/clone-rules.pl b/admin/clone-rules.pl index d2412ae15d..9fd330fa71 100755 --- a/admin/clone-rules.pl +++ b/admin/clone-rules.pl @@ -33,7 +33,6 @@ use C4::Output; use C4::Auth; use C4::Koha; use C4::Debug; -use C4::Branch; # GetBranchesLoop my $input = new CGI; my $dbh = C4::Context->dbh; @@ -49,13 +48,10 @@ my ($template, $loggedinuser, $cookie) my $frombranch = $input->param("frombranch"); my $tobranch = $input->param("tobranch"); -my $branchloop = GetBranchesLoop; $template->param(frombranch => $frombranch) if ($frombranch); $template->param(tobranch => $tobranch) if ($tobranch); -$template->param(branchloop => $branchloop); - if ($frombranch && $tobranch) { my $error; diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl index 4f5185dc04..6019214ef8 100755 --- a/admin/smart-rules.pl +++ b/admin/smart-rules.pl @@ -461,16 +461,6 @@ $template->param( defaultRefundRule => Koha::RefundLostItemFeeRules->_default_rule ); -my $branches = GetBranches(); -my @branchloop; -for my $thisbranch (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %$branches) { - push @branchloop, { - value => $thisbranch, - selected => $thisbranch eq $branch, - branchname => $branches->{$thisbranch}->{'branchname'}, - }; -} - my $patron_categories = Koha::Patron::Categories->search({}, { order_by => ['description'] }); my @row_loop; @@ -624,8 +614,7 @@ $template->param( patron_categories => $patron_categories, itemtypeloop => \@itemtypes, rules => \@sorted_row_loop, - branchloop => \@branchloop, - humanbranch => ($branch ne '*' ? $branches->{$branch}->{branchname} : ''), + humanbranch => ($branch ne '*' ? $branch : ''), current_branch => $branch, definedbranch => scalar(@sorted_row_loop)>0 ); diff --git a/catalogue/search.pl b/catalogue/search.pl index 3fa25c02d3..5428edeb08 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -214,25 +214,9 @@ if($cgi->cookie("intranet_bib_list")){ } # load the branches -my $branches = GetBranches(); - -# Populate branch_loop with all branches sorted by their name. If -# IndependentBranches is activated, set the default branch to the borrower -# branch, except for superlibrarian who need to search all libraries. -my $user = C4::Context->userenv; -my @branch_loop = map { - { - value => $_, - branchname => $branches->{$_}->{branchname}, - selected => $user->{branch} eq $_ && C4::Branch::onlymine(), - } -} sort { - $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} -} keys %$branches; - my $categories = Koha::LibraryCategories->search( { categorytype => 'searchdomain' }, { order_by => [ 'categorytype', 'categorycode' ] } ); -$template->param(branchloop => \@branch_loop, searchdomainloop => $categories); +$template->param(searchdomainloop => $categories); # load the Type stuff my $itemtypes = GetItemTypes; @@ -537,7 +521,7 @@ eval { my $itemtypes = GetItemTypes; ( $error, $results_hashref, $facets ) = $searcher->search_compat( $query, $simple_query, \@sort_by, \@servers, - $results_per_page, $offset, $expanded_facet, $branches, + $results_per_page, $offset, $expanded_facet, undef, $itemtypes, $query_type, $scan ); }; diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index 86abc5709d..9f0f146b48 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -29,9 +29,9 @@ use C4::Items; use C4::Context; use C4::Circulation; use C4::Koha; -use C4::Branch; use C4::ClassSource; use Koha::DateUtils; +use Koha::Libraries; use List::MoreUtils qw/any/; use C4::Search; use Storable qw(thaw freeze); @@ -175,9 +175,9 @@ sub generate_subfield_form { # builds list, depending on authorised value... if ( $subfieldlib->{authorised_value} eq "branches" ) { foreach my $thisbranch (@$branches) { - push @authorised_values, $thisbranch->{value}; - $authorised_lib{$thisbranch->{value}} = $thisbranch->{branchname}; - $value = $thisbranch->{value} if $thisbranch->{selected} && !$value; + push @authorised_values, $thisbranch->{branchcode}; + $authorised_lib{$thisbranch->{branchcode}} = $thisbranch->{branchname}; + $value = $thisbranch->{branchcode} if $thisbranch->{selected} && !$value; } } elsif ( $subfieldlib->{authorised_value} eq "itemtypes" ) { @@ -863,13 +863,11 @@ my $i=0; my $pref_itemcallnumber = C4::Context->preference('itemcallnumber'); -my $onlymine = - C4::Context->preference('IndependentBranches') - && C4::Context->userenv - && !C4::Context->IsSuperLibrarian() - && C4::Context->userenv->{branch}; my $branch = $input->param('branch') || C4::Context->userenv->{branch}; -my $branches = GetBranchesLoop($branch,$onlymine); # build once ahead of time, instead of multiple times later. +my $libraries = Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed;# build once ahead of time, instead of multiple times later. +for my $library ( @$libraries ) { + $library->{selected} = 1 if $library->{branchcode} eq $branch +} # We generate form, from actuel record @fields = (); @@ -884,7 +882,7 @@ if($itemrecord){ next if ($tagslib->{$tag}->{$subfieldtag}->{'tab'} ne "10"); - my $subfield_data = generate_subfield_form($tag, $subfieldtag, $value, $tagslib, $subfieldlib, $branches, $biblionumber, $temp, \@loop_data, $i, $restrictededition); + my $subfield_data = generate_subfield_form($tag, $subfieldtag, $value, $tagslib, $subfieldlib, $libraries, $biblionumber, $temp, \@loop_data, $i, $restrictededition); push @fields, "$tag$subfieldtag"; push (@loop_data, $subfield_data); $i++; @@ -908,7 +906,7 @@ foreach my $tag ( keys %{$tagslib}){ my @values = (undef); @values = $itemrecord->field($tag)->subfield($subtag) if ($itemrecord && defined($itemrecord->field($tag)) && defined($itemrecord->field($tag)->subfield($subtag))); for my $value (@values){ - my $subfield_data = generate_subfield_form($tag, $subtag, $value, $tagslib, $tagslib->{$tag}->{$subtag}, $branches, $biblionumber, $temp, \@loop_data, $i, $restrictededition); + my $subfield_data = generate_subfield_form($tag, $subtag, $value, $tagslib, $tagslib->{$tag}->{$subtag}, $libraries, $biblionumber, $temp, \@loop_data, $i, $restrictededition); push (@loop_data, $subfield_data); $i++; } diff --git a/circ/bookcount.pl b/circ/bookcount.pl index 09dc6fcbf0..d4d3e54ed0 100755 --- a/circ/bookcount.pl +++ b/circ/bookcount.pl @@ -32,6 +32,7 @@ use C4::Auth; use C4::Branch; # GetBranches use C4::Biblio; # GetBiblioItemData use Koha::DateUtils; +use Koha::Libraries; my $input = new CGI; my $itm = $input->param('itm'); @@ -69,10 +70,11 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); -my $branchloop = GetBranchesLoop(C4::Context->userenv->{branch}); -foreach (@$branchloop) { - $_->{issues} = issuesat($itm, $_->{value}); - $_->{seen} = lastseenat( $itm, $_->{value} ) || undef; +my $libraries = Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed; +for my $library ( @$libraries ) { + $library->{selected} = 1 if $library->{branchcode} eq C4::Context->userenv->{branch}; + $library->{issues} = issuesat($itm, $library->{branchcode}); + $library->{seen} = lastseenat( $itm, $library->{branchcode} ) || undef; } $template->param( @@ -85,7 +87,7 @@ $template->param( holdingbranch => $holdingbranch, lastdate => $lastdate ? $lastdate : 0, count => $count, - branchloop => $branchloop, + libraries => $libraries, ); output_html_with_http_headers $input, $cookie, $template->output; diff --git a/circ/branchtransfers.pl b/circ/branchtransfers.pl index a826289b65..8b7bddd69f 100755 --- a/circ/branchtransfers.pl +++ b/circ/branchtransfers.pl @@ -236,7 +236,6 @@ $template->param( cancelled => $cancelled, setwaiting => $setwaiting, trsfitemloop => \@trsfitemloop, - branchoptionloop => GetBranchesLoop($tobranchcd), errmsgloop => \@errmsgloop, CircAutocompl => C4::Context->preference("CircAutocompl") ); diff --git a/circ/overdue.pl b/circ/overdue.pl index 047e073f8b..c76b52991a 100755 --- a/circ/overdue.pl +++ b/circ/overdue.pl @@ -214,9 +214,6 @@ if (@patron_attr_filter_loop) { $template->param( patron_attr_header_loop => [ map { { header => $_->{description} } } grep { ! $_->{isclone} } @patron_attr_filter_loop ], - branchloop => GetBranchesLoop($branchfilter, $onlymine), - homebranchloop => GetBranchesLoop( $homebranchfilter, $onlymine ), - holdingbranchloop => GetBranchesLoop( $holdingbranchfilter, $onlymine ), branchfilter => $branchfilter, homebranchfilter => $homebranchfilter, holdingbranchfilter => $homebranchfilter, diff --git a/circ/selectbranchprinter.pl b/circ/selectbranchprinter.pl index 42e8b05993..d87261d027 100755 --- a/circ/selectbranchprinter.pl +++ b/circ/selectbranchprinter.pl @@ -26,7 +26,7 @@ use C4::Output; use C4::Auth qw/:DEFAULT get_session/; use C4::Print; # GetPrinters use C4::Koha; -use C4::Branch; # GetBranches GetBranchesLoop +use C4::Branch; # GetBranches use Koha::Libraries; @@ -136,7 +136,7 @@ if (scalar @updated and not scalar @recycle_loop) { $template->param( referer => $referer, printerloop => \@printerloop, - branchloop => GetBranchesLoop($branch), + branch => $branch, recycle_loop=> \@recycle_loop, ); diff --git a/circ/view_holdsqueue.pl b/circ/view_holdsqueue.pl index d21d3e7581..ce632e6d92 100755 --- a/circ/view_holdsqueue.pl +++ b/circ/view_holdsqueue.pl @@ -30,7 +30,6 @@ use C4::Output; use C4::Biblio; use C4::Items; use C4::Koha; # GetItemTypes -use C4::Branch; # GetBranches use C4::HoldsQueue qw(GetHoldsQueueItems); my $query = new CGI; @@ -72,7 +71,6 @@ foreach my $thisitemtype ( sort keys %$itemtypes ) { } $template->param( - branchloop => GetBranchesLoop(C4::Context->userenv->{'branch'}), itemtypeloop => \@itemtypesloop, ); diff --git a/course_reserves/add_items.pl b/course_reserves/add_items.pl index 24ea732201..bcfadc7f0d 100755 --- a/course_reserves/add_items.pl +++ b/course_reserves/add_items.pl @@ -26,7 +26,6 @@ use C4::Auth; use C4::Output; use C4::Koha; use C4::Biblio; -use C4::Branch; use C4::CourseReserves qw(GetCourse GetCourseItem GetCourseReserve ModCourseItem ModCourseReserve); @@ -73,7 +72,6 @@ if ( $action eq 'lookup' ) { ccodes => GetAuthorisedValues('CCODE'), locations => GetAuthorisedValues('LOC'), itypes => GetItemTypes( style => 'array' ), - branches => GetBranchesLoop(), return => $return, ); diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/budgets-admin-search.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/budgets-admin-search.inc index c2babc2002..3399ce9405 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/budgets-admin-search.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/budgets-admin-search.inc @@ -1,4 +1,5 @@ [% USE Koha %] +[% USE Branches %]