Added POD.
[koha.git] / newjmember.pl
1 #!/usr/bin/perl
2
3 #script to print confirmation screen, then if accepted calls itself to insert data
4
5
6 # Copyright 2000-2002 Katipo Communications
7 #
8 # This file is part of Koha.
9 #
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
13 # version.
14 #
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License along with
20 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
21 # Suite 330, Boston, MA  02111-1307 USA
22
23 use strict;
24 use C4::Output;
25 use C4::Input;
26 use CGI;
27 use Date::Manip;
28
29 my %env;
30 my $input = new CGI;
31 #get varibale that tells us whether to show confirmation page
32 #or insert data
33 my $insert=$input->param('insert');
34 print $input->header;
35 #get rest of data
36 my %data;
37 my @names=$input->param;
38 foreach my $key (@names){                                                                                    
39   $data{$key}=$input->param($key);                                                                           
40 }  
41 my $ok=0;
42
43 my $string="The following compulsary fields have been left blank. Please push the back button
44 and try again<p>";                                                                                    
45 for (my $i=0;$i<3;$i++){
46   my $number=$data{"cardnumber_child_$i"};
47   my $firstname=$data{"firstname_child_$i"};
48   my $surname=$data{"surname_child_$i"};
49   my $dob=$data{"dateofbirth_child_$i"};
50   my $sex=$data{"sex_child_$i"};
51   if ($number eq ''){                                                                       
52     if ($i == 0){
53       $string.=" Cardnumber<br>";                                                                        
54       $ok=1;               
55     }
56   } else {
57     if ($firstname eq ''){                                                                         
58       $string.=" Given Names<br>";                                                                        
59       $ok=1;                                                                                              
60     }                                                                                                     
61     if ($surname eq ''){                                                                          
62       $string.=" Surname<br>";                                                                            
63       $ok=1;                                                                                              
64     }
65     if ($dob eq ''){                                                                          
66       $string.=" Date Of Birth<br>";                                                                            
67       $ok=1;                                                                                              
68     }
69     if ($sex eq ''){                                                                              
70       $string.=" Gender <br>";                                                                            
71       $ok=1;                                                                                              
72     } 
73     my $valid=checkdigit(\%env,$data{"cardnumber_child_$i"});                                                   
74     if ($valid != 1){                                                                                  
75       $ok=1;                                                                                           
76       $string.=" Invalid Cardnumber $number<br>";
77     }                                
78   }
79 }
80
81 print startpage();
82 print startmenu('member');
83
84 if ($ok == 0){
85   print mkheadr(1,'Confirm Record');
86   my $main="#99cc33";                                                                                     
87   my $image="/images/background-mem.gif"; 
88   for (my $i=0;$i<3;$i++){
89     if ($data{"cardnumber_child_$i"} ne ''){
90       print mktablehdr;                                                                                    
91       print mktablerow(2,$main,bold('NEW MEMBER'),"",$image);
92       my $name=$data{"firstname_child_$i"}.$data{"surname_child_$i"};
93       print mktablerow(2,'white',bold('Name'),$name);
94       print mktablerow(2,$main,bold('MEMBERSHIP DETAILS'),"",$image);
95       print mktablerow(2,'white',bold('Membership Number'),$data{"bornumber_child_$i"});
96       print mktablerow(2,'white',bold('Date of Birth'),$data{"dateofbirth_child_$i"});
97       my $sex;
98       if ($data{"sex_child_$i"} eq 'M'){
99          $sex="Male";
100       } else {
101          $sex="Female";
102       }
103       print mktablerow(2,'white',bold('Sex'),$sex);
104       print mktablerow(2,'white',bold('School'),$data{"school_child_$i"});
105       print mktablerow(2,'white',bold('General Notes'),$data{"altnotes_child_$i"});
106       
107       print mktableft;
108       print "<p>";
109     }
110   }
111   my $i=0;                                                                                             
112   my @inputs;                                                                                          
113   while (my ($key, $value) = each %data) {                                                             
114     $value=~ s/\"/%22/g;                                                                               
115     $inputs[$i]=["hidden","$key","$value"];                                                            
116     $i++;                                                                                              
117   }                                                                                                    
118   $inputs[$i]=["submit","submit","submit"];                                                            
119   print mkformnotable("/cgi-bin/koha/insertjdata.pl",@inputs);                                          
120   
121 } else {
122
123
124 #print $input->dump;
125 print $string;
126 }
127 print endmenu('member');
128 print endpage();