From 0ab0f61657d7a93b5eab1fe4327b7254c10032e3 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: Joy Nelson --- 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 43facd7133..6791a63198 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -1833,7 +1833,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; @@ -2236,7 +2236,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 3c05fd1b60..c254dbd676 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 c628732f6d..19cbae27f9 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -649,6 +649,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 @@ -661,12 +663,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 1271f1bbf7..949aaa7b9f 100755 --- a/opac/opac-shelves.pl +++ b/opac/opac-shelves.pl @@ -282,9 +282,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 bc5ac8a9e3..ab73449402 100755 --- a/opac/opac-tags.pl +++ b/opac/opac-tags.pl @@ -267,10 +267,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