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"?
20 # Copyright 2000-2002 Katipo Communications
22 # This file is part of Koha.
24 # Koha is free software; you can redistribute it and/or modify it under the
25 # terms of the GNU General Public License as published by the Free Software
26 # Foundation; either version 2 of the License, or (at your option) any later
29 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
30 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
31 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
33 # You should have received a copy of the GNU General Public License along with
34 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
35 # Suite 330, Boston, MA 02111-1307 USA
40 use C4::Interface::CGI::Output;
50 my @names=$input->param;
51 foreach my $key (@names){
52 $data{$key}=$input->param($key);
55 my ($template, $borrowernumber, $cookie)
56 = get_template_and_user({template_name => "newmember.tmpl",
60 flagsrequired => {parameters => 1},
63 #Get the database handle
64 my $dbh = C4::Context->dbh;
66 # Check that all compulsary fields are entered
67 # If everything is ok, set $ok = 0
68 # Otherwise set $ok = 1 and $string to the error message to display.
71 my $string = "The following compulsary fields have been left blank. "
72 . "Please push the back button and try again<p>";
74 if ($data{'cardnumber'} eq ''){
75 push @errors,"cardnumber";
78 #check cardnumber is valid
80 if ( $data{'type'} eq "Add" ) {
85 my $valid=checkdigit(\%env,$data{'cardnumber'}, $nounique);
88 push @errors, "invalid_cardnumber";
91 if ($data{'sex'} eq ''){
92 push @errors, "gender";
95 if ($data{'firstname'} eq ''){
96 push @errors,"firstname";
99 if ($data{'surname'} eq ''){
100 push @errors,"surname";
103 if ($data{'address'} eq ''){
104 push @errors, "address";
107 if ($data{'city'} eq ''){
108 push @errors, "city";
112 # Pass the ok/not ok status and the error message to the template
113 $template->param( OK=> ($ok==0));
114 foreach my $error (@errors) {
115 $template->param( $error => 1);
118 # If things are ok, display the confirmation page
120 my $name=$data{'title'}." ";
121 if ($data{'othernames'} ne ''){
122 $name.=$data{'othernames'}." ";
124 $name.=$data{'firstname'}." ";
126 $name.="$data{'surname'} ( $data{'firstname'}, $data{'initials'})";
128 if ($data{'sex'} eq 'M'){
133 if ($data{'joining'} eq ''){
134 $data{'joining'}=ParseDate('today');
135 $data{'joining'}=format_date($data{'joining'});
137 if ($data{'expiry'} eq ''){
138 my $get_enrolmentperiod = $dbh->prepare(q{SELECT enrolmentperiod FROM categories WHERE categorycode = ?});
139 $get_enrolmentperiod->execute($data{'categorycode'});
140 my ( $period ) = $get_enrolmentperiod->fetchrow;
141 if ( ($period) && ($period != 1))
143 $data{'expiry'}=ParseDate("in $period years");
144 $data{'expiry'}=format_date($data{'expiry'});
148 $data{'expiry'}=ParseDate('in 1 year');
149 $data{'expiry'}=format_date($data{'expiry'});
152 my $ethnic=$data{'ethnicity'}." ".$data{'ethnicnotes'};
153 my $postal=$data{'address'}."<br>".$data{'city'};
155 if ($data{'streetaddress'} ne ''){
156 $home=$data{'streetaddress'}."<br>".$data{'streetcity'};
161 while (my ($key, $value) = each %data) {
165 $line{'value'}=$value;
166 push(@inputsloop, \%line);
170 my $sth = $dbh->prepare("SELECT enrolmentfee FROM categories WHERE categorycode = ?");
171 $sth->execute($data{'categorycode'});
172 my ($fee) = $sth->fetchrow;
175 $template->param(name => $name,
176 bornum => $data{'borrowernumber'},
177 cardnum => $data{'cardnumber'},
178 memcat => $data{'categorycode'},
180 joindate => format_date($data{'joining'}),
181 expdate => format_date($data{'expiry'}),
182 branchcode => $data{'branchcode'},
184 dob => format_date($data{'dateofbirth'}),
188 zipcode => $data{'zipcode'},
189 homezipcode => $data{'homezipcode'},
190 phone => $data{'phone'},
191 phoneday => $data{'phoneday'},
192 faxnumber => $data{'faxnumber'},
193 emailaddress => $data{'emailaddress'},
194 textmessaging => $data{'textmessaging'},
195 contactname => $data{'contactname'},
196 altphone => $data{'altphone'},
197 altrelationship => $data{'altrelationship'},
198 altnotes => $data{'altnotes'},
199 bornotes => $data{'borrowernotes'},
200 inputsloop => \@inputsloop);
202 # If things are not ok, display the error message
204 # Nothing to do; the "OK" and "string" variables have already been set
208 output_html_with_http_headers $input, $cookie, $template->output;