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 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
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.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
24 upload-cover-image.pl - Script for handling uploading of both single and bulk coverimages and importing them into the database.
32 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.
33 Images will be resized into thumbnails of 140x200 pixels and larger images of
34 800x600 pixels. If the images that are uploaded are larger, they will be
35 resized, maintaining aspect ratio.
56 my $fileID=$input->param('uploadedfileid');
57 my ($template, $loggedinuser, $cookie)
58 = get_template_and_user({template_name => "tools/upload-images.tmpl",
62 flagsrequired => { tools => 'upload_cover_images'},
66 my $filetype = $input->param('filetype');
67 my $biblionumber = $input->param('biblionumber');
68 my $uploadfilename = $input->param('uploadfile');
69 my $replace = $input->param('replace');
70 my $op = $input->param('op');
71 my %cookies = parse CGI::Cookie($cookie);
72 my $sessionID = $cookies{'CGISESSID'}->value;
76 $template->{VARS}->{'filetype'} = $filetype;
77 $template->{VARS}->{'biblionumber'} = $biblionumber;
82 my $uploaded_file = C4::UploadedFile->fetch($sessionID, $fileID);
83 if ($filetype eq 'image') {
84 my $fh = $uploaded_file->fh();
85 my $srcimage = GD::Image->new($fh);
86 if (defined $srcimage) {
87 my $dberror = PutImage($biblionumber, $srcimage, $replace);
98 my $filename = $uploaded_file->filename();
99 my $dirname = File::Temp::tempdir( CLEANUP => 1);
100 unless (system("unzip", $filename, '-d', $dirname) == 0) {
104 push @directories, "$dirname";
105 foreach my $recursive_dir ( @directories ) {
107 opendir $dir, $recursive_dir;
108 while ( my $entry = readdir $dir ) {
109 push @directories, "$recursive_dir/$entry" if ( -d "$recursive_dir/$entry" and $entry !~ /^[._]/ );
113 foreach my $dir ( @directories ) {
115 if ( -e "$dir/idlink.txt" ) {
116 $file = "$dir/idlink.txt";
117 } elsif ( -e "$dir/datalink.txt" ) {
118 $file = "$dir/datalink.txt";
122 if (open (FILE, $file)) {
123 while (my $line = <FILE>) {
124 my $delim = ($line =~ /\t/) ? "\t" : ($line =~ /,/) ? "," : "";
125 #$debug and warn "Delimeter is \'$delim\'";
126 unless ( $delim eq "," || $delim eq "\t" ) {
127 warn "Unrecognized or missing field delimeter. Please verify that you are using either a ',' or a 'tab'";
130 ($biblionumber, $filename) = split $delim, $line;
131 $biblionumber =~ s/[\"\r\n]//g; # remove offensive characters
132 $filename =~ s/[\"\r\n\s]//g;
133 my $srcimage = GD::Image->new("$dir/$filename");
134 if (defined $srcimage) {
136 my $dberror = PutImage($biblionumber, $srcimage, $replace);
153 $template->{VARS}->{'total'} = $total;
154 $template->{VARS}->{'uploadimage'} = 1;
155 $template->{VARS}->{'error'} = $error;
156 $template->{VARS}->{'biblionumber'} = $biblionumber;
159 output_html_with_http_headers $input, $cookie, $template->output;
165 Written by Jared Camins-Esakov of C & P Bibliography Services, in part based on
166 code by Koustubha Kale of Anant Corporation and Chris Nighswonger of Foundation