alternative contact no more mandatory
[koha.git] / newmember.pl
1 #!/usr/bin/perl
2
3 # $Id$
4
5 #script to print confirmation screen, then if accepted calls itself to insert data
6 # FIXME - Yes, but what does it _do_?
7 # 2002/12/18 hdl@ifrance.com templating
8
9 # 2003/01/20 acli@ada.dhs.org XXX it seems to do the following:
10 # * "insert" seems to do nothing; in 1.2.2 the script just returns a blank
11 #   page (with the headers etc.) if "insert" has anything in it
12 # * $ok has the opposite meaning of what one expects; $ok == 1 means "not ok"
13 # * if ($ok == 0) considers the "ok" case; it displays a confirmation page
14 #   for the user to "click to confirm that everything is entered correctly"
15 # * The "else" case for ($ok == 0) handles the "not ok" case; $string is the
16 #   error message to display
17
18 # FIXME - What is the correct value of "flagsrequired"?
19 # FIXME - untranslatable strings here
20
21 # Copyright 2000-2002 Katipo Communications
22 #
23 # This file is part of Koha.
24 #
25 # Koha is free software; you can redistribute it and/or modify it under the
26 # terms of the GNU General Public License as published by the Free Software
27 # Foundation; either version 2 of the License, or (at your option) any later
28 # version.
29 #
30 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
31 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
32 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
33 #
34 # You should have received a copy of the GNU General Public License along with
35 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
36 # Suite 330, Boston, MA  02111-1307 USA
37
38 use strict;
39 use C4::Auth;
40 use C4::Input;
41 use C4::Interface::CGI::Output;
42 use CGI;
43 use Date::Manip;
44 use HTML::Template;
45 use C4::Date;
46 my %env;
47 my $input = new CGI;
48
49 #get rest of data
50 my %data;
51 my @names=$input->param;
52 foreach my $key (@names){
53   $data{$key}=$input->param($key);
54 }
55
56 my ($template, $borrowernumber, $cookie)
57     = get_template_and_user({template_name => "newmember.tmpl",
58                              query => $input,
59                              type => "intranet",
60                              authnotrequired => 0,
61                              flagsrequired => {parameters => 1},
62                          });
63
64 # Check that all compulsary fields are entered
65 # If everything is ok, set $ok = 0
66 # Otherwise set $ok = 1 and $string to the error message to display.
67
68 my $ok=0;
69 my $string = "The following compulsary fields have been left blank. "
70         . "Please push the back button and try again<p>";
71
72 if ($data{'cardnumber'} eq ''){
73     $string.=" Cardnumber<br>";
74     $ok=1;
75 } else {
76     #check cardnumber is valid
77     my $nounique;
78     if ( $data{'type'} ne "Add" )
79     {
80         $nounique = 1;
81     }
82     else
83     {
84         $nounique = 0;
85     }
86     my $valid=checkdigit(\%env,$data{'cardnumber'}, $nounique);
87     if ($valid != 1){
88         $ok=1;
89         $string.=" Invalid Cardnumber<br>";
90     }
91 }
92 if ($data{'sex'} eq ''){
93     $string.=" Gender <br>";
94     $ok=1;
95 }
96 if ($data{'firstname'} eq ''){
97     $string.=" Given Names<br>";
98     $ok=1;
99 }
100 if ($data{'surname'} eq ''){
101     $string.=" Surname<br>";
102     $ok=1;
103 }
104 if ($data{'address'} eq ''){
105     $string.=" Postal Street Address<br>";
106     $ok=1;
107 }
108 if ($data{'city'} eq ''){
109     $string.=" Postal City<br>";
110     $ok=1;
111 }
112
113 # Pass the ok/not ok status and the error message to the template
114 $template->param(       OK=> ($ok==0),
115                         string=> $string);
116
117 # If things are ok, display the confirmation page
118 if ($ok == 0) {
119     my $name=$data{'title'}." ";
120     if ($data{'othernames'} ne ''){
121         $name.=$data{'othernames'}." ";
122     } else {
123         $name.=$data{'firstname'}." ";
124     }
125     $name.="$data{'surname'} ( $data{'firstname'}, $data{'initials'})";
126     my $sex;
127     if ($data{'sex'} eq 'M'){
128         $sex="Male";
129     } else {
130         $sex="Female";
131     }
132     if ($data{'joining'} eq ''){
133         $data{'joining'}=ParseDate('today');
134         $data{'joining'}=format_date($data{'joining'});
135     }
136     if ($data{'expiry'} eq ''){
137         $data{'expiry'}=ParseDate('in 1 year');
138         $data{'expiry'}=format_date($data{'expiry'});
139     }
140     my $ethnic=$data{'ethnicity'}." ".$data{'ethnicnotes'};
141     my $postal=$data{'address'}."<br>".$data{'city'};
142     my $home;
143     if ($data{'streetaddress'} ne ''){
144         $home=$data{'streetaddress'}."<br>".$data{'streetcity'};
145     } else {
146         $home=$postal;
147     }
148     my @inputsloop;
149     while (my ($key, $value) = each %data) {
150         $value=~ s/\"/%22/g;
151         my %line;
152         $line{'key'}=$key;
153         $line{'value'}=$value;
154         push(@inputsloop, \%line);
155     }
156
157     #Get the fee
158     my $dbh = C4::Context->dbh;
159     my $sth = $dbh->prepare("SELECT enrolmentfee FROM categories WHERE categorycode = ?");
160     $sth->execute($data{'categorycode'});
161     my ($fee) = $sth->fetchrow;
162     $sth->finish;
163
164     $template->param(name => $name,
165                      bornum => $data{'borrowernumber'},
166                      cardnum => $data{'cardnumber'},
167                      memcat => $data{'categorycode'},
168                      fee => $fee,
169                      joindate => format_date($data{'joining'}),
170                      expdate => format_date($data{'expiry'}),
171                      branchcode => $data{'branchcode'},
172                      ethnic => $ethnic,
173                      dob => format_date($data{'dateofbirth'}),
174                      sex => $sex,
175                      postal => $postal,
176                      home => $home,
177                         zipcode => $data{'zipcode'},
178                         homezipcode => $data{'homezipcode'},
179                      phone => $data{'phone'},
180                      phoneday => $data{'phoneday'},
181                      faxnumber => $data{'faxnumber'},
182                      emailaddress => $data{'emailaddress'},
183                         textmessaging => $data{'textmessaging'},
184                      contactname => $data{'contactname'},
185                      altphone => $data{'altphone'},
186                      altrelationship => $data{'altrelationship'},
187                      altnotes => $data{'altnotes'},
188                      bornotes => $data{'borrowernotes'},
189                      inputsloop => \@inputsloop);
190
191 # If things are not ok, display the error message
192 } else {
193     # Nothing to do; the "OK" and "string" variables have already been set
194     ;
195 }
196
197 output_html_with_http_headers $input, $cookie, $template->output;
198
199