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

(-)a/C4/Auth.pm (+1 lines)
Lines 344-349 sub get_template_and_user { Link Here
344
            LoginFirstname               => (C4::Context->userenv?C4::Context->userenv->{"firstname"}:"Bel"),
344
            LoginFirstname               => (C4::Context->userenv?C4::Context->userenv->{"firstname"}:"Bel"),
345
            LoginSurname                 => C4::Context->userenv?C4::Context->userenv->{"surname"}:"Inconnu",
345
            LoginSurname                 => C4::Context->userenv?C4::Context->userenv->{"surname"}:"Inconnu",
346
            TagsEnabled                  => C4::Context->preference("TagsEnabled"),
346
            TagsEnabled                  => C4::Context->preference("TagsEnabled"),
347
            OpacStarRatings              => C4::Context->preference("OpacStarRatings"),
347
            hide_marc                    => C4::Context->preference("hide_marc"),
348
            hide_marc                    => C4::Context->preference("hide_marc"),
348
            item_level_itypes            => C4::Context->preference('item-level_itypes'),
349
            item_level_itypes            => C4::Context->preference('item-level_itypes'),
349
            patronimages                 => C4::Context->preference("patronimages"),
350
            patronimages                 => C4::Context->preference("patronimages"),
(-)a/C4/Output.pm (-9 / +25 lines)
Lines 40-57 BEGIN { Link Here
40
    # set the version for version checking
40
    # set the version for version checking
41
    $VERSION = 3.03;
41
    $VERSION = 3.03;
42
    require Exporter;
42
    require Exporter;
43
    @ISA    = qw(Exporter);
43
44
	@EXPORT_OK = qw(&is_ajax ajax_fail); # More stuff should go here instead
44
 @ISA    = qw(Exporter);
45
	%EXPORT_TAGS = ( all =>[qw(&pagination_bar
45
    @EXPORT_OK = qw(&is_ajax ajax_fail); # More stuff should go here instead
46
							   &output_with_http_headers &output_html_with_http_headers)],
46
    %EXPORT_TAGS = ( all =>[qw(&themelanguage &gettemplate setlanguagecookie pagination_bar
47
					ajax =>[qw(&output_with_http_headers is_ajax)],
47
                                &output_with_http_headers &output_ajax_with_http_headers &output_html_with_http_headers)],
48
					html =>[qw(&output_with_http_headers &output_html_with_http_headers)]
48
                    ajax =>[qw(&output_with_http_headers &output_ajax_with_http_headers is_ajax)],
49
				);
49
                    html =>[qw(&output_with_http_headers &output_html_with_http_headers)]
50
                );
50
    push @EXPORT, qw(
51
    push @EXPORT, qw(
51
        &output_html_with_http_headers &output_with_http_headers FormatData FormatNumber pagination_bar
52
        &themelanguage &gettemplate setlanguagecookie getlanguagecookie pagination_bar
53
    );
54
    push @EXPORT, qw(
55
        &output_html_with_http_headers &output_ajax_with_http_headers &output_with_http_headers FormatData FormatNumber
52
    );
56
    );
53
}
54
57
58
}
55
59
56
=head1 NAME
60
=head1 NAME
57
61
Lines 310-315 sub output_html_with_http_headers ($$$;$) { Link Here
310
    output_with_http_headers( $query, $cookie, $data, 'html', $status );
314
    output_with_http_headers( $query, $cookie, $data, 'html', $status );
311
}
315
}
312
316
317
318
sub output_ajax_with_http_headers ($$) {
319
    my ( $query, $js ) = @_;
320
    print $query->header(
321
        -type            => 'text/javascript',
322
        -charset         => 'UTF-8',
323
        -Pragma          => 'no-cache',
324
        -'Cache-Control' => 'no-cache',
325
        -expires         => '-1d',
326
    ), $js;
327
}
328
313
sub is_ajax () {
329
sub is_ajax () {
314
    my $x_req = $ENV{HTTP_X_REQUESTED_WITH};
330
    my $x_req = $ENV{HTTP_X_REQUESTED_WITH};
315
    return ( $x_req and $x_req =~ /XMLHttpRequest/i ) ? 1 : 0;
331
    return ( $x_req and $x_req =~ /XMLHttpRequest/i ) ? 1 : 0;
(-)a/C4/Ratings.pm (+163 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
      &get_rating
38
      &add_rating
39
      &mod_rating
40
      &del_rating
41
    );
42
}
43
44
sub get_rating {
45
    my ( $biblionumber, $borrowernumber ) = @_;
46
    my $query = qq| SELECT COUNT(*) AS total, SUM(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{total}   = $res->{total};
64
    $rating_hash{avg}     = $avg;
65
    $rating_hash{avg_int} = $avg_int;
66
67
    if ($borrowernumber) {
68
        my $q2 = qq| SELECT value FROM ratings 
69
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{'my_rating'} = $res1->{"value"};
74
    }
75
    return \%rating_hash;
76
}
77
78
sub add_rating {
79
    my ( $biblionumber, $borrowernumber, $value ) = @_;
80
    my $query = qq| INSERT INTO ratings (borrowernumber,biblionumber,value)
81
        VALUES (?,?,?)|;
82
    my $sth = C4::Context->dbh->prepare($query);
83
    $sth->execute( $borrowernumber, $biblionumber, $value );
84
    my $rating = get_rating( $biblionumber, $borrowernumber );
85
    return $rating;
86
}
87
88
sub mod_rating {
89
####  mod_rating
90
    my ( $biblionumber, $borrowernumber, $value ) = @_;
91
    my $query =
92
qq|UPDATE ratings SET value = ? WHERE borrowernumber = ? AND biblionumber = ?|;
93
    my $sth = C4::Context->dbh->prepare($query);
94
    $sth->execute( $value, $borrowernumber, $biblionumber );
95
    my $rating = get_rating( $biblionumber, $borrowernumber );
96
    return $rating;
97
}
98
99
# del_rating is currently only used for passing the Ratings.t test
100
sub del_rating {
101
    my ( $biblionumber, $borrowernumber ) = @_;
102
    my $dbh = C4::Context->dbh;
103
    my $query =
104
      "delete from ratings where borrowernumber = ? and biblionumber = ?";
105
    my $sth    = C4::Context->dbh->prepare($query);
106
    my $rv     = $sth->execute( $borrowernumber, $biblionumber );
107
    my $rating = get_rating( $biblionumber, undef );
108
    return $rating;
109
}
110
111
1;
112
__END__
113
114
=head1 NAME
115
116
C4::Ratings - creates, updates and fetches Koha ratings
117
118
=head1 SYNOPSIS
119
120
# get a rating for a bib
121
 my $rating = get_rating( $biblionumber, undef );
122
 my $rating = get_rating( $biblionumber, $borrowernumber );
123
124
# add a rating for a bib
125
 my $rating = add_rating( $biblionumber, $borrowernumber, $my_rating );
126
127
# mod a rating for a bib
128
 my $rating = mod_rating( $biblionumber, $borrowernumber, $my_rating );
129
130
# delete a rating for a bib
131
 my $rv = del_rating( $biblionumber, $borrowernumber );
132
133
=head1 DESCRIPTION
134
135
This module provides simple functionality for a user to 'rate' a biblio, and to return a biblio's rating infor
136
137
=head1 BUGS
138
139
Please use bugs.koha-community.org for tracking bugs.
140
141
=head1 SOURCE AVAILABILITY
142
143
The source is available from the koha-community.org git server
144
L<http://git.koha-community.org>
145
146
=head1 AUTHOR
147
148
Original code: Mason James <mtj@kohaaloha.com>
149
150
=head1 COPYRIGHT
151
152
Copyright (c) 2011 Mason James <mtj@kohaaloha.com>
153
154
=head1 LICENSE
155
156
C4::Ratings is free software. You can redistribute it and/or
157
modify it under the same terms as Koha itself.
158
159
=head1 CREDITS
160
161
 Mason James <mtj@kohaaloha.com>
162
163
=cut
(-)a/installer/data/mysql/kohastructure.sql (+14 lines)
Lines 2654-2659 CREATE TABLE `fieldmapping` ( -- koha to keyword mapping Link Here
2654
  PRIMARY KEY  (`id`)
2654
  PRIMARY KEY  (`id`)
2655
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2655
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2656
2656
2657
---
2658
--- 'Ratings' table. This tracks the star ratings set by borrowers.
2659
---
2660
2661
DROP TABLE IF EXISTS `ratings`;
2662
CREATE TABLE `ratings` (
2663
    `borrowernumber` int(11) NOT NULL, --- the borrower this rating is for
2664
    `biblionumber` int(11) NOT NULL, --- the biblio it's for
2665
    `value` tinyint(1) NOT NULL, --- the rating, from 1-5
2666
    `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
2667
    PRIMARY KEY  (`borrowernumber`,`biblionumber`),
2668
    KEY `ratings_borrowers_fk_1` (`borrowernumber`),
2669
    KEY `ratings_biblionumber_fk_1` (`biblionumber`)
2670
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2657
2671
2658
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
2672
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
2659
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
2673
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
(-)a/installer/data/mysql/updatedatabase.pl (+18 lines)
Lines 4447-4452 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
4447
}
4447
}
4448
4448
4449
4449
4450
$DBversion = '3.05.00.XXX';
4451
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
4452
    $dbh->do( qq |
4453
 CREATE TABLE `ratings` (
4454
  `borrowernumber` int(11) NOT NULL,
4455
  `biblionumber` int(11) NOT NULL,
4456
  `value` tinyint(1) NOT NULL,
4457
  `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
4458
  PRIMARY KEY  (`rating_id`),
4459
  KEY `ratings_borrowers_fk_1` (`borrowernumber`),
4460
  KEY `ratings_biblionumber_fk_1` (`biblionumber`)
4461
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |);
4462
4463
    $dbh->do(qq|INSERT INTO `systempreferences` VALUES ('OpacStarRatings','0',NULL,NULL,NULL)|);
4464
    print "Upgrade to $DBversion done (Add 'ratings' table and 'OpacStarRatings' syspref)\n";
4465
    SetVersion($DBversion);
4466
}
4467
4450
=head1 FUNCTIONS
4468
=head1 FUNCTIONS
4451
4469
4452
=head2 DropAllForeignKeys($table)
4470
=head2 DropAllForeignKeys($table)
(-)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 / +61 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 %][% 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 %][% 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
     $(document).ready(function() { 
9
     $(document).ready(function() { 
Lines 31-36 Link Here
31
	[% IF ( opacuserlogin ) %][% IF ( loggedinusername ) %][% IF ( TagsEnabled ) %]
34
	[% IF ( opacuserlogin ) %][% IF ( loggedinusername ) %][% IF ( TagsEnabled ) %]
32
        $(".tagbutton").click(KOHA.Tags.add_tag_button);[% END %][% END %][% END %]
35
        $(".tagbutton").click(KOHA.Tags.add_tag_button);[% END %][% END %][% END %]
33
36
37
    // ratings code
38
    // hide 'rate' button
39
    $('input[name="rate_button"]').remove();
40
41
42
$(".auto-submit-star").rating({
43
   callback: function (value, link) {
44
     $.post("/cgi-bin/koha/opac-ratings-ajax.pl", {
45
       my_rating: $("#my_rating").attr("value"),
46
       borrowernumber: "[% borrowernumber %]",
47
       biblionumber: "[% biblionumber %]",
48
       value: value,
49
     }, function (data) {
50
51
       if (data.no_op == 1) {
52
            //no-op
53
       } else { 
54
         $("#rating_avg_text").text('average ' + data.avg_int);
55
56
         if (data.my_rating == null) {  //delete
57
           $("#my_rating_text").text('your rating: none, ');
58
           $("#my_rating").val(data.my_rating);
59
60
         } else {  // an add or mod
61
           $("#my_rating_text").text('your rating: ' + data.my_rating + ', ');
62
           $("#my_rating").val(data.my_rating);
63
         }
64
65
         $("#rating_avg").text('average: ' + data.avg_int);
66
         $("#rating_total").text(' (' + data.rating_total + ' votes)');
67
       }
68
     }, "json");
69
   }
70
});
71
72
34
});
73
});
35
74
36
YAHOO.util.Event.onContentReady("furtherm", function () {
75
YAHOO.util.Event.onContentReady("furtherm", function () {
Lines 47-53 YAHOO.util.Event.onContentReady("furtherm", function () { Link Here
47
		YAHOO.util.Event.addListener("furthersearches", "click", furthersearchesMenu.show, null, furthersearchesMenu);
86
		YAHOO.util.Event.addListener("furthersearches", "click", furthersearchesMenu.show, null, furthersearchesMenu);
48
		YAHOO.widget.Overlay.windowResizeEvent.subscribe(positionfurthersearchesMenu);
87
		YAHOO.widget.Overlay.windowResizeEvent.subscribe(positionfurthersearchesMenu);
49
 });
88
 });
50
	
51
//]]>
89
//]]>
52
</script>
90
</script>
53
[% IF ( opacuserlogin ) %][% IF ( loggedinusername ) %][% IF ( TagsEnabled ) %]<style type="text/css">
91
[% IF ( opacuserlogin ) %][% IF ( loggedinusername ) %][% IF ( TagsEnabled ) %]<style type="text/css">
Lines 311-317 YAHOO.util.Event.onContentReady("furtherm", function () { Link Here
311
        </span>
349
        </span>
312
        [% END %][% END %][% END %]
350
        [% END %][% END %][% END %]
313
351
314
    [% IF ( BakerTaylorContentURL ) %]
352
    [% IF ( OpacStarRatings ) %]
353
        <form method="post" action="/cgi-bin/koha/opac-ratings.pl">
354
        <div class="results_summary">   
355
<input class="auto-submit-star" type="radio" name="rating" value="1"[% IF rating_avg == 1 %]checked="1"[% END %][% UNLESS borrowernumber %]disabled="disabled"[% END %]/>
356
<input class="auto-submit-star" type="radio" name="rating" value="2"[% IF rating_avg == 2 %]checked="1"[% END %][% UNLESS borrowernumber %]disabled="disabled"[% END %]/>
357
<input class="auto-submit-star" type="radio" name="rating" value="3"[% IF rating_avg == 3 %]checked="1"[% END %][% UNLESS borrowernumber %]disabled="disabled"[% END %]/>
358
<input class="auto-submit-star" type="radio" name="rating" value="4"[% IF rating_avg == 4 %]checked="1"[% END %][% UNLESS borrowernumber %]disabled="disabled"[% END %]/>
359
<input class="auto-submit-star" type="radio" name="rating" value="5"[% IF rating_avg == 5 %]checked="1"[% END %][% UNLESS borrowernumber %]disabled="disabled"[% END %]/>
360
        <input  type="hidden" name='biblionumber'  value="[% biblionumber %]" />
361
        <input  type="hidden" name='borrowernumber'  value="[% borrowernumber %]" />
362
        <input  type="hidden" name='my_rating' id='my_rating' value="[% my_rating %]" />
363
364
        [% UNLESS ( rating_readonly ) %]&nbsp;  <INPUT name="rate_button" type="submit" value="Rate me">[% END %]&nbsp;
365
366
        <span id="my_rating_text">your rating: [% IF my_rating %][% my_rating %][% ELSE %]none[% END %],</span>
367
        <span id="rating_avg">average: [% rating_avg_int %]</span><span id="rating_total">&nbsp;([% rating_total %] votes)</span>
368
369
        </div>
370
        </FORM>
371
    [% END %]
372
373
    [% IF ( BakerTaylorContenturl ) %]
315
        <span class="results_summary">
374
        <span class="results_summary">
316
        <span class="label">Enhanced Content: </span> 
375
        <span class="label">Enhanced Content: </span> 
317
        [% IF ( OPACurlOpenInNewWindow ) %]<a href="[% BakerTaylorContentURL |html %]" target="_blank">Content Cafe</a>[% ELSE %]<a href="[% BakerTaylorContentURL |html %]">Content Cafe</a>[% END %]
376
        [% 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 / +24 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
                <span id="rating_total_[% SEARCH_RESULT.biblionumber %]">&nbsp;&nbsp;([% SEARCH_RESULT.rating_total %] votes)</span>
497
498
499
                </form>
500
                </div>
501
				[% END %]
502
481
				[% IF ( opacuserlogin ) %][% IF ( TagsEnabled ) %]
503
				[% IF ( opacuserlogin ) %][% IF ( TagsEnabled ) %]
482
                                [% IF ( TagsShowOnList ) %]
504
                                [% IF ( TagsShowOnList ) %]
483
                                [% IF ( SEARCH_RESULT.TagLoop.size ) %]
505
                                [% IF ( SEARCH_RESULT.TagLoop.size ) %]
(-)a/opac/opac-detail.pl (+28 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 64-69 my ( $template, $borrowernumber, $cookie ) = get_template_and_user( Link Here
64
    }
69
    }
65
);
70
);
66
71
72
73
74
#### $borrowernumber
75
76
77
67
my $biblionumber = $query->param('biblionumber') || $query->param('bib');
78
my $biblionumber = $query->param('biblionumber') || $query->param('bib');
68
79
69
$template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
80
$template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
Lines 306-311 if (!$@ and C4::Context->preference('ShowReviewer') and C4::Context->preference( Link Here
306
317
307
my $reviews = getreviews( $biblionumber, 1 );
318
my $reviews = getreviews( $biblionumber, 1 );
308
my $loggedincommenter;
319
my $loggedincommenter;
320
321
322
323
309
foreach ( @$reviews ) {
324
foreach ( @$reviews ) {
310
    my $borrowerData   = GetMember('borrowernumber' => $_->{borrowernumber});
325
    my $borrowerData   = GetMember('borrowernumber' => $_->{borrowernumber});
311
    # setting some borrower info into this hash
326
    # setting some borrower info into this hash
Lines 318-323 foreach ( @$reviews ) { Link Here
318
    $_->{userid}    = $borrowerData->{'userid'};
333
    $_->{userid}    = $borrowerData->{'userid'};
319
    $_->{cardnumber}    = $borrowerData->{'cardnumber'};
334
    $_->{cardnumber}    = $borrowerData->{'cardnumber'};
320
    $_->{datereviewed} = format_date($_->{datereviewed});
335
    $_->{datereviewed} = format_date($_->{datereviewed});
336
321
    if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
337
    if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
322
		$_->{your_comment} = 1;
338
		$_->{your_comment} = 1;
323
		$loggedincommenter = 1;
339
		$loggedincommenter = 1;
Lines 564-569 if (C4::Context->preference("OPACURLOpenInNewWindow")) { Link Here
564
    $template->param(covernewwindow => 'false');
580
    $template->param(covernewwindow => 'false');
565
}
581
}
566
582
583
584
if ( C4::Context->preference('OpacStarRatings') =~ /1|details/ ) {
585
    my $rating = get_rating( $biblionumber, $borrowernumber );
586
    $template->param(
587
        my_rating      => $rating->{'my_rating'},
588
        rating_total   => $rating->{'total'},
589
        rating_avg     => $rating->{'avg'},
590
        rating_avg_int => $rating->{'avg_int'},
591
        borrowernumber => $borrowernumber
592
    );
593
}
594
567
#Search for title in links
595
#Search for title in links
568
my $marccontrolnumber   = GetMarcControlnumber   ($record, $marcflavour);
596
my $marccontrolnumber   = GetMarcControlnumber   ($record, $marcflavour);
569
597
(-)a/opac/opac-ratings-ajax.pl (+134 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
31
  CGI::Cookie;  # need to check cookies before having CGI parse the POST request
32
33
#use JSON;
34
35
use C4::Auth qw(:DEFAULT check_cookie_auth);
36
use C4::Context;
37
use C4::Debug;
38
use C4::Output 3.02 qw(:html :ajax pagination_bar);
39
use C4::Dates qw(format_date);
40
use C4::Ratings;
41
use Data::Dumper;
42
43
#use Smart::Comments '####';
44
45
my $is_ajax       = is_ajax();
46
my $query         = ($is_ajax) ? &ajax_auth_cgi( {} ) : CGI->new();
47
my $biblionumber  = $query->param('biblionumber');
48
my $my_rating     = $query->param('value');
49
my $my_old_rating = $query->param('my_rating');
50
51
my ( $template, $loggedinuser, $cookie );
52
if ($is_ajax) {
53
    $loggedinuser = C4::Context->userenv->{'number'};
54
}
55
else {
56
    ( $template, $loggedinuser, $cookie ) = get_template_and_user(
57
        {
58
            template_name   => "opac-detail.tmpl",
59
            query           => $query,
60
            type            => "opac",
61
            authnotrequired => 0,                    # auth required to add tags
62
            debug           => 1,
63
        }
64
    );
65
}
66
67
my $rating;
68
my $no_op;
69
70
undef $my_old_rating if $my_old_rating eq '';
71
undef $my_rating     if $my_rating     eq '';
72
73
if ( !$my_rating ) {
74
#### delete
75
    $rating = del_rating( $biblionumber, $loggedinuser );
76
}
77
78
elsif ( $my_rating and !$my_old_rating ) {
79
#### insert
80
    $rating = add_rating( $biblionumber, $loggedinuser, $my_rating );
81
}
82
83
elsif ( $my_rating ne $my_old_rating ) {
84
#### mod
85
    $rating = mod_rating( $biblionumber, $loggedinuser, $my_rating );
86
}
87
else {
88
#### noop
89
    $no_op = 1;
90
}
91
92
my %js_reply = (
93
    rating_total => $rating->{'total'},
94
    avg          => $rating->{'avg'},
95
    avg_int      => $rating->{'avg_int'},
96
    my_rating    => $rating->{'my_rating'},
97
    no_op        => $no_op
98
99
);
100
101
use JSON;
102
my $json_reply = JSON->new->encode( \%js_reply );
103
104
#### $rating
105
#### %js_reply
106
#### $json_reply
107
108
output_ajax_with_http_headers( $query, $json_reply );
109
exit;
110
111
# TODO: move this sub() to C4:Auth...
112
sub ajax_auth_cgi ($) {    # returns CGI object
113
    my $needed_flags = shift;
114
    my %cookies      = fetch CGI::Cookie;
115
    my $input        = CGI->new;
116
    my $sessid = $cookies{'CGISESSID'}->value || $input->param('CGISESSID');
117
    my ( $auth_status, $auth_sessid ) =
118
      check_cookie_auth( $sessid, $needed_flags );
119
    $debug
120
      and print STDERR
121
      "($auth_status, $auth_sessid) = check_cookie_auth($sessid,"
122
      . Dumper($needed_flags) . ")\n";
123
    if ( $auth_status ne "ok" ) {
124
        output_ajax_with_http_headers $input,
125
          "window.alert('Your CGI session cookie ($sessid) is not current.  "
126
          . "Please refresh the page and try again.');\n";
127
        exit 0;
128
    }
129
    $debug
130
      and print STDERR "AJAX request: " . Dumper($input),
131
      "\n(\$auth_status,\$auth_sessid) = ($auth_status,$auth_sessid)\n";
132
    return $input;
133
}
134
(-)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 script to add a rating for a bib, and return rating information.
23
24
=cut
25
26
use strict;
27
use warnings;
28
use CGI;
29
use CGI::Cookie;
30
use C4::Auth qw(:DEFAULT check_cookie_auth);
31
use C4::Context;
32
use C4::Output 3.02 qw(:html :ajax pagination_bar);
33
use C4::Dates qw(format_date);
34
use C4::Biblio;
35
use C4::Ratings;
36
#use C4::Debug;
37
#use Data::Dumper;
38
#use Smart::Comments '####';
39
40
my $query = CGI->new();
41
####  $query
42
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
43
    {   template_name   => "",
44
        query           => $query,
45
        type            => "opac",
46
        authnotrequired => 0,        # auth required to add tags
47
        debug           => 1,
48
    }
49
);
50
51
my $biblionumber  = $query->param('biblionumber');
52
my $my_rating     = $query->param('my_rating');
53
my $my_new_rating = $query->param('rating');
54
my $rating;
55
56
#### $loggedinuser
57
if ( $my_rating == '' ) {
58
####insert
59
    $rating = add_rating( $biblionumber, $loggedinuser, $my_new_rating );
60
#### do nothing.
61
} elsif ( $my_new_rating ne $my_rating ) {
62
#### update
63
    $rating = mod_rating( $biblionumber, $loggedinuser, $my_new_rating );
64
}
65
print $query->redirect("/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber");
(-)a/opac/opac-search.pl (-3 / +32 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-41 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
41
42
use Smart::Comments '####';
43
44
45
use C4::Ratings;
46
39
use POSIX qw(ceil floor strftime);
47
use POSIX qw(ceil floor strftime);
40
use URI::Escape;
48
use URI::Escape;
41
use Storable qw(thaw freeze);
49
use Storable qw(thaw freeze);
Lines 359-364 if ($params->{'limit-yr'}) { Link Here
359
# Params that can only have one value
367
# Params that can only have one value
360
my $scan = $params->{'scan'};
368
my $scan = $params->{'scan'};
361
my $count = C4::Context->preference('OPACnumSearchResults') || 20;
369
my $count = C4::Context->preference('OPACnumSearchResults') || 20;
370
my $count = 3;
371
372
373
362
my $countRSS         = C4::Context->preference('numSearchRSSResults') || 50;
374
my $countRSS         = C4::Context->preference('numSearchRSSResults') || 50;
363
my $results_per_page = $params->{'count'} || $count;
375
my $results_per_page = $params->{'count'} || $count;
364
my $offset = $params->{'offset'} || 0;
376
my $offset = $params->{'offset'} || 0;
Lines 485-495 for (my $i=0;$i<@servers;$i++) { Link Here
485
										limit=>$tag_quantity });
497
										limit=>$tag_quantity });
486
			}
498
			}
487
		}
499
		}
488
                if (C4::Context->preference('COinSinOPACResults')) {
500
        if (C4::Context->preference('COinSinOPACResults')) {
489
		    foreach (@newresults) {
501
		    foreach (@newresults) {
490
		      $_->{coins} = GetCOinSBiblio($_->{'biblionumber'});
502
		      $_->{coins} = GetCOinSBiblio($_->{'biblionumber'});
491
		    }
503
		    }
492
                }
504
        }
505
506
        if ( C4::Context->preference('OpacStarRatings') == 1 ) {
507
            foreach (@newresults) {
508
                my $rating = get_rating( $_->{'biblionumber'}, $borrowernumber );
509
                ####  $rating 
510
511
512
                $_->{'my_rating'}     = $rating->{'my_rating'};
513
                $_->{'rating_total'}  = $rating->{'total'};
514
                $_->{'rating_avg'}    = $rating->{'avg'};
515
                $_->{'rating_avgint'} = $rating->{'avg_int'};
516
517
#### $_
518
            }
519
        }
520
493
      
521
      
494
	if ($results_hashref->{$server}->{"hits"}){
522
	if ($results_hashref->{$server}->{"hits"}){
495
	    $total = $total + $results_hashref->{$server}->{"hits"};
523
	    $total = $total + $results_hashref->{$server}->{"hits"};
Lines 698-701 if (C4::Context->preference('GoogleIndicTransliteration')) { Link Here
698
        $template->param('GoogleIndicTransliteration' => 1);
726
        $template->param('GoogleIndicTransliteration' => 1);
699
}
727
}
700
728
729
	$template->param( borrowernumber    => $borrowernumber);
701
output_with_http_headers $cgi, $cookie, $template->output, $content_type;
730
output_with_http_headers $cgi, $cookie, $template->output, $content_type;
(-)a/t/db_dependent/Ratings.t (+53 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
#
3
use strict;
4
use warnings;
5
use Test::More tests => 12;
6
7
# use Smart::Comments '####';
8
9
BEGIN {
10
11
    use FindBin;
12
    use C4::Ratings;
13
    use_ok('C4::Ratings');
14
15
    my $rating1 = add_rating( 1, 1, 3 );
16
    my $rating2 = add_rating( 1, 2, 4 );
17
    my $rating3 = mod_rating( 1, 1, 5 );
18
    my $rating4 = get_rating( 1, 1 );
19
    my $rating5 = get_rating( 1, undef );
20
    my $rating6 = del_rating( 1, 1 );
21
    my $rating7 = del_rating( 1, 2 );
22
23
    ok( defined $rating1, 'add a rating' );
24
    ok( defined $rating2, 'add another rating' );
25
    ok( defined $rating3, 'update a rating' );
26
    ok( defined $rating4, 'get a rating' );
27
    ok( defined $rating5, 'get a rating, passing no userid' );
28
    ok( $rating3->{'avg'} == '4',     "get a bib's average(float) rating" );
29
    ok( $rating3->{'avg_int'} == 4.5, "get a bib's average(int) rating" );
30
    ok( $rating3->{'total'} == 2,     "get a bib's total number of ratings" );
31
    ok( $rating3->{'my_rating'} == 5, "get a users rating for a bib" );
32
    ok( defined $rating6,             'delete a rating' );
33
    ok( defined $rating7,             'delete another rating' );
34
}
35
36
=c
37
38
$ perl  ./t/db_dependent/Ratings.t 
39
1..12
40
ok 1 - use C4::Ratings;
41
ok 2 - add a rating
42
ok 3 - add another rating
43
ok 4 - update a rating
44
ok 5 - get a rating
45
ok 6 - get a rating, passing no userid
46
ok 7 - get a bib's average(float) rating
47
ok 8 - get a bib's average(int) rating
48
ok 9 - get a bib's total number of ratings
49
ok 10 - get a users rating for a bib
50
ok 11 - delete a rating
51
ok 12 - delete another rating
52
53
=cut
(-)a/t/db_dependent/lib/KohaTest.pm (+1 lines)
Lines 228-233 sub startup_15_truncate_tables : Test( startup => 1 ) { Link Here
228
                              subscriptionroutinglist
228
                              subscriptionroutinglist
229
                              suggestions
229
                              suggestions
230
                              tags
230
                              tags
231
                              ratings
231
                              virtualshelfcontents
232
                              virtualshelfcontents
232
                        );
233
                        );
233
234
(-)a/t/test-config.txt (-1 / +53 lines)
Line 0 Link Here
0
- 
1
# This configuration file lets the t/Makefile prepare a test koha-conf.xml file.
2
# It is generated by the top-level Makefile.PL.
3
# It is separate from the standard koha-conf.xml so that you can edit this by hand and test with different configurations.
4
ZEBRA_DATA_DIR = /home/mason/git.xen1/head/t/run/var/lib/zebradb
5
INTRANET_WWW_DIR = /home/mason/git.xen1/head/koha-tmpl
6
OPAC_CGI_DIR = /home/mason/git.xen1/head
7
PERL_MODULE_DIR = /home/mason/git.xen1/head
8
ZEBRA_LOCK_DIR = /home/mason/git.xen1/head/t/run/var/lock/zebradb
9
INTRANET_CGI_DIR = /home/mason/git.xen1/head
10
OPAC_TMPL_DIR = /home/mason/git.xen1/head/koha-tmpl/opac-tmpl
11
SCRIPT_NONDEV_DIR = /home/mason/koha-dev/bin
12
ZEBRA_RUN_DIR = /home/mason/git.xen1/head/t/run/var/run/zebradb
13
MAN_DIR = /home/mason/koha-dev/man
14
LOG_DIR = /home/mason/git.xen1/head/t/run/var/log
15
PAZPAR2_CONF_DIR = /home/mason/koha-dev/etc/pazpar2
16
KOHA_CONF_DIR = /home/mason/git.xen1/head/t/run/etc
17
OPAC_WWW_DIR = /home/mason/git.xen1/head/koha-tmpl
18
SCRIPT_DIR = /home/mason/git.xen1/head/t/run/bin
19
DOC_DIR = /home/mason/koha-dev/doc
20
INTRANET_TMPL_DIR = /home/mason/git.xen1/head/koha-tmpl/intranet-tmpl
21
MISC_DIR = /home/mason/koha-dev/misc
22
ZEBRA_CONF_DIR = /home/mason/git.xen1/head/t/run/etc/zebradb
23
24
TEST_DB_PASS = kohakoha
25
AUTH_INDEX_MODE = dom
26
DB_PASS = kohakoha
27
INSTALL_PAZPAR2 = no
28
PATH_TO_ZEBRA = /usr/bin
29
INSTALL_ZEBRA = yes
30
USE_MEMCACHED = no
31
DB_NAME = koha
32
ZEBRA_USER = kohauser
33
ZEBRA_SRU_BIBLIOS_PORT = 9998
34
INSTALL_SRU = yes
35
RUN_DATABASE_TESTS = yes
36
DB_USER = kohaadmin
37
TEST_DB_NAME = kohatest
38
DB_HOST = localhost
39
ZEBRA_MARC_FORMAT = marc21
40
ZEBRA_PASS = zebrastripes
41
DB_PORT = 3306
42
TEST_DB_TYPE = mysql
43
TEST_DB_HOST = localhost
44
KOHA_INSTALLED_VERSION = 3.05.00.004
45
ZEBRA_SRU_HOST = localhost
46
ZEBRA_SRU_AUTHORITIES_PORT = 9999
47
DB_TYPE = mysql
48
ZEBRA_LANGUAGE = en
49
TEST_DB_USER = kohaadmin
50
AUTH_RETRIEVAL_CFG = retrieval-info-auth-dom.xml
51
ZEBRA_AUTH_CFG = zebra-authorities-dom.cfg
52
INSTALL_BASE = /home/mason/koha-dev
53
INSTALL_MODE = dev

Return to bug 5668