Bug 30477: Add new UNIMARC installer translation files
[koha.git] / members / patronimage.pl
1 #!/usr/bin/perl
2 #
3 # Copyright 2008 Foundations Bible College & Seminary Inc.
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19 #
20 #
21 #
22
23 use Modern::Perl;
24
25 use CGI qw ( -utf8 );
26 use C4::Auth qw( check_api_auth );
27 use C4::Context;
28 use Koha::Patrons;
29
30 $|=1;
31
32 my $query = CGI->new;
33 my $borrowernumber;
34
35 =head1 NAME
36
37 patronimage.pl - Script for retrieving and formatting Koha patron images for display
38
39 =head1 SYNOPSIS
40
41 <img src="patronimage.pl?borrowernumber= />
42
43 =head1 DESCRIPTION
44
45 This script, when called from within HTML and passed a valid patron borrowernumber, will retrieve the image data associated with that borrowernumber if one exists, format it in proper HTML format and pass it back to be displayed.
46
47 =cut
48
49 my ($status, $cookie, $sessionID) = check_api_auth($query, [ { borrowers => '*' }, { circulate => '*' } ] );
50
51 unless ( $status eq 'ok' ) {
52     print $query->header(-type => 'text/plain', -status => '403 Forbidden');
53     exit 0;
54 }
55
56 if ($query->param('borrowernumber')) {
57     $borrowernumber = $query->param('borrowernumber');
58 } else {
59     $borrowernumber = shift;
60 }
61
62 my $patron         = Koha::Patrons->find( $borrowernumber );
63 my $userenv = C4::Context->userenv;
64 my $logged_in_user = Koha::Patrons->find( $userenv->{number} );
65
66 unless ( $logged_in_user->can_see_patron_infos( $patron ) ) {
67     print $query->header(-type => 'text/plain', -status => '403 Forbidden');
68     exit 0;
69 }
70
71 my $patron_image = $patron->image;
72
73 # NOTE: Never dump the contents of $imagedata->{'patronimage'} via a warn to a log or nasty
74 # things will result... you have been warned!
75
76 if ($patron_image) {
77     print $query->header (-type => $patron_image->mimetype, -'Cache-Control' => 'no-store', -Content_Length => length ($patron_image->imagefile)), $patron_image->imagefile;
78     exit;
79 } else {
80     warn "No image exists for $borrowernumber";
81     exit;
82 }
83
84 exit;
85
86 =head1 AUTHOR
87
88 Chris Nighswonger cnighswonger <at> foundations <dot> edu
89
90 =cut