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

(-)a/C4/Auth.pm (-4 / +3 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 383-390 sub get_template_and_user { Link Here
383
            StaffSerialIssueDisplayCount => C4::Context->preference("StaffSerialIssueDisplayCount"),
383
            StaffSerialIssueDisplayCount => C4::Context->preference("StaffSerialIssueDisplayCount"),
384
            NoZebra                     => C4::Context->preference('NoZebra'),
384
            NoZebra                     => C4::Context->preference('NoZebra'),
385
        );
385
        );
386
    }
386
    } else {
387
    else {
388
        warn "template type should be OPAC, here it is=[" . $in->{'type'} . "]" unless ( $in->{'type'} eq 'opac' );
387
        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
388
        #TODO : replace LibraryName syspref with 'system name', and remove this html processing
390
        my $LibraryNameTitle = C4::Context->preference("LibraryName");
389
        my $LibraryNameTitle = C4::Context->preference("LibraryName");
(-)a/C4/Search.pm (-6 / +11 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
sub AddSearchHistory {
2538
	my ($borrowernumber,$session,$query_desc,$query_cgi, $total)=@_;
2543
    my ( $borrowernumber, $session, $query_desc, $query_cgi, $limit_desc, $limit_cgi, $total ) = @_;
2539
    my $dbh = C4::Context->dbh;
2544
    my $dbh = C4::Context->dbh;
2540
2545
2541
    # Add the request the user just made
2546
    # Add the request the user just made
2542
    my $sql = "INSERT INTO search_history(userid, sessionid, query_desc, query_cgi, total, time) VALUES(?, ?, ?, ?, ?, NOW())";
2547
    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);
2548
    my $sth = $dbh->prepare($sql);
2544
    $sth->execute($borrowernumber, $session, $query_desc, $query_cgi, $total);
2549
    $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);
2550
    return $dbh->last_insert_id( undef, 'search_history', undef, undef, undef );
2546
}
2551
}
2547
2552
2548
sub GetSearchHistory{
2553
sub GetSearchHistory{
(-)a/installer/data/mysql/kohastructure.sql (+2 lines)
Lines 1636-1641 CREATE TABLE IF NOT EXISTS `search_history` ( Link Here
1636
  `sessionid` varchar(32) NOT NULL,
1636
  `sessionid` varchar(32) NOT NULL,
1637
  `query_desc` varchar(255) NOT NULL,
1637
  `query_desc` varchar(255) NOT NULL,
1638
  `query_cgi` varchar(255) NOT NULL,
1638
  `query_cgi` varchar(255) NOT NULL,
1639
  `limit_desc` varchar(255) DEFAULT NULL,
1640
  `limit_cgi` varchar(255) DEFAULT NULL,
1639
  `total` int(11) NOT NULL,
1641
  `total` int(11) NOT NULL,
1640
  `time` timestamp NOT NULL default CURRENT_TIMESTAMP,
1642
  `time` timestamp NOT NULL default CURRENT_TIMESTAMP,
1641
  KEY `userid` (`userid`),
1643
  KEY `userid` (`userid`),
(-)a/installer/data/mysql/updatedatabase.pl (+10 lines)
Lines 4439-4444 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
4439
    SetVersion($DBversion);
4439
    SetVersion($DBversion);
4440
}
4440
}
4441
4441
4442
$DBversion = "3.05.00.XXX";
4443
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
4444
	$dbh->do(q{
4445
	ALTER TABLE `search_history` ADD `limit_desc` VARCHAR( 255 ) NULL DEFAULT NULL AFTER `query_cgi` ,
4446
	ADD `limit_cgi` VARCHAR( 255 ) NULL DEFAULT NULL AFTER `limit_desc` 
4447
    });
4448
	print "Upgrade to $DBversion done (adding limits to the opac search history)\n";
4449
	SetVersion ($DBversion);
4450
}
4451
4442
4452
4443
=head1 FUNCTIONS
4453
=head1 FUNCTIONS
4444
4454
(-)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 (-3 / +4 lines)
Lines 516-521 for (my $i=0;$i<@servers;$i++) { Link Here
516
     		    push @recentSearches, {
516
     		    push @recentSearches, {
517
     					    "query_desc" => $query_desc || "unknown", 
517
     					    "query_desc" => $query_desc || "unknown", 
518
     					    "query_cgi"  => $query_cgi  || "unknown", 
518
     					    "query_cgi"  => $query_cgi  || "unknown", 
519
                            "limit_desc" => $limit_desc,
520
                            "limit_cgi"  => $limit_cgi,
519
     					    "time"       => time(),
521
     					    "time"       => time(),
520
     					    "total"      => $total
522
     					    "total"      => $total
521
     					  };
523
     					  };
Lines 534-541 for (my $i=0;$i<@servers;$i++) { Link Here
534
 	    } 
536
 	    } 
535
		else {
537
		else {
536
 	    # To the session (the user is logged in)
538
 	    # To the session (the user is logged in)
537
                       if (($params->{'offset'}||'') eq '') {
539
            if (($params->{'offset'}||'') eq '') {
538
				AddSearchHistory($borrowernumber, $cgi->cookie("CGISESSID"), $query_desc, $query_cgi, $total);
540
                AddSearchHistory( $borrowernumber, $cgi->cookie("CGISESSID"), $query_desc, $query_cgi, $limit_desc, $limit_cgi, $total );
539
     		    $template->param(ShowOpacRecentSearchLink => 1);
541
     		    $template->param(ShowOpacRecentSearchLink => 1);
540
     		}
542
     		}
541
 	    }
543
 	    }
542
- 

Return to bug 5981