From c00fc958b7613021ef843e1a9a725ca4d5762b3d Mon Sep 17 00:00:00 2001 From: Mark Tompsett Date: Fri, 10 Jul 2020 18:21:37 +0000 Subject: [PATCH] Bug 6815: Actually push the taken picture to the DB Tweak circ-menu, so we can close the modal. Tweak patron-webcam so it does the push. Tweak picture-upload, so it decodes rather than tries to receive the picture. --- .../intranet-tmpl/prog/en/includes/circ-menu.inc | 2 +- .../intranet-tmpl/prog/js/pages/patron-webcam.js | 6 +-- tools/picture-upload.pl | 50 +++++++++++++++------- 3 files changed, 39 insertions(+), 19 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc index 790fae6836..a97085f81a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc @@ -167,7 +167,7 @@ diff --git a/koha-tmpl/intranet-tmpl/prog/js/pages/patron-webcam.js b/koha-tmpl/intranet-tmpl/prog/js/pages/patron-webcam.js index 3677b84abe..25813020ad 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/pages/patron-webcam.js +++ b/koha-tmpl/intranet-tmpl/prog/js/pages/patron-webcam.js @@ -54,7 +54,6 @@ function initializeCamera( camera_form ){ var download_anchor = document.getElementById('download'); download_anchor.href = canvas.toDataURL('image/jpeg'); download_anchor.download = "patron-photo.jpg"; - download_anchor.click(); // gather form data for AJAX POST var data = new FormData(); data.append("uploadfiletext", download_anchor.href ); @@ -72,7 +71,8 @@ function initializeCamera( camera_form ){ contentType: false, processData: false }).done(function() { - + var cancel_button = document.getElementById('cancel_capture'); + cancel_button.click(); }); }); } @@ -110,4 +110,4 @@ $(document).ready(function(){ }); }); -}) \ No newline at end of file +}) diff --git a/tools/picture-upload.pl b/tools/picture-upload.pl index c114a86a32..1908d63e24 100755 --- a/tools/picture-upload.pl +++ b/tools/picture-upload.pl @@ -25,6 +25,7 @@ use File::Temp; use File::Copy; use CGI qw ( -utf8 ); use GD; +use MIME::Base64; use C4::Context; use C4::Auth; use C4::Output; @@ -43,18 +44,21 @@ unless (C4::Context->preference('patronimages')) { exit; } -my ($template, $loggedinuser, $cookie) - = get_template_and_user({template_name => "tools/picture-upload.tt", - query => $input, - type => "intranet", - authnotrequired => 0, - flagsrequired => { tools => 'batch_upload_patron_images'}, - debug => 0, - }); +my ($template, $loggedinuser, $cookie) = get_template_and_user( + { + template_name => "tools/picture-upload.tt", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => { tools => 'batch_upload_patron_images'}, + debug => 0, + } +); our $filetype = $input->param('filetype') || ''; my $cardnumber = $input->param('cardnumber'); -our $uploadfilename = $input->param('uploadfile') || ''; +our $uploadfilename = $input->param('uploadfile') || $input->param('uploadfilename') || ''; +my $uploadfiletext = $input->param('uploadfiletext') || ''; my $uploadfile = $input->upload('uploadfile'); my $borrowernumber = $input->param('borrowernumber'); my $op = $input->param('op') || ''; @@ -87,7 +91,7 @@ our @counts = (); our %errors = (); # Case is important in these operational values as the template must use case to be visually pleasing! -if ( ( $op eq 'Upload' ) && $uploadfile ) { +if ( ( $op eq 'Upload' ) && ($uploadfile || $uploadfiletext) ) { output_and_exit( $input, $cookie, $template, 'wrong_csrf_token' ) unless Koha::Token->new->check_csrf({ @@ -106,18 +110,34 @@ if ( ( $op eq 'Upload' ) && $uploadfile ) { $debug and warn "tempfile = $tempfile"; my ( @directories, $results ); - $errors{'NOTZIP'} = 1 - if ( $uploadfilename !~ /\.zip$/i && $filetype =~ m/zip/i ); $errors{'NOWRITETEMP'} = 1 unless ( -w $dirname ); - $errors{'EMPTYUPLOAD'} = 1 unless ( length($uploadfile) > 0 ); + if ( length($uploadfiletext) == 0 ) { + $errors{'NOTZIP'} = 1 + if ( $uploadfilename !~ /\.zip$/i && $filetype =~ m/zip/i ); + $errors{'EMPTYUPLOAD'} = 1 unless ( length($uploadfile) > 0 ); + } if (%errors) { $template->param( ERRORS => [ \%errors ] ); output_html_with_http_headers $input, $cookie, $template->output; exit; } - while (<$uploadfile>) { - print $tfh $_; + + if ( length($uploadfiletext) == 0 ) { + while (<$uploadfile>) { + print $tfh $_; + } + } else { + if ( $uploadfiletext =~ /data:image\/jpeg;base64,(.*)/ ) { + my $encoded_picture = $1; + my $decoded_picture = decode_base64($encoded_picture); + print $tfh $decoded_picture; + } else { + $errors{'BADPICTUREDATA'} = 1; + $template->param( ERRORS => [ \%errors ] ); + output_html_with_http_headers $input, $cookie, $template->output; + exit; + } } close $tfh; if ( $filetype eq 'zip' ) { -- 2.11.0