@@ -, +, @@ --- C4/Auth.pm | 11 ++- C4/Search.pm | 48 +++++++++-- installer/data/mysql/kohastructure.sql | 2 + installer/data/mysql/updatedatabase.pl | 10 ++ .../prog/en/modules/opac-search-history.tt | 5 +- kohaversion.pl | 2 +- opac/opac-search-history.pl | 44 +++++----- opac/opac-search.pl | 90 ++++++++++++++++++- 8 files changed, 172 insertions(+), 40 deletions(-) --- a/C4/Auth.pm +++ a/C4/Auth.pm @@ -130,8 +130,8 @@ Output.pm module. =cut my $SEARCH_HISTORY_INSERT_SQL =< C4::Context->preference("IntranetmainUserblock"), LibraryName => C4::Context->preference("LibraryName"), LoginBranchname => (C4::Context->userenv?C4::Context->userenv->{"branchname"}:"insecure"), + TemplateEncoding => C4::Context->preference("TemplateEncoding"), advancedMARCEditor => C4::Context->preference("advancedMARCEditor"), canreservefromotherbranches => C4::Context->preference('canreservefromotherbranches'), intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"), @@ -381,9 +382,10 @@ sub get_template_and_user { virtualshelves => C4::Context->preference("virtualshelves"), StaffSerialIssueDisplayCount => C4::Context->preference("StaffSerialIssueDisplayCount"), NoZebra => C4::Context->preference('NoZebra'), + IntranetXSLTDetailsDisplay => C4::Context->preference("IntranetXSLTDetailsDisplay"), + IntranetXSLTResultsDisplay => C4::Context->preference("IntranetXSLTResultsDisplay"), ); - } - else { + } else { warn "template type should be OPAC, here it is=[" . $in->{'type'} . "]" unless ( $in->{'type'} eq 'opac' ); #TODO : replace LibraryName syspref with 'system name', and remove this html processing my $LibraryNameTitle = C4::Context->preference("LibraryName"); @@ -442,6 +444,7 @@ sub get_template_and_user { OPACFinesTab => C4::Context->preference("OPACFinesTab"), OpacTopissue => C4::Context->preference("OpacTopissue"), RequestOnOpac => C4::Context->preference("RequestOnOpac"), + TemplateEncoding => "" . C4::Context->preference("TemplateEncoding"), 'Version' => C4::Context->preference('Version'), hidelostitems => C4::Context->preference("hidelostitems"), mylibraryfirst => (C4::Context->preference("SearchMyLibraryFirst") && C4::Context->userenv) ? C4::Context->userenv->{'branch'} : '', --- a/C4/Search.pm +++ a/C4/Search.pm @@ -1238,6 +1238,11 @@ sub buildQuery { $truncated_operand .= $index_plus_comma . "rltrn:@$rightlefttruncated "; $previous_truncation_operand = 1; } + if ( scalar @$regexpr ) { + $truncated_operand .= "and " if $previous_truncation_operand; + $truncated_operand .= $index_plus_comma . "regExpr-1:@$regexpr "; + $previous_truncation_operand = 1; + } } $operand = $truncated_operand if $truncated_operand; warn "TRUNCATED OPERAND: >$truncated_operand<" if $DEBUG; @@ -2534,15 +2539,46 @@ sub enabled_staff_search_views ); } -sub AddSearchHistory{ - my ($borrowernumber,$session,$query_desc,$query_cgi, $total)=@_; +=head2 enabled_opac_search_views + +%hash = enabled_opac_search_views() + +This function returns a hash that contains two flags obtained from the system +preferences, used to determine whether a particular opac search results view +is enabled. + +=over 2 + +=item C + + * $hash{can_view_MARC} is true only if the MARC view is enabled + * $hash{can_view_ISBD} is true only if the ISBD view is enabled + +=item C + +=back + +$template->param ( C4::Search::enabled_opac_search_views ); + +=cut + +sub enabled_opac_search_views +{ + return ( + can_opac_view_MARC => C4::Context->preference('OPACviewMARC'), # 1 if the opac search allows the MARC view + can_opac_view_ISBD => C4::Context->preference('OPACviewISBD'), # 1 if the opac search allows the ISBD view + ); +} + +sub AddSearchHistory { + my ( $borrowernumber, $session, $query_desc, $query_cgi, $limit_desc, $limit_cgi, $total ) = @_; my $dbh = C4::Context->dbh; # Add the request the user just made - my $sql = "INSERT INTO search_history(userid, sessionid, query_desc, query_cgi, total, time) VALUES(?, ?, ?, ?, ?, NOW())"; - my $sth = $dbh->prepare($sql); - $sth->execute($borrowernumber, $session, $query_desc, $query_cgi, $total); - return $dbh->last_insert_id(undef, 'search_history', undef,undef,undef); + my $sql = "INSERT INTO search_history(userid, sessionid, query_desc, query_cgi, limit_desc, limit_cgi, total, time) VALUES(?, ?, ?, ?, ?, ?, ?, NOW())"; + my $sth = $dbh->prepare($sql); + $sth->execute( $borrowernumber, $session, $query_desc, $query_cgi, $limit_desc, $limit_cgi, $total ); + return $dbh->last_insert_id( undef, 'search_history', undef, undef, undef ); } sub GetSearchHistory{ --- a/installer/data/mysql/kohastructure.sql +++ a/installer/data/mysql/kohastructure.sql @@ -1633,6 +1633,8 @@ CREATE TABLE IF NOT EXISTS `search_history` ( `sessionid` varchar(32) NOT NULL, `query_desc` varchar(255) NOT NULL, `query_cgi` varchar(255) NOT NULL, + `limit_desc` varchar(255) DEFAULT NULL, + `limit_cgi` varchar(255) DEFAULT NULL, `total` int(11) NOT NULL, `time` timestamp NOT NULL default CURRENT_TIMESTAMP, KEY `userid` (`userid`), --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -4369,6 +4369,16 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { print "Upgrade to $DBversion done (Add syspref ShowReviewerPhoto)\n"; SetVersion($DBversion); } +$DBversion = "3.05.00.005"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do(q{ + ALTER TABLE `search_history` ADD `limit_desc` VARCHAR( 255 ) NULL DEFAULT NULL AFTER `query_cgi` , + ADD `limit_cgi` VARCHAR( 255 ) NULL DEFAULT NULL AFTER `limit_desc` + }); + print "Upgrade to $DBversion done (adding limits to the opac search history)\n"; + SetVersion ($DBversion); +} + =head1 FUNCTIONS --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-search-history.tt +++ a/koha-tmpl/opac-tmpl/prog/en/modules/opac-search-history.tt @@ -47,7 +47,8 @@ [% FOREACH recentSearche IN recentSearches %] [% recentSearche.time %] - [% recentSearche.query_desc |html %] + [% recentSearche.query_desc|html %] [% recentSearche.limit_desc|html %] + [% recentSearche.total %] [% END %] @@ -65,7 +66,7 @@ [% FOREACH previousSearche IN previousSearches %] [% previousSearche.time %] - [% previousSearche.query_desc |html %] + [% previousSearche.query_desc|html %] [% previousSearche.limit_desc|html %] [% previousSearche.total %] [% END %] --- a/kohaversion.pl +++ a/kohaversion.pl @@ -16,7 +16,7 @@ the kohaversion is divided in 4 parts : use strict; sub kohaversion { - our $VERSION = '3.05.00.004'; + our $VERSION = '3.05.00.005'; # version needs to be set this way # so that it can be picked up by Makefile.PL # during install --- a/opac/opac-search-history.pl +++ a/opac/opac-search-history.pl @@ -113,28 +113,28 @@ if (!$loggedinuser) { # Showing search history } else { - my $date = C4::Dates->new(); - my $dateformat = $date->DHTMLcalendar() . " %H:%i:%S"; # Current syspref date format + standard time format - - # Getting the data with date format work done by mysql - my $query = "SELECT userid, sessionid, query_desc, query_cgi, total, DATE_FORMAT(time, \"$dateformat\") as time FROM search_history WHERE userid = ? AND sessionid = ?"; - my $sth = $dbh->prepare($query); - $sth->execute($loggedinuser, $cgi->cookie("CGISESSID")); - my $searches = $sth->fetchall_arrayref({}); - $template->param(recentSearches => $searches); - - # Getting searches from previous sessions - $query = "SELECT COUNT(*) FROM search_history WHERE userid = ? AND sessionid != ?"; - $sth = $dbh->prepare($query); - $sth->execute($loggedinuser, $cgi->cookie("CGISESSID")); - - # If at least one search from previous sessions has been performed - if ($sth->fetchrow_array > 0) { - $query = "SELECT userid, sessionid, query_desc, query_cgi, total, DATE_FORMAT(time, \"$dateformat\") as time FROM search_history WHERE userid = ? AND sessionid != ?"; - $sth = $dbh->prepare($query); - $sth->execute($loggedinuser, $cgi->cookie("CGISESSID")); - my $previoussearches = $sth->fetchall_arrayref({}); - $template->param(previousSearches => $previoussearches); + my $date = C4::Dates->new(); + my $dateformat = $date->DHTMLcalendar() . " %H:%i:%S"; # Current syspref date format + standard time format + + # Getting the data with date format work done by mysql + my $query = "SELECT userid, sessionid, query_desc, query_cgi, limit_desc, limit_cgi, total, DATE_FORMAT(time, \"$dateformat\") as time FROM search_history WHERE userid = ? AND sessionid = ?"; + my $sth = $dbh->prepare($query); + $sth->execute( $loggedinuser, $cgi->cookie("CGISESSID") ); + my $searches = $sth->fetchall_arrayref( {} ); + $template->param( recentSearches => $searches ); + + # Getting searches from previous sessions + $query = "SELECT COUNT(*) FROM search_history WHERE userid = ? AND sessionid != ?"; + $sth = $dbh->prepare($query); + $sth->execute( $loggedinuser, $cgi->cookie("CGISESSID") ); + + # If at least one search from previous sessions has been performed + if ( $sth->fetchrow_array > 0 ) { + $query = "SELECT userid, sessionid, query_desc, query_cgi, limit_desc, limit_cgi, total, DATE_FORMAT(time, \"$dateformat\") as time FROM search_history WHERE userid = ? AND sessionid != ?"; + $sth = $dbh->prepare($query); + $sth->execute( $loggedinuser, $cgi->cookie("CGISESSID") ); + my $previoussearches = $sth->fetchall_arrayref( {} ); + $template->param( previousSearches => $previoussearches ); } --- a/opac/opac-search.pl +++ a/opac/opac-search.pl @@ -538,11 +538,91 @@ for (my $i=0;$i<@servers;$i++) { } } } - ## If there's just one result, redirect to the detail page - if ($total == 1 && $format ne 'rss2' - && $format ne 'opensearchdescription' && $format ne 'atom') { - my $biblionumber=$newresults[0]->{biblionumber}; - if (C4::Context->preference('BiblioDefaultView') eq 'isbd') { + my $tag_quantity; + if ( C4::Context->preference('TagsEnabled') + and $tag_quantity = C4::Context->preference('TagsShowOnList') ) { + foreach (@newresults) { + my $bibnum = $_->{biblionumber} or next; + $_->{itemsissued} = CountItemsIssued($bibnum); + $_->{'TagLoop'} = get_tags( + { biblionumber => $bibnum, + approved => 1, + 'sort' => '-weight', + limit => $tag_quantity + } + ); + } + } + foreach (@newresults) { + $_->{coins} = GetCOinSBiblio( $_->{'biblionumber'} ); + } + + if ( $results_hashref->{$server}->{"hits"} ) { + $total = $total + $results_hashref->{$server}->{"hits"}; + } + + # Opac search history + my $newsearchcookie; + if ( C4::Context->preference('EnableOpacSearchHistory') ) { + my @recentSearches; + + # Getting the (maybe) already sent cookie + my $searchcookie = $cgi->cookie('KohaOpacRecentSearches'); + if ($searchcookie) { + $searchcookie = uri_unescape($searchcookie); + if ( thaw($searchcookie) ) { + @recentSearches = @{ thaw($searchcookie) }; + } + } + + # Adding the new search if needed + if ( not defined $borrowernumber or $borrowernumber eq '' ) { + + # To a cookie (the user is not logged in) + + if ( not defined $params->{'offset'} or $params->{'offset'} eq '' ) { + push @recentSearches, + { "query_desc" => $query_desc || "unknown", + "query_cgi" => $query_cgi || "unknown", + "limit_desc" => $limit_desc, + "limit_cgi" => $limit_cgi, + "time" => time(), + "total" => $total + }; + $template->param( ShowOpacRecentSearchLink => 1 ); + } + + # Only the 15 more recent searches are kept + # TODO: This has been done because of cookies' max size, which is + # usually 4KB. A real check on cookie actual size would be better + # than setting an arbitrary limit on the number of searches + shift @recentSearches if (@recentSearches > 15); + + # Pushing the cookie back + $newsearchcookie = $cgi->cookie( + -name => 'KohaOpacRecentSearches', + + # We uri_escape the whole freezed structure so we're sure we won't have any encoding problems + -value => uri_escape( freeze( \@recentSearches ) ), + -expires => '' + ); + $cookie = [ $cookie, $newsearchcookie ]; + } else { + + # To the session (the user is logged in) + if ( not defined $params->{'offset'} or $params->{'offset'} eq '' ) { + AddSearchHistory( $borrowernumber, $cgi->cookie("CGISESSID"), $query_desc, $query_cgi, $limit_desc, $limit_cgi, $total ); + $template->param( ShowOpacRecentSearchLink => 1 ); + } + } + } + ## If there's just one result, redirect to the detail page + if ( $total == 1 + && $format ne 'rss2' + && $format ne 'opensearchdescription' + && $format ne 'atom' ) { + my $biblionumber = $newresults[0]->{biblionumber}; + if ( C4::Context->preference('BiblioDefaultView') eq 'isbd' ) { print $cgi->redirect("/cgi-bin/koha/opac-ISBDdetail.pl?biblionumber=$biblionumber"); } elsif (C4::Context->preference('BiblioDefaultView') eq 'marc') { print $cgi->redirect("/cgi-bin/koha/opac-MARCdetail.pl?biblionumber=$biblionumber"); --