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

(-)a/C4/Auth.pm (-2 / +2 lines)
Lines 41-48 BEGIN { Link Here
41
	if ( psgi_env ) { die 'psgi:exit' }
41
	if ( psgi_env ) { die 'psgi:exit' }
42
	else { exit }
42
	else { exit }
43
    }
43
    }
44
44
    $VERSION     = 3.02;    # set version for version checking
45
    $VERSION     = 3.02;                                                                                                            # set version for version checking
46
    $debug       = $ENV{DEBUG};
45
    $debug       = $ENV{DEBUG};
47
    @ISA         = qw(Exporter);
46
    @ISA         = qw(Exporter);
48
    @EXPORT      = qw(&checkauth &get_template_and_user &haspermission &get_user_subpermissions);
47
    @EXPORT      = qw(&checkauth &get_template_and_user &haspermission &get_user_subpermissions);
Lines 1665-1670 sub getborrowernumber { Link Here
1665
    return 0;
1664
    return 0;
1666
}
1665
}
1667
1666
1667
1668
END { }    # module clean-up code here (global destructor)
1668
END { }    # module clean-up code here (global destructor)
1669
1;
1669
1;
1670
__END__
1670
__END__
(-)a/C4/Output.pm (-10 / +26 lines)
Lines 39-56 BEGIN { Link Here
39
    # set the version for version checking
39
    # set the version for version checking
40
    $VERSION = 3.03;
40
    $VERSION = 3.03;
41
    require Exporter;
41
    require Exporter;
42
    @ISA    = qw(Exporter);
42
43
	@EXPORT_OK = qw(&is_ajax ajax_fail); # More stuff should go here instead
43
 @ISA    = qw(Exporter);
44
	%EXPORT_TAGS = ( all =>[qw(&pagination_bar
44
    @EXPORT_OK = qw(&is_ajax ajax_fail); # More stuff should go here instead
45
							   &output_with_http_headers &output_html_with_http_headers)],
45
    %EXPORT_TAGS = ( all =>[qw(&themelanguage &gettemplate setlanguagecookie pagination_bar
46
					ajax =>[qw(&output_with_http_headers is_ajax)],
46
                                &output_with_http_headers &output_ajax_with_http_headers &output_html_with_http_headers)],
47
					html =>[qw(&output_with_http_headers &output_html_with_http_headers)]
47
                    ajax =>[qw(&output_with_http_headers &output_ajax_with_http_headers is_ajax)],
48
				);
48
                    html =>[qw(&output_with_http_headers &output_html_with_http_headers)]
49
                );
49
    push @EXPORT, qw(
50
    push @EXPORT, qw(
50
        &output_html_with_http_headers &output_with_http_headers FormatData FormatNumber pagination_bar
51
        &themelanguage &gettemplate setlanguagecookie getlanguagecookie pagination_bar
52
    );
53
    push @EXPORT, qw(
54
        &output_html_with_http_headers &output_ajax_with_http_headers &output_with_http_headers FormatData FormatNumber
51
    );
55
    );
52
}
53
56
57
}
54
58
55
=head1 NAME
59
=head1 NAME
56
60
Lines 306-312 sub output_html_with_http_headers ($$$;$) { Link Here
306
    output_with_http_headers( $query, $cookie, $data, 'html', $status );
310
    output_with_http_headers( $query, $cookie, $data, 'html', $status );
307
}
311
}
308
312
309
sub is_ajax () {
313
314
sub output_ajax_with_http_headers {
315
    my ( $query, $js ) = @_;
316
    print $query->header(
317
        -type            => 'text/javascript',
318
        -charset         => 'UTF-8',
319
        -Pragma          => 'no-cache',
320
        -'Cache-Control' => 'no-cache',
321
        -expires         => '-1d',
322
    ), $js;
323
}
324
325
sub is_ajax {
310
    my $x_req = $ENV{HTTP_X_REQUESTED_WITH};
326
    my $x_req = $ENV{HTTP_X_REQUESTED_WITH};
311
    return ( $x_req and $x_req =~ /XMLHttpRequest/i ) ? 1 : 0;
327
    return ( $x_req and $x_req =~ /XMLHttpRequest/i ) ? 1 : 0;
312
}
328
}
(-)a/C4/Ratings.pm (+249 lines)
Line 0 Link Here
1
package C4::Ratings;
2
3
# Copyright 2011 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
use strict;
22
use warnings;
23
use Carp;
24
use Exporter;
25
use POSIX;
26
use C4::Debug;
27
use C4::Context;
28
29
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
30
31
BEGIN {
32
    $VERSION = 3.00;
33
    @ISA     = qw(Exporter);
34
35
    @EXPORT = qw(
36
      &GetRating
37
      &AddRating
38
      &ModRating
39
      &DelRating
40
    );
41
}
42
43
=head1 NAME
44
45
C4::Ratings - a module to manage user ratings of Koha biblios
46
47
=head1 DESCRIPTION
48
49
Ratings.pm provides simple functionality for a user to 'rate' a biblio, and to retrieve a biblio's rating info
50
51
the 4 subroutines allow a user to add, delete modify and retrieve rating info for a biblio.
52
53
The rating can be from 1 to 5 stars, (5 stars being the highest rating)
54
55
=head1 SYNOPSIS
56
57
Get a rating for a bib
58
 my $rating_hashref = GetRating( $biblionumber, undef );
59
 my $rating_hashref = GetRating( $biblionumber, $borrowernumber );
60
61
Add a rating for a bib
62
 my $rating_hashref = AddRating( $biblionumber, $borrowernumber, $rating_value );
63
64
Mod a rating for a bib
65
 my $rating_hashref = ModRating( $biblionumber, $borrowernumber, $rating_value );
66
67
Delete a rating for a bib
68
 my $rating_hashref = DelRating( $biblionumber, $borrowernumber );
69
70
71
All subroutines in Ratings.pm return a hashref which contain 4 keys
72
73
for example, after executing this statment below...
74
75
    my $rating_hashref = GetRating ( $biblionumber, $borrowernumber ) ;
76
77
$rating_hashref now contains a hashref that looks like this...
78
79
    $rating  = {
80
             rating_avg       => '2',
81
             rating_avg_int   => '2.3',
82
             rating_total     => '432',
83
             rating_value => '5'
84
    }
85
86
they 4 keys returned in the hashref are...
87
88
    rating_avg:            average rating of a biblio
89
    rating_avg_int:        average rating of a biblio, rounded to 1dp
90
    rating_total:          total number of ratings of a biblio
91
    rating_value:          logged-in user's rating of a biblio
92
93
=head1 BUGS
94
95
Please use bugs.koha-community.org for tracking bugs.
96
97
=head1 SOURCE AVAILABILITY
98
99
The source is available from the koha-community.org git server
100
L<http://git.koha-community.org>
101
102
=head1 AUTHOR
103
104
Original code: Mason James <mtj@kohaaloha.com>
105
106
=head1 COPYRIGHT
107
108
Copyright (c) 2011 Mason James <mtj@kohaaloha.com>
109
110
=head1 LICENSE
111
112
C4::Ratings is free software. You can redistribute it and/or
113
modify it under the same terms as Koha itself.
114
115
=head1 CREDITS
116
117
 Mason James <mtj@kohaaloha.com>
118
 Koha Dev Team <http://koha-community.org>
119
120
121
=head2 GetRating
122
123
    GetRating($biblionumber, [$borrowernumber])
124
125
Get a rating for a bib
126
 my $rating_hashref = GetRating( $biblionumber, undef );
127
 my $rating_hashref = GetRating( $biblionumber, $borrowernumber );
128
129
This returns the rating for the supplied biblionumber. It will also return
130
the rating that the supplied user gave to the provided biblio. If a particular
131
value can't be supplied, '0' is returned for that value.
132
133
=head3 RETURNS
134
135
A hashref containing:
136
137
=over
138
139
=item * rating_avg - average rating of a biblio
140
=item * rating_avg_int - average rating of a biblio, rounded to 1dp
141
=item * rating_total - total number of ratings of a biblio
142
=item * rating_value - logged-in user's rating of a biblio
143
144
=back
145
146
=cut
147
148
sub GetRating {
149
    my ( $biblionumber, $borrowernumber ) = @_;
150
    my $query = qq| SELECT COUNT(*) AS total, SUM(rating_value) AS sum
151
FROM ratings WHERE biblionumber = ? |;
152
153
    my $sth = C4::Context->dbh->prepare($query);
154
    $sth->execute($biblionumber);
155
    my $res = $sth->fetchrow_hashref();
156
157
    my ( $avg, $avg_int ) = 0;
158
159
    if ( $res->{sum} and $res->{total} ) {
160
        eval { $avg = $res->{sum} / $res->{total} };
161
    }
162
163
    $avg_int = sprintf( "%.1f", $avg );
164
    $avg     = sprintf( "%.0f", $avg );
165
166
    my %rating_hash;
167
    $rating_hash{rating_total}   = $res->{total} || 0;
168
    $rating_hash{rating_avg}     = $avg || 0;
169
    $rating_hash{rating_avg_int} = $avg_int ||0;
170
171
    if ($borrowernumber) {
172
        my $q2 = qq| 
173
SELECT rating_value FROM ratings WHERE biblionumber = ? AND borrowernumber = ?|;
174
        my $sth1 = C4::Context->dbh->prepare($q2);
175
        $sth1->execute( $biblionumber, $borrowernumber );
176
        my $res1 = $sth1->fetchrow_hashref();
177
        $rating_hash{'rating_value'} = $res1->{"rating_value"};
178
    }
179
    else {
180
        $rating_hash{rating_borrowernumber} = undef;
181
        $rating_hash{rating_value}          = undef;
182
    }
183
184
#### %rating_hash
185
    return \%rating_hash;
186
}
187
188
=head2 AddRating
189
190
    my $rating_hashref = AddRating( $biblionumber, $borrowernumber, $rating_value );
191
192
Add a rating for a bib
193
194
This adds or updates a rating for a particular user on a biblio. If the value
195
is 0, then the rating will be deleted. If the value is out of the range of
196
0-5, nothing will happen.
197
198
=cut
199
200
sub AddRating {
201
    my ( $biblionumber, $borrowernumber, $rating_value ) = @_;
202
    my $query =
203
      qq| INSERT INTO ratings (borrowernumber,biblionumber,rating_value)
204
        VALUES (?,?,?)|;
205
    my $sth = C4::Context->dbh->prepare($query);
206
    $sth->execute( $borrowernumber, $biblionumber, $rating_value );
207
    my $rating = GetRating( $biblionumber, $borrowernumber );
208
    return $rating;
209
}
210
211
=head2 ModRating
212
213
    my $rating_hashref = ModRating( $biblionumber, $borrowernumber, $rating_value );
214
215
Mod a rating for a bib
216
217
=cut
218
219
sub ModRating {
220
    my ( $biblionumber, $borrowernumber, $rating_value ) = @_;
221
    my $query =
222
qq|UPDATE ratings SET rating_value = ? WHERE borrowernumber = ? AND biblionumber = ?|;
223
    my $sth = C4::Context->dbh->prepare($query);
224
    $sth->execute( $rating_value, $borrowernumber, $biblionumber );
225
    my $rating = GetRating( $biblionumber, $borrowernumber );
226
    return $rating;
227
}
228
229
=head2 DelRating
230
231
    my $rating_hashref = DelRating( $biblionumber, $borrowernumber );
232
233
Delete a rating for a bib
234
235
=cut
236
237
sub DelRating {
238
    my ( $biblionumber, $borrowernumber ) = @_;
239
    my $dbh = C4::Context->dbh;
240
    my $query =
241
      "delete from ratings where borrowernumber = ? and biblionumber = ?";
242
    my $sth    = C4::Context->dbh->prepare($query);
243
    my $rv     = $sth->execute( $borrowernumber, $biblionumber );
244
    my $rating = GetRating( $biblionumber, undef );
245
    return $rating;
246
}
247
248
1;
249
__END__
(-)a/installer/data/mysql/kohastructure.sql (+15 lines)
Lines 2809-2814 CREATE TABLE IF NOT EXISTS `social_data` ( Link Here
2809
  PRIMARY KEY  (`isbn`)
2809
  PRIMARY KEY  (`isbn`)
2810
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2810
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2811
2811
2812
--
2813
-- 'Ratings' table. This tracks the star ratings set by borrowers.
2814
--
2815
2816
DROP TABLE IF EXISTS ratings;
2817
CREATE TABLE ratings (
2818
    borrowernumber int(11) NOT NULL, --- the borrower this rating is for
2819
    biblionumber int(11) NOT NULL, --- the biblio it's for
2820
    rating_value tinyint(1) NOT NULL, --- the rating, from 1-5
2821
    timestamp timestamp NOT NULL default CURRENT_TIMESTAMP,
2822
    PRIMARY KEY  (borrowernumber,biblionumber),
2823
    CONSTRAINT ratings_ibfk_1 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE,
2824
    CONSTRAINT ratings_ibfk_2 FOREIGN KEY (biblionumber) REFERENCES biblio (biblionumber) ON DELETE CASCADE ON UPDATE CASCADE
2825
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2826
2812
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
2827
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
2813
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
2828
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
2814
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
2829
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
(-)a/installer/data/mysql/sysprefs.sql (+1 lines)
Lines 360-362 INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES Link Here
360
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('SocialNetworks','1','Enable/Disable social networks links in opac detail pages','','YesNo');
360
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('SocialNetworks','1','Enable/Disable social networks links in opac detail pages','','YesNo');
361
INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES('SubscriptionDuplicateDroppedInput','','','List of fields which must not be rewritten when a subscription is duplicated (Separated by pipe |)','Free');
361
INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES('SubscriptionDuplicateDroppedInput','','','List of fields which must not be rewritten when a subscription is duplicated (Separated by pipe |)','Free');
362
INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('AutoResumeSuspendedHolds',  '1', NULL ,  'Allow suspended holds to be automatically resumed by a set date.',  'YesNo');
362
INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('AutoResumeSuspendedHolds',  '1', NULL ,  'Allow suspended holds to be automatically resumed by a set date.',  'YesNo');
363
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OpacStarRatings','all',NULL,'disable|all|details','Choice');
(-)a/installer/data/mysql/updatedatabase.pl (+22 lines)
Lines 4929-4934 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { Link Here
4929
    INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('AllowPKIAuth','None','Use the field from a client-side SSL certificate to look a user in the Koha database','None|Common Name|emailAddress','Choice');
4929
    INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('AllowPKIAuth','None','Use the field from a client-side SSL certificate to look a user in the Koha database','None|Common Name|emailAddress','Choice');
4930
    });
4930
    });
4931
    print "Upgrade to $DBversion done (Bug 6296 New System preference AllowPKIAuth)\n";
4931
    print "Upgrade to $DBversion done (Bug 6296 New System preference AllowPKIAuth)\n";
4932
}
4933
4934
$DBversion = "3.07.00.XXX";
4935
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
4936
    $dbh->do(
4937
        q | CREATE TABLE ratings (
4938
  borrowernumber int(11) NOT NULL,
4939
  biblionumber int(11) NOT NULL,
4940
  rating_value tinyint(1) NOT NULL,
4941
  timestamp timestamp NOT NULL default CURRENT_TIMESTAMP,
4942
  PRIMARY KEY  (borrowernumber,biblionumber),
4943
  CONSTRAINT ratings_ibfk_1 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE,
4944
  CONSTRAINT ratings_ibfk_2 FOREIGN KEY (biblionumber) REFERENCES biblio (biblionumber) ON DELETE CASCADE ON UPDATE CASCADE
4945
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
4946
    );
4947
4948
    $dbh->do(
4949
q /INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OpacStarRatings','disable',NULL,'disable|all|details','Choice') /
4950
    );
4951
4952
    print
4953
"Upgrade to $DBversion done (Add 'ratings' table and 'OpacStarRatings' syspref)\n";
4932
    SetVersion($DBversion);
4954
    SetVersion($DBversion);
4933
}
4955
}
4934
4956
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt (+6 lines)
Lines 342-347 Link Here
342
                  <a rel="license" href="http://creativecommons.org/licenses/by-sa/2.5/">Creative Commons Attribution-ShareAlike 2.5 License</a>
342
                  <a rel="license" href="http://creativecommons.org/licenses/by-sa/2.5/">Creative Commons Attribution-ShareAlike 2.5 License</a>
343
                  by the Bridge Consortium of Carleton College and St. Olaf College.</li>
343
                  by the Bridge Consortium of Carleton College and St. Olaf College.</li>
344
              </ul>
344
              </ul>
345
346
            <h2>jQuery Star Rating Plugin</h2>
347
              <p>jQuery Star Rating Plugin v3.14 by <a href="http://www.fyneworks.com/">Fyneworks.com</a> is licensed under the <a target="_blank" href="http://en.wikipedia.org/wiki/MIT_License">MIT License</a> and the <a target="_blank" href="http://creativecommons.org/licenses/GPL/2.0/">GPL License</a>.</p>
348
349
            <p>Copyright &copy; 2008 <a href="http://www.fyneworks.com/">Fyneworks.com</a></p>
350
345
        </div>
351
        </div>
346
352
347
        <div id="translations">
353
        <div id="translations">
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref (+12 lines)
Lines 6-11 OPAC: Link Here
6
              choices: opac-templates
6
              choices: opac-templates
7
            - theme on the OPAC.
7
            - theme on the OPAC.
8
        -
8
        -
9
10
11
12
9
            - "The OPAC is located at http://"
13
            - "The OPAC is located at http://"
10
            - pref: OPACBaseURL
14
            - pref: OPACBaseURL
11
              class: url
15
              class: url
Lines 22-27 OPAC: Link Here
22
                  no: Disable
26
                  no: Disable
23
            - "Koha OPAC as public. Private OPAC requires authentification before accessing the OPAC."
27
            - "Koha OPAC as public. Private OPAC requires authentification before accessing the OPAC."
24
        -
28
        -
29
            - "Show star-ratings on"
30
            - pref: OpacStarRatings
31
              choices:
32
                  all: "results and details"
33
                  disable: "no"
34
                  details: "only details"
35
            - "pages."
36
        -
25
            - pref: OpacMaintenance
37
            - pref: OpacMaintenance
26
              choices:
38
              choices:
27
                  yes: Show
39
                  yes: Show
(-)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:15px;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 -32px!important}
7
div.star-rating-hover a{background-position:0 -16px}
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.js (+392 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
12
/*# AVOID COLLISIONS #*/
13
;if(window.jQuery) (function($){
14
/*# AVOID COLLISIONS #*/
15
	
16
	// IE6 Background Image Fix
17
	if ($.browser.msie) try { document.execCommand("BackgroundImageCache", false, true)} catch(e) { };
18
	// Thanks to http://www.visualjquery.com/rating/rating_redux.html
19
	
20
	// plugin initialization
21
	$.fn.rating = function(options){
22
		if(this.length==0) return this; // quick fail
23
		
24
		// Handle API methods
25
		if(typeof arguments[0]=='string'){
26
			// Perform API methods on individual elements
27
			if(this.length>1){
28
				var args = arguments;
29
				return this.each(function(){
30
					$.fn.rating.apply($(this), args);
31
    });
32
			};
33
			// Invoke API method handler
34
			$.fn.rating[arguments[0]].apply(this, $.makeArray(arguments).slice(1) || []);
35
			// Quick exit...
36
			return this;
37
		};
38
		
39
		// Initialize options for this call
40
		var options = $.extend(
41
			{}/* new object */,
42
			$.fn.rating.options/* default options */,
43
			options || {} /* just-in-time options */
44
		);
45
		
46
		// Allow multiple controls with the same name by making each call unique
47
		$.fn.rating.calls++;
48
		
49
		// loop through each matched element
50
		this
51
		 .not('.star-rating-applied')
52
			.addClass('star-rating-applied')
53
		.each(function(){
54
			
55
			// Load control parameters / find context / etc
56
			var control, input = $(this);
57
			var eid = (this.name || 'unnamed-rating').replace(/\[|\]/g, '_').replace(/^\_+|\_+$/g,'');
58
			var context = $(this.form || document.body);
59
			
60
			// FIX: http://code.google.com/p/jquery-star-rating-plugin/issues/detail?id=23
61
			var raters = context.data('rating');
62
			if(!raters || raters.call!=$.fn.rating.calls) raters = { count:0, call:$.fn.rating.calls };
63
			var rater = raters[eid];
64
			
65
			// if rater is available, verify that the control still exists
66
			if(rater) control = rater.data('rating');
67
			
68
			if(rater && control)//{// save a byte!
69
				// add star to control if rater is available and the same control still exists
70
				control.count++;
71
				
72
			//}// save a byte!
73
			else{
74
				// create new control if first star or control element was removed/replaced
75
				
76
				// Initialize options for this rater
77
				control = $.extend(
78
					{}/* new object */,
79
					options || {} /* current call options */,
80
					($.metadata? input.metadata(): ($.meta?input.data():null)) || {}, /* metadata options */
81
					{ count:0, stars: [], inputs: [] }
82
				);
83
				
84
				// increment number of rating controls
85
				control.serial = raters.count++;
86
				
87
				// create rating element
88
				rater = $('<span class="star-rating-control"/>');
89
				input.before(rater);
90
				
91
				// Mark element for initialization (once all stars are ready)
92
				rater.addClass('rating-to-be-drawn');
93
				
94
				// Accept readOnly setting from 'disabled' property
95
				if(input.attr('disabled') || input.hasClass('disabled')) control.readOnly = true;
96
				
97
				// Accept required setting from class property (class='required')
98
				if(input.hasClass('required')) control.required = true;
99
				
100
				// Create 'cancel' button
101
				rater.append(
102
					control.cancel = $('<div class="rating-cancel"><a title="' + control.cancel + '">' + control.cancelValue + '</a></div>')
103
					.mouseover(function(){
104
						$(this).rating('drain');
105
						$(this).addClass('star-rating-hover');
106
						//$(this).rating('focus');
107
					})
108
					.mouseout(function(){
109
						$(this).rating('draw');
110
						$(this).removeClass('star-rating-hover');
111
						//$(this).rating('blur');
112
					})
113
					.click(function(){
114
					 $(this).rating('select');
115
					})
116
					.data('rating', control)
117
				);
118
				
119
			}; // first element of group
120
			
121
			// insert rating star
122
			var star = $('<div class="star-rating rater-'+ control.serial +'"><a title="' + (this.title || this.value) + '">' + this.value + '</a></div>');
123
			rater.append(star);
124
			
125
			// inherit attributes from input element
126
			if(this.id) star.attr('id', this.id);
127
			if(this.className) star.addClass(this.className);
128
			
129
			// Half-stars?
130
			if(control.half) control.split = 2;
131
			
132
			// Prepare division control
133
			if(typeof control.split=='number' && control.split>0){
134
				var stw = ($.fn.width ? star.width() : 0) || control.starWidth;
135
				var spi = (control.count % control.split), spw = Math.floor(stw/control.split);
136
				star
137
				// restrict star's width and hide overflow (already in CSS)
138
				.width(spw)
139
				// move the star left by using a negative margin
140
				// this is work-around to IE's stupid box model (position:relative doesn't work)
141
				.find('a').css({ 'margin-left':'-'+ (spi*spw) +'px' })
142
			};
143
			
144
			// readOnly?
145
			if(control.readOnly)//{ //save a byte!
146
				// Mark star as readOnly so user can customize display
147
				star.addClass('star-rating-readonly');
148
			//}  //save a byte!
149
			else//{ //save a byte!
150
			 // Enable hover css effects
151
				star.addClass('star-rating-live')
152
				 // Attach mouse events
153
					.mouseover(function(){
154
						$(this).rating('fill');
155
						$(this).rating('focus');
156
					})
157
					.mouseout(function(){
158
						$(this).rating('draw');
159
						$(this).rating('blur');
160
					})
161
					.click(function(){
162
						$(this).rating('select');
163
					})
164
				;
165
			//}; //save a byte!
166
			
167
			// set current selection
168
			if(this.checked)	control.current = star;
169
			
170
			// set current select for links
171
			if(this.nodeName=="A"){
172
    if($(this).hasClass('selected'))
173
     control.current = star;
174
   };
175
			
176
			// hide input element
177
			input.hide();
178
			
179
			// backward compatibility, form element to plugin
180
			input.change(function(){
181
    $(this).rating('select');
182
   });
183
			
184
			// attach reference to star to input element and vice-versa
185
			star.data('rating.input', input.data('rating.star', star));
186
			
187
			// store control information in form (or body when form not available)
188
			control.stars[control.stars.length] = star[0];
189
			control.inputs[control.inputs.length] = input[0];
190
			control.rater = raters[eid] = rater;
191
			control.context = context;
192
			
193
			input.data('rating', control);
194
			rater.data('rating', control);
195
			star.data('rating', control);
196
			context.data('rating', raters);
197
  }); // each element
198
		
199
		// Initialize ratings (first draw)
200
		$('.rating-to-be-drawn').rating('draw').removeClass('rating-to-be-drawn');
201
		
202
		return this; // don't break the chain...
203
	};
204
	
205
	/*--------------------------------------------------------*/
206
	
207
	/*
208
		### Core functionality and API ###
209
	*/
210
	$.extend($.fn.rating, {
211
		// Used to append a unique serial number to internal control ID
212
		// each time the plugin is invoked so same name controls can co-exist
213
		calls: 0,
214
		
215
		focus: function(){
216
			var control = this.data('rating'); if(!control) return this;
217
			if(!control.focus) return this; // quick fail if not required
218
			// find data for event
219
			var input = $(this).data('rating.input') || $( this.tagName=='INPUT' ? this : null );
220
   // focus handler, as requested by focusdigital.co.uk
221
			if(control.focus) control.focus.apply(input[0], [input.val(), $('a', input.data('rating.star'))[0]]);
222
		}, // $.fn.rating.focus
223
		
224
		blur: function(){
225
			var control = this.data('rating'); if(!control) return this;
226
			if(!control.blur) return this; // quick fail if not required
227
			// find data for event
228
			var input = $(this).data('rating.input') || $( this.tagName=='INPUT' ? this : null );
229
   // blur handler, as requested by focusdigital.co.uk
230
			if(control.blur) control.blur.apply(input[0], [input.val(), $('a', input.data('rating.star'))[0]]);
231
		}, // $.fn.rating.blur
232
		
233
		fill: function(){ // fill to the current mouse position.
234
			var control = this.data('rating'); if(!control) return this;
235
			// do not execute when control is in read-only mode
236
			if(control.readOnly) return;
237
			// Reset all stars and highlight them up to this element
238
			this.rating('drain');
239
			this.prevAll().andSelf().filter('.rater-'+ control.serial).addClass('star-rating-hover');
240
		},// $.fn.rating.fill
241
		
242
		drain: function() { // drain all the stars.
243
			var control = this.data('rating'); if(!control) return this;
244
			// do not execute when control is in read-only mode
245
			if(control.readOnly) return;
246
			// Reset all stars
247
			control.rater.children().filter('.rater-'+ control.serial).removeClass('star-rating-on').removeClass('star-rating-hover');
248
		},// $.fn.rating.drain
249
		
250
		draw: function(){ // set value and stars to reflect current selection
251
			var control = this.data('rating'); if(!control) return this;
252
			// Clear all stars
253
			this.rating('drain');
254
			// Set control value
255
			if(control.current){
256
				control.current.data('rating.input').attr('checked','checked');
257
				control.current.prevAll().andSelf().filter('.rater-'+ control.serial).addClass('star-rating-on');
258
			}
259
			else
260
			 $(control.inputs).removeAttr('checked');
261
			// Show/hide 'cancel' button
262
			control.cancel[control.readOnly || control.required?'hide':'show']();
263
			// Add/remove read-only classes to remove hand pointer
264
			this.siblings()[control.readOnly?'addClass':'removeClass']('star-rating-readonly');
265
		},// $.fn.rating.draw
266
		
267
		
268
		
269
		
270
		
271
		select: function(value,wantCallBack){ // select a value
272
					
273
					// ***** MODIFICATION *****
274
					// Thanks to faivre.thomas - http://code.google.com/p/jquery-star-rating-plugin/issues/detail?id=27
275
					//
276
					// ***** LIST OF MODIFICATION *****
277
					// ***** added Parameter wantCallBack : false if you don't want a callback. true or undefined if you want postback to be performed at the end of this method'
278
					// ***** recursive calls to this method were like : ... .rating('select') it's now like .rating('select',undefined,wantCallBack); (parameters are set.)
279
					// ***** line which is calling callback
280
					// ***** /LIST OF MODIFICATION *****
281
			
282
			var control = this.data('rating'); if(!control) return this;
283
			// do not execute when control is in read-only mode
284
			if(control.readOnly) return;
285
			// clear selection
286
			control.current = null;
287
			// programmatically (based on user input)
288
			if(typeof value!='undefined'){
289
			 // select by index (0 based)
290
				if(typeof value=='number')
291
 			 return $(control.stars[value]).rating('select',undefined,wantCallBack);
292
				// select by literal value (must be passed as a string
293
				if(typeof value=='string')
294
					//return
295
					$.each(control.stars, function(){
296
						if($(this).data('rating.input').val()==value) $(this).rating('select',undefined,wantCallBack);
297
					});
298
			}
299
			else
300
				control.current = this[0].tagName=='INPUT' ?
301
				 this.data('rating.star') :
302
					(this.is('.rater-'+ control.serial) ? this : null);
303
304
			// Update rating control state
305
			this.data('rating', control);
306
			// Update display
307
			this.rating('draw');
308
			// find data for event
309
			var input = $( control.current ? control.current.data('rating.input') : null );
310
			// click callback, as requested here: http://plugins.jquery.com/node/1655
311
					
312
					// **** MODIFICATION *****
313
					// Thanks to faivre.thomas - http://code.google.com/p/jquery-star-rating-plugin/issues/detail?id=27
314
					//
315
					//old line doing the callback :
316
					//if(control.callback) control.callback.apply(input[0], [input.val(), $('a', control.current)[0]]);// callback event
317
					//
318
					//new line doing the callback (if i want :)
319
					if((wantCallBack ||wantCallBack == undefined) && control.callback) control.callback.apply(input[0], [input.val(), $('a', control.current)[0]]);// callback event
320
					//to ensure retro-compatibility, wantCallBack must be considered as true by default
321
					// **** /MODIFICATION *****
322
					
323
  },// $.fn.rating.select
324
		
325
		
326
		
327
		
328
		
329
		readOnly: function(toggle, disable){ // make the control read-only (still submits value)
330
			var control = this.data('rating'); if(!control) return this;
331
			// setread-only status
332
			control.readOnly = toggle || toggle==undefined ? true : false;
333
			// enable/disable control value submission
334
			if(disable) $(control.inputs).attr("disabled", "disabled");
335
			else     			$(control.inputs).removeAttr("disabled");
336
			// Update rating control state
337
			this.data('rating', control);
338
			// Update display
339
			this.rating('draw');
340
		},// $.fn.rating.readOnly
341
		
342
		disable: function(){ // make read-only and never submit value
343
			this.rating('readOnly', true, true);
344
		},// $.fn.rating.disable
345
		
346
		enable: function(){ // make read/write and submit value
347
			this.rating('readOnly', false, false);
348
		}// $.fn.rating.select
349
		
350
 });
351
	
352
	/*--------------------------------------------------------*/
353
	
354
	/*
355
		### Default Settings ###
356
		eg.: You can override default control like this:
357
		$.fn.rating.options.cancel = 'Clear';
358
	*/
359
	$.fn.rating.options = { //$.extend($.fn.rating, { options: {
360
			cancel: 'Cancel Rating',   // advisory title for the 'cancel' link
361
			cancelValue: '',           // value to submit when user click the 'cancel' link
362
			split: 0,                  // split the star into how many parts?
363
			
364
			// Width of star image in case the plugin can't work it out. This can happen if
365
			// the jQuery.dimensions plugin is not available OR the image is hidden at installation
366
			starWidth: 16//,
367
			
368
			//NB.: These don't need to be pre-defined (can be undefined/null) so let's save some code!
369
			//half:     false,         // just a shortcut to control.split = 2
370
			//required: false,         // disables the 'cancel' button so user can only select one of the specified values
371
			//readOnly: false,         // disable rating plugin interaction/ values cannot be changed
372
			//focus:    function(){},  // executed when stars are focused
373
			//blur:     function(){},  // executed when stars are focused
374
			//callback: function(){},  // executed when a star is clicked
375
 }; //} });
376
	
377
	/*--------------------------------------------------------*/
378
	
379
	/*
380
		### Default implementation ###
381
		The plugin will attach itself to file inputs
382
		with the class 'multi' when the page loads
383
	*/
384
	$(function(){
385
	 $('input[type=radio].star').rating();
386
	});
387
	
388
	
389
	
390
/*# AVOID COLLISIONS #*/
391
})(jQuery);
392
/*# AVOID COLLISIONS #*/
(-)a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt (-1 / +88 lines)
Lines 9-14 Link Here
9
      {lang: '[% lang %]'}
9
      {lang: '[% lang %]'}
10
    </script>
10
    </script>
11
[% END %]
11
[% END %]
12
<script type="text/javascript" src="/opac-tmpl/prog/en/lib/jquery/plugins/jquery.rating.js"></script>
13
<link rel="stylesheet" type="text/css" href="/opac-tmpl/prog/en/css/jquery.rating.css" />
14
12
<script type="text/JavaScript" language="JavaScript">
15
<script type="text/JavaScript" language="JavaScript">
13
//<![CDATA[
16
//<![CDATA[
14
    [% IF ( busc ) %]
17
    [% IF ( busc ) %]
Lines 83-90 Link Here
83
        [% END %]
86
        [% END %]
84
87
85
        $(".branch-info-tooltip-trigger").tooltip({delay: 100, position: "top right"});
88
        $(".branch-info-tooltip-trigger").tooltip({delay: 100, position: "top right"});
89
90
// -----------------------------------------------------
91
// star-ratings code
92
// -----------------------------------------------------
93
// hide 'rate' button if javascript enabled
94
95
$('input[name="rate_button"]').remove();
96
97
$(function () {
98
  $(".auto-submit-star").rating({
99
    callback: function (value, link) {
100
101
      // if the new value equals the old value, dont execute callback...
102
      // just do nothing!
103
      if ($("#rating_value").attr("value") != value) {
104
105
        $(function () {
106
107
          $.post("/cgi-bin/koha/opac-ratings-ajax.pl", {
108
            rating_old_value: $("#rating_value").attr("value"),
109
            borrowernumber: "[% borrowernumber %]",
110
            biblionumber: "[% biblionumber %]",
111
            rating_value: value,
112
            auth_error: value,
113
          }, function (data) {
114
115
            if (data.auth_status != 'ok') {
116
              window.alert('Your CGI session cookie is not current. Please refresh the page and try again.');
117
            } else {
118
              $("#rating_value").val(data.rating_value);
119
120
              if (data.rating_value) {
121
                $("#rating_value_text").text('your rating: ' + data.rating_value + ', ');
122
              } else {
123
                $("#rating_value_text").text('');
124
              }
125
126
              $("#rating_text").text('average rating: ' + data.rating_avg_int + ' (' + data.rating_total + ' votes)');
127
128
            }
129
          }, "json");
130
        });
131
      };
132
    }
133
  });
86
});
134
});
135
// -----------------------------------------------------
87
136
137
});
88
138
89
[% IF ( busc ) %]
139
[% IF ( busc ) %]
90
140
Lines 215-221 YAHOO.util.Event.onContentReady("furtherm", function () { Link Here
215
		YAHOO.util.Event.addListener("furthersearches", "click", furthersearchesMenu.show, null, furthersearchesMenu);
265
		YAHOO.util.Event.addListener("furthersearches", "click", furthersearchesMenu.show, null, furthersearchesMenu);
216
		YAHOO.widget.Overlay.windowResizeEvent.subscribe(positionfurthersearchesMenu);
266
		YAHOO.widget.Overlay.windowResizeEvent.subscribe(positionfurthersearchesMenu);
217
 });
267
 });
218
	
219
//]]>
268
//]]>
220
</script>
269
</script>
221
[% IF ( opacuserlogin ) %][% IF ( loggedinusername ) %][% IF ( TagsEnabled ) %]<style type="text/css">
270
[% IF ( opacuserlogin ) %][% IF ( loggedinusername ) %][% IF ( TagsEnabled ) %]<style type="text/css">
Lines 488-493 YAHOO.util.Event.onContentReady("furtherm", function () { Link Here
488
        </span>
537
        </span>
489
        [% END %][% END %][% END %]
538
        [% END %][% END %][% END %]
490
539
540
    [% IF ( OpacStarRatings != 'disable' ) %]
541
        <form method="post" action="/cgi-bin/koha/opac-ratings.pl">
542
        <div class="results_summary">
543
544
      [% FOREACH i  IN [ 1 2 3 4 5  ] %]
545
        [% IF rating_avg == i && borrowernumber %]
546
            <input class="auto-submit-star" type="radio" name="rating"  value="[% i %]"  checked="checked" />
547
        [% ELSIF rating_avg == i %]
548
            <input class="auto-submit-star" type="radio" name="rating" value="[% i %]" checked="checked" disabled="disabled" />
549
        [% ELSIF borrowernumber  %]
550
            <input class="auto-submit-star" type="radio" name="rating" value="[% i %]" />
551
        [% ELSE   %]
552
            <input class="auto-submit-star" type="radio" name="rating" value="[% i %]" disabled="disabled" />
553
        [% END %]
554
      [% END %]
555
556
<!-- define some hidden vars for ratings -->
557
558
        <input  type="hidden" name='biblionumber'  value="[% biblionumber %]" />
559
        <input  type="hidden" name='borrowernumber'  value="[% borrowernumber %]" />
560
        <input  type="hidden" name='rating_value' id='rating_value' value="[% rating_value %]" />
561
        <input  type="hidden" name='rating_total' id='rating_total' value="[% rating_total %]" />
562
        <input  type="hidden" name='rating_avg_int' id='rating_avg_int' value="[% rating_avg_int %]" />
563
564
        [% UNLESS ( rating_readonly ) %]&nbsp;  <INPUT name="rate_button" type="submit" value="Rate me">[% END %]&nbsp;
565
566
	    [% IF ( rating_value ) %]
567
            <span id="rating_value_text">your rating: [% rating_value %], </span>
568
        [% ELSE %]
569
            <span id="rating_value_text"></span>
570
        [% END %]
571
572
            <span id="rating_text">average rating: [% rating_avg_int %] ([% rating_total %] votes)</span>
573
574
        </div>
575
        </FORM>
576
    [% END %]
577
491
    [% IF ( BakerTaylorContentURL ) %]
578
    [% IF ( BakerTaylorContentURL ) %]
492
        <span class="results_summary">
579
        <span class="results_summary">
493
        <span class="label">Enhanced Content: </span> 
580
        <span class="label">Enhanced Content: </span> 
(-)a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt (-5 / +35 lines)
Lines 6-13 Link Here
6
    You did not specify any search criteria.
6
    You did not specify any search criteria.
7
[% END %]
7
[% END %]
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
<script type="text/javascript" src="/opac-tmpl/prog/en/lib/jquery/jquery.js"></script>
11
<script type="text/javascript" src="/opac-tmpl/prog/en/lib/jquery/plugins/jquery.rating.js"></script>
12
<link rel="stylesheet" type="text/css" href="/opac-tmpl/prog/en/css/jquery.rating.css" />
11
13
12
<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.checkboxes.min.js"></script>
14
<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>
15
[% IF ( OpacHighlightedWords ) %]<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.highlight-3.js"></script>
Lines 234-239 $(document).ready(function(){ Link Here
234
    [% IF OPACLocalCoverImages %]KOHA.LocalCover.GetCoverFromBibnumber(false);[% END %]
236
    [% IF OPACLocalCoverImages %]KOHA.LocalCover.GetCoverFromBibnumber(false);[% END %]
235
    [% IF ( GoogleJackets ) %]KOHA.Google.GetCoverFromIsbn();[% END %]
237
    [% IF ( GoogleJackets ) %]KOHA.Google.GetCoverFromIsbn();[% END %]
236
});
238
});
239
237
//]]>
240
//]]>
238
</script>
241
</script>
239
</head>
242
</head>
Lines 481-488 $(document).ready(function(){ Link Here
481
                    [% IF ( SEARCH_RESULT.intransitcount ) %] In transit ([% SEARCH_RESULT.intransitcount %]),[% END %]
484
                    [% IF ( SEARCH_RESULT.intransitcount ) %] In transit ([% SEARCH_RESULT.intransitcount %]),[% END %]
482
                    </span>
485
                    </span>
483
                </span>
486
                </span>
484
485
                [% END %]
487
                [% END %]
488
486
                [% IF ( SEARCH_RESULT.score_avg ) %]
489
                [% IF ( SEARCH_RESULT.score_avg ) %]
487
                    <span class="result_summary">
490
                    <span class="result_summary">
488
                        <img src="[% themelang %]/../images/Star[% SEARCH_RESULT.score_int %].gif" title="" style="max-height: 15px;"/> <span style="font-size: 85%;">[% SEARCH_RESULT.score_avg %] / 5 (on [% SEARCH_RESULT.num_scores %] rates)</span>
491
                        <img src="[% themelang %]/../images/Star[% SEARCH_RESULT.score_int %].gif" title="" style="max-height: 15px;"/> <span style="font-size: 85%;">[% SEARCH_RESULT.score_avg %] / 5 (on [% SEARCH_RESULT.num_scores %] rates)</span>
Lines 500-507 $(document).ready(function(){ Link Here
500
                        [% END %]
503
                        [% END %]
501
                    </span>
504
                    </span>
502
                [% END %]
505
                [% END %]
503
                [% IF ( LibraryThingForLibrariesID ) %]<div class="ltfl_reviews"></div>[% END %]
506
504
                [% IF ( opacuserlogin ) %][% IF ( TagsEnabled ) %]
507
508
				[% IF ( OpacStarRatings == 'all' ) %]
509
                <div class="results_summary">
510
511
[% FOREACH i  IN [ 1 2 3 4 5  ] %]
512
513
[% IF ( SEARCH_RESULT.rating_avg == i ) %]
514
    <input class="star" type="radio"  name="rating-[% SEARCH_RESULT.biblionumber %]" value="[% i %]" checked="checked" disabled="disabled"   />
515
[% ELSE   %]
516
    <input class="star" type="radio"  name="rating-[% SEARCH_RESULT.biblionumber %]" value="[% i %]" disabled="disabled"   />
517
[% END %]
518
519
[% END %]
520
                <input type="hidden" name='biblionumber'  value="[% SEARCH_RESULT.biblionumber %]" />
521
                <input type="hidden" name='loggedinuser'  value="[% loggedinuser %]" />
522
523
				[% IF (  SEARCH_RESULT.rating_total ) > 0  %]
524
                    <span id="rating_total_[% SEARCH_RESULT.biblionumber %]">&nbsp;&nbsp;([% SEARCH_RESULT.rating_total %] votes)</span>
525
				[% ELSE %]
526
                    </br>
527
				[% END %]
528
529
                </div>
530
				[% END %]
531
532
533
				[% IF ( LibraryThingForLibrariesID ) %]<div class="ltfl_reviews"></div>[% END %]
534
				[% IF ( opacuserlogin ) %][% IF ( TagsEnabled ) %]
505
                                [% IF ( TagsShowOnList ) %]
535
                                [% IF ( TagsShowOnList ) %]
506
                                [% IF ( SEARCH_RESULT.TagLoop.size ) %]
536
                                [% IF ( SEARCH_RESULT.TagLoop.size ) %]
507
                                        <div class="results_summary"><span class="label">Tags:</span>
537
                                        <div class="results_summary"><span class="label">Tags:</span>
(-)a/opac/opac-detail.pl (-1 / +21 lines)
Lines 2-7 Link Here
2
2
3
# Copyright 2000-2002 Katipo Communications
3
# Copyright 2000-2002 Katipo Communications
4
# Copyright 2010 BibLibre
4
# Copyright 2010 BibLibre
5
# Copyright 2011 KohaAloha, NZ
5
#
6
#
6
# This file is part of Koha.
7
# This file is part of Koha.
7
#
8
#
Lines 36-41 use C4::XISBN qw(get_xisbns get_biblionumber_from_isbn); Link Here
36
use C4::External::Amazon;
37
use C4::External::Amazon;
37
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 );
38
use C4::Review;
39
use C4::Review;
40
use C4::Ratings;
39
use C4::Members;
41
use C4::Members;
40
use C4::VirtualShelves;
42
use C4::VirtualShelves;
41
use C4::XSLT;
43
use C4::XSLT;
Lines 548-554 my $subtitle = GetRecordValue('subtitle', $record, GetFrameworkCode($bib Link Here
548
                     MARCAUTHORS             => $marcauthorsarray,
550
                     MARCAUTHORS             => $marcauthorsarray,
549
                     MARCSERIES              => $marcseriesarray,
551
                     MARCSERIES              => $marcseriesarray,
550
                     MARCURLS                => $marcurlsarray,
552
                     MARCURLS                => $marcurlsarray,
551
		     MARCHOSTS               => $marchostsarray,
553
		             MARCHOSTS               => $marchostsarray,
552
                     norequests              => $norequests,
554
                     norequests              => $norequests,
553
                     RequestOnOpac           => C4::Context->preference("RequestOnOpac"),
555
                     RequestOnOpac           => C4::Context->preference("RequestOnOpac"),
554
                     itemdata_ccode          => $itemfields{ccode},
556
                     itemdata_ccode          => $itemfields{ccode},
Lines 558-563 my $subtitle = GetRecordValue('subtitle', $record, GetFrameworkCode($bib Link Here
558
                     itemdata_itemnotes          => $itemfields{itemnotes},
560
                     itemdata_itemnotes          => $itemfields{itemnotes},
559
                     authorised_value_images => $biblio_authorised_value_images,
561
                     authorised_value_images => $biblio_authorised_value_images,
560
                     subtitle                => $subtitle,
562
                     subtitle                => $subtitle,
563
                     OpacStarRatings         => C4::Context->preference("OpacStarRatings"),
561
    );
564
    );
562
565
563
if (C4::Context->preference("AlternateHoldingsField") && scalar @items == 0) {
566
if (C4::Context->preference("AlternateHoldingsField") && scalar @items == 0) {
Lines 628-633 if ( C4::Context->preference('ShowReviewer') and C4::Context->preference('ShowRe Link Here
628
631
629
my $reviews = getreviews( $biblionumber, 1 );
632
my $reviews = getreviews( $biblionumber, 1 );
630
my $loggedincommenter;
633
my $loggedincommenter;
634
635
636
637
631
foreach ( @$reviews ) {
638
foreach ( @$reviews ) {
632
    my $borrowerData   = GetMember('borrowernumber' => $_->{borrowernumber});
639
    my $borrowerData   = GetMember('borrowernumber' => $_->{borrowernumber});
633
    # setting some borrower info into this hash
640
    # setting some borrower info into this hash
Lines 639-644 foreach ( @$reviews ) { Link Here
639
    }
646
    }
640
    $_->{userid}    = $borrowerData->{'userid'};
647
    $_->{userid}    = $borrowerData->{'userid'};
641
    $_->{cardnumber}    = $borrowerData->{'cardnumber'};
648
    $_->{cardnumber}    = $borrowerData->{'cardnumber'};
649
    $_->{datereviewed} = format_date($_->{datereviewed});
650
642
    if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
651
    if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
643
		$_->{your_comment} = 1;
652
		$_->{your_comment} = 1;
644
		$loggedincommenter = 1;
653
		$loggedincommenter = 1;
Lines 907-912 my $OpacExportOptions=C4::Context->preference("OpacExportOptions"); Link Here
907
my @export_options = split(/\|/,$OpacExportOptions);
916
my @export_options = split(/\|/,$OpacExportOptions);
908
$template->{VARS}->{'export_options'} = \@export_options;
917
$template->{VARS}->{'export_options'} = \@export_options;
909
918
919
if ( C4::Context->preference('OpacStarRatings') !~ /disable/ ) {
920
    my $rating = GetRating( $biblionumber, $borrowernumber );
921
    $template->param(
922
        rating_value   => $rating->{'rating_value'},
923
        rating_total   => $rating->{'rating_total'},
924
        rating_avg     => $rating->{'rating_avg'},
925
        rating_avg_int => $rating->{'rating_avg_int'},
926
        borrowernumber => $borrowernumber
927
    );
928
}
929
910
#Search for title in links
930
#Search for title in links
911
my $marccontrolnumber   = GetMarcControlnumber ($record, $marcflavour);
931
my $marccontrolnumber   = GetMarcControlnumber ($record, $marcflavour);
912
my $marcissns = GetMarcISSN ( $record, $marcflavour );
932
my $marcissns = GetMarcISSN ( $record, $marcflavour );
(-)a/opac/opac-ratings-ajax.pl (+115 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2011 KohaAloha, NZ
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
=head1 DESCRIPTION
21
22
A script that takes an ajax json query, and then inserts or modifies a star-rating.
23
24
=cut
25
26
use strict;
27
use warnings;
28
29
use CGI;
30
use CGI::Cookie;  # need to check cookies before having CGI parse the POST request
31
32
use C4::Auth qw(:DEFAULT check_cookie_auth);
33
use C4::Context;
34
use C4::Debug;
35
use C4::Output 3.02 qw(:html :ajax pagination_bar);
36
use C4::Ratings;
37
use JSON;
38
39
my $is_ajax = is_ajax();
40
41
my ( $query, $auth_status );
42
if ($is_ajax) {
43
    ( $query, $auth_status ) = &ajax_auth_cgi( {} );
44
}
45
else {
46
    $query = CGI->new();
47
}
48
49
my $biblionumber     = $query->param('biblionumber');
50
my $rating_value     = $query->param('rating_value');
51
my $rating_old_value = $query->param('rating_old_value');
52
53
my ( $template, $loggedinuser, $cookie );
54
if ($is_ajax) {
55
    $loggedinuser = C4::Context->userenv->{'number'};
56
}
57
else {
58
    ( $template, $loggedinuser, $cookie ) = get_template_and_user(
59
        {
60
            template_name   => "opac-detail.tt",
61
            query           => $query,
62
            type            => "opac",
63
            authnotrequired => 0,                    # auth required to add tags
64
            debug           => 1,
65
        }
66
    );
67
}
68
69
my $rating;
70
71
undef $rating_value if $rating_value eq '';
72
73
if ( !$rating_value ) {
74
#### delete
75
    $rating = DelRating( $biblionumber, $loggedinuser );
76
}
77
78
elsif ( $rating_value and !$rating_old_value ) {
79
#### insert
80
    $rating = AddRating( $biblionumber, $loggedinuser, $rating_value );
81
}
82
83
elsif ( $rating_value ne $rating_old_value ) {
84
#### mod
85
    $rating = ModRating( $biblionumber, $loggedinuser, $rating_value );
86
}
87
88
my %js_reply = (
89
    rating_total   => $rating->{'rating_total'},
90
    rating_avg     => $rating->{'rating_avg'},
91
    rating_avg_int => $rating->{'rating_avg_int'},
92
    rating_value   => $rating->{'rating_value'},
93
    auth_status    => $auth_status,
94
95
);
96
97
my $json_reply = JSON->new->encode( \%js_reply );
98
99
#### $rating
100
#### %js_reply
101
#### $json_reply
102
103
output_ajax_with_http_headers( $query, $json_reply );
104
exit;
105
106
# a ratings specific ajax return sub, returns CGI object, and an 'auth_success' value
107
sub ajax_auth_cgi {
108
    my $needed_flags = shift;
109
    my %cookies      = fetch CGI::Cookie;
110
    my $input        = CGI->new;
111
    my $sessid = $cookies{'CGISESSID'}->value || $input->param('CGISESSID');
112
    my ( $auth_status, $auth_sessid ) =
113
      check_cookie_auth( $sessid, $needed_flags );
114
    return $input, $auth_status;
115
}
(-)a/opac/opac-ratings.pl (+65 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2011 KohaAloha, NZ
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
=head1
21
22
A non-javascript method to add/modify a biblio's rating, called from opac-detail.pl
23
24
note: there is currently no 'delete rating' functionality in this script
25
26
=cut
27
28
use strict;
29
use warnings;
30
use CGI;
31
use CGI::Cookie;
32
use C4::Auth qw(:DEFAULT check_cookie_auth);
33
use C4::Context;
34
use C4::Output;
35
use C4::Dates qw(format_date);
36
use C4::Biblio;
37
use C4::Ratings;
38
use C4::Debug;
39
40
my $query = CGI->new();
41
my $a     = $query->Vars;
42
####  $a
43
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
44
    {
45
        template_name   => "",
46
        query           => $query,
47
        type            => "opac",
48
        authnotrequired => 0,        # auth required to add tags
49
        debug           => 0,
50
    }
51
);
52
53
my $biblionumber     = $query->param('biblionumber');
54
my $rating_old_value = $query->param('rating_value');
55
my $rating_value     = $query->param('rating');
56
my $rating;
57
58
if ( !$rating_old_value ) {
59
    $rating = AddRating( $biblionumber, $loggedinuser, $rating_value );
60
}
61
else {
62
    $rating = ModRating( $biblionumber, $loggedinuser, $rating_value );
63
}
64
print $query->redirect(
65
    "/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber");
(-)a/opac/opac-search.pl (-2 / +22 lines)
Lines 1-7 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
# Copyright 2008 Garry Collum and the Koha Koha Development team
3
# Copyright 2008 Garry Collum and the Koha Development team
4
# Copyright 2010 BibLibre
4
# Copyright 2010 BibLibre
5
# Copyright 2011 KohaAloha, NZ
5
#
6
#
6
# This file is part of Koha.
7
# This file is part of Koha.
7
#
8
#
Lines 37-48 use C4::Koha; Link Here
37
use C4::Tags qw(get_tags);
38
use C4::Tags qw(get_tags);
38
use C4::Branch; # GetBranches
39
use C4::Branch; # GetBranches
39
use C4::SocialData;
40
use C4::SocialData;
41
use C4::Ratings;
42
40
use POSIX qw(ceil floor strftime);
43
use POSIX qw(ceil floor strftime);
41
use URI::Escape;
44
use URI::Escape;
42
use Storable qw(thaw freeze);
45
use Storable qw(thaw freeze);
43
use Business::ISBN;
46
use Business::ISBN;
44
47
45
46
my $DisplayMultiPlaceHold = C4::Context->preference("DisplayMultiPlaceHold");
48
my $DisplayMultiPlaceHold = C4::Context->preference("DisplayMultiPlaceHold");
47
# create a new CGI object
49
# create a new CGI object
48
# FIXME: no_undef_params needs to be tested
50
# FIXME: no_undef_params needs to be tested
Lines 113-118 elsif (C4::Context->preference("marcflavour") eq "MARC21" ) { Link Here
113
$template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
115
$template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
114
$template->param( 'OPACNoResultsFound' => C4::Context->preference('OPACNoResultsFound') );
116
$template->param( 'OPACNoResultsFound' => C4::Context->preference('OPACNoResultsFound') );
115
117
118
$template->param(
119
    OpacStarRatings => C4::Context->preference("OpacStarRatings") );
120
116
if (C4::Context->preference('BakerTaylorEnabled')) {
121
if (C4::Context->preference('BakerTaylorEnabled')) {
117
    $template->param(
122
    $template->param(
118
        BakerTaylorEnabled  => 1,
123
        BakerTaylorEnabled  => 1,
Lines 121-126 if (C4::Context->preference('BakerTaylorEnabled')) { Link Here
121
        BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
126
        BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
122
    );
127
    );
123
}
128
}
129
124
if (C4::Context->preference('TagsEnabled')) {
130
if (C4::Context->preference('TagsEnabled')) {
125
    $template->param(TagsEnabled => 1);
131
    $template->param(TagsEnabled => 1);
126
    foreach (qw(TagsShowOnList TagsInputOnList)) {
132
    foreach (qw(TagsShowOnList TagsInputOnList)) {
Lines 520-525 for (my $i=0;$i<@servers;$i++) { Link Here
520
            }
526
            }
521
        }
527
        }
522
528
529
523
        my $tag_quantity;
530
        my $tag_quantity;
524
        if (C4::Context->preference('TagsEnabled') and
531
        if (C4::Context->preference('TagsEnabled') and
525
            $tag_quantity = C4::Context->preference('TagsShowOnList')) {
532
            $tag_quantity = C4::Context->preference('TagsShowOnList')) {
Lines 530-535 for (my $i=0;$i<@servers;$i++) { Link Here
530
                                        limit=>$tag_quantity });
537
                                        limit=>$tag_quantity });
531
            }
538
            }
532
        }
539
        }
540
533
        if (C4::Context->preference('COinSinOPACResults')) {
541
        if (C4::Context->preference('COinSinOPACResults')) {
534
            foreach (@newresults) {
542
            foreach (@newresults) {
535
                my $record = GetMarcBiblio($_->{'biblionumber'});
543
                my $record = GetMarcBiblio($_->{'biblionumber'});
Lines 551-556 for (my $i=0;$i<@servers;$i++) { Link Here
551
            }
559
            }
552
        }
560
        }
553
561
562
563
        if ( C4::Context->preference('OpacStarRatings') eq 'all' ) {
564
            foreach my $res (@newresults) {
565
                my $rating = GetRating( $res->{'biblionumber'}, $borrowernumber );
566
                $res->{'rating_value'}  = $rating->{'rating_value'};
567
                $res->{'rating_total'}  = $rating->{'rating_total'};
568
                $res->{'rating_avg'}    = $rating->{'rating_avg'};
569
                $res->{'rating_avg_int'} = $rating->{'rating_avg_int'};
570
            }
571
        }
572
554
        if ($results_hashref->{$server}->{"hits"}){
573
        if ($results_hashref->{$server}->{"hits"}){
555
            $total = $total + $results_hashref->{$server}->{"hits"};
574
            $total = $total + $results_hashref->{$server}->{"hits"};
556
        }
575
        }
Lines 773-776 if (C4::Context->preference('GoogleIndicTransliteration')) { Link Here
773
        $template->param('GoogleIndicTransliteration' => 1);
792
        $template->param('GoogleIndicTransliteration' => 1);
774
}
793
}
775
794
795
	$template->param( borrowernumber    => $borrowernumber);
776
output_with_http_headers $cgi, $cookie, $template->output, $content_type;
796
output_with_http_headers $cgi, $cookie, $template->output, $content_type;
(-)a/t/db_dependent/Ratings.t (-1 / +63 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use strict;
4
use warnings;
5
use Test::More tests => 12;
6
use C4::Members;
7
8
BEGIN {
9
10
    use FindBin;
11
    use C4::Ratings;
12
    use_ok('C4::Ratings');
13
14
    DelRating( 1, 901 );
15
    DelRating( 1, 902 );
16
17
    my $rating5 = GetRating( 1, undef );
18
    ok( defined $rating5, 'get a rating, without borrowernumber' );
19
20
    my $borrower102 = GetMember( borrowernumber => 102);
21
    my $borrower103 = GetMember( borrowernumber => 103);
22
    SKIP: {
23
        skip 'Missing test borrowers, skipping specific tests', 10 unless ( defined $borrower102 && defined $borrower103 );
24
        my $rating1 = AddRating( 1, 102, 3 );
25
        my $rating2 = AddRating( 1, 103, 4 );
26
        my $rating3 = ModRating( 1, 102, 5 );
27
        my $rating4 = GetRating( 1, 103 );
28
        my $rating6 = DelRating( 1, 102 );
29
        my $rating7 = DelRating( 1, 103 );
30
31
        ok( defined $rating1, 'add a rating' );
32
        ok( defined $rating2, 'add another rating' );
33
        ok( defined $rating3, 'update a rating' );
34
        ok( defined $rating4, 'get a rating, with borrowernumber' );
35
        ok( defined $rating6,                'delete a rating' );
36
        ok( defined $rating7,                'delete another rating' );
37
38
        ok( $rating3->{'rating_avg'} == '4', "get a bib's average(float) rating" );
39
        ok( $rating3->{'rating_avg_int'} == 4.5, "get a bib's average(int) rating" );
40
        ok( $rating3->{'rating_total'} == 2, "get a bib's total number of ratings" );
41
        ok( $rating3->{'rating_value'} == 5, "verify user's bib rating" );
42
    }
43
44
}
45
46
=c
47
48
mason@xen1:~/g/head$ perl t/db_dependent/Ratings.t
49
1..12
50
ok 1 - use C4::Ratings;
51
ok 2 - add a rating
52
ok 3 - add another rating
53
ok 4 - update a rating
54
ok 5 - get a rating, with borrowernumber
55
ok 6 - get a rating, without borrowernumber
56
ok 7 - get a bib's average(float) rating
57
ok 8 - get a bib's average(int) rating
58
ok 9 - get a bib's total number of ratings
59
ok 10 - verify user's bib rating
60
ok 11 - delete a rating
61
ok 12 - delete another rating
62
63
=cut

Return to bug 5668