french version
[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::Auth;
28 use C4::Context;
29 use C4::Output;
30 use C4::Input;
31 use C4::Interface::CGI::Output;
32 use C4::Interface::CGI::Template;
33 use C4::Koha;
34 use CGI;
35 use Date::Manip;
36 use HTML::Template;
37
38 my %env;
39 my $input = new CGI;
40 #get varibale that tells us whether to show confirmation page
41 #or insert data
42 my $insert=$input->param('insert');
43
44 my ($template, $loggedinuser, $cookie)
45     = get_template_and_user({template_name => "newjmember.tmpl",
46                              query => $input,
47                              type => "intranet",
48                              authnotrequired => 0,
49                              flagsrequired => {borrowers => 1},
50                              debug => 1,
51                              });
52
53 #get rest of data
54 my %data;
55 my @names=$input->param;
56 foreach my $key (@names){
57   $data{$key}=$input->param($key);
58 }
59 my $missing=0;
60
61 my $string="The following compulsary fields have been left blank. Please push the back button
62 and try again<p>";
63 for (my $i=0;$i<3;$i++){
64   my $number=$data{"cardnumber_child_$i"};
65   my $firstname=$data{"firstname_child_$i"};
66   my $surname=$data{"surname_child_$i"};
67   my $dob=$data{"dateofbirth_child_$i"};
68   my $sex=$data{"sex_child_$i"};
69   if ($number eq ''){
70     if ($i == 0){
71       $string.=" Cardnumber<br>";
72       $missing=1;
73     }
74   } else {
75     if ($firstname eq ''){
76       $string.=" Given Names<br>";
77       $missing=1;
78     }
79     if ($surname eq ''){
80       $string.=" Surname<br>";
81       $missing=1;
82     }
83     if ($dob eq ''){
84       $string.=" Date Of Birth<br>";
85       $missing=1;
86     }
87     if ($sex eq ''){
88       $string.=" Gender <br>";
89       $missing=1;
90     }
91     my $valid=checkdigit(\%env,$data{"cardnumber_child_$i"});
92     if ($valid != 1){
93       $string.=" Invalid Cardnumber $number<br>";
94       $missing=1;
95     }
96   }
97 }
98         my @identsloop;
99         for (my $i=0;$i<3;$i++){
100                 my %ident;
101 #               $ident{'main'}=$main;
102 #               $ident{'image'}=$image;
103                 $ident{'cardchild'}=($data{"cardnumber_child_$i"} ne '');
104                 if ($data{"cardnumber_child_$i"} ne ''){
105                         my $name=$data{"firstname_child_$i"} . " " . $data{"surname_child_$i"};
106                         $ident{'name'}=$name;
107                         $ident{'bornum'}=$data{"bornumber_child_$i"};
108                         $ident{'dob'}=$data{"dateofbirth_child_$i"};
109                         ($data{"sex_child_$i"} eq 'M') ? ($ident{'sex'}="Male") : ($ident{'sex'}="Female") ;
110                         $ident{'school'}=$data{"school_child_$i"};
111                         $ident{'notes'}=$data{"altnotes_child_$i"};
112                         push(@identsloop, \%ident);
113                 }
114         }
115         my @inputsloop;
116         while (my ($key, $value) = each %data) {
117                 $value=~ s/\"/%22/g;
118                 my %line;
119                 $line{'key'}=$key;
120                 $line{'value'}=$value;
121                 push(@inputsloop, \%line);
122         }
123
124 # FIXME IF main and image are not fetched by HTML::TEMPLATE get them into identsloop
125 $template->param(       NOK => ($missing==1),
126                                                                 identsloop => \@identsloop,
127                                                                 inputsloop => \@inputsloop,
128                                                                 string => $string);
129
130 output_html_with_http_headers $input, $cookie, $template->output;