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

(-)a/C4/Auth.pm (-2 / +3 lines)
Lines 487-492 sub get_template_and_user { Link Here
487
            SyndeticsSeries              => C4::Context->preference("SyndeticsSeries"),
487
            SyndeticsSeries              => C4::Context->preference("SyndeticsSeries"),
488
            SyndeticsCoverImageSize      => C4::Context->preference("SyndeticsCoverImageSize"),
488
            SyndeticsCoverImageSize      => C4::Context->preference("SyndeticsCoverImageSize"),
489
            OPACLocalCoverImages         => C4::Context->preference("OPACLocalCoverImages"),
489
            OPACLocalCoverImages         => C4::Context->preference("OPACLocalCoverImages"),
490
            RatingsEnabled               => C4::Context->preference("RatingsEnabled"),
490
        );
491
        );
491
492
492
        $template->param(OpacPublic => '1') if ($user || C4::Context->preference("OpacPublic"));
493
        $template->param(OpacPublic => '1') if ($user || C4::Context->preference("OpacPublic"));
Lines 982-990 sub checkauth { Link Here
982
        OpacAuthorities      => C4::Context->preference("OpacAuthorities"),
983
        OpacAuthorities      => C4::Context->preference("OpacAuthorities"),
983
        OpacBrowser          => C4::Context->preference("OpacBrowser"),
984
        OpacBrowser          => C4::Context->preference("OpacBrowser"),
984
        opacheader           => C4::Context->preference("opacheader"),
985
        opacheader           => C4::Context->preference("opacheader"),
985
        TagsEnabled                  => C4::Context->preference("TagsEnabled"),
986
        OPACUserCSS           => C4::Context->preference("OPACUserCSS"),
987
        opacstylesheet       => C4::Context->preference("opacstylesheet"),
986
        opacstylesheet       => C4::Context->preference("opacstylesheet"),
987
        TagsEnabled          => C4::Context->preference("TagsEnabled"),
988
        OPACUserCSS          => C4::Context->preference("OPACUserCSS"),
988
        intranetcolorstylesheet =>
989
        intranetcolorstylesheet =>
989
								C4::Context->preference("intranetcolorstylesheet"),
990
								C4::Context->preference("intranetcolorstylesheet"),
990
        intranetstylesheet => C4::Context->preference("intranetstylesheet"),
991
        intranetstylesheet => C4::Context->preference("intranetstylesheet"),
(-)a/C4/Output.pm (-4 / +19 lines)
Lines 41-53 BEGIN { Link Here
41
    require Exporter;
41
    require Exporter;
42
    @ISA    = qw(Exporter);
42
    @ISA    = qw(Exporter);
43
	@EXPORT_OK = qw(&is_ajax ajax_fail); # More stuff should go here instead
43
	@EXPORT_OK = qw(&is_ajax ajax_fail); # More stuff should go here instead
44
	%EXPORT_TAGS = ( all =>[qw(&pagination_bar
44
	%EXPORT_TAGS = ( all =>[qw(&themelanguage &gettemplate setlanguagecookie &pagination_bar
45
							   &output_with_http_headers &output_html_with_http_headers)],
45
							   &output_with_http_headers &output_ajax_with_http_headers &output_html_with_http_headers)],
46
					ajax =>[qw(&output_with_http_headers is_ajax)],
46
					ajax =>[qw(&output_with_http_headers &output_ajax_with_http_headers is_ajax)],
47
					html =>[qw(&output_with_http_headers &output_html_with_http_headers)]
47
					html =>[qw(&output_with_http_headers &output_html_with_http_headers)]
48
				);
48
				);
49
    push @EXPORT, qw(
49
    push @EXPORT, qw(
50
        &output_html_with_http_headers &output_with_http_headers FormatData FormatNumber pagination_bar
50
        &themelanguage &gettemplate setlanguagecookie getlanguagecookie
51
    );
52
    push @EXPORT, qw(
53
        &output_html_with_http_headers &output_ajax_with_http_headers &output_with_http_headers FormatData FormatNumber pagination_bar
51
    );
54
    );
52
}
55
}
53
56
Lines 306-311 sub output_html_with_http_headers ($$$;$) { Link Here
306
    output_with_http_headers( $query, $cookie, $data, 'html', $status );
309
    output_with_http_headers( $query, $cookie, $data, 'html', $status );
307
}
310
}
308
311
312
313
sub output_ajax_with_http_headers ($$) {
314
    my ( $query, $js ) = @_;
315
    print $query->header(
316
        -type            => 'text/javascript',
317
        -charset         => 'UTF-8',
318
        -Pragma          => 'no-cache',
319
        -'Cache-Control' => 'no-cache',
320
        -expires         => '-1d',
321
    ), $js;
322
}
323
309
sub is_ajax () {
324
sub is_ajax () {
310
    my $x_req = $ENV{HTTP_X_REQUESTED_WITH};
325
    my $x_req = $ENV{HTTP_X_REQUESTED_WITH};
311
    return ( $x_req and $x_req =~ /XMLHttpRequest/i ) ? 1 : 0;
326
    return ( $x_req and $x_req =~ /XMLHttpRequest/i ) ? 1 : 0;
(-)a/C4/Ratings.pm (+161 lines)
Line 0 Link Here
1
package C4::Ratings;
2
3
# Copyright 2010 KohaAloha, NZ
4
# Parts copyright 2011, Catalyst IT, NZ.
5
#
6
# This file is part of Koha.
7
#
8
# Koha is free software; you can redistribute it and/or modify it under the
9
# terms of the GNU General Public License as published by the Free Software
10
# Foundation; either version 2 of the License, or (at your option) any later
11
# version.
12
#
13
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License along
18
# with Koha; if not, write to the Free Software Foundation, Inc.,
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21
=head1 C4::Ratings - the Koha API for dealing with star ratings for biblios
22
23
This provides an interface to the ratings system, in order to allow them
24
to be manipulated or queried.
25
26
=cut
27
28
use strict;
29
use warnings;
30
use Carp;
31
use Exporter;
32
33
use C4::Debug;
34
use C4::Context;
35
36
=head1 NAME
37
38
C4::Ratings - Koha functions for dealing with star ratings.
39
40
=head1 SYNOPSIS
41
42
  use C4::Ratings;
43
44
=head1 DESCRIPTION
45
46
This modules provides somes functions to deal with star ratings.
47
48
=cut
49
50
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
51
52
BEGIN {
53
    $VERSION = 3.00;
54
    @ISA     = qw(Exporter);
55
56
    @EXPORT = qw(
57
      get_rating add_rating
58
    );
59
60
    #	%EXPORT_TAGS = ();
61
}
62
63
=head1 FUNCTIONS
64
65
=cut
66
67
=head2 get_rating
68
69
    get_rating($biblionumber, $borrowernumber)
70
71
This returns the rating for the supplied biblionumber. It will also return
72
the rating that the supplied user gave to the provided biblio. If a particular
73
value can't be supplied, '0' is returned for that value.
74
75
=head 3 RETURNS
76
77
A hashref containing:
78
79
=over
80
81
=item total - the total number of ratings
82
=item avg - the average of the ratings
83
=item avgint - the integer form of the average
84
=item value - the user's rating
85
86
=back
87
88
=cut
89
90
my ($total_query_sth, $user_query_sth);
91
sub get_rating {
92
    my ( $biblionumber, $borrowernumber ) = @_;
93
    my $dbh = C4::Context->dbh;
94
95
    my $total_query = "
96
	SELECT    AVG(value) AS average,COUNT(value) AS total  FROM ratings
97
    WHERE       biblionumber = ?";
98
    $total_query_sth = $total_query_sth || $dbh->prepare($total_query);
99
100
    $total_query_sth->execute($biblionumber);
101
    my $total_query_res = $total_query_sth->fetchrow_hashref();
102
103
    my $user_rating = 0;
104
    if ($borrowernumber) {
105
        my $user_query = "
106
        SELECT    value  from ratings
107
        WHERE       biblionumber = ? and borrowernumber = ?";
108
        $user_query_sth ||= $dbh->prepare($user_query);
109
110
        $user_query_sth->execute( $biblionumber, $borrowernumber );
111
        my $user_query_res = $user_query_sth->fetchrow_hashref();
112
        $user_rating = $user_query_res->{value} || 0;
113
    }
114
    my ( $avg, $avgint ) = 0;
115
    $avg = $total_query_res->{average} || 0;
116
    $avgint = sprintf( "%.0f", $avg );
117
118
    my %rating_hash;
119
    $rating_hash{total}  = $total_query_res->{total} || 0;
120
    $rating_hash{avg}    = $avg;
121
    $rating_hash{avgint} = $avgint;
122
    $rating_hash{value}  = $user_rating;
123
    return \%rating_hash;
124
}
125
126
=head2 add_rating
127
128
    add_rating($biblionumber, $borrowernumber, $value)
129
130
This adds or updates a rating for a particular user on a biblio. If the value
131
is 0, then the rating will be deleted. If the value is out of the range of
132
0-5, nothing will happen.
133
134
=cut
135
136
my ($delete_query_sth, $insert_query_sth);
137
sub add_rating {
138
    my ( $biblionumber, $borrowernumber, $value ) = @_;
139
    if (!defined($biblionumber) || !defined($borrowernumber) ||
140
        $value < 0 || $value > 5) {
141
        # Seen this happen, want to know about it if it happens again.
142
        carp "Invalid input coming in to C4::Ratings::add_rating";
143
        return;
144
    }
145
    if ($borrowernumber == 0) {
146
    	carp "Attempted to add a rating for borrower number 0";
147
    	return;
148
    }
149
    my $dbh = C4::Context->dbh;
150
    my $delete_query = "DELETE FROM ratings WHERE borrowernumber = ? AND biblionumber = ? LIMIT 1";
151
    my $delete_query_sth ||= $dbh->prepare($delete_query);
152
    $delete_query_sth->execute( $borrowernumber, $biblionumber );
153
    return if $value == 0; # We don't add a rating for zero
154
155
    my $insert_query = "INSERT INTO ratings (borrowernumber,biblionumber,value)
156
    VALUES (?,?,?)";
157
    $insert_query_sth ||= $dbh->prepare($insert_query);
158
    $insert_query_sth->execute( $borrowernumber, $biblionumber, $value );
159
}
160
161
1;
(-)a/installer/data/mysql/kohastructure.sql (+16 lines)
Lines 2705-2710 CREATE TABLE `bibliocoverimage` ( Link Here
2705
 CONSTRAINT `bibliocoverimage_fk1` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
2705
 CONSTRAINT `bibliocoverimage_fk1` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
2706
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2706
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2707
2707
2708
--
2709
-- 'Ratings' table. This tracks the star ratings set by borrowers.
2710
--
2711
2712
DROP TABLE IF EXISTS `ratings`;
2713
CREATE TABLE `ratings` (
2714
    `borrowernumber` int(11) NOT NULL, -- the borrower this rating is for
2715
    `biblionumber` int(11) NOT NULL, -- the biblio it's for
2716
    `value` tinyint(1) NOT NULL, -- the rating, from 1-5
2717
    `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
2718
    PRIMARY KEY  (`borrowernumber`,`biblionumber`),
2719
    CONSTRAINT `ratings_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
2720
    CONSTRAINT `ratings_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
2721
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2722
2723
2708
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
2724
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
2709
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
2725
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
2710
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
2726
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
(-)a/installer/data/mysql/updatedatabase.pl (+19 lines)
Lines 4734-4739 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { Link Here
4734
    SetVersion($DBversion);
4734
    SetVersion($DBversion);
4735
}
4735
}
4736
4736
4737
$DBversion = '3.07.00.XXX';
4738
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
4739
    $dbh->do( qq |
4740
 CREATE TABLE `ratings` (
4741
  `borrowernumber` int(11) NOT NULL,
4742
  `biblionumber` int(11) NOT NULL,
4743
  `value` tinyint(1) NOT NULL,
4744
  `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
4745
  PRIMARY KEY (`borrowernumber`, `biblionumber`),
4746
  CONSTRAINT `ratings_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
4747
  CONSTRAINT `ratings_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
4748
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |  );
4749
4750
    $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('RatingsEnabled','','Enabled or disables ratings feature in the OPAC',NULL,'YesNo')");
4751
4752
    print "Upgrade to $DBversion done (Added 'ratings' table, and 'RatingsEnabled' syspref\n";
4753
    SetVersion ($DBversion);
4754
}
4755
4737
=head1 FUNCTIONS
4756
=head1 FUNCTIONS
4738
4757
4739
=head2 DropAllForeignKeys($table)
4758
=head2 DropAllForeignKeys($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref (+6 lines)
Lines 304-309 OPAC: Link Here
304
            - pref: numSearchRSSResults
304
            - pref: numSearchRSSResults
305
              class: long
305
              class: long
306
            -  search results in the RSS feed.
306
            -  search results in the RSS feed.
307
        -
308
            - pref: RatingsEnabled
309
              choices:
310
                  yes: Show
311
                  no: "Don't show"
312
            - star ratings
307
    Policy:
313
    Policy:
308
        -
314
        -
309
            - pref: singleBranchMode
315
            - pref: singleBranchMode
(-)a/koha-tmpl/opac-tmpl/prog/en/css/jquery.rating.css (+12 lines)
Line 0 Link Here
1
/* jQuery.Rating Plugin CSS - http://www.fyneworks.com/jquery/star-rating/ */
2
div.rating-cancel,div.star-rating{float:left;width:17px;height:15px;text-indent:-999em;cursor:pointer;display:block;background:transparent;overflow:hidden}
3
div.rating-cancel,div.rating-cancel a{background:url(../../images/delete.gif) no-repeat 0 -16px}
4
div.star-rating,div.star-rating a{background:url(../../images/star.gif) no-repeat 0 0px}
5
div.rating-cancel a,div.star-rating a{display:block;width:16px;height:100%;background-position:0 0px;border:0}
6
div.star-rating-on a{background-position:0 -16px!important}
7
div.star-rating-hover a{background-position:0 -32px}
8
/* Read Only CSS */
9
div.star-rating-readonly a{cursor:default !important}
10
/* Partial Star CSS */
11
div.star-rating{background:transparent!important;overflow:hidden!important}
12
/* END jQuery.Rating Plugin CSS */
(-)a/koha-tmpl/opac-tmpl/prog/en/lib/jquery/plugins/jquery.rating.pack.js (+11 lines)
Line 0 Link Here
1
/*
2
 ### jQuery Star Rating Plugin v3.14 - 2012-01-26 ###
3
 * Home: http://www.fyneworks.com/jquery/star-rating/
4
 * Code: http://code.google.com/p/jquery-star-rating-plugin/
5
 *
6
	* Dual licensed under the MIT and GPL licenses:
7
 *   http://www.opensource.org/licenses/mit-license.php
8
 *   http://www.gnu.org/licenses/gpl.html
9
 ###
10
*/
11
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}(';5(1W.1z)(7($){5($.21.1Y)1X{1u.1Q("1P",M,t)}1O(e){};$.n.3=7(i){5(4.S==0)l 4;5(H Q[0]==\'1s\'){5(4.S>1){8 j=Q;l 4.11(7(){$.n.3.G($(4),j)})};$.n.3[Q[0]].G(4,$.20(Q).1T(1)||[]);l 4};8 i=$.U({},$.n.3.1k,i||{});$.n.3.O++;4.1K(\'.k-3-1j\').p(\'k-3-1j\').11(7(){8 a,9=$(4);8 b=(4.28||\'26-3\').1g(/\\[|\\]/g,\'10\').1g(/^\\10+|\\10+$/g,\'\');8 c=$(4.1N||1u.1B);8 d=c.6(\'3\');5(!d||d.1d!=$.n.3.O)d={B:0,1d:$.n.3.O};8 e=d[b];5(e)a=e.6(\'3\');5(e&&a)a.B++;C{a=$.U({},i||{},($.1c?9.1c():($.1C?9.6():u))||{},{B:0,F:[],v:[]});a.w=d.B++;e=$(\'<23 14="k-3-1I"/>\');9.1M(e);e.p(\'3-18-19-1a\');5(9.T(\'J\')||9.12(\'J\'))a.m=t;5(9.12(\'Y\'))a.Y=t;e.1o(a.D=$(\'<L 14="3-D"><a 13="\'+a.D+\'">\'+a.1e+\'</a></L>\').1f(7(){$(4).3(\'R\');$(4).p(\'k-3-P\')}).1h(7(){$(4).3(\'x\');$(4).E(\'k-3-P\')}).1i(7(){$(4).3(\'r\')}).6(\'3\',a))};8 f=$(\'<L 14="k-3 q-\'+a.w+\'"><a 13="\'+(4.13||4.1l)+\'">\'+4.1l+\'</a></L>\');e.1o(f);5(4.17)f.T(\'17\',4.17);5(4.1m)f.p(4.1m);5(a.1Z)a.s=2;5(H a.s==\'1n\'&&a.s>0){8 g=($.n.Z?f.Z():0)||a.1p;8 h=(a.B%a.s),W=1D.1E(g/a.s);f.Z(W).1F(\'a\').1G({\'1H-1A\':\'-\'+(h*W)+\'1J\'})};5(a.m)f.p(\'k-3-1q\');C f.p(\'k-3-1L\').1f(7(){$(4).3(\'1r\');$(4).3(\'I\')}).1h(7(){$(4).3(\'x\');$(4).3(\'z\')}).1i(7(){$(4).3(\'r\')});5(4.N)a.o=f;5(4.1R=="A"){5($(4).12(\'1S\'))a.o=f};9.1t();9.1U(7(){$(4).3(\'r\')});f.6(\'3.9\',9.6(\'3.k\',f));a.F[a.F.S]=f[0];a.v[a.v.S]=9[0];a.q=d[b]=e;a.1V=c;9.6(\'3\',a);e.6(\'3\',a);f.6(\'3\',a);c.6(\'3\',d)});$(\'.3-18-19-1a\').3(\'x\').E(\'3-18-19-1a\');l 4};$.U($.n.3,{O:0,I:7(){8 a=4.6(\'3\');5(!a)l 4;5(!a.I)l 4;8 b=$(4).6(\'3.9\')||$(4.V==\'15\'?4:u);5(a.I)a.I.G(b[0],[b.K(),$(\'a\',b.6(\'3.k\'))[0]])},z:7(){8 a=4.6(\'3\');5(!a)l 4;5(!a.z)l 4;8 b=$(4).6(\'3.9\')||$(4.V==\'15\'?4:u);5(a.z)a.z.G(b[0],[b.K(),$(\'a\',b.6(\'3.k\'))[0]])},1r:7(){8 a=4.6(\'3\');5(!a)l 4;5(a.m)l;4.3(\'R\');4.1v().1w().X(\'.q-\'+a.w).p(\'k-3-P\')},R:7(){8 a=4.6(\'3\');5(!a)l 4;5(a.m)l;a.q.22().X(\'.q-\'+a.w).E(\'k-3-1x\').E(\'k-3-P\')},x:7(){8 a=4.6(\'3\');5(!a)l 4;4.3(\'R\');5(a.o){a.o.6(\'3.9\').T(\'N\',\'N\');a.o.1v().1w().X(\'.q-\'+a.w).p(\'k-3-1x\')}C $(a.v).1y(\'N\');a.D[a.m||a.Y?\'1t\':\'24\']();4.25()[a.m?\'p\':\'E\'](\'k-3-1q\')},r:7(a,b){8 c=4.6(\'3\');5(!c)l 4;5(c.m)l;c.o=u;5(H a!=\'y\'){5(H a==\'1n\')l $(c.F[a]).3(\'r\',y,b);5(H a==\'1s\')$.11(c.F,7(){5($(4).6(\'3.9\').K()==a)$(4).3(\'r\',y,b)})}C c.o=4[0].V==\'15\'?4.6(\'3.k\'):(4.27(\'.q-\'+c.w)?4:u);4.6(\'3\',c);4.3(\'x\');8 d=$(c.o?c.o.6(\'3.9\'):u);5((b||b==y)&&c.1b)c.1b.G(d[0],[d.K(),$(\'a\',c.o)[0]])},m:7(a,b){8 c=4.6(\'3\');5(!c)l 4;c.m=a||a==y?t:M;5(b)$(c.v).T("J","J");C $(c.v).1y("J");4.6(\'3\',c);4.3(\'x\')},29:7(){4.3(\'m\',t,t)},2a:7(){4.3(\'m\',M,M)}});$.n.3.1k={D:\'2b 2c\',1e:\'\',s:0,1p:16};$(7(){$(\'9[2d=2e].k\').3()})})(1z);',62,139,'|||rating|this|if|data|function|var|input|||||||||||star|return|readOnly|fn|current|addClass|rater|select|split|true|null|inputs|serial|draw|undefined|blur||count|else|cancel|removeClass|stars|apply|typeof|focus|disabled|val|div|false|checked|calls|hover|arguments|drain|length|attr|extend|tagName|spw|filter|required|width|_|each|hasClass|title|class|INPUT||id|to|be|drawn|callback|metadata|call|cancelValue|mouseover|replace|mouseout|click|applied|options|value|className|number|append|starWidth|readonly|fill|string|hide|document|prevAll|andSelf|on|removeAttr|jQuery|left|body|meta|Math|floor|find|css|margin|control|px|not|live|before|form|catch|BackgroundImageCache|execCommand|nodeName|selected|slice|change|context|window|try|msie|half|makeArray|browser|children|span|show|siblings|unnamed|is|name|disable|enable|Cancel|Rating|type|radio'.split('|'),0,{}))
(-)a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt (-1 / +48 lines)
Lines 1-6 Link Here
1
[% INCLUDE 'doc-head-open.inc' %][% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha Online[% END %] Catalog &rsaquo; Details for: [% title |html %][% FOREACH subtitl IN subtitle %], [% subtitl.subfield |html %][% END %]
1
[% INCLUDE 'doc-head-open.inc' %][% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha Online[% END %] Catalog &rsaquo; Details for: [% title |html %][% FOREACH subtitl IN subtitle %], [% subtitl.subfield |html %][% END %]
2
[% INCLUDE 'doc-head-close.inc' %]
2
[% INCLUDE 'doc-head-close.inc' %]
3
<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.tablesorter.min.js"></script>
3
<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.tablesorter.min.js"></script>
4
<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.rating.pack.js"></script>
5
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/jquery.rating.css" />
4
<script type="text/JavaScript" language="JavaScript">
6
<script type="text/JavaScript" language="JavaScript">
5
//<![CDATA[
7
//<![CDATA[
6
    [% IF ( busc ) %]
8
    [% IF ( busc ) %]
Lines 206-212 YAHOO.util.Event.onContentReady("furtherm", function () { Link Here
206
		YAHOO.util.Event.addListener("furthersearches", "click", furthersearchesMenu.show, null, furthersearchesMenu);
208
		YAHOO.util.Event.addListener("furthersearches", "click", furthersearchesMenu.show, null, furthersearchesMenu);
207
		YAHOO.widget.Overlay.windowResizeEvent.subscribe(positionfurthersearchesMenu);
209
		YAHOO.widget.Overlay.windowResizeEvent.subscribe(positionfurthersearchesMenu);
208
 });
210
 });
209
	
211
212
[% IF (RatingsEnabled) %]
213
$(document).ready(function() { 
214
215
$(".auto-submit-star").rating({
216
    callback: function(value, link){
217
        $.post("/cgi-bin/koha/opac-ratings.pl", 
218
        {   rating: value, 
219
            biblionumber: "[% biblionumber %]"  
220
        },
221
        function(data){
222
            $("#rating_total").html('&nbsp;('+data.total+' '+ (data.total==1 ? _('vote') : _('votes'))+')');
223
            if (data.value) {
224
                $("#rating_user").text(_('your rating added: ')+data.value);
225
            } else {
226
                $("#rating_user").text('');
227
            }
228
        }
229
        , "json");
230
    }
231
});
232
233
});
234
[% END %]
210
//]]>
235
//]]>
211
</script>
236
</script>
212
[% IF ( opacuserlogin ) %][% IF ( loggedinusername ) %][% IF ( TagsEnabled ) %]<style type="text/css">
237
[% IF ( opacuserlogin ) %][% IF ( loggedinusername ) %][% IF ( TagsEnabled ) %]<style type="text/css">
Lines 471-476 YAHOO.util.Event.onContentReady("furtherm", function () { Link Here
471
        </span>
496
        </span>
472
        [% END %][% END %][% END %]
497
        [% END %][% END %][% END %]
473
498
499
 [% IF (RatingsEnabled) %]
500
 <div class="results_summary">   
501
    [% FOR i IN [1..5] %]
502
        [% checked = i == rating_avgint %]
503
    <input class="auto-submit-star" type="radio"  name="rating[% biblionumber %]"  value="[% i %]" [% checked ? 'checked' : '' %] [% rating_readonly ? 'disabled="disabled"' : '' %] />
504
    [% END %]
505
506
    <input  type="hidden" name='biblionumber'  value="[% biblionumber %]" />
507
508
   <span  id="rating_total"  >
509
[% IF(rating_total) %]&nbsp;([% rating_total %] [% IF (rating_total==1) %]vote[% ELSE %]votes[% END %])[% END %]
510
</span>
511
512
   <span id="rating_user">[% IF (rating_value) %]your rating: [% rating_value %][% END %]</span>
513
    [% IF (rating_readonly) %]
514
        <span id="rating_login">Log in to add your rating.</span>
515
    [% END %]
516
</div>
517
518
[% END %]
519
520
474
    [% IF ( BakerTaylorContentURL ) %]
521
    [% IF ( BakerTaylorContentURL ) %]
475
        <span class="results_summary">
522
        <span class="results_summary">
476
        <span class="label">Enhanced Content: </span> 
523
        <span class="label">Enhanced Content: </span> 
(-)a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt (+57 lines)
Lines 8-13 Link Here
8
[% INCLUDE 'doc-head-close.inc' %]
8
[% INCLUDE 'doc-head-close.inc' %]
9
<link rel="alternate" type="application/rss+xml" title="[% LibraryName |html %] Search RSS Feed" href="[% OPACBaseURL %]/cgi-bin/koha/opac-search.pl?[% query_cgi |html %][% limit_cgi |html %]&amp;count=[% countrss |html %]&amp;sort_by=acqdate_dsc&amp;format=rss2" />
9
<link rel="alternate" type="application/rss+xml" title="[% LibraryName |html %] Search RSS Feed" href="[% OPACBaseURL %]/cgi-bin/koha/opac-search.pl?[% query_cgi |html %][% limit_cgi |html %]&amp;count=[% countrss |html %]&amp;sort_by=acqdate_dsc&amp;format=rss2" />
10
10
11
<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.rating.pack.js"></script>
12
13
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/jquery.rating.css" />
14
11
15
12
<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.checkboxes.min.js"></script>
16
<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.checkboxes.min.js"></script>
13
[% IF ( OpacHighlightedWords ) %]<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.highlight-3.js"></script>
17
[% IF ( OpacHighlightedWords ) %]<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.highlight-3.js"></script>
Lines 78-83 function tagAdded() { Link Here
78
    KOHA.Tags.add_multitags_button(bibs, tag);
82
    KOHA.Tags.add_multitags_button(bibs, tag);
79
    return false;
83
    return false;
80
}[% END %][% END %]
84
}[% END %][% END %]
85
86
81
[% IF ( OpacHighlightedWords ) %]
87
[% IF ( OpacHighlightedWords ) %]
82
var q_array = new Array();  // holds search terms if available
88
var q_array = new Array();  // holds search terms if available
83
89
Lines 231-237 $(document).ready(function(){ Link Here
231
    [% IF OpenLibraryCovers %]KOHA.OpenLibrary.GetCoverFromIsbn();[% END %]
237
    [% IF OpenLibraryCovers %]KOHA.OpenLibrary.GetCoverFromIsbn();[% END %]
232
	[% IF OPACLocalCoverImages %]KOHA.LocalCover.GetCoverFromBibnumber(false);[% END %]
238
	[% IF OPACLocalCoverImages %]KOHA.LocalCover.GetCoverFromBibnumber(false);[% END %]
233
    [% IF ( GoogleJackets ) %]KOHA.Google.GetCoverFromIsbn();[% END %]
239
    [% IF ( GoogleJackets ) %]KOHA.Google.GetCoverFromIsbn();[% END %]
240
241
242
}); // end of $(document).ready
243
244
[% IF ( RatingsEnabled ) %]
245
$(document).ready(function() { 
246
    $('.auto-submit-star').rating({
247
        callback: function(value, link){
248
                      var bibnum = this.name.replace(/^rating/, "");
249
250
                      $.post("/cgi-bin/koha/opac-ratings.pl", {   
251
                          rating: value,
252
                          biblionumber: bibnum  
253
                      }, function(data){
254
                          $("#rating_total_"+bibnum).html("&nbsp;("+data.total+' '+ (data.total==1 ? _('vote') : _('votes'))+')');
255
                            if (data.value) {
256
                                $("#rating_value_"+bibnum).text(_('your rating added: ')+data.value);
257
                            } else {
258
                                $("#rating_value_"+bibnum).text('');
259
                            }
260
                      }, "json");
261
                  }
262
    });
234
});
263
});
264
[% END %]
265
235
//]]>
266
//]]>
236
</script>
267
</script>
237
</head>
268
</head>
Lines 501-506 $(document).ready(function(){ Link Here
501
                                    </div>[% END %]
532
                                    </div>[% END %]
502
                                [% END %]
533
                                [% END %]
503
                                [% END %][% END %]
534
                                [% END %][% END %]
535
536
[% IF ( RatingsEnabled ) %]
537
<div class="results_summary">
538
    <form name="ratingform[% SEARCH_RESULT.biblionumber %]" method="post" action="/cgi-bin/koha/opac-ratings.pl">
539
    [% FOR i IN [1..5] %]
540
        [% checked = i == SEARCH_RESULT.rating_avgint %]
541
        <input class="auto-submit-star" type="radio"  name="rating[% SEARCH_RESULT.biblionumber %]"  value="[% i %]" [% checked ? 'checked' : '' %] [% rating_readonly ? 'disabled="disabled"' : '' %]  />
542
    [% END %]
543
        <input  type="hidden" name='[% SEARCH_RESULT.biblionumber %]'  value="[% SEARCH_RESULT.biblionumber %]" />
544
        <span id="rating_total_[% SEARCH_RESULT.biblionumber %]">
545
            [% IF (SEARCH_RESULT.rating_total) %]
546
            &nbsp;([% SEARCH_RESULT.rating_total %] [% IF (SEARCH_RESULT.rating_total==1) %]vote[% ELSE %]votes[% END %])
547
            [% END %]
548
        </span>
549
550
        <span id="rating_value_[% SEARCH_RESULT.biblionumber %]">
551
            [% IF ( SEARCH_RESULT.rating_value ) %]&nbsp;your rating: [% SEARCH_RESULT.rating_value %][% END %]
552
        </span>
553
554
    </form>
555
    <br />
556
</div>
557
[% END %]
558
559
560
504
				[% IF ( SEARCH_RESULT.searchhighlightblob ) %]<span class="results_summary"><span class="label">Match:</span> [% SEARCH_RESULT.searchhighlightblob %]</span>[% END %]
561
				[% IF ( SEARCH_RESULT.searchhighlightblob ) %]<span class="results_summary"><span class="label">Match:</span> [% SEARCH_RESULT.searchhighlightblob %]</span>[% END %]
505
562
506
<span class="results_summary actions"><span class="label">Actions:</span>
563
<span class="results_summary actions"><span class="label">Actions:</span>
(-)a/opac/opac-detail.pl (+24 lines)
Lines 37-42 use C4::XISBN qw(get_xisbns get_biblionumber_from_isbn); Link Here
37
use C4::External::Amazon;
37
use C4::External::Amazon;
38
use C4::External::Syndetics qw(get_syndetics_index get_syndetics_summary get_syndetics_toc get_syndetics_excerpt get_syndetics_reviews get_syndetics_anotes );
38
use C4::External::Syndetics qw(get_syndetics_index get_syndetics_summary get_syndetics_toc get_syndetics_excerpt get_syndetics_reviews get_syndetics_anotes );
39
use C4::Review;
39
use C4::Review;
40
use C4::Ratings;
40
use C4::Members;
41
use C4::Members;
41
use C4::VirtualShelves;
42
use C4::VirtualShelves;
42
use C4::XSLT;
43
use C4::XSLT;
Lines 642-647 foreach ( @$reviews ) { Link Here
642
    $_->{userid}    = $borrowerData->{'userid'};
643
    $_->{userid}    = $borrowerData->{'userid'};
643
    $_->{cardnumber}    = $borrowerData->{'cardnumber'};
644
    $_->{cardnumber}    = $borrowerData->{'cardnumber'};
644
    $_->{datereviewed} = format_date($_->{datereviewed});
645
    $_->{datereviewed} = format_date($_->{datereviewed});
646
647
648
649
650
#    my $value =  get_rating_by_review($_->{reviewid});
651
    my $rating =  get_rating(  $biblionumber ,  $_->{borrowernumber});
652
653
    $_->{rating} = $rating->{value} ;
654
645
    if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
655
    if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
646
		$_->{your_comment} = 1;
656
		$_->{your_comment} = 1;
647
		$loggedincommenter = 1;
657
		$loggedincommenter = 1;
Lines 901-906 if (C4::Context->preference("OPACURLOpenInNewWindow")) { Link Here
901
    $template->param(covernewwindow => 'false');
911
    $template->param(covernewwindow => 'false');
902
}
912
}
903
913
914
if (C4::Context->preference('RatingsEnabled') ) {
915
    my $rating = get_rating( $biblionumber, $borrowernumber );
916
    $template->param(
917
        RatingsShowOnDetail => 1,
918
        RatingsEnabled => 1,
919
        rating_value        => $rating->{'value'},
920
        rating_total        => $rating->{'total'},
921
        rating_avg          => $rating->{'avg'},
922
        rating_avgint       => $rating->{'avgint'},
923
        rating_readonly     => ( $borrowernumber ? 0 : 1 ),
924
        borrowernumber      => $borrowernumber,
925
    );
926
}
927
904
#Export options
928
#Export options
905
my $OpacExportOptions=C4::Context->preference("OpacExportOptions");
929
my $OpacExportOptions=C4::Context->preference("OpacExportOptions");
906
my @export_options = split(/\|/,$OpacExportOptions);
930
my @export_options = split(/\|/,$OpacExportOptions);
(-)a/opac/opac-ratings.pl (+104 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2010 KohaAloha, NZ
4
# Parts copyright 2011, Catalyst IT, NZ
5
#
6
# This file is part of Koha.
7
#
8
# Koha is free software; you can redistribute it and/or modify it under the
9
# terms of the GNU General Public License as published by the Free Software
10
# Foundation; either version 2 of the License, or (at your option) any later
11
# version.
12
#
13
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License along with
18
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19
# Suite 330, Boston, MA  02111-1307 USA
20
21
=head1
22
23
opac-ratings.pl - API endpoint for setting rating values
24
25
This receives a POST containing biblionumber and rating. It
26
updates rating for the logged in user.
27
28
=cut
29
30
use strict;
31
use warnings;
32
use CGI;
33
use CGI::Cookie;    # need to check cookies before having CGI parse the POST request
34
use JSON;
35
36
use C4::Auth qw(:DEFAULT check_cookie_auth);
37
use C4::Context;
38
use C4::Debug;
39
use C4::Output 3.02 qw(:html :ajax pagination_bar);
40
use C4::Ratings;
41
42
use Data::Dumper;
43
44
my %ratings = ();
45
my %counts  = ();
46
my @errors  = ();
47
48
my $is_ajax = is_ajax();
49
50
my $query = ($is_ajax) ? &ajax_auth_cgi( {} ) : CGI->new();
51
52
my $biblionumber   = $query->param('biblionumber');
53
my $value;
54
55
foreach ( $query->param ) {
56
    if (/^rating(.*)/) {
57
        $value = $query->param($_);
58
        last;
59
    }
60
}
61
62
my ( $template, $loggedinuser, $cookie );
63
64
if ($is_ajax) {
65
    $loggedinuser = C4::Context->userenv->{'number'};
66
    add_rating( $biblionumber, $loggedinuser, $value );
67
    my $rating = get_rating($biblionumber, $loggedinuser);
68
    my $js_reply = "{total: $rating->{'total'}, value: $rating->{'value'}}";
69
70
    output_ajax_with_http_headers( $query, $js_reply );
71
    exit;
72
}
73
74
# Future enhancements could have this have its own template to
75
# display the users' ratings, or tie in with their reading history
76
# to get them to rate things they read recently.
77
( $template, $loggedinuser, $cookie ) = get_template_and_user(
78
    {   template_name   => "opac-user.tmpl",
79
        query           => $query,
80
        type            => "opac",
81
        authnotrequired => 0,                  # auth required to add ratings
82
        debug           => 0,
83
    }
84
);
85
86
my $results = [];
87
88
( scalar @errors ) and $template->param( ERRORS => \@errors );
89
90
output_html_with_http_headers $query, $cookie, $template->output;
91
92
sub ajax_auth_cgi ($) {                            # returns CGI object
93
    my $needed_flags = shift;
94
    my %cookies      = fetch CGI::Cookie;
95
    my $input        = CGI->new;
96
    my $sessid       = $cookies{'CGISESSID'}->value || $input->param('CGISESSID');
97
    my ( $auth_status, $auth_sessid ) = check_cookie_auth( $sessid, $needed_flags );
98
    if ( $auth_status ne "ok" ) {
99
        output_ajax_with_http_headers $input, "window.alert('Your CGI session cookie ($sessid) is not current.  " . "Please refresh the page and try again.');\n";
100
        exit 0;
101
    }
102
    return $input;
103
}
104
(-)a/opac/opac-search.pl (-2 / +27 lines)
Lines 36-45 use C4::Biblio; # GetBiblioData Link Here
36
use C4::Koha;
36
use C4::Koha;
37
use C4::Tags qw(get_tags);
37
use C4::Tags qw(get_tags);
38
use C4::Branch; # GetBranches
38
use C4::Branch; # GetBranches
39
use C4::Ratings;
40
39
use POSIX qw(ceil floor strftime);
41
use POSIX qw(ceil floor strftime);
40
use URI::Escape;
42
use URI::Escape;
41
use Storable qw(thaw freeze);
43
use Storable qw(thaw freeze);
42
44
45
#use Smart::Comments '####';
46
43
47
44
my $DisplayMultiPlaceHold = C4::Context->preference("DisplayMultiPlaceHold");
48
my $DisplayMultiPlaceHold = C4::Context->preference("DisplayMultiPlaceHold");
45
# create a new CGI object
49
# create a new CGI object
Lines 119-124 if (C4::Context->preference('BakerTaylorEnabled')) { Link Here
119
        BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
123
        BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
120
    );
124
    );
121
}
125
}
126
122
if (C4::Context->preference('TagsEnabled')) {
127
if (C4::Context->preference('TagsEnabled')) {
123
    $template->param(TagsEnabled => 1);
128
    $template->param(TagsEnabled => 1);
124
    foreach (qw(TagsShowOnList TagsInputOnList)) {
129
    foreach (qw(TagsShowOnList TagsInputOnList)) {
Lines 126-131 if (C4::Context->preference('TagsEnabled')) { Link Here
126
    }
131
    }
127
}
132
}
128
133
134
if (C4::Context->preference('RatingsEnabled')) {
135
####  $borrowernumber 
136
	$template->param(RatingsEnabled => 1);
137
	$template->param(rating_readonly => 1)  unless $borrowernumber ;
138
	$template->param(borrowernumber =>  $borrowernumber );
139
}
140
141
142
129
## URI Re-Writing
143
## URI Re-Writing
130
# Deprecated, but preserved because it's interesting :-)
144
# Deprecated, but preserved because it's interesting :-)
131
# The same thing can be accomplished with mod_rewrite in
145
# The same thing can be accomplished with mod_rewrite in
Lines 528-533 for (my $i=0;$i<@servers;$i++) { Link Here
528
            }
542
            }
529
        }
543
        }
530
      
544
      
545
        if (C4::Context->preference('RatingsEnabled')) {
546
            foreach (@newresults) {
547
                my $rating = get_rating( $_->{'biblionumber'}, $borrowernumber );
548
549
                my $bib = $_->{'biblionumber'};
550
                $_->{'rating_user'}                         = $rating->{'user'};
551
                $_->{'rating_total'}                        = $rating->{'total'};
552
                $_->{'rating_avg'}                          = $rating->{'avg'};
553
                $_->{'rating_avgint'}                       = $rating->{'avgint'};
554
                $_->{'rating_value'}                        = $rating->{'value'};
555
            }
556
        }
557
531
        if ($results_hashref->{$server}->{"hits"}){
558
        if ($results_hashref->{$server}->{"hits"}){
532
            $total = $total + $results_hashref->{$server}->{"hits"};
559
            $total = $total + $results_hashref->{$server}->{"hits"};
533
        }
560
        }
Lines 667-673 for (my $i=0;$i<@servers;$i++) { Link Here
667
                      };
694
                      };
668
695
669
                }
696
                }
670
                        
671
            }
697
            }
672
            # now, show twenty pages, with the current one smack in the middle
698
            # now, show twenty pages, with the current one smack in the middle
673
            else {
699
            else {
674
- 

Return to bug 5668