fixes for #207, 208, 211
[koha.git] / newjmember.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.comTemplating
8
9 # Copyright 2000-2002 Katipo Communications
10 #
11 # This file is part of Koha.
12 #
13 # Koha is free software; you can redistribute it and/or modify it under the
14 # terms of the GNU General Public License as published by the Free Software
15 # Foundation; either version 2 of the License, or (at your option) any later
16 # version.
17 #
18 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
19 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
20 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License along with
23 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
24 # Suite 330, Boston, MA  02111-1307 USA
25
26 use strict;
27 use C4::Output;
28 use C4::Input;
29 use CGI;
30 use Date::Manip;
31 use HTML::Template;
32
33 my %env;
34 my $input = new CGI;
35 #get varibale that tells us whether to show confirmation page
36 #or insert data
37 my $insert=$input->param('insert');
38
39 my $template = gettemplate("newjmember.tmpl");
40
41 #get rest of data
42 my %data;
43 my @names=$input->param;
44 foreach my $key (@names){
45   $data{$key}=$input->param($key);
46 }
47 my $missing=0;
48
49 my $string="The following compulsary fields have been left blank. Please push the back button
50 and try again<p>";
51 for (my $i=0;$i<3;$i++){
52   my $number=$data{"cardnumber_child_$i"};
53   my $firstname=$data{"firstname_child_$i"};
54   my $surname=$data{"surname_child_$i"};
55   my $dob=$data{"dateofbirth_child_$i"};
56   my $sex=$data{"sex_child_$i"};
57   if ($number eq ''){
58     if ($i == 0){
59       $string.=" Cardnumber<br>";
60       $missing=1;
61     }
62   } else {
63     if ($firstname eq ''){
64       $string.=" Given Names<br>";
65       $missing=1;
66     }
67     if ($surname eq ''){
68       $string.=" Surname<br>";
69       $missing=1;
70     }
71     if ($dob eq ''){
72       $string.=" Date Of Birth<br>";
73       $missing=1;
74     }
75     if ($sex eq ''){
76       $string.=" Gender <br>";
77       $missing=1;
78     }
79     my $valid=checkdigit(\%env,$data{"cardnumber_child_$i"});
80     if ($valid != 1){
81       $string.=" Invalid Cardnumber $number<br>";
82       $missing=1;
83     }
84   }
85 }
86         my @identsloop;
87         for (my $i=0;$i<3;$i++){
88                 my %ident;
89 #               $ident{'main'}=$main;
90 #               $ident{'image'}=$image;
91                 $ident{'cardchlid')=($data{"cardnumber_child_$i"} ne '');
92                 if ($data{"cardnumber_child_$i"} ne ''){
93                         my $name=$data{"firstname_child_$i"}.$data{"surname_child_$i"};
94                         $ident{'name'}=$name;
95                         $ident{'bornum'}=$data{"bornumber_child_$i"};
96                         $ident{'dob'}=$data{"dateofbirth_child_$i"};
97                         ($data{"sex_child_$i"} eq 'M') ? ($ident{'sex'}="Male") : ($ident{'sex'}="Female") ;
98                         $ident{'school'}=$data{"school_child_$i"};
99                         $ident{'notes'}=$data{"altnotes_child_$i"}
100                         push(@identsloop, \%ident);
101                 }
102         }
103         my @inputsloop;
104         while (my ($key, $value) = each %data) {
105                 $value=~ s/\"/%22/g;
106                 my %line;
107                 $line{'key'}=$key;
108                 $line{'value'}=$value;
109                 push(@inputsloop, \%line);
110         }
111
112 # FIXME IF main and image are not fetched by HTML::TEMPLATE get them into identsloop
113 $template->param(       NOK => ($missing==1),
114                                                                 main => $main,
115                                                                 image => $image,
116                                                                 identsloop => \@identsloop,
117                                                                 inputsloop => \@inputsloop,
118                                                                 string => $string);
119
120 print "Content-Type: text/html\n\n", $template->output;