diff --git a/C4/XSLT.pm b/C4/XSLT.pm index 6600045a34..ffdc3ab975 100644 --- a/C4/XSLT.pm +++ b/C4/XSLT.pm @@ -189,7 +189,8 @@ sub XSLTParse4Display { Display856uAsImage OPACDisplay856uAsImage UseControlNumber IntranetBiblioDefaultView BiblioDefaultView singleBranchMode OPACItemLocation - AlternateHoldingsField AlternateHoldingsSeparator / ) + AlternateHoldingsField AlternateHoldingsSeparator + TrackClicks / ) { my $sp = C4::Context->preference( $syspref ); next unless defined($sp); diff --git a/Koha/Linktracker.pm b/Koha/Linktracker.pm new file mode 100644 index 0000000000..5255d06660 --- /dev/null +++ b/Koha/Linktracker.pm @@ -0,0 +1,67 @@ +package Koha::Linktracker; + +# Copyright 2013 chris@bigballofwax.co.nz +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +=head1 NAME + +Koha::Linktracker + +=head1 SYNOPSIS + + use Koha::Linktracker; + my $tracker = Koha::Linktracker->new(); + $tracker->trackclick( $linkinfo ); + +=head1 FUNCTIONS + +=cut + +use Modern::Perl; +use Carp; +use C4::Context; +use base qw(Class::Accessor); + +__PACKAGE__->mk_accessors(qw( trackingmethod )); + +sub trackclick { + my ( $self, $linkinfo ) = @_; + my $dbh = C4::Context->dbh(); + my $query = "INSERT INTO linktracker (biblionumber,itemnumber,borrowernumber + ,url,timeclicked) VALUES (?,?,?,?,now())"; + my $sth = $dbh->prepare($query); + $sth->execute( + $linkinfo->{biblionumber}, $linkinfo->{itemnumber}, + $linkinfo->{borrowernumber}, $linkinfo->{uri} + ); + +} + +=head2 EXPORT + +None by default. + + +=head1 AUTHOR + +Chris Cormack, Echris@bigballofwax.co.nzE + +=cut + +1; + +__END__ diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index ed673da455..d004fe1d64 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -3056,6 +3056,26 @@ CREATE TABLE IF NOT EXISTS `borrower_modifications` ( KEY `borrowernumber` (`borrowernumber`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +-- +-- Table structure for table linktracker +-- This stores clicks to external links +-- + +DROP TABLE IF EXISTS linktracker; +CREATE TABLE linktracker ( + id int(11) NOT NULL AUTO_INCREMENT, -- primary key identifier + biblionumber int(11) DEFAULT NULL, -- biblionumber of the record the link is from + itemnumber int(11) DEFAULT NULL, -- itemnumber if applicable that the link was from + borrowernumber int(11) DEFAULT NULL, -- borrowernumber who clicked the link + url text, -- the link itself + timeclicked datetime DEFAULT NULL, -- the date and time the link was clicked + PRIMARY KEY (id), + KEY bibidx (biblionumber), + KEY itemidx (itemnumber), + KEY borridx (borrowernumber), + KEY dateidx (timeclicked) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 40bbfed3d8..cad409c53d 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -417,3 +417,4 @@ INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ( INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('UNIMARCField100Language', 'fre','UNIMARC field 100 default language',NULL,'short'); INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('Persona',0,'Use Mozilla Persona for login','','YesNo'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacItemLocation','callnum','Show the shelving location of items in the opac','callnum|ccode|location','Choice'); +INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('TrackClicks','0','Track links clicked',NULL,'Integer'); diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 4fa2fccf4c..405e033cec 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -6444,6 +6444,30 @@ if ( CheckVersion($DBversion) ) { SetVersion($DBversion); } +$DBversion = "3.11.00.025"; +if ( CheckVersion($DBversion) ) { + $dbh->do( + "CREATE TABLE linktracker ( + id int(11) NOT NULL AUTO_INCREMENT, + biblionumber int(11) DEFAULT NULL, + itemnumber int(11) DEFAULT NULL, + borrowernumber int(11) DEFAULT NULL, + url text, + timeclicked datetime DEFAULT NULL, + PRIMARY KEY (id), + KEY bibidx (biblionumber), + KEY itemidx (itemnumber), + KEY borridx (borrowernumber), + KEY dateidx (timeclicked) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8;" + ); + $dbh->do( " + INSERT INTO systempreferences (variable,value,explanation,options,type) + VALUES('TrackClicks','0','Track links clicked',NULL,'Integer')" ); + print +"Upgrade to $DBversion done (Adds feature Bug 8917, the ability to track links clicked)\n"; + SetVersion($DBversion); +} $DBversion = "3.11.00.024"; if ( CheckVersion($DBversion) ) { diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref index f1be4494ab..57df5127a6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -525,6 +525,14 @@ OPAC: - pref: AnonymousPatron class: integer - as the Anonymous Patron (for anonymous suggestions and reading history) + - + - pref: TrackClicks + default: 0 + choices: + anonymous: "Track anonymously" + track: "Track" + no: "Don't track" + - links that patrons click on Shelf Browser: - diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt index cd58cb5738..6321efd3e9 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt @@ -715,9 +715,21 @@ YAHOO.util.Event.onContentReady("furtherm", function () {
  • [% IF ( MARCurl.part ) %][% MARCurl.part %]
    [% END %] - - [% IF ( OPACURLOpenInNewWindow ) %][% ELSE %][% END %] - + + [% IF ( OPACurlOpenInNewWindow ) %] + [% IF trackclicks == 'track' || trackclicks == 'anonymous' %] + + [% ELSE %] + + [% END %] + [% ELSE %] + [% IF trackclicks == 'track' || trackclicks == 'anonymous' %] + + [% ELSE %] + + [% END %] + [% END %] + [% MARCurl.linktext %] [% IF ( MARCurl.notes ) %]
      [% FOREACH note IN MARCurl.notes %]
    • [% note.note %]
    • [% END %]
    [% END %]
  • [% END %] @@ -1476,7 +1488,16 @@ YAHOO.util.Event.onContentReady("furtherm", function () { [% IF ( itemdata_ccode ) %][% ITEM_RESULT.ccode %][% END %] [% IF ( ITEM_RESULT.itemcallnumber ) %] [% ITEM_RESULT.itemcallnumber %][% IF ( OPACShelfBrowser ) %] (Browse shelf)[% END %][% END %] [% IF ( itemdata_enumchron ) %][% ITEM_RESULT.enumchron %][% END %] - [% IF ( itemdata_uri ) %][% ITEM_RESULT.uri %][% END %] + [% IF ( itemdata_uri ) %] + [% IF ITEM_RESULT.uri %] + [% IF trackclicks == 'track' || trackclicks == 'anonymous' %] + Link to resource + [% ELSE %] + [% ITEM_RESULT.uri %] + [% END %] + [% END %] + + [% END %] [% IF ( itemdata_copynumber ) %][% ITEM_RESULT.copynumber %][% END %] [% INCLUDE 'item-status.inc' item = ITEM_RESULT %] [% IF ( itemdata_itemnotes ) %][% ITEM_RESULT.itemnotes %][% END %] diff --git a/koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACDetail.xsl b/koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACDetail.xsl index 31cbb362ce..5130e8b11d 100644 --- a/koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACDetail.xsl +++ b/koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACDetail.xsl @@ -26,6 +26,8 @@ + + { @@ -550,7 +552,18 @@ Online resources: - + + + + /cgi-bin/koha/tracklinks.pl?uri=;biblionumber= + + + /cgi-bin/koha/tracklinks.pl?uri=;biblionumber= + + + + + _blank diff --git a/koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACResults.xsl b/koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACResults.xsl index cfcc2dd773..4335e504dc 100644 --- a/koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACResults.xsl +++ b/koha-tmpl/opac-tmpl/prog/en/xslt/MARC21slim2OPACResults.xsl @@ -29,6 +29,7 @@ + @@ -950,7 +951,18 @@ - + + + + /cgi-bin/koha/tracklinks.pl?uri=;biblionumber= + + + /cgi-bin/koha/tracklinks.pl?uri=;biblionumber= + + + + + 100 @@ -974,7 +986,18 @@ - + + + + /cgi-bin/koha/tracklinks.pl?uri=;biblionumber= + + + /cgi-bin/koha/tracklinks.pl?uri=;biblionumber= + + + + + 100 diff --git a/kohaversion.pl b/kohaversion.pl index 015f9d3415..7276d74785 100644 --- a/kohaversion.pl +++ b/kohaversion.pl @@ -16,7 +16,7 @@ the kohaversion is divided in 4 parts : use strict; sub kohaversion { - our $VERSION = '3.11.00.024'; + our $VERSION = '3.11.00.025'; # version needs to be set this way # so that it can be picked up by Makefile.PL # during install diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index bb9cbd5d7b..5b2da845d5 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -1006,5 +1006,6 @@ $template->{VARS}->{OPACPopupAuthorsSearch} = C4::Context->preference('OPACPopup if (C4::Context->preference('OpacHighlightedWords')) { $template->{VARS}->{query_desc} = $query->param('query_desc'); } +$template->{VARS}->{'trackclicks'} = C4::Context->preference('TrackClicks'); output_html_with_http_headers $query, $cookie, $template->output; diff --git a/opac/tracklinks.pl b/opac/tracklinks.pl new file mode 100755 index 0000000000..7182fdb4ee --- /dev/null +++ b/opac/tracklinks.pl @@ -0,0 +1,78 @@ +#!/usr/bin/perl + +# script to log clicks on links to external urls + +# Copyright 2012 Catalyst IT +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; +use C4::Context; +use C4::Auth qw(checkauth); +use Koha::Linktracker; +use CGI; + +my $cgi = new CGI; +my $uri = $cgi->param('uri') || ''; + +my $tracker = Koha::Linktracker->new( + { trackingmethod => C4::Context->preference('TrackClicks') } ); + +if ($uri) { + if ( $tracker->trackingmethod() eq 'track' + || $tracker->trackingmethod() eq 'anonymous' ) + { + my $borrowernumber = 0; + + # we have a uri and we want to track + if ( $tracker->trackingmethod() eq 'track' ) { + my ( $user, $cookie, $sessionID, $flags ) = + checkauth( $cgi, 1, {}, 'opac' ); + my $userenv = C4::Context->userenv; + + if ( defined($userenv) + && ref($userenv) eq 'HASH' + && $userenv->{number} ) + { + $borrowernumber = $userenv->{number}; + } + + # get borrower info + } + my $biblionumber = $cgi->param('biblionumber') || 0; + my $itemnumber = $cgi->param('itemnumber') || 0; + + $tracker->trackclick( + { + uri => $uri, + biblionumber => $biblionumber, + borrowernumber => $borrowernumber, + itemnumber => $itemnumber + } + ); + print $cgi->redirect($uri); + } + else { + + # We have a valid url, but we shouldn't track it, just redirect + print $cgi->redirect($uri); + } +} +else { + + # we shouldn't be here, bail out + print $cgi->redirect("/cgi-bin/koha/errors/404.pl"); # escape early + exit; +}