Bug 33168: Prevent debhelper from renaming history.txt to changelog
[koha-ffzg.git] / patroncards / image-manage.pl
index e5c4729..3a63656 100755 (executable)
@@ -4,14 +4,12 @@ use Modern::Perl;
 
 use CGI qw ( -utf8 );
 use Graphics::Magick;
-use POSIX qw(ceil);
 
 use C4::Context;
-use C4::Auth;
-use C4::Output;
-use C4::Debug;
-use C4::Creators;
-use C4::Patroncards;
+use C4::Auth qw( get_template_and_user );
+use C4::Output qw( output_html_with_http_headers );
+use C4::Creators qw( html_table );
+use C4::Patroncards qw( get_image put_image rm_image );
 
 my $cgi = CGI->new;
 
@@ -19,16 +17,21 @@ my ($template, $loggedinuser, $cookie) = get_template_and_user({
                     template_name       => "patroncards/image-manage.tt",
                     query               => $cgi,
                     type                => "intranet",
-                    authnotrequired     => 0,
-                    flagsrequired       => {tools => 'batch_upload_patron_images'}, # FIXME: establish flag for patron card creator
-                    debug               => 0,
+                    flagsrequired       => {tools => 'label_creator'},
                     });
 
 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->multi_param('image_id') if $cgi->param('image_id');
+my @image_ids = $cgi->multi_param('image_id');
+
+my @errors = ( 'pdferr', 'errnocards', 'errba', 'errpl', 'errpt', 'errlo', 'errtpl', );
+foreach my $param (@errors) {
+    my $error = $cgi->param($param) ? 1 : 0;
+    $template->param( 'error_' . $param => $error )
+      if $error;
+}
 
 my $source_file = "$file_name"; # otherwise we end up with what amounts to a pointer to a filehandle rather than a user-friendly filename
 
@@ -87,7 +90,7 @@ if ($op eq 'upload') {
             else {
                 my $errstr = '';
                 my $size = $image->Get('filesize');
-                $errstr =  302 if $size > 500000;
+                $errstr =  302 if $size > 2097152;
                 $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;