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