Bug 17879: Use image filename if no image name is entered
[koha.git] / patroncards / image-manage.pl
index f9f7eac..ed0302c 100755 (executable)
@@ -3,7 +3,7 @@
 use warnings;
 use strict;
 
-use CGI;
+use CGI qw ( -utf8 );
 use Graphics::Magick;
 use POSIX qw(ceil);
 use autouse 'Data::Dumper' => qw(Dumper);
@@ -18,7 +18,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 +26,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'}},
                                     ],
 };
@@ -54,8 +55,7 @@ if ($op eq 'upload') {
             SOURCE_FILE => $source_file,
             IMAGE_NAME => $image_name,
             TABLE => $table,
-            error => 1,
-            $errstr => 1,
+            error => $errstr,
         );
     }
     else {
@@ -69,8 +69,7 @@ if ($op eq 'upload') {
                 SOURCE_FILE => $source_file,
                 IMAGE_NAME => $image_name,
                 TABLE => $table,
-                error => 1,
-                $errstr => 1,
+                error => $errstr,
             );
         }
         else {
@@ -87,8 +86,7 @@ if ($op eq 'upload') {
                     SOURCE_FILE => $source_file,
                     IMAGE_NAME => $image_name,
                     TABLE => $table,
-                    error => 1,
-                    $errstr => 1,
+                    error => $errstr,
                     image_limit => $image_limit,
                 );
             }
@@ -120,8 +118,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 +146,7 @@ else { # to trap unsupported operations
         SOURCE_FILE => $source_file,
         IMAGE_NAME => $image_name,
         TABLE => $table,
-        error => 1,
-        $errstr => 1,
+        error => $errstr,
     );
 }