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 369-374 sub get_template_and_user { Link Here
369
            IntranetmainUserblock       => C4::Context->preference("IntranetmainUserblock"),
369
            IntranetmainUserblock       => C4::Context->preference("IntranetmainUserblock"),
370
            LibraryName                 => C4::Context->preference("LibraryName"),
370
            LibraryName                 => C4::Context->preference("LibraryName"),
371
            LoginBranchname             => (C4::Context->userenv?C4::Context->userenv->{"branchname"}:"insecure"),
371
            LoginBranchname             => (C4::Context->userenv?C4::Context->userenv->{"branchname"}:"insecure"),
372
            TemplateEncoding                                                           => C4::Context->preference("TemplateEncoding"),
372
            advancedMARCEditor          => C4::Context->preference("advancedMARCEditor"),
373
            advancedMARCEditor          => C4::Context->preference("advancedMARCEditor"),
373
            canreservefromotherbranches => C4::Context->preference('canreservefromotherbranches'),
374
            canreservefromotherbranches => C4::Context->preference('canreservefromotherbranches'),
374
            intranetcolorstylesheet     => C4::Context->preference("intranetcolorstylesheet"),
375
            intranetcolorstylesheet     => C4::Context->preference("intranetcolorstylesheet"),
Lines 382-390 sub get_template_and_user { Link Here
382
            virtualshelves              => C4::Context->preference("virtualshelves"),
383
            virtualshelves              => C4::Context->preference("virtualshelves"),
383
            StaffSerialIssueDisplayCount => C4::Context->preference("StaffSerialIssueDisplayCount"),
384
            StaffSerialIssueDisplayCount => C4::Context->preference("StaffSerialIssueDisplayCount"),
384
            NoZebra                     => C4::Context->preference('NoZebra'),
385
            NoZebra                     => C4::Context->preference('NoZebra'),
386
            IntranetXSLTDetailsDisplay                                                 => C4::Context->preference("IntranetXSLTDetailsDisplay"),
387
            IntranetXSLTResultsDisplay                                                 => C4::Context->preference("IntranetXSLTResultsDisplay"),
385
        );
388
        );
386
    }
389
    } else {
387
    else {
388
        warn "template type should be OPAC, here it is=[" . $in->{'type'} . "]" unless ( $in->{'type'} eq 'opac' );
390
        warn "template type should be OPAC, here it is=[" . $in->{'type'} . "]" unless ( $in->{'type'} eq 'opac' );
389
        #TODO : replace LibraryName syspref with 'system name', and remove this html processing
391
        #TODO : replace LibraryName syspref with 'system name', and remove this html processing
390
        my $LibraryNameTitle = C4::Context->preference("LibraryName");
392
        my $LibraryNameTitle = C4::Context->preference("LibraryName");
Lines 443-448 sub get_template_and_user { Link Here
443
            OPACFinesTab              => C4::Context->preference("OPACFinesTab"),
445
            OPACFinesTab              => C4::Context->preference("OPACFinesTab"),
444
            OpacTopissue              => C4::Context->preference("OpacTopissue"),
446
            OpacTopissue              => C4::Context->preference("OpacTopissue"),
445
            RequestOnOpac             => C4::Context->preference("RequestOnOpac"),
447
            RequestOnOpac             => C4::Context->preference("RequestOnOpac"),
448
            TemplateEncoding               => "" . C4::Context->preference("TemplateEncoding"),
446
            'Version'                 => C4::Context->preference('Version'),
449
            'Version'                 => C4::Context->preference('Version'),
447
            hidelostitems             => C4::Context->preference("hidelostitems"),
450
            hidelostitems             => C4::Context->preference("hidelostitems"),
448
            mylibraryfirst            => (C4::Context->preference("SearchMyLibraryFirst") && C4::Context->userenv) ? C4::Context->userenv->{'branch'} : '',
451
            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 1635-1640 CREATE TABLE IF NOT EXISTS `search_history` ( Link Here
1635
  `sessionid` varchar(32) NOT NULL,
1635
  `sessionid` varchar(32) NOT NULL,
1636
  `query_desc` varchar(255) NOT NULL,
1636
  `query_desc` varchar(255) NOT NULL,
1637
  `query_cgi` varchar(255) NOT NULL,
1637
  `query_cgi` varchar(255) NOT NULL,
1638
  `limit_desc` varchar(255) DEFAULT NULL,
1639
  `limit_cgi` varchar(255) DEFAULT NULL,
1638
  `total` int(11) NOT NULL,
1640
  `total` int(11) NOT NULL,
1639
  `time` timestamp NOT NULL default CURRENT_TIMESTAMP,
1641
  `time` timestamp NOT NULL default CURRENT_TIMESTAMP,
1640
  KEY `userid` (`userid`),
1642
  KEY `userid` (`userid`),
(-)a/installer/data/mysql/updatedatabase.pl (+11 lines)
Lines 4399-4404 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
4399
    SetVersion($DBversion);
4399
    SetVersion($DBversion);
4400
}
4400
}
4401
4401
4402
$DBversion = "3.05.00.XXX";
4403
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
4404
	$dbh->do(q{
4405
	ALTER TABLE `search_history` ADD `limit_desc` VARCHAR( 255 ) NULL DEFAULT NULL AFTER `query_cgi` ,
4406
	ADD `limit_cgi` VARCHAR( 255 ) NULL DEFAULT NULL AFTER `limit_desc` 
4407
    });
4408
	print "Upgrade to $DBversion done (adding limits to the opac search history)\n";
4409
	SetVersion ($DBversion);
4410
}
4411
4412
4402
=head1 FUNCTIONS
4413
=head1 FUNCTIONS
4403
4414
4404
=head2 DropAllForeignKeys($table)
4415
=head2 DropAllForeignKeys($table)
(-)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/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 541-551 for (my $i=0;$i<@servers;$i++) { Link Here
541
     		}
541
     		}
542
 	    }
542
 	    }
543
 	}
543
 	}
544
    ## If there's just one result, redirect to the detail page
544
        my $tag_quantity;
545
        if ($total == 1 && $format ne 'rss2'
545
        if ( C4::Context->preference('TagsEnabled')
546
	    && $format ne 'opensearchdescription' && $format ne 'atom') {   
546
            and $tag_quantity = C4::Context->preference('TagsShowOnList') ) {
547
            my $biblionumber=$newresults[0]->{biblionumber};
547
            foreach (@newresults) {
548
            if (C4::Context->preference('BiblioDefaultView') eq 'isbd') {
548
                my $bibnum = $_->{biblionumber} or next;
549
                $_->{itemsissued} = CountItemsIssued($bibnum);
550
                $_->{'TagLoop'} = get_tags(
551
                    {   biblionumber => $bibnum,
552
                        approved     => 1,
553
                        'sort'       => '-weight',
554
                        limit        => $tag_quantity
555
                    }
556
                );
557
            }
558
        }
559
        foreach (@newresults) {
560
            $_->{coins} = GetCOinSBiblio( $_->{'biblionumber'} );
561
        }
562
563
        if ( $results_hashref->{$server}->{"hits"} ) {
564
            $total = $total + $results_hashref->{$server}->{"hits"};
565
        }
566
567
        # Opac search history
568
        my $newsearchcookie;
569
        if ( C4::Context->preference('EnableOpacSearchHistory') ) {
570
            my @recentSearches;
571
572
            # Getting the (maybe) already sent cookie
573
            my $searchcookie = $cgi->cookie('KohaOpacRecentSearches');
574
            if ($searchcookie) {
575
                $searchcookie = uri_unescape($searchcookie);
576
                if ( thaw($searchcookie) ) {
577
                    @recentSearches = @{ thaw($searchcookie) };
578
                }
579
            }
580
581
            # Adding the new search if needed
582
            if ( not defined $borrowernumber or $borrowernumber eq '' ) {
583
584
                # To a cookie (the user is not logged in)
585
586
                if ( not defined $params->{'offset'} or $params->{'offset'} eq '' ) {
587
                    push @recentSearches,
588
                      { "query_desc" => $query_desc || "unknown",
589
                        "query_cgi"  => $query_cgi  || "unknown",
590
                        "limit_desc" => $limit_desc,
591
                        "limit_cgi"  => $limit_cgi,
592
                        "time"       => time(),
593
                        "total"      => $total
594
                      };
595
                    $template->param( ShowOpacRecentSearchLink => 1 );
596
                }
597
598
		# Only the 15 more recent searches are kept
599
		# TODO: This has been done because of cookies' max size, which is
600
		# usually 4KB. A real check on cookie actual size would be better
601
		# than setting an arbitrary limit on the number of searches
602
		shift @recentSearches if (@recentSearches > 15);
603
604
                # Pushing the cookie back
605
                $newsearchcookie = $cgi->cookie(
606
                    -name => 'KohaOpacRecentSearches',
607
608
                    # We uri_escape the whole freezed structure so we're sure we won't have any encoding problems
609
                    -value   => uri_escape( freeze( \@recentSearches ) ),
610
                    -expires => ''
611
                );
612
                $cookie = [ $cookie, $newsearchcookie ];
613
            } else {
614
615
                # To the session (the user is logged in)
616
                if ( not defined $params->{'offset'} or $params->{'offset'} eq '' ) {
617
                    AddSearchHistory( $borrowernumber, $cgi->cookie("CGISESSID"), $query_desc, $query_cgi, $limit_desc, $limit_cgi, $total );
618
                    $template->param( ShowOpacRecentSearchLink => 1 );
619
                }
620
            }
621
        }
622
        ## If there's just one result, redirect to the detail page
623
        if (   $total == 1
624
            && $format ne 'rss2'
625
            && $format ne 'opensearchdescription'
626
            && $format ne 'atom' ) {
627
            my $biblionumber = $newresults[0]->{biblionumber};
628
            if ( C4::Context->preference('BiblioDefaultView') eq 'isbd' ) {
549
                print $cgi->redirect("/cgi-bin/koha/opac-ISBDdetail.pl?biblionumber=$biblionumber");
629
                print $cgi->redirect("/cgi-bin/koha/opac-ISBDdetail.pl?biblionumber=$biblionumber");
550
            } elsif  (C4::Context->preference('BiblioDefaultView') eq 'marc') {
630
            } elsif  (C4::Context->preference('BiblioDefaultView') eq 'marc') {
551
                print $cgi->redirect("/cgi-bin/koha/opac-MARCdetail.pl?biblionumber=$biblionumber");
631
                print $cgi->redirect("/cgi-bin/koha/opac-MARCdetail.pl?biblionumber=$biblionumber");
552
- 

Return to bug 5981