From 94ea9b8bee9a14992b23d4c0517cc6dcbf65e0e9 Mon Sep 17 00:00:00 2001 From: Robin Sheat Date: Wed, 8 Oct 2014 19:12:13 +1300 Subject: [PATCH] Bug 13040 - multiple branch selections in exporter This allows the exporter (Tools -> Export) to have any combination of branches selected, rather than it being all or only one. Test Plan: * Apply the patch * Go to the exporter, see that instead of a dropdown you now have an elegently laid out grid of branches you can select from * Select some branches, run the export * Note that only records with items in the selected branches are returned. * Repeat this with the item related options (as that code was refactored slightly) and make sure everything is sane. Sponsored-By: South Taranaki District Libraries --- .../intranet-tmpl/prog/en/css/staff-global.css | 12 +++++++++ .../prog/en/includes/branch-selector.inc | 21 +++++++++++++++ .../intranet-tmpl/prog/en/modules/tools/export.tt | 13 +++------ tools/export.pl | 31 +++++++++++----------- 4 files changed, 51 insertions(+), 26 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/branch-selector.inc diff --git a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css b/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css index 382701b..675908f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css +++ b/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css @@ -2713,3 +2713,15 @@ span.browse-button { #i18nMenu .dropdown-menu a:focus { color : #FFF; } + +.branchgriditem { + display: table-cell; + float: left; +} +.branchgridrow { + display: table-row; +} +.branchselector { + display: table; +} + diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/branch-selector.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/branch-selector.inc new file mode 100644 index 0000000..a5ce611 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/branch-selector.inc @@ -0,0 +1,21 @@ +[%# First check to see if we have anything selected, otherwise we select all %] +[% selectall = 1 %] +[% FOREACH branch IN branches; + IF branch.selected; + selectall = 0; + END; +END %] +
+
+ [% FOREACH branch IN branches %] +
+ + +
+ [% IF loop.count() % 4 == 0 && !loop.last() %] +
+
+ [% END %] + [% END %] +
+
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt index 0ac62d1..bacc296 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt @@ -65,16 +65,9 @@ $(document).ready(function() {
  • - - + + [% INCLUDE 'branch-selector.inc' + branches = branchloop %]
  • diff --git a/tools/export.pl b/tools/export.pl index 8a5c2a5..c3d1d60 100755 --- a/tools/export.pl +++ b/tools/export.pl @@ -131,13 +131,17 @@ my $limit_ind_branch = && !C4::Context->IsSuperLibrarian() && C4::Context->userenv->{branch} ) ? 1 : 0; -my $branch = $query->param("branch") || ''; +my @branch = $query->param("branch"); if ( C4::Context->preference("IndependentBranches") && C4::Context->userenv && !C4::Context->IsSuperLibrarian() ) { - $branch = C4::Context->userenv->{'branch'}; + @branch = ( C4::Context->userenv->{'branch'} ); } +# if stripping nonlocal items, use loggedinuser's branch if they didn't select one +@branch = ( C4::Context->userenv->{'branch'} ) + unless @branch; +my %branchmap = map { $_ => 1 } @branch; # for quick lookups my $backupdir = C4::Context->config('backupdir'); @@ -245,7 +249,7 @@ if ( $op eq "export" ) { itemstable => $itemstable, StartingBiblionumber => $StartingBiblionumber, EndingBiblionumber => $EndingBiblionumber, - branch => $branch, + branch => \@branch, start_callnumber => $start_callnumber, end_callnumber => $end_callnumber, start_accession => $start_accession, @@ -322,7 +326,6 @@ if ( $op eq "export" ) { # Someone is trying to mess us up exit; } - unless (@biblionumbers) { my $sth = $dbh->prepare($sql_query); $sth->execute(@sql_params); @@ -363,14 +366,10 @@ if ( $op eq "export" ) { my ( $homebranchfield, $homebranchsubfield ) = GetMarcFromKohaField( 'items.homebranch', '' ); 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 ); + || !$branchmap{ $itemfield->subfield( + $homebranchsubfield) } ); } } } @@ -470,7 +469,7 @@ else { push @branchloop, { value => $thisbranch, - selected => $thisbranch eq $branch, + selected => $branchmap{$thisbranch}, branchname => $branches->{$thisbranch}->{'branchname'}, }; } @@ -545,14 +544,14 @@ sub construct_query { my $itemstable = $params->{itemstable}; my $StartingBiblionumber = $params->{StartingBiblionumber}; my $EndingBiblionumber = $params->{EndingBiblionumber}; - my $branch = $params->{branch}; + my @branch = @{ $params->{branch} }; my $start_callnumber = $params->{start_callnumber}; my $end_callnumber = $params->{end_callnumber}; my $start_accession = $params->{start_accession}; my $end_accession = $params->{end_accession}; my $itemtype = $params->{itemtype}; my $items_filter = - $branch + @branch || $start_callnumber || $end_callnumber || $start_accession @@ -574,9 +573,9 @@ sub construct_query { push @sql_params, $EndingBiblionumber; } - if ($branch) { - $sql_query .= " AND homebranch = ? "; - push @sql_params, $branch; + if (@branch) { + $sql_query .= " AND homebranch IN (".join(',',map({'?'} @branch)).")"; + push @sql_params, @branch; } if ($start_callnumber) { -- 1.9.1