bugfix
[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 #print $input->header;
40 my $template = gettemplate("newjmember.tmpl");
41
42 #get rest of data
43 my %data;
44 my @names=$input->param;
45 foreach my $key (@names){
46   $data{$key}=$input->param($key);
47 }
48 my $ok=0;
49
50 my $string="The following compulsary fields have been left blank. Please push the back button
51 and try again<p>";
52 for (my $i=0;$i<3;$i++){
53   my $number=$data{"cardnumber_child_$i"};
54   my $firstname=$data{"firstname_child_$i"};
55   my $surname=$data{"surname_child_$i"};
56   my $dob=$data{"dateofbirth_child_$i"};
57   my $sex=$data{"sex_child_$i"};
58   if ($number eq ''){
59     if ($i == 0){
60       $string.=" Cardnumber<br>";
61       $ok=1;
62     }
63   } else {
64     if ($firstname eq ''){
65       $string.=" Given Names<br>";
66       $ok=1;
67     }
68     if ($surname eq ''){
69       $string.=" Surname<br>";
70       $ok=1;
71     }
72     if ($dob eq ''){
73       $string.=" Date Of Birth<br>";
74       $ok=1;
75     }
76     if ($sex eq ''){
77       $string.=" Gender <br>";
78       $ok=1;
79     }
80     my $valid=checkdigit(\%env,$data{"cardnumber_child_$i"});
81     if ($valid != 1){
82       $ok=1;
83       $string.=" Invalid Cardnumber $number<br>";
84     }
85   }
86 }
87         my @identsloop;
88         for (my $i=0;$i<3;$i++){
89                 my %ident;
90 #               $ident{'main'}=$main;
91 #               $ident{'image'}=$image;
92                 $ident{'cardchlid')=($data{"cardnumber_child_$i"} ne '');
93                 if ($data{"cardnumber_child_$i"} ne ''){
94                         my $name=$data{"firstname_child_$i"}.$data{"surname_child_$i"};
95                         $ident{'name'}=$name;
96                         $ident{'bornum'}=$data{"bornumber_child_$i"};
97                         $ident{'dob'}=$data{"dateofbirth_child_$i"};
98                         ($data{"sex_child_$i"} eq 'M') ? ($ident{'sex'}="Male") : ($ident{'sex'}="Female") ;
99                         $ident{'school'}=$data{"school_child_$i"};
100                         $ident{'notes'}=$data{"altnotes_child_$i"}
101                         push(@identsloop, \%ident);
102                 }
103         }
104         my @inputsloop;
105         while (my ($key, $value) = each %data) {
106                 $value=~ s/\"/%22/g;
107                 my %line;
108                 $line{'key'}=$key;
109                 $line{'value'}=$value;
110                 push(@inputsloop, \%line);
111         }
112
113 # FIXME IF main and image are not fetched by HTML::TEMPLATE get them into identsloop
114 $template->param(       NOK => (ok==1),
115                                                                 main => $main,
116                                                                 image => $image,
117                                                                 identsloop => \@identsloop,
118                                                                 inputsloop => \@inputsloop,
119                                                                 string => $string);
120
121 print "Content-Type: text/html\n\n", $template->output;