[Koha-patches] [PATCH] in export.pl use GetBranchesLoop, mybranch, onlymine

Michael Hafen mdhafen at tech.washk12.org
Tue Sep 29 22:03:17 CEST 2009


Change tools/export.pl to use GetBranchesLoop instead of GetBranches and
building the loop itself.  Also use mybranch and onlymine.

Also moved a variable assignment out of a loop.
---
 tools/export.pl |   31 ++++++++-----------------------
 1 files changed, 8 insertions(+), 23 deletions(-)

diff --git a/tools/export.pl b/tools/export.pl
index 4e78159..6123494 100755
--- a/tools/export.pl
+++ b/tools/export.pl
@@ -23,7 +23,7 @@ use C4::Output;    # contains gettemplate
 use C4::Biblio;    # GetMarcBiblio GetXmlBiblio
 use CGI;
 use C4::Koha;      # GetItemTypes
-use C4::Branch;    # GetBranches
+use C4::Branch;    # GetBranchesLoop onlymine mybranch
 
 my $query       = new CGI;
 my $op          = $query->param("op") || '';
@@ -41,16 +41,10 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     }
 );
 
-my $limit_ind_branch = (
-    C4::Context->preference('IndependantBranches') &&
-    C4::Context->userenv &&
-    C4::Context->userenv->{flags} % 2 != 1 &&
-    C4::Context->userenv->{branch} ? 1 : 0
-);
-my $branches = GetBranches($limit_ind_branch);
+my $limit_ind_branch = C4::Branch::onlymine();
 my $branch = $query->param("branch") || '';
-if ( C4::Context->preference("IndependantBranches") ) {
-    $branch = C4::Context->userenv->{'branch'};
+if ( $limit_ind_branch ) {
+    $branch = C4::Branch::mybranch();
 }
 
 if ( $op eq "export" ) {
@@ -138,10 +132,10 @@ if ( $op eq "export" ) {
         next if not defined $record;
         if ( $dont_export_items || $strip_nonlocal_items || $limit_ind_branch ) {
             my ( $homebranchfield, $homebranchsubfield ) = GetMarcFromKohaField( 'items.homebranch', '' );
+            # if stripping nonlocal items, use loggedinuser's branch if they didn't select one
+            $branch ||= C4::Branch::mybranch();
             for my $itemfield ( $record->field($homebranchfield) ) {
 
-                # if stripping nonlocal items, use loggedinuser's branch if they didn't select one
-                $branch = C4::Context->userenv->{'branch'} unless $branch;
                 $record->delete_field($itemfield) if ( $dont_export_items || ( $itemfield->subfield($homebranchsubfield) ne $branch ) );
             }
         }
@@ -183,19 +177,10 @@ else {
         );
         push @itemtypesloop, \%row;
     }
-    my @branchloop;
-    for my $thisbranch ( sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %$branches ) {
-        my $selected = 1 if $thisbranch eq $branch;
-        my %row = (
-            value      => $thisbranch,
-            selected   => $selected,
-            branchname => $branches->{$thisbranch}->{'branchname'},
-        );
-        push @branchloop, \%row;
-    }
+    my $branchloop = GetBranchesLoop();
 
     $template->param(
-        branchloop               => \@branchloop,
+        branchloop               => $branchloop,
         itemtypeloop             => \@itemtypesloop,
         DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
     );
-- 
1.6.0.4



More information about the Koha-patches mailing list