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 1700-1705 sub getborrowernumber { Link Here
1700
    return 0;
1699
    return 0;
1701
}
1700
}
1702
1701
1702
1703
END { }    # module clean-up code here (global destructor)
1703
END { }    # module clean-up code here (global destructor)
1704
1;
1704
1;
1705
__END__
1705
__END__
(-)a/C4/Output.pm (-8 / +23 lines)
Lines 39-57 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
42
    @ISA    = qw(Exporter);
43
    @ISA    = qw(Exporter);
43
	@EXPORT_OK = qw(&is_ajax ajax_fail); # More stuff should go here instead
44
    @EXPORT_OK = qw(&is_ajax ajax_fail); # More stuff should go here instead
44
	%EXPORT_TAGS = ( all =>[qw(&pagination_bar
45
    %EXPORT_TAGS = ( all =>[qw(&themelanguage &gettemplate setlanguagecookie pagination_bar
45
							   &output_with_http_headers &output_html_with_http_headers)],
46
                                &output_with_http_headers &output_ajax_with_http_headers &output_html_with_http_headers)],
46
					ajax =>[qw(&output_with_http_headers is_ajax)],
47
                    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)]
48
                    html =>[qw(&output_with_http_headers &output_html_with_http_headers)]
48
				);
49
                );
50
    push @EXPORT, qw(
51
        &themelanguage &gettemplate setlanguagecookie getlanguagecookie pagination_bar
52
    );
49
    push @EXPORT, qw(
53
    push @EXPORT, qw(
50
        &output_html_with_http_headers &output_with_http_headers FormatData FormatNumber pagination_bar
54
        &output_html_with_http_headers &output_ajax_with_http_headers &output_with_http_headers FormatData FormatNumber
51
    );
55
    );
52
}
56
}
53
57
54
55
=head1 NAME
58
=head1 NAME
56
59
57
C4::Output - Functions for managing output, is slowly being deprecated
60
C4::Output - Functions for managing output, is slowly being deprecated
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 (+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 (+14 lines)
Lines 2710-2715 CREATE TABLE `biblioimages` ( Link Here
2710
 CONSTRAINT `bibliocoverimage_fk1` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
2710
 CONSTRAINT `bibliocoverimage_fk1` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
2711
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2711
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2712
2712
2713
-- 'Ratings' table. This tracks the star ratings set by borrowers.
2714
--
2715
2716
DROP TABLE IF EXISTS ratings;
2717
CREATE TABLE ratings (
2718
    borrowernumber int(11) NOT NULL, --- the borrower this rating is for
2719
    biblionumber int(11) NOT NULL, --- the biblio it's for
2720
    rating_value tinyint(1) NOT NULL, --- the rating, from 1-5
2721
    timestamp timestamp NOT NULL default CURRENT_TIMESTAMP,
2722
    PRIMARY KEY  (borrowernumber,biblionumber),
2723
    CONSTRAINT ratings_ibfk_1 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE,
2724
    CONSTRAINT ratings_ibfk_2 FOREIGN KEY (biblionumber) REFERENCES biblio (biblionumber) ON DELETE CASCADE ON UPDATE CASCADE
2725
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2726
2713
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
2727
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
2714
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
2728
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
2715
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
2729
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
(-)a/installer/data/mysql/sysprefs.sql (+1 lines)
Lines 352-354 INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES(' Link Here
352
INSERT INTO systempreferences` (variable,value,options,explanation,type) VALUES ('ExpireReservesMaxPickUpDelayCharge', '0', NULL , 'If ExpireReservesMaxPickUpDelay is enabled, and this field has a non-zero value, than a borrower whose waiting hold has expired will be charged this amount.',  'free')
352
INSERT INTO systempreferences` (variable,value,options,explanation,type) VALUES ('ExpireReservesMaxPickUpDelayCharge', '0', NULL , 'If ExpireReservesMaxPickUpDelay is enabled, and this field has a non-zero value, than a borrower whose waiting hold has expired will be charged this amount.',  'free')
353
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('RoutingListNote','To change this note edit <a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=RoutingListNote#jumped">RoutlingListNote</a> system preference.','Define a note to be shown on all routing lists','70|10','Textarea');
353
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('RoutingListNote','To change this note edit <a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=RoutingListNote#jumped">RoutlingListNote</a> system preference.','Define a note to be shown on all routing lists','70|10','Textarea');
354
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');
354
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');
355
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OpacStarRatings','0',NULL,'yes|no|details','Choice');
(-)a/installer/data/mysql/updatedatabase.pl (+23 lines)
Lines 4932-4937 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { Link Here
4932
    SetVersion($DBversion);
4932
    SetVersion($DBversion);
4933
}
4933
}
4934
4934
4935
$DBversion = "3.07.00.XXX";
4936
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
4937
    $dbh->do(
4938
        q | CREATE TABLE ratings (
4939
  borrowernumber int(11) NOT NULL,
4940
  biblionumber int(11) NOT NULL,
4941
  rating_value tinyint(1) NOT NULL,
4942
  timestamp timestamp NOT NULL default CURRENT_TIMESTAMP,
4943
  PRIMARY KEY  (borrowernumber,biblionumber),
4944
  CONSTRAINT ratings_ibfk_1 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE,
4945
  CONSTRAINT ratings_ibfk_2 FOREIGN KEY (biblionumber) REFERENCES biblio (biblionumber) ON DELETE CASCADE ON UPDATE CASCADE
4946
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
4947
    );
4948
    $dbh->do(
4949
q /INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OpacStarRatings','0',NULL,'yes|no|details','Choice') /
4950
    );
4951
    print
4952
"Upgrade to $DBversion done (Add 'ratings' table and 'OpacStarRatings' syspref)\n";
4953
    SetVersion($DBversion);
4954
}
4955
4956
4957
4935
=head1 FUNCTIONS
4958
=head1 FUNCTIONS
4936
4959
4937
=head2 DropAllForeignKeys($table)
4960
=head2 DropAllForeignKeys($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt (+6 lines)
Lines 341-346 Link Here
341
                  <a rel="license" href="http://creativecommons.org/licenses/by-sa/2.5/">Creative Commons Attribution-ShareAlike 2.5 License</a>
341
                  <a rel="license" href="http://creativecommons.org/licenses/by-sa/2.5/">Creative Commons Attribution-ShareAlike 2.5 License</a>
342
                  by the Bridge Consortium of Carleton College and St. Olaf College.</li>
342
                  by the Bridge Consortium of Carleton College and St. Olaf College.</li>
343
              </ul>
343
              </ul>
344
345
            <h2>jQuery Star Rating Plugin</h2>
346
              <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>
347
348
            <p>Copyright &copy; 2008 <a href="http://www.fyneworks.com/">Fyneworks.com</a></p>
349
344
        </div>
350
        </div>
345
351
346
        <div id="translations">
352
        <div id="translations">
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref (+8 lines)
Lines 22-27 OPAC: Link Here
22
                  no: Disable
22
                  no: Disable
23
            - "Koha OPAC as public. Private OPAC requires authentification before accessing the OPAC."
23
            - "Koha OPAC as public. Private OPAC requires authentification before accessing the OPAC."
24
        -
24
        -
25
            - "Show star-ratings on"
26
            - pref: OpacStarRatings
27
              choices:
28
                  yes: "results and details"
29
                  no: "no"
30
                  details: "only details"
31
            - "pages."
32
        -
25
            - pref: OpacMaintenance
33
            - pref: OpacMaintenance
26
              choices:
34
              choices:
27
                  yes: Show
35
                  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 (-2 / +84 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="/opac-tmpl/prog/en/lib/jquery/plugins/jquery.rating.js"></script>
5
<link rel="stylesheet" type="text/css" href="/opac-tmpl/prog/en/css/jquery.rating.css" />
6
4
<script type="text/JavaScript" language="JavaScript">
7
<script type="text/JavaScript" language="JavaScript">
5
//<![CDATA[
8
//<![CDATA[
6
    [% IF ( busc ) %]
9
    [% IF ( busc ) %]
Lines 74-79 Link Here
74
        });
77
        });
75
        [% END %]
78
        [% END %]
76
79
80
// -----------------------------------------------------
81
// star-ratings code
82
83
// hide 'rate' button if javascript enabled
84
$('input[name="rate_button"]').remove();
85
86
87
$(".auto-submit-star").rating({
88
   callback: function (value, link) {
89
     $.post("/cgi-bin/koha/opac-ratings-ajax.pl", {
90
       rating_old_value: $("#rating_value").attr("value"),
91
       borrowernumber: "[% borrowernumber %]",
92
       biblionumber: "[% biblionumber %]",
93
       rating_value: value,
94
       auth_error: value,
95
     }, function (data) {
96
97
98
        if  (data.auth_status != 'ok' ) {
99
            window.alert('Your CGI session cookie is not current. Please refresh the page and try again.');
100
        } else {
101
102
            $("#rating_value").val(data.rating_value);
103
104
            if (data.rating_value ) {
105
                $("#rating_value_text").text('your rating: ' + data.rating_value + ', ');
106
            } else  {
107
                $("#rating_value_text").text('');
108
            }
109
110
            $("#rating_text").text('average rating: ' + data.rating_avg_int + ' (' + data.rating_total + ' votes)'  );
111
112
        }
113
     }, "json");
114
   }
115
});
116
// -----------------------------------------------------
117
118
77
});
119
});
78
120
79
121
Lines 206-212 YAHOO.util.Event.onContentReady("furtherm", function () { Link Here
206
		YAHOO.util.Event.addListener("furthersearches", "click", furthersearchesMenu.show, null, furthersearchesMenu);
248
		YAHOO.util.Event.addListener("furthersearches", "click", furthersearchesMenu.show, null, furthersearchesMenu);
207
		YAHOO.widget.Overlay.windowResizeEvent.subscribe(positionfurthersearchesMenu);
249
		YAHOO.widget.Overlay.windowResizeEvent.subscribe(positionfurthersearchesMenu);
208
 });
250
 });
209
	
210
//]]>
251
//]]>
211
</script>
252
</script>
212
[% IF ( opacuserlogin ) %][% IF ( loggedinusername ) %][% IF ( TagsEnabled ) %]<style type="text/css">
253
[% IF ( opacuserlogin ) %][% IF ( loggedinusername ) %][% IF ( TagsEnabled ) %]<style type="text/css">
Lines 471-477 YAHOO.util.Event.onContentReady("furtherm", function () { Link Here
471
        </span>
512
        </span>
472
        [% END %][% END %][% END %]
513
        [% END %][% END %][% END %]
473
514
474
    [% IF ( BakerTaylorContentURL ) %]
515
    [% IF ( OpacStarRatings ) %]
516
        <form method="post" action="/cgi-bin/koha/opac-ratings.pl">
517
        <div class="results_summary">
518
519
    [% FOREACH i  IN [ 1 2 3 4 5  ] %]
520
521
        [% IF rating_avg == i && borrowernumber %]
522
            <input class="auto-submit-star" type="radio" name="rating"  value="[% i %]"  checked="checked" />
523
        [% ELSIF rating_avg == i %]
524
            <input class="auto-submit-star" type="radio" name="rating" value="[% i %]" checked="checked" disabled="disabled" />
525
        [% ELSIF borrowernumber  %]
526
            <input class="auto-submit-star" type="radio" name="rating" value="[% i %]" />
527
        [% ELSE   %]
528
            <input class="auto-submit-star" type="radio" name="rating" value="[% i %]" disabled="disabled" />
529
        [% END %]
530
531
    [% END %]
532
533
534
<!-- define some hidden vars for ratings -->
535
536
        <input  type="hidden" name='biblionumber'  value="[% biblionumber %]" />
537
        <input  type="hidden" name='borrowernumber'  value="[% borrowernumber %]" />
538
        <input  type="hidden" name='rating_value' id='rating_value' value="[% rating_value %]" />
539
        <input  type="hidden" name='rating_total' id='rating_total' value="[% rating_total %]" />
540
        <input  type="hidden" name='rating_avg_int' id='rating_avg_int' value="[% rating_avg_int %]" />
541
542
        [% UNLESS ( rating_readonly ) %]&nbsp;  <INPUT name="rate_button" type="submit" value="Rate me">[% END %]&nbsp;
543
544
	    [% IF ( rating_value ) %]
545
            <span id="rating_value_text">your rating: [% rating_value %], </span>
546
        [% ELSE %]
547
            <span id="rating_value_text"></span>
548
        [% END %]
549
550
            <span id="rating_text">average rating: [% rating_avg_int %] ([% rating_total %] votes)</span>
551
552
        </div>
553
        </FORM>
554
    [% END %]
555
556
    [% IF ( BakerTaylorContenturl ) %]
475
        <span class="results_summary">
557
        <span class="results_summary">
476
        <span class="label">Enhanced Content: </span> 
558
        <span class="label">Enhanced Content: </span> 
477
              [% IF ( OPACurlOpenInNewWindow ) %]<a href="[% BakerTaylorContentURL |html %]" target="_blank">Content Cafe</a>[% ELSE %]<a href="[% BakerTaylorContentURL |html %]">Content Cafe</a>[% END %]
559
              [% IF ( OPACurlOpenInNewWindow ) %]<a href="[% BakerTaylorContentURL |html %]" target="_blank">Content Cafe</a>[% ELSE %]<a href="[% BakerTaylorContentURL |html %]">Content Cafe</a>[% END %]
(-)a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt (-5 / +28 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 232-237 $(document).ready(function(){ Link Here
232
    [% IF OPACLocalCoverImages %]KOHA.LocalCover.GetCoverFromBibnumber(false);[% END %]
234
    [% IF OPACLocalCoverImages %]KOHA.LocalCover.GetCoverFromBibnumber(false);[% END %]
233
    [% IF ( GoogleJackets ) %]KOHA.Google.GetCoverFromIsbn();[% END %]
235
    [% IF ( GoogleJackets ) %]KOHA.Google.GetCoverFromIsbn();[% END %]
234
});
236
});
237
235
//]]>
238
//]]>
236
</script>
239
</script>
237
</head>
240
</head>
Lines 476-485 $(document).ready(function(){ Link Here
476
                    [% IF ( SEARCH_RESULT.intransitcount ) %] In transit ([% SEARCH_RESULT.intransitcount %]),[% END %]
479
                    [% IF ( SEARCH_RESULT.intransitcount ) %] In transit ([% SEARCH_RESULT.intransitcount %]),[% END %]
477
                    </span>
480
                    </span>
478
                </span>
481
                </span>
482
				[% END %]
479
483
480
                [% END %]
484
				[% IF ( LibraryThingForLibrariesID ) %]<div class="ltfl_reviews"></div>[% END %]
481
                [% IF ( LibraryThingForLibrariesID ) %]<div class="ltfl_reviews"></div>[% END %]
485
482
                [% IF ( opacuserlogin ) %][% IF ( TagsEnabled ) %]
486
				[% IF ( OpacStarRatings == '1' ) %]
487
                <div class="results_summary">
488
[% FOREACH i  IN [ 1 2 3 4 5  ] %]
489
  [% IF ( SEARCH_RESULT.rating_avg == i ) %]
490
    <input class="star" type="radio"  name="rating-[% SEARCH_RESULT.biblionumber %]" value="[% i %]" checked="checked" disabled="disabled"   />
491
  [% ELSE   %]
492
    <input class="star" type="radio"  name="rating-[% SEARCH_RESULT.biblionumber %]" value="[% i %]" disabled="disabled"   />
493
  [% END %]
494
[% END %]
495
                <input type="hidden" name='biblionumber'  value="[% SEARCH_RESULT.biblionumber %]" />
496
                <input type="hidden" name='loggedinuser'  value="[% loggedinuser %]" />
497
				  [% IF (  SEARCH_RESULT.rating_total ) > 0  %]
498
                    <span id="rating_total_[% SEARCH_RESULT.biblionumber %]">&nbsp;&nbsp;([% SEARCH_RESULT.rating_total %] votes)</span>
499
				  [% ELSE %]
500
                    </br>
501
				  [% END %]
502
                </div>
503
				[% END %]
504
505
				[% IF ( opacuserlogin ) %][% IF ( TagsEnabled ) %]
483
                                [% IF ( TagsShowOnList ) %]
506
                                [% IF ( TagsShowOnList ) %]
484
                                [% IF ( SEARCH_RESULT.TagLoop.size ) %]
507
                                [% IF ( SEARCH_RESULT.TagLoop.size ) %]
485
                                        <div class="results_summary"><span class="label">Tags:</span>
508
                                        <div class="results_summary"><span class="label">Tags:</span>
(-)a/opac/opac-detail.pl (-3 / +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
# Parts copyright 2011 KohaAloha, NZ
5
#
6
#
6
# This file is part of Koha.
7
# This file is part of Koha.
7
#
8
#
Lines 37-42 use C4::XISBN qw(get_xisbns get_biblionumber_from_isbn); Link Here
37
use C4::External::Amazon;
38
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 );
39
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;
40
use C4::Review;
41
use C4::Ratings;
40
use C4::Members;
42
use C4::Members;
41
use C4::VirtualShelves;
43
use C4::VirtualShelves;
42
use C4::XSLT;
44
use C4::XSLT;
Lines 86-92 if($query->cookie("bib_list")){ Link Here
86
    }
88
    }
87
}
89
}
88
90
89
90
SetUTF8Flag($record);
91
SetUTF8Flag($record);
91
92
92
# XSLT processing of some stuff
93
# XSLT processing of some stuff
Lines 541-547 my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour); Link Here
541
my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
542
my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
542
my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
543
my $marcseriesarray  = GetMarcSeries  ($record,$marcflavour);
543
my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
544
my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
544
my $marchostsarray  = GetMarcHosts($record,$marcflavour);
545
my $marchostsarray   = GetMarcHosts($record,$marcflavour);
545
my $subtitle         = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber));
546
my $subtitle         = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber));
546
547
547
    $template->param(
548
    $template->param(
Lines 550-556 my $subtitle = GetRecordValue('subtitle', $record, GetFrameworkCode($bib Link Here
550
                     MARCAUTHORS             => $marcauthorsarray,
551
                     MARCAUTHORS             => $marcauthorsarray,
551
                     MARCSERIES              => $marcseriesarray,
552
                     MARCSERIES              => $marcseriesarray,
552
                     MARCURLS                => $marcurlsarray,
553
                     MARCURLS                => $marcurlsarray,
553
		     MARCHOSTS               => $marchostsarray,
554
		             MARCHOSTS               => $marchostsarray,
554
                     norequests              => $norequests,
555
                     norequests              => $norequests,
555
                     RequestOnOpac           => C4::Context->preference("RequestOnOpac"),
556
                     RequestOnOpac           => C4::Context->preference("RequestOnOpac"),
556
                     itemdata_ccode          => $itemfields{ccode},
557
                     itemdata_ccode          => $itemfields{ccode},
Lines 560-565 my $subtitle = GetRecordValue('subtitle', $record, GetFrameworkCode($bib Link Here
560
                     itemdata_itemnotes          => $itemfields{itemnotes},
561
                     itemdata_itemnotes          => $itemfields{itemnotes},
561
                     authorised_value_images => $biblio_authorised_value_images,
562
                     authorised_value_images => $biblio_authorised_value_images,
562
                     subtitle                => $subtitle,
563
                     subtitle                => $subtitle,
564
                     OpacStarRatings         => C4::Context->preference("OpacStarRatings"),
563
    );
565
    );
564
566
565
if (C4::Context->preference("AlternateHoldingsField") && scalar @items == 0) {
567
if (C4::Context->preference("AlternateHoldingsField") && scalar @items == 0) {
Lines 630-635 if ( C4::Context->preference('ShowReviewer') and C4::Context->preference('ShowRe Link Here
630
632
631
my $reviews = getreviews( $biblionumber, 1 );
633
my $reviews = getreviews( $biblionumber, 1 );
632
my $loggedincommenter;
634
my $loggedincommenter;
635
636
637
638
633
foreach ( @$reviews ) {
639
foreach ( @$reviews ) {
634
    my $borrowerData   = GetMember('borrowernumber' => $_->{borrowernumber});
640
    my $borrowerData   = GetMember('borrowernumber' => $_->{borrowernumber});
635
    # setting some borrower info into this hash
641
    # setting some borrower info into this hash
Lines 642-647 foreach ( @$reviews ) { Link Here
642
    $_->{userid}    = $borrowerData->{'userid'};
648
    $_->{userid}    = $borrowerData->{'userid'};
643
    $_->{cardnumber}    = $borrowerData->{'cardnumber'};
649
    $_->{cardnumber}    = $borrowerData->{'cardnumber'};
644
    $_->{datereviewed} = format_date($_->{datereviewed});
650
    $_->{datereviewed} = format_date($_->{datereviewed});
651
645
    if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
652
    if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
646
		$_->{your_comment} = 1;
653
		$_->{your_comment} = 1;
647
		$loggedincommenter = 1;
654
		$loggedincommenter = 1;
Lines 906-911 my $OpacExportOptions=C4::Context->preference("OpacExportOptions"); Link Here
906
my @export_options = split(/\|/,$OpacExportOptions);
913
my @export_options = split(/\|/,$OpacExportOptions);
907
$template->{VARS}->{'export_options'} = \@export_options;
914
$template->{VARS}->{'export_options'} = \@export_options;
908
915
916
if ( C4::Context->preference('OpacStarRatings') =~ /1|details/ ) {
917
    my $rating = GetRating( $biblionumber, $borrowernumber );
918
    $template->param(
919
        rating_value   => $rating->{'rating_value'},
920
        rating_total   => $rating->{'rating_total'},
921
        rating_avg     => $rating->{'rating_avg'},
922
        rating_avg_int => $rating->{'rating_avg_int'},
923
        borrowernumber => $borrowernumber
924
    );
925
}
926
909
#Search for title in links
927
#Search for title in links
910
my $marccontrolnumber   = GetMarcControlnumber ($record, $marcflavour);
928
my $marccontrolnumber   = GetMarcControlnumber ($record, $marcflavour);
911
my $marcissns = GetMarcISSN ( $record, $marcflavour );
929
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.tmpl",
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
# an 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 (-7 / +25 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
# Parts copyright 2011 KohaAloha, NZ
5
#
6
#
6
# This file is part of Koha.
7
# This file is part of Koha.
7
#
8
#
Lines 36-46 use C4::Biblio; # GetBiblioData Link Here
36
use C4::Koha;
37
use C4::Koha;
37
use C4::Tags qw(get_tags);
38
use C4::Tags qw(get_tags);
38
use C4::Branch; # GetBranches
39
use C4::Branch; # GetBranches
40
use C4::Ratings;
41
39
use POSIX qw(ceil floor strftime);
42
use POSIX qw(ceil floor strftime);
40
use URI::Escape;
43
use URI::Escape;
41
use Storable qw(thaw freeze);
44
use Storable qw(thaw freeze);
42
45
43
44
my $DisplayMultiPlaceHold = C4::Context->preference("DisplayMultiPlaceHold");
46
my $DisplayMultiPlaceHold = C4::Context->preference("DisplayMultiPlaceHold");
45
# create a new CGI object
47
# create a new CGI object
46
# FIXME: no_undef_params needs to be tested
48
# FIXME: no_undef_params needs to be tested
Lines 111-116 elsif (C4::Context->preference("marcflavour") eq "MARC21" ) { Link Here
111
$template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
113
$template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
112
$template->param( 'OPACNoResultsFound' => C4::Context->preference('OPACNoResultsFound') );
114
$template->param( 'OPACNoResultsFound' => C4::Context->preference('OPACNoResultsFound') );
113
115
116
$template->param(
117
    OpacStarRatings => C4::Context->preference("OpacStarRatings") );
118
114
if (C4::Context->preference('BakerTaylorEnabled')) {
119
if (C4::Context->preference('BakerTaylorEnabled')) {
115
    $template->param(
120
    $template->param(
116
        BakerTaylorEnabled  => 1,
121
        BakerTaylorEnabled  => 1,
Lines 119-124 if (C4::Context->preference('BakerTaylorEnabled')) { Link Here
119
        BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
124
        BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
120
    );
125
    );
121
}
126
}
127
122
if (C4::Context->preference('TagsEnabled')) {
128
if (C4::Context->preference('TagsEnabled')) {
123
    $template->param(TagsEnabled => 1);
129
    $template->param(TagsEnabled => 1);
124
    foreach (qw(TagsShowOnList TagsInputOnList)) {
130
    foreach (qw(TagsShowOnList TagsInputOnList)) {
Lines 518-523 for (my $i=0;$i<@servers;$i++) { Link Here
518
            }
524
            }
519
        }
525
        }
520
526
527
        if (C4::Context->preference('COinSinOPACResults')) {
528
            foreach (@newresults) {
529
                my $record = GetMarcBiblio($_->{'biblionumber'});
530
                $_->{coins} = GetCOinSBiblio($record);
531
            }
532
        }
533
521
        my $tag_quantity;
534
        my $tag_quantity;
522
        if (C4::Context->preference('TagsEnabled') and
535
        if (C4::Context->preference('TagsEnabled') and
523
            $tag_quantity = C4::Context->preference('TagsShowOnList')) {
536
            $tag_quantity = C4::Context->preference('TagsShowOnList')) {
Lines 528-540 for (my $i=0;$i<@servers;$i++) { Link Here
528
                                        limit=>$tag_quantity });
541
                                        limit=>$tag_quantity });
529
            }
542
            }
530
        }
543
        }
531
        if (C4::Context->preference('COinSinOPACResults')) {
544
532
            foreach (@newresults) {
545
        if ( C4::Context->preference('OpacStarRatings') == 1 ) {
533
                my $record = GetMarcBiblio($_->{'biblionumber'});
546
            foreach my $res (@newresults) {
534
                $_->{coins} = GetCOinSBiblio($record);
547
                my $rating = GetRating( $res->{'biblionumber'}, $borrowernumber );
548
                $res->{'rating_value'}  = $rating->{'rating_value'};
549
                $res->{'rating_total'}  = $rating->{'rating_total'};
550
                $res->{'rating_avg'}    = $rating->{'rating_avg'};
551
                $res->{'rating_avg_int'} = $rating->{'rating_avg_int'};
535
            }
552
            }
536
        }
553
        }
537
      
554
538
        if ($results_hashref->{$server}->{"hits"}){
555
        if ($results_hashref->{$server}->{"hits"}){
539
            $total = $total + $results_hashref->{$server}->{"hits"};
556
            $total = $total + $results_hashref->{$server}->{"hits"};
540
        }
557
        }
Lines 767-770 if (C4::Context->preference('GoogleIndicTransliteration')) { Link Here
767
        $template->param('GoogleIndicTransliteration' => 1);
784
        $template->param('GoogleIndicTransliteration' => 1);
768
}
785
}
769
786
787
	$template->param( borrowernumber    => $borrowernumber);
770
output_with_http_headers $cgi, $cookie, $template->output, $content_type;
788
output_with_http_headers $cgi, $cookie, $template->output, $content_type;
(-)a/t/db_dependent/Ratings.t (-1 / +60 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use strict;
4
use warnings;
5
use Test::More tests => 12;
6
7
BEGIN {
8
9
    use FindBin;
10
    use C4::Ratings;
11
    use_ok('C4::Ratings');
12
13
    DelRating( 1, 901 );
14
    DelRating( 1, 902 );
15
16
    my $rating1 = AddRating( 1, 100001, 3 );
17
    my $rating2 = AddRating( 1, 100002, 4 );
18
    my $rating3 = ModRating( 1, 100001, 5 );
19
    my $rating4 = GetRating( 1, 100002 );
20
    my $rating5 = GetRating( 1, undef );
21
    my $rating6 = DelRating( 1, 100001 );
22
    my $rating7 = DelRating( 1, 100002 );
23
24
    ok( defined $rating1, 'add a rating' );
25
    ok( defined $rating2, 'add another rating' );
26
    ok( defined $rating3, 'update a rating' );
27
    ok( defined $rating4, 'get a rating, with userid' );
28
    ok( defined $rating5, 'get a rating, without userid' );
29
30
    # these next 3 test only pass on a DB with an empty 'ratings' table
31
    ok( $rating3->{'rating_avg'} == '4', "get a bib's average(float) rating" );
32
    ok( $rating3->{'rating_avg_int'} == 4.5,
33
        "get a bib's average(int) rating" );
34
    ok( $rating3->{'rating_total'} == 2,
35
        "get a bib's total number of ratings" );
36
37
    ok( $rating3->{'rating_value'} == 5, "verify user's bib rating" );
38
    ok( defined $rating6,                'delete a rating' );
39
    ok( defined $rating7,                'delete another rating' );
40
41
}
42
43
=c
44
45
mason@xen1:~/koha$ perl  t/db_dependent/Ratings.t
46
1..12
47
ok 1 - use C4::Ratings;
48
ok 2 - add a rating
49
ok 3 - add another rating
50
ok 4 - update a rating
51
ok 5 - get a rating, with userid
52
ok 6 - get a rating, without userid
53
ok 7 - get a bib's average(float) rating
54
ok 8 - get a bib's average(int) rating
55
ok 9 - get a bib's total number of ratings
56
ok 10 - verify user's bib rating
57
ok 11 - delete a rating
58
ok 12 - delete another rating
59
60
=cut

Return to bug 5668