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

(-)a/C4/Auth.pm (-2 / +3 lines)
Lines 351-356 sub get_template_and_user { Link Here
351
            LoginFirstname               => (C4::Context->userenv?C4::Context->userenv->{"firstname"}:"Bel"),
351
            LoginFirstname               => (C4::Context->userenv?C4::Context->userenv->{"firstname"}:"Bel"),
352
            LoginSurname                 => C4::Context->userenv?C4::Context->userenv->{"surname"}:"Inconnu",
352
            LoginSurname                 => C4::Context->userenv?C4::Context->userenv->{"surname"}:"Inconnu",
353
            TagsEnabled                  => C4::Context->preference("TagsEnabled"),
353
            TagsEnabled                  => C4::Context->preference("TagsEnabled"),
354
            RatingsEnabled               => C4::Context->preference("RatingsEnabled"),
354
            hide_marc                    => C4::Context->preference("hide_marc"),
355
            hide_marc                    => C4::Context->preference("hide_marc"),
355
            item_level_itypes            => C4::Context->preference('item-level_itypes'),
356
            item_level_itypes            => C4::Context->preference('item-level_itypes'),
356
            patronimages                 => C4::Context->preference("patronimages"),
357
            patronimages                 => C4::Context->preference("patronimages"),
Lines 993-1001 sub checkauth { Link Here
993
        OpacAuthorities      => C4::Context->preference("OpacAuthorities"),
994
        OpacAuthorities      => C4::Context->preference("OpacAuthorities"),
994
        OpacBrowser          => C4::Context->preference("OpacBrowser"),
995
        OpacBrowser          => C4::Context->preference("OpacBrowser"),
995
        opacheader           => C4::Context->preference("opacheader"),
996
        opacheader           => C4::Context->preference("opacheader"),
996
        TagsEnabled                  => C4::Context->preference("TagsEnabled"),
997
        OPACUserCSS           => C4::Context->preference("OPACUserCSS"),
998
        opacstylesheet       => C4::Context->preference("opacstylesheet"),
997
        opacstylesheet       => C4::Context->preference("opacstylesheet"),
998
        TagsEnabled          => C4::Context->preference("TagsEnabled"),
999
        OPACUserCSS          => C4::Context->preference("OPACUserCSS"),
999
        intranetcolorstylesheet =>
1000
        intranetcolorstylesheet =>
1000
								C4::Context->preference("intranetcolorstylesheet"),
1001
								C4::Context->preference("intranetcolorstylesheet"),
1001
        intranetstylesheet => C4::Context->preference("intranetstylesheet"),
1002
        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 (+143 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
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
37
38
BEGIN {
39
    $VERSION = 3.00;
40
    @ISA     = qw(Exporter);
41
42
    @EXPORT = qw(
43
      get_rating add_rating
44
    );
45
46
    #	%EXPORT_TAGS = ();
47
}
48
49
=head2 get_rating
50
51
    get_rating($biblionumber, $borrowernumber)
52
53
This returns the rating for the supplied biblionumber. It will also return
54
the rating that the supplied user gave to the provided biblio. If a particular
55
value can't be supplied, '0' is returned for that value.
56
57
=head 3 RETURNS
58
59
A hashref containing:
60
61
=over
62
63
=item total - the total number of ratings
64
=item avg - the average of the ratings
65
=item avgint - the integer form of the average
66
=item value - the user's rating
67
68
=back
69
70
=cut
71
72
my ($total_query_sth, $user_query_sth);
73
sub get_rating {
74
    my ( $biblionumber, $borrowernumber ) = @_;
75
    my $dbh = C4::Context->dbh;
76
77
    my $total_query = "
78
	SELECT    AVG(value) AS average,COUNT(value) AS total  FROM ratings
79
    WHERE       biblionumber = ?";
80
    $total_query_sth = $total_query_sth || $dbh->prepare($total_query);
81
82
    $total_query_sth->execute($biblionumber);
83
    my $total_query_res = $total_query_sth->fetchrow_hashref();
84
85
    my $user_rating = 0;
86
    if ($borrowernumber) {
87
        my $user_query = "
88
        SELECT    value  from ratings
89
        WHERE       biblionumber = ? and borrowernumber = ?";
90
        $user_query_sth ||= $dbh->prepare($user_query);
91
92
        $user_query_sth->execute( $biblionumber, $borrowernumber );
93
        my $user_query_res = $user_query_sth->fetchrow_hashref();
94
        $user_rating = $user_query_res->{value} || 0;
95
    }
96
    my ( $avg, $avgint ) = 0;
97
    $avg = $total_query_res->{average} || 0;
98
    $avgint = sprintf( "%.0f", $avg );
99
100
    my %rating_hash;
101
    $rating_hash{total}  = $total_query_res->{total} || 0;
102
    $rating_hash{avg}    = $avg;
103
    $rating_hash{avgint} = $avgint;
104
    $rating_hash{value}  = $user_rating;
105
    return \%rating_hash;
106
}
107
108
=head2 add_rating
109
110
    add_rating($biblionumber, $borrowernumber, $value)
111
112
This adds or updates a rating for a particular user on a biblio. If the value
113
is 0, then the rating will be deleted. If the value is out of the range of
114
0-5, nothing will happen.
115
116
=cut
117
118
my ($delete_query_sth, $insert_query_sth);
119
sub add_rating {
120
    my ( $biblionumber, $borrowernumber, $value ) = @_;
121
    if (!defined($biblionumber) || !defined($borrowernumber) ||
122
        $value < 0 || $value > 5) {
123
        # Seen this happen, want to know about it if it happens again.
124
        carp "Invalid input coming in to C4::Ratings::add_rating";
125
        return;
126
    }
127
    if ($borrowernumber == 0) {
128
    	carp "Attempted to add a rating for borrower number 0";
129
    	return;
130
    }
131
    my $dbh = C4::Context->dbh;
132
    my $delete_query = "DELETE FROM ratings WHERE borrowernumber = ? AND biblionumber = ? LIMIT 1";
133
    my $delete_query_sth ||= $dbh->prepare($delete_query);
134
    $delete_query_sth->execute( $borrowernumber, $biblionumber );
135
    return if $value == 0; # We don't add a rating for zero
136
137
    my $insert_query = "INSERT INTO ratings (borrowernumber,biblionumber,value)
138
    VALUES (?,?,?)";
139
    $insert_query_sth ||= $dbh->prepare($insert_query);
140
    $insert_query_sth->execute( $borrowernumber, $biblionumber, $value );
141
}
142
143
1;
(-)a/installer/data/mysql/kohastructure.sql (+16 lines)
Lines 2686-2691 CREATE TABLE `bibliocoverimage` ( Link Here
2686
 CONSTRAINT `bibliocoverimage_fk1` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
2686
 CONSTRAINT `bibliocoverimage_fk1` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
2687
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2687
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2688
2688
2689
--
2690
-- 'Ratings' table. This tracks the star ratings set by borrowers.
2691
--
2692
2693
DROP TABLE IF EXISTS `ratings`;
2694
CREATE TABLE `ratings` (
2695
    `borrowernumber` int(11) NOT NULL, -- the borrower this rating is for
2696
    `biblionumber` int(11) NOT NULL, -- the biblio it's for
2697
    `value` tinyint(1) NOT NULL, -- the rating, from 1-5
2698
    `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
2699
    PRIMARY KEY  (`borrowernumber`,`biblionumber`),
2700
    CONSTRAINT `ratings_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
2701
    CONSTRAINT `ratings_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
2702
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2703
2704
2689
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
2705
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
2690
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
2706
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
2691
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
2707
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
(-)a/installer/data/mysql/updatedatabase.pl (+19 lines)
Lines 4671-4676 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
4671
    SetVersion ($DBversion);
4671
    SetVersion ($DBversion);
4672
}
4672
}
4673
4673
4674
$DBversion = '3.07.00.XXX';
4675
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
4676
    $dbh->do( qq |
4677
 CREATE TABLE `ratings` (
4678
  `borrowernumber` int(11) NOT NULL,
4679
  `biblionumber` int(11) NOT NULL,
4680
  `value` tinyint(1) NOT NULL,
4681
  `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
4682
  PRIMARY KEY (`borrowernumber`, `biblionumber`),
4683
  CONSTRAINT `ratings_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
4684
  CONSTRAINT `ratings_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
4685
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |  );
4686
4687
    $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('RatingsEnabled','','Enabled or disables ratings feature in the OPAC',NULL,'YesNo')");
4688
4689
    print "Upgrade to $DBversion done (Added 'ratings' table, and 'RatingsEnabled' syspref\n";
4690
    SetVersion ($DBversion);
4691
}
4692
4674
=head1 FUNCTIONS
4693
=head1 FUNCTIONS
4675
4694
4676
=head2 DropAllForeignKeys($table)
4695
=head2 DropAllForeignKeys($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref (+6 lines)
Lines 292-297 OPAC: Link Here
292
            - pref: numSearchRSSResults
292
            - pref: numSearchRSSResults
293
              class: long
293
              class: long
294
            -  search results in the RSS feed.
294
            -  search results in the RSS feed.
295
        -
296
            - pref: RatingsEnabled
297
              choices:
298
                  yes: Show
299
                  no: "Don't show"
300
            - star ratings
295
    Policy:
301
    Policy:
296
        -
302
        -
297
            - pref: singleBranchMode
303
            - 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 / +49 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
    <input class="auto-submit-star" type="radio"  name="rating[% biblionumber %]"  value="1" [% IF (rating_val_1) %]checked="1"[% END %] [% IF (rating_readonly) %]disabled="disabled"[% END %]   />
502
    <input class="auto-submit-star" type="radio"  name="rating[% biblionumber %]"  value="2" [% IF (rating_val_2) %]checked="1"[% END %] [% IF (rating_readonly) %]disabled="disabled"[% END %]   />
503
    <input class="auto-submit-star" type="radio"  name="rating[% biblionumber %]"  value="3" [% IF (rating_val_3) %]checked="1"[% END %] [% IF (rating_readonly) %]disabled="disabled"[% END %]   />
504
    <input class="auto-submit-star" type="radio"  name="rating[% biblionumber %]"  value="4" [% IF (rating_val_4) %]checked="1"[% END %] [% IF (rating_readonly) %]disabled="disabled"[% END %]   />
505
    <input class="auto-submit-star" type="radio"  name="rating[% biblionumber %]"  value="5" [% IF (rating_val_5) %]checked="1"[% END %] [% IF (rating_readonly) %]disabled="disabled"[% END %]   />
506
507
    <input  type="hidden" name='biblionumber'  value="[% biblionumber %]" />
508
509
   <span  id="rating_total"  >
510
[% IF(rating_total) %]&nbsp;([% rating_total %] [% IF (rating_total==1) %]vote[% ELSE %]votes[% END %])[% END %]
511
</span>
512
513
   <span id="rating_user">[% IF (rating_value) %]your rating: [% rating_value %][% END %]</span>
514
    [% IF (rating_readonly) %]
515
        <span id="rating_login">Log in to add your rating.</span>
516
    [% END %]
517
</div>
518
519
[% END %]
520
521
474
    [% IF ( BakerTaylorContentURL ) %]
522
    [% IF ( BakerTaylorContentURL ) %]
475
        <span class="results_summary">
523
        <span class="results_summary">
476
        <span class="label">Enhanced Content: </span> 
524
        <span class="label">Enhanced Content: </span> 
(-)a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt (+58 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
        <input class="auto-submit-star" type="radio"  name="rating[% SEARCH_RESULT.biblionumber %]"  value="1" [% IF ( SEARCH_RESULT.rating_val_1 ) %]checked="1"[% END %] [% IF ( rating_readonly ) %]disabled="disabled"[% END %]   />
540
        <input class="auto-submit-star" type="radio"  name="rating[% SEARCH_RESULT.biblionumber %]"  value="2" [% IF ( SEARCH_RESULT.rating_val_2 ) %]checked="1"[% END %] [% IF ( rating_readonly ) %]disabled="disabled"[% END %]   />
541
        <input class="auto-submit-star" type="radio"  name="rating[% SEARCH_RESULT.biblionumber %]"  value="3" [% IF ( SEARCH_RESULT.rating_val_3 ) %]checked="1"[% END %] [% IF ( rating_readonly ) %]disabled="disabled"[% END %]   />
542
        <input class="auto-submit-star" type="radio"  name="rating[% SEARCH_RESULT.biblionumber %]"  value="4" [% IF ( SEARCH_RESULT.rating_val_4 ) %]checked="1"[% END %] [% IF ( rating_readonly ) %]disabled="disabled"[% END %]   />
543
        <input class="auto-submit-star" type="radio"  name="rating[% SEARCH_RESULT.biblionumber %]"  value="5" [% IF ( SEARCH_RESULT.rating_val_5 ) %]checked="1"[% END %] [% IF ( rating_readonly ) %]disabled="disabled"[% END %]   />
544
        <input  type="hidden" name='[% SEARCH_RESULT.biblionumber %]'  value="[% SEARCH_RESULT.biblionumber %]" />
545
        <span id="rating_total_[% SEARCH_RESULT.biblionumber %]">
546
            [% IF (SEARCH_RESULT.rating_total) %]
547
            &nbsp;([% SEARCH_RESULT.rating_total %] [% IF (SEARCH_RESULT.rating_total==1) %]vote[% ELSE %]votes[% END %])
548
            [% END %]
549
        </span>
550
551
        <span id="rating_value_[% SEARCH_RESULT.biblionumber %]">
552
            [% IF ( SEARCH_RESULT.rating_value ) %]&nbsp;your rating: [% SEARCH_RESULT.rating_value %][% END %]
553
        </span>
554
555
    </form>
556
    <br />
557
</div>
558
[% END %]
559
560
561
504
				[% IF ( SEARCH_RESULT.searchhighlightblob ) %]<span class="results_summary"><span class="label">Match:</span> [% SEARCH_RESULT.searchhighlightblob %]</span>[% END %]
562
				[% IF ( SEARCH_RESULT.searchhighlightblob ) %]<span class="results_summary"><span class="label">Match:</span> [% SEARCH_RESULT.searchhighlightblob %]</span>[% END %]
505
563
506
<span class="results_summary actions"><span class="label">Actions:</span>
564
<span class="results_summary actions"><span class="label">Actions:</span>
(-)a/opac/opac-detail.pl (+32 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 47-52 use MARC::Field; Link Here
47
use List::MoreUtils qw/any none/;
48
use List::MoreUtils qw/any none/;
48
use C4::Images;
49
use C4::Images;
49
50
51
#use Smart::Comments '####';
52
50
BEGIN {
53
BEGIN {
51
	if (C4::Context->preference('BakerTaylorEnabled')) {
54
	if (C4::Context->preference('BakerTaylorEnabled')) {
52
		require C4::External::BakerTaylor;
55
		require C4::External::BakerTaylor;
Lines 632-637 foreach ( @$reviews ) { Link Here
632
    $_->{userid}    = $borrowerData->{'userid'};
635
    $_->{userid}    = $borrowerData->{'userid'};
633
    $_->{cardnumber}    = $borrowerData->{'cardnumber'};
636
    $_->{cardnumber}    = $borrowerData->{'cardnumber'};
634
    $_->{datereviewed} = format_date($_->{datereviewed});
637
    $_->{datereviewed} = format_date($_->{datereviewed});
638
639
640
641
642
#    my $value =  get_rating_by_review($_->{reviewid});
643
    my $rating =  get_rating(  $biblionumber ,  $_->{borrowernumber});
644
645
    $_->{"borr_rating_val_".$rating->{value}} = 1;
646
    $_->{rating} = $rating->{value} ;
647
648
    ####  $rating
649
#### $_
650
651
635
    if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
652
    if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
636
		$_->{your_comment} = 1;
653
		$_->{your_comment} = 1;
637
		$loggedincommenter = 1;
654
		$loggedincommenter = 1;
Lines 891-896 if (C4::Context->preference("OPACURLOpenInNewWindow")) { Link Here
891
    $template->param(covernewwindow => 'false');
908
    $template->param(covernewwindow => 'false');
892
}
909
}
893
910
911
if (C4::Context->preference('RatingsEnabled') ) {
912
my $rating = get_rating( $biblionumber, $borrowernumber );
913
$template->param(
914
  RatingsShowOnDetail => 1,
915
  RatingsEnabled => 1,
916
  rating_value        => $rating->{'value'},
917
  rating_total        => $rating->{'total'},
918
  rating_avg          => $rating->{'avg'},
919
  rating_avgint       => $rating->{'avgint'},
920
  rating_readonly     => ( $borrowernumber ? 0 : 1 ),
921
  borrowernumber      => $borrowernumber,
922
  "rating_val_" . "$rating->{'avgint'}" => $rating->{'avgint'},
923
  );
924
}
925
894
#Search for title in links
926
#Search for title in links
895
my $marccontrolnumber   = GetMarcControlnumber   ($record, $marcflavour);
927
my $marccontrolnumber   = GetMarcControlnumber   ($record, $marcflavour);
896
928
(-)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 / +28 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 111-116 if (C4::Context->preference('BakerTaylorEnabled')) { Link Here
111
        BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
115
        BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
112
    );
116
    );
113
}
117
}
118
114
if (C4::Context->preference('TagsEnabled')) {
119
if (C4::Context->preference('TagsEnabled')) {
115
    $template->param(TagsEnabled => 1);
120
    $template->param(TagsEnabled => 1);
116
    foreach (qw(TagsShowOnList TagsInputOnList)) {
121
    foreach (qw(TagsShowOnList TagsInputOnList)) {
Lines 118-123 if (C4::Context->preference('TagsEnabled')) { Link Here
118
    }
123
    }
119
}
124
}
120
125
126
if (C4::Context->preference('RatingsEnabled')) {
127
####  $borrowernumber 
128
	$template->param(RatingsEnabled => 1);
129
	$template->param(rating_readonly => 1)  unless $borrowernumber ;
130
	$template->param(borrowernumber =>  $borrowernumber );
131
}
132
133
134
121
## URI Re-Writing
135
## URI Re-Writing
122
# Deprecated, but preserved because it's interesting :-)
136
# Deprecated, but preserved because it's interesting :-)
123
# The same thing can be accomplished with mod_rewrite in
137
# The same thing can be accomplished with mod_rewrite in
Lines 516-521 for (my $i=0;$i<@servers;$i++) { Link Here
516
            }
530
            }
517
        }
531
        }
518
      
532
      
533
        if (C4::Context->preference('RatingsEnabled')) {
534
            foreach (@newresults) {
535
                my $rating = get_rating( $_->{'biblionumber'}, $borrowernumber );
536
537
                my $bib = $_->{'biblionumber'};
538
                $_->{'rating_user'}                         = $rating->{'user'};
539
                $_->{'rating_total'}                        = $rating->{'total'};
540
                $_->{'rating_avg'}                          = $rating->{'avg'};
541
                $_->{'rating_avgint'}                       = $rating->{'avgint'};
542
                $_->{ 'rating_val_' . $rating->{'avgint'} } = $rating->{'avgint'};
543
                $_->{'rating_value'}                        = $rating->{'value'};
544
            }
545
        }
546
519
        if ($results_hashref->{$server}->{"hits"}){
547
        if ($results_hashref->{$server}->{"hits"}){
520
            $total = $total + $results_hashref->{$server}->{"hits"};
548
            $total = $total + $results_hashref->{$server}->{"hits"};
521
        }
549
        }
Lines 655-661 for (my $i=0;$i<@servers;$i++) { Link Here
655
                      };
683
                      };
656
684
657
                }
685
                }
658
                        
659
            }
686
            }
660
            # now, show twenty pages, with the current one smack in the middle
687
            # now, show twenty pages, with the current one smack in the middle
661
            else {
688
            else {
662
- 

Return to bug 5668