Pretty sure that "S" is needed. Significant typo.
[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 with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA  02111-1307 USA
19
20 use strict;
21 require Exporter;
22 use CGI;
23 use Mail::Sendmail;
24
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::Branch;
33
34 my $query = new CGI;
35
36 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
37     {
38         template_name   => "opac-userupdate.tmpl",
39         query           => $query,
40         type            => "opac",
41         authnotrequired => 0,
42         flagsrequired   => { borrow => 1 },
43         debug           => 1,
44     }
45 );
46
47 # get borrower information ....
48 my ( $borr, $flags ) = GetMemberDetails( $borrowernumber );
49 my $lib = GetBranchDetail($borr->{'branchcode'});
50
51 # handle the new information....
52 # collect the form values and send an email.
53 my @fields = (
54     'surname',       'firstname',    'phone',
55     'fax', 'address','address2','city','zipcode','phone','mobile','fax','phonepro', 'emailaddress','B_streetaddress','B_city','B_zipcode','dateofbirth','sex'
56 );
57 my $update;
58 my $updateemailaddress = $lib->{'branchemail'};
59 $updateemailaddress = C4::Context->preference('KohaAdminEmailAddress') unless( $updateemailaddress =~ /\w+@\w+/);
60 if ( $updateemailaddress eq '' ) {
61     warn
62 "KohaAdminEmailAddress system preference not set.  Couldn't send patron update information for $borr->{'firstname'} $borr->{'surname'} (#$borrowernumber)\n";
63     my ($template) = get_template_and_user(
64         {
65             template_name   => "kohaerror.tmpl",
66             query           => $query,
67             type            => "opac",
68             authnotrequired => 1,
69             flagsrequired   => { borrow => 1 },
70             debug           => 1,
71         }
72     );
73
74     $template->param(
75         errormessage => 'KohaAdminEmailAddress system preference
76     is not set.  Please visit the library to update your user record'
77     );
78
79     output_html_with_http_headers $query, $cookie, $template->output;
80     exit;
81 }
82
83 if ( $query->{'modify'} ) {
84
85     # get all the fields:
86     my $message = <<"EOF";
87 Borrower $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     foreach my $field (@fields) {
93         my $newfield = $query->param($field);
94         $message .= "$field : $borr->{$field}  -->  $newfield\n";
95     }
96     $message .= "\n\nThanks,\nKoha\n\n";
97     my %mail = (
98         To      => $updateemailaddress,
99         From    => $updateemailaddress,
100         Subject => "User Request for update of Record.",
101         Message => $message
102     );
103
104     if ( sendmail %mail ) {
105
106         # do something if it works....
107         warn "Mail sent ok\n";
108         print $query->redirect('/cgi-bin/koha/opac-user.pl?patronupdate=sent');
109         exit;
110     }
111     else {
112
113         # do something if it doesnt work....
114         warn "Error sending mail: $Mail::Sendmail::error \n";
115     }
116 }
117
118 $borr->{'dateenrolled'} = format_date( $borr->{'dateenrolled'} );
119 $borr->{'expiry'}       = format_date( $borr->{'expiry'} );
120 $borr->{'dateofbirth'}  = format_date( $borr->{'dateofbirth'} );
121 $borr->{'ethnicity'}    = fixEthnicity( $borr->{'ethnicity'} );
122
123 my @bordat;
124 $bordat[0] = $borr;
125
126 $template->param( 
127     BORROWER_INFO => \@bordat,
128     userupdateview => 1,
129 );
130
131 output_html_with_http_headers $query, $cookie, $template->output;