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