Moved C4/Charset.pm to C4/Interface/CGI/Output.pm
[koha.git] / opac / opac-userupdate.pl
1 #!/usr/bin/perl
2 use strict;
3 require Exporter;
4 use CGI;
5 use Mail::Sendmail;
6
7 use C4::Auth;         # checkauth, getborrowernumber.
8 use C4::Koha;
9 use C4::Circulation::Circ2;
10 use HTML::Template;
11
12
13 my $query = new CGI;
14
15 my ($template, $borrowernumber, $cookie) 
16     = get_template_and_user({template_name => "opac-userupdate.tmpl",
17                              query => $query,
18                              type => "opac",
19                              authnotrequired => 0,
20                              flagsrequired => {borrow => 1},
21                              debug => 1,
22                              });
23
24 # get borrower information ....
25 my ($borr, $flags) = getpatroninformation(undef, $borrowernumber);
26
27
28 # handle the new information....
29 # collect the form values and send an email.
30 my @fields = ('title', 'surname', 'firstname', 'phone', 'faxnumber', 'streetaddress', 'emailaddress', 'city');
31 my $update;
32 my $updateemailaddress = "finlay\@katipo.co.nz";      #Will have to change this! !!!!!!!!!!!!!!!!!!!
33 if ($query->{'title'}) {
34     # get all the fields:
35     my $message = <<"EOF";
36 Borrower $borr->{'cardnumber'} http://intradev.katipo.co.nz/cgi-bin/koha/moremember.pl?bornum=$borrowernumber
37
38 has requested to change their personal details. Please check these new details and make the changes:
39 EOF
40     foreach my $field (@fields){
41         my $newfield = $query->param($field);
42         $message .= "$field : $borr->{$field}  -->  $newfield\n";
43     }
44     $message .= "\n\nThanks,\nKoha\n\n";
45     my %mail = ( To      => $updateemailaddress ,
46                  From    => $updateemailaddress ,
47                  Subject => "User Request for update of Record.",
48                  Message => $message );
49     if (sendmail %mail) {
50 # do something if it works....
51         warn "Mail sent ok\n";
52         print $query->redirect('/cgi-bin/koha/opac-user.pl');
53     } else {
54 # do something if it doesnt work....
55         warn "Error sending mail: $Mail::Sendmail::error \n";
56     }
57 }
58
59
60 $borr->{'dateenrolled'} = slashifyDate($borr->{'dateenrolled'});
61 $borr->{'expiry'}       = slashifyDate($borr->{'expiry'});
62 $borr->{'dateofbirth'}  = slashifyDate($borr->{'dateofbirth'});
63 $borr->{'ethnicity'}    = fixEthnicity($borr->{'ethnicity'});
64
65
66 my @bordat;
67 $bordat[0] = $borr;
68
69 $template->param(BORROWER_INFO => \@bordat);
70
71 output_html_with_http_headers $query, $cookie, $template->output;