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

(-)a/C4/Auth.pm (+1 lines)
Lines 351-356 sub get_template_and_user { Link Here
351
            LoginFirstname               => (C4::Context->userenv?C4::Context->userenv->{"firstname"}:"Bel"),
351
            LoginFirstname               => (C4::Context->userenv?C4::Context->userenv->{"firstname"}:"Bel"),
352
            LoginSurname                 => C4::Context->userenv?C4::Context->userenv->{"surname"}:"Inconnu",
352
            LoginSurname                 => C4::Context->userenv?C4::Context->userenv->{"surname"}:"Inconnu",
353
            TagsEnabled                  => C4::Context->preference("TagsEnabled"),
353
            TagsEnabled                  => C4::Context->preference("TagsEnabled"),
354
            OpacStarRatings              => C4::Context->preference("OpacStarRatings"),
354
            hide_marc                    => C4::Context->preference("hide_marc"),
355
            hide_marc                    => C4::Context->preference("hide_marc"),
355
            item_level_itypes            => C4::Context->preference('item-level_itypes'),
356
            item_level_itypes            => C4::Context->preference('item-level_itypes'),
356
            patronimages                 => C4::Context->preference("patronimages"),
357
            patronimages                 => C4::Context->preference("patronimages"),
(-)a/C4/Output.pm (-9 / +25 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-311 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
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
309
sub is_ajax () {
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;
(-)a/C4/Ratings.pm (+194 lines)
Line 0 Link Here
1
package C4::Ratings;
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
use strict;
21
use warnings;
22
use Carp;
23
use Exporter;
24
use POSIX;
25
use C4::Debug;
26
use C4::Context;
27
28
#use Smart::Comments '####';
29
30
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
31
32
BEGIN {
33
    $VERSION = 3.00;
34
    @ISA     = qw(Exporter);
35
36
    @EXPORT = qw(
37
      &GetRating
38
      &AddRating
39
      &ModRating
40
      &DelRating
41
    );
42
}
43
44
sub GetRating {
45
    my ( $biblionumber, $borrowernumber ) = @_;
46
    my $query = qq| SELECT COUNT(*) AS total, SUM(rating_value) AS sum
47
FROM ratings WHERE biblionumber = ? |;
48
49
    my $sth = C4::Context->dbh->prepare($query);
50
    $sth->execute($biblionumber);
51
    my $res = $sth->fetchrow_hashref();
52
53
    my ( $avg, $avg_int ) = 0;
54
55
    if ( $res->{sum} and $res->{total} ) {
56
        eval { $avg = $res->{sum} / $res->{total} };
57
    }
58
59
    $avg_int = sprintf( "%.1f", $avg );
60
    $avg     = sprintf( "%.0f", $avg );
61
62
    my %rating_hash;
63
    $rating_hash{rating_total}   = $res->{total};
64
    $rating_hash{rating_avg}     = $avg;
65
    $rating_hash{rating_avg_int} = $avg_int;
66
67
    if ($borrowernumber) {
68
        my $q2 = qq|
69
SELECT rating_value FROM ratings WHERE biblionumber = ? AND borrowernumber = ?|;
70
        my $sth1 = C4::Context->dbh->prepare($q2);
71
        $sth1->execute( $biblionumber, $borrowernumber );
72
        my $res1 = $sth1->fetchrow_hashref();
73
        $rating_hash{'rating_value'} = $res1->{"rating_value"};
74
    }
75
    else {
76
        $rating_hash{rating_borrowernumber} = undef;
77
        $rating_hash{rating_value}      = undef;
78
    }
79
80
#### %rating_hash
81
    return \%rating_hash;
82
}
83
84
sub AddRating {
85
    my ( $biblionumber, $borrowernumber, $rating_value ) = @_;
86
    my $query = qq| INSERT INTO ratings (borrowernumber,biblionumber,rating_value)
87
        VALUES (?,?,?)|;
88
    my $sth = C4::Context->dbh->prepare($query);
89
    $sth->execute( $borrowernumber, $biblionumber, $rating_value );
90
    my $rating = GetRating( $biblionumber, $borrowernumber );
91
    return $rating;
92
}
93
94
sub ModRating {
95
    my ( $biblionumber, $borrowernumber, $rating_value ) = @_;
96
    my $query =
97
qq|UPDATE ratings SET rating_value = ? WHERE borrowernumber = ? AND biblionumber = ?|;
98
    my $sth = C4::Context->dbh->prepare($query);
99
    $sth->execute( $rating_value, $borrowernumber, $biblionumber );
100
    my $rating = GetRating( $biblionumber, $borrowernumber );
101
    return $rating;
102
}
103
104
sub DelRating {
105
    my ( $biblionumber, $borrowernumber ) = @_;
106
    my $dbh = C4::Context->dbh;
107
    my $query =
108
      "delete from ratings where borrowernumber = ? and biblionumber = ?";
109
    my $sth    = C4::Context->dbh->prepare($query);
110
    my $rv     = $sth->execute( $borrowernumber, $biblionumber );
111
    my $rating = GetRating( $biblionumber, undef );
112
    return $rating;
113
}
114
115
1;
116
__END__
117
118
=head1 NAME
119
120
C4::Ratings - a module to manage user ratings of Koha biblios
121
122
=head1 DESCRIPTION
123
124
Ratings.pm provides simple functionality for a user to 'rate' a biblio, and to retrieve a biblio's rating info
125
126
the 4 subroutines allow a user to add, delete modify and retrieve rating info for a biblio.
127
128
The rating can be from 1 to 5 stars, (5 stars being the highest rating)
129
130
=head1 SYNOPSIS
131
132
# get a rating for a bib
133
 my $rating_hashref = GetRating( $biblionumber, undef );
134
 my $rating_hashref = GetRating( $biblionumber, $borrowernumber );
135
136
# add a rating for a bib
137
 my $rating_hashref = AddRating( $biblionumber, $borrowernumber, $rating_value );
138
139
# mod a rating for a bib
140
 my $rating_hashref = ModRating( $biblionumber, $borrowernumber, $rating_value );
141
142
# delete a rating for a bib
143
 my $rating_hashref = DelRating( $biblionumber, $borrowernumber );
144
145
All subroutines in Ratings.pm return a hashref which contain 4 keys
146
147
for example, after executing this statment below...
148
149
    my $rating_hashref = GetRating ( $biblionumber, $borrowernumber ) ;
150
151
$rating_hashref now contains a hashref that looks like this...
152
153
    $rating  = {
154
             rating_avg       => '2',
155
             rating_avg_int   => '2.3',
156
             rating_total     => '432',
157
             rating_value => '5'
158
    }
159
160
they 4 keys returned in the hashref are...
161
162
    rating_avg:            average rating of a biblio
163
    rating_avg_int:        average rating of a biblio, rounded to 1dp
164
    rating_total:          total number of ratings of a biblio
165
    rating_value:          logged-in user's rating of a biblio
166
167
=head1 BUGS
168
169
Please use bugs.koha-community.org for tracking bugs.
170
171
=head1 SOURCE AVAILABILITY
172
173
The source is available from the koha-community.org git server
174
L<http://git.koha-community.org>
175
176
=head1 AUTHOR
177
178
Original code: Mason James <mtj@kohaaloha.com>
179
180
=head1 COPYRIGHT
181
182
Copyright (c) 2011 Mason James <mtj@kohaaloha.com>
183
184
=head1 LICENSE
185
186
C4::Ratings is free software. You can redistribute it and/or
187
modify it under the same terms as Koha itself.
188
189
=head1 CREDITS
190
191
 Mason James <mtj@kohaaloha.com>
192
 Koha Dev Team <http://koha-community.org>
193
194
=cut
(-)a/installer/data/mysql/kohastructure.sql (+14 lines)
Lines 2668-2673 CREATE TABLE `fieldmapping` ( -- koha to keyword mapping Link Here
2668
  PRIMARY KEY  (`id`)
2668
  PRIMARY KEY  (`id`)
2669
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2669
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2670
2670
2671
--
2672
-- 'Ratings' table. This tracks the star ratings set by borrowers.
2673
--
2674
2675
DROP TABLE IF EXISTS `ratings`;
2676
CREATE TABLE `ratings` (
2677
    `borrowernumber` int(11) NOT NULL, -- the borrower this rating is for
2678
    `biblionumber` int(11) NOT NULL, -- the biblio it's for
2679
    `rating_value` tinyint(1) NOT NULL, -- the rating value, from 1-5
2680
    `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
2681
    PRIMARY KEY  (`borrowernumber`,`biblionumber`),
2682
    KEY `ratings_borrowers_fk_1` (`borrowernumber`),
2683
    KEY `ratings_biblionumber_fk_1` (`biblionumber`)
2684
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2671
2685
2672
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
2686
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
2673
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
2687
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
(-)a/installer/data/mysql/updatedatabase.pl (-1 / +17 lines)
Lines 4598-4604 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
4598
    SetVersion($DBversion);
4598
    SetVersion($DBversion);
4599
}
4599
}
4600
4600
4601
4602
$DBversion = "3.07.00.007";
4601
$DBversion = "3.07.00.007";
4603
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
4602
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
4604
    $dbh->do("ALTER TABLE items MODIFY materials text;");
4603
    $dbh->do("ALTER TABLE items MODIFY materials text;");
Lines 4619-4624 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
4619
    SetVersion ($DBversion);
4618
    SetVersion ($DBversion);
4620
}
4619
}
4621
4620
4621
$DBversion = '3.07.00.XXX';
4622
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
4623
    $dbh->do( qq |
4624
 CREATE TABLE `ratings` (
4625
  `borrowernumber` int(11) NOT NULL,
4626
  `biblionumber` int(11) NOT NULL,
4627
  `rating_value` tinyint(1) NOT NULL,
4628
  `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
4629
  PRIMARY KEY  (`borrowernumber`,`biblionumber`),
4630
  KEY `ratings_borrowers_fk_1` (`borrowernumber`),
4631
  KEY `ratings_biblionumber_fk_1` (`biblionumber`)
4632
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |);
4633
4634
    $dbh->do(qq|INSERT INTO `systempreferences` VALUES ('OpacStarRatings','0',NULL,NULL,NULL)|);
4635
    print "Upgrade to $DBversion done (Add 'ratings' table and 'OpacStarRatings' syspref)\n";
4636
    SetVersion($DBversion);
4637
}
4622
4638
4623
=head1 FUNCTIONS
4639
=head1 FUNCTIONS
4624
4640
(-)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
                  yes: "results and details"
33
                  no: "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 (+344 lines)
Line 0 Link Here
1
/*
2
 ### jQuery Star Rating Plugin v3.10 - 2009-03-23 ###
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
		// loop through each matched element
47
		this
48
		 .not('.star-rating-applied')
49
			.addClass('star-rating-applied')
50
		.each(function(){
51
52
			// Load control parameters / find context / etc
53
			var eid = (this.name || 'unnamed-rating').replace(/\[|\]+/g, "_");
54
			var context = $(this.form || document.body);
55
			var input = $(this);
56
			var raters = context.data('rating') || { count:0 };
57
			var rater = raters[eid];
58
			var control;
59
60
			// if rater is available, verify that the control still exists
61
			if(rater) control = rater.data('rating');
62
63
			if(rater && control){
64
				// add star to control if rater is available and the same control still exists
65
				control.count++;
66
67
			}
68
			else{
69
				// create new control if first star or control element was removed/replaced
70
71
				// Initialize options for this raters
72
				control = $.extend(
73
					{}/* new object */,
74
					options || {} /* current call options */,
75
					($.metadata? input.metadata(): ($.meta?input.data():null)) || {}, /* metadata options */
76
					{ count:0, stars: [], inputs: [] }
77
				);
78
79
				// increment number of rating controls
80
				control.serial = raters.count++;
81
82
				// create rating element
83
				rater = $('<span class="star-rating-control"/>');
84
				input.before(rater);
85
86
				// Mark element for initialization (once all stars are ready)
87
				rater.addClass('rating-to-be-drawn');
88
89
				// Accept readOnly setting from 'disabled' property
90
				if(input.attr('disabled')) control.readOnly = true;
91
92
				// Create 'cancel' button
93
				rater.append(
94
					control.cancel = $('<div class="rating-cancel"><a title="' + control.cancel + '">' + control.cancelValue + '</a></div>')
95
					.mouseover(function(){
96
						$(this).rating('drain');
97
						$(this).addClass('star-rating-hover');
98
						//$(this).rating('focus');
99
					})
100
					.mouseout(function(){
101
						$(this).rating('draw');
102
						$(this).removeClass('star-rating-hover');
103
						//$(this).rating('blur');
104
					})
105
					.click(function(){
106
					 $(this).rating('select');
107
					})
108
					.data('rating', control)
109
				);
110
111
			}; // first element of group
112
113
			// insert rating star
114
			var star = $('<div class="star-rating rater-'+ control.serial +'"><a title="' + (this.title || this.value) + '">' + this.value + '</a></div>');
115
			rater.append(star);
116
117
			// inherit attributes from input element
118
			if(this.id) star.attr('id', this.id);
119
			if(this.className) star.addClass(this.className);
120
121
			// Half-stars?
122
			if(control.half) control.split = 2;
123
124
			// Prepare division control
125
			if(typeof control.split=='number' && control.split>0){
126
				var stw = ($.fn.width ? star.width() : 0) || control.starWidth;
127
				var spi = (control.count % control.split), spw = Math.floor(stw/control.split);
128
				star
129
				// restrict star's width and hide overflow (already in CSS)
130
				.width(spw)
131
				// move the star left by using a negative margin
132
				// this is work-around to IE's stupid box model (position:relative doesn't work)
133
				.find('a').css({ 'margin-left':'-'+ (spi*spw) +'px' })
134
			};
135
136
			// readOnly?
137
			if(control.readOnly)//{ //save a byte!
138
				// Mark star as readOnly so user can customize display
139
				star.addClass('star-rating-readonly');
140
			//}  //save a byte!
141
			else//{ //save a byte!
142
			 // Enable hover css effects
143
				star.addClass('star-rating-live')
144
				 // Attach mouse events
145
					.mouseover(function(){
146
						$(this).rating('fill');
147
						$(this).rating('focus');
148
					})
149
					.mouseout(function(){
150
						$(this).rating('draw');
151
						$(this).rating('blur');
152
					})
153
					.click(function(){
154
						$(this).rating('select');
155
					})
156
				;
157
			//}; //save a byte!
158
159
			// set current selection
160
			if(this.checked)	control.current = star;
161
162
			// hide input element
163
			input.hide();
164
165
			// backward compatibility, form element to plugin
166
			input.change(function(){
167
    $(this).rating('select');
168
   });
169
170
			// attach reference to star to input element and vice-versa
171
			star.data('rating.input', input.data('rating.star', star));
172
173
			// store control information in form (or body when form not available)
174
			control.stars[control.stars.length] = star[0];
175
			control.inputs[control.inputs.length] = input[0];
176
			control.rater = raters[eid] = rater;
177
			control.context = context;
178
179
			input.data('rating', control);
180
			rater.data('rating', control);
181
			star.data('rating', control);
182
			context.data('rating', raters);
183
  }); // each element
184
185
		// Initialize ratings (first draw)
186
		$('.rating-to-be-drawn').rating('draw').removeClass('rating-to-be-drawn');
187
188
		return this; // don't break the chain...
189
	};
190
191
	/*--------------------------------------------------------*/
192
193
	/*
194
		### Core functionality and API ###
195
	*/
196
	$.extend($.fn.rating, {
197
198
		focus: function(){
199
			var control = this.data('rating'); if(!control) return this;
200
			if(!control.focus) return this; // quick fail if not required
201
			// find data for event
202
			var input = $(this).data('rating.input') || $( this.tagName=='INPUT' ? this : null );
203
   // focus handler, as requested by focusdigital.co.uk
204
			if(control.focus) control.focus.apply(input[0], [input.val(), $('a', input.data('rating.star'))[0]]);
205
		}, // $.fn.rating.focus
206
207
		blur: function(){
208
			var control = this.data('rating'); if(!control) return this;
209
			if(!control.blur) return this; // quick fail if not required
210
			// find data for event
211
			var input = $(this).data('rating.input') || $( this.tagName=='INPUT' ? this : null );
212
   // blur handler, as requested by focusdigital.co.uk
213
			if(control.blur) control.blur.apply(input[0], [input.val(), $('a', input.data('rating.star'))[0]]);
214
		}, // $.fn.rating.blur
215
216
		fill: function(){ // fill to the current mouse position.
217
			var control = this.data('rating'); if(!control) return this;
218
			// do not execute when control is in read-only mode
219
			if(control.readOnly) return;
220
			// Reset all stars and highlight them up to this element
221
			this.rating('drain');
222
			this.prevAll().andSelf().filter('.rater-'+ control.serial).addClass('star-rating-hover');
223
		},// $.fn.rating.fill
224
225
		drain: function() { // drain all the stars.
226
			var control = this.data('rating'); if(!control) return this;
227
			// do not execute when control is in read-only mode
228
			if(control.readOnly) return;
229
			// Reset all stars
230
			control.rater.children().filter('.rater-'+ control.serial).removeClass('star-rating-on').removeClass('star-rating-hover');
231
		},// $.fn.rating.drain
232
233
		draw: function(){ // set value and stars to reflect current selection
234
			var control = this.data('rating'); if(!control) return this;
235
			// Clear all stars
236
			this.rating('drain');
237
			// Set control value
238
			if(control.current){
239
				control.current.data('rating.input').attr('checked','checked');
240
				control.current.prevAll().andSelf().filter('.rater-'+ control.serial).addClass('star-rating-on');
241
			}
242
			else
243
			 $(control.inputs).removeAttr('checked');
244
			// Show/hide 'cancel' button
245
			control.cancel[control.readOnly || control.required?'hide':'show']();
246
			// Add/remove read-only classes to remove hand pointer
247
			this.siblings()[control.readOnly?'addClass':'removeClass']('star-rating-readonly');
248
		},// $.fn.rating.draw
249
250
		select: function(value){ // select a value
251
			var control = this.data('rating'); if(!control) return this;
252
			// do not execute when control is in read-only mode
253
			if(control.readOnly) return;
254
			// clear selection
255
			control.current = null;
256
			// programmatically (based on user input)
257
			if(typeof value!='undefined'){
258
			 // select by index (0 based)
259
				if(typeof value=='number')
260
			 return $(control.stars[value]).rating('select');
261
				// select by literal value (must be passed as a string
262
				if(typeof value=='string')
263
					//return
264
					$.each(control.stars, function(){
265
						if($(this).data('rating.input').val()==value) $(this).rating('select');
266
					});
267
			}
268
			else
269
				control.current = this[0].tagName=='INPUT' ?
270
				 this.data('rating.star') :
271
					(this.is('.rater-'+ control.serial) ? this : null);
272
273
			// Update rating control state
274
			this.data('rating', control);
275
			// Update display
276
			this.rating('draw');
277
			// find data for event
278
			var input = $( control.current ? control.current.data('rating.input') : null );
279
			// click callback, as requested here: http://plugins.jquery.com/node/1655
280
			if(control.callback) control.callback.apply(input[0], [input.val(), $('a', control.current)[0]]);// callback event
281
		},// $.fn.rating.select
282
283
		readOnly: function(toggle, disable){ // make the control read-only (still submits value)
284
			var control = this.data('rating'); if(!control) return this;
285
			// setread-only status
286
			control.readOnly = toggle || toggle==undefined ? true : false;
287
			// enable/disable control value submission
288
			if(disable) $(control.inputs).attr("disabled", "disabled");
289
			else     			$(control.inputs).removeAttr("disabled");
290
			// Update rating control state
291
			this.data('rating', control);
292
			// Update display
293
			this.rating('draw');
294
		},// $.fn.rating.readOnly
295
296
		disable: function(){ // make read-only and never submit value
297
			this.rating('readOnly', true, true);
298
		},// $.fn.rating.disable
299
300
		enable: function(){ // make read/write and submit value
301
			this.rating('readOnly', false, false);
302
		}// $.fn.rating.select
303
304
 });
305
306
	/*--------------------------------------------------------*/
307
308
	/*
309
		### Default Settings ###
310
		eg.: You can override default control like this:
311
		$.fn.rating.options.cancel = 'Clear';
312
	*/
313
	$.fn.rating.options = { //$.extend($.fn.rating, { options: {
314
			cancel: 'Cancel Rating',   // advisory title for the 'cancel' link
315
			cancelValue: '',           // value to submit when user click the 'cancel' link
316
			split: 0,                  // split the star into how many parts?
317
318
			// Width of star image in case the plugin can't work it out. This can happen if
319
			// the jQuery.dimensions plugin is not available OR the image is hidden at installation
320
			starWidth: 16//,
321
322
			//NB.: These don't need to be pre-defined (can be undefined/null) so let's save some code!
323
			//half:     false,         // just a shortcut to control.split = 2
324
			//required: false,         // disables the 'cancel' button so user can only select one of the specified values
325
			//readOnly: false,         // disable rating plugin interaction/ values cannot be changed
326
			//focus:    function(){},  // executed when stars are focused
327
			//blur:     function(){},  // executed when stars are focused
328
			//callback: function(){},  // executed when a star is clicked
329
 }; //} });
330
331
	/*--------------------------------------------------------*/
332
333
	/*
334
		### Default implementation ###
335
		The plugin will attach itself to file inputs
336
		with the class 'multi' when the page loads
337
	*/
338
	$(function(){ $('input[type=radio].star').rating(); });
339
340
341
342
/*# AVOID COLLISIONS #*/
343
})(jQuery);
344
/*# AVOID COLLISIONS #*/
(-)a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt (-2 / +76 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 71-76 Link Here
71
        });
74
        });
72
        [% END %]
75
        [% END %]
73
76
77
    // ratings code
78
    // hide 'rate' button
79
    $('input[name="rate_button"]').remove();
80
81
82
$(".auto-submit-star").rating({
83
   callback: function (value, link) {
84
     $.post("/cgi-bin/koha/opac-ratings-ajax.pl", {
85
       rating_old_value: $("#rating_value").attr("value"),
86
       borrowernumber: "[% borrowernumber %]",
87
       biblionumber: "[% biblionumber %]",
88
       rating_value: value,
89
     }, function (data) {
90
91
         $("#rating_value").val(data.rating_value);
92
         if (data.rating_value ) {
93
           $("#rating_value_text").text('your rating: ' + data.rating_value + ', ');
94
         } else  {
95
           $("#rating_value_text").text('');
96
         }
97
98
         if (data.rating_total ) {
99
           $("#rating_text").text('average rating: ' + data.rating_avg_int + ' (' + data.rating_total + ' votes)'  );
100
         } else  {
101
           $("#rating_value_text").text('');
102
         }
103
104
     }, "json");
105
   }
106
});
107
108
74
});
109
});
75
110
76
111
Lines 203-209 YAHOO.util.Event.onContentReady("furtherm", function () { Link Here
203
		YAHOO.util.Event.addListener("furthersearches", "click", furthersearchesMenu.show, null, furthersearchesMenu);
238
		YAHOO.util.Event.addListener("furthersearches", "click", furthersearchesMenu.show, null, furthersearchesMenu);
204
		YAHOO.widget.Overlay.windowResizeEvent.subscribe(positionfurthersearchesMenu);
239
		YAHOO.widget.Overlay.windowResizeEvent.subscribe(positionfurthersearchesMenu);
205
 });
240
 });
206
	
207
//]]>
241
//]]>
208
</script>
242
</script>
209
[% IF ( opacuserlogin ) %][% IF ( loggedinusername ) %][% IF ( TagsEnabled ) %]<style type="text/css">
243
[% IF ( opacuserlogin ) %][% IF ( loggedinusername ) %][% IF ( TagsEnabled ) %]<style type="text/css">
Lines 467-473 YAHOO.util.Event.onContentReady("furtherm", function () { Link Here
467
        </span>
501
        </span>
468
        [% END %][% END %][% END %]
502
        [% END %][% END %][% END %]
469
503
470
    [% IF ( BakerTaylorContentURL ) %]
504
    [% IF ( OpacStarRatings ) %]
505
        <form method="post" action="/cgi-bin/koha/opac-ratings.pl">
506
        <div class="results_summary">
507
<input class="auto-submit-star" type="radio" name="rating" value="1"[% IF rating_avg == 1 %]checked="1"[% END %][% UNLESS borrowernumber %]disabled="disabled"[% END %]/>
508
<input class="auto-submit-star" type="radio" name="rating" value="2"[% IF rating_avg == 2 %]checked="1"[% END %][% UNLESS borrowernumber %]disabled="disabled"[% END %]/>
509
<input class="auto-submit-star" type="radio" name="rating" value="3"[% IF rating_avg == 3 %]checked="1"[% END %][% UNLESS borrowernumber %]disabled="disabled"[% END %]/>
510
<input class="auto-submit-star" type="radio" name="rating" value="4"[% IF rating_avg == 4 %]checked="1"[% END %][% UNLESS borrowernumber %]disabled="disabled"[% END %]/>
511
<input class="auto-submit-star" type="radio" name="rating" value="5"[% IF rating_avg == 5 %]checked="1"[% END %][% UNLESS borrowernumber %]disabled="disabled"[% END %]/>
512
513
514
<!-- define some hidden vars for ratings -->
515
516
        <input  type="hidden" name='biblionumber'  value="[% biblionumber %]" />
517
        <input  type="hidden" name='borrowernumber'  value="[% borrowernumber %]" />
518
519
        <input  type="hidden" name='rating_value' id='rating_value' value="[% rating_value %]" />
520
521
522
        <input  type="hidden" name='rating_total' id='rating_total' value="[% rating_total %]" />
523
        <input  type="hidden" name='rating_avg_int' id='rating_avg_int' value="[% rating_avg_int %]" />
524
525
        [% UNLESS ( rating_readonly ) %]&nbsp;  <INPUT name="rate_button" type="submit" value="Rate me">[% END %]&nbsp;
526
527
	    [% IF ( rating_value ) %]
528
            <span id="rating_value_text">your rating: [% rating_value %], </span>
529
        [% ELSE %]
530
            <span id="rating_value_text"></span>
531
        [% END %]
532
533
534
	    [% IF ( rating_total ) %]
535
            <span id="rating_text">average rating: [% rating_avg_int %] ([% rating_total %] votes)</span>
536
        [% END %]
537
538
539
540
        </div>
541
        </FORM>
542
    [% END %]
543
544
    [% IF ( BakerTaylorContenturl ) %]
471
        <span class="results_summary">
545
        <span class="results_summary">
472
        <span class="label">Enhanced Content: </span> 
546
        <span class="label">Enhanced Content: </span> 
473
              [% IF ( OPACurlOpenInNewWindow ) %]<a href="[% BakerTaylorContentURL |html %]" target="_blank">Content Cafe</a>[% ELSE %]<a href="[% BakerTaylorContentURL |html %]">Content Cafe</a>[% END %]
547
              [% 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 (-2 / +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 231-236 $(document).ready(function(){ Link Here
231
    [% IF OpenLibraryCovers %]KOHA.OpenLibrary.GetCoverFromIsbn();[% END %]
233
    [% IF OpenLibraryCovers %]KOHA.OpenLibrary.GetCoverFromIsbn();[% END %]
232
    [% IF ( GoogleJackets ) %]KOHA.Google.GetCoverFromIsbn();[% END %]
234
    [% IF ( GoogleJackets ) %]KOHA.Google.GetCoverFromIsbn();[% END %]
233
});
235
});
236
234
//]]>
237
//]]>
235
</script>
238
</script>
236
</head>
239
</head>
Lines 478-483 $(document).ready(function(){ Link Here
478
481
479
				[% END %]
482
				[% END %]
480
				[% IF ( LibraryThingForLibrariesID ) %]<div class="ltfl_reviews"></div>[% END %]
483
				[% IF ( LibraryThingForLibrariesID ) %]<div class="ltfl_reviews"></div>[% END %]
484
485
				[% IF ( OpacStarRatings == '1' ) %]
486
                <div class="results_summary">
487
                <form name="moo" method="post" action="/cgi-bin/koha/opac-ratings.pl">
488
<input class="star" type="radio" name="rating-[% SEARCH_RESULT.biblionumber %]" value="1" [% IF ( SEARCH_RESULT.rating_avg == 1 ) %]checked="checked"[% END %] disabled="disabled" />
489
<input class="star" type="radio" name="rating-[% SEARCH_RESULT.biblionumber %]" value="2" [% IF ( SEARCH_RESULT.rating_avg == 2 ) %]checked="checked"[% END %] disabled="disabled" />
490
<input class="star" type="radio" name="rating-[% SEARCH_RESULT.biblionumber %]" value="3" [% IF ( SEARCH_RESULT.rating_avg == 3 ) %]checked="checked"[% END %] disabled="disabled" />
491
<input class="star" type="radio" name="rating-[% SEARCH_RESULT.biblionumber %]" value="4" [% IF ( SEARCH_RESULT.rating_avg == 4 ) %]checked="checked"[% END %] disabled="disabled" />
492
<input class="star" type="radio" name="rating-[% SEARCH_RESULT.biblionumber %]" value="5" [% IF ( SEARCH_RESULT.rating_avg == 5 ) %]checked="checked"[% END %] disabled="disabled" />
493
                <input type="hidden" name='biblionumber'  value="[% SEARCH_RESULT.biblionumber %]" />
494
                <input type="hidden" name='loggedinuser'  value="[% loggedinuser %]" />
495
496
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
503
                </form>
504
                </div>
505
				[% END %]
506
481
				[% IF ( opacuserlogin ) %][% IF ( TagsEnabled ) %]
507
				[% IF ( opacuserlogin ) %][% IF ( TagsEnabled ) %]
482
                                [% IF ( TagsShowOnList ) %]
508
                                [% IF ( TagsShowOnList ) %]
483
                                   <div class="results_summary">	
509
                                   <div class="results_summary">	
(-)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 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;
42
use C4::Serials;
40
use C4::Members;
43
use C4::Members;
41
use C4::VirtualShelves;
44
use C4::VirtualShelves;
42
use C4::XSLT;
45
use C4::XSLT;
Lines 46-51 use MARC::Record; Link Here
46
use MARC::Field;
49
use MARC::Field;
47
use List::MoreUtils qw/any none/;
50
use List::MoreUtils qw/any none/;
48
51
52
#use Smart::Comments '####';
53
49
BEGIN {
54
BEGIN {
50
	if (C4::Context->preference('BakerTaylorEnabled')) {
55
	if (C4::Context->preference('BakerTaylorEnabled')) {
51
		require C4::External::BakerTaylor;
56
		require C4::External::BakerTaylor;
Lines 73-79 if ( ! $record ) { Link Here
73
}
78
}
74
$template->param( biblionumber => $biblionumber );
79
$template->param( biblionumber => $biblionumber );
75
80
76
77
SetUTF8Flag($record);
81
SetUTF8Flag($record);
78
82
79
# XSLT processing of some stuff
83
# XSLT processing of some stuff
Lines 619-624 if ( C4::Context->preference('ShowReviewer') and C4::Context->preference('ShowRe Link Here
619
623
620
my $reviews = getreviews( $biblionumber, 1 );
624
my $reviews = getreviews( $biblionumber, 1 );
621
my $loggedincommenter;
625
my $loggedincommenter;
626
627
628
629
622
foreach ( @$reviews ) {
630
foreach ( @$reviews ) {
623
    my $borrowerData   = GetMember('borrowernumber' => $_->{borrowernumber});
631
    my $borrowerData   = GetMember('borrowernumber' => $_->{borrowernumber});
624
    # setting some borrower info into this hash
632
    # setting some borrower info into this hash
Lines 631-636 foreach ( @$reviews ) { Link Here
631
    $_->{userid}    = $borrowerData->{'userid'};
639
    $_->{userid}    = $borrowerData->{'userid'};
632
    $_->{cardnumber}    = $borrowerData->{'cardnumber'};
640
    $_->{cardnumber}    = $borrowerData->{'cardnumber'};
633
    $_->{datereviewed} = format_date($_->{datereviewed});
641
    $_->{datereviewed} = format_date($_->{datereviewed});
642
634
    if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
643
    if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
635
		$_->{your_comment} = 1;
644
		$_->{your_comment} = 1;
636
		$loggedincommenter = 1;
645
		$loggedincommenter = 1;
Lines 885-890 if (C4::Context->preference("OPACURLOpenInNewWindow")) { Link Here
885
    $template->param(covernewwindow => 'false');
894
    $template->param(covernewwindow => 'false');
886
}
895
}
887
896
897
if ( C4::Context->preference('OpacStarRatings') =~ /1|details/ ) {
898
    my $rating = GetRating( $biblionumber, $borrowernumber );
899
    $template->param(
900
        rating_value   => $rating->{'rating_value'},
901
        rating_total   => $rating->{'rating_total'},
902
        rating_avg     => $rating->{'rating_avg'},
903
        rating_avg_int => $rating->{'rating_avg_int'},
904
        borrowernumber => $borrowernumber
905
    );
906
}
907
888
#Search for title in links
908
#Search for title in links
889
my $marccontrolnumber   = GetMarcControlnumber   ($record, $marcflavour);
909
my $marccontrolnumber   = GetMarcControlnumber   ($record, $marcflavour);
890
910
(-)a/opac/opac-ratings-ajax.pl (+122 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
28
#use warnings;
29
use CGI;
30
use CGI::Cookie;  # need to check cookies before having CGI parse the POST request
31
use JSON;
32
33
use C4::Auth qw(:DEFAULT check_cookie_auth);
34
use C4::Context;
35
use C4::Debug;
36
use C4::Output 3.02 qw(:html :ajax pagination_bar);
37
use C4::Dates qw(format_date);
38
use C4::Ratings;
39
use Data::Dumper;
40
41
#use Smart::Comments '####';
42
43
my $is_ajax      = is_ajax();
44
my $query        = ($is_ajax) ? &ajax_auth_cgi( {} ) : CGI->new();
45
my $biblionumber = $query->param('biblionumber');
46
my $rating_value        = $query->param('rating_value');
47
my $rating_old_value    = $query->param('rating_old_value');
48
49
## ## $query
50
my $a = $query->Vars;
51
####  $a
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           => 0,
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
94
);
95
96
my $json_reply = JSON->new->encode( \%js_reply );
97
output_ajax_with_http_headers( $query, $json_reply );
98
exit;
99
100
# TODO: move this sub() to C4:Auth...
101
sub ajax_auth_cgi ($) {    # returns CGI object
102
    my $needed_flags = shift;
103
    my %cookies      = fetch CGI::Cookie;
104
    my $input        = CGI->new;
105
    my $sessid = $cookies{'CGISESSID'}->value || $input->param('CGISESSID');
106
    my ( $auth_status, $auth_sessid ) =
107
      check_cookie_auth( $sessid, $needed_flags );
108
    $debug
109
      and print STDERR
110
      "($auth_status, $auth_sessid) = check_cookie_auth($sessid,"
111
      . Dumper($needed_flags) . ")\n";
112
    if ( $auth_status ne "ok" ) {
113
        output_ajax_with_http_headers $input,
114
          "window.alert('Your CGI session cookie ($sessid) is not current.  "
115
          . "Please refresh the page and try again.');\n";
116
        exit 0;
117
    }
118
    $debug
119
      and print STDERR "AJAX request: " . Dumper($input),
120
      "\n(\$auth_status,\$auth_sessid) = ($auth_status,$auth_sessid)\n";
121
    return $input;
122
}
(-)a/opac/opac-ratings.pl (+67 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
#use Data::Dumper;
40
#use Smart::Comments '####';
41
42
my $query = CGI->new();
43
my $a     = $query->Vars;
44
####  $a
45
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
46
    {
47
        template_name   => "",
48
        query           => $query,
49
        type            => "opac",
50
        authnotrequired => 0,        # auth required to add tags
51
        debug           => 0,
52
    }
53
);
54
55
my $biblionumber     = $query->param('biblionumber');
56
my $rating_old_value = $query->param('rating_value');
57
my $rating_value     = $query->param('rating');
58
my $rating;
59
60
if ( !$rating_old_value ) {
61
    $rating = AddRating( $biblionumber, $loggedinuser, $rating_value );
62
}
63
else {
64
    $rating = ModRating( $biblionumber, $loggedinuser, $rating_value );
65
}
66
print $query->redirect(
67
    "/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber");
(-)a/opac/opac-search.pl (-6 / +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 36-45 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
46
#use Smart::Comments '####';
43
47
44
my $DisplayMultiPlaceHold = C4::Context->preference("DisplayMultiPlaceHold");
48
my $DisplayMultiPlaceHold = C4::Context->preference("DisplayMultiPlaceHold");
45
# create a new CGI object
49
# create a new CGI object
Lines 499-504 for (my $i=0;$i<@servers;$i++) { Link Here
499
            if ( not exists $line->{'size'} ) { $line->{'size'} = "" }
503
            if ( not exists $line->{'size'} ) { $line->{'size'} = "" }
500
        }
504
        }
501
505
506
        if (C4::Context->preference('COinSinOPACResults')) {
507
            foreach (@newresults) {
508
                my $record = GetMarcBiblio($_->{'biblionumber'});
509
                $_->{coins} = GetCOinSBiblio($record);
510
            }
511
        }
512
502
        my $tag_quantity;
513
        my $tag_quantity;
503
        if (C4::Context->preference('TagsEnabled') and
514
        if (C4::Context->preference('TagsEnabled') and
504
            $tag_quantity = C4::Context->preference('TagsShowOnList')) {
515
            $tag_quantity = C4::Context->preference('TagsShowOnList')) {
Lines 509-521 for (my $i=0;$i<@servers;$i++) { Link Here
509
                                        limit=>$tag_quantity });
520
                                        limit=>$tag_quantity });
510
            }
521
            }
511
        }
522
        }
512
        if (C4::Context->preference('COinSinOPACResults')) {
523
513
            foreach (@newresults) {
524
        if ( C4::Context->preference('OpacStarRatings') == 1 ) {
514
                my $record = GetMarcBiblio($_->{'biblionumber'});
525
            foreach my $res (@newresults) {
515
                $_->{coins} = GetCOinSBiblio($record);
526
                my $rating = GetRating( $res->{'biblionumber'}, $borrowernumber );
527
                $res->{'rating_value'}  = $rating->{'rating_value'};
528
                $res->{'rating_total'}  = $rating->{'rating_total'};
529
                $res->{'rating_avg'}    = $rating->{'rating_avg'};
530
                $res->{'rating_avgint'} = $rating->{'rating_avg_int'};
516
            }
531
            }
517
        }
532
        }
518
      
533
519
        if ($results_hashref->{$server}->{"hits"}){
534
        if ($results_hashref->{$server}->{"hits"}){
520
            $total = $total + $results_hashref->{$server}->{"hits"};
535
            $total = $total + $results_hashref->{$server}->{"hits"};
521
        }
536
        }
Lines 740-743 if (C4::Context->preference('GoogleIndicTransliteration')) { Link Here
740
        $template->param('GoogleIndicTransliteration' => 1);
755
        $template->param('GoogleIndicTransliteration' => 1);
741
}
756
}
742
757
758
	$template->param( borrowernumber    => $borrowernumber);
743
output_with_http_headers $cgi, $cookie, $template->output, $content_type;
759
output_with_http_headers $cgi, $cookie, $template->output, $content_type;
(-)a/t/db_dependent/Ratings.t (-1 / +55 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
#
3
use strict;
4
use warnings;
5
use Test::More tests => 9;
6
7
# use Smart::Comments '####';
8
9
BEGIN {
10
11
    use FindBin;
12
    use C4::Ratings;
13
    use_ok('C4::Ratings');
14
15
    DelRating( 1, 901 );
16
    DelRating( 1, 902 );
17
18
    my $rating1 = AddRating( 1, 100001, 3 );
19
    my $rating2 = AddRating( 1, 100002, 4 );
20
    my $rating3 = ModRating( 1, 100001, 5 );
21
    my $rating4 = GetRating( 1, 100002 );
22
    my $rating5 = GetRating( 1, undef );
23
    my $rating6 = DelRating( 1, 100001 );
24
    my $rating7 = DelRating( 1, 100002 );
25
26
    ok( defined $rating1, 'add a rating' );
27
    ok( defined $rating2, 'add another rating' );
28
    ok( defined $rating3, 'update a rating' );
29
    ok( defined $rating4, 'get a rating, with userid' );
30
    ok( defined $rating5, 'get a rating, without userid' );
31
32
#    ok( $rating3->{'rating_avg'} == '4', "get a bib's average(float) rating" );
33
#    ok( $rating3->{'rating_avg_int'} == 4.5, "get a bib's average(int) rating" );
34
#    ok( $rating3->{'rating_total'} == 2, "get a bib's total number of ratings" );
35
36
    ok( $rating3->{'rating_value'} == 5, "verify user's bib rating" );
37
    ok( defined $rating6,                'delete a rating' );
38
    ok( defined $rating7,                'delete another rating' );
39
40
}
41
42
=c
43
44
1..9
45
ok 1 - use C4::Ratings;
46
ok 2 - add a rating
47
ok 3 - add another rating
48
ok 4 - update a rating
49
ok 5 - get a rating, with userid
50
ok 6 - get a rating, without userid
51
ok 7 - verify user's bib rating
52
ok 8 - delete a rating
53
ok 9 - delete another rating
54
55
=cut

Return to bug 5668