3 # Copyright 2011 C & P Bibliography Services
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
25 upload-cover-image.pl - Script for handling uploading of both single and bulk coverimages and importing them into the database.
33 This script is called and presents the user with an interface allowing him/her to upload a single cover image or bulk cover images via a zip file.
34 Images will be resized into thumbnails of 140x200 pixels and larger images of
35 800x600 pixels. If the images that are uploaded are larger, they will be
36 resized, maintaining aspect ratio.
49 use Koha
::UploadedFiles
;
56 my $fileID = $input->param('uploadedfileid');
57 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
59 template_name
=> "tools/upload-images.tt",
63 flagsrequired
=> { tools
=> 'upload_local_cover_images' },
68 my $filetype = $input->param('filetype');
69 my $biblionumber = $input->param('biblionumber');
70 #my $uploadfilename = $input->param('uploadfile'); # obsolete?
71 my $replace = !C4
::Context
->preference("AllowMultipleCovers")
72 || $input->param('replace');
73 my $op = $input->param('op');
74 my %cookies = parse CGI
::Cookie
($cookie);
75 my $sessionID = $cookies{'CGISESSID'}->value;
79 $template->{VARS
}->{'filetype'} = $filetype;
80 $template->{VARS
}->{'biblionumber'} = $biblionumber;
85 my $upload = Koha
::UploadedFiles
->find( $fileID );
86 if ( $filetype eq 'image' ) {
87 my $fh = $upload->file_handle;
88 my $srcimage = GD
::Image
->new($fh);
90 if ( defined $srcimage ) {
91 my $dberror = PutImage
( $biblionumber, $srcimage, $replace );
105 my $filename = $upload->full_path;
106 my $dirname = File
::Temp
::tempdir
( CLEANUP
=> 1 );
107 unless ( system( "unzip", $filename, '-d', $dirname ) == 0 ) {
112 push @directories, "$dirname";
113 foreach my $recursive_dir (@directories) {
115 opendir $dir, $recursive_dir;
116 while ( my $entry = readdir $dir ) {
117 push @directories, "$recursive_dir/$entry"
118 if ( -d
"$recursive_dir/$entry" and $entry !~ /^[._
]/ );
122 foreach my $dir (@directories) {
124 if ( -e
"$dir/idlink.txt" ) {
125 $file = "$dir/idlink.txt";
127 elsif ( -e
"$dir/datalink.txt" ) {
128 $file = "$dir/datalink.txt";
133 if ( open( FILE
, $file ) ) {
134 while ( my $line = <FILE
> ) {
136 ( $line =~ /\t/ ) ?
"\t"
137 : ( $line =~ /,/ ) ?
","
140 #$debug and warn "Delimeter is \'$delim\'";
141 unless ( $delim eq "," || $delim eq "\t" ) {
143 "Unrecognized or missing field delimeter. Please verify that you are using either a ',' or a 'tab'";
147 ( $biblionumber, $filename ) = split $delim, $line, 2;
149 s/[\"\r\n]//g; # remove offensive characters
150 $filename =~ s/[\"\r\n]//g;
151 $filename =~ s/^\s+//;
152 $filename =~ s/\s+$//;
153 if (C4
::Context
->preference("CataloguingLog")) {
154 logaction
('CATALOGUING', 'MODIFY', $biblionumber, "biblio cover image: $filename");
156 my $srcimage = GD
::Image
->new("$dir/$filename");
157 if ( defined $srcimage ) {
160 PutImage
( $biblionumber, $srcimage,
180 $template->{VARS
}->{'total'} = $total;
181 $template->{VARS
}->{'uploadimage'} = 1;
182 $template->{VARS
}->{'error'} = $error;
183 $template->{VARS
}->{'biblionumber'} = $biblionumber;
186 output_html_with_http_headers
$input, $cookie, $template->output;
192 Written by Jared Camins-Esakov of C & P Bibliography Services, in part based on
193 code by Koustubha Kale of Anant Corporation and Chris Nighswonger of Foundation