From robin at catalyst.net.nz Wed Oct 8 08:18:25 2014 From: robin at catalyst.net.nz (Robin Sheat) Date: Wed, 8 Oct 2014 19:18:25 +1300 Subject: [Koha-patches] [PATCH] Bug 13040 - multiple branch selections in exporter Message-ID: <1412749105-18959-1-git-send-email-robin@catalyst.net.nz> 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 + at 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 From tomascohen at gmail.com Fri Oct 31 17:12:53 2014 From: tomascohen at gmail.com (Tomas Cohen Arazi) Date: Fri, 31 Oct 2014 13:12:53 -0300 Subject: [Koha-patches] [PATCH] Bug 10582: Koha OPAC URL shows Perl error message before web installer was run Message-ID: <1414771973-18783-1-git-send-email-tomascohen@gmail.com> This patch makes opac/maintenance.pl run smoothly when the DB hasn't been populated yet. It does so, by using C4::Templates::gettemplate instead of C4::Auth::get_user_and_template as the maintenance page doesn't need authentication checks at all, it should happen *before* any attempt to check credentials. To test: - Backup and DROP your database - Point your browser to the OPAC page => FAIL: An error is shown: "Cant's use an undefined value as an ARRAY..." - Apply the patch - Relad the page => SUCCESS: The maintenance page correctly shows. We should now check the rest of the script's behaviour remains untouched: - Reload your backed up DB - Change your DB version number by hand to one version lower, like in: > UPDATE systempreferences SET value="3.1700042" WHERE variable LIKE '%version%'; - Go to the OPAC => SUCCESS: Maintenance page shows as expected - Recover the right version number, like in: > UPDATE systempreferences SET value="3.1700043" WHERE variable LIKE '%version%'; - Set OpacMaintenance to Show on the staff client - Reload the OPAC => SUCCESS: Maintenance page shows as expected - Set OpacMaintenance to 'Don't show' on the staff client - Reload the OPAC => SUCCESS: Normal OPAC shows - Sign off :-D Regards Sponsored-by: Universidad Nacional de Cordoba --- opac/maintenance.pl | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/opac/maintenance.pl b/opac/maintenance.pl index 9c2d9b0..53394cb 100755 --- a/opac/maintenance.pl +++ b/opac/maintenance.pl @@ -15,36 +15,29 @@ # with Koha; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -use strict; -use warnings; - -# FIXME - Generates a warning from C4/Context.pm (uninitilized value). +use Modern::Perl; use CGI; use C4::Auth; use C4::Output; +use C4::Templates qw/gettemplate/; -my $input = new CGI; - -my ( $template, $borrowernumber, $cookie ) = get_template_and_user( - { - template_name => "maintenance.tt", - type => "opac", - query => $input, - authnotrequired => 1, - flagsrequired => { borrow => 1 }, - } -); +my $query = new CGI; +my $template = C4::Templates::gettemplate( 'maintenance.tt', 'opac', $query, 0 ); my $koha_db_version = C4::Context->preference('Version'); my $kohaversion = C4::Context::KOHAVERSION; -$kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/; - -#warn "db: $koha_db_version, koha: $kohaversion"; - -if ( $kohaversion > $koha_db_version or C4::Context->preference('OpacMaintenance') ) { - output_html_with_http_headers $input, '', $template->output; +# Strip dots from version +$kohaversion =~ s/\.//g if defined $kohaversion; +$koha_db_version =~ s/\.//g if defined $koha_db_version; + +if ( !defined $koha_db_version || # DB not populated + $kohaversion > $koha_db_version || # Update needed + C4::Context->preference('OpacMaintenance') ) { # Maintenance mode enabled + output_html_with_http_headers $query, '', $template->output; } else { - print $input->redirect("/cgi-bin/koha/opac-main.pl"); + print $query->redirect("/cgi-bin/koha/opac-main.pl"); } + +1; \ No newline at end of file -- 1.9.1 From tomascohen at gmail.com Fri Oct 31 17:13:19 2014 From: tomascohen at gmail.com (Tomas Cohen Arazi) Date: Fri, 31 Oct 2014 13:13:19 -0300 Subject: [Koha-patches] [PATCH] Bug 13169: C4::Templates::themelanguage fails if the DB is not populated Message-ID: <1414771999-18851-1-git-send-email-tomascohen@gmail.com> With the aim to remove hardcoded themes the C4::Templates::themelanguage got dependent on the DB being populated. This patch reintroduced the hardcoded defaults as a last resort. To test: - Do a fresh install, clean your browser's cache, empty DB - Open the staff interface => FAIL: A "Software error" screen shows "Template process failed: file error..." - Apply the patch - Reload => SUCCESS: The webinstaller prompts for login correctly. - Sign off :-D Regards --- C4/Templates.pm | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/C4/Templates.pm b/C4/Templates.pm index 7d09a58..3a3a65c 100644 --- a/C4/Templates.pm +++ b/C4/Templates.pm @@ -4,7 +4,7 @@ use strict; use warnings; use Carp; use CGI; -use List::MoreUtils qw/any/; +use List::MoreUtils qw/any uniq/; # Copyright 2009 Chris Cormack and The Koha Dev Team # @@ -250,9 +250,20 @@ sub gettemplate { } -#--------------------------------------------------------------------------------------------------------- -# FIXME - POD -# FIXME - Rewritten to remove hardcoded theme with minimal changes, need to be rethinked +=head2 themelanguage + + my ($theme,$lang,\@themes) = themelanguage($htdocs,$tmpl,$interface,query); + +This function returns the theme and language to be used for rendering the UI. +It also returns the list of themes that should be applied as a fallback. This is +used for the theme overlay feature (i.e. if a file doesn't exist on the requested +theme, fallback to the configured fallback). + +Important: this function is used on the webinstaller too, so always consider +the use case where the DB is not populated already when rewriting/fixing. + +=cut + sub themelanguage { my ($htdocs, $tmpl, $interface, $query) = @_; ($query) or warn "no query in themelanguage"; @@ -261,20 +272,31 @@ sub themelanguage { my $lang = C4::Languages::getlanguage($query); # Get theme - my @themes = ( C4::Context->preference( ($interface eq 'intranet') ? 'template' : 'opacthemes' ) ); - my $fallback = C4::Context->preference( ($interface eq 'intranet') ? 'template' : 'OPACFallback' ); - push @themes, $fallback; + my @themes; + my $theme_syspref = ($interface eq 'intranet') ? 'template' : 'opacthemes'; + my $fallback_syspref = ($interface eq 'intranet') ? 'template' : 'OPACFallback'; + # Yeah, hardcoded, last resort if the DB is not populated + my $hardcoded_theme = ($interface eq 'intranet') ? 'prog' : 'bootstrap'; + + # Configured theme is the first one + push @themes, C4::Context->preference( $theme_syspref ) + if C4::Context->preference( $theme_syspref ); + # Configured fallback next + push @themes, C4::Context->preference( $fallback_syspref ) + if C4::Context->preference( $fallback_syspref ); + # The hardcoded fallback theme is the last one + push @themes, $hardcoded_theme; # Try to find first theme for the selected theme/lang, then for fallback/lang for my $theme (@themes) { if ( -e "$htdocs/$theme/$lang/modules/$tmpl" ) { - return ($theme, $lang, \@themes); + return ( $theme, $lang, uniq( \@themes ) ); } } # Otherwise return theme/'en', last resort fallback/'en' for my $theme (@themes) { if ( -e "$htdocs/$theme/en/modules/$tmpl" ) { - return ($theme, 'en', \@themes); + return ( $theme, 'en', uniq( \@themes ) ); } } } -- 1.9.1