fix for bug 2348: Cannot change patron category
[koha.git] / opac / opac-userupdate.pl
blob384f003d838d6558f178e3f956e51ee0c926252d
1 #!/usr/bin/perl
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
10 # version.
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
20 use strict;
21 require Exporter;
22 use CGI;
23 use Mail::Sendmail;
25 use C4::Auth; # checkauth, getborrowernumber.
26 use C4::Context;
27 use C4::Koha;
28 use C4::Circulation;
29 use C4::Output;
30 use C4::Dates qw/format_date/;
31 use C4::Members;
32 use C4::Members::Attributes;
33 use C4::Branch;
35 my $query = new CGI;
37 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
39 template_name => "opac-userupdate.tmpl",
40 query => $query,
41 type => "opac",
42 authnotrequired => 0,
43 flagsrequired => { borrow => 1 },
44 debug => 1,
48 # get borrower information ....
49 my ( $borr ) = GetMemberDetails( $borrowernumber );
50 my $lib = GetBranchDetail($borr->{'branchcode'});
52 # handle the new information....
53 # collect the form values and send an email.
54 my @fields = (
55 'surname', 'firstname', 'phone',
56 'fax', 'address','address2','city','zipcode','phone','mobile','fax','phonepro', 'emailaddress','B_streetaddress','B_city','B_zipcode','dateofbirth','sex'
58 my $update;
59 my $updateemailaddress = $lib->{'branchemail'};
60 $updateemailaddress = C4::Context->preference('KohaAdminEmailAddress') unless( $updateemailaddress =~ /\w+@\w+/);
61 if ( $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(
66 template_name => "kohaerror.tmpl",
67 query => $query,
68 type => "opac",
69 authnotrequired => 1,
70 flagsrequired => { borrow => 1 },
71 debug => 1,
75 $template->param(
76 errormessage => 'KohaAdminEmailAddress system preference
77 is not set. Please visit the library to update your user record'
80 output_html_with_http_headers $query, $cookie, $template->output;
81 exit;
84 if ( $query->{'modify'} ) {
86 # get all the fields:
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:
92 EOF
93 foreach my $field (@fields) {
94 my $newfield = $query->param($field);
95 $message .= "$field : $borr->{$field} --> $newfield\n";
97 $message .= "\n\nThanks,\nKoha\n\n";
98 my %mail = (
99 To => $updateemailaddress,
100 From => $updateemailaddress,
101 Subject => "User Request for update of Record.",
102 Message => $message,
103 'Content-Type' => 'text/plain; charset="utf8"',
106 if ( sendmail %mail ) {
108 # do something if it works....
109 warn "Mail sent ok\n";
110 print $query->redirect('/cgi-bin/koha/opac-user.pl?patronupdate=sent');
111 exit;
113 else {
115 # do something if it doesnt work....
116 warn "Error sending mail: $Mail::Sendmail::error \n";
120 $borr->{'dateenrolled'} = format_date( $borr->{'dateenrolled'} );
121 $borr->{'expiry'} = format_date( $borr->{'expiry'} );
122 $borr->{'dateofbirth'} = format_date( $borr->{'dateofbirth'} );
123 $borr->{'ethnicity'} = fixEthnicity( $borr->{'ethnicity'} );
125 if (C4::Context->preference('ExtendedPatronAttributes')) {
126 my $attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber, 'opac');
127 if (scalar(@$attributes) > 0) {
128 $borr->{ExtendedPatronAttributes} = 1;
129 $borr->{patron_attributes} = $attributes;
133 my @bordat;
134 $bordat[0] = $borr;
136 $template->param(
137 BORROWER_INFO => \@bordat,
138 userupdateview => 1,
141 output_html_with_http_headers $query, $cookie, $template->output;