19 my ($template, $loggedinuser, $cookie) = get_template_and_user
({
20 template_name
=> "patroncards/image-manage.tt",
24 flagsrequired
=> {tools
=> 'batch_upload_patron_images'}, # FIXME: establish flag for patron card creator
28 my $file_name = $cgi->param('uploadfile') || '';
29 my $image_name = $cgi->param('image_name') || $file_name;
30 my $upload_file = $cgi->upload('uploadfile') || '';
31 my $op = $cgi->param('op') || 'none';
32 my @image_ids = $cgi->multi_param('image_id') if $cgi->param('image_id');
34 my $source_file = "$file_name"; # otherwise we end up with what amounts to a pointer to a filehandle rather than a user-friendly filename
36 my $display_columns = { image
=> [ #{db column => {label => 'col label', is link? }},
37 {image_id
=> {label
=> 'ID', link_field
=> 0}},
38 {image_name
=> {label
=> 'Name', link_field
=> 0}},
39 {_delete
=> {label
=> 'Delete', link_field
=> 0}},
40 {select => {label
=> 'Select', value
=> 'image_id'}},
43 my $table = html_table
($display_columns->{'image'}, get_image
(undef, "image_id, image_name"));
45 my $image_limit = C4
::Context
->preference('ImageLimit') || '';
46 my $errstr = ''; # NOTE: For error codes see error-messages.inc
48 if ($op eq 'upload') {
49 # Checking for duplicate image name
50 my $dbh = C4
::Context
->dbh;
51 my $query = "SELECT COUNT(*) FROM creator_images WHERE image_name=?";
52 my ( $exists ) = $dbh->selectrow_array( $query, undef, $image_name );
56 IMPORT_SUCCESSFUL
=> 0,
57 SOURCE_FILE
=> $source_file,
58 IMAGE_NAME
=> $image_name,
64 warn sprintf('An error occurred while attempting to upload file %s.', $source_file);
67 IMPORT_SUCCESSFUL
=> 0,
68 SOURCE_FILE
=> $source_file,
69 IMAGE_NAME
=> $image_name,
75 my $image = Graphics
::Magick
->new;
76 eval{$image->Read($cgi->tmpFileName($file_name));};
78 warn sprintf('An error occurred while creating the image object: %s',$@
);
81 IMPORT_SUCCESSFUL
=> 0,
82 SOURCE_FILE
=> $source_file,
83 IMAGE_NAME
=> $image_name,
90 my $size = $image->Get('filesize');
91 $errstr = 302 if $size > 500000;
92 $image->Set(magick
=> 'png'); # convert all images to png as this is a lossless format which is important for resizing operations later on
93 my $err = put_image
($image_name, $image->ImageToBlob()) || '0';
94 $errstr = 101 if $err == 1;
95 $errstr = 303 if $err == 202;
98 IMPORT_SUCCESSFUL
=> 0,
99 SOURCE_FILE
=> $source_file,
100 IMAGE_NAME
=> $image_name,
103 image_limit
=> $image_limit,
107 $table = html_table
($display_columns->{'image'}, get_image
(undef, "image_id, image_name")); # refresh table data after successfully performing save operation
109 IMPORT_SUCCESSFUL
=> 1,
110 SOURCE_FILE
=> $source_file,
111 IMAGE_NAME
=> $image_name,
119 elsif ($op eq 'delete') {
123 $err = rm_image
(\
@image_ids);
124 $errstr = 102 if $err;
127 warn sprintf('No image ids passed in to delete.');
132 DELETE_SUCCESSFULL
=> 0,
133 IMAGE_IDS
=> join(', ', @image_ids),
136 image_ids
=> join(',',@image_ids),
140 $table = html_table
($display_columns->{'image'}, get_image
(undef, "image_id, image_name")); # refresh table data after successfully performing delete operation
142 DELETE_SUCCESSFULL
=> 1,
147 elsif ($op eq 'none') {
149 IMPORT_SUCCESSFUL
=> 0,
150 SOURCE_FILE
=> $source_file,
151 IMAGE_NAME
=> $image_name,
155 else { # to trap unsupported operations
156 warn sprintf('Image upload interface called an unsupported operation: %s',$op);
159 IMPORT_SUCCESSFUL
=> 0,
160 SOURCE_FILE
=> $source_file,
161 IMAGE_NAME
=> $image_name,
167 output_html_with_http_headers
$cgi, $cookie, $template->output;
173 image-upload.pl - Script for handling uploading of single images and importing them into the database.
181 This script is called and presents the user with an interface allowing him/her to upload a single image file. Files greater than 500K will be refused.
185 Chris Nighswonger <cnighswonger AT foundations DOT edu>
189 Copyright 2009 Foundations Bible College.
193 This file is part of Koha.
195 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
196 Foundation; either version 2 of the License, or (at your option) any later version.
198 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,
199 Fifth Floor, Boston, MA 02110-1301 USA.
201 =head1 DISCLAIMER OF WARRANTY
203 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
204 A PARTICULAR PURPOSE. See the GNU General Public License for more details.