From 2a216e206c13585308fbfb8897f78f9672bd81e0 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 7 May 2020 14:23:40 -0300 Subject: [PATCH] Bug 25416: Let OPAC XSLTs know if the context is an anonymous session This patch makes use of the 'variables' parameter in XSLTParse4Display method in the different places that it is used in the OPAC. It does by passing this parameter with anonymous_session => 1|0 The value will depend on the output from get_template_and_user (i.e. if there's a returned borrowernumber). A special case takes place in search results, as the call to XSLTParse4Display happens in C4::Search::searchResults. So a new parameter 'xslt_variables' is added to it. To test: 1. Apply the [DO NOT PUSH] patch 2. Open the OPAC in your browser 3. Try detail pages, search results, tags and lists/shelves pages with or without an active session => FAIL: It always says (somewhere) 'Anonymous session: Yes' 4. Apply this patch, restart_all 5. Repeat 3 => SUCCESS: It will tell the Yes/No correctly regarding anonymous sessions! 6. Sign off :-D Sponsored-by: Universidad ORT Uruguay Signed-off-by: Victor Grousset/tuxayo Signed-off-by: Nick Clemens Signed-off-by: Martin Renvoize --- C4/Search.pm | 4 ++-- opac/opac-detail.pl | 11 ++++++++--- opac/opac-search.pl | 6 ++++-- opac/opac-shelves.pl | 14 +++++++++++--- opac/opac-tags.pl | 12 +++++++++--- 5 files changed, 34 insertions(+), 13 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index a10e50f2b6..0ab24a5ff8 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -1677,7 +1677,7 @@ Format results in a form suitable for passing to the template # IMO this subroutine is pretty messy still -- it's responsible for # building the HTML output for the template sub searchResults { - my ( $search_context, $searchdesc, $hits, $results_per_page, $offset, $scan, $marcresults ) = @_; + my ( $search_context, $searchdesc, $hits, $results_per_page, $offset, $scan, $marcresults, $xslt_variables ) = @_; my $dbh = C4::Context->dbh; my @newresults; @@ -2087,7 +2087,7 @@ sub searchResults { # XSLT processing of some stuff # we fetched the sysprefs already before the loop through all retrieved record! if (!$scan && $xslfile) { - $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display($oldbiblio->{biblionumber}, $marcrecord, $xslsyspref, 1, \@hiddenitems, $sysxml, $xslfile, $lang); + $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display($oldbiblio->{biblionumber}, $marcrecord, $xslsyspref, 1, \@hiddenitems, $sysxml, $xslfile, $lang, $xslt_variables); } # if biblio level itypes are used and itemtype is notforloan, it can't be reserved either diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index b3e8dbda63..5c1880fbed 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -170,11 +170,16 @@ my $lang = $xslfile ? C4::Languages::getlanguage() : undef; my $sysxml = $xslfile ? C4::XSLT::get_xslt_sysprefs() : undef; if ( $xslfile ) { + + my $variables = { + anonymous_session => ($borrowernumber) ? 0 : 1 + }; + $template->param( XSLTBloc => XSLTParse4Display( - $biblionumber, $record, "OPACXSLTDetailsDisplay", - 1, undef, $sysxml, $xslfile, $lang - ) + $biblionumber, $record, "OPACXSLTDetailsDisplay", 1, undef, + $sysxml, $xslfile, $lang, $variables + ) ); } diff --git a/opac/opac-search.pl b/opac/opac-search.pl index 01887f283a..54655d8b23 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -650,6 +650,8 @@ if (C4::Context->preference('OpacHiddenItemsExceptions')){ $search_context->{'category'} = $patron ? $patron->categorycode : q{}; } +my $variables = { anonymous_session => ($borrowernumber) ? 0 : 1 }; + for (my $i=0;$i<@servers;$i++) { my $server = $servers[$i]; if ($server && $server =~/biblioserver/) { # this is the local bibliographic server @@ -662,12 +664,12 @@ for (my $i=0;$i<@servers;$i++) { # we want as specified by $offset and $results_per_page, # we need to set the offset parameter of searchResults to 0 my @group_results = searchResults( $search_context, $query_desc, $group->{'group_count'},$results_per_page, 0, $scan, - $group->{"RECORDS"}); + $group->{"RECORDS"}, $variables); push @newresults, { group_label => $group->{'group_label'}, GROUP_RESULTS => \@group_results }; } } else { @newresults = searchResults( $search_context, $query_desc, $hits, $results_per_page, $offset, $scan, - $results_hashref->{$server}->{"RECORDS"}); + $results_hashref->{$server}->{"RECORDS"}, $variables); } $hits = 0 unless @newresults; diff --git a/opac/opac-shelves.pl b/opac/opac-shelves.pl index c0140c7a75..e2ac9aafc8 100755 --- a/opac/opac-shelves.pl +++ b/opac/opac-shelves.pl @@ -316,9 +316,17 @@ if ( $op eq 'view' ) { }); $record_processor->process($record); - if ( $xslfile ) { - $this_item->{XSLTBloc} = XSLTParse4Display( $biblionumber, $record, "OPACXSLTListsDisplay", - 1, undef, $sysxml, $xslfile, $lang); + if ($xslfile) { + my $variables = { + anonymous_session => ($loggedinuser) ? 0 : 1 + }; + $this_item->{XSLTBloc} = XSLTParse4Display( + $biblionumber, $record, + "OPACXSLTListsDisplay", 1, + undef, $sysxml, + $xslfile, $lang, + $variables + ); } my $marcflavour = C4::Context->preference("marcflavour"); diff --git a/opac/opac-tags.pl b/opac/opac-tags.pl index 39e756a3cd..b125f8c2f6 100755 --- a/opac/opac-tags.pl +++ b/opac/opac-tags.pl @@ -284,10 +284,16 @@ if ($loggedinuser) { my $lang = $xslfile ? C4::Languages::getlanguage() : undef; my $sysxml = $xslfile ? C4::XSLT::get_xslt_sysprefs() : undef; - if ( $xslfile ) { + if ($xslfile) { + my $variables = { + anonymous_session => ($loggedinuser) ? 0 : 1 + }; $tag->{XSLTBloc} = XSLTParse4Display( - $tag->{ biblionumber }, $record, "OPACXSLTResultsDisplay", - 1, $hidden_items, $sysxml, $xslfile, $lang + $tag->{biblionumber}, $record, + "OPACXSLTResultsDisplay", 1, + $hidden_items, $sysxml, + $xslfile, $lang, + $variables ); } -- 2.39.5