3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
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
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.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
26 use C4::Auth; # checkauth, getborrowernumber.
31 use C4::Dates qw/format_date/;
33 use C4::Members::Attributes;
38 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
40 template_name => "opac-userupdate.tmpl",
44 flagsrequired => { borrow => 1 },
49 # get borrower information ....
50 my ( $borr ) = GetMemberDetails( $borrowernumber );
51 my $lib = GetBranchDetail($borr->{'branchcode'});
53 # handle the new information....
54 # collect the form values and send an email.
56 'surname', 'firstname',
57 'address','address2','city','zipcode','phone','mobile','fax','phonepro', 'emailaddress','B_streetaddress','B_city','B_zipcode','dateofbirth','sex'
60 my $updateemailaddress = $lib->{'branchemail'};
61 $updateemailaddress = C4::Context->preference('KohaAdminEmailAddress') unless( $updateemailaddress =~ /\w+@\w+/);
62 if ( $updateemailaddress eq '' ) {
64 "KohaAdminEmailAddress system preference not set. Couldn't send patron update information for $borr->{'firstname'} $borr->{'surname'} (#$borrowernumber)\n";
65 my ($template) = get_template_and_user(
67 template_name => "kohaerror.tmpl",
71 flagsrequired => { borrow => 1 },
80 output_html_with_http_headers $query, $cookie, $template->output;
84 if ( $query->param('modify') ) {
87 my $message = <<"EOF";
88 Borrower $borr->{'cardnumber'}
90 has requested to change her/his personal details.
91 Please check these new details and make the changes:
94 my $B_streetnumber = $borr->{'B_streetnumber'} || '';
95 my $B_address = $borr->{'B_address'} || '';
97 foreach my $field (@fields) {
98 my $newfield = $query->param($field) || '';
99 my $borrowerfield = '';
100 if($borr->{$field}) {
101 $borrowerfield = $borr->{$field};
103 # reconstruct the alternate address
104 if($field eq "B_streetaddress") {
105 $borrowerfield = "$B_streetnumber $B_address";
108 if($field eq "dateofbirth") {
109 $borrowerfield = format_date( $borr->{'dateofbirth'} ) || '';
112 if($borrowerfield eq $newfield) {
113 $message .= "$field : $borrowerfield --> $newfield\n";
115 $message .= uc($field) . " : $borrowerfield --> $newfield\n";
118 $message .= "\n\nThanks,\nKoha\n\n";
120 To => $updateemailaddress,
121 From => $updateemailaddress,
122 Subject => "User Request for update of Record.",
124 'Content-Type' => 'text/plain; charset="utf8"',
127 if ( sendmail %mail ) {
129 # do something if it works....
130 warn "Mail sent ok\n";
131 print $query->redirect('/cgi-bin/koha/opac-user.pl?patronupdate=sent');
136 # do something if it doesnt work....
137 warn "Error sending mail: $Mail::Sendmail::error \n";
141 $borr->{'dateenrolled'} = format_date( $borr->{'dateenrolled'} );
142 $borr->{'dateexpiry'} = format_date( $borr->{'dateexpiry'} );
143 $borr->{'dateofbirth'} = format_date( $borr->{'dateofbirth'} );
144 $borr->{'ethnicity'} = fixEthnicity( $borr->{'ethnicity'} );
146 if (C4::Context->preference('ExtendedPatronAttributes')) {
147 my $attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber, 'opac');
148 if (scalar(@$attributes) > 0) {
149 $borr->{ExtendedPatronAttributes} = 1;
150 $borr->{patron_attributes} = $attributes;
154 my $checkin_prefs = C4::Members::Messaging::GetMessagingPreferences({
155 borrowernumber => $borrowernumber,
156 message_name => 'Item Checkout'
158 for (@{ $checkin_prefs->{transports} }) {
159 $borr->{"items_returned_$_"} = 1;
161 my $checkout_prefs = C4::Members::Messaging::GetMessagingPreferences({
162 borrowernumber => $borrowernumber,
163 message_name => 'Item Check-in'
165 for (@{ $checkout_prefs->{transports} }) {
166 $borr->{"items_borrowed_$_"} = 1;
173 BORROWER_INFO => \@bordat,
177 output_html_with_http_headers $query, $cookie, $template->output;