Lines 47-69
my $image_limit = C4::Context->preference('ImageLimit') || '';
Link Here
|
47 |
my $errstr = ''; # NOTE: For error codes see error-messages.inc |
47 |
my $errstr = ''; # NOTE: For error codes see error-messages.inc |
48 |
|
48 |
|
49 |
if ($op eq 'upload') { |
49 |
if ($op eq 'upload') { |
50 |
if (!$upload_file) { |
50 |
# Checking for duplicate image name |
51 |
warn sprintf('An error occurred while attempting to upload file %s.', $source_file); |
51 |
my $duplicate; |
52 |
$errstr = 301; |
52 |
my $dbh = C4::Context->dbh; |
53 |
$template->param( |
53 |
my $query = "SELECT image_name FROM creator_images"; |
54 |
IMPORT_SUCCESSFUL => 0, |
54 |
my $sth = $dbh->prepare($query); |
55 |
SOURCE_FILE => $source_file, |
55 |
$sth->execute(); |
56 |
IMAGE_NAME => $image_name, |
56 |
my $image_names = $sth->fetchall_arrayref; |
57 |
TABLE => $table, |
57 |
foreach my $img ( @{$image_names} ) { |
58 |
error => $errstr, |
58 |
if ( $img->[0] eq $image_name ) { |
59 |
); |
59 |
$duplicate = 1; |
|
|
60 |
warn sprintf('Image name already exists.'); |
61 |
$errstr = 304; |
62 |
$template->param( |
63 |
IMPORT_SUCCESSFUL => 0, |
64 |
SOURCE_FILE => $source_file, |
65 |
IMAGE_NAME => $image_name, |
66 |
TABLE => $table, |
67 |
error => $errstr, |
68 |
); |
69 |
} |
60 |
} |
70 |
} |
61 |
else { |
71 |
unless ($duplicate) { |
62 |
my $image = Graphics::Magick->new; |
72 |
if (!$upload_file) { |
63 |
eval{$image->Read($cgi->tmpFileName($file_name));}; |
73 |
warn sprintf('An error occurred while attempting to upload file %s.', $source_file); |
64 |
if ($@) { |
74 |
$errstr = 301; |
65 |
warn sprintf('An error occurred while creating the image object: %s',$@); |
|
|
66 |
$errstr = 202; |
67 |
$template->param( |
75 |
$template->param( |
68 |
IMPORT_SUCCESSFUL => 0, |
76 |
IMPORT_SUCCESSFUL => 0, |
69 |
SOURCE_FILE => $source_file, |
77 |
SOURCE_FILE => $source_file, |
Lines 73-103
if ($op eq 'upload') {
Link Here
|
73 |
); |
81 |
); |
74 |
} |
82 |
} |
75 |
else { |
83 |
else { |
76 |
my $errstr = ''; |
84 |
my $image = Graphics::Magick->new; |
77 |
my $size = $image->Get('filesize'); |
85 |
eval{$image->Read($cgi->tmpFileName($file_name));}; |
78 |
$errstr = 302 if $size > 500000; |
86 |
if ($@) { |
79 |
$image->Set(magick => 'png'); # convert all images to png as this is a lossless format which is important for resizing operations later on |
87 |
warn sprintf('An error occurred while creating the image object: %s',$@); |
80 |
my $err = put_image($image_name, $image->ImageToBlob()) || '0'; |
88 |
$errstr = 202; |
81 |
$errstr = 101 if $err == 1; |
|
|
82 |
$errstr = 303 if $err == 202; |
83 |
if ($errstr) { |
84 |
$template->param( |
89 |
$template->param( |
85 |
IMPORT_SUCCESSFUL => 0, |
90 |
IMPORT_SUCCESSFUL => 0, |
86 |
SOURCE_FILE => $source_file, |
91 |
SOURCE_FILE => $source_file, |
87 |
IMAGE_NAME => $image_name, |
92 |
IMAGE_NAME => $image_name, |
88 |
TABLE => $table, |
93 |
TABLE => $table, |
89 |
error => $errstr, |
94 |
error => $errstr, |
90 |
image_limit => $image_limit, |
|
|
91 |
); |
95 |
); |
92 |
} |
96 |
} |
93 |
else { |
97 |
else { |
94 |
$table = html_table($display_columns->{'image'}, get_image(undef, "image_id, image_name")); # refresh table data after successfully performing save operation |
98 |
my $errstr = ''; |
95 |
$template->param( |
99 |
my $size = $image->Get('filesize'); |
96 |
IMPORT_SUCCESSFUL => 1, |
100 |
$errstr = 302 if $size > 500000; |
97 |
SOURCE_FILE => $source_file, |
101 |
$image->Set(magick => 'png'); # convert all images to png as this is a lossless format which is important for resizing operations later on |
98 |
IMAGE_NAME => $image_name, |
102 |
my $err = put_image($image_name, $image->ImageToBlob()) || '0'; |
99 |
TABLE => $table, |
103 |
$errstr = 101 if $err == 1; |
100 |
); |
104 |
$errstr = 303 if $err == 202; |
|
|
105 |
if ($errstr) { |
106 |
$template->param( |
107 |
IMPORT_SUCCESSFUL => 0, |
108 |
SOURCE_FILE => $source_file, |
109 |
IMAGE_NAME => $image_name, |
110 |
TABLE => $table, |
111 |
error => $errstr, |
112 |
image_limit => $image_limit, |
113 |
); |
114 |
} |
115 |
else { |
116 |
$table = html_table($display_columns->{'image'}, get_image(undef, "image_id, image_name")); # refresh table data after successfully performing save operation |
117 |
$template->param( |
118 |
IMPORT_SUCCESSFUL => 1, |
119 |
SOURCE_FILE => $source_file, |
120 |
IMAGE_NAME => $image_name, |
121 |
TABLE => $table, |
122 |
); |
123 |
} |
101 |
} |
124 |
} |
102 |
} |
125 |
} |
103 |
} |
126 |
} |
104 |
- |
|
|