Bug 15758: Koha::Libraries - Remove GetBranchesLoop
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 3 Feb 2016 15:58:08 +0000 (15:58 +0000)
committerKyle M Hall <kyle@bywatersolutions.com>
Thu, 8 Sep 2016 14:36:02 +0000 (14:36 +0000)
Signed-off-by: Owen Leonard <oleonard@myacpl.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

100 files changed:
C4/Auth.pm
C4/Branch.pm
C4/Search.pm
Koha/Template/Plugin/Branches.pm
acqui/basketgroup.pl
acqui/basketheader.pl
acqui/neworderempty.pl
admin/aqbudgetperiods.pl
admin/aqbudgets.pl
admin/aqplan.pl
admin/clone-rules.pl
admin/smart-rules.pl
catalogue/search.pl
cataloguing/additem.pl
circ/bookcount.pl
circ/branchtransfers.pl
circ/overdue.pl
circ/selectbranchprinter.pl
circ/view_holdsqueue.pl
course_reserves/add_items.pl
koha-tmpl/intranet-tmpl/prog/en/includes/budgets-admin-search.inc
koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc
koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc [new file with mode: 0644]
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tt
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketheader.tt
koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt
koha-tmpl/intranet-tmpl/prog/en/modules/admin/clone-rules.tt
koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt
koha-tmpl/intranet-tmpl/prog/en/modules/admin/transport-cost-matrix.tt
koha-tmpl/intranet-tmpl/prog/en/modules/auth.tt
koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt
koha-tmpl/intranet-tmpl/prog/en/modules/circ/bookcount.tt
koha-tmpl/intranet-tmpl/prog/en/modules/circ/branchtransfers.tt
koha-tmpl/intranet-tmpl/prog/en/modules/circ/overdue.tt
koha-tmpl/intranet-tmpl/prog/en/modules/circ/selectbranchprinter.tt
koha-tmpl/intranet-tmpl/prog/en/modules/circ/view_holdsqueue.tt
koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/add_items-step2.tt
koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt
koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt
koha-tmpl/intranet-tmpl/prog/en/modules/reports/bor_issues_top.tt
koha-tmpl/intranet-tmpl/prog/en/modules/reports/borrowers_stats.tt
koha-tmpl/intranet-tmpl/prog/en/modules/reports/cat_issues_top.tt
koha-tmpl/intranet-tmpl/prog/en/modules/reports/catalogue_out.tt
koha-tmpl/intranet-tmpl/prog/en/modules/reports/catalogue_stats.tt
koha-tmpl/intranet-tmpl/prog/en/modules/reports/issues_avg_stats.tt
koha-tmpl/intranet-tmpl/prog/en/modules/reports/issues_by_borrower_category.tt
koha-tmpl/intranet-tmpl/prog/en/modules/reports/issues_stats.tt
koha-tmpl/intranet-tmpl/prog/en/modules/reports/itemslost.tt
koha-tmpl/intranet-tmpl/prog/en/modules/reports/itemtypes.tt
koha-tmpl/intranet-tmpl/prog/en/modules/reports/reserves_stats.tt
koha-tmpl/intranet-tmpl/prog/en/modules/reports/serials_stats.tt
koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt
koha-tmpl/intranet-tmpl/prog/en/modules/serials/checkexpiration.tt
koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt
koha-tmpl/intranet-tmpl/prog/en/modules/tools/import_borrowers.tt
koha-tmpl/intranet-tmpl/prog/en/modules/tools/inventory.tt
koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt
koha-tmpl/intranet-tmpl/prog/en/modules/tools/overduerules.tt
koha-tmpl/opac-tmpl/bootstrap/en/includes/doc-head-close.inc
koha-tmpl/opac-tmpl/bootstrap/en/includes/html_helpers.inc [new file with mode: 0644]
koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc
koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-topissues.inc
koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-advsearch.tt
koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt
koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt
koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt
members/memberentry.pl
members/members-home.pl
opac/opac-memberentry.pl
opac/opac-reserve.pl
opac/opac-suggestions.pl
opac/opac-topissues.pl
opac/opac-user.pl
reports/bor_issues_top.pl
reports/borrowers_stats.pl
reports/cat_issues_top.pl
reports/catalogue_out.pl
reports/catalogue_stats.pl
reports/guided_reports.pl
reports/issues_avg_stats.pl
reports/issues_by_borrower_category.plugin
reports/issues_stats.pl
reports/itemslost.pl
reports/itemtypes.plugin
reports/reserves_stats.pl
reports/serials_stats.pl
reserve/request.pl
serials/checkexpiration.pl
serials/claims.pl
t/db_dependent/Branch.t
t/db_dependent/Holds/LocalHoldsPriority.t
t/db_dependent/Holds/RevertWaitingStatus.t
t/db_dependent/Reserves.t
tools/batchMod.pl
tools/holidays.pl
tools/import_borrowers.pl
tools/inventory.pl
tools/letter.pl
tools/modborrowers.pl
tools/overduerules.pl

index f0822a6..0bcad66 100644 (file)
@@ -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
index 7b9b85d..f2d7bf1 100644 (file)
@@ -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 %]
     </select>
 
-=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 );
index 29e6062..ab84087 100644 (file)
@@ -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    = {};
index 0b95e42..8b959a2 100644 (file)
@@ -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 );
-
-    if ( $selected ) {
-        for my $branch ( @$branches ) {
-            if ( $branch->{branchcode} eq $selected ) {
-                $branch->{selected} = 1;
-            }
+    my $libraries = $dbh->selectall_arrayref( $query, { Slice => {} }, @params );
+
+    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;
index 85422cb..ddc2ec2 100755 (executable)
@@ -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
index c59ea87..cdef0df 100755 (executable)
@@ -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' ) {
index da5acd5..72cab5a 100755 (executable)
@@ -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'});
index f7d8a46..7ce5783 100755 (executable)
@@ -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);
index 0e6b744..c9baad7 100755 (executable)
@@ -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,
     );
 
index c6946d6..a27fb0a 100755 (executable)
@@ -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;
index d2412ae..9fd330f 100755 (executable)
@@ -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; 
index 4f5185d..6019214 100755 (executable)
@@ -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
                         );
index 3fa25c0..5428ede 100755 (executable)
@@ -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
     );
 };
index 86abc57..9f0f146 100755 (executable)
@@ -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++;
         }
index 09dc6fc..d4d3e54 100755 (executable)
@@ -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;
index a826289..8b7bddd 100755 (executable)
@@ -236,7 +236,6 @@ $template->param(
     cancelled               => $cancelled,
     setwaiting              => $setwaiting,
     trsfitemloop            => \@trsfitemloop,
-    branchoptionloop        => GetBranchesLoop($tobranchcd),
     errmsgloop              => \@errmsgloop,
     CircAutocompl           => C4::Context->preference("CircAutocompl")
 );
index 047e073..c76b529 100755 (executable)
@@ -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,
index 42e8b05..d87261d 100755 (executable)
@@ -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,
 );
 
index d21d3e7..ce632e6 100755 (executable)
@@ -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,
 );
 
index 24ea732..bcfadc7 100755 (executable)
@@ -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,
     );
 
index c2babc2..3399ce9 100644 (file)
@@ -1,4 +1,5 @@
 [% USE Koha %]
+[% USE Branches %]
 <div class="gradient">
 <h1 id="logo"><a href="/cgi-bin/koha/mainpage.pl">[% LibraryName %]</a></h1><!-- Begin Fund Admin Resident Search Box -->
 
             <label for="filter_budgetbranch">Library: </label>
             <select name="filter_budgetbranch" id="filter_budgetbranch" style="width:10em;">
                 <option value=""></option>
-                    [% FOREACH branchloo IN branchloop %]
-                        [% IF ( branchloo.selected ) %]
-                        <option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>
+                    [% FOREACH branchloo IN Branches.all( selected => selected_branchcode ) %]
+                        [% IF branchloo.selected %]
+                        <option value="[% branchloo.branchcode %]" selected="selected">[% branchloo.branchname %]</option>
                         [% ELSE %]
-                        <option value="[% branchloo.value %]" >[% branchloo.branchname %]</option>
+                        <option value="[% branchloo.branchcode %]" >[% branchloo.branchname %]</option>
                         [% END %]
                     [% END %]
             </select>
index f72425d..078a6c3 100644 (file)
@@ -43,6 +43,7 @@
 <script type="text/javascript" src="[% interface %]/[% theme %]/js/staff-global.js"></script>
 
 [% INCLUDE 'validator-strings.inc' %]
+[% PROCESS 'html_helpers.inc' %]
 [% IF ( IntranetUserJS ) %]
     <script type="text/javascript">
     //<![CDATA[
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc
new file mode 100644 (file)
index 0000000..82714d0
--- /dev/null
@@ -0,0 +1,9 @@
+[% BLOCK options_for_libraries %]
+    [% FOREACH l IN libraries %]
+        [% IF l.selected %]
+            <option value="[% l.branchcode | html %]" selected="selected">[% l.branchname %]</option>
+        [% ELSE %]
+            <option value="[% l.branchcode | html %]">[% l.branchname %]</option>
+        [% END%]
+    [% END %]
+[% END %]
index 100565c..d89602a 100644 (file)
@@ -202,18 +202,11 @@ function submitForm(form) {
                                                 <label for="billingplace">Billing place:</label>
                                                 <select name="billingplace" id="billingplace" style="width:13em;">
                                                     <option value="">--</option>
-                                                    [% FOREACH billingplaceloo IN billingplaceloop %]
-                                                        [% IF ( billingplaceloo.selected ) %]<option value="[% billingplaceloo.value %]" selected="selected">[% billingplaceloo.branchname %]</option>
-                                                        [% ELSE %]<option value="[% billingplaceloo.value %]">[% billingplaceloo.branchname %]</option>[% END%]
-                                                    [% END %]
+                                                    [% PROCESS options_for_libraries libraries => Branches.all( selected => billingplace ) %]
                                                 </select>
                                             [% ELSE %]
                                                 <span class="label">Billing place:</span>
-                                                [% FOREACH billingplaceloo IN billingplaceloop %]
-                                                    [% IF ( billingplaceloo.selected ) %]
-                                                        <input name="billingplace" id="billingplace" type ="hidden" value="[% billingplaceloo.value %]" />[% billingplaceloo.branchname %]
-                                                    [% END %]
-                                                [% END %]
+                                                <input name="billingplace" id="billingplace" type ="hidden" value="[% billingplace %]" />[% Branches.GetName( billingplace ) %]
                                             [% END %]
                                         </li>
                                         [% UNLESS (closedbg) %]
@@ -221,11 +214,8 @@ function submitForm(form) {
                                                 <label for="deliveryplace">Delivery place:</label>
                                                 <select name="deliveryplace" id="deliveryplace" style="width:13em;">
                                                     <option value="">--</option>
-                                                    [% FOREACH deliveryplaceloo IN deliveryplaceloop %]
-                                                        [% IF ( deliveryplaceloo.selected ) %]<option value="[% deliveryplaceloo.value %]" selected="selected">[% deliveryplaceloo.branchname %]</option>
-                                                        [% ELSE %]<option value="[% deliveryplaceloo.value %]">[% deliveryplaceloo.branchname %]</option>[% END %]
-                                                    [% END %]
-                                                    <select>
+                                                    [% PROCESS options_for_libraries libraries => Branches.all( selected => deliveryplace ) %]
+                                                <select>
                                             </li>
                                             <li><p>or</p></li>
                                             <li>
@@ -239,11 +229,7 @@ function submitForm(form) {
                                                         <input name="freedeliveryplace" id="freedeliveryplace" type ="hidden" value="[% freedeliveryplace %]" />[% freedeliveryplace %]
                                                         <input name="deliveryplace" id="deliveryplace" type ="hidden" value="" />
                                                     [% ELSE %]
-                                                        [% FOREACH deliveryplaceloo IN deliveryplaceloop %]
-                                                            [% IF ( deliveryplaceloo.selected ) %]
-                                                                <input name="deliveryplace" id="deliveryplace" type ="hidden" value="[% deliveryplaceloo.value %]" />[% deliveryplaceloo.branchname %]
-                                                            [% END %]
-                                                        [% END %]
+                                                        <input name="deliveryplace" id="deliveryplace" type ="hidden" value="[% deliveryplace %]" />[% Branches.GetName( deliveryplace ) %]
                                                         <input name="freedeliveryplace" id="freedeliveryplace" type ="hidden" value="" />
                                                     [% END %]
                                                 </li>
index 195022a..5cc8cc7 100644 (file)
@@ -1,3 +1,4 @@
+[% USE Branches %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Acquisitions &rsaquo;
 [% IF ( add_form ) %]
                     <label for="billingplace">Billing place:</label>
                     <select name="billingplace" id="billingplace">
                         <option value="">--</option>
-                        [% FOREACH billingplace IN billingplaceloop %]
-                            [% IF ( billingplace.selected ) %]
-                                <option value="[% billingplace.value %]" selected="selected">
-                            [% ELSE %]
-                                <option value="[% billingplace.value %]">
-                            [% END %]
-                                [% billingplace.branchname %]
-                            </option>
-                        [% END %]
+                        [% PROCESS options_for_libraries libraries => Branches.all( selected => billingplace ) %]
                     </select>
                 </li>
                 <li>
                     <label for="deliveryplace">Delivery place:</label>
                     <select name="deliveryplace" id="deliveryplace">
                         <option value="">--</option>
-                        [% FOREACH deliveryplace IN deliveryplaceloop %]
-                            [% IF ( deliveryplace.selected ) %]
-                                <option value="[% deliveryplace.value %]" selected="selected">
-                            [% ELSE %]
-                                <option value="[% deliveryplace.value %]">
-                            [% END %]
-                                [% deliveryplace.branchname %]
-                            </option>
-                        [% END %]
+                        [% PROCESS options_for_libraries libraries => Branches.all( selected => deliveryplace ) %]
                     </select>
                 </li>
                 <li>
index 2719a43..4454734 100644 (file)
@@ -521,10 +521,8 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget")
     <li>
     <label for="budget_branchcode">Library: </label>
     <select name="budget_branchcode" id="budget_branchcode">
-    <option value=""></option>
-    [% FOREACH branchloop_selec IN branchloop_select %]
-        [% UNLESS ( branchloop_selec.selected ) %] <option value="[% branchloop_selec.value %]" > [% ELSE %] <option value="[% branchloop_selec.value %]" selected="selected"> [% END %] [% branchloop_selec.value %]-[% branchloop_selec.branchname %]</option>
-    [% END %]
+        <option value=""></option>
+        [% PROCESS options_for_libraries libraries => branchloop_select %]
     </select>
     </li>
 
@@ -655,11 +653,7 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget")
             <label for="filter_budgetbranch2">Library: </label>
             <select name="filter_budgetbranch" id="filter_budgetbranch2" style="width:10em;">
                 <option value=""></option>
-                [% FOREACH branchloo IN branchloop %]
-                [% UNLESS ( branchloo.selected ) %]<option value="[% branchloo.value %]">
-                [% ELSE %]<option value="[% branchloo.value %]" selected="selected">[% END %]
-                [% branchloo.branchname %]</option>
-                [% END %]
+                [% PROCESS options_for_libraries libraries => branchloop_select %]
             </select>
         </li>
         <li class="radio">
index 310d81f..8828425 100644 (file)
     [% ELSE %]
 
     <p class="help">Use carefully! If the destination library already has circulation and fine rules, they will be deleted without warning!</p>
-       <form action="/cgi-bin/koha/admin/clone-rules.pl" method="post">
-           [% UNLESS ( frombranch ) %]
-           <fieldset>
-               <legend>Please choose a library to clone rules from:</legend> 
-               <label for="frombranch">Source library:</label>
-               <select name="frombranch" id="frombranch">
-                       <option value="">Default</option>
-                       [% FOREACH branchloo IN branchloop %]
-                               [% IF ( branchloo.selected ) %]
-                                       <option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>
-                               [% ELSE %]
-                                       <option value="[% branchloo.value %]">[% branchloo.branchname %]</option>
-                               [% END %]
-                       [% END %]
-               </select>
-               [% IF ( tobranch ) %]<input type="hidden" name="tobranch" value="[% tobranch %]" />[% END %]
-           </fieldset>
-           [% END %]
+    <form action="/cgi-bin/koha/admin/clone-rules.pl" method="post">
+        [% UNLESS ( frombranch ) %]
+            <fieldset>
+                <legend>Please choose a library to clone rules from:</legend>
+                <label for="frombranch">Source library:</label>
+                <select name="frombranch" id="frombranch">
+                    <option value="">Default</option>
+                    [% PROCESS options_for_libraries libraries => Branches.all() %]
+                </select>
+                [% IF ( tobranch ) %]<input type="hidden" name="tobranch" value="[% tobranch %]" />[% END %]
+            </fieldset>
+        [% END %]
 
-           [% UNLESS ( tobranch ) %]
-           <fieldset>
-               <legend>Please choose the library to clone the rules to:</legend> 
-               <label for="tobranch">Destination library:</label>
-               <select name="tobranch" id="tobranch">
-                       <option value="">Default</option>
-                       [% FOREACH branchloo IN branchloop %]
-                               [% IF ( branchloo.selected ) %]
-                                       <option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>
-                               [% ELSE %]
-                                       <option value="[% branchloo.value %]">[% branchloo.branchname %]</option>
-                               [% END %]
-                       [% END %]
-               </select>
-               [% IF ( frombranch ) %]<input type="hidden" name="frombranch" value="[% frombranch %]" />[% END %]
-           </fieldset>
-       [% END %]
-       <input type="submit" value="Submit" />
-    <a href="/cgi-bin/koha/admin/smart-rules.pl" class="cancel">Cancel</a>
-       </form>
+        [% UNLESS ( tobranch ) %]
+            <fieldset>
+            <legend>Please choose the library to clone the rules to:</legend>
+            <label for="tobranch">Destination library:</label>
+            <select name="tobranch" id="tobranch">
+                <option value="">Default</option>
+                [% PROCESS options_for_libraries libraries => Branches.all() %]
+            </select>
+            [% IF ( frombranch ) %]<input type="hidden" name="frombranch" value="[% frombranch %]" />[% END %]
+            </fieldset>
+        [% END %]
+        <input type="submit" value="Submit" />
+    </form>
 
     [% END %]
     </div>
index 18fe7ea..13b5cb1 100644 (file)
@@ -1,3 +1,4 @@
+[% USE Branches %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Administration &rsaquo; Circulation and fine rules</title>
 [% INCLUDE 'doc-head-close.inc' %]
@@ -117,8 +118,8 @@ $(document).ready(function() {
     <div id="yui-main">
     <div class="yui-b">
     <h1 class="parameters">
-        [% IF ( humanbranch ) %]
-            Defining circulation and fine rules for "[% humanbranch %]"
+        [% IF humanbranch %]
+            Defining circulation and fine rules for "[% Branches.GetName( humanbranch ) %]"
         [% ELSE %]
             Defining circulation and fine rules for all libraries
         [% END %]
@@ -142,14 +143,21 @@ $(document).ready(function() {
         Select a library :
             <select name="branch" id="branch" style="width:20em;">
                 <option value="*">All libraries</option>
-            [% FOREACH branchloo IN branchloop %]
-                               [% IF ( branchloo.selected ) %]<option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>[% ELSE %]<option value="[% branchloo.value %]">[% branchloo.branchname %]</option>[% END %]
-            [% END %]
+                [% PROCESS options_for_libraries libraries => Branches.all( selected => current_branch ) %]
             </select>
         </form>
-[% IF ( definedbranch ) %]<form action="/cgi-bin/koha/admin/clone-rules.pl" method="post"><label 
-for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidden" name="frombranch" value="[% current_branch %]" />
-            <select name="tobranch" id="tobranch">[% FOREACH branchloo IN branchloop %]<option value="[% branchloo.value %]">[% branchloo.branchname %]</option>[% END %]</select> <input type="submit" value="Clone" /></form>[% END %]
+        [% IF ( definedbranch ) %]
+            <form action="/cgi-bin/koha/admin/clone-rules.pl" method="post">
+                <label for="tobranch"><strong>Clone these rules to:</strong></label>
+                <input type="hidden" name="frombranch" value="[% current_branch %]" />
+                <select name="tobranch" id="tobranch">
+                    [% FOREACH l IN Branches.all() %]
+                        <option value="[% l.value %]">[% l.branchname %]</option>
+                    [% END %]
+                </select>
+                <input type="submit" value="Clone" />
+            </form>
+        [% END %]
 
         <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
             <input type="hidden" name="op" value="add" />
@@ -387,7 +395,7 @@ for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde
         </form>
     </div>
     <div id="defaults-for-this-library" class="container">
-    <h3>Default checkout, hold and return policy[% IF ( humanbranch ) %] for [% humanbranch %][% END %]</h3>
+    <h3>Default checkout, hold and return policy[% IF humanbranch %] for [% Branches.GetName( humanbranch ) %][% END %]</h3>
         <p>You can set a default maximum number of checkouts, hold policy and return policy that will be used if none is defined below for a particular item type or category.</p>
         <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
             <input type="hidden" name="op" value="set-branch-defaults" />
@@ -499,7 +507,7 @@ for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde
     </div>
     [% IF ( show_branch_cat_rule_form ) %]
     <div id="holds-policy-by-patron-category" class="container">
-    <h3>[% IF humanbranch %]Checkout limit by patron category for [% humanbranch %][% ELSE %]Default checkout limit by patron category[% END %]</h3>
+    <h3>[% IF humanbranch %]Checkout limit by patron category for [% Branches.GetName( humanbranch ) %][% ELSE %]Default checkout limit by patron category[% END %]</h3>
         <p>For this library, you can specify the maximum number of loans that
             a patron of a given category can make, regardless of the item type.
         </p>
@@ -643,7 +651,7 @@ for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde
     </div>
 
     <div id="holds-policy-by-item-type" class="container">
-    <h3>[% IF humanbranch %]Holds policy by item type for [% humanbranch %][% ELSE %]Default holds policy by item type[% END %]</h3>
+    <h3>[% IF humanbranch %]Holds policy by item type for [% Branches.GetName( humanbranch ) %][% ELSE %]Default holds policy by item type[% END %]</h3>
         <p>
             For this library, you can edit rules for given itemtypes, regardless
             of the patron's category.
index dfdf64c..87a1c15 100644 (file)
@@ -1,3 +1,4 @@
+[% USE Branches %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Administration &rsaquo; Transport cost matrix</title>
 [% INCLUDE 'doc-head-close.inc' %]
@@ -100,8 +101,8 @@ $(document).ready(function(){
                 <table>
                     <tr>
                         <th>From \ To</th>
-                        [% FOR b IN branchloop %]
-                        <th>[% b.name %]</th>
+                        [% FOR b IN Branches.all() %]
+                        <th>[% b.branchname %]</th>
                         [% END %]
                     </tr>
                 [% FOR bf IN branchfromloop %]
index 411c563..a5c419a 100644 (file)
@@ -57,8 +57,8 @@
 <p><label for="branch">Library:</label>
     <select name="branch" id="branch" class="input" tabindex="3">
     <option value="">My library</option>
-    [% FOREACH branchloo IN branchloop %]
-    <option value="[% branchloo.branchcode %]">[% branchloo.branchname %]</option>
+    [% FOREACH l IN Branches.all() %]
+        <option value="[% l.branchcode %]">[% l.branchname %]</option>
     [% END %]
     </select>
     </p>[% END %]
index 0496c4f..987d4c9 100644 (file)
 <fieldset id="select-libs">
         <p><label for="branchloop">Individual libraries:</label><select name="limit" id="branchloop" onchange='if(this.value != ""){document.getElementById("categoryloop").disabled=true;} else {document.getElementById("categoryloop").disabled=false;}'>
         <option value="">All libraries</option>
-        [% FOREACH branchloo IN branchloop %]
-        [% IF ( branchloo.selected ) %]
-        <option value="branch:[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>
-        [% ELSE %]
-        <option value="branch:[% branchloo.value %]">[% branchloo.branchname %]</option>
-        [% END %]
-        [% END %]
+        [% PROCESS options_for_libraries libraries => Branches.all() %]
         </select></p>
     <!-- <input type="hidden" name="limit" value="branch: MAIN" /> -->
         [% IF ( searchdomainloop ) %]
index be52899..60b3f52 100644 (file)
@@ -38,16 +38,16 @@ $(document).ready(function(){
         <th>No. of times checked out</th>
         <th>Last seen</th>
     </tr>
-    [% FOREACH branchloo IN branchloop %]
-    [% IF ( branchloo.selected ) %]
+    [% FOREACH library IN libraries %]
+    [% IF library.selected %]
         <tr class="mybranch">
     [% ELSE %]
         <tr>
     [% END %]
-            <td>[% branchloo.branchname %]</td>
-            <td>[% branchloo.issues %]</td>
-            <td>[% IF ( branchloo.seen ) %]
-                    [% branchloo.seen | $KohaDates with_hours => 1 %]
+            <td>[% library.branchname %]</td>
+            <td>[% library.issues %]</td>
+            <td>[% IF library.seen %]
+                    [% library.seen | $KohaDates with_hours => 1 %]
                 [% ELSE %]
                     <span>Never</span>
                 [% END %]
index 7f0ac14..c7a365c 100644 (file)
@@ -1,4 +1,5 @@
 [% USE Koha %]
+[% USE Branches %]
 [% USE ItemTypes %]
 [% USE AuthorisedValues %]
 [% INCLUDE 'doc-head-open.inc' %]
                        <li>
                 <label for="tobranchcd">Destination library: </label>
                     <select name="tobranchcd" id="tobranchcd">
-                        [% FOREACH branchoptionloo IN branchoptionloop %]
-                                               [% IF ( branchoptionloo.selected ) %]
-                            <option value="[% branchoptionloo.value %]" selected="selected">
-                                               [% ELSE %]
-                            <option value="[% branchoptionloo.value %]">
-                                               [% END %]
-                                [% branchoptionloo.branchname %]
-                            </option>
-                        [% END %]
+                        [% PROCESS options_for_libraries libraries => Branches.all( selected => tobranchcd ) %]
                     </select>
             </li>
             <li>
index 64eb871..6c3ee80 100644 (file)
         <label>Item home library:</label>
         <select name="homebranch" id="homebranch">
             <option value="">Any</option>
-            [% FOREACH homebranchloo IN homebranchloop %][% IF ( homebranchloo.selected ) %]
-            <option value="[% homebranchloo.value |html %]" selected="selected">[% homebranchloo.branchname %]</option>[% ELSE %]
-            <option value="[% homebranchloo.value |html %]">[% homebranchloo.branchname %]</option>[% END %]
-            [% END %]
+            [% PROCESS options_for_libraries libraries => Branches.all( selected => homebranchfilter ) %]
         </select>
     </li>
 
     <li>
         <label>Item holding library:</label>
-            <select name="holdingbranch" id="holdingbranch">
+        <select name="holdingbranch" id="holdingbranch">
             <option value="">Any</option>
-            [% FOREACH holdingbranchloo IN holdingbranchloop %][% IF ( holdingbranchloo.selected ) %]
-            <option value="[% holdingbranchloo.value |html %]" selected="selected">[% holdingbranchloo.branchname %]</option>[% ELSE %]
-            <option value="[% holdingbranchloo.value |html %]">[% holdingbranchloo.branchname %]</option>[% END %]
-            [% END %]
+            [% PROCESS options_for_libraries libraries => Branches.all( selected => holdingbranchfilter ) %]
         </select>
     </li>
 
     <li>
-    <label>Library of the patron:</label><select name="branch" id="branch">
-        <option value="">Any</option>
-      [% FOREACH branchloo IN branchloop %]
-        [% IF ( branchloo.selected ) %]
-        <option value="[% branchloo.value |html %]" selected="selected">[% branchloo.branchname %]</option>[% ELSE %]
-        <option value="[% branchloo.value |html %]">[% branchloo.branchname %]</option>[% END %]
-      [% END %]
-      </select>
+        <label>Library of the patron:</label>
+        <select name="branch" id="branch">
+            <option value="">Any</option>
+            [% PROCESS options_for_libraries libraries => Branches.all( selected => branchfilter ) %]
+        </select>
     </li>
 
     <li><label for="order">Sort by:</label> <select name="order" id="order">
index faaa963..4b3933d 100644 (file)
@@ -1,3 +1,4 @@
+[% USE Branches %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Circulation &rsaquo; Set library</title>
 [% INCLUDE 'doc-head-close.inc' %]
@@ -54,13 +55,7 @@ Updated:<ul>
     [% ELSE %]
         <li><label for="branch">Choose library:</label>
         <select name="branch" id="branch">
-        [% FOREACH branchloo IN branchloop %]
-            [% IF ( branchloo.selected ) %]
-            <option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>
-            [% ELSE %]
-            <option value="[% branchloo.value %]">[% branchloo.branchname %]</option>
-            [% END %]
-        [% END %]
+            [% PROCESS options_for_libraries libraries => Branches.all( selected => branch ) %]
         </select></li>
     [% END %]
 <!--
index 541ddbd..67f3fc4 100644 (file)
@@ -192,15 +192,13 @@ $(document).ready(function() {
 <form name="f" action="/cgi-bin/koha/circ/view_holdsqueue.pl" method="post">
        <fieldset class="rows">
        <ol>
-       <li><label for="branchlimit">Library: </label><select name="branchlimit" id="branchlimit">
+        <li>
+            <label for="branchlimit">Library: </label>
+            <select name="branchlimit" id="branchlimit">
                 <option value="">All</option>
-            [% FOREACH branchloo IN branchloop %]
-                [% IF ( branchloo.selected ) %]<option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>
-                               [% ELSE %]
-                               <option value="[% branchloo.value %]">[% branchloo.branchname %]</option>
-                               [% END %]
-            [% END %]
-            </select></li>
+                [% PROCESS options_for_libraries libraries => Branches.all() %]
+            </select>
+        </li>
                        <!-- FIXME Not working yet
                        <li><label for="itemtypeslimit">Item Type: </label><select name="itemtypeslimit" id="itemtypeslimit">
                 <option value="">All</option>
index c1c284c..3286640 100644 (file)
@@ -1,3 +1,4 @@
+[% USE Branches %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Course reserves &rsaquo; Add items</title>
 [% INCLUDE 'doc-head-close.inc' %]
                         <label class="required" for="holdingbranch">Holding library:</label>
                         <select id="holdingbranch" name="holdingbranch">
                             <option value="">LEAVE UNCHANGED</option>
-
-                            [% FOREACH b IN branches %]
+                            [% FOREACH b IN Branches.all() %]
                                 [% IF course_item.holdingbranch && ( ( course.enabled == 'yes' && b.value == item.holdingbranch ) || ( course.enabled == 'no' && b.value == course_item.holdingbranch ) ) %]
-                                    <option value="[% b.value %]" selected="selected">[% b.branchname %]</option>
+                                    <option value="[% b.branchcode %]" selected="selected">[% b.branchname %]</option>
                                 [% ELSE %]
-                                    <option value="[% b.value %]">[% b.branchname %]</option>
+                                    <option value="[% b.branchcode %]">[% b.branchname %]</option>
                                 [% END %]
                             [% END %]
                         </select>
index 0ee110b..09e9f9d 100644 (file)
@@ -506,13 +506,7 @@ function filterByFirstLetterSurname(letter) {
                 [% IF branches.size != 1 %]
                   <option value="">Any</option>
                 [% END %]
-                [% FOREACH b IN branches %]
-                  [% IF b.selected %]
-                    <option selected="selected" value="[% b.branchcode %]">[% b.branchname %]</option>
-                  [% ELSE %]
-                    <option value="[% b.branchcode %]">[% b.branchname %]</option>
-                  [% END %]
-                [% END %]
+                [% PROCESS options_for_libraries libraries => branches %]
               </select>
             </li>
           </ol>
index ad74964..82418ff 100644 (file)
@@ -1,5 +1,6 @@
 [% USE Koha %]
 [% USE KohaDates %]
+[% USE Branches %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Patrons &rsaquo; [% IF ( opadd ) %]Add[% ELSIF ( opduplicate ) %]Duplicate[% ELSE %] Modify[% END %] patron [% IF (firstname) %][% firstname %] [% END %][% IF (surname) %][% surname %] [% END %]([%IF ( categoryname ) %][% categoryname %][% ELSE %][% IF ( I ) %]Organization[% END %][% IF ( A ) %]Adult[% END %][% IF ( C ) %]Child[% END %][% IF ( P ) %]Professional[% END %][% IF ( S ) %]Staff[% END %][% END %])</title>
 [% INCLUDE 'doc-head-close.inc' %]
@@ -628,15 +629,9 @@ $(document).ready(function() {
     <li>
         <label for="libraries" class="required">Library:</label>
         <select name="branchcode" size="1" id="libraries">
-        [%- FOREACH branchloo IN branchloop %]
-          [% IF ( branchloo.selected ) -%]
-            <option value="[% branchloo.branchcode %]" selected="selected">[% branchloo.branchname %]</option>
-          [%- ELSE -%]
-            <option value="[% branchloo.branchcode %]">[% branchloo.branchname %]</option>
-          [%- END -%]
-        [%- END %]
-      </select>
-      <span class="required">Required</span>
+            [% PROCESS options_for_libraries libraries => Branches.all( selected => userbranch ) %]
+        </select>
+        <span class="required">Required</span>
     </li>
         [% END %]
     <li>
index 88cdeb0..30f7287 100644 (file)
@@ -141,8 +141,8 @@ function Dopop(link) {
                        <li> 
                                <label for="branch">Library: </label>
 <select name="Filter" id="branch"><option value="" > Any library</option>
-    [% FOREACH branchloo IN branchloop %]
-        <option value="[% branchloo.value %]" >[% branchloo.branchname %] </option>  
+    [% FOREACH l IN Branches.all( unfiltered => 1 ) %]
+        <option value="[% l.branchcode %]" >[% l.branchname %] </option>
      [% END %] 
     </select>                  </li>
                        <li> 
index 10882da..2c14305 100644 (file)
@@ -1,3 +1,4 @@
+[% USE Branches %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Reports [% IF ( do_it ) %]&rsaquo; Patrons statistics &rsaquo; Results[% ELSE %]&rsaquo; Patrons statistics[% END %]</title>
 [% INCLUDE 'doc-head-close.inc' %]
                        <td><input type="radio" name="Line"   value="branchcode" /></td>
                        <td><input type="radio" name="Column" value="branchcode" /></td>
                        <td>
-                               <select name="Filter"  size="1" id="branch">
-                               <option value=""></option>
-                               [% FOREACH BRANCH_LOO IN BRANCH_LOOP %]
-                                       <option value="[% BRANCH_LOO.branchcode %]">[% BRANCH_LOO.branchcode %] - [% BRANCH_LOO.branchname %]</option>
-                               [% END %]
-                               </select>
+                <select name="Filter"  size="1" id="branch">
+                <option value=""></option>
+                [% FOREACH l IN Branches.all() %]
+                    <option value="[% l.branchcode %]">[% l.branchcode %] - [% l.branchname || 'UNKNOWN' %]</option>
+                [% END %]
+                </select>
                        </td>
                        </tr>
                    <tr>
index 0d1fb5f..d6d77b5 100644 (file)
@@ -1,3 +1,4 @@
+[% USE Branches %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Reports &rsaquo; Most-circulated items[% IF ( do_it ) %] &rsaquo; Results[% END %]</title>
 [% INCLUDE 'doc-head-close.inc' %]
         <li><label for="fromRO">Check-in date from</label> <input type="text" size="10" id="fromRO" name="Filter" />
         <label for="toRO" class="inline">To: </label> <input type="text" size="10" id="toRO" name="Filter" value="" />
                     <span class="hint">[% INCLUDE 'date-format.inc' %]</span></li>
-                               <li><label for="branch">Library: </label>
-<select name="Filter" id="branch"><option value="" > Any library</option>
-    [% FOREACH branchloo IN branchloop %]
-        <option value="[% branchloo.value %]" >[% branchloo.branchname %] </option>  
-     [% END %] 
-    </select>     </li>
+        <li>
+            <label for="branch">Library: </label>
+            <select name="Filter" id="branch"><option value="" > Any library</option>
+                [% PROCESS options_for_libraries libraries => Branches.all() %]
+            </select>
+        </li>
       <li> 
         <label for="documenttype">Item type: </label><select name="Filter" id="documenttype"><option value="" > Any item type</option>
     [% FOREACH itemtypeloo IN itemtypeloop %]
index 76517f3..7a83df5 100644 (file)
                        <li><label for="branch">Library: </label>
        <select name="Filter" id="branch">
         <option value="">Any library</option>
-    [% FOREACH branchloo IN branchloop %]
-      [% IF ( branchloo.selected ) %]
-        <option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>
-      [% ELSE %]
-        <option value="[% branchloo.value %]">[% branchloo.branchname %]</option>
-      [% END %]
-    [% END %]
+        [% PROCESS options_for_libraries libraries => Branches.all() %]
     </select></li>
       <li> 
         <label for="documenttype">Item type: </label><select name="Filter" id="documenttype">
index 7e04361..c1f4aab 100644 (file)
@@ -1,3 +1,4 @@
+[% USE Branches %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Reports [% IF ( do_it ) %]&rsaquo; Catalog statistics &rsaquo; Results[% ELSE %]&rsaquo; Catalog statistics[% END %]</title>
 [% INCLUDE 'doc-head-close.inc' %]
                                <td><input type="radio" name="Line" value="items.homebranch" /></td>
                                <td><input type="radio" name="Column" value="items.homebranch" /></td>
                                <td><select name="Filter" id="branch">
-                                       <option value=""> </option>
-                                       [% FOREACH CGIBranc IN CGIBranch %]
-                                       [% IF ( CGIBranc.selected ) %]<option value="[% CGIBranc.value %]" selected="selected">[% CGIBranc.branchname %]</option>[% ELSE %]<option value="[% CGIBranc.value %]">[% CGIBranc.branchname %]</option>[% END %]
-                                       [% END %]
-                                       </select>
+                    <option value=""> </option>
+                    [% PROCESS options_for_libraries libraries => Branches.all() %]
+                    </select>
                                </td>
                        </tr>
                        <tr>
index 7b38c76..7288508 100644 (file)
@@ -1,3 +1,4 @@
+[% USE Branches %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Reports &rsaquo; Average checkout period</title>
 [% INCLUDE 'doc-head-close.inc' %]
                 <td>
                     <select name="Filter" size="1" id="branch">
                         <option value=""></option>
-                        [%- FOREACH branchloo IN branchloop %]
-                        <option value="[% branchloo.value %]">[% branchloo.branchname %]</option>
-                        [%- END %]
+                        [% PROCESS options_for_libraries libraries => Branches.all() %]
                     </select>
                 </td>
                        </tr>
index a07077f..6fcd0d1 100644 (file)
@@ -1,3 +1,4 @@
+[% USE Branches %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Reports &rsaquo; Checkouts by patron category</title>
 [% INCLUDE 'doc-head-close.inc' %]
@@ -68,8 +69,8 @@
                 <label for="branch">Select a library:</label>
                 <select name="value" size="1" id="branch">
                   <option value=""></option>
-                [%- FOREACH branchloo IN branchloop %]
-                  <option value="[% branchloo.branchcode %]">[% branchloo.branchname %]</option>
+                [%- FOREACH l IN Branches.all() %]
+                  <option value="[% l.branchcode %]">[% l.branchname %]</option>
                 [%- END %]
                </select>
               </li>
index 1bc8c23..aa227fa 100644 (file)
@@ -1,3 +1,4 @@
+[% USE Branches %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Reports &rsaquo; Circulation statistics [% IF ( do_it ) %]&rsaquo; Results[% END %]</title>
 [% INCLUDE 'doc-head-close.inc' %]
             <td><input type="radio" name="Line" value="branch" /></td>
             <td><input type="radio" name="Column" value="branch" /></td>
             <td><select name="Filter" id="branch">
-               <option value=""> </option>
-               [% FOREACH branchloo IN branchloop %]
-[% IF ( branchloo.selected ) %]<option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>[% ELSE %]<option value="[% branchloo.value %]">[% branchloo.branchname %]</option>[% END %]
-                               [% END %]
+                <option value=""> </option>
+                [% PROCESS options_for_libraries libraries => Branches.all() %]
                </select>
              </td> 
         </tr>
             <td><input type="radio" name="Column" value="items.homebranch" /></td>
             <td><select name="Filter" id="homebranch">
                     <option value=""> </option>
-                    [% FOREACH branchloo IN branchloop %]
-                        [% IF ( branchloo.selected ) %]<option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>[% ELSE %]<option value="[% branchloo.value %]">[% branchloo.branchname %]</option>[% END %]
-                                   [% END %]
+                    [% PROCESS options_for_libraries libraries => Branches.all() %]
                 </select>
             </td>
         </tr>
             <td><input type="radio" name="Column" value="items.holdingbranch" /></td>
             <td><select name="Filter" id="holdingbranch">
                     <option value=""> </option>
-                    [% FOREACH branchloo IN branchloop %]
-                        [% IF ( branchloo.selected ) %]<option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>[% ELSE %]<option value="[% branchloo.value %]">[% branchloo.branchname %]</option>[% END %]
-                                   [% END %]
+                    [% PROCESS options_for_libraries libraries => Branches.all() %]
                 </select>
             </td>
         </tr>
index 29f65d0..c6f9661 100644 (file)
        <li><label for="barcodefilter">Barcode: </label><input type="text" name="barcodefilter" id="barcodefilter" size="6" /></li>
        <li><label for="branchfilter">Library: </label><select name="branchfilter" id="branchfilter">
                 <option value="">All</option>
-            [% FOREACH branchloo IN branchloop %]
-                [% IF ( branchloo.selected ) %]<option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>
-                               [% ELSE %]
-                               <option value="[% branchloo.value %]">[% branchloo.branchname %]</option>
-                               [% END %]
-            [% END %]
+                [% PROCESS options_for_libraries libraries => Branches.all() %]
             </select></li>
     <li><label for="itemtypesfilter">Item type: </label><select name="itemtypesfilter" id="itemtypesfilter">
                 <option value="">All</option>
index 9156006..1bfd416 100644 (file)
@@ -65,13 +65,7 @@ $(document).ready(function(){
                 <label for="value">Select a library:</label>
                 <select name="value" size="1" id="value">
                   <option value=""></option>
-                [%- FOREACH branchloo IN branchloop %]
-                 [% IF ( branchloo.selected ) -%]
-                  <option value="[% branchloo.branchcode %]" selected="selected">[% branchloo.branchname %]</option>
-                 [%- ELSE -%]
-                  <option value="[% branchloo.branchcode %]">[% branchloo.branchname %]</option>
-                 [%- END -%]
-                [%- END %]
+                  [% PROCESS options_for_libraries libraries => Branches.all() %]
                 </select>
                 <span class="tip">Select none to see all libraries</span>
               </li>
index 8ef7b22..8e35d43 100644 (file)
@@ -1,3 +1,4 @@
+[% USE Branches %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Reports &rsaquo; Holds statistics [% IF ( do_it ) %]&rsaquo; Results[% END %]</title>
 [% INCLUDE 'doc-head-close.inc' %]
             <td><input type="radio" name="Column" value="reserves.branchcode" /></td>
             <td><select name="filter_reserves.branchcode" id="resbranchcode">
                <option value=""> </option>
-               [% FOREACH branchloo IN branchloop %]
-[% IF ( branchloo.selected ) %]<option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>[% ELSE %]<option value="[% branchloo.value %]">[% branchloo.branchname %]</option>[% END %]
-                               [% END %]
+                [% PROCESS options_for_libraries libraries => Branches.all() %]
                </select>
              </td> 
         </tr>
             <td><input type="radio" name="Column" value="items.holdingbranch" /></td>
             <td><select name="filter_items.holdingbranch" id="holdingbranch">
                <option value=""> </option>
-               [% FOREACH branchloo IN branchloop %]
-[% IF ( branchloo.selected ) %]<option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>[% ELSE %]<option value="[% branchloo.value %]">[% branchloo.branchname %]</option>[% END %]
-                               [% END %]
+                [% PROCESS options_for_libraries libraries => Branches.all() %]
                </select>
              </td> 
         </tr>
             <td><input type="radio" name="Line" value="items.homebranch" /></td>
             <td><input type="radio" name="Column" value="items.homebranch" /></td>
             <td><select name="filter_items.homebranch" id="homebranch">
-               <option value=""> </option>
-               [% FOREACH branchloo IN branchloop %]
-[% IF ( branchloo.selected ) %]<option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>[% ELSE %]<option value="[% branchloo.value %]">[% branchloo.branchname %]</option>[% END %]
-                               [% END %]
+                <option value=""> </option>
+                [% PROCESS options_for_libraries libraries => Branches.all() %]
                </select>
              </td> 
         </tr>
index 1476b14..3b9ac4c 100644 (file)
                        </label>
                        <select name="branchcode"  id="branchcode">
                                <option value="">Any library</option>
-                    [% FOREACH branche IN branches %]
-                        [% IF ( branche.selected ) %]
-                            <option value="[% branche.value %]" selected="selected">[% branche.branchname %]</option>
-                        [% ELSE %]
-                            <option value="[% branche.value %]">[% branche.branchname %]</option>
-                        [% END %]
-                                       [% END %]
+                [% PROCESS options_for_libraries libraries => Branches.all() %]
                        </select>
 
                    </li>
index 633de39..f051141 100644 (file)
@@ -374,13 +374,7 @@ function checkMultiHold() {
         <li>
             <label for="pickup">Pickup at:</label>
             <select name="pickup" size="1" id="pickup">
-            [%- FOREACH branchloo IN branchloop %]
-              [% IF ( branchloo.selected ) -%]
-                <option value="[% branchloo.branchcode %]" selected="selected">[% branchloo.branchname %]</option>
-              [%- ELSE -%]
-                <option value="[% branchloo.branchcode %]">[% branchloo.branchname %]</option>
-              [%- END -%]
-            [%- END %]
+                [% PROCESS options_for_libraries libraries => Branches.all() %]
             </select>
         </li>
 
@@ -810,17 +804,9 @@ function checkMultiHold() {
             Item being transferred to <b> [% reserveloo.wbrname %]</b> <input type="hidden" name="pickup" value="[% reserveloo.wbrcode %]" />
          [% END %]
     [% ELSE %]
-          <select name="pickup">
-      [% FOREACH branchloo IN reserveloo.branchloop %]
-        [% IF ( branchloo.selected ) %]
-            <option value="[% branchloo.branchcode %]" selected="selected">
-        [% ELSE %]
-            <option value="[% branchloo.branchcode %]">
-        [% END %]
-              [% branchloo.branchname %]
-            </option>
-      [% END %]
-          </select>
+        <select name="pickup">
+            [% PROCESS options_for_libraries libraries => Branches.all( selected => reserveloo.branchcode ) %]
+        </select>
     [% END %]
         </td>
         <td>
index 5e573ff..45e3704 100644 (file)
@@ -1,3 +1,4 @@
+[% USE Branches %]
 [% USE KohaDates %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Serials &rsaquo; Check expiration</title>
 
         <li><label for="issn">ISSN:</label>
         <input id="issn" type="text" name="issn" size="15" value="[% issn | html %]" /></li>
-        [% IF (branches_loop.size) %]
+        [% IF can_change_library %]
         <li><label for="branch">Library:</label>
         <select id="branch" name="branch">
             <option value="">All</option>
-            [% FOREACH branch IN branches_loop %]
-                [% IF branch.selected %]
-                    <option selected="selected" value="[% branch.branchcode %]">
-                [% ELSE %]
-                    <option value="[% branch.branchcode %]">
-                [% END %]
-                    [% branch.branchname %]
-                </option>
-            [% END %]
+            [% PROCESS options_for_libraries libraries => Branches.all( selected => branch ) %]
         </select>
         </li>
         [% END %]
@@ -96,7 +89,7 @@
         <tr>
             <th>ISSN</th>
             <th>Title</th>
-            [% IF ( branches_loop.size ) %]<th>Library</th>[% END %]
+            [% IF can_change_library %]<th>Library</th>[% END %]
             <th>OPAC note</th>
             <th>Nonpublic note</th>
             <th>Expiration date</th>
                 [% END %]
                 </a>
             </td>
-            [% IF ( branches_loop.size ) %]<td>
+            [% IF can_change_library %]<td>
                 [% Branches.GetName( subscriptions_loo.branchcode ) %]
             </td>[% END %]
             <td>
index 4c9aa92..6061d99 100644 (file)
@@ -239,13 +239,7 @@ td.repeatableyearly a.ui-state-default {  background:  #FFCC66 none; color :  Bl
     <div class="yui-u first">
         <label for="branch">Define the holidays for:</label>
             <select id="branch" name="branch">
-                [% FOREACH branchloo IN branchloop %]
-                    [% IF ( branchloo.selected ) %]
-                        <option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>
-                    [% ELSE %]
-                        <option value="[% branchloo.value %]">[% branchloo.branchname %]</option>
-                    [% END %]
-                [% END %]
+                [% PROCESS options_for_libraries libraries => Branches.all( selected => branch ) %]
             </select>
     
     <!-- ******************************** FLAT PANELS ******************************************* -->
@@ -410,8 +404,8 @@ td.repeatableyearly a.ui-state-default {  background:  #FFCC66 none; color :  Bl
   <label for="branchcode">Copy holidays to:</label>
   <select id="branchcode" name="branchcode">
     <option value=""></option>
-    [% FOREACH branchloo IN branchloop %]
-    <option value="[% branchloo.value %]">[% branchloo.branchname %]</option>
+    [% FOREACH l IN Branches.all() %]
+    <option value="[% l.branchcode %]">[% l.branchname %]</option>
     [% END %]
   </select>
     <input type="submit" value="Copy" />
index 4e708c5..ea3a3c9 100644 (file)
@@ -1,4 +1,5 @@
 [% USE Koha %]
+[% USE Branches %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Tools &rsaquo; Import patrons [% IF ( uploadborrowers ) %]&rsaquo; Results[% END %]</title>
 [% INCLUDE 'doc-head-close.inc' %]
         <label class="description" for="branchcode">[% borrower_field.description %]: </label>
         <select id="branchcode" name="branchcode">
             <option value="" selected="selected"></option>
-        [% FOREACH branch IN branches %]
-            <option value="[% branch.branchcode %]">
-                [% branch.branchname %]</option>
+        [% FOREACH library IN Branches.all() %]
+            <option value="[% library.branchcode %]">
+                [% library.branchname %]</option>
         [% END %]
         </select><span class="field_hint">[% borrower_field.field %]</span>
     </li>
index ef92067..7563827 100644 (file)
@@ -139,13 +139,7 @@ $(document).ready(function(){
         </li><li>
         <label for="branchloop">Library: </label><select id="branchloop" name="branchcode" style="width:12em;">
             <option value="">All libraries</option>
-        [% FOREACH branchloo IN branchloop %]
-            [% IF ( branchloo.selected ) %]
-                <option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>
-            [% ELSE %]
-                <option value="[% branchloo.value %]">[% branchloo.branchname %]</option>
-            [% END %]
-        [% END %]
+            [% PROCESS options_for_libraries libraries => Branches.all( selected => branchcode ) %]
         </select>
         </li>
         [% IF (authorised_values) %]
index 2af7a0e..3d1eb15 100644 (file)
@@ -165,9 +165,7 @@ $(document).ready(function() {
         Select a library :
             <select name="branchcode" id="branch" style="width:20em;">
                 <option value="*">All libraries</option>
-            [% FOREACH branchloo IN branchloop %]
-                [% IF ( branchloo.selected ) %]<option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>[% ELSE %]<option value="[% branchloo.value %]">[% branchloo.branchname %]</option>[% END %]
-            [% END %]
+                [% PROCESS options_for_libraries libraries => Branches.all( selected => branchcode ) %]
             </select>
       </p>
     [% END %]
@@ -183,8 +181,8 @@ $(document).ready(function() {
                [% IF ( letter && !independant_branch) %]
             [% select_for_copy = BLOCK %]
             <select name="branchcode">
-                [% FOREACH branchloo IN branchloop %]
-                <option value="[% branchloo.value %]">Copy to [% branchloo.branchname %]</option>
+                [% FOREACH l IN Branches.all() %]
+                <option value="[% l.branchcode %]">Copy to [% l.branchname %]</option>
                 [% END %]
             </select>
             [% END %]
@@ -276,9 +274,7 @@ $(document).ready(function() {
                     <label for="branch">Library:</label>
                     <select name="branchcode" id="branch" style="width:20em;">
                         <option value="">All libraries</option>
-                    [% FOREACH branchloo IN branchloop %]
-                        [% IF ( branchloo.selected ) %]<option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>[% ELSE %]<option value="[% branchloo.value %]">[% branchloo.branchname %]</option>[% END %]
-                    [% END %]
+                        [% PROCESS options_for_libraries libraries => Branches.all( selected => branchcode ) %]
                     </select>
                 [% ELSE %]
                     <span class="label">Library:</span>
index 350b5bc..c780f30 100644 (file)
@@ -44,13 +44,7 @@ $(document).ready(function() {
             <label for="branch">Select a library:</label>
                 <select id="branch" name="branch">
                     <option value="">Default</option>
-                    [% FOREACH branchloo IN branchloop %]
-                        [% IF ( branchloo.selected ) %]
-                            <option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>
-                        [% ELSE %]
-                            <option value="[% branchloo.value %]">[% branchloo.branchname %]</option>
-                        [% END %]
-                    [% END %]
+                    [% PROCESS options_for_libraries libraries => Branches.all( selected => branch ) %]
                 </select>
                 <input type="submit" value="Select" />
             </form>
index 287b0c7..b57404e 100644 (file)
@@ -55,3 +55,4 @@
 </script>
 <script type="text/javascript" src="[% interface %]/[% theme %]/lib/modernizr.min.js"></script>
 <link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/lib/font-awesome/css/font-awesome.min.css" />
+[% PROCESS 'html_helpers.inc' %]
diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/html_helpers.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/html_helpers.inc
new file mode 100644 (file)
index 0000000..1d38382
--- /dev/null
@@ -0,0 +1,9 @@
+[% BLOCK options_for_libraries %]
+    [% FOREACH l IN libraries %]
+        [% IF l.selected %]
+            <option value="[% l.branchcode %]" selected="selected">[% l.branchname %]</option>
+        [% ELSE %]
+            <option value="[% l.branchcode %]">[% l.branchname %]</option>
+        [% END%]
+    [% END %]
+[% END %]
index b2aceaa..fdce32c 100644 (file)
@@ -1,4 +1,5 @@
 [% USE Koha %]
+[% USE Branches %]
 [% SET OpacLangSelectorMode = Koha.Preference('OpacLangSelectorMode') %]
 <div id="wrap">
     <div id="header-region" class="noprint">
                                         <select name="branch_group_limit" id="select_library">
                                             <option value="">All libraries</option>
                                             [% IF BranchCategoriesLoop %]<optgroup label="Libraries">[% END %]
-                                                [% FOREACH BranchesLoo IN BranchesLoop %]
-                                                    [% IF ( BranchesLoo.selected ) %]<option selected="selected" value="branch:[% BranchesLoo.value %]">[% BranchesLoo.branchname %]</option>
-                                                    [% ELSE %]<option value="branch:[% BranchesLoo.value %]">[% BranchesLoo.branchname %]</option>[% END %]
+                                                [% FOREACH BranchesLoo IN Branches.all( selected => opac_name ) %]
+                                                    [% IF BranchesLoo.selected %]
+                                                        <option selected="selected" value="branch:[% BranchesLoo.branchcode %]">[% BranchesLoo.branchname %]</option>
+                                                    [% ELSE %]
+                                                        <option value="branch:[% BranchesLoo.branchcode %]">[% BranchesLoo.branchname %]</option>
+                                                    [% END %]
                                                 [% END %]
                                             [% IF BranchCategoriesLoop %]
                                                 </optgroup>
index 55b57a3..2b520c3 100644 (file)
@@ -1,4 +1,5 @@
 [% USE Koha %]
+[% USE Branches %]
 
 <div id="search-facets">
     <form method="get" action="/cgi-bin/koha/opac-topissues.pl">
                 <li><label for="branch">From: </label>
                             <select name="branch" id="branch">
                                 <option value="">All libraries</option>
-                                [% FOREACH branchloo IN branchloop %]
-                                    [% IF ( branchloo.selected ) %]
-                                        <option value="[% branchloo.value %]" selected="selected">
-                                    [% ELSE %]
-                                        <option value="[% branchloo.value %]">
-                                    [% END %]
-                                            [% branchloo.branchname %]
-                                        </option>
-                                [% END %]
+                                [% PROCESS options_for_libraries libraries => Branches.all( selected => branch ) %]
                             </select></li>
 
                 [% AdvancedSearchTypes = Koha.Preference('AdvancedSearchTypes').split('\|') %]
index c77742b..5b461f4 100644 (file)
@@ -1,4 +1,5 @@
 [% USE Koha %]
+[% USE Branches %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>[% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha online[% END %] catalog &rsaquo; Advanced search</title>
 [% INCLUDE 'doc-head-close.inc' %]
                                     <label for="branchloop">Library:</label>
                                     <select name="limit" id="branchloop">
                                     <option value="">All libraries</option>
-                                    [% FOREACH BranchesLoo IN BranchesLoop %]
-                                        [% IF ( BranchesLoo.selected ) %]
-                                            <option value="branch:[% BranchesLoo.value %]" selected="selected">[% BranchesLoo.branchname %]</option>
+                                    [% FOREACH BranchesLoo IN Branches.all( selected => opac_name ) %]
+                                        [% IF BranchesLoo.selected %]
+                                            <option value="branch:[% BranchesLoo.branchcode %]" selected="selected">[% BranchesLoo.branchname %]</option>
                                         [% ELSE %]
-                                            <option value="branch:[% BranchesLoo.value %]">[% BranchesLoo.branchname %]</option>
+                                            <option value="branch:[% BranchesLoo.branchcode %]">[% BranchesLoo.branchname %]</option>
                                         [% END %]
                                     [% END %]
                                     </select>
index 609ea45..e19d067 100644 (file)
@@ -1,5 +1,6 @@
 [% USE Categories %]
 [% USE Koha %]
+[% USE Branches %]
 [% USE KohaDates %]
 [% SET userupdateview = 1 %]
 
                                         Home library:</label>
 
                                         <select id="borrower_branchcode" name="borrower_branchcode">
-                                            [% FOREACH b IN branches %]
-                                                [% IF b.value == borrower.branchcode %]
-                                                    <option value="[% b.value %]" selected="selected">[% b.branchname %]</option>
-                                                [% ELSE %]
-                                                    <option value="[% b.value %]">[% b.branchname %]</option>
-                                                [% END %]
-                                            [% END %]
+                                            [% PROCESS options_for_libraries libraries => Branches.all( selected => borrower.branchcode ) %]
                                         </select>
                                     </li>
                                 [% END %]
index 8decae4..bca3bff 100644 (file)
@@ -1,4 +1,5 @@
 [% USE Koha %]
+[% USE Branches %]
 [% USE KohaDates %]
 [% USE Price %]
 [% USE ItemTypes %]
                                                                 <label for="branch_[% bibitemloo.biblionumber %]">Pick up location:</label>
                                                                 [% UNLESS ( bibitemloo.holdable ) %]
                                                                     <select name="branch" id="branch_[% bibitemloo.biblionumber %]" disabled="disabled">
-                                                                        [% FOREACH branchloo IN bibitemloo.branchloop %]
-                                                                            [% IF ( branchloo.selected ) %]
-                                                                                <option value="[% branchloo.branchcode %]" selected="selected">[% branchloo.branchname %]</option>
-                                                                            [% ELSE %]
-                                                                                <option value="[% branchloo.branchcode %]">[% branchloo.branchname %]</option>
-                                                                            [% END %]
-                                                                        [% END %]
+                                                                        [% PROCESS options_for_libraries libraries => Branches.all( selected => branch ) %]
                                                                     </select>
                                                                 [% ELSE %]
                                                                     <select name="branch" id="branch_[% bibitemloo.biblionumber %]">
-                                                                        [% FOREACH branchloo IN bibitemloo.branchloop %]
-                                                                            [% IF ( branchloo.selected ) %]
-                                                                                <option value="[% branchloo.branchcode %]" selected="selected">[% branchloo.branchname %]</option>
-                                                                            [% ELSE %]
-                                                                                <option value="[% branchloo.branchcode %]">[% branchloo.branchname %]</option>
-                                                                            [% END %]
-                                                                        [% END %]
+                                                                        [% PROCESS options_for_libraries libraries => Branches.all( selected => branch ) %]
                                                                     </select>
                                                                 [% END # / UNLESS bibitemloo.holdable %]
                                                             </li>
index 3f4234f..2645905 100644 (file)
@@ -1,4 +1,5 @@
 [% USE Koha %]
+[% USE Branches %]
 [% USE AuthorisedValues %]
 [% USE KohaDates %]
 [% INCLUDE 'doc-head-open.inc' %]
                                         <li><label for="itemtype">Item type:</label>
                                             [% PROCESS 'av-build-dropbox.inc' name="itemtype", category="SUGGEST_FORMAT", size = 20 %]
                                         </li>
-                                        [% IF ( branchloop ) %]
+                                        [% IF branchcode %]
                                             <li><label for="branch">Library:</label>
                                                 <select name="branchcode" id="branch">
-                                                    [% FOREACH branchloo IN branchloop %]
-                                                        [% IF ( branchloo.selected ) %]
-                                                            <option value="[% branchloo.branchcode %]" selected="selected">[% branchloo.branchname %]</option>
-                                                        [% ELSE %]
-                                                            <option value="[% branchloo.branchcode %]">[% branchloo.branchname %]</option>
-                                                        [% END %]
-                                                    [% END %]
+                                                    [% PROCESS options_for_libraries libraries => Branches.all( selected => branchcode ) %]
                                                 </select>
                                             </li>
                                         [% END %]
index 7d36e2f..d77e339 100755 (executable)
@@ -42,6 +42,7 @@ use C4::Form::MessagingPreferences;
 use Koha::Patron::Debarments;
 use Koha::Cities;
 use Koha::DateUtils;
+use Koha::Libraries;
 use Koha::Patron::Categories;
 use Koha::Token;
 use Email::Valid;
@@ -595,8 +596,8 @@ foreach (keys(%flags)) {
 }
 
 # get Branch Loop
-# in modify mod: userbranch value for GetBranchesLoop() comes from borrowers table
-# in add    mod: userbranch value come from branches table (ip correspondence)
+# in modify mod: userbranch value comes from borrowers table
+# in add    mod: userbranch value comes from branches table (ip correspondence)
 
 my $userbranch = '';
 if (C4::Context->userenv && C4::Context->userenv->{'branch'}) {
@@ -606,10 +607,9 @@ if (C4::Context->userenv && C4::Context->userenv->{'branch'}) {
 if (defined ($data{'branchcode'}) and ( $op eq 'modify' || $op eq 'duplicate' || ( $op eq 'add' && $category_type eq 'C' ) )) {
     $userbranch = $data{'branchcode'};
 }
+$template->param( userbranch => $userbranch );
 
-my $branchloop = GetBranchesLoop( $userbranch );
-
-if( !$branchloop ){
+if ( Koha::Libraries->search->count < 1 ){
     $no_add = 1;
     $template->param(no_branches => 1);
 }
@@ -681,7 +681,6 @@ $template->param(
   check_member    => $check_member,#to know if the borrower already exist(=>1) or not (=>0) 
   "op$op"   => 1);
 
-$template->param( branchloop => $branchloop ) if ( $branchloop );
 $template->param(
   nodouble  => $nodouble,
   borrowernumber  => $borrowernumber, #register number
index 26d91ce..5e474bb 100755 (executable)
@@ -24,7 +24,6 @@ use C4::Auth;
 use C4::Output;
 use C4::Context;
 use C4::Members;
-use C4::Branch;
 use Koha::Patron::Modifications;
 use Koha::Libraries;
 use Koha::List::Patron;
@@ -44,37 +43,10 @@ my ($template, $loggedinuser, $cookie)
                  debug => 1,
                  });
 
-my $branches = GetBranches;
-my @branchloop;
-if ( C4::Branch::onlymine ) {
-    my $userenv = C4::Context->userenv;
-    my $library = Koha::Libraries->find( $userenv->{'branch'} );
-    push @branchloop, {
-        value => $library->id,
-        branchcode => $library->branchcode,
-        branchname => $library->branchname,
-        selected => 1
-    }
-} else {
-    foreach (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %{$branches}) {
-        my $selected = 0;
-        $selected = 1 if $branch and $branch eq $_;
-        push @branchloop, {
-            value => $_,
-            branchcode => $_,
-            branchname => $branches->{$_}->{branchname},
-            selected => $selected
-        };
-    }
-}
-
 my $no_add = 0;
-if(scalar(@branchloop) < 1){
+if( Koha::Libraries->search->count < 1){
     $no_add = 1;
     $template->param(no_branches => 1);
-} 
-else {
-    $template->param(branchloop=>\@branchloop);
 }
 
 my @categories = Koha::Patron::Categories->search_limited;
index 1a5bac4..8b5ade9 100755 (executable)
@@ -29,7 +29,6 @@ use C4::Form::MessagingPreferences;
 use Koha::Patrons;
 use Koha::Patron::Modification;
 use Koha::Patron::Modifications;
-use C4::Branch qw(GetBranchesLoop);
 use C4::Scrubber;
 use Email::Valid;
 use Koha::DateUtils;
@@ -70,7 +69,6 @@ $template->param(
     action            => $action,
     hidden            => GetHiddenFields( $mandatory, 'registration' ),
     mandatory         => $mandatory,
-    branches          => GetBranchesLoop(),
     OPACPatronDetails => C4::Context->preference('OPACPatronDetails'),
 );
 
index 1fd2f82..9dd9e3d 100755 (executable)
@@ -127,9 +127,6 @@ my $branch = $query->param('branch') || $borr->{'branchcode'} || C4::Context->us
 ($branches->{$branch}) or $branch = "";     # Confirm branch is real
 $template->param( branch => $branch );
 
-# make branch selection options...
-my $branchloop = GetBranchesLoop($branch);
-
 # Is the person allowed to choose their branch
 my $OPACChooseBranch = (C4::Context->preference("OPACAllowUserToChooseBranch")) ? 1 : 0;
 
@@ -383,7 +380,7 @@ foreach my $biblioNum (@biblionumbers) {
 
     my $record = GetMarcBiblio($biblioNum);
     # Init the bib item with the choices for branch pickup
-    my %biblioLoopIter = ( branchloop => $branchloop );
+    my %biblioLoopIter;
 
     # Get relevant biblio data.
     my $biblioData = $biblioDataHash{$biblioNum};
index b183364..388e04a 100755 (executable)
@@ -22,7 +22,6 @@ use CGI qw ( -utf8 );
 use Encode qw( encode );
 use C4::Auth;    # get_template_and_user
 use C4::Members;
-use C4::Branch;
 use C4::Koha;
 use C4::Output;
 use C4::Suggestions;
@@ -202,9 +201,7 @@ if ( C4::Context->preference("AllowPurchaseSuggestionBranchChoice") ) {
     }
     my $branchcode = $input->param('branchcode') || $borr->{'branchcode'} || $userbranch || '' ;
 
-# make branch selection options...
-    my $branchloop = GetBranchesLoop($branchcode);
-    $template->param( branchloop => $branchloop );
+    $template->param( branchcode => $branchcode );
 }
 
 my $mandatoryfields = '';
index 1bb4d2d..9e2f613 100755 (executable)
@@ -100,6 +100,4 @@ $template->param(
     results => \@results,
 );
 
-$template->param(branchloop => GetBranchesLoop($branch));
-
 output_html_with_http_headers $input, $cookie, $template->output;
index 3eac79f..95adbbc 100755 (executable)
@@ -272,24 +272,6 @@ if ($show_barcode) {
 }
 $template->param( show_barcode => 1 ) if $show_barcode;
 
-# load the branches
-my $branches = GetBranches();
-my @branch_loop;
-for my $branch_hash ( sort keys %{$branches} ) {
-    my $selected;
-    if ( C4::Context->preference('SearchMyLibraryFirst') ) {
-        $selected =
-          ( C4::Context->userenv
-              && ( $branch_hash eq C4::Context->userenv->{branch} ) );
-    }
-    push @branch_loop,
-      { value      => "branch: $branch_hash",
-        branchname => $branches->{$branch_hash}->{'branchname'},
-        selected   => $selected,
-      };
-}
-$template->param( branchloop => \@branch_loop );
-
 # now the reserved items....
 my $reserves = Koha::Holds->search( { borrowernumber => $borrowernumber } );
 
index 1e1dcfd..cd2964b 100755 (executable)
@@ -23,7 +23,6 @@ use CGI qw ( -utf8 );
 use C4::Auth;
 use C4::Output;
 use C4::Context;
-use C4::Branch; # GetBranches
 use C4::Koha;
 use C4::Circulation;
 use C4::Members;
@@ -110,16 +109,6 @@ my @values;
 # here each element returned by map is a hashref, get it?
 my @mime  = ( map { {type =>$_} } (split /[;:]/, 'CSV') ); # FIXME translation
 my $delims = GetDelimiterChoices;
-my $branches = GetBranches;
-my @branchloop;
-foreach (sort keys %$branches) {
-#      my $selected = 1 if $thisbranch eq $branch;
-       my %row = ( value => $_,
-#                              selected => $selected,
-                               branchname => $branches->{$_}->{branchname},
-                       );
-       push @branchloop, \%row;
-}
 
 my $itemtypes = GetItemTypes;
 my @itemtypeloop;
@@ -135,7 +124,6 @@ my $patron_categories = Koha::Patron::Categories->search_limited({}, {order_by =
 $template->param(
            mimeloop => \@mime,
          CGIseplist => $delims,
-         branchloop => \@branchloop,
        itemtypeloop => \@itemtypeloop,
 patron_categories => $patron_categories,
 );
index a7e656f..c4203b6 100755 (executable)
@@ -65,9 +65,6 @@ my $output = $input->param("output");
 my $basename = $input->param("basename");
 our $sep     = $input->param("sep");
 $sep = "\t" if ($sep and $sep eq 'tabulation');
-my $selected_branch; # = $input->param("?");
-
-our $branches = GetBranches;
 
 my ($template, $borrowernumber, $cookie)
        = get_template_and_user({template_name => $fullreportname,
@@ -121,13 +118,6 @@ if ($do_it) {
        my $req;
     my $patron_categories = Koha::Patron::Categories->search({}, {order_by => ['description']});
     $template->param( patron_categories => $patron_categories );
-       my @branchloop;
-       foreach (sort {$branches->{$a}->{branchname} cmp $branches->{$b}->{branchname}} keys %$branches) {
-               my $line = {branchcode => $_, branchname => $branches->{$_}->{branchname} || 'UNKNOWN'};
-               $line->{selected} = 'selected' if ($selected_branch and $selected_branch eq $_);
-               push @branchloop, $line;
-       }
-       $template->param(BRANCH_LOOP => \@branchloop);
        $req = $dbh->prepare("SELECT DISTINCTROW zipcode FROM borrowers WHERE zipcode IS NOT NULL AND zipcode <> '' ORDER BY zipcode");
        $req->execute;
        $template->param(   ZIP_LOOP => $req->fetchall_arrayref({}));
index ce7eded..dd37811 100755 (executable)
@@ -23,7 +23,6 @@ use strict;
 use C4::Auth;
 use CGI qw ( -utf8 );
 use C4::Context;
-use C4::Branch; # GetBranches
 use C4::Output;
 use C4::Koha;
 use C4::Circulation;
@@ -159,7 +158,6 @@ if ($do_it) {
     $template->param(
                     CGIextChoice => $CGIextChoice,
                     CGIsepChoice => $CGIsepChoice,
-                    branchloop => GetBranchesLoop(C4::Context->userenv->{'branch'}),
                     itemtypeloop =>\@itemtypeloop,
                     ccodeloop =>\@ccodeloop,
                     shelvinglocloop =>\@shelvinglocloop,
index 4ce9b3f..73595f4 100755 (executable)
@@ -24,7 +24,6 @@ use CGI qw ( -utf8 );
 use C4::Auth;
 use C4::Context;
 use C4::Debug;
-use C4::Branch;    # GetBranchesLoop
 use C4::Output;
 use C4::Koha;      # GetItemTypes
 # use Date::Manip;  # TODO: add not borrowed since date X criteria
@@ -78,7 +77,6 @@ foreach (
 
 $template->param(
     itemtypeloop => \@itemtypeloop,
-    branchloop   => GetBranchesLoop(),
 );
 output_html_with_http_headers $input, $cookie, $template->output;
 
index c153947..b0a72b0 100755 (executable)
@@ -23,7 +23,6 @@ use strict;
 use C4::Auth;
 use CGI qw ( -utf8 );
 use C4::Context;
-use C4::Branch; # GetBranches
 use C4::Output;
 use C4::Koha;
 use C4::Reports;
@@ -156,7 +155,6 @@ if ($do_it) {
 
     $template->param(
         itemtypes    => $itemtypes,
-        CGIBranch    => GetBranchesLoop( C4::Context->userenv->{'branch'} ),
         locationloop => \@locations,
         authvals     => \@authvals,
         CGIextChoice => \@mime,
index c5ad623..3a122d2 100755 (executable)
@@ -29,13 +29,13 @@ use C4::Auth qw/:DEFAULT get_session/;
 use C4::Output;
 use C4::Debug;
 use C4::Koha qw/GetFrameworksLoop/;
-use C4::Branch;
 use C4::Context;
 use Koha::Caches;
 use C4::Log;
 use Koha::DateUtils qw/dt_from_string output_pref/;
 use Koha::AuthorisedValue;
 use Koha::AuthorisedValues;
+use Koha::Libraries;
 use Koha::Patron::Categories;
 
 =head1 NAME
@@ -664,10 +664,10 @@ elsif ($phase eq 'Run this report'){
                     my %authorised_lib;
                     # builds list, depending on authorised value...
                     if ( $authorised_value eq "branches" ) {
-                        my $branches = GetBranchesLoop();
-                        foreach my $thisbranch (@$branches) {
-                            push @authorised_values, $thisbranch->{value};
-                            $authorised_lib{$thisbranch->{value}} = $thisbranch->{branchname};
+                        my $libraries = Koha::Libraries->search( {}, { order_by => ['branchname'] } );
+                        while ( my $library = $libraries->next ) {
+                            push @authorised_values, $library->branchcode;
+                            $authorised_lib{$library->branchcode} = $library->branchname;
                         }
                     }
                     elsif ( $authorised_value eq "itemtypes" ) {
index 797d5f4..cf2686a 100755 (executable)
@@ -154,7 +154,6 @@ if ($do_it) {
     $template->param(
                     patron_categories => $patron_categories,
                     itemtypes    => $itemtypes,
-                    branchloop   => GetBranchesLoop(),
                     hassort1     => $hassort1,
                     hassort2     => $hassort2,
                     HlghtSort2   => $hglghtsort2,
index 060d345..27d837c 100755 (executable)
@@ -66,8 +66,6 @@ the hashes are then translated to hash / arrays to be returned to manager.pl & s
 sub set_parameters {
     my ($template) = @_;
 
-    $template->param( branchloop => GetBranchesLoop() );
-
     my $patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['categorycode']});
     $template->param( patron_categories => $patron_categories );
     return $template;
index 48df561..665e02b 100755 (executable)
@@ -26,7 +26,6 @@ use Date::Manip;
 use C4::Auth;
 use C4::Debug;
 use C4::Context;
-use C4::Branch; # GetBranches
 use C4::Koha;
 use C4::Output;
 use C4::Circulation;
@@ -156,7 +155,6 @@ $template->param(
        itemtypeloop => \@itemtypeloop,
        locationloop => \@locations,
           ccodeloop => \@ccodes,
-         branchloop => GetBranchesLoop(C4::Context->userenv->{'branch'}),
        hassort1=> $hassort1,
        hassort2=> $hassort2,
        Bsort1 => $Bsort1,
index f0f318a..00f2b99 100755 (executable)
@@ -34,7 +34,6 @@ use C4::Output;
 use C4::Biblio;
 use C4::Items;
 use C4::Koha;                  # GetItemTypes
-use C4::Branch; # GetBranches
 use Koha::DateUtils;
 
 my $query = new CGI;
@@ -80,10 +79,6 @@ if ( $get_items ) {
                  );
 }
 
-# getting all branches.
-#my $branches = GetBranches;
-#my $branch   = C4::Context->userenv->{"branchname"};
-
 # getting all itemtypes
 my $itemtypes = &GetItemTypes();
 my @itemtypesloop;
@@ -98,7 +93,7 @@ foreach my $thisitemtype ( sort {$itemtypes->{$a}->{translated_description} cmp
 # get lost statuses
 my $lost_status_loop = C4::Koha::GetAuthorisedValues( 'LOST' );
 
-$template->param( branchloop     => GetBranchesLoop(C4::Context->userenv->{'branch'}),
+$template->param(
                   itemtypeloop   => \@itemtypesloop,
                   loststatusloop => $lost_status_loop,
 );
index b1b7c3d..ffa6fb7 100755 (executable)
@@ -25,18 +25,12 @@ use C4::Context;
 use C4::Search;
 use C4::Output;
 use C4::Koha;
-use C4::Branch; # GetBranches
 =head1
 
 =cut
 
 sub set_parameters {
     my ($template) = @_;
-    my $userbranch = '';
-    if (C4::Context->userenv && C4::Context->userenv->{'branch'}) {
-        $userbranch = C4::Context->userenv->{'branch'};
-    }
-    $template->param( branchloop => GetBranchesLoop($userbranch) );
     return $template;
 }
 
index 04d6268..40a231d 100755 (executable)
@@ -26,7 +26,6 @@ use CGI qw ( -utf8 );
 use C4::Auth;
 use C4::Debug;
 use C4::Context;
-use C4::Branch; # GetBranches
 use C4::Koha;
 use C4::Output;
 use C4::Reports;
@@ -164,7 +163,6 @@ $template->param(
        itemtypeloop => \@itemtypeloop,
        locationloop => \@locations,
           ccodeloop => \@ccodes,
-         branchloop => GetBranchesLoop(C4::Context->userenv->{'branch'}),
        hassort1=> $hassort1,
        hassort2=> $hassort2,
        Bsort1 => $Bsort1,
index f6ba4c0..614b95f 100755 (executable)
@@ -22,7 +22,6 @@ use warnings;
 use C4::Auth;
 use CGI qw ( -utf8 );
 use C4::Context;
-use C4::Branch; # GetBranches
 use C4::Output;
 use C4::Koha;
 use C4::Reports;
@@ -153,7 +152,7 @@ if($do_it){
                CGIextChoice => $CGIextChoice,
                CGIsepChoice => $CGIsepChoice,
         booksellers  => \@booksellers,
-        branches     => GetBranchesLoop(C4::Context->userenv->{'branch'}));
+    );
 }
 
 output_html_with_http_headers $input, $cookie, $template->output;
index e656e0e..f4d0279 100755 (executable)
@@ -67,12 +67,6 @@ my $showallitems = $input->param('showallitems');
 my $branches = GetBranches();
 my $itemtypes = GetItemTypes();
 
-my $userbranch = '';
-if (C4::Context->userenv && C4::Context->userenv->{'branch'}) {
-    $userbranch = C4::Context->userenv->{'branch'};
-}
-
-
 # Select borrowers infos
 my $findborrower = $input->param('findborrower');
 $findborrower = '' unless defined $findborrower;
@@ -588,13 +582,7 @@ foreach my $biblionumber (@biblionumbers) {
         $reserve{'suspend_until'}  = $res->suspend_until();
         $reserve{'reserve_id'}     = $res->reserve_id();
         $reserve{itemtype}         = $res->itemtype();
-
-        if ( C4::Context->preference('IndependentBranches') && $flags->{'superlibrarian'} != 1 ) {
-            $reserve{'branchloop'} = [ Koha::Libraries->find( $res->branchcode() ) ];
-        }
-        else {
-            $reserve{'branchloop'} = GetBranchesLoop( $res->branchcode() );
-        }
+        $reserve{branchcode}       = $res->branchcode();
 
         push( @reserveloop, \%reserve );
     }
@@ -603,7 +591,6 @@ foreach my $biblionumber (@biblionumbers) {
     my $time = time();
 
     $template->param(
-                     branchloop  => GetBranchesLoop($userbranch),
                      time        => $time,
                      fixedRank   => $fixedRank,
                     );
index e4fa9ce..7e2eed4 100755 (executable)
@@ -47,7 +47,6 @@ use warnings;
 use CGI qw ( -utf8 );
 use C4::Auth;
 use C4::Serials; # GetExpirationDate
-use C4::Branch;
 use C4::Output;
 use C4::Context;
 use Koha::DateUtils;
@@ -113,18 +112,19 @@ if ($date) {
     );
 }
 
-my $branches_loop;
+my $can_change_library;;
 if (  !C4::Context->preference("IndependentBranches")
     or C4::Context->IsSuperLibrarian()
     or ( ref $flags->{serials}  and $flags->{serials}->{superserials} )
     or ( !ref $flags->{serials} and $flags->{serials} == 1 ) )
 {
-    $branches_loop = C4::Branch::GetBranchesLoop( $branch );
+    $can_change_library = 1;
 }
 
 $template->param (
     (uc(C4::Context->preference("marcflavour"))) => 1,
-    branches_loop   => $branches_loop,
+    can_change_library => $can_change_library,
+    branch => $branch,
 );
 
 output_html_with_http_headers $query, $cookie, $template->output;
index 97f52ae..b4bc94f 100755 (executable)
@@ -25,7 +25,6 @@ use C4::Acquisition;
 use C4::Output;
 use C4::Context;
 use C4::Letters;
-use C4::Branch;    # GetBranches GetBranchesLoop
 use C4::Koha qw( GetAuthorisedValues );
 
 use Koha::AdditionalField;
@@ -65,7 +64,6 @@ for my $field ( @$additional_fields ) {
     }
 }
 
-my $branchloop = GetBranchesLoop();
 
 my @serialnums=$input->multi_param('serialid');
 if (@serialnums) { # i.e. they have been flagged to generate claims
@@ -105,7 +103,6 @@ $template->param(
         missingissues => \@missingissues,
         supplierid => $supplierid,
         claimletter => $claimletter,
-        branchloop   => $branchloop,
         additional_fields_for_subscription => $additional_fields,
         csv_profiles => [ Koha::CsvProfiles->search({ type => 'sql' }) ],
         letters => $letters,
index 51c629e..348adb3 100644 (file)
@@ -38,7 +38,6 @@ can_ok(
     'C4::Branch', qw(
       GetBranch
       GetBranches
-      GetBranchesLoop
       mybranch
       )
 );
@@ -198,8 +197,4 @@ is( Koha::LibraryCategories->search->count, $count_cat + 3, "Two categories adde
 #TODO later: test mybranchine and onlymine
 # Actually we cannot mock C4::Context->userenv in unit tests
 
-#Test GetBranchesLoop
-my $loop = GetBranchesLoop;
-is( scalar(@$loop), Koha::Libraries->search->count, 'There is the right number of branches' );
-
 $schema->storage->txn_rollback;
index b58362b..241272c 100755 (executable)
@@ -63,9 +63,6 @@ foreach ( 1 .. $borrowers_count ) {
 
 my $biblionumber = $bibnum;
 
-my @branches = GetBranchesLoop();
-my $branch   = $branches[0][0]{value};
-
 # Create five item level holds
 my $i = 1;
 foreach my $borrowernumber (@borrowernumbers) {
index 513eb52..90419df 100755 (executable)
@@ -13,6 +13,8 @@ use C4::Items;
 use C4::Members;
 use C4::Reserves;
 
+use Koha::Libraries;
+
 use t::lib::TestBuilder;
 
 my $schema = Koha::Database->schema;
@@ -61,13 +63,12 @@ foreach my $i ( 1 .. $borrowers_count ) {
 
 my $biblionumber = $bibnum;
 
-my @branches = GetBranchesLoop();
-my $branch   = $branches[0][0]{value};
+my $branchcode = Koha::Libraries->search->next->branchcode;
 
 # Create five item level holds
 foreach my $borrowernumber (@borrowernumbers) {
     AddReserve(
-        $branch,
+        $branchcode,
         $borrowernumber,
         $biblionumber,
         my $bibitems   = q{},
index 987ccc8..e26e553 100755 (executable)
@@ -113,10 +113,9 @@ my $notes          = '';
 my $checkitem      = undef;
 my $found          = undef;
 
-my @branches = GetBranchesLoop();
-my $branch = $branches[0][0]{value};
+my $branchcode = Koha::Libraries->search->next->branchcode;
 
-AddReserve($branch,    $borrowernumber, $biblionumber,
+AddReserve($branchcode,    $borrowernumber, $biblionumber,
         $bibitems,  $priority, $resdate, $expdate, $notes,
         $title,      $checkitem, $found);
 
index 0ef4248..439e424 100755 (executable)
@@ -292,11 +292,11 @@ $query  .= qq{ AND ( branchcode = ? OR branchcode IS NULL ) } if $branch_limit;
 $query  .= qq{ GROUP BY lib ORDER BY lib, lib_opac};
 my $authorised_values_sth = $dbh->prepare( $query );
 
-my $branches = GetBranchesLoop();  # 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.
 
 # Adding a default choice, in case the user does not want to modify the branch
 my $nochange_branch = { branchname => '', value => '', selected => 1 };
-unshift (@$branches, $nochange_branch);
+unshift (@$libraries, $nochange_branch);
 
 my $pref_itemcallnumber = C4::Context->preference('itemcallnumber');
 
@@ -350,14 +350,14 @@ foreach my $tag (sort keys %{$tagslib}) {
        my @authorised_values;
        my %authorised_lib;
        # builds list, depending on authorised value...
-  
-       if ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "branches" ) {
-           foreach my $thisbranch (@$branches) {
-               push @authorised_values, $thisbranch->{value};
-               $authorised_lib{$thisbranch->{value}} = $thisbranch->{branchname};
-           }
+
+    if ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "branches" ) {
+        foreach my $library (@$libraries) {
+            push @authorised_values, $library->{branchcode};
+            $authorised_lib{$library->{branchcode}} = $library->{branchname};
+        }
         $value = "";
-       }
+    }
     elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
         push @authorised_values, "";
         my $itemtypes = GetItemTypes( style => 'array' );
index 2aee9ba..4de6886 100755 (executable)
@@ -51,26 +51,6 @@ my $keydate = output_pref( { dt => $calendarinput_dt, dateonly => 1, dateformat
 $keydate =~ s/-/\//g;
 
 my $branch= $input->param('branch') || C4::Context->userenv->{'branch'};
-# Set all the branches.
-my $onlymine =
-  (      C4::Context->preference('IndependentBranches')
-      && C4::Context->userenv
-      && !C4::Context->IsSuperLibrarian()
-      && C4::Context->userenv->{branch} ? 1 : 0 );
-if ( $onlymine ) { 
-    $branch = C4::Context->userenv->{'branch'};
-}
-my $branches   = GetBranches($onlymine);
-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'},
-      };
-}
 
 # branches calculated - put branch codes in a single string so they can be passed in a form
 my $branchcodes = join '|', keys %{$branches};
@@ -145,7 +125,6 @@ foreach my $yearMonthDay (keys %$single_holidays) {
 
 $template->param(
     WEEK_DAYS_LOOP           => \@week_days,
-    branchloop               => \@branchloop,
     HOLIDAYS_LOOP            => \@holidays,
     EXCEPTION_HOLIDAYS_LOOP  => \@exception_holidays,
     DAY_MONTH_HOLIDAYS_LOOP  => \@day_month_holidays,
index d4a5a9e..ed5f788 100755 (executable)
@@ -40,7 +40,6 @@ use warnings;
 use C4::Auth;
 use C4::Output;
 use C4::Context;
-use C4::Branch qw/GetBranchesLoop/;
 use C4::Members;
 use C4::Members::Attributes qw(:all);
 use C4::Members::AttributeTypes;
@@ -85,9 +84,6 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
         debug           => 1,
 });
 
-# get the branches and pass them to the template
-my $branches = GetBranchesLoop();
-$template->param( branches => $branches ) if ( $branches );
 # get the patron categories and pass them to the template
 my @patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['description']});
 $template->param( categories => \@patron_categories );
index 990855f..5e5a5e3 100755 (executable)
@@ -64,16 +64,6 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
     }
 );
 
-
-my $branches = GetBranches();
-my @branch_loop;
-for my $branch_hash (keys %$branches) {
-    push @branch_loop, {value => "$branch_hash",
-                       branchname => $branches->{$branch_hash}->{'branchname'},
-                       selected => ($branch_hash eq $branchcode?1:0)};
-}
-
-@branch_loop = sort {$a->{branchname} cmp $b->{branchname}} @branch_loop;
 my @authorised_value_list;
 my $authorisedvalue_categories = '';
 
@@ -128,7 +118,6 @@ for my $authvfield (@$statuses) {
 }
 $statussth =~ s, and $,,g;
 $template->param(
-    branchloop               => \@branch_loop,
     authorised_values        => \@authorised_value_list,
     today                    => dt_from_string,
     minlocation              => $minlocation,
index 9f8ac95..0f72cd6 100755 (executable)
@@ -104,7 +104,6 @@ if ($op eq 'copy_form') {
     $template->param(
         oldbranchcode => $oldbranchcode,
         branchcode => $branchcode,
-        branchloop => _branchloop($branchcode),
         copying => 1,
         modify => 0,
     );
@@ -240,7 +239,6 @@ sub add_form {
 
     $template->param(
         module     => $module,
-        branchloop => _branchloop($branchcode),
         SQLfieldnames => $field_selection,
         branchcode => $branchcode,
     );
@@ -379,26 +377,10 @@ sub default_display {
 
     $template->param(
         letter => $loop_data,
-        branchloop => _branchloop($branchcode),
+        branchcode => $branchcode,
     );
 }
 
-sub _branchloop {
-    my ($branchcode) = @_;
-
-    my $branches = GetBranches();
-    my @branchloop;
-    for my $thisbranch (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %$branches) {
-        push @branchloop, {
-            value      => $thisbranch,
-            selected   => $branchcode && $thisbranch eq $branchcode,
-            branchname => $branches->{$thisbranch}->{'branchname'},
-        };
-    }
-
-    return \@branchloop;
-}
-
 sub add_fields {
     my @tables = @_;
     my @fields = ();
index db532a6..31e4ec1 100755 (executable)
@@ -28,7 +28,6 @@
 use Modern::Perl;
 use CGI qw ( -utf8 );
 use C4::Auth;
-use C4::Branch;
 use C4::Koha;
 use C4::Members;
 use C4::Members::Attributes;
@@ -37,6 +36,7 @@ use C4::Output;
 use List::MoreUtils qw /any uniq/;
 use Koha::DateUtils qw( dt_from_string );
 use Koha::List::Patron;
+use Koha::Libraries;
 use Koha::Patron::Categories;
 
 my $input = new CGI;
@@ -145,7 +145,7 @@ if ( $op eq 'show' ) {
         if @notfoundcardnumbers;
 
     # Construct drop-down list values
-    my $branches = GetBranchesLoop;
+    my $branches = Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed;
     my @branches_option;
     push @branches_option, { value => $_->{value}, lib => $_->{branchname} } for @$branches;
     unshift @branches_option, { value => "", lib => "" };
index 8ce3f3c..f21092d 100755 (executable)
@@ -24,7 +24,6 @@ use C4::Context;
 use C4::Output;
 use C4::Auth;
 use C4::Koha;
-use C4::Branch;
 use C4::Letters;
 use C4::Members;
 use C4::Overdues;
@@ -210,7 +209,6 @@ if ($op eq 'save') {
         $input_saved = 1;
     }
 }
-my $branchloop = GetBranchesLoop($branch);
 
 my $letters = C4::Letters::GetLettersAvailableForALibrary(
     {
@@ -310,7 +308,6 @@ my @tabs = (
 
 $template->param(
     table => ( @first or @second or @third ? 1 : 0 ),
-    branchloop => $branchloop,
     branch => $branch,
     tabs => \@tabs,
     message_transport_types => $message_transport_types,