X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=patroncards%2Fimage-manage.pl;h=e5c472968636775e06f818d1b16e4b42205809c4;hb=7d8b96803f664d86762a6afb966051f7d565c40e;hp=f9f7eac984aacd77fecbf468532cb03556e7249e;hpb=130e3d9c108fb35955ab9a9944e16946537aafe9;p=koha-ffzg.git diff --git a/patroncards/image-manage.pl b/patroncards/image-manage.pl index f9f7eac984..e5c4729686 100755 --- a/patroncards/image-manage.pl +++ b/patroncards/image-manage.pl @@ -1,12 +1,10 @@ #!/usr/bin/perl -use warnings; -use strict; +use Modern::Perl; -use CGI; +use CGI qw ( -utf8 ); use Graphics::Magick; use POSIX qw(ceil); -use autouse 'Data::Dumper' => qw(Dumper); use C4::Context; use C4::Auth; @@ -18,7 +16,7 @@ use C4::Patroncards; my $cgi = CGI->new; my ($template, $loggedinuser, $cookie) = get_template_and_user({ - template_name => "patroncards/image-manage.tmpl", + template_name => "patroncards/image-manage.tt", query => $cgi, type => "intranet", authnotrequired => 0, @@ -26,17 +24,18 @@ my ($template, $loggedinuser, $cookie) = get_template_and_user({ debug => 0, }); -my $image_name = $cgi->param('image_name') || ''; my $file_name = $cgi->param('uploadfile') || ''; +my $image_name = $cgi->param('image_name') || $file_name; my $upload_file = $cgi->upload('uploadfile') || ''; my $op = $cgi->param('op') || 'none'; -my @image_ids = $cgi->param('image_id') if $cgi->param('image_id'); +my @image_ids = $cgi->multi_param('image_id') if $cgi->param('image_id'); my $source_file = "$file_name"; # otherwise we end up with what amounts to a pointer to a filehandle rather than a user-friendly filename my $display_columns = { image => [ #{db column => {label => 'col label', is link? }}, {image_id => {label => 'ID', link_field => 0}}, {image_name => {label => 'Name', link_field => 0}}, + {_delete => {label => 'Delete', link_field => 0}}, {select => {label => 'Select', value => 'image_id'}}, ], }; @@ -46,60 +45,72 @@ my $image_limit = C4::Context->preference('ImageLimit') || ''; my $errstr = ''; # NOTE: For error codes see error-messages.inc if ($op eq 'upload') { - if (!$upload_file) { - warn sprintf('An error occurred while attempting to upload file %s.', $source_file); - $errstr = 301; + # Checking for duplicate image name + my $dbh = C4::Context->dbh; + my $query = "SELECT COUNT(*) FROM creator_images WHERE image_name=?"; + my ( $exists ) = $dbh->selectrow_array( $query, undef, $image_name ); + if ( $exists ) { + $errstr = 304; $template->param( IMPORT_SUCCESSFUL => 0, SOURCE_FILE => $source_file, IMAGE_NAME => $image_name, TABLE => $table, - error => 1, - $errstr => 1, + error => $errstr, ); - } - else { - my $image = Graphics::Magick->new; - eval{$image->Read($cgi->tmpFileName($file_name));}; - if ($@) { - warn sprintf('An error occurred while creating the image object: %s',$@); - $errstr = 202; + } else { + if (!$upload_file) { + warn sprintf('An error occurred while attempting to upload file %s.', $source_file); + $errstr = 301; $template->param( IMPORT_SUCCESSFUL => 0, SOURCE_FILE => $source_file, IMAGE_NAME => $image_name, TABLE => $table, - error => 1, - $errstr => 1, + error => $errstr, ); } else { - my $errstr = ''; - my $size = $image->Get('filesize'); - $errstr = 302 if $size > 500000; - $image->Set(magick => 'png'); # convert all images to png as this is a lossless format which is important for resizing operations later on - my $err = put_image($image_name, $image->ImageToBlob()) || '0'; - $errstr = 101 if $err == 1; - $errstr = 303 if $err == 202; - if ($errstr) { + my $image = Graphics::Magick->new; + eval{$image->Read($cgi->tmpFileName($file_name));}; + if ($@) { + warn sprintf('An error occurred while creating the image object: %s',$@); + $errstr = 202; $template->param( IMPORT_SUCCESSFUL => 0, SOURCE_FILE => $source_file, IMAGE_NAME => $image_name, TABLE => $table, - error => 1, - $errstr => 1, - image_limit => $image_limit, + error => $errstr, ); } else { - $table = html_table($display_columns->{'image'}, get_image(undef, "image_id, image_name")); # refresh table data after successfully performing save operation - $template->param( - IMPORT_SUCCESSFUL => 1, - SOURCE_FILE => $source_file, - IMAGE_NAME => $image_name, - TABLE => $table, - ); + my $errstr = ''; + my $size = $image->Get('filesize'); + $errstr = 302 if $size > 500000; + $image->Set(magick => 'png'); # convert all images to png as this is a lossless format which is important for resizing operations later on + my $err = put_image($image_name, $image->ImageToBlob()) || '0'; + $errstr = 101 if $err == 1; + $errstr = 303 if $err == 202; + if ($errstr) { + $template->param( + IMPORT_SUCCESSFUL => 0, + SOURCE_FILE => $source_file, + IMAGE_NAME => $image_name, + TABLE => $table, + error => $errstr, + image_limit => $image_limit, + ); + } + else { + $table = html_table($display_columns->{'image'}, get_image(undef, "image_id, image_name")); # refresh table data after successfully performing save operation + $template->param( + IMPORT_SUCCESSFUL => 1, + SOURCE_FILE => $source_file, + IMAGE_NAME => $image_name, + TABLE => $table, + ); + } } } } @@ -120,8 +131,7 @@ elsif ($op eq 'delete') { DELETE_SUCCESSFULL => 0, IMAGE_IDS => join(', ', @image_ids), TABLE => $table, - error => 1, - $errstr => 1, + error => $errstr, image_ids => join(',',@image_ids), ); } @@ -149,8 +159,7 @@ else { # to trap unsupported operations SOURCE_FILE => $source_file, IMAGE_NAME => $image_name, TABLE => $table, - error => 1, - $errstr => 1, + error => $errstr, ); } @@ -182,11 +191,18 @@ Copyright 2009 Foundations Bible College. This file is part of Koha. -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 -Foundation; either version 2 of the License, or (at your option) any later version. +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 Foundation; either version 3 of the License, or +(at your option) any later version. + +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 A PARTICULAR PURPOSE. See the +GNU General Public License for more details. -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, -Fifth Floor, Boston, MA 02110-1301 USA. +You should have received a copy of the GNU General Public License +along with Koha; if not, see . =head1 DISCLAIMER OF WARRANTY