18 my ($template, $loggedinuser, $cookie) = get_template_and_user
({
19 template_name
=> "patroncards/image-manage.tt",
23 flagsrequired
=> {tools
=> 'batch_upload_patron_images'}, # FIXME: establish flag for patron card creator
27 my $file_name = $cgi->param('uploadfile') || '';
28 my $image_name = $cgi->param('image_name') || $file_name;
29 my $upload_file = $cgi->upload('uploadfile') || '';
30 my $op = $cgi->param('op') || 'none';
31 my @image_ids = $cgi->multi_param('image_id') if $cgi->param('image_id');
33 my $source_file = "$file_name"; # otherwise we end up with what amounts to a pointer to a filehandle rather than a user-friendly filename
35 my $display_columns = { image
=> [ #{db column => {label => 'col label', is link? }},
36 {image_id
=> {label
=> 'ID', link_field
=> 0}},
37 {image_name
=> {label
=> 'Name', link_field
=> 0}},
38 {_delete
=> {label
=> 'Delete', link_field
=> 0}},
39 {select => {label
=> 'Select', value
=> 'image_id'}},
42 my $table = html_table
($display_columns->{'image'}, get_image
(undef, "image_id, image_name"));
44 my $image_limit = C4
::Context
->preference('ImageLimit') || '';
45 my $errstr = ''; # NOTE: For error codes see error-messages.inc
47 if ($op eq 'upload') {
48 # Checking for duplicate image name
49 my $dbh = C4
::Context
->dbh;
50 my $query = "SELECT COUNT(*) FROM creator_images WHERE image_name=?";
51 my ( $exists ) = $dbh->selectrow_array( $query, undef, $image_name );
55 IMPORT_SUCCESSFUL
=> 0,
56 SOURCE_FILE
=> $source_file,
57 IMAGE_NAME
=> $image_name,
63 warn sprintf('An error occurred while attempting to upload file %s.', $source_file);
66 IMPORT_SUCCESSFUL
=> 0,
67 SOURCE_FILE
=> $source_file,
68 IMAGE_NAME
=> $image_name,
74 my $image = Graphics
::Magick
->new;
75 eval{$image->Read($cgi->tmpFileName($file_name));};
77 warn sprintf('An error occurred while creating the image object: %s',$@
);
80 IMPORT_SUCCESSFUL
=> 0,
81 SOURCE_FILE
=> $source_file,
82 IMAGE_NAME
=> $image_name,
89 my $size = $image->Get('filesize');
90 $errstr = 302 if $size > 500000;
91 $image->Set(magick
=> 'png'); # convert all images to png as this is a lossless format which is important for resizing operations later on
92 my $err = put_image
($image_name, $image->ImageToBlob()) || '0';
93 $errstr = 101 if $err == 1;
94 $errstr = 303 if $err == 202;
97 IMPORT_SUCCESSFUL
=> 0,
98 SOURCE_FILE
=> $source_file,
99 IMAGE_NAME
=> $image_name,
102 image_limit
=> $image_limit,
106 $table = html_table
($display_columns->{'image'}, get_image
(undef, "image_id, image_name")); # refresh table data after successfully performing save operation
108 IMPORT_SUCCESSFUL
=> 1,
109 SOURCE_FILE
=> $source_file,
110 IMAGE_NAME
=> $image_name,
118 elsif ($op eq 'delete') {
122 $err = rm_image
(\
@image_ids);
123 $errstr = 102 if $err;
126 warn sprintf('No image ids passed in to delete.');
131 DELETE_SUCCESSFULL
=> 0,
132 IMAGE_IDS
=> join(', ', @image_ids),
135 image_ids
=> join(',',@image_ids),
139 $table = html_table
($display_columns->{'image'}, get_image
(undef, "image_id, image_name")); # refresh table data after successfully performing delete operation
141 DELETE_SUCCESSFULL
=> 1,
146 elsif ($op eq 'none') {
148 IMPORT_SUCCESSFUL
=> 0,
149 SOURCE_FILE
=> $source_file,
150 IMAGE_NAME
=> $image_name,
154 else { # to trap unsupported operations
155 warn sprintf('Image upload interface called an unsupported operation: %s',$op);
158 IMPORT_SUCCESSFUL
=> 0,
159 SOURCE_FILE
=> $source_file,
160 IMAGE_NAME
=> $image_name,
166 output_html_with_http_headers
$cgi, $cookie, $template->output;
172 image-upload.pl - Script for handling uploading of single images and importing them into the database.
180 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.
184 Chris Nighswonger <cnighswonger AT foundations DOT edu>
188 Copyright 2009 Foundations Bible College.
192 This file is part of Koha.
194 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
195 Foundation; either version 2 of the License, or (at your option) any later version.
197 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,
198 Fifth Floor, Boston, MA 02110-1301 USA.
200 =head1 DISCLAIMER OF WARRANTY
202 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
203 A PARTICULAR PURPOSE. See the GNU General Public License for more details.