#!/usr/bin/perl
-use warnings;
-use strict;
+use Modern::Perl;
use CGI qw ( -utf8 );
use Graphics::Magick;
use POSIX qw(ceil);
-use autouse 'Data::Dumper' => qw(Dumper);
use C4::Context;
use C4::Auth;
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,
TABLE => $table,
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,
);
}
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 => $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,
- );
+ 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,
+ );
+ }
}
}
}