View | Details | Raw Unified | Return to bug 5981
Collapse All | Expand All

(-)a/C4/Auth.pm (-4 / +7 lines)
Lines 130-137 Output.pm module. Link Here
130
=cut
130
=cut
131
131
132
my $SEARCH_HISTORY_INSERT_SQL =<<EOQ;
132
my $SEARCH_HISTORY_INSERT_SQL =<<EOQ;
133
INSERT INTO search_history(userid, sessionid, query_desc, query_cgi, total, time            )
133
INSERT INTO search_history(userid, sessionid, query_desc, query_cgi, limit_desc, limit_cgi, total, time            )
134
VALUES                    (     ?,         ?,          ?,         ?,     ?, FROM_UNIXTIME(?))
134
VALUES                    (     ?,         ?,          ?,         ?,          ?,         ?,     ?, FROM_UNIXTIME(?))
135
EOQ
135
EOQ
136
sub get_template_and_user {
136
sub get_template_and_user {
137
    my $in       = shift;
137
    my $in       = shift;
Lines 368-373 sub get_template_and_user { Link Here
368
            IntranetmainUserblock       => C4::Context->preference("IntranetmainUserblock"),
368
            IntranetmainUserblock       => C4::Context->preference("IntranetmainUserblock"),
369
            LibraryName                 => C4::Context->preference("LibraryName"),
369
            LibraryName                 => C4::Context->preference("LibraryName"),
370
            LoginBranchname             => (C4::Context->userenv?C4::Context->userenv->{"branchname"}:"insecure"),
370
            LoginBranchname             => (C4::Context->userenv?C4::Context->userenv->{"branchname"}:"insecure"),
371
            TemplateEncoding                                                           => C4::Context->preference("TemplateEncoding"),
371
            advancedMARCEditor          => C4::Context->preference("advancedMARCEditor"),
372
            advancedMARCEditor          => C4::Context->preference("advancedMARCEditor"),
372
            canreservefromotherbranches => C4::Context->preference('canreservefromotherbranches'),
373
            canreservefromotherbranches => C4::Context->preference('canreservefromotherbranches'),
373
            intranetcolorstylesheet     => C4::Context->preference("intranetcolorstylesheet"),
374
            intranetcolorstylesheet     => C4::Context->preference("intranetcolorstylesheet"),
Lines 381-389 sub get_template_and_user { Link Here
381
            virtualshelves              => C4::Context->preference("virtualshelves"),
382
            virtualshelves              => C4::Context->preference("virtualshelves"),
382
            StaffSerialIssueDisplayCount => C4::Context->preference("StaffSerialIssueDisplayCount"),
383
            StaffSerialIssueDisplayCount => C4::Context->preference("StaffSerialIssueDisplayCount"),
383
            NoZebra                     => C4::Context->preference('NoZebra'),
384
            NoZebra                     => C4::Context->preference('NoZebra'),
385
            IntranetXSLTDetailsDisplay                                                 => C4::Context->preference("IntranetXSLTDetailsDisplay"),
386
            IntranetXSLTResultsDisplay                                                 => C4::Context->preference("IntranetXSLTResultsDisplay"),
384
        );
387
        );
385
    }
388
    } else {
386
    else {
387
        warn "template type should be OPAC, here it is=[" . $in->{'type'} . "]" unless ( $in->{'type'} eq 'opac' );
389
        warn "template type should be OPAC, here it is=[" . $in->{'type'} . "]" unless ( $in->{'type'} eq 'opac' );
388
        #TODO : replace LibraryName syspref with 'system name', and remove this html processing
390
        #TODO : replace LibraryName syspref with 'system name', and remove this html processing
389
        my $LibraryNameTitle = C4::Context->preference("LibraryName");
391
        my $LibraryNameTitle = C4::Context->preference("LibraryName");
Lines 442-447 sub get_template_and_user { Link Here
442
            OPACFinesTab              => C4::Context->preference("OPACFinesTab"),
444
            OPACFinesTab              => C4::Context->preference("OPACFinesTab"),
443
            OpacTopissue              => C4::Context->preference("OpacTopissue"),
445
            OpacTopissue              => C4::Context->preference("OpacTopissue"),
444
            RequestOnOpac             => C4::Context->preference("RequestOnOpac"),
446
            RequestOnOpac             => C4::Context->preference("RequestOnOpac"),
447
            TemplateEncoding               => "" . C4::Context->preference("TemplateEncoding"),
445
            'Version'                 => C4::Context->preference('Version'),
448
            'Version'                 => C4::Context->preference('Version'),
446
            hidelostitems             => C4::Context->preference("hidelostitems"),
449
            hidelostitems             => C4::Context->preference("hidelostitems"),
447
            mylibraryfirst            => (C4::Context->preference("SearchMyLibraryFirst") && C4::Context->userenv) ? C4::Context->userenv->{'branch'} : '',
450
            mylibraryfirst            => (C4::Context->preference("SearchMyLibraryFirst") && C4::Context->userenv) ? C4::Context->userenv->{'branch'} : '',
(-)a/C4/Search.pm (-6 / +42 lines)
Lines 1238-1243 sub buildQuery { Link Here
1238
                        $truncated_operand .= $index_plus_comma . "rltrn:@$rightlefttruncated ";
1238
                        $truncated_operand .= $index_plus_comma . "rltrn:@$rightlefttruncated ";
1239
                        $previous_truncation_operand = 1;
1239
                        $previous_truncation_operand = 1;
1240
                    }
1240
                    }
1241
                    if ( scalar @$regexpr ) {
1242
                        $truncated_operand .= "and " if $previous_truncation_operand;
1243
                        $truncated_operand .= $index_plus_comma . "regExpr-1:@$regexpr ";
1244
                        $previous_truncation_operand = 1;
1245
                    }
1241
                }
1246
                }
1242
                $operand = $truncated_operand if $truncated_operand;
1247
                $operand = $truncated_operand if $truncated_operand;
1243
                warn "TRUNCATED OPERAND: >$truncated_operand<" if $DEBUG;
1248
                warn "TRUNCATED OPERAND: >$truncated_operand<" if $DEBUG;
Lines 2534-2548 sub enabled_staff_search_views Link Here
2534
	);
2539
	);
2535
}
2540
}
2536
2541
2537
sub AddSearchHistory{
2542
=head2 enabled_opac_search_views
2538
	my ($borrowernumber,$session,$query_desc,$query_cgi, $total)=@_;
2543
2544
%hash = enabled_opac_search_views()
2545
2546
This function returns a hash that contains two flags obtained from the system
2547
preferences, used to determine whether a particular opac search results view
2548
is enabled.
2549
2550
=over 2
2551
2552
=item C<Output arg:>
2553
2554
    * $hash{can_view_MARC} is true only if the MARC view is enabled
2555
    * $hash{can_view_ISBD} is true only if the ISBD view is enabled
2556
2557
=item C<usage in the script:>
2558
2559
=back
2560
2561
$template->param ( C4::Search::enabled_opac_search_views );
2562
2563
=cut
2564
2565
sub enabled_opac_search_views
2566
{
2567
	return (
2568
		can_opac_view_MARC		=> C4::Context->preference('OPACviewMARC'),		# 1 if the opac search allows the MARC view
2569
		can_opac_view_ISBD		=> C4::Context->preference('OPACviewISBD'),		# 1 if the opac search allows the ISBD view
2570
	);
2571
}
2572
2573
sub AddSearchHistory {
2574
    my ( $borrowernumber, $session, $query_desc, $query_cgi, $limit_desc, $limit_cgi, $total ) = @_;
2539
    my $dbh = C4::Context->dbh;
2575
    my $dbh = C4::Context->dbh;
2540
2576
2541
    # Add the request the user just made
2577
    # Add the request the user just made
2542
    my $sql = "INSERT INTO search_history(userid, sessionid, query_desc, query_cgi, total, time) VALUES(?, ?, ?, ?, ?, NOW())";
2578
    my $sql = "INSERT INTO search_history(userid, sessionid, query_desc, query_cgi, limit_desc, limit_cgi, total, time) VALUES(?, ?, ?, ?, ?, ?, ?, NOW())";
2543
    my $sth   = $dbh->prepare($sql);
2579
    my $sth = $dbh->prepare($sql);
2544
    $sth->execute($borrowernumber, $session, $query_desc, $query_cgi, $total);
2580
    $sth->execute( $borrowernumber, $session, $query_desc, $query_cgi, $limit_desc, $limit_cgi, $total );
2545
	return $dbh->last_insert_id(undef, 'search_history', undef,undef,undef);
2581
    return $dbh->last_insert_id( undef, 'search_history', undef, undef, undef );
2546
}
2582
}
2547
2583
2548
sub GetSearchHistory{
2584
sub GetSearchHistory{
(-)a/installer/data/mysql/kohastructure.sql (+2 lines)
Lines 1633-1638 CREATE TABLE IF NOT EXISTS `search_history` ( Link Here
1633
  `sessionid` varchar(32) NOT NULL,
1633
  `sessionid` varchar(32) NOT NULL,
1634
  `query_desc` varchar(255) NOT NULL,
1634
  `query_desc` varchar(255) NOT NULL,
1635
  `query_cgi` varchar(255) NOT NULL,
1635
  `query_cgi` varchar(255) NOT NULL,
1636
  `limit_desc` varchar(255) DEFAULT NULL,
1637
  `limit_cgi` varchar(255) DEFAULT NULL,
1636
  `total` int(11) NOT NULL,
1638
  `total` int(11) NOT NULL,
1637
  `time` timestamp NOT NULL default CURRENT_TIMESTAMP,
1639
  `time` timestamp NOT NULL default CURRENT_TIMESTAMP,
1638
  KEY `userid` (`userid`),
1640
  KEY `userid` (`userid`),
(-)a/installer/data/mysql/updatedatabase.pl (+10 lines)
Lines 4369-4374 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
4369
    print "Upgrade to $DBversion done (Add syspref ShowReviewerPhoto)\n";
4369
    print "Upgrade to $DBversion done (Add syspref ShowReviewerPhoto)\n";
4370
    SetVersion($DBversion);
4370
    SetVersion($DBversion);
4371
}
4371
}
4372
$DBversion = "3.05.00.005";
4373
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
4374
	$dbh->do(q{
4375
	ALTER TABLE `search_history` ADD `limit_desc` VARCHAR( 255 ) NULL DEFAULT NULL AFTER `query_cgi` ,
4376
	ADD `limit_cgi` VARCHAR( 255 ) NULL DEFAULT NULL AFTER `limit_desc` 
4377
    });
4378
	print "Upgrade to $DBversion done (adding limits to the opac search history)\n";
4379
	SetVersion ($DBversion);
4380
}
4381
4372
4382
4373
=head1 FUNCTIONS
4383
=head1 FUNCTIONS
4374
4384
(-)a/koha-tmpl/opac-tmpl/prog/en/modules/opac-search-history.tt (-2 / +3 lines)
Lines 47-53 Link Here
47
		    [% FOREACH recentSearche IN recentSearches %]
47
		    [% FOREACH recentSearche IN recentSearches %]
48
		    <tr>
48
		    <tr>
49
			<td>[% recentSearche.time %]</td>
49
			<td>[% recentSearche.time %]</td>
50
			<td><a href="/cgi-bin/koha/opac-search.pl?[% recentSearche.query_cgi |html %]">[% recentSearche.query_desc |html %]</a></td>
50
			<td><a href="/cgi-bin/koha/opac-search.pl?[% recentSearche.query_cgi |html %][% recentSearche.limit_cgi|html %]">[% recentSearche.query_desc|html %] [% recentSearche.limit_desc|html %]</a></td>
51
51
			<td>[% recentSearche.total %]</td>
52
			<td>[% recentSearche.total %]</td>
52
		    </tr>
53
		    </tr>
53
		    [% END %]
54
		    [% END %]
Lines 65-71 Link Here
65
		    [% FOREACH previousSearche IN previousSearches %]
66
		    [% FOREACH previousSearche IN previousSearches %]
66
		    <tr>
67
		    <tr>
67
			<td>[% previousSearche.time %]</td>
68
			<td>[% previousSearche.time %]</td>
68
			<td><a href="/cgi-bin/koha/opac-search.pl?[% previousSearche.query_cgi |html %]">[% previousSearche.query_desc |html %]</a></td>
69
			<td><a href="/cgi-bin/koha/opac-search.pl?[% previousSearche.query_cgi |html %][% previousSearche.limit_cgi|html %]">[% previousSearche.query_desc|html %] [% previousSearche.limit_desc|html %]</a></td>
69
			<td>[% previousSearche.total %]</td>
70
			<td>[% previousSearche.total %]</td>
70
		    </tr>
71
		    </tr>
71
		    [% END %]
72
		    [% END %]
(-)a/kohaversion.pl (-1 / +1 lines)
Lines 16-22 the kohaversion is divided in 4 parts : Link Here
16
use strict;
16
use strict;
17
17
18
sub kohaversion {
18
sub kohaversion {
19
    our $VERSION = '3.05.00.004';
19
    our $VERSION = '3.05.00.005';
20
    # version needs to be set this way
20
    # version needs to be set this way
21
    # so that it can be picked up by Makefile.PL
21
    # so that it can be picked up by Makefile.PL
22
    # during install
22
    # during install
(-)a/opac/opac-search-history.pl (-22 / +22 lines)
Lines 113-140 if (!$loggedinuser) { Link Here
113
    # Showing search history
113
    # Showing search history
114
    } else {
114
    } else {
115
115
116
	my $date = C4::Dates->new();
116
        my $date       = C4::Dates->new();
117
	my $dateformat = $date->DHTMLcalendar() . " %H:%i:%S"; # Current syspref date format + standard time format
117
        my $dateformat = $date->DHTMLcalendar() . " %H:%i:%S";    # Current syspref date format + standard time format
118
118
119
	# Getting the data with date format work done by mysql
119
        # Getting the data with date format work done by mysql
120
	my $query = "SELECT userid, sessionid, query_desc, query_cgi, total, DATE_FORMAT(time, \"$dateformat\") as time FROM search_history WHERE userid = ? AND sessionid = ?";
120
        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 = ?";
121
	my $sth   = $dbh->prepare($query);
121
        my $sth   = $dbh->prepare($query);
122
	$sth->execute($loggedinuser, $cgi->cookie("CGISESSID"));
122
        $sth->execute( $loggedinuser, $cgi->cookie("CGISESSID") );
123
	my $searches = $sth->fetchall_arrayref({});
123
        my $searches = $sth->fetchall_arrayref( {} );
124
	$template->param(recentSearches => $searches);
124
        $template->param( recentSearches => $searches );
125
	
125
126
	# Getting searches from previous sessions
126
        # Getting searches from previous sessions
127
	$query = "SELECT COUNT(*) FROM search_history WHERE userid = ? AND sessionid != ?";
127
        $query = "SELECT COUNT(*) FROM search_history WHERE userid = ? AND sessionid != ?";
128
	$sth   = $dbh->prepare($query);
128
        $sth   = $dbh->prepare($query);
129
	$sth->execute($loggedinuser, $cgi->cookie("CGISESSID"));
129
        $sth->execute( $loggedinuser, $cgi->cookie("CGISESSID") );
130
130
131
	# If at least one search from previous sessions has been performed
131
        # If at least one search from previous sessions has been performed
132
        if ($sth->fetchrow_array > 0) {
132
        if ( $sth->fetchrow_array > 0 ) {
133
	    $query = "SELECT userid, sessionid, query_desc, query_cgi, total, DATE_FORMAT(time, \"$dateformat\") as time FROM search_history WHERE userid = ? AND sessionid != ?";
133
            $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 != ?";
134
	    $sth   = $dbh->prepare($query);
134
            $sth   = $dbh->prepare($query);
135
	    $sth->execute($loggedinuser, $cgi->cookie("CGISESSID"));
135
            $sth->execute( $loggedinuser, $cgi->cookie("CGISESSID") );
136
    	    my $previoussearches = $sth->fetchall_arrayref({});
136
            my $previoussearches = $sth->fetchall_arrayref( {} );
137
    	    $template->param(previousSearches => $previoussearches);
137
            $template->param( previousSearches => $previoussearches );
138
	
138
	
139
	}
139
	}
140
140
(-)a/opac/opac-search.pl (-6 / +85 lines)
Lines 538-548 for (my $i=0;$i<@servers;$i++) { Link Here
538
     		}
538
     		}
539
 	    }
539
 	    }
540
 	}
540
 	}
541
    ## If there's just one result, redirect to the detail page
541
        my $tag_quantity;
542
        if ($total == 1 && $format ne 'rss2'
542
        if ( C4::Context->preference('TagsEnabled')
543
	    && $format ne 'opensearchdescription' && $format ne 'atom') {   
543
            and $tag_quantity = C4::Context->preference('TagsShowOnList') ) {
544
            my $biblionumber=$newresults[0]->{biblionumber};
544
            foreach (@newresults) {
545
            if (C4::Context->preference('BiblioDefaultView') eq 'isbd') {
545
                my $bibnum = $_->{biblionumber} or next;
546
                $_->{itemsissued} = CountItemsIssued($bibnum);
547
                $_->{'TagLoop'} = get_tags(
548
                    {   biblionumber => $bibnum,
549
                        approved     => 1,
550
                        'sort'       => '-weight',
551
                        limit        => $tag_quantity
552
                    }
553
                );
554
            }
555
        }
556
        foreach (@newresults) {
557
            $_->{coins} = GetCOinSBiblio( $_->{'biblionumber'} );
558
        }
559
560
        if ( $results_hashref->{$server}->{"hits"} ) {
561
            $total = $total + $results_hashref->{$server}->{"hits"};
562
        }
563
564
        # Opac search history
565
        my $newsearchcookie;
566
        if ( C4::Context->preference('EnableOpacSearchHistory') ) {
567
            my @recentSearches;
568
569
            # Getting the (maybe) already sent cookie
570
            my $searchcookie = $cgi->cookie('KohaOpacRecentSearches');
571
            if ($searchcookie) {
572
                $searchcookie = uri_unescape($searchcookie);
573
                if ( thaw($searchcookie) ) {
574
                    @recentSearches = @{ thaw($searchcookie) };
575
                }
576
            }
577
578
            # Adding the new search if needed
579
            if ( not defined $borrowernumber or $borrowernumber eq '' ) {
580
581
                # To a cookie (the user is not logged in)
582
583
                if ( not defined $params->{'offset'} or $params->{'offset'} eq '' ) {
584
                    push @recentSearches,
585
                      { "query_desc" => $query_desc || "unknown",
586
                        "query_cgi"  => $query_cgi  || "unknown",
587
                        "limit_desc" => $limit_desc,
588
                        "limit_cgi"  => $limit_cgi,
589
                        "time"       => time(),
590
                        "total"      => $total
591
                      };
592
                    $template->param( ShowOpacRecentSearchLink => 1 );
593
                }
594
595
		# Only the 15 more recent searches are kept
596
		# TODO: This has been done because of cookies' max size, which is
597
		# usually 4KB. A real check on cookie actual size would be better
598
		# than setting an arbitrary limit on the number of searches
599
		shift @recentSearches if (@recentSearches > 15);
600
601
                # Pushing the cookie back
602
                $newsearchcookie = $cgi->cookie(
603
                    -name => 'KohaOpacRecentSearches',
604
605
                    # We uri_escape the whole freezed structure so we're sure we won't have any encoding problems
606
                    -value   => uri_escape( freeze( \@recentSearches ) ),
607
                    -expires => ''
608
                );
609
                $cookie = [ $cookie, $newsearchcookie ];
610
            } else {
611
612
                # To the session (the user is logged in)
613
                if ( not defined $params->{'offset'} or $params->{'offset'} eq '' ) {
614
                    AddSearchHistory( $borrowernumber, $cgi->cookie("CGISESSID"), $query_desc, $query_cgi, $limit_desc, $limit_cgi, $total );
615
                    $template->param( ShowOpacRecentSearchLink => 1 );
616
                }
617
            }
618
        }
619
        ## If there's just one result, redirect to the detail page
620
        if (   $total == 1
621
            && $format ne 'rss2'
622
            && $format ne 'opensearchdescription'
623
            && $format ne 'atom' ) {
624
            my $biblionumber = $newresults[0]->{biblionumber};
625
            if ( C4::Context->preference('BiblioDefaultView') eq 'isbd' ) {
546
                print $cgi->redirect("/cgi-bin/koha/opac-ISBDdetail.pl?biblionumber=$biblionumber");
626
                print $cgi->redirect("/cgi-bin/koha/opac-ISBDdetail.pl?biblionumber=$biblionumber");
547
            } elsif  (C4::Context->preference('BiblioDefaultView') eq 'marc') {
627
            } elsif  (C4::Context->preference('BiblioDefaultView') eq 'marc') {
548
                print $cgi->redirect("/cgi-bin/koha/opac-MARCdetail.pl?biblionumber=$biblionumber");
628
                print $cgi->redirect("/cgi-bin/koha/opac-MARCdetail.pl?biblionumber=$biblionumber");
549
- 

Return to bug 5981