17 my ($template, $loggedinuser, $cookie) = get_template_and_user({
18 template_name => "patroncards/image-manage.tt",
21 flagsrequired => {tools => 'label_creator'},
24 my $file_name = $cgi->param('uploadfile') || '';
25 my $image_name = $cgi->param('image_name') || $file_name;
26 my $upload_file = $cgi->upload('uploadfile') || '';
27 my $op = $cgi->param('op') || 'none';
28 my @image_ids = $cgi->multi_param('image_id');
30 my $source_file = "$file_name"; # otherwise we end up with what amounts to a pointer to a filehandle rather than a user-friendly filename
32 my $display_columns = { image => [ #{db column => {label => 'col label', is link? }},
33 {image_id => {label => 'ID', link_field => 0}},
34 {image_name => {label => 'Name', link_field => 0}},
35 {_delete => {label => 'Delete', link_field => 0}},
36 {select => {label => 'Select', value => 'image_id'}},
39 my $table = html_table($display_columns->{'image'}, get_image(undef, "image_id, image_name"));
41 my $image_limit = C4::Context->preference('ImageLimit') || '';
42 my $errstr = ''; # NOTE: For error codes see error-messages.inc
44 if ($op eq 'upload') {
45 # Checking for duplicate image name
46 my $dbh = C4::Context->dbh;
47 my $query = "SELECT COUNT(*) FROM creator_images WHERE image_name=?";
48 my ( $exists ) = $dbh->selectrow_array( $query, undef, $image_name );
52 IMPORT_SUCCESSFUL => 0,
53 SOURCE_FILE => $source_file,
54 IMAGE_NAME => $image_name,
60 warn sprintf('An error occurred while attempting to upload file %s.', $source_file);
63 IMPORT_SUCCESSFUL => 0,
64 SOURCE_FILE => $source_file,
65 IMAGE_NAME => $image_name,
71 my $image = Graphics::Magick->new;
72 eval{$image->Read($cgi->tmpFileName($file_name));};
74 warn sprintf('An error occurred while creating the image object: %s',$@);
77 IMPORT_SUCCESSFUL => 0,
78 SOURCE_FILE => $source_file,
79 IMAGE_NAME => $image_name,
86 my $size = $image->Get('filesize');
87 $errstr = 302 if $size > 500000;
88 $image->Set(magick => 'png'); # convert all images to png as this is a lossless format which is important for resizing operations later on
89 my $err = put_image($image_name, $image->ImageToBlob()) || '0';
90 $errstr = 101 if $err == 1;
91 $errstr = 303 if $err == 202;
94 IMPORT_SUCCESSFUL => 0,
95 SOURCE_FILE => $source_file,
96 IMAGE_NAME => $image_name,
99 image_limit => $image_limit,
103 $table = html_table($display_columns->{'image'}, get_image(undef, "image_id, image_name")); # refresh table data after successfully performing save operation
105 IMPORT_SUCCESSFUL => 1,
106 SOURCE_FILE => $source_file,
107 IMAGE_NAME => $image_name,
115 elsif ($op eq 'delete') {
119 $err = rm_image(\@image_ids);
120 $errstr = 102 if $err;
123 warn sprintf('No image ids passed in to delete.');
128 DELETE_SUCCESSFULL => 0,
129 IMAGE_IDS => join(', ', @image_ids),
132 image_ids => join(',',@image_ids),
136 $table = html_table($display_columns->{'image'}, get_image(undef, "image_id, image_name")); # refresh table data after successfully performing delete operation
138 DELETE_SUCCESSFULL => 1,
143 elsif ($op eq 'none') {
145 IMPORT_SUCCESSFUL => 0,
146 SOURCE_FILE => $source_file,
147 IMAGE_NAME => $image_name,
151 else { # to trap unsupported operations
152 warn sprintf('Image upload interface called an unsupported operation: %s',$op);
155 IMPORT_SUCCESSFUL => 0,
156 SOURCE_FILE => $source_file,
157 IMAGE_NAME => $image_name,
163 output_html_with_http_headers $cgi, $cookie, $template->output;
169 image-upload.pl - Script for handling uploading of single images and importing them into the database.
177 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.
181 Chris Nighswonger <cnighswonger AT foundations DOT edu>
185 Copyright 2009 Foundations Bible College.
189 This file is part of Koha.
191 Koha is free software; you can redistribute it and/or modify it
192 under the terms of the GNU General Public License as published by
193 the Free Software Foundation; either version 3 of the License, or
194 (at your option) any later version.
196 Koha is distributed in the hope that it will be useful, but
197 WITHOUT ANY WARRANTY; without even the implied warranty of
198 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
199 GNU General Public License for more details.
201 You should have received a copy of the GNU General Public License
202 along with Koha; if not, see <http://www.gnu.org/licenses>.
204 =head1 DISCLAIMER OF WARRANTY
206 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
207 A PARTICULAR PURPOSE. See the GNU General Public License for more details.