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