Merging from rel-1-2 to trunk
[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 $flagsrequired;
16 $flagsrequired->{borrow}=1;
17
18 my ($loggedinuser, $cookie, $sessionID) = checkauth($query, 0, $flagsrequired);
19
20 # get borrower information ....
21 my $borrowernumber = getborrowernumber($loggedinuser);
22 my ($borr, $flags) = getpatroninformation(undef, $borrowernumber);
23
24
25 # handle the new information....
26 # collect the form values and send an email.
27 my @fields = ('title', 'surname', 'firstname', 'phone', 'faxnumber', 'streetaddress', 'emailaddress', 'city');
28 my $update;
29 my $updateemailaddress = "finlay\@katipo.co.nz";      #Will have to change this! !!!!!!!!!!!!!!!!!!!
30 if ($query->{'title'}) {
31     # get all the fields:
32     my $message = <<"EOF";
33 Borrower $borr->{'cardnumber'} http://intradev.katipo.co.nz/cgi-bin/koha/moremember.pl?bornum=$borrowernumber
34
35 has requested to change their personal details. Please check these new details and make the changes:
36 EOF
37     foreach my $field (@fields){
38         my $newfield = $query->param($field);
39         $message .= "$field : $borr->{$field}  -->  $newfield\n";
40     }
41     $message .= "\n\nThanks,\nKoha\n\n";
42     my %mail = ( To      => $updateemailaddress ,
43                  From    => $updateemailaddress ,
44                  Subject => "User Request for update of Record.",
45                  Message => $message );
46     if (sendmail %mail) {
47 # do something if it works....
48         warn "Mail sent ok\n";
49         print $query->redirect('/cgi-bin/koha/opac-user.pl');
50     } else {
51 # do something if it doesnt work....
52         warn "Error sending mail: $Mail::Sendmail::error \n";
53     }
54 }
55
56 my $template = gettemplate("opac-userupdate.tmpl", "opac");
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
71 $template->param(loggedinuser => $loggedinuser);
72
73 print "Content-Type: text/html\n\n", $template->output;