From 7f19f8fe54b0f663f1786c425c22ad563934fb1a Mon Sep 17 00:00:00 2001 From: Mark Tompsett Date: Sat, 25 Apr 2015 19:41:12 -0400 Subject: [PATCH] Bug 6815: Capture picture from web cam This enhancement gives the librarian the ability to capture a photo from a webcam attached to the Koha server. It does this by adding a 'Capture' button to the member details page. This button is only visible if there is likely a webcam. This is determined by if /dev/video{something} exists. This also corrects the functionality of the delete button, which is broken, because borrowernumber and cardnumber got mixed up. This requires the package streamer be installed: $ sudo apt-get install streamer Additionally, I had to add www-data to the video group. $ sudo addgroup www-data video TEST PLAN --------- 1) Back up DB. 2) Have a picture file available for uploading. 3) Find a particular patron 4) Upload the picture file on hand. -- should work fine. 5) Delete the patron picture. -- fails. 6) Apply patch. 7) Delete the patron picture. -- success 8) Upload the patron picture again. -- success 9) Check for Capture button. a) plug in it and refresh page -- capture button should be there. b) unplug it and refresh page -- capture button should not be there. c) plug it back in and refresh 10) Make a strange face, hold it, and click 'Capture' -- a few seconds later the page should refresh with your face. 11) Restore DB 12) run koha qa test tools. --- .../prog/en/modules/members/moremember.tt | 6 +++--- members/moremember.pl | 13 +++++++++++- tools/picture-upload.pl | 24 ++++++++++++++++------ 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt index 9536a22..be49b97 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt @@ -271,9 +271,9 @@ function validate1(date) {
- - - [% IF ( picture ) %]Delete[% END %] +      + [% IF ( webcam ) %]    [% END %] + [% IF ( picture ) %]Delete[% END %]
diff --git a/members/moremember.pl b/members/moremember.pl index a0024cb..8606108 100755 --- a/members/moremember.pl +++ b/members/moremember.pl @@ -50,7 +50,7 @@ use C4::Letters; use C4::Biblio; use C4::Branch; # GetBranchName use C4::Form::MessagingPreferences; -use List::MoreUtils qw/uniq/; +use List::MoreUtils qw/uniq none/; use C4::Members::Attributes qw(GetBorrowerAttributes); use Koha::Borrower::Debarments qw(GetDebarments IsDebarred); use Module::Load; @@ -113,6 +113,17 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( ); my $borrowernumber = $input->param('borrowernumber'); +# Look for something that might be a webcam. +opendir DIR, "/dev" or die "cannot determine devices on system: $!"; +my @devices = readdir DIR; +close DIR; +if (none { $_ =~ /video/ } @devices) { + $template->param( webcam => 0 ); +} +else { + $template->param( webcam => 1 ); +} + my ( $od, $issue, $fines ) = GetMemberIssuesAndFines($borrowernumber); $template->param( issuecount => $issue ); diff --git a/tools/picture-upload.pl b/tools/picture-upload.pl index 3ae4f62..22e9178 100755 --- a/tools/picture-upload.pl +++ b/tools/picture-upload.pl @@ -75,13 +75,17 @@ $debug and warn "Operation requested: $op"; my ( $total, $handled, @counts, $tempfile, $tfh, %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) || + ( $op eq 'Capture' ) ) { my $dirname = File::Temp::tempdir( CLEANUP => 1 ); $debug and warn "dirname = $dirname"; my $filesuffix; if ( $uploadfilename =~ m/(\..+)$/i ) { $filesuffix = $1; } + if ( $op eq 'Capture' ) { + $filesuffix = '.jpeg'; + } ( $tfh, $tempfile ) = File::Temp::tempfile( SUFFIX => $filesuffix, UNLINK => 1 ); $debug and warn "tempfile = $tempfile"; @@ -90,17 +94,25 @@ if ( ( $op eq 'Upload' ) && $uploadfile ) { $errors{'NOTZIP'} = 1 if ( $uploadfilename !~ /\.zip$/i && $filetype =~ m/zip/i ); $errors{'NOWRITETEMP'} = 1 unless ( -w $dirname ); - $errors{'EMPTYUPLOAD'} = 1 unless ( length($uploadfile) > 0 ); + $errors{'EMPTYUPLOAD'} = 1 unless ( + (defined($uploadfile) && length($uploadfile) > 0) || + $op eq 'Capture' ); if (%errors) { $template->param( ERRORS => [ \%errors ] ); output_html_with_http_headers $input, $cookie, $template->output; exit; } - while (<$uploadfile>) { - print $tfh $_; + if ( $op eq 'Upload' ) { + while (<$uploadfile>) { + print $tfh $_; + } + close $tfh; + } + elsif ( $op eq 'Capture' ) { + close $tfh; + system('/usr/bin/streamer -o ' . $tempfile); } - close $tfh; if ( $filetype eq 'zip' ) { unless ( system( "unzip", $tempfile, '-d', $dirname ) == 0 ) { $errors{'UZIPFAIL'} = $uploadfilename; @@ -157,7 +169,7 @@ elsif ( ( $op eq 'Upload' ) && !$uploadfile ) { $template->param( filetype => $filetype ); } elsif ( $op eq 'Delete' ) { - my $dberror = RmPatronImage($cardnumber); + my $dberror = RmPatronImage($borrowernumber); $debug and warn "Patron image deleted for $cardnumber"; warn "Database returned $dberror" if $dberror; } -- 1.9.1