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.
50 use Koha::UploadedFiles;
57 my $fileID = $input->param('uploadedfileid');
58 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
60 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 $itemnumber = $input->param('itemnumber');
71 #my $uploadfilename = $input->param('uploadfile'); # obsolete?
72 my $replace = !C4::Context->preference("AllowMultipleCovers")
73 || $input->param('replace');
74 my $op = $input->param('op');
75 my %cookies = parse CGI::Cookie($cookie);
76 my $sessionID = $cookies{'CGISESSID'}->value;
81 filetype => $filetype,
82 biblionumber => $biblionumber,
83 itemnumber => $itemnumber,
89 my $upload = Koha::UploadedFiles->find( $fileID );
90 if ( $filetype eq 'image' ) {
91 my $fh = $upload->file_handle;
92 my $srcimage = GD::Image->new($fh);
94 if ( defined $srcimage ) {
95 my $dberror = PutImage( { biblionumber => $biblionumber, itemnumber => $itemnumber, src_image => $srcimage, replace => $replace } );
109 my $filename = $upload->full_path;
110 my $dirname = File::Temp::tempdir( CLEANUP => 1 );
111 qx/unzip $filename -d $dirname/;
113 unless ( $exit_code == 0 ) {
118 push @directories, "$dirname";
119 foreach my $recursive_dir (@directories) {
121 opendir $dir, $recursive_dir;
122 while ( my $entry = readdir $dir ) {
123 push @directories, "$recursive_dir/$entry"
124 if ( -d "$recursive_dir/$entry" and $entry !~ /^[._]/ );
128 foreach my $dir (@directories) {
130 if ( -e "$dir/idlink.txt" ) {
131 $file = "$dir/idlink.txt";
133 elsif ( -e "$dir/datalink.txt" ) {
134 $file = "$dir/datalink.txt";
139 if ( open( my $fh, '<', $file ) ) {
140 while ( my $line = <$fh> ) {
142 ( $line =~ /\t/ ) ? "\t"
143 : ( $line =~ /,/ ) ? ","
146 #$debug and warn "Delimeter is \'$delim\'";
147 unless ( $delim eq "," || $delim eq "\t" ) {
149 "Unrecognized or missing field delimeter. Please verify that you are using either a ',' or a 'tab'";
153 ( $biblionumber, $filename ) = split $delim, $line, 2;
155 s/[\"\r\n]//g; # remove offensive characters
156 $filename =~ s/[\"\r\n]//g;
157 $filename =~ s/^\s+//;
158 $filename =~ s/\s+$//;
159 if (C4::Context->preference("CataloguingLog")) {
160 logaction('CATALOGUING', 'MODIFY', $biblionumber, "biblio cover image: $filename");
162 my $srcimage = GD::Image->new("$dir/$filename");
163 if ( defined $srcimage ) {
165 my $dberror = PutImage(
167 biblionumber => $biblionumber,
168 src_image => $srcimage,
195 biblionumber => $biblionumber || Koha::Items->find($itemnumber)->biblionumber,
196 itemnumber => $itemnumber,
200 output_html_with_http_headers $input, $cookie, $template->output;
206 Written by Jared Camins-Esakov of C & P Bibliography Services, in part based on
207 code by Koustubha Kale of Anant Corporation and Chris Nighswonger of Foundation