Skip to content

Commit

Permalink
Bug 1633: QA follow-up
Browse files Browse the repository at this point in the history
* Show the "Upload images" button when OPACLocalCoverImages is enabled but
LocalCoverImages (i.e. local cover images on the staff client) is not
* Correct copyright and license comments in new files
* perltidy and replace tabs by four spaces

Signed-off-by: Koustubha Kale <[email protected]>
Signed-off-by: Paul Poulain <[email protected]>
  • Loading branch information
jcamins authored and PaulPoulain committed Jan 24, 2012
1 parent e901c4f commit 587e2e9
Show file tree
Hide file tree
Showing 11 changed files with 322 additions and 219 deletions.
1 change: 1 addition & 0 deletions C4/Auth.pm
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ sub get_template_and_user {
NoZebra => C4::Context->preference('NoZebra'),
EasyAnalyticalRecords => C4::Context->preference('EasyAnalyticalRecords'),
LocalCoverImages => C4::Context->preference('LocalCoverImages'),
OPACLocalCoverImages => C4::Context->preference('OPACLocalCoverImages'),
AllowMultipleCovers => C4::Context->preference('AllowMultipleCovers'),
);
}
Expand Down
128 changes: 84 additions & 44 deletions C4/Images.pm
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
package C4::Images;

# Copyright (C) 2011 C & P Bibliography Services
# Jared Camins-Esakov <[email protected]>
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Koha; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

use strict;
use warnings;
use 5.010;
Expand All @@ -9,17 +28,18 @@ use GD;
use vars qw($debug $VERSION @ISA @EXPORT);

BEGIN {
# set the version for version checking
$VERSION = 3.03;
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(
&PutImage
&RetrieveImage
&ListImagesForBiblio
&DelImage

# set the version for version checking
$VERSION = 3.03;
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(
&PutImage
&RetrieveImage
&ListImagesForBiblio
&DelImage
);
$debug = $ENV{KOHA_DEBUG} || $ENV{DEBUG} || 0;
$debug = $ENV{KOHA_DEBUG} || $ENV{DEBUG} || 0;
}

=head2 PutImage
Expand All @@ -31,27 +51,33 @@ Stores binary image data and thumbnail in database, optionally replacing existin
=cut

sub PutImage {
my ($biblionumber, $srcimage, $replace) = @_;
my ( $biblionumber, $srcimage, $replace ) = @_;

return -1 unless defined($srcimage);

if ($replace) {
foreach (ListImagesForBiblio($biblionumber)) {
foreach ( ListImagesForBiblio($biblionumber) ) {
DelImage($_);
}
}

my $dbh = C4::Context->dbh;
my $query = "INSERT INTO biblioimages (biblionumber, mimetype, imagefile, thumbnail) VALUES (?,?,?,?);";
my $query =
"INSERT INTO biblioimages (biblionumber, mimetype, imagefile, thumbnail) VALUES (?,?,?,?);";
my $sth = $dbh->prepare($query);

my $mimetype = 'image/png'; # GD autodetects three basic image formats: PNG, JPEG, XPM; we will convert all to PNG which is lossless...
# Check the pixel size of the image we are about to import...
my $thumbnail = _scale_image($srcimage, 140, 200); # MAX pixel dims are 140 X 200 for thumbnail...
my $fullsize = _scale_image($srcimage, 600, 800); # MAX pixel dims are 600 X 800 for full-size image...
my $mimetype = 'image/png'
; # GD autodetects three basic image formats: PNG, JPEG, XPM; we will convert all to PNG which is lossless...

# Check the pixel size of the image we are about to import...
my $thumbnail = _scale_image( $srcimage, 140, 200 )
; # MAX pixel dims are 140 X 200 for thumbnail...
my $fullsize = _scale_image( $srcimage, 600, 800 )
; # MAX pixel dims are 600 X 800 for full-size image...
$debug and warn "thumbnail is " . length($thumbnail) . " bytes.";

$sth->execute($biblionumber,$mimetype,$fullsize->png(),$thumbnail->png());
$sth->execute( $biblionumber, $mimetype, $fullsize->png(),
$thumbnail->png() );
my $dberror = $sth->errstr;
warn "Error returned inserting $biblionumber.$mimetype." if $sth->errstr;
undef $thumbnail;
Expand All @@ -70,14 +96,16 @@ sub RetrieveImage {
my ($imagenumber) = @_;

my $dbh = C4::Context->dbh;
my $query = 'SELECT mimetype, imagefile, thumbnail FROM biblioimages WHERE imagenumber = ?';
my $query =
'SELECT mimetype, imagefile, thumbnail FROM biblioimages WHERE imagenumber = ?';
my $sth = $dbh->prepare($query);
$sth->execute($imagenumber);
my $imagedata = $sth->fetchrow_hashref;
if ($sth->err) {
if ( $sth->err ) {
warn "Database error!";
return undef;
} else {
}
else {
return $imagedata;
}
}
Expand All @@ -89,22 +117,22 @@ Gets a list of all images associated with a particular biblio.
=cut


sub ListImagesForBiblio {
my ($biblionumber) = @_;

my @imagenumbers;
my $dbh = C4::Context->dbh;
my $dbh = C4::Context->dbh;
my $query = 'SELECT imagenumber FROM biblioimages WHERE biblionumber = ?';
my $sth = $dbh->prepare($query);
my $sth = $dbh->prepare($query);
$sth->execute($biblionumber);
warn "Database error!" if $sth->errstr;
if (!$sth->errstr && $sth->rows > 0) {
while (my $row = $sth->fetchrow_hashref) {
if ( !$sth->errstr && $sth->rows > 0 ) {
while ( my $row = $sth->fetchrow_hashref ) {
push @imagenumbers, $row->{'imagenumber'};
}
return @imagenumbers;
} else {
}
else {
return undef;
}
}
Expand All @@ -120,34 +148,46 @@ Removes the image with the supplied imagenumber.
sub DelImage {
my ($imagenumber) = @_;
warn "Imagenumber passed to DelImage is $imagenumber" if $debug;
my $dbh = C4::Context->dbh;
my $dbh = C4::Context->dbh;
my $query = "DELETE FROM biblioimages WHERE imagenumber = ?;";
my $sth = $dbh->prepare($query);
my $sth = $dbh->prepare($query);
$sth->execute($imagenumber);
my $dberror = $sth->errstr;
warn "Database error!" if $sth->errstr;
return $dberror;
}

sub _scale_image {
my ($image, $maxwidth, $maxheight) = @_;
my ($width, $height) = $image->getBounds();
my ( $image, $maxwidth, $maxheight ) = @_;
my ( $width, $height ) = $image->getBounds();
$debug and warn "image is $width pix X $height pix.";
if ($width > $maxwidth || $height > $maxheight) {
if ( $width > $maxwidth || $height > $maxheight ) {

# $debug and warn "$filename exceeds the maximum pixel dimensions of $maxwidth X $maxheight. Resizing...";
my $percent_reduce; # Percent we will reduce the image dimensions by...
if ($width > $maxwidth) {
$percent_reduce = sprintf("%.5f",($maxwidth/$width)); # If the width is oversize, scale based on width overage...
} else {
$percent_reduce = sprintf("%.5f",($maxheight/$height)); # otherwise scale based on height overage.
}
my $width_reduce = sprintf("%.0f", ($width * $percent_reduce));
my $height_reduce = sprintf("%.0f", ($height * $percent_reduce));
$debug and warn "Reducing image by " . ($percent_reduce * 100) . "\% or to $width_reduce pix X $height_reduce pix";
my $newimage = GD::Image->new($width_reduce, $height_reduce, 1); #'1' creates true color image...
$newimage->copyResampled($image,0,0,0,0,$width_reduce,$height_reduce,$width,$height);
my $percent_reduce; # Percent we will reduce the image dimensions by...
if ( $width > $maxwidth ) {
$percent_reduce =
sprintf( "%.5f", ( $maxwidth / $width ) )
; # If the width is oversize, scale based on width overage...
}
else {
$percent_reduce =
sprintf( "%.5f", ( $maxheight / $height ) )
; # otherwise scale based on height overage.
}
my $width_reduce = sprintf( "%.0f", ( $width * $percent_reduce ) );
my $height_reduce = sprintf( "%.0f", ( $height * $percent_reduce ) );
$debug
and warn "Reducing image by "
. ( $percent_reduce * 100 )
. "\% or to $width_reduce pix X $height_reduce pix";
my $newimage = GD::Image->new( $width_reduce, $height_reduce, 1 )
; #'1' creates true color image...
$newimage->copyResampled( $image, 0, 0, 0, 0, $width_reduce,
$height_reduce, $width, $height );
return $newimage;
} else {
}
else {
return $image;
}
}
Expand Down
42 changes: 28 additions & 14 deletions catalogue/image.pl
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/perl
#
# Copyright (C) 2011 C & P Bibliography Services
# Jared Camins-Esakov <[email protected]>
#
# based on patronimage.pl
#
# This file is part of Koha.
Expand All @@ -23,14 +26,14 @@
use strict;
use warnings;

use CGI; #qw(:standard escapeHTML);
use CGI; #qw(:standard escapeHTML);
use C4::Context;
use C4::Images;

$|=1;
$| = 1;

my $DEBUG = 0;
my $data = new CGI;
my $data = new CGI;
my $imagenumber;

=head1 NAME
Expand All @@ -57,17 +60,20 @@ =head1 DESCRIPTION

error() unless C4::Context->preference("OPACLocalCoverImages");

if (defined $data->param('imagenumber')) {
if ( defined $data->param('imagenumber') ) {
$imagenumber = $data->param('imagenumber');
} elsif (defined $data->param('biblionumber')) {
my @imagenumbers = ListImagesForBiblio($data->param('biblionumber'));
}
elsif ( defined $data->param('biblionumber') ) {
my @imagenumbers = ListImagesForBiblio( $data->param('biblionumber') );
if (@imagenumbers) {
$imagenumber = $imagenumbers[0];
} else {
}
else {
warn "No images for this biblio" if $DEBUG;
error();
}
} else {
}
else {
$imagenumber = shift;
}

Expand All @@ -79,25 +85,33 @@ =head1 DESCRIPTION

if ($imagedata) {
my $image;
if ($data->param('thumbnail')) {
if ( $data->param('thumbnail') ) {
$image = $imagedata->{'thumbnail'};
} else {
}
else {
$image = $imagedata->{'imagefile'};
}
print $data->header (-type => $imagedata->{'mimetype'}, -'Cache-Control' => 'no-store', -expires => 'now', -Content_Length => length ($image)), $image;
print $data->header(
-type => $imagedata->{'mimetype'},
-'Cache-Control' => 'no-store',
-expires => 'now',
-Content_Length => length($image)
), $image;
exit;
} else {
}
else {
warn "No image exists for $imagenumber" if $DEBUG;
error();
}
} else {
}
else {
error();
}

error();

sub error {
print $data->header ( -status=> '404', -expires => 'now' );
print $data->header( -status => '404', -expires => 'now' );
exit;
}

Expand Down
38 changes: 21 additions & 17 deletions catalogue/imageviewer.pl
Original file line number Diff line number Diff line change
Expand Up @@ -40,38 +40,42 @@
);

my $biblionumber = $query->param('biblionumber') || $query->param('bib');
my $imagenumber = $query ->param('imagenumber');
my ($count, $biblio) = GetBiblio($biblionumber);
my $imagenumber = $query->param('imagenumber');
my ( $count, $biblio ) = GetBiblio($biblionumber);
my $itemcount = GetItemsCount($biblionumber);

my @items = GetItemsInfo( $biblionumber );
my @items = GetItemsInfo($biblionumber);

my $norequests = 1;
foreach my $item (@items) {

# can place holds defaults to yes
$norequests = 0 unless ( ( $item->{'notforloan_per_itemtype'} > 0 ) || ( $item->{'itemnotforloan'} > 0 ) );
$norequests = 0
unless ( ( $item->{'notforloan_per_itemtype'} > 0 )
|| ( $item->{'itemnotforloan'} > 0 ) );
}

if($query->cookie("holdfor")){
my $holdfor_patron = GetMember('borrowernumber' => $query->cookie("holdfor"));
if ( $query->cookie("holdfor") ) {
my $holdfor_patron =
GetMember( 'borrowernumber' => $query->cookie("holdfor") );
$template->param(
holdfor => $query->cookie("holdfor"),
holdfor_surname => $holdfor_patron->{'surname'},
holdfor_firstname => $holdfor_patron->{'firstname'},
holdfor => $query->cookie("holdfor"),
holdfor_surname => $holdfor_patron->{'surname'},
holdfor_firstname => $holdfor_patron->{'firstname'},
holdfor_cardnumber => $holdfor_patron->{'cardnumber'},
);
}

if (C4::Context->preference("LocalCoverImages")) {
if ( C4::Context->preference("LocalCoverImages") ) {
my @images = ListImagesForBiblio($biblionumber);
$template->{VARS}->{'LocalCoverImages'} = 1;
$template->{VARS}->{'images'} = \@images;
$template->{VARS}->{'imagenumber'} = $imagenumber || $images[0] || '';
$template->{VARS}->{'images'} = \@images;
$template->{VARS}->{'imagenumber'} = $imagenumber || $images[0] || '';
}
$template->{VARS}->{'count'} = $itemcount;
$template->{VARS}->{'biblionumber'} = $biblionumber;
$template->{VARS}->{'norequests'} = $norequests;
$template->param( C4::Search::enabled_staff_search_views );
$template->{VARS}->{'biblio'} = $biblio;
$template->{VARS}->{'count'} = $itemcount;
$template->{VARS}->{'biblionumber'} = $biblionumber;
$template->{VARS}->{'norequests'} = $norequests;
$template->param(C4::Search::enabled_staff_search_views);
$template->{VARS}->{'biblio'} = $biblio;

output_html_with_http_headers $query, $cookie, $template->output;
Loading

0 comments on commit 587e2e9

Please sign in to comment.