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

(-)a/C4/Auth.pm (-4 / +7 lines)
Lines 121-128 Output.pm module. Link Here
121
=cut
121
=cut
122
122
123
my $SEARCH_HISTORY_INSERT_SQL =<<EOQ;
123
my $SEARCH_HISTORY_INSERT_SQL =<<EOQ;
124
INSERT INTO search_history(userid, sessionid, query_desc, query_cgi, total, time            )
124
INSERT INTO search_history(userid, sessionid, query_desc, query_cgi, limit_desc, limit_cgi, total, time            )
125
VALUES                    (     ?,         ?,          ?,         ?,     ?, FROM_UNIXTIME(?))
125
VALUES                    (     ?,         ?,          ?,         ?,          ?,         ?,     ?, FROM_UNIXTIME(?))
126
EOQ
126
EOQ
127
sub get_template_and_user {
127
sub get_template_and_user {
128
    my $in       = shift;
128
    my $in       = shift;
Lines 356-361 sub get_template_and_user { Link Here
356
            IntranetmainUserblock       => C4::Context->preference("IntranetmainUserblock"),
356
            IntranetmainUserblock       => C4::Context->preference("IntranetmainUserblock"),
357
            LibraryName                 => C4::Context->preference("LibraryName"),
357
            LibraryName                 => C4::Context->preference("LibraryName"),
358
            LoginBranchname             => (C4::Context->userenv?C4::Context->userenv->{"branchname"}:"insecure"),
358
            LoginBranchname             => (C4::Context->userenv?C4::Context->userenv->{"branchname"}:"insecure"),
359
            TemplateEncoding                                                           => C4::Context->preference("TemplateEncoding"),
359
            advancedMARCEditor          => C4::Context->preference("advancedMARCEditor"),
360
            advancedMARCEditor          => C4::Context->preference("advancedMARCEditor"),
360
            canreservefromotherbranches => C4::Context->preference('canreservefromotherbranches'),
361
            canreservefromotherbranches => C4::Context->preference('canreservefromotherbranches'),
361
            intranetcolorstylesheet     => C4::Context->preference("intranetcolorstylesheet"),
362
            intranetcolorstylesheet     => C4::Context->preference("intranetcolorstylesheet"),
Lines 369-377 sub get_template_and_user { Link Here
369
            virtualshelves              => C4::Context->preference("virtualshelves"),
370
            virtualshelves              => C4::Context->preference("virtualshelves"),
370
            StaffSerialIssueDisplayCount => C4::Context->preference("StaffSerialIssueDisplayCount"),
371
            StaffSerialIssueDisplayCount => C4::Context->preference("StaffSerialIssueDisplayCount"),
371
            NoZebra                     => C4::Context->preference('NoZebra'),
372
            NoZebra                     => C4::Context->preference('NoZebra'),
373
            IntranetXSLTDetailsDisplay                                                 => C4::Context->preference("IntranetXSLTDetailsDisplay"),
374
            IntranetXSLTResultsDisplay                                                 => C4::Context->preference("IntranetXSLTResultsDisplay"),
372
        );
375
        );
373
    }
376
    } else {
374
    else {
375
        warn "template type should be OPAC, here it is=[" . $in->{'type'} . "]" unless ( $in->{'type'} eq 'opac' );
377
        warn "template type should be OPAC, here it is=[" . $in->{'type'} . "]" unless ( $in->{'type'} eq 'opac' );
376
        #TODO : replace LibraryName syspref with 'system name', and remove this html processing
378
        #TODO : replace LibraryName syspref with 'system name', and remove this html processing
377
        my $LibraryNameTitle = C4::Context->preference("LibraryName");
379
        my $LibraryNameTitle = C4::Context->preference("LibraryName");
Lines 421-426 sub get_template_and_user { Link Here
421
            OPACFinesTab              => C4::Context->preference("OPACFinesTab"),
423
            OPACFinesTab              => C4::Context->preference("OPACFinesTab"),
422
            OpacTopissue              => C4::Context->preference("OpacTopissue"),
424
            OpacTopissue              => C4::Context->preference("OpacTopissue"),
423
            RequestOnOpac             => C4::Context->preference("RequestOnOpac"),
425
            RequestOnOpac             => C4::Context->preference("RequestOnOpac"),
426
            TemplateEncoding               => "" . C4::Context->preference("TemplateEncoding"),
424
            'Version'                 => C4::Context->preference('Version'),
427
            'Version'                 => C4::Context->preference('Version'),
425
            hidelostitems             => C4::Context->preference("hidelostitems"),
428
            hidelostitems             => C4::Context->preference("hidelostitems"),
426
            mylibraryfirst            => (C4::Context->preference("SearchMyLibraryFirst") && C4::Context->userenv) ? C4::Context->userenv->{'branch'} : '',
429
            mylibraryfirst            => (C4::Context->preference("SearchMyLibraryFirst") && C4::Context->userenv) ? C4::Context->userenv->{'branch'} : '',
(-)a/C4/Search.pm (-6 / +42 lines)
Lines 1223-1228 sub buildQuery { Link Here
1223
                        $truncated_operand .= $index_plus_comma . "rltrn:@$rightlefttruncated ";
1223
                        $truncated_operand .= $index_plus_comma . "rltrn:@$rightlefttruncated ";
1224
                        $previous_truncation_operand = 1;
1224
                        $previous_truncation_operand = 1;
1225
                    }
1225
                    }
1226
                    if ( scalar @$regexpr ) {
1227
                        $truncated_operand .= "and " if $previous_truncation_operand;
1228
                        $truncated_operand .= $index_plus_comma . "regExpr-1:@$regexpr ";
1229
                        $previous_truncation_operand = 1;
1230
                    }
1226
                }
1231
                }
1227
                $operand = $truncated_operand if $truncated_operand;
1232
                $operand = $truncated_operand if $truncated_operand;
1228
                warn "TRUNCATED OPERAND: >$truncated_operand<" if $DEBUG;
1233
                warn "TRUNCATED OPERAND: >$truncated_operand<" if $DEBUG;
Lines 2473-2487 sub enabled_staff_search_views Link Here
2473
	);
2478
	);
2474
}
2479
}
2475
2480
2476
sub AddSearchHistory{
2481
=head2 enabled_opac_search_views
2477
	my ($borrowernumber,$session,$query_desc,$query_cgi, $total)=@_;
2482
2483
%hash = enabled_opac_search_views()
2484
2485
This function returns a hash that contains two flags obtained from the system
2486
preferences, used to determine whether a particular opac search results view
2487
is enabled.
2488
2489
=over 2
2490
2491
=item C<Output arg:>
2492
2493
    * $hash{can_view_MARC} is true only if the MARC view is enabled
2494
    * $hash{can_view_ISBD} is true only if the ISBD view is enabled
2495
2496
=item C<usage in the script:>
2497
2498
=back
2499
2500
$template->param ( C4::Search::enabled_opac_search_views );
2501
2502
=cut
2503
2504
sub enabled_opac_search_views
2505
{
2506
	return (
2507
		can_opac_view_MARC		=> C4::Context->preference('OPACviewMARC'),		# 1 if the opac search allows the MARC view
2508
		can_opac_view_ISBD		=> C4::Context->preference('OPACviewISBD'),		# 1 if the opac search allows the ISBD view
2509
	);
2510
}
2511
2512
sub AddSearchHistory {
2513
    my ( $borrowernumber, $session, $query_desc, $query_cgi, $limit_desc, $limit_cgi, $total ) = @_;
2478
    my $dbh = C4::Context->dbh;
2514
    my $dbh = C4::Context->dbh;
2479
2515
2480
    # Add the request the user just made
2516
    # Add the request the user just made
2481
    my $sql = "INSERT INTO search_history(userid, sessionid, query_desc, query_cgi, total, time) VALUES(?, ?, ?, ?, ?, NOW())";
2517
    my $sql = "INSERT INTO search_history(userid, sessionid, query_desc, query_cgi, limit_desc, limit_cgi, total, time) VALUES(?, ?, ?, ?, ?, ?, ?, NOW())";
2482
    my $sth   = $dbh->prepare($sql);
2518
    my $sth = $dbh->prepare($sql);
2483
    $sth->execute($borrowernumber, $session, $query_desc, $query_cgi, $total);
2519
    $sth->execute( $borrowernumber, $session, $query_desc, $query_cgi, $limit_desc, $limit_cgi, $total );
2484
	return $dbh->last_insert_id(undef, 'search_history', undef,undef,undef);
2520
    return $dbh->last_insert_id( undef, 'search_history', undef, undef, undef );
2485
}
2521
}
2486
2522
2487
sub GetSearchHistory{
2523
sub GetSearchHistory{
(-)a/installer/data/mysql/kohastructure.sql (+2 lines)
Lines 1623-1628 CREATE TABLE IF NOT EXISTS `search_history` ( Link Here
1623
  `sessionid` varchar(32) NOT NULL,
1623
  `sessionid` varchar(32) NOT NULL,
1624
  `query_desc` varchar(255) NOT NULL,
1624
  `query_desc` varchar(255) NOT NULL,
1625
  `query_cgi` varchar(255) NOT NULL,
1625
  `query_cgi` varchar(255) NOT NULL,
1626
  `limit_desc` varchar(255) DEFAULT NULL,
1627
  `limit_cgi` varchar(255) DEFAULT NULL,
1626
  `total` int(11) NOT NULL,
1628
  `total` int(11) NOT NULL,
1627
  `time` timestamp NOT NULL default CURRENT_TIMESTAMP,
1629
  `time` timestamp NOT NULL default CURRENT_TIMESTAMP,
1628
  KEY `userid` (`userid`),
1630
  KEY `userid` (`userid`),
(-)a/installer/data/mysql/updatedatabase.pl (+13 lines)
Lines 4134-4143 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
4134
    SetVersion ($DBversion);
4134
    SetVersion ($DBversion);
4135
}
4135
}
4136
4136
4137
$DBversion = "3.03.00.XXX";
4138
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
4139
	$dbh->do(q{
4140
	ALTER TABLE `search_history` ADD `limit_desc` VARCHAR( 255 ) NULL DEFAULT NULL AFTER `query_cgi` ,
4141
	ADD `limit_cgi` VARCHAR( 255 ) NULL DEFAULT NULL AFTER `limit_desc` 
4142
    });
4143
	print "Upgrade to $DBversion done (adding limits to the opac search history)\n";
4144
	SetVersion ($DBversion);
4145
}
4146
4147
4137
=head1 FUNCTIONS
4148
=head1 FUNCTIONS
4138
4149
4139
=head2 DropAllForeignKeys($table)
4150
=head2 DropAllForeignKeys($table)
4140
4151
4152
=item DropAllForeignKeys($table)
4153
4141
Drop all foreign keys of the table $table
4154
Drop all foreign keys of the table $table
4142
4155
4143
=cut
4156
=cut
(-)a/koha-tmpl/opac-tmpl/prog/en/modules/opac-search-history.tmpl (-2 / +2 lines)
Lines 47-53 Link Here
47
		    <!-- TMPL_LOOP NAME="recentSearches" -->
47
		    <!-- TMPL_LOOP NAME="recentSearches" -->
48
		    <tr>
48
		    <tr>
49
			<td><!-- TMPL_VAR NAME="time" --></td>
49
			<td><!-- TMPL_VAR NAME="time" --></td>
50
			<td><a href="/cgi-bin/koha/opac-search.pl?<!-- TMPL_VAR NAME="query_cgi" ESCAPE="html" -->"><!-- TMPL_VAR NAME="query_desc" ESCAPE="html" --></a></td>
50
			<td><a href="/cgi-bin/koha/opac-search.pl?<!-- TMPL_VAR NAME="query_cgi" ESCAPE="html" --><!-- TMPL_VAR NAME="limit_cgi" ESCAPE="html" -->"><!-- TMPL_VAR NAME="query_desc" ESCAPE="html" --> <!-- TMPL_VAR NAME="limit_desc" ESCAPE="html" --></a></td>
51
			<td><!-- TMPL_VAR NAME="total" --></td>
51
			<td><!-- TMPL_VAR NAME="total" --></td>
52
		    </tr>
52
		    </tr>
53
		    <!-- /TMPL_LOOP -->
53
		    <!-- /TMPL_LOOP -->
Lines 65-71 Link Here
65
		    <!-- TMPL_LOOP NAME="previousSearches" -->
65
		    <!-- TMPL_LOOP NAME="previousSearches" -->
66
		    <tr>
66
		    <tr>
67
			<td><!-- TMPL_VAR NAME="time" --></td>
67
			<td><!-- TMPL_VAR NAME="time" --></td>
68
			<td><a href="/cgi-bin/koha/opac-search.pl?<!-- TMPL_VAR NAME="query_cgi" ESCAPE="html" -->"><!-- TMPL_VAR NAME="query_desc" ESCAPE="html" --></a></td>
68
			<td><a href="/cgi-bin/koha/opac-search.pl?<!-- TMPL_VAR NAME="query_cgi" ESCAPE="html" --><!-- TMPL_VAR NAME="limit_cgi" ESCAPE="html" -->"><!-- TMPL_VAR NAME="query_desc" ESCAPE="html" --> <!-- TMPL_VAR NAME="limit_desc" ESCAPE="html" --></a></td>
69
			<td><!-- TMPL_VAR NAME="total" --></td>
69
			<td><!-- TMPL_VAR NAME="total" --></td>
70
		    </tr>
70
		    </tr>
71
		    <!-- /TMPL_LOOP -->
71
		    <!-- /TMPL_LOOP -->
(-)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 (-3 / +87 lines)
Lines 455-462 for (my $i=0;$i<@servers;$i++) { Link Here
455
                push @newresults, { group_label => $group->{'group_label'}, GROUP_RESULTS => \@group_results };
455
                push @newresults, { group_label => $group->{'group_label'}, GROUP_RESULTS => \@group_results };
456
            }
456
            }
457
        } else {
457
        } else {
458
            @newresults = searchResults('opac', $query_desc, $hits, $results_per_page, $offset, $scan,
458
            @newresults =
459
                                        @{$results_hashref->{$server}->{"RECORDS"}},, C4::Context->preference('hidelostitems'));
459
              searchResults( $query_desc, $hits, $results_per_page, $offset, $scan, @{ $results_hashref->{$server}->{"RECORDS"} },, C4::Context->preference('hidelostitems') );
460
        }
460
        }
461
		my $tag_quantity;
461
		my $tag_quantity;
462
		if (C4::Context->preference('TagsEnabled') and
462
		if (C4::Context->preference('TagsEnabled') and
Lines 526-531 for (my $i=0;$i<@servers;$i++) { Link Here
526
	    && $format ne 'opensearchdescription' && $format ne 'atom') {   
526
	    && $format ne 'opensearchdescription' && $format ne 'atom') {   
527
            my $biblionumber=$newresults[0]->{biblionumber};
527
            my $biblionumber=$newresults[0]->{biblionumber};
528
            if (C4::Context->preference('BiblioDefaultView') eq 'isbd') {
528
            if (C4::Context->preference('BiblioDefaultView') eq 'isbd') {
529
        my $tag_quantity;
530
        if ( C4::Context->preference('TagsEnabled')
531
            and $tag_quantity = C4::Context->preference('TagsShowOnList') ) {
532
            foreach (@newresults) {
533
                my $bibnum = $_->{biblionumber} or next;
534
                $_->{itemsissued} = CountItemsIssued($bibnum);
535
                $_->{'TagLoop'} = get_tags(
536
                    {   biblionumber => $bibnum,
537
                        approved     => 1,
538
                        'sort'       => '-weight',
539
                        limit        => $tag_quantity
540
                    }
541
                );
542
            }
543
        }
544
        foreach (@newresults) {
545
            $_->{coins} = GetCOinSBiblio( $_->{'biblionumber'} );
546
        }
547
548
        if ( $results_hashref->{$server}->{"hits"} ) {
549
            $total = $total + $results_hashref->{$server}->{"hits"};
550
        }
551
552
        # Opac search history
553
        my $newsearchcookie;
554
        if ( C4::Context->preference('EnableOpacSearchHistory') ) {
555
            my @recentSearches;
556
557
            # Getting the (maybe) already sent cookie
558
            my $searchcookie = $cgi->cookie('KohaOpacRecentSearches');
559
            if ($searchcookie) {
560
                $searchcookie = uri_unescape($searchcookie);
561
                if ( thaw($searchcookie) ) {
562
                    @recentSearches = @{ thaw($searchcookie) };
563
                }
564
            }
565
566
            # Adding the new search if needed
567
            if ( not defined $borrowernumber or $borrowernumber eq '' ) {
568
569
                # To a cookie (the user is not logged in)
570
571
                if ( not defined $params->{'offset'} or $params->{'offset'} eq '' ) {
572
                    push @recentSearches,
573
                      { "query_desc" => $query_desc || "unknown",
574
                        "query_cgi"  => $query_cgi  || "unknown",
575
                        "limit_desc" => $limit_desc,
576
                        "limit_cgi"  => $limit_cgi,
577
                        "time"       => time(),
578
                        "total"      => $total
579
                      };
580
                    $template->param( ShowOpacRecentSearchLink => 1 );
581
                }
582
583
		# Only the 15 more recent searches are kept
584
		# TODO: This has been done because of cookies' max size, which is
585
		# usually 4KB. A real check on cookie actual size would be better
586
		# than setting an arbitrary limit on the number of searches
587
		shift @recentSearches if (@recentSearches > 15);
588
589
                # Pushing the cookie back
590
                $newsearchcookie = $cgi->cookie(
591
                    -name => 'KohaOpacRecentSearches',
592
593
                    # We uri_escape the whole freezed structure so we're sure we won't have any encoding problems
594
                    -value   => uri_escape( freeze( \@recentSearches ) ),
595
                    -expires => ''
596
                );
597
                $cookie = [ $cookie, $newsearchcookie ];
598
            } else {
599
600
                # To the session (the user is logged in)
601
                if ( not defined $params->{'offset'} or $params->{'offset'} eq '' ) {
602
                    AddSearchHistory( $borrowernumber, $cgi->cookie("CGISESSID"), $query_desc, $query_cgi, $limit_desc, $limit_cgi, $total );
603
                    $template->param( ShowOpacRecentSearchLink => 1 );
604
                }
605
            }
606
        }
607
        ## If there's just one result, redirect to the detail page
608
        if (   $total == 1
609
            && $format ne 'rss2'
610
            && $format ne 'opensearchdescription'
611
            && $format ne 'atom' ) {
612
            my $biblionumber = $newresults[0]->{biblionumber};
613
            if ( C4::Context->preference('BiblioDefaultView') eq 'isbd' ) {
529
                print $cgi->redirect("/cgi-bin/koha/opac-ISBDdetail.pl?biblionumber=$biblionumber");
614
                print $cgi->redirect("/cgi-bin/koha/opac-ISBDdetail.pl?biblionumber=$biblionumber");
530
            } elsif  (C4::Context->preference('BiblioDefaultView') eq 'marc') {
615
            } elsif  (C4::Context->preference('BiblioDefaultView') eq 'marc') {
531
                print $cgi->redirect("/cgi-bin/koha/opac-MARCdetail.pl?biblionumber=$biblionumber");
616
                print $cgi->redirect("/cgi-bin/koha/opac-MARCdetail.pl?biblionumber=$biblionumber");
532
- 

Return to bug 5981