18 my ($template, $loggedinuser, $cookie) = get_template_and_user
({
19 template_name
=> "patroncards/image-manage.tt",
22 flagsrequired
=> {tools
=> 'batch_upload_patron_images'}, # FIXME: establish flag for patron card creator
26 my $file_name = $cgi->param('uploadfile') || '';
27 my $image_name = $cgi->param('image_name') || $file_name;
28 my $upload_file = $cgi->upload('uploadfile') || '';
29 my $op = $cgi->param('op') || 'none';
30 my @image_ids = $cgi->multi_param('image_id');
32 my $source_file = "$file_name"; # otherwise we end up with what amounts to a pointer to a filehandle rather than a user-friendly filename
34 my $display_columns = { image
=> [ #{db column => {label => 'col label', is link? }},
35 {image_id
=> {label
=> 'ID', link_field
=> 0}},
36 {image_name
=> {label
=> 'Name', link_field
=> 0}},
37 {_delete
=> {label
=> 'Delete', link_field
=> 0}},
38 {select => {label
=> 'Select', value
=> 'image_id'}},
41 my $table = html_table
($display_columns->{'image'}, get_image
(undef, "image_id, image_name"));
43 my $image_limit = C4
::Context
->preference('ImageLimit') || '';
44 my $errstr = ''; # NOTE: For error codes see error-messages.inc
46 if ($op eq 'upload') {
47 # Checking for duplicate image name
48 my $dbh = C4
::Context
->dbh;
49 my $query = "SELECT COUNT(*) FROM creator_images WHERE image_name=?";
50 my ( $exists ) = $dbh->selectrow_array( $query, undef, $image_name );
54 IMPORT_SUCCESSFUL
=> 0,
55 SOURCE_FILE
=> $source_file,
56 IMAGE_NAME
=> $image_name,
62 warn sprintf('An error occurred while attempting to upload file %s.', $source_file);
65 IMPORT_SUCCESSFUL
=> 0,
66 SOURCE_FILE
=> $source_file,
67 IMAGE_NAME
=> $image_name,
73 my $image = Graphics
::Magick
->new;
74 eval{$image->Read($cgi->tmpFileName($file_name));};
76 warn sprintf('An error occurred while creating the image object: %s',$@
);
79 IMPORT_SUCCESSFUL
=> 0,
80 SOURCE_FILE
=> $source_file,
81 IMAGE_NAME
=> $image_name,
88 my $size = $image->Get('filesize');
89 $errstr = 302 if $size > 500000;
90 $image->Set(magick
=> 'png'); # convert all images to png as this is a lossless format which is important for resizing operations later on
91 my $err = put_image
($image_name, $image->ImageToBlob()) || '0';
92 $errstr = 101 if $err == 1;
93 $errstr = 303 if $err == 202;
96 IMPORT_SUCCESSFUL
=> 0,
97 SOURCE_FILE
=> $source_file,
98 IMAGE_NAME
=> $image_name,
101 image_limit
=> $image_limit,
105 $table = html_table
($display_columns->{'image'}, get_image
(undef, "image_id, image_name")); # refresh table data after successfully performing save operation
107 IMPORT_SUCCESSFUL
=> 1,
108 SOURCE_FILE
=> $source_file,
109 IMAGE_NAME
=> $image_name,
117 elsif ($op eq 'delete') {
121 $err = rm_image
(\
@image_ids);
122 $errstr = 102 if $err;
125 warn sprintf('No image ids passed in to delete.');
130 DELETE_SUCCESSFULL
=> 0,
131 IMAGE_IDS
=> join(', ', @image_ids),
134 image_ids
=> join(',',@image_ids),
138 $table = html_table
($display_columns->{'image'}, get_image
(undef, "image_id, image_name")); # refresh table data after successfully performing delete operation
140 DELETE_SUCCESSFULL
=> 1,
145 elsif ($op eq 'none') {
147 IMPORT_SUCCESSFUL
=> 0,
148 SOURCE_FILE
=> $source_file,
149 IMAGE_NAME
=> $image_name,
153 else { # to trap unsupported operations
154 warn sprintf('Image upload interface called an unsupported operation: %s',$op);
157 IMPORT_SUCCESSFUL
=> 0,
158 SOURCE_FILE
=> $source_file,
159 IMAGE_NAME
=> $image_name,
165 output_html_with_http_headers
$cgi, $cookie, $template->output;
171 image-upload.pl - Script for handling uploading of single images and importing them into the database.
179 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.
183 Chris Nighswonger <cnighswonger AT foundations DOT edu>
187 Copyright 2009 Foundations Bible College.
191 This file is part of Koha.
193 Koha is free software; you can redistribute it and/or modify it
194 under the terms of the GNU General Public License as published by
195 the Free Software Foundation; either version 3 of the License, or
196 (at your option) any later version.
198 Koha is distributed in the hope that it will be useful, but
199 WITHOUT ANY WARRANTY; without even the implied warranty of
200 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
201 GNU General Public License for more details.
203 You should have received a copy of the GNU General Public License
204 along with Koha; if not, see <http://www.gnu.org/licenses>.
206 =head1 DISCLAIMER OF WARRANTY
208 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
209 A PARTICULAR PURPOSE. See the GNU General Public License for more details.