Bug 6362: fixes display to re-embed items in OPAC MARC view
[koha.git] / opac / opac-userupdate.pl
1 #!/usr/bin/perl
2
3 # Copyright 2000-2002 Katipo Communications
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 use strict;
21 use warnings;
22
23 use CGI;
24 use Mail::Sendmail;
25
26 use C4::Auth;    # checkauth, getborrowernumber.
27 use C4::Context;
28 use C4::Koha;
29 use C4::Circulation;
30 use C4::Output;
31 use C4::Dates qw/format_date/;
32 use C4::Members;
33 use C4::Members::Attributes;
34 use C4::Branch;
35
36 my $query = new CGI;
37
38 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
39     {
40         template_name   => "opac-userupdate.tmpl",
41         query           => $query,
42         type            => "opac",
43         authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
44         flagsrequired   => { borrow => 1 },
45         debug           => 1,
46     }
47 );
48
49 # get borrower information ....
50 my ( $borr ) = GetMemberDetails( $borrowernumber );
51 my $lib = GetBranchDetail($borr->{'branchcode'});
52
53 # handle the new information....
54 # collect the form values and send an email.
55 my @fields = (
56     'surname','firstname','othernames','streetnumber','address','address2','city','state','zipcode','country','phone','mobile','fax','phonepro', 'emailaddress','emailpro','B_streetnumber','B_address','B_address2','B_city','B_state','B_zipcode','B_country','B_phone','B_email','dateofbirth','sex'
57 );
58 my $update;
59 my $updateemailaddress = $lib->{'branchemail'};
60 $updateemailaddress = C4::Context->preference('KohaAdminEmailAddress') unless( $updateemailaddress =~ /\w+@\w+/);
61 if ( !$updateemailaddress || $updateemailaddress eq '' ) {
62     warn
63 "KohaAdminEmailAddress system preference not set.  Couldn't send patron update information for $borr->{'firstname'} $borr->{'surname'} (#$borrowernumber)\n";
64     my ($template) = get_template_and_user(
65         {
66             template_name   => "kohaerror.tmpl",
67             query           => $query,
68             type            => "opac",
69             authnotrequired => 1,
70             flagsrequired   => { borrow => 1 },
71             debug           => 1,
72         }
73     );
74
75     $template->param(
76         noadminemail => 1,
77     );
78
79     output_html_with_http_headers $query, $cookie, $template->output;
80     exit;
81 }
82
83 if ( $query->param('modify') ) {
84
85     # get all the fields:
86     my $message = <<"EOF";
87 Patron $borr->{'cardnumber'}
88
89 has requested to change her/his personal details.
90 Please check these new details and make the changes:
91 EOF
92
93     my $streetnumber = $borr->{'streetnumber'} || '';
94     my $address = $borr->{'address'} || '';
95     my $address2 = $borr->{'address2'} || '';
96     my $B_streetnumber = $borr->{'B_streetnumber'} || '';
97     my $B_address = $borr->{'B_address'} || '';
98     my $B_address2 = $borr->{'B_address2'} || '';
99
100     foreach my $field (@fields) {
101         my $newfield = $query->param($field) || '';
102         my $borrowerfield = '';
103         if($borr->{$field}) {
104             $borrowerfield = $borr->{$field};
105         }
106         
107         if($field eq "dateofbirth") {
108            $borrowerfield  = format_date( $borr->{'dateofbirth'} ) || '';
109         }
110
111         if($borrowerfield eq $newfield) {
112             $message .= "$field : $borrowerfield  -->  $newfield\n";
113         } else {
114             $message .= uc($field) . " : $borrowerfield  -->  $newfield\n";
115         }
116     }
117     $message .= "\n\nThanks,\nKoha\n\n";
118     my %mail = (
119         To      => $updateemailaddress,
120         From    => $updateemailaddress,
121         Subject => "User Request for update of Record.",
122         Message => $message,
123         'Content-Type' => 'text/plain; charset="utf8"',
124     );
125
126     if ( sendmail %mail ) {
127
128         # do something if it works....
129         print $query->redirect('/cgi-bin/koha/opac-user.pl?patronupdate=sent');
130         exit;
131     }
132     else {
133
134         # do something if it doesnt work....
135         warn "Error sending mail: $Mail::Sendmail::error \n";
136     }
137 }
138
139 $borr->{'dateenrolled'} = format_date( $borr->{'dateenrolled'} );
140 $borr->{'dateexpiry'}   = format_date( $borr->{'dateexpiry'} );
141 $borr->{'dateofbirth'}  = format_date( $borr->{'dateofbirth'} );
142 $borr->{'ethnicity'}    = fixEthnicity( $borr->{'ethnicity'} );
143 $borr->{'branchname'}   = GetBranchName($borr->{'branchcode'});
144
145 if (C4::Context->preference('ExtendedPatronAttributes')) {
146     my $attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber, 'opac');
147     if (scalar(@$attributes) > 0) {
148         $borr->{ExtendedPatronAttributes} = 1;
149         $borr->{patron_attributes} = $attributes;
150     }
151 }
152
153 my $checkin_prefs  = C4::Members::Messaging::GetMessagingPreferences({
154     borrowernumber => $borrowernumber,
155     message_name   => 'Item Checkout'
156 });
157 for (@{ $checkin_prefs->{transports} }) {
158     $borr->{"items_returned_$_"} = 1;
159 }
160 my $checkout_prefs = C4::Members::Messaging::GetMessagingPreferences({
161     borrowernumber => $borrowernumber,
162     message_name   => 'Item Check-in'
163 });
164 for (@{ $checkout_prefs->{transports} }) {
165     $borr->{"items_borrowed_$_"} = 1;
166 }
167
168 my @bordat;
169 $bordat[0] = $borr;
170
171 $template->param( 
172     BORROWER_INFO => \@bordat,
173     userupdateview => 1,
174 );
175
176 output_html_with_http_headers $query, $cookie, $template->output;