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

(-)a/C4/Dates.pm (-114 / +160 lines)
Lines 1-4 Link Here
1
package C4::Dates;
1
package C4::Dates;
2
2
# This file is part of Koha.
3
# This file is part of Koha.
3
#
4
#
4
# Koha is free software; you can redistribute it and/or modify it under the
5
# Koha is free software; you can redistribute it and/or modify it under the
Lines 26-179 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); Link Here
26
use vars qw($debug $cgi_debug);
27
use vars qw($debug $cgi_debug);
27
28
28
BEGIN {
29
BEGIN {
29
	$VERSION = 0.04;
30
    $VERSION   = 0.04;
30
	@ISA = qw(Exporter);
31
    @ISA       = qw(Exporter);
31
	@EXPORT_OK = qw(format_date_in_iso format_date);
32
    @EXPORT_OK = qw(format_date_in_iso format_date);
32
}
33
}
33
34
34
use vars qw($prefformat);
35
use vars qw($prefformat);
36
35
sub _prefformat {
37
sub _prefformat {
36
    unless (defined $prefformat) {
38
    unless ( defined $prefformat ) {
37
        $prefformat = C4::Context->preference('dateformat');
39
        $prefformat = C4::Context->preference('dateformat');
38
    }
40
    }
39
    return $prefformat;
41
    return $prefformat;
40
}
42
}
41
43
42
our %format_map = ( 
44
our %format_map = (
43
	  iso  => 'yyyy-mm-dd', # plus " HH:MM:SS"
45
    iso    => 'yyyy-mm-dd',           # plus " HH:MM:SS"
44
	metric => 'dd/mm/yyyy', # plus " HH:MM:SS"
46
    metric => 'dd/mm/yyyy',           # plus " HH:MM:SS"
45
	  us   => 'mm/dd/yyyy', # plus " HH:MM:SS"
47
    us     => 'mm/dd/yyyy',           # plus " HH:MM:SS"
46
	  sql  => 'yyyymmdd    HHMMSS',
48
    sql    => 'yyyymmdd    HHMMSS',
49
    rfc822 => 'a, dd b y HH:MM:SS z ',
47
);
50
);
48
our %posix_map = (
51
our %posix_map = (
49
	  iso  => '%Y-%m-%d',	# or %F, "Full Date"
52
    iso    => '%Y-%m-%d',             # or %F, "Full Date"
50
	metric => '%d/%m/%Y',
53
    metric => '%d/%m/%Y',
51
	  us   => '%m/%d/%Y',
54
    us     => '%m/%d/%Y',
52
	  sql  => '%Y%m%d    %H%M%S',
55
    sql    => '%Y%m%d    %H%M%S',
56
    rfc822 => '%a, %d %b %Y %H:%M:%S %z',
53
);
57
);
54
58
55
our %dmy_subs = (			# strings to eval  (after using regular expression returned by regexp below)
59
our %dmy_subs = (                     # strings to eval  (after using regular expression returned by regexp below)
56
							# make arrays for POSIX::strftime()
60
                                      # make arrays for POSIX::strftime()
57
	  iso  => '[(($6||0),($5||0),($4||0),$3, $2 - 1, $1 - 1900)]',		
61
    iso    => '[(($6||0),($5||0),($4||0),$3, $2 - 1, $1 - 1900)]',
58
	metric => '[(($6||0),($5||0),($4||0),$1, $2 - 1, $3 - 1900)]',
62
    metric => '[(($6||0),($5||0),($4||0),$1, $2 - 1, $3 - 1900)]',
59
	  us   => '[(($6||0),($5||0),($4||0),$2, $1 - 1, $3 - 1900)]',
63
    us     => '[(($6||0),($5||0),($4||0),$2, $1 - 1, $3 - 1900)]',
60
	  sql  => '[(($6||0),($5||0),($4||0),$3, $2 - 1, $1 - 1900)]',
64
    sql    => '[(($6||0),($5||0),($4||0),$3, $2 - 1, $1 - 1900)]',
65
    rfc822 => '[($7, $6, $5, $2, $3, $4 - 1900, $8)]',
61
);
66
);
62
67
68
our @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
69
70
our @days = qw(Sun Mon Tue Wed Thu Fri Sat);
71
63
sub regexp ($;$) {
72
sub regexp ($;$) {
64
	my $self = shift;
73
    my $self   = shift;
65
	my $delim = qr/:?\:|\/|-/;	# "non memory" cluster: no backreference
74
    my $delim  = qr/:?\:|\/|-/;                                                                  # "non memory" cluster: no backreference
66
	my $format = (@_) ? _recognize_format(shift) : ($self->{'dateformat'} || _prefformat());
75
    my $format = (@_) ? _recognize_format(shift) : ( $self->{'dateformat'} || _prefformat() );
67
76
68
    # Extra layer of checking $self->{'dateformat'}.
77
    # Extra layer of checking $self->{'dateformat'}.
69
    # Why?  Because it is assumed you might want to check regexp against an *instantiated* Dates object as a
78
    # Why?  Because it is assumed you might want to check regexp against an *instantiated* Dates object as a
70
    # way of saying "does this string match *whatever* format that Dates object is?"
79
    # way of saying "does this string match *whatever* format that Dates object is?"
71
80
72
	($format eq 'sql') and 
81
    ( $format eq 'sql' )
73
	return qr/^(\d{4})(\d{1,2})(\d{1,2})(?:\s{4}(\d{2})(\d{2})(\d{2}))?/;
82
      and return qr/^(\d{4})(\d{1,2})(\d{1,2})(?:\s{4}(\d{2})(\d{2})(\d{2}))?/;
74
	($format eq 'iso') and 
83
    ( $format eq 'iso' )
75
	return qr/^(\d{4})$delim(\d{1,2})$delim(\d{1,2})(?:(?:\s{1}|T)(\d{2})\:?(\d{2})\:?(\d{2}))?Z?/;
84
      and return qr/^(\d{4})$delim(\d{1,2})$delim(\d{1,2})(?:(?:\s{1}|T)(\d{2})\:?(\d{2})\:?(\d{2}))?Z?/;
76
	return qr/^(\d{1,2})$delim(\d{1,2})$delim(\d{4})(?:\s{1}(\d{1,2})\:?(\d{1,2})\:?(\d{1,2}))?/;  # everything else
85
    ( $format eq 'rfc822' )
86
      and return qr/^([a-zA-Z]{3}),\s{1}(\d{1,2})\s{1}([a-zA-Z]{3})\s{1}(\d{4})\s{1}(\d{1,2})\:(\d{1,2})\:(\d{1,2})\s{1}(([\-|\+]\d{4})|([A-Z]{3}))/;
87
    return qr/^(\d{1,2})$delim(\d{1,2})$delim(\d{4})(?:\s{1}(\d{1,2})\:?(\d{1,2})\:?(\d{1,2}))?/;    # everything else
77
}
88
}
78
89
79
sub dmy_map ($$) {
90
sub dmy_map ($$) {
80
	my $self = shift;
91
    my $self    = shift;
81
	my $val  = shift 					or return undef;
92
    my $val     = shift or return undef;
82
	my $dformat = $self->{'dateformat'} or return undef;
93
    my $dformat = $self->{'dateformat'} or return undef;
83
	my $re = $self->regexp();
94
    my $re      = $self->regexp();
84
	my $xsub = $dmy_subs{$dformat};
95
    my $xsub    = $dmy_subs{$dformat};
85
	$debug and print STDERR "xsub: $xsub \n";
96
    $debug and print STDERR "xsub: $xsub \n";
86
	if ($val =~ /$re/) {
97
    if ( $val =~ /$re/ ) {
87
		my $aref = eval $xsub;
98
        my $aref = eval $xsub;
99
        if ($dformat eq 'rfc822') {
100
            $aref = _abbr_to_numeric($aref, $dformat);
101
            pop(@{$aref}); #pop off tz offset because we are not setup to handle tz conversions just yet
102
        }
88
        _check_date_and_time($aref);
103
        _check_date_and_time($aref);
89
		return  @{$aref}; 
104
        push @{$aref}, (-1,-1,1); # for some reason unknown to me, setting isdst to -1 or undef causes strftime to fail to return the tz offset which is required in RFC822 format -chris_n
90
	}
105
        return @{$aref};
91
	# $debug and 
106
    }
92
	carp "Illegal Date '$val' does not match '$dformat' format: " . $self->visual();
107
93
	return 0;
108
    # $debug and
109
    carp "Illegal Date '$val' does not match '$dformat' format: " . $self->visual();
110
    return 0;
111
}
112
113
sub _abbr_to_numeric {
114
    my $aref    = shift;
115
    my $dformat = shift;
116
    my ($month_abbr, $day_abbr) = ($aref->[4], $aref->[3]) if $dformat eq 'rfc822';
117
118
    for( my $i = 0; $i < scalar(@months); $i++ ) {
119
        if ( $months[$i] =~ /$month_abbr/ ) {
120
            $aref->[4] = $i-1;
121
            last;
122
        }
123
    };
124
125
    for( my $i = 0; $i < scalar(@days); $i++ ) {
126
        if ( $days[$i] =~ /$day_abbr/ ) {
127
            $aref->[3] = $i;
128
            last;
129
        }
130
    };
131
    return $aref;
94
}
132
}
95
133
96
sub _check_date_and_time {
134
sub _check_date_and_time {
97
    my $chron_ref = shift;
135
    my $chron_ref = shift;
98
    my ($year, $month, $day) = _chron_to_ymd($chron_ref);
136
    my ( $year, $month, $day ) = _chron_to_ymd($chron_ref);
99
    unless (check_date($year, $month, $day)) {
137
    unless ( check_date( $year, $month, $day ) ) {
100
        carp "Illegal date specified (year = $year, month = $month, day = $day)";
138
        carp "Illegal date specified (year = $year, month = $month, day = $day)";
101
    }
139
    }
102
    my ($hour, $minute, $second) = _chron_to_hms($chron_ref);
140
    my ( $hour, $minute, $second ) = _chron_to_hms($chron_ref);
103
    unless (check_time($hour, $minute, $second)) {
141
    unless ( check_time( $hour, $minute, $second ) ) {
104
        carp "Illegal time specified (hour = $hour, minute = $minute, second = $second)";
142
        carp "Illegal time specified (hour = $hour, minute = $minute, second = $second)";
105
    }
143
    }
106
}
144
}
107
145
108
sub _chron_to_ymd {
146
sub _chron_to_ymd {
109
    my $chron_ref = shift;
147
    my $chron_ref = shift;
110
    return ($chron_ref->[5] + 1900, $chron_ref->[4] + 1, $chron_ref->[3]);
148
    return ( $chron_ref->[5] + 1900, $chron_ref->[4] + 1, $chron_ref->[3] );
111
}
149
}
112
150
113
sub _chron_to_hms {
151
sub _chron_to_hms {
114
    my $chron_ref = shift;
152
    my $chron_ref = shift;
115
    return ($chron_ref->[2], $chron_ref->[1], $chron_ref->[0]);
153
    return ( $chron_ref->[2], $chron_ref->[1], $chron_ref->[0] );
116
}
154
}
117
155
118
sub new {
156
sub new {
119
	my $this = shift;
157
    my $this  = shift;
120
	my $class = ref($this) || $this;
158
    my $class = ref($this) || $this;
121
	my $self = {};
159
    my $self  = {};
122
	bless $self, $class;
160
    bless $self, $class;
123
	return $self->init(@_);
161
    return $self->init(@_);
124
}
162
}
163
125
sub init ($;$$) {
164
sub init ($;$$) {
126
	my $self = shift;
165
    my $self = shift;
127
	my $dformat;
166
    my $dformat;
128
	$self->{'dateformat'} = $dformat = (scalar(@_) >= 2) ? $_[1] : _prefformat();
167
    $self->{'dateformat'} = $dformat = ( scalar(@_) >= 2 ) ? $_[1] : _prefformat();
129
	($format_map{$dformat}) or croak 
168
    ( $format_map{$dformat} ) or croak "Invalid date format '$dformat' from " . ( ( scalar(@_) >= 2 ) ? 'argument' : 'system preferences' );
130
		"Invalid date format '$dformat' from " . ((scalar(@_) >= 2) ? 'argument' : 'system preferences');
169
    $self->{'dmy_arrayref'} = [ ( (@_) ? $self->dmy_map(shift) : localtime ) ];
131
	$self->{'dmy_arrayref'} = [((@_) ? $self->dmy_map(shift) : localtime )] ;
170
    $debug and warn "(during init) \@\$self->{'dmy_arrayref'}: " . join( ' ', @{ $self->{'dmy_arrayref'} } ) . "\n";
132
	$debug and warn "(during init) \@\$self->{'dmy_arrayref'}: " . join(' ',@{$self->{'dmy_arrayref'}}) . "\n";
171
    return $self;
133
	return $self;
134
}
172
}
173
135
sub output ($;$) {
174
sub output ($;$) {
136
	my $self = shift;
175
    my $self = shift;
137
	my $newformat = (@_) ? _recognize_format(shift) : _prefformat();
176
    my $newformat = (@_) ? _recognize_format(shift) : _prefformat();
138
	return (eval {POSIX::strftime($posix_map{$newformat}, @{$self->{'dmy_arrayref'}})} || undef);
177
    return ( eval { POSIX::strftime( $posix_map{$newformat}, @{ $self->{'dmy_arrayref'} } ) } || undef );
139
}
178
}
140
sub today ($;$) {		# NOTE: sets date value to today (and returns it in the requested or current format)
179
141
	my $class = shift;
180
sub today ($;$) {    # NOTE: sets date value to today (and returns it in the requested or current format)
142
	$class = ref($class) || $class;
181
    my $class = shift;
143
	my $format = (@_) ? _recognize_format(shift) : _prefformat();
182
    $class = ref($class) || $class;
144
	return $class->new()->output($format);
183
    my $format = (@_) ? _recognize_format(shift) : _prefformat();
184
    return $class->new()->output($format);
145
}
185
}
186
146
sub _recognize_format($) {
187
sub _recognize_format($) {
147
	my $incoming = shift;
188
    my $incoming = shift;
148
	($incoming eq 'syspref') and return _prefformat();
189
    ( $incoming eq 'syspref' ) and return _prefformat();
149
	(scalar grep (/^$incoming$/, keys %format_map) == 1) or croak "The format you asked for ('$incoming') is unrecognized.";
190
    ( scalar grep ( /^$incoming$/, keys %format_map ) == 1 ) or croak "The format you asked for ('$incoming') is unrecognized.";
150
	return $incoming;
191
    return $incoming;
151
}
192
}
152
sub DHTMLcalendar ($;$) {	# interface to posix_map
193
153
	my $class = shift;
194
sub DHTMLcalendar ($;$) {    # interface to posix_map
154
	my $format = (@_) ? shift : _prefformat();
195
    my $class = shift;
155
	return $posix_map{$format};	
196
    my $format = (@_) ? shift : _prefformat();
197
    return $posix_map{$format};
156
}
198
}
157
sub format {	# get or set dateformat: iso, metric, us, etc.
199
158
	my $self = shift;
200
sub format {                 # get or set dateformat: iso, metric, us, etc.
159
	(@_) or return $self->{'dateformat'}; 
201
    my $self = shift;
160
	$self->{'dateformat'} = _recognize_format(shift);
202
    (@_) or return $self->{'dateformat'};
203
    $self->{'dateformat'} = _recognize_format(shift);
161
}
204
}
205
162
sub visual {
206
sub visual {
163
	my $self = shift;
207
    my $self = shift;
164
	if (@_) {
208
    if (@_) {
165
		return $format_map{ _recognize_format(shift) };
209
        return $format_map{ _recognize_format(shift) };
166
	}
210
    }
167
	$self eq __PACKAGE__ and return $format_map{_prefformat()};
211
    $self eq __PACKAGE__ and return $format_map{ _prefformat() };
168
	return $format_map{ eval { $self->{'dateformat'} } || _prefformat()} ;
212
    return $format_map{ eval { $self->{'dateformat'} } || _prefformat() };
169
}
213
}
170
214
171
# like the functions from the old C4::Date.pm
215
# like the functions from the old C4::Date.pm
172
sub format_date {
216
sub format_date {
173
	return __PACKAGE__ -> new(shift,'iso')->output((@_) ? shift : _prefformat());
217
    return __PACKAGE__->new( shift, 'iso' )->output( (@_) ? shift : _prefformat() );
174
}
218
}
219
175
sub format_date_in_iso {
220
sub format_date_in_iso {
176
	return __PACKAGE__ -> new(shift,_prefformat())->output('iso');
221
    return __PACKAGE__->new( shift, _prefformat() )->output('iso');
177
}
222
}
178
223
179
1;
224
1;
Lines 192-197 The formats supported by Koha are: Link Here
192
    us - U.S. standard
237
    us - U.S. standard
193
    metric - European standard (slight misnomer, not really decimalized metric)
238
    metric - European standard (slight misnomer, not really decimalized metric)
194
    sql - log format, not really for human consumption
239
    sql - log format, not really for human consumption
240
    rfc822 - Standard for using with RSS feeds, etc.
195
241
196
=head2 ->new([string_date,][date_format])
242
=head2 ->new([string_date,][date_format])
197
243
Lines 200-218 used. If date_format is not supplied, the system preference from C4::Context is Link Here
200
246
201
Examples:
247
Examples:
202
248
203
		my $now   = C4::Dates->new();
249
        my $now   = C4::Dates->new();
204
		my $date1 = C4::Dates->new("09-21-1989","us");
250
        my $date1 = C4::Dates->new("09-21-1989","us");
205
		my $date2 = C4::Dates->new("19890921    143907","sql");
251
        my $date2 = C4::Dates->new("19890921    143907","sql");
206
252
207
=head2 ->output([date_format])
253
=head2 ->output([date_format])
208
254
209
The date value is stored independent of any specific format.  Therefore any format can be 
255
The date value is stored independent of any specific format.  Therefore any format can be 
210
invoked when displaying it. 
256
invoked when displaying it. 
211
257
212
		my $date = C4::Dates->new();    # say today is July 12th, 2010
258
        my $date = C4::Dates->new();    # say today is July 12th, 2010
213
		print $date->output("iso");     # prints "2010-07-12"
259
        print $date->output("iso");     # prints "2010-07-12"
214
		print "\n";
260
        print "\n";
215
		print $date->output("metric");  # prints "12-07-2010"
261
        print $date->output("metric");  # prints "12-07-2010"
216
262
217
However, it is still necessary to know the format of any incoming date value (e.g., 
263
However, it is still necessary to know the format of any incoming date value (e.g., 
218
setting the value of an object with new()).  Like new(), output() assumes the system preference
264
setting the value of an object with new()).  Like new(), output() assumes the system preference
Lines 228-259 method/function to tell you whether or not a Dates.pm object is of the 'iso' typ Link Here
228
can see by this example that such a test is trivial to accomplish, and not necessary to 
274
can see by this example that such a test is trivial to accomplish, and not necessary to 
229
include in the module:
275
include in the module:
230
276
231
		sub is_iso {
277
        sub is_iso {
232
			my $self = shift;
278
            my $self = shift;
233
			return ($self->format() eq "iso");
279
            return ($self->format() eq "iso");
234
		}
280
        }
235
281
236
Note: A similar function would need to be included for each format. 
282
Note: A similar function would need to be included for each format. 
237
283
238
Instead a dependent script can retrieve the format of the object directly and decide what to
284
Instead a dependent script can retrieve the format of the object directly and decide what to
239
do with it from there:
285
do with it from there:
240
286
241
		my $date = C4::Dates->new();
287
        my $date = C4::Dates->new();
242
		my $format = $date->format();
288
        my $format = $date->format();
243
		($format eq "iso") or do_something($date);
289
        ($format eq "iso") or do_something($date);
244
290
245
Or if you just want to print a given value and format, no problem:
291
Or if you just want to print a given value and format, no problem:
246
292
247
		my $date = C4::Dates->new("1989-09-21", "iso");
293
        my $date = C4::Dates->new("1989-09-21", "iso");
248
		print $date->output;
294
        print $date->output;
249
295
250
Alternatively:
296
Alternatively:
251
297
252
		print C4::Dates->new("1989-09-21", "iso")->output;
298
        print C4::Dates->new("1989-09-21", "iso")->output;
253
299
254
Or even:
300
Or even:
255
301
256
		print C4::Dates->new("21-09-1989", "metric")->output("iso");
302
        print C4::Dates->new("21-09-1989", "metric")->output("iso");
257
303
258
=head2 "syspref" -- System Preference(s)
304
=head2 "syspref" -- System Preference(s)
259
305
Lines 263-286 psuedo-format argument "syspref". Link Here
263
309
264
For example, to print an ISO date (from the database) in the <systempreference> format:
310
For example, to print an ISO date (from the database) in the <systempreference> format:
265
311
266
		my $date = C4::Dates->new($date_from_database,"iso");
312
        my $date = C4::Dates->new($date_from_database,"iso");
267
		my $datestring_for_display = $date->output("syspref");
313
        my $datestring_for_display = $date->output("syspref");
268
		print $datestring_for_display;
314
        print $datestring_for_display;
269
315
270
Or even:
316
Or even:
271
317
272
		print C4::Dates->new($date_from_database,"iso")->output("syspref");
318
        print C4::Dates->new($date_from_database,"iso")->output("syspref");
273
319
274
If you just want to know what the <systempreferece> is, a default Dates object can tell you:
320
If you just want to know what the <systempreferece> is, a default Dates object can tell you:
275
321
276
		C4::Dates->new()->format();
322
        C4::Dates->new()->format();
277
323
278
=head2 ->DHMTLcalendar([date_format])
324
=head2 ->DHMTLcalendar([date_format])
279
325
280
Returns the format string for DHTML Calendar Display based on date_format.  
326
Returns the format string for DHTML Calendar Display based on date_format.  
281
If date_format is not supplied, the return is based on system preference.
327
If date_format is not supplied, the return is based on system preference.
282
328
283
		C4::Dates->DHTMLcalendar();	#  e.g., returns "%m/%d/%Y" for 'us' system preference
329
        C4::Dates->DHTMLcalendar(); #  e.g., returns "%m/%d/%Y" for 'us' system preference
284
330
285
=head3 Error Handling
331
=head3 Error Handling
286
332
Lines 290-301 fatal error (because it is programmer error, not user error, typically). Link Here
290
Scripts must still perform validation of user input.  Attempting to set an invalid value will 
336
Scripts must still perform validation of user input.  Attempting to set an invalid value will 
291
return 0 or undefined, so a script might check as follows:
337
return 0 or undefined, so a script might check as follows:
292
338
293
		my $date = C4::Dates->new($input) or deal_with_it("$input didn't work");
339
        my $date = C4::Dates->new($input) or deal_with_it("$input didn't work");
294
340
295
To validate before creating a new object, use the regexp method of the class:
341
To validate before creating a new object, use the regexp method of the class:
296
342
297
		$input =~ C4::Dates->regexp("iso") or deal_with_it("input ($input) invalid as iso format");
343
        $input =~ C4::Dates->regexp("iso") or deal_with_it("input ($input) invalid as iso format");
298
		my $date = C4::Dates->new($input,"iso");
344
        my $date = C4::Dates->new($input,"iso");
299
345
300
More verbose debugging messages are sent in the presence of non-zero $ENV{"DEBUG"}.
346
More verbose debugging messages are sent in the presence of non-zero $ENV{"DEBUG"}.
301
347
(-)a/C4/Review.pm (-5 / +15 lines)
Lines 29-35 BEGIN { Link Here
29
	$VERSION = 3.00;
29
	$VERSION = 3.00;
30
	require Exporter;
30
	require Exporter;
31
	@ISA    = qw(Exporter);
31
	@ISA    = qw(Exporter);
32
	@EXPORT = qw(getreview savereview updatereview numberofreviews
32
	@EXPORT = qw(getreview savereview updatereview numberofreviews numberofreviewsbybiblionumber
33
		getreviews getallreviews approvereview deletereview);
33
		getreviews getallreviews approvereview deletereview);
34
}
34
}
35
35
Lines 91-96 sub updatereview { Link Here
91
}
91
}
92
92
93
sub numberofreviews {
93
sub numberofreviews {
94
    my $dbh            = C4::Context->dbh;
95
    my $query          =
96
      "SELECT count(*) FROM reviews WHERE approved=?";
97
    my $sth = $dbh->prepare($query);
98
    $sth->execute( 1 );
99
  return $sth->fetchrow;
100
}
101
102
sub numberofreviewsbybiblionumber {
94
    my ($biblionumber) = @_;
103
    my ($biblionumber) = @_;
95
    my $dbh            = C4::Context->dbh;
104
    my $dbh            = C4::Context->dbh;
96
    my $query          =
105
    my $query          =
Lines 111-122 sub getreviews { Link Here
111
}
120
}
112
121
113
sub getallreviews {
122
sub getallreviews {
114
    my ($status) = @_;
123
    my ($status, $offset, $row_count) = @_;
124
    my @params = ($status,($offset ? $offset : 0),($row_count ? $row_count : 20));
115
    my $dbh      = C4::Context->dbh;
125
    my $dbh      = C4::Context->dbh;
116
    my $query    =
126
    my $query    =
117
      "SELECT * FROM reviews WHERE approved=? order by datereviewed desc";
127
      "SELECT * FROM reviews WHERE approved=? order by datereviewed desc LIMIT ?, ?";
118
    my $sth = $dbh->prepare($query);
128
    my $sth = $dbh->prepare($query) || warn $dbh->err_str;
119
    $sth->execute($status);
129
    $sth->execute(@params);
120
	return $sth->fetchall_arrayref({});
130
	return $sth->fetchall_arrayref({});
121
}
131
}
122
132
(-)a/koha-tmpl/opac-tmpl/prog/en/css/opac.css (-2 / +26 lines)
Lines 1021-1028 a.cancel { Link Here
1021
1021
1022
.searchresults p {
1022
.searchresults p {
1023
	margin: 0;
1023
	margin: 0;
1024
	padding: 0;
1024
	padding: 0 0 .6em 0;
1025
	padding-top : .6em;
1026
}
1025
}
1027
1026
1028
td.resultscontrol img {
1027
td.resultscontrol img {
Lines 1970-1972 div.ft { Link Here
1970
	list-style:disc outside url("../../images/item-bullet.gif");
1969
	list-style:disc outside url("../../images/item-bullet.gif");
1971
	padding:0.2em 0;
1970
	padding:0.2em 0;
1972
}
1971
}
1972
1973
#recentcomments {
1974
	margin:auto;
1975
	max-width:750px;
1976
}
1977
1978
.searchresults .commentline {
1979
	background-color : rgb(255, 255, 204);
1980
	background-color : rgba(255, 255, 204, 0.4);
1981
	border : 1px solid #CCC;
1982
	display: inline-block;
1983
	-webkit-border-radius: 4px;
1984
	-moz-border-radius: 4px;
1985
	border-radius: 4px;
1986
	-webkit-box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.2);
1987
	-moz-box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.2);
1988
	box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.2);
1989
	margin : .3em;
1990
	padding : .4em;
1991
}
1992
1993
.searchresults .commentline.yours {
1994
	background-color : rgb(239, 254, 213);
1995
	background-color : rgba(239, 254, 213, 0.4);
1996
}
(-)a/koha-tmpl/opac-tmpl/prog/en/modules/opac-showreviews-rss.tmpl (+36 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="utf-8"?>
2
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
3
<channel>
4
     <title><![CDATA[<!-- TMPL_IF NAME="LibraryNameTitle" --><!-- TMPL_VAR NAME="LibraryNameTitle" --><!-- TMPL_ELSE -->Koha Online<!-- /TMPL_IF --> Catalog Recent Comments]]></title>
5
     <link><!-- TMPL_VAR NAME="OPACBaseURL" -->/cgi-bin/koha/opac-showreviews.pl&amp;format=rss2</link>
6
     <description><![CDATA[ The most recent comments from <!-- TMPL_IF NAME="LibraryNameTitle" --><!-- TMPL_VAR NAME="LibraryNameTitle" --><!-- TMPL_ELSE -->Koha Online<!-- /TMPL_IF --> Catalog. Comments can be made by logged in users and are moderated by library staff.]]></description>
7
     <atom:link href="<!-- TMPL_VAR NAME="OPACBaseURL" -->/cgi-bin/koha/opac-showreviews.pl&amp;format=rss2" rel="self" type="application/rss+xml" />
8
     <lastBuildDate><!-- TMPL_VAR NAME="timestamp" --></lastBuildDate>
9
	 <!--TMPL_LOOP NAME="reviews"-->
10
     <item>
11
       <title>New comment on <!-- TMPL_VAR NAME="title" ESCAPE="html" --> <!-- TMPL_LOOP NAME="subtitle" -->, <!-- TMPL_VAR ESCAPE="HTML" NAME="subfield" --><!-- /TMPL_LOOP --></title>
12
       <link><!-- TMPL_VAR NAME="OPACBaseURL" -->/cgi-bin/koha/opac-detail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->#comments</link>
13
       <description><![CDATA[
14
<!-- TMPL_IF NAME="OPACAmazonEnabled" --><!-- TMPL_IF NAME="OPACAmazonCoverImages" --><!-- TMPL_IF NAME="normalized_isbn" --><img src="http://images.amazon.com/images/P/<!-- TMPL_VAR NAME="normalized_isbn" -->.01.TZZZZZZZ.jpg" alt="" /><!-- /TMPL_IF --><!-- /TMPL_IF --><!-- /TMPL_IF -->
15
16
<!-- TMPL_IF NAME="SyndeticsEnabled" --><!-- TMPL_IF NAME="SyndeticsCoverImages" --><!-- TMPL_IF NAME="content_identifier_exists" --><!-- TMPL_IF NAME="using_https" --><img src="https://secure.syndetics.com/index.aspx?isbn=<!-- TMPL_VAR NAME="normalized_isbn" -->/SC.GIF&amp;client=<!-- TMPL_VAR NAME="SyndeticsClientCode" -->&amp;type=xw10&amp;upc=<!-- TMPL_VAR NAME="normalized_upc" -->&amp;oclc=<!-- TMPL_VAR NAME="normalized_oclc" -->" alt="" />
17
<!-- TMPL_ELSE -->
18
<img src="http://www.syndetics.com/index.aspx?isbn=<!-- TMPL_VAR NAME="normalized_isbn" -->/SC.GIF&amp;client=<!-- TMPL_VAR NAME="SyndeticsClientCode" -->&amp;type=xw10&amp;upc=<!-- TMPL_VAR NAME="normalized_upc" -->&amp;oclc=<!-- TMPL_VAR NAME="normalized_oclc" -->" alt="" />
19
<!-- /TMPL_IF --><!-- /TMPL_IF --><!-- /TMPL_IF --><!-- /TMPL_IF -->
20
21
<!-- TMPL_IF NAME="BakerTaylorEnabled" --><!-- TMPL_IF NAME="normalized_isbn" --><a href="https://<!-- TMPL_VAR name="BakerTaylorBookstoreURL" ESCAPE="HTML" --><!-- TMPL_VAR name="normalized_isbn" -->"><img alt="See Baker &amp; Taylor" src="<!-- TMPL_VAR name="BakerTaylorImageURL" ESCAPE="HTML" --><!-- TMPL_VAR name="normalized_isbn" -->" /></a><!-- /TMPL_IF --><!-- /TMPL_IF -->
22
	   <!-- TMPL_IF NAME="author" --><p>By <!-- TMPL_VAR NAME="author"  ESCAPE="html" -->.</p> <!-- /TMPL_IF -->
23
	   <p><!-- TMPL_IF name="place" --><!-- TMPL_VAR name="place"  ESCAPE="html" --> <!-- /TMPL_IF --><!-- TMPL_IF name="publishercode" --><!-- TMPL_VAR name="publishercode"  ESCAPE="html" --><!-- /TMPL_IF --><!-- TMPL_IF name="publicationyear" --> <!-- TMPL_VAR name="publicationyear"  ESCAPE="html" -->
24
                    <!-- TMPL_ELSE --><!-- TMPL_IF name="copyrightdate" --> <!-- TMPL_VAR name="copyrightdate"  ESCAPE="html" --><!-- /TMPL_IF --><!-- /TMPL_IF -->
25
                        <!-- TMPL_IF name="pages" -->. <!-- TMPL_VAR name="pages"  ESCAPE="html" --><!-- /TMPL_IF -->
26
                        <!-- TMPL_IF name="notes" -->, <!-- TMPL_VAR name="notes"  ESCAPE="html" --><!-- /TMPL_IF -->
27
                        <!-- TMPL_IF name="size" --> <!-- TMPL_VAR name="size"  ESCAPE="html" -->. <!-- /TMPL_IF -->
28
                        <!-- TMPL_IF name="isbn" --> <!-- TMPL_VAR name="isbn"  ESCAPE="html" --><!-- /TMPL_IF --> </p>
29
<p><!-- TMPL_VAR NAME="firstname" --> <!-- TMPL_VAR NAME="surname" --> commented on <!-- TMPL_VAR NAME="datereviewed" -->: <!--TMPL_VAR NAME="review" ESCAPE="HTML"--></p>
30
						]]></description>
31
       <guid><!-- TMPL_VAR NAME="OPACBaseURL" -->/cgi-bin/koha/opac-detail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->&amp;reviewid=<!-- TMPL_VAR NAME="reviewid" --></guid>
32
       <pubDate><!-- TMPL_VAR NAME="timestamp" --></pubDate>
33
     </item>
34
	 <!-- /TMPL_LOOP -->
35
   </channel>
36
</rss>
(-)a/koha-tmpl/opac-tmpl/prog/en/modules/opac-showreviews.tmpl (-21 / +79 lines)
Lines 1-39 Link Here
1
<!-- TMPL_INCLUDE name="doc-head-open.inc" --><!-- TMPL_IF NAME="LibraryNameTitle" --><!-- TMPL_VAR NAME="LibraryNameTitle" --><!-- TMPL_ELSE -->Koha Online<!-- /TMPL_IF --> Catalog &rsaquo;   
1
<!-- TMPL_INCLUDE name="doc-head-open.inc" --><!-- TMPL_IF NAME="LibraryNameTitle" --><!-- TMPL_VAR NAME="LibraryNameTitle" --><!-- TMPL_ELSE -->Koha Online<!-- /TMPL_IF --> Catalog &rsaquo; Recent Comments
2
<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
2
<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
3
<link rel="alternate" type="application/rss+xml" title="<!-- TMPL_IF NAME="LibraryNameTitle" --><!-- TMPL_VAR NAME="LibraryNameTitle" --><!-- TMPL_ELSE -->Koha Online<!-- /TMPL_IF --> Catalog Recent Comments" href="<!-- TMPL_VAR NAME="OPACBaseURL" -->/cgi-bin/koha/opac-showreviews.pl?format=rss" />
4
<script type="text/javascript">
5
//<![CDATA[
6
$(document).ready(function(){
7
    <!-- TMPL_IF NAME="GoogleJackets" -->KOHA.Google.GetCoverFromIsbn();<!-- /TMPL_IF -->
8
});
9
//]]>
10
</script>
3
</head>
11
</head>
4
<body id="opac-showreviews">
12
<body id="opac-showreviews">
5
13
<!-- TMPL_IF EXPR="OpacNav" --><div id="doc3" class="yui-t1"><!-- TMPL_ELSE --><div id="doc3" class="yui-t7"><!-- /TMPL_IF -->
6
<!-- TMPL_INCLUDE name="masthead.inc" -->
7
8
<div id="doc3" class="yui-t1">
9
   <div id="bd">
14
   <div id="bd">
15
<!-- TMPL_INCLUDE name="masthead.inc" -->
10
	<div id="yui-main">
16
	<div id="yui-main">
11
	<div class="yui-b"><div class="container">
17
	<div class="yui-b"><div class="container">
12
18
    <div id="recentcomments" class="searchresults">
19
<h3>Recent comments</h3>
13
<table>
20
<table>
14
    <!--TMPL_LOOP NAME="reviews"-->
21
    <!--TMPL_LOOP NAME="reviews"-->
15
    <tr>
22
    <!-- TMPL_UNLESS NAME="__odd__" --><tr class="highlight"><!-- TMPL_ELSE --><tr><!-- /TMPL_UNLESS -->
16
        <th>
17
                <b><!--TMPL_VAR NAME="title"--></b>
18
        </th>
19
    </tr>
20
    <tr>
21
        <td>
23
        <td>
22
            <!--TMPL_VAR NAME="review" ESCAPE="HTML"-->
24
23
            <p><!--TMPL_VAR NAME="datereviewed"--></p>
25
<p><!-- TMPL_IF name="BiblioDefaultViewmarc" --><a class="title" href="/cgi-bin/koha/opac-MARCdetail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" ESCAPE="URL" -->" title="View details for this title">
26
    <!-- TMPL_ELSE -->
27
    <!-- TMPL_IF name="BiblioDefaultViewisbd" --><a class="title" href="/cgi-bin/koha/opac-ISBDdetail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" ESCAPE="URL" -->" title="View details for this title">
28
    <!-- TMPL_ELSE --><a class="title" href="/cgi-bin/koha/opac-detail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" ESCAPE="URL" -->#comments" title="View details for this title">
29
    <!-- /TMPL_IF -->
30
    <!-- /TMPL_IF -->
31
    <!-- TMPL_IF NAME="title" --><!-- TMPL_VAR NAME="title" ESCAPE="html" --><!-- TMPL_ELSE -->No title<!-- /TMPL_IF --> <!-- TMPL_LOOP NAME="subtitle"  --> <!--TMPL_VAR Name="subfield"--><!--/TMPL_LOOP--></a>
32
    <!-- TMPL_IF NAME="author" -->by <a href="/cgi-bin/koha/opac-search.pl?q=au:<!-- TMPL_VAR NAME="author" ESCAPE="URL" -->" title="Search for works by this author" class="author"><!-- TMPL_VAR NAME="author" --></a></p>
33
    <!-- /TMPL_IF -->
34
    <p>
35
    <span class="results_summary"><span class="label">Publication:</span>
36
            <!-- TMPL_IF name="place" --><!-- TMPL_VAR name="place" --> <!-- /TMPL_IF --><!-- TMPL_IF name="publishercode" --><!-- TMPL_VAR name="publishercode" --><!-- /TMPL_IF --><!-- TMPL_IF name="publicationyear" --> <!-- TMPL_VAR name="publicationyear" -->
37
        <!-- TMPL_ELSE --><!-- TMPL_IF name="copyrightdate" --> <!-- TMPL_VAR name="copyrightdate" --><!-- /TMPL_IF --><!-- /TMPL_IF -->
38
            <!-- TMPL_IF name="pages" -->. <!-- TMPL_VAR name="pages" --><!-- /TMPL_IF -->
39
            <!-- TMPL_IF name="notes" -->, <!-- TMPL_VAR name="notes" --><!-- /TMPL_IF -->
40
            <!-- TMPL_IF name="size" --> <!-- TMPL_VAR name="size" --><!-- /TMPL_IF -->
41
    </span>
42
    <!-- TMPL_IF NAME="summary" -->
43
    <span class="result_summary">
44
        <!-- TMPL_VAR name="summary" -->
45
    </span>
46
    <!-- /TMPL_IF -->
47
    <!-- TMPL_IF NAME="copyrightdate" --><span class="results_summary"><span class="label">Date:</span><!-- TMPL_VAR NAME="copyrightdate" --></span><!-- /TMPL_IF --></p>
48
49
            <p class="commentline<!-- TMPL_IF NAME="your_comment" --> yours<!-- /TMPL_IF -->"><!--TMPL_VAR NAME="review" ESCAPE="HTML"-->
50
            <span style="font-size:87%;font-color:#CCC;">Added <!--TMPL_VAR NAME="datereviewed"--> by <!-- TMPL_IF NAME="your_comment" --><strong>you</strong><!-- TMPL_ELSE --><!-- TMPL_VAR NAME="firstname" --> <!-- TMPL_VAR NAME="surname" --><!-- /TMPL_IF --></span></p>
51
        </td>
52
        <td>
53
            <a class="p1" href="/cgi-bin/koha/opac-detail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->">
54
55
<!-- TMPL_IF name="BiblioDefaultViewmarc" --><a class="title" href="/cgi-bin/koha/opac-MARCdetail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" ESCAPE="URL" -->" title="View details for this title">
56
    <!-- TMPL_ELSE -->
57
    <!-- TMPL_IF name="BiblioDefaultViewisbd" --><a class="title" href="/cgi-bin/koha/opac-ISBDdetail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" ESCAPE="URL" -->" title="View details for this title">
58
    <!-- TMPL_ELSE --><a class="title" href="/cgi-bin/koha/opac-detail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" ESCAPE="URL" -->#comments" title="View details for this title">
59
    <!-- /TMPL_IF -->
60
    <!-- /TMPL_IF -->
61
62
63
            <!-- TMPL_IF NAME="OPACAmazonEnabled" --><!-- TMPL_IF NAME="OPACAmazonCoverImages" --><!-- TMPL_IF NAME="normalized_isbn" --><img src="http://images.amazon.com/images/P/<!-- TMPL_VAR NAME="normalized_isbn" -->.01.TZZZZZZZ.jpg" alt="" class="thumbnail" /><!-- TMPL_ELSE --><span class="no-image">No cover image available</span><!-- /TMPL_IF --><!-- /TMPL_IF --><!-- /TMPL_IF -->
64
65
            <!-- TMPL_IF NAME="SyndeticsEnabled" --><!-- TMPL_IF NAME="SyndeticsCoverImages" --><!-- TMPL_IF NAME="using_https" -->
66
        <img src="https://secure.syndetics.com/index.aspx?isbn=<!-- TMPL_VAR NAME="normalized_isbn" -->/SC.GIF&amp;client=<!-- TMPL_VAR NAME="SyndeticsClientCode" -->&amp;type=xw10&amp;upc=<!-- TMPL_VAR NAME="normalized_upc" -->&amp;oclc=<!-- TMPL_VAR NAME="normalized_oclc" -->" alt="" class="thumbnail" />
67
        <!--TMPL_ELSE -->
68
        <img src="http://www.syndetics.com/index.aspx?isbn=<!-- TMPL_VAR NAME="normalized_isbn" -->/SC.GIF&amp;client=<!-- TMPL_VAR NAME="SyndeticsClientCode" -->&amp;type=xw10&amp;upc=<!-- TMPL_VAR NAME="normalized_upc" -->&amp;oclc=<!-- TMPL_VAR NAME="normalized_oclc" -->" alt="" class="thumbnail" /><!-- /TMPL_IF --><!-- /TMPL_IF --><!-- /TMPL_IF -->
69
70
        <!-- TMPL_IF NAME="GoogleJackets" --><!-- TMPL_IF NAME="normalized_isbn" --><div style="block" title="<!-- TMPL_VAR NAME="biblionumber" ESCAPE="URL" -->" class="<!-- TMPL_VAR name="normalized_isbn" -->" id="gbs-thumbnail<!--TMPL_VAR NAME="__counter__"-->"></div><!-- TMPL_ELSE --><span class="no-image">No cover image available</span><!-- /TMPL_IF --><!-- /TMPL_IF -->
71
        </a>
72
        <!-- TMPL_IF NAME="BakerTaylorEnabled" --><!-- TMPL_IF NAME="normalized_isbn" --><a href="https://<!-- TMPL_VAR name="BakerTaylorBookstoreURL" ESCAPE="HTML" --><!-- TMPL_VAR name="normalized_isbn" -->"><img alt="See Baker &amp; Taylor" src="<!-- TMPL_VAR name="BakerTaylorImageURL" ESCAPE="HTML" --><!-- TMPL_VAR name="normalized_isbn" -->" /></a><!-- TMPL_ELSE --><span class="no-image">No cover image available</span><!-- /TMPL_IF --><!-- /TMPL_IF -->
24
        </td>
73
        </td>
25
    </tr>
74
    </tr>
26
    <!--/TMPL_LOOP-->
75
    <!--/TMPL_LOOP-->
27
</table>
76
</table>
28
77
<!-- TMPL_IF NAME="PAGE_NUMBERS" --><div class="pages">
29
</div>
78
    <!-- Row of numbers corresponding to showreviews result pages -->
79
        <!-- TMPL_IF NAME="previous_page_offset" --><a class="nav" href="/cgi-bin/koha/opac-showreviews.pl?offset=<!-- TMPL_VAR NAME="previous_page_offset" -->">&lt;&lt; Previous</a>
80
        <!-- TMPL_ELSE -->
81
        <!-- TMPL_IF NAME="previous_page_first" --><a class="nav" href="/cgi-bin/koha/opac-showreviews.pl?offset=0">&lt;&lt; Previous</a><!-- /TMPL_IF -->
82
        <!-- /TMPL_IF -->
83
    <!-- TMPL_LOOP NAME="PAGE_NUMBERS" --><!-- TMPL_IF NAME="highlight" --><span class="current"><!-- TMPL_VAR NAME="pg" --></span><!-- TMPL_ELSE --><a class="nav" href="/cgi-bin/koha/opac-showreviews.pl?offset=<!-- TMPL_VAR NAME="offset" -->"><!-- TMPL_VAR NAME="pg" --></a><!-- /TMPL_IF -->
84
    <!-- /TMPL_LOOP -->
85
        <!-- TMPL_IF NAME="next_page_offset" --><a class="nav" href="/cgi-bin/koha/opac-showreviews.pl?offset=<!-- TMPL_VAR NAME="next_page_offset" -->">Next &gt;&gt;</a><!-- /TMPL_IF -->
86
</div><!-- /TMPL_IF -->
30
</div>
87
</div>
31
</div>
88
</div>
32
<div class="yui-b">
33
<div class="container">
34
<!--TMPL_INCLUDE NAME="navigation.inc" -->
35
<!-- TMPL_INCLUDE name="usermenu.inc" -->
36
</div>
89
</div>
37
</div>
90
</div>
91
<!-- TMPL_IF EXPR="OpacNav" -->
92
<div class="yui-b"><div class="container">
93
<!--TMPL_INCLUDE NAME="navigation.inc" -->
94
</div></div>
95
<!-- /TMPL_IF -->
38
</div>
96
</div>
39
<!-- TMPL_INCLUDE NAME="opac-bottom.inc" -->
97
<!-- TMPL_INCLUDE NAME="opac-bottom.inc" -->
(-)a/opac/opac-showreviews.pl (-8 / +120 lines)
Lines 1-5 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
# Copyright 2000-2002 Katipo Communications
4
# Parts copyright 2010 Nelsonville Public Library
5
#
3
# This file is part of Koha.
6
# This file is part of Koha.
4
#
7
#
5
# Koha is free software; you can redistribute it and/or modify it under the
8
# Koha is free software; you can redistribute it and/or modify it under the
Lines 25-50 use C4::Output; Link Here
25
use C4::Circulation;
28
use C4::Circulation;
26
use C4::Review;
29
use C4::Review;
27
use C4::Biblio;
30
use C4::Biblio;
31
use C4::Dates qw/format_date/;
32
use C4::Members qw/GetMemberDetails/;
33
use POSIX qw(ceil strftime);
34
35
my $template_name;
36
my $query = new CGI;
37
my $format = $query->param("format") || '';
38
my $count = C4::Context->preference('OPACnumSearchResults') || 20;
39
my $results_per_page = $query->param('count') || $count;
40
my $offset = $query->param('offset') || 0;
41
my $page = $query->param('page') || 1;
42
$offset = ($page-1)*$results_per_page if $page>1;
28
43
29
my $query        = new CGI;
44
if ($format eq "rss") {
30
my $biblionumber = $query->param('biblionumber');
45
    $template_name = "opac-showreviews-rss.tmpl";
46
} else {
47
    $template_name = "opac-showreviews.tmpl",
48
}
31
49
32
my ( $template, $borrowernumber, $cookie ) = &get_template_and_user(
50
my ( $template, $borrowernumber, $cookie ) = &get_template_and_user(
33
    {
51
    {
34
        template_name   => "opac-showreviews.tmpl",
52
        template_name   => $template_name,
35
        query           => $query,
53
        query           => $query,
36
        type            => "opac",
54
        type            => "opac",
37
        authnotrequired => 1,
55
        authnotrequired => 1,
38
    }
56
    }
39
);
57
);
40
58
41
my $biblio  = GetBiblioData( $biblionumber );
59
if($format eq "rss"){
42
my $reviews = getreviews( $biblionumber, 1 );
60
    my $lastbuilddate = C4::Dates->new();
61
    my $lastbuilddate_output = $lastbuilddate->output("rfc822");
62
    $template->param(
63
        rss => 1,
64
        timestamp => $lastbuilddate_output
65
        );
66
}
67
68
my $reviews = getallreviews(1,$offset,$results_per_page);
69
my $marcflavour      = C4::Context->preference("marcflavour");
70
my $hits = numberofreviews();
71
my $i = 0;
72
my $latest_comment_date;
73
for my $result (@$reviews){
74
    my $biblionumber = $result->{biblionumber};
75
	my $bib = &GetBiblioData($biblionumber);
76
    my $record = GetMarcBiblio($biblionumber);
77
    my $frameworkcode = GetFrameworkCode($biblionumber);
78
	my ( $borr ) = GetMemberDetails( $result->{borrowernumber} );
79
	$result->{normalized_upc} = GetNormalizedUPC($record,$marcflavour);
80
	$result->{normalized_ean} = GetNormalizedEAN($record,$marcflavour);
81
	$result->{normalized_oclc} = GetNormalizedOCLCNumber($record,$marcflavour);
82
	$result->{normalized_isbn} = GetNormalizedISBN(undef,$record,$marcflavour);
83
	$result->{title} = $bib->{'title'};
84
	$result->{subtitle} = GetRecordValue('subtitle', $record, $frameworkcode);
85
	$result->{author} = $bib->{'author'};
86
	$result->{place} = $bib->{'place'};
87
	$result->{publishercode} = $bib->{'publishercode'};
88
	$result->{copyrightdate} = $bib->{'copyrightdate'};
89
	$result->{pages} = $bib->{'pages'};
90
	$result->{size} = $bib->{'size'};
91
	$result->{notes} = $bib->{'notes'};
92
	$result->{timestamp} = $bib->{'timestamp'};
93
	$result->{firstname} = $borr->{'firstname'};
94
	$result->{surname} = $borr->{'surname'};
95
    if ($result->{borrowernumber} eq $borrowernumber) {
96
		$result->{your_comment} = 1;
97
	}
98
99
    if($format eq "rss"){
100
        my $rsstimestamp = C4::Dates->new($result->{datereviewed},"iso");
101
        my $rsstimestamp_output = $rsstimestamp->output("rfc822");
102
        $result->{timestamp} = $rsstimestamp_output;
103
        $result->{datereviewed} = format_date($result->{datereviewed});
104
    } else {
105
        $result->{datereviewed} = format_date($result->{datereviewed});
106
    }
107
}
108
## Build the page numbers on the bottom of the page
109
            my @page_numbers;
110
            my $previous_page_first;
111
            my $previous_page_offset;
112
            # total number of pages there will be
113
            my $pages = ceil($hits / $results_per_page);
114
            # default page number
115
            my $current_page_number = 1;
116
            $current_page_number = ($offset / $results_per_page + 1) if $offset;
117
            if($offset - $results_per_page == 0){
118
            	$previous_page_first = 1;
119
            } elsif ($offset - $results_per_page > 0){
120
            	$previous_page_offset = $offset - $results_per_page;
121
            }
122
            my $next_page_offset = $offset + $results_per_page;
123
            # If we're within the first 10 pages, keep it simple
124
            if ($current_page_number < 10) {
125
                # just show the first 10 pages
126
                # Loop through the pages
127
                my $pages_to_show = 10;
128
                $pages_to_show = $pages if $pages<10;
129
                for ($i=1; $i<=$pages_to_show;$i++) {
130
                    # the offset for this page
131
                    my $this_offset = (($i*$results_per_page)-$results_per_page);
132
                    # the page number for this page
133
                    my $this_page_number = $i;
134
                    # it should only be highlighted if it's the current page
135
                    my $highlight = 1 if ($this_page_number == $current_page_number);
136
                    # put it in the array
137
                    push @page_numbers, { offset => $this_offset, pg => $this_page_number, highlight => $highlight };
138
                                
139
                }
140
                        
141
            }
142
            # now, show twenty pages, with the current one smack in the middle
143
            else {
144
                for ($i=$current_page_number; $i<=($current_page_number + 20 );$i++) {
145
                    my $this_offset = ((($i-9)*$results_per_page)-$results_per_page);
146
                    my $this_page_number = $i-9;
147
                    my $highlight = 1 if ($this_page_number == $current_page_number);
148
                    if ($this_page_number <= $pages) {
149
                        push @page_numbers, { offset => $this_offset, pg => $this_page_number, highlight => $highlight };
150
                    }
151
                }
152
            }
153
$template->param(   PAGE_NUMBERS => \@page_numbers,
154
					previous_page_first => $previous_page_first,
155
                    previous_page_offset => $previous_page_offset) unless $pages < 2;
156
$template->param(next_page_offset => $next_page_offset) unless $pages eq $current_page_number;
43
157
44
$template->param(
158
$template->param(
45
    reviews => $reviews,
159
    reviews => $reviews,
46
    title   => $biblio->{'title'},
47
);
160
);
48
161
49
output_html_with_http_headers $query, $cookie, $template->output;
162
output_html_with_http_headers $query, $cookie, $template->output;
50
(-)a/t/Dates.t (-58 / +58 lines)
Lines 3-46 Link Here
3
use strict;
3
use strict;
4
use warnings;
4
use warnings;
5
5
6
use Test::More tests => 276;
6
use Test::More tests => 327;
7
7
BEGIN {
8
BEGIN {
8
	use FindBin;
9
    use FindBin;
9
	use lib $FindBin::Bin;
10
    use lib $FindBin::Bin;
10
	use_ok('C4::Dates', qw(format_date format_date_in_iso));
11
    use_ok( 'C4::Dates', qw(format_date format_date_in_iso) );
11
}
12
}
12
13
13
sub describe ($$) {
14
sub describe ($$) {
14
	my $front = sprintf("%-25s", shift);
15
    my $front = sprintf( "%-25s", shift );
15
	my $tail = shift || 'FAILED';
16
    my $tail = shift || 'FAILED';
16
	return  "$front : $tail";
17
    return "$front : $tail";
17
}
18
}
18
19
19
# Keep the number of test elements per [array] equal or the predicted number of tests 
20
# Keep the number of test elements per [array] equal or the predicted number of tests
20
# needs to be different for different (fake) sysprefs.
21
# needs to be different for different (fake) sysprefs.
21
my %thash = (
22
my %thash = (
22
	  iso  => ['2001-1-1','1989-9-21','1952-1-0', '1989-9-21 13:46:02','2001-01-01','1989-09-21','1952-01-00', '1989-09-21 13:46:02'],
23
    iso    => [ '2001-1-1',           '1989-9-21',          '1952-1-0',           '1989-9-21 13:46:02', '2001-01-01', '1989-09-21', '1952-01-00', '1989-09-21 13:46:02' ],
23
	metric => ["1-1-2001",'21-9-1989','00-1-1952', '21-9-1989 13:46:02',"01-01-2001",'21-09-1989','00-01-1952', '21-09-1989 13:46:02'],
24
    metric => [ "1-1-2001",           '21-9-1989',          '00-1-1952',          '21-9-1989 13:46:02', "01-01-2001", '21-09-1989', '00-01-1952', '21-09-1989 13:46:02' ],
24
	   us  => ["01-01-2001",'09-21-1989','01-00-1952', '09-21-1989 13:46:02'],
25
    us     => [ "01-01-2001",         '09-21-1989',         '01-00-1952',         '09-21-1989 13:46:02' ],
25
	  sql  => ['20010101    010101',
26
    sql    => [ '20010101    010101', '19890921    143907', '19520100    000000', '19890921    134602' ],
26
	  		   '19890921    143907',
27
    rfc822 => [ 'Wed, 02 Oct 2002 15:00:00 +0200', 'Fri, 10 Sep 2010 08:00:00 +0500' ],
27
	  		   '19520100    000000',
28
	  		   '19890921    134602'     ],
29
);
28
);
30
29
31
my ($date, $format, $today, $today0, $val, $re, $syspref);
30
my ( $date, $format, $today, $today0, $val, $re, $syspref );
32
my @formats = sort keys %thash;
31
my @formats              = sort keys %thash;
33
my $fake_syspref_default = 'us';
32
my $fake_syspref_default = 'us';
34
my $fake_syspref = (@ARGV) ? shift : $ENV{KOHA_TEST_DATE_FORMAT};
33
my $fake_syspref         = (@ARGV) ? shift : $ENV{KOHA_TEST_DATE_FORMAT};
35
if ($fake_syspref) {
34
if ($fake_syspref) {
36
    diag "You asked for date format '$fake_syspref'.";
35
    diag "You asked for date format '$fake_syspref'.";
37
    unless (scalar grep {/^$fake_syspref$/} @formats) {
36
    unless ( scalar grep { /^$fake_syspref$/ } @formats ) {
38
        diag "Warning: Unkown date format '$fake_syspref', reverting to default '$fake_syspref_default'.";
37
        diag "Warning: Unkown date format '$fake_syspref', reverting to default '$fake_syspref_default'.";
39
        $fake_syspref = $fake_syspref_default;
38
        $fake_syspref = $fake_syspref_default;
40
    }
39
    }
41
}
40
}
42
$fake_syspref or $fake_syspref = $fake_syspref_default;
41
$fake_syspref or $fake_syspref = $fake_syspref_default;
43
$C4::Dates::prefformat = $fake_syspref;     # So Dates doesn't have to ask the DB anything.
42
$C4::Dates::prefformat = $fake_syspref;    # So Dates doesn't have to ask the DB anything.
44
43
45
diag <<EndOfDiag;
44
diag <<EndOfDiag;
46
45
Lines 56-112 Testing Legacy Functions: format_date and format_date_in_iso Link Here
56
55
57
EndOfDiag
56
EndOfDiag
58
57
59
ok($syspref = C4::Dates->new->format(),         "Your system preference is: $syspref");
58
ok( $syspref = C4::Dates->new->format(), "Your system preference is: $syspref" );
60
print "\n";
59
print "\n";
61
foreach (@{$thash{'iso'}}) {
60
foreach ( @{ $thash{'iso'} } ) {
62
	ok($val = format_date($_),                  "format_date('$_'): $val"            );
61
    ok( $val = format_date($_), "format_date('$_'): $val" );
63
}
62
}
64
foreach (@{$thash{$syspref}}) {
63
foreach ( @{ $thash{$syspref} } ) {
65
	ok($val = format_date_in_iso($_),           "format_date_in_iso('$_'): $val"     );
64
    ok( $val = format_date_in_iso($_), "format_date_in_iso('$_'): $val" );
66
}
65
}
67
ok($today0 = C4::Dates->today(),                "(default) CLASS ->today : $today0" );
66
ok( $today0 = C4::Dates->today(), "(default) CLASS ->today : $today0" );
68
diag "\nTesting " . scalar(@formats) . " formats.\nTesting no input (defaults):\n";
67
diag "\nTesting " . scalar(@formats) . " formats.\nTesting no input (defaults):\n";
69
print "\n";
68
print "\n";
70
foreach (@formats) {
69
foreach (@formats) {
71
	my $pre = sprintf '(%-6s)', $_;
70
    my $pre = sprintf '(%-6s)', $_;
72
	ok($date = C4::Dates->new(),                "$pre Date Creation   : new()");
71
    ok( $date = C4::Dates->new(), "$pre Date Creation   : new()" );
73
	ok($_ eq ($format = $date->format($_)),     "$pre format($_)      : " . ($format|| 'FAILED') );
72
    ok( $_ eq ( $format = $date->format($_) ), "$pre format($_)      : " . ( $format || 'FAILED' ) );
74
	ok($format = $date->visual(),  				"$pre visual()        : " . ($format|| 'FAILED') );
73
    ok( $format = $date->visual(), "$pre visual()        : " . ( $format || 'FAILED' ) );
75
	ok($today  = $date->output(),               "$pre output()        : " . ($today || 'FAILED') );
74
    ok( $today  = $date->output(), "$pre output()        : " . ( $today  || 'FAILED' ) );
76
	ok($today  = $date->today(),                "$pre object->today   : " . ($today || 'FAILED') );
75
    ok( $today  = $date->today(),  "$pre object->today   : " . ( $today  || 'FAILED' ) );
77
	print "\n";
76
    print "\n";
78
}
77
}
79
78
80
diag "\nTesting with valid inputs:\n";
79
diag "\nTesting with valid inputs:\n";
81
foreach $format (@formats) {
80
foreach $format (@formats) {
82
	my $pre = sprintf '(%-6s)', $format;
81
    my $pre = sprintf '(%-6s)', $format;
83
  foreach my $testval (@{$thash{ $format }}) {
82
    foreach my $testval ( @{ $thash{$format} } ) {
84
	ok($date = C4::Dates->new($testval,$format),         "$pre Date Creation   : new('$testval','$format')");
83
        ok( $date = C4::Dates->new( $testval, $format ), "$pre Date Creation   : new('$testval','$format')" );
85
	ok($re   = $date->regexp,                            "$pre has regexp()" );
84
        ok( $re = $date->regexp, "$pre has regexp()" );
86
	ok($testval =~ /^$re$/,                              "$pre has regexp() match $testval");
85
        ok( $testval =~ /^$re$/, "$pre has regexp() match $testval" );
87
	ok($val  = $date->output(),                 describe("$pre output()", $val) );
86
        ok( $val = $date->output(), describe( "$pre output()", $val ) );
88
    SKIP: {
87
      SKIP: {
89
        skip("special case with explicit regexp('syspref') because $format isn't $syspref", 1) unless ($format eq $syspref);
88
            skip( "special case with explicit regexp('syspref') because $format isn't $syspref", 1 ) unless ( $format eq $syspref );
90
        my $re_syspref = C4::Dates->regexp('syspref');
89
            my $re_syspref = C4::Dates->regexp('syspref');
91
        ok($testval =~ /^$re_syspref$/,                  "$pre has regexp('syspref') match $testval");
90
            ok( $testval =~ /^$re_syspref$/, "$pre has regexp('syspref') match $testval" );
91
        }
92
        foreach ( grep { !/$format/ } @formats ) {
93
            ok( $today = $date->output($_), describe( sprintf( "$pre output(%8s)", "'$_'" ), $today ) );
94
        }
95
        ok( $today = $date->today(), describe( "$pre object->today", $today ) );
96
97
        # ok($today == ($today = C4::Dates->today()), "$pre CLASS ->today   : $today" );
98
        ok( $val = $date->output(), describe( "$pre output()", $val ) );
99
100
        # ok($format eq ($format = $date->format()),  "$pre format()        : $format" );
101
        print "\n";
92
    }
102
    }
93
	foreach (grep {!/$format/} @formats) {
94
		ok($today = $date->output($_),          describe(sprintf("$pre output(%8s)","'$_'"), $today) );
95
	}
96
	ok($today  = $date->today(),                describe("$pre object->today", $today) );
97
	# ok($today == ($today = C4::Dates->today()), "$pre CLASS ->today   : $today" );
98
	ok($val  = $date->output(),                 describe("$pre output()", $val) );
99
	# ok($format eq ($format = $date->format()),  "$pre format()        : $format" );
100
	print "\n";
101
  }
102
}
103
}
103
104
104
diag "\nTesting object independence from class\n";
105
diag "\nTesting object independence from class\n";
105
my $in1 = '12/25/1952';	# us
106
my $in1  = '12/25/1952';                       # us
106
my $in2 = '13/01/2001'; # metric
107
my $in2  = '13/01/2001';                       # metric
107
my $d1 = C4::Dates->new($in1, 'us');
108
my $d1   = C4::Dates->new( $in1, 'us' );
108
my $d2 = C4::Dates->new($in2, 'metric');
109
my $d2   = C4::Dates->new( $in2, 'metric' );
109
my $out1 = $d1->output('iso');
110
my $out1 = $d1->output('iso');
110
my $out2 = $d2->output('iso');
111
my $out2 = $d2->output('iso');
111
ok($out1 ne $out2,                             "subsequent constructors get different dataspace ($out1 != $out2)");
112
ok( $out1 ne $out2, "subsequent constructors get different dataspace ($out1 != $out2)" );
112
diag "done.\n";
113
diag "done.\n";
113
- 

Return to bug 4473