Using my precrash CVS copy I did the following:
[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::Circ2;
29 use C4::Interface::CGI::Output;
30 use C4::Date;
31 use C4::Members;
32
33 my $query = new CGI;
34
35 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
36     {
37         template_name   => "opac-userupdate.tmpl",
38         query           => $query,
39         type            => "opac",
40         authnotrequired => 0,
41         flagsrequired   => { borrow => 1 },
42         debug           => 1,
43     }
44 );
45
46 # get borrower information ....
47 my ( $borr, $flags ) = getpatroninformation( undef, $borrowernumber );
48
49 # handle the new information....
50 # collect the form values and send an email.
51 my @fields = (
52     'title',     'surname',       'firstname',    'phone',
53     'fax', 'streetaddress', 'emailaddress', 'city','phonepro',
54 );
55 my $update;
56 my $updateemailaddress = C4::Context->preference('KohaAdminEmailAddress');
57 if ( $updateemailaddress eq '' ) {
58     warn
59 "KohaAdminEmailAddress system preference not set.  Couldn't send patron update information for $borr->{'firstname'} $borr->{'surname'} (#$borrowernumber)\n";
60     my ($template) = get_template_and_user(
61         {
62             template_name   => "kohaerror.tmpl",
63             query           => $query,
64             type            => "opac",
65             authnotrequired => 1,
66             flagsrequired   => { borrow => 1 },
67             debug           => 1,
68         }
69     );
70
71     $template->param(
72         errormessage => 'KohaAdminEmailAddress system preference
73     is not set.  Please visit the library to update your user record'
74     );
75
76     output_html_with_http_headers $query, $cookie, $template->output;
77     exit;
78 }
79
80 if ( $query->{'title'} ) {
81
82     # get all the fields:
83     my $message = <<"EOF";
84 Borrower $borr->{'cardnumber'}
85
86 has requested to change her/his personal details.
87 Please check these new details and make the changes:
88 EOF
89     foreach my $field (@fields) {
90         my $newfield = $query->param($field);
91         $message .= "$field : $borr->{$field}  -->  $newfield\n";
92     }
93     $message .= "\n\nThanks,\nKoha\n\n";
94     my %mail = (
95         To      => $updateemailaddress,
96         From    => $updateemailaddress,
97         Subject => "User Request for update of Record.",
98         Message => $message
99     );
100
101     if ( sendmail %mail ) {
102
103         # do something if it works....
104         warn "Mail sent ok\n";
105         print $query->redirect('/cgi-bin/koha/opac-user.pl');
106         exit;
107     }
108     else {
109
110         # do something if it doesnt work....
111         warn "Error sending mail: $Mail::Sendmail::error \n";
112     }
113 }
114
115 $borr->{'dateenrolled'} = format_date( $borr->{'dateenrolled'} );
116 $borr->{'expiry'}       = format_date( $borr->{'expiry'} );
117 $borr->{'dateofbirth'}  = format_date( $borr->{'dateofbirth'} );
118 $borr->{'ethnicity'}    = fixEthnicity( $borr->{'ethnicity'} );
119
120 my @bordat;
121 $bordat[0] = $borr;
122
123 $template->param( 
124     BORROWER_INFO => \@bordat
125 );
126
127 output_html_with_http_headers $query, $cookie, $template->output;