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
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
18 # FIXME - What is the correct value of "flagsrequired"?
19 # FIXME - untranslatable strings here
21 # Copyright 2000-2002 Katipo Communications
23 # This file is part of Koha.
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
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.
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
41 use C4::Interface::CGI::Output;
51 my @names=$input->param;
52 foreach my $key (@names){
53 $data{$key}=$input->param($key);
56 my ($template, $borrowernumber, $cookie)
57 = get_template_and_user({template_name => "newmember.tmpl",
61 flagsrequired => {parameters => 1},
64 #Get the database handle
65 my $dbh = C4::Context->dbh;
67 # Check that all compulsary fields are entered
68 # If everything is ok, set $ok = 0
69 # Otherwise set $ok = 1 and $string to the error message to display.
72 my $string = "The following compulsary fields have been left blank. "
73 . "Please push the back button and try again<p>";
75 if ($data{'cardnumber'} eq ''){
76 $string.=" Cardnumber<br>";
79 #check cardnumber is valid
81 if ( $data{'type'} ne "Add" )
89 my $valid=checkdigit(\%env,$data{'cardnumber'}, $nounique);
92 $string.=" Invalid Cardnumber<br>";
95 if ($data{'sex'} eq ''){
96 $string.=" Gender <br>";
99 if ($data{'firstname'} eq ''){
100 $string.=" Given Names<br>";
103 if ($data{'surname'} eq ''){
104 $string.=" Surname<br>";
107 if ($data{'address'} eq ''){
108 $string.=" Postal Street Address<br>";
111 if ($data{'city'} eq ''){
112 $string.=" Postal City<br>";
116 # Pass the ok/not ok status and the error message to the template
117 $template->param( OK=> ($ok==0),
120 # If things are ok, display the confirmation page
122 my $name=$data{'title'}." ";
123 if ($data{'othernames'} ne ''){
124 $name.=$data{'othernames'}." ";
126 $name.=$data{'firstname'}." ";
128 $name.="$data{'surname'} ( $data{'firstname'}, $data{'initials'})";
130 if ($data{'sex'} eq 'M'){
135 if ($data{'joining'} eq ''){
136 $data{'joining'}=ParseDate('today');
137 $data{'joining'}=format_date($data{'joining'});
139 if ($data{'expiry'} eq ''){
140 my $get_enrolmentperiod = $dbh->prepare(q{SELECT enrolmentperiod FROM categories WHERE categorycode = ?});
141 $get_enrolmentperiod->execute($data{'categorycode'});
142 my ( $period ) = $get_enrolmentperiod->fetchrow;
143 if ( ($period) && ($period != 1))
145 $data{'expiry'}=ParseDate("in $period years");
146 $data{'expiry'}=format_date($data{'expiry'});
150 $data{'expiry'}=ParseDate('in 1 year');
151 $data{'expiry'}=format_date($data{'expiry'});
154 my $ethnic=$data{'ethnicity'}." ".$data{'ethnicnotes'};
155 my $postal=$data{'address'}."<br>".$data{'city'};
157 if ($data{'streetaddress'} ne ''){
158 $home=$data{'streetaddress'}."<br>".$data{'streetcity'};
163 while (my ($key, $value) = each %data) {
167 $line{'value'}=$value;
168 push(@inputsloop, \%line);
172 my $sth = $dbh->prepare("SELECT enrolmentfee FROM categories WHERE categorycode = ?");
173 $sth->execute($data{'categorycode'});
174 my ($fee) = $sth->fetchrow;
177 $template->param(name => $name,
178 bornum => $data{'borrowernumber'},
179 cardnum => $data{'cardnumber'},
180 memcat => $data{'categorycode'},
182 joindate => format_date($data{'joining'}),
183 expdate => format_date($data{'expiry'}),
184 branchcode => $data{'branchcode'},
186 dob => format_date($data{'dateofbirth'}),
190 zipcode => $data{'zipcode'},
191 homezipcode => $data{'homezipcode'},
192 phone => $data{'phone'},
193 phoneday => $data{'phoneday'},
194 faxnumber => $data{'faxnumber'},
195 emailaddress => $data{'emailaddress'},
196 textmessaging => $data{'textmessaging'},
197 contactname => $data{'contactname'},
198 altphone => $data{'altphone'},
199 altrelationship => $data{'altrelationship'},
200 altnotes => $data{'altnotes'},
201 bornotes => $data{'borrowernotes'},
202 inputsloop => \@inputsloop);
204 # If things are not ok, display the error message
206 # Nothing to do; the "OK" and "string" variables have already been set
210 output_html_with_http_headers $input, $cookie, $template->output;